Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Auto Album creation with cpg1.4 and SMF1.1.4  (Read 20173 times)

0 Members and 1 Guest are viewing this topic.

Hot Rides

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 108
  • I am
    • Hot Rides Show & Cruise
Auto Album creation with cpg1.4 and SMF1.1.4
« on: April 18, 2008, 12:08:40 am »

I had been searching on how to do this and found easy answers for a standalone but nothing for a bridge.
Everyone here said it was a SMF problem. Everyone there said it was a CPM problem. Well it turns out it was a CPM problem and after a lot of help from a SMF user and some good luck by me I found the answer.

So for anyone running a bridge CPM and SMF looking to have an album automaticlly created for your users so they dont have to manually create one before uploading pics (because we all know the easier it is for them, the more likely they are to stay), heres the answer.

in bridge/smf10.ini.php find;
Code: [Select]
        // overriding authenticate() as we can let SMF do this all for us.
        function authenticate()
scrol down to just above;
Code: [Select]
$this->session_update();

And add;
Code: [Select]
if($user_settings['ID_MEMBER'] != 0)
{
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (10000 + $user_settings['ID_MEMBER']);
$result = cpg_db_query($sql);
if(mysql_num_rows($result) == 0)
{
$sql = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (title, category) VALUES ('My album', " .(10000 + $user_settings['ID_MEMBER']) . ")";
cpg_db_query($sql);
}
mysql_free_result($result);
}

This will automatically create an album for each user named 'My Album' Unless the already have an album created.  And the album can not be deleted until the user creates another album because it will recreate the album if another does not exist every time they access the gallery.

I am not a great coder, I will be of limited help if this does not work for you. I just wanted to share this with everyone has it has helped me.
Logged

Debugger

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #1 on: June 21, 2008, 03:19:15 pm »

For PhpBB
you must patch phpbb2018.inc.php file

after
Code: [Select]
function phpbb2018_udb(){
...
}

add code like this
Code: [Select]
function authenticate()
        {
                global $USER_DATA, $CONFIG;

                if (!($auth = $this->session_extraction()) && !($auth = $this->cookie_extraction())) {
                        $this->load_guest_data();
                } else {
                        list ($id, $cookie_pass) = $auth;
                        $f = $this->field;

                        if (isset($this->usergroupstable)){
                                $sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, ug.{$f['usertbl_group_id']} AS group_id ".
                                           "FROM {$this->usertable} AS u, {$this->usergroupstable} AS ug ".
                                           "WHERE u.{$f['user_id']}=ug.{$f['user_id']} AND u.{$f['user_id']}='$id'";
                        } else {
                                $sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, u.{$f['usertbl_group_id']}+100 AS group_id ".
                                           "FROM {$this->usertable} AS u INNER JOIN {$this->groupstable} AS g ON u.{$f['usertbl_group_id']}=g.{$f['grouptbl_group_id']} ".
                                           "WHERE u.{$f['user_id']}='$id'";
                        }

                        $result = cpg_db_query($sql, $this->link_id);

                        if (mysql_num_rows($result)){
                                $row = mysql_fetch_assoc($result);
                                mysql_free_result($result);

                                $db_pass = $this->udb_hash_db($row['password']);
                                if ($db_pass === $cookie_pass) {
                                        $this->load_user_data($row);
                                } else {
                                        $this->load_guest_data();
                                }
                        } else {
                                $this->load_guest_data();
                        }
                }

                $user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';

        $USER_DATA = array_merge($USER_DATA, $this->get_user_data($USER_DATA['groups'][0], $USER_DATA['groups'], $this->guestgroup));

                if ($this->use_post_based_groups){
                        $USER_DATA['has_admin_access'] = (in_array($USER_DATA['groups'][0] - 100,$this->admingroups)) ? 1 : 0;
                } else {
                        $USER_DATA['has_admin_access'] = ($USER_DATA['groups'][0] == 1) ? 1 : 0;
                }

                $USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];

                // avoids a template error
                if (!$USER_DATA['user_id']) $USER_DATA['can_create_albums'] = 0;

                // For error checking
                $CONFIG['TABLE_USERS'] = '**ERROR**';


                define('USER_ID', $USER_DATA['user_id']);
        define('USER_NAME', addslashes($USER_DATA['user_name']));
        define('USER_GROUP', $USER_DATA['group_name']);
        define('USER_GROUP_SET', $user_group_set);
        define('USER_IS_ADMIN', $USER_DATA['has_admin_access']);
        define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
        define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
        define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
        define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
        define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
        define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
        define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
        define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
        define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);

        //Autocreating albums
        if($USER_DATA['user_id'] != 0)
        {
                $cid = 10000 + $USER_DATA['user_id'];
                $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . $cid;
                $result = cpg_db_query($sql);
                if(mysql_num_rows($result) == 0)
                {
                        $sql = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos) VALUES ('$cid', 'My Album', 'NO',  '1')";
                        cpg_db_query($sql);
                }
                mysql_free_result($result);
        }
                $this->session_update();
        }
Logged

Hot Rides

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 108
  • I am
    • Hot Rides Show & Cruise
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #2 on: June 27, 2008, 07:46:16 pm »

thanks for adding to it!! ;D
Logged

pvisser

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #3 on: June 30, 2008, 03:09:03 pm »

I Try to do it but i haven an FATAL ERROR: and i white page.
See my codin now.
Code: [Select]
// overriding authenticate() as we can let SMF do this all for us.
        function authenticate()
        {
                global $USER_DATA, $user_settings;

                if (!$user_settings){
                        $this->load_guest_data();
                } else {

                        $row = array(
                                'id' => $user_settings['ID_MEMBER'],
                                'username' => $user_settings['memberName'],
                                'group_id' => $user_settings['ID_GROUP']
                        );

                        $this->load_user_data($row);
                }

                $user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';

$USER_DATA = array_merge($USER_DATA, $this->get_user_data($USER_DATA['groups'][0], $USER_DATA['groups'], $this->guestgroup));

                 $USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'] = array_intersect($USER_DATA['groups'],$this->admingroups) ? 1 : 0;

                // avoids a template error
                if (!$USER_DATA['user_id']) $USER_DATA['can_create_albums'] = 0;

// For error checking
                $CONFIG['TABLE_USERS'] = '**ERROR**';

                define('USER_ID', $USER_DATA['user_id']);
define('USER_NAME', addslashes($USER_DATA['user_name']));
define('USER_GROUP', $USER_DATA['group_name']);
define('USER_GROUP_SET', $user_group_set);
define('USER_IS_ADMIN', $USER_DATA['has_admin_access']);
define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);

//!!!!!!!!!!!!!!!!!!!!!!!--------------Here is your pasted coding..
                if($user_settings['ID_MEMBER'] != 0)
{
$sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . (10000 + $user_settings['ID_MEMBER']);
$result = cpg_db_query($sql);
if(mysql_num_rows($result) == 0)
{
$sql = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (title, category) VALUES ('My album', " .(10000 + $user_settings['ID_MEMBER']) . ")";
cpg_db_query($sql);
}
mysql_free_result($result);
}
    // !!!!!!!!!!!!!!!!!!!!!!----------------Here end your mod



$this->session_update();


Please advice.
Logged

pvisser

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #4 on: July 03, 2008, 06:18:33 pm »

no one? ???
Logged

Nibbler

  • Guest
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #5 on: July 03, 2008, 06:30:15 pm »

Enable debug mode in config and post the mysql error message you get when you replicate the error.
Logged

pvisser

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #6 on: July 03, 2008, 07:22:39 pm »

Thanks, The Message is


While executing query "SELECT aid FROM  WHERE category = 10001" on 0

mySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE category = 10001' at line 1

Can you advice me or help me? Thanks
Greetings Patrick Visser
Logged

Nibbler

  • Guest
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #7 on: July 03, 2008, 08:02:04 pm »

Find

Code: [Select]
global $USER_DATA, $user_settings;
change to

Code: [Select]
global $USER_DATA, $user_settings, $CONFIG;
Logged

pvisser

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #8 on: July 03, 2008, 08:10:44 pm »

O Nope. Same i Think. This is the message:

While executing query "SELECT aid FROM  WHERE category = 10001" on 0

mySQL error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE category = 10001' at line 1
Logged

Nibbler

  • Guest
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #9 on: July 03, 2008, 08:30:16 pm »

Strange. Hardcode your table names instead then.

Change

Code: [Select]
{$CONFIG['TABLE_ALBUMS']}
to

Code: [Select]
cpg_albums
or whatever prefix your chose during installation. Read the debug output if you don't know what you chose.
Logged

pvisser

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #10 on: July 04, 2008, 09:28:16 am »

Thanks Nibbler, The cpg_albums part did the trick. Now its working.  Is it also possible to automatic enter an album discription ad the same time? If so kan you please advice my hou te do this. Thanks for the help.
Logged

Nibbler

  • Guest
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #11 on: July 04, 2008, 12:13:33 pm »

Yeah, you can just add it in.

Code: [Select]
$sql = "INSERT INTO cpg_albums (title, category, description) VALUES ('My album', " .(10000 + $user_settings['ID_MEMBER']) . ", 'Your description here')";
Logged

pvisser

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #12 on: July 05, 2008, 09:16:02 am »

I'm so thankfull, I try this part and let you know. ;D
Logged

dannypritchett01

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #13 on: August 02, 2008, 08:09:47 am »

For PhpBB
you must patch phpbb2018.inc.php file

after
Code: [Select]
function phpbb2018_udb(){
...
}

add code like this
Code: [Select]
function authenticate()
        {
                global $USER_DATA, $CONFIG;

                if (!($auth = $this->session_extraction()) && !($auth = $this->cookie_extraction())) {
                        $this->load_guest_data();
                } else {
                        list ($id, $cookie_pass) = $auth;
                        $f = $this->field;

                        if (isset($this->usergroupstable)){
                                $sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, ug.{$f['usertbl_group_id']} AS group_id ".
                                           "FROM {$this->usertable} AS u, {$this->usergroupstable} AS ug ".
                                           "WHERE u.{$f['user_id']}=ug.{$f['user_id']} AND u.{$f['user_id']}='$id'";
                        } else {
                                $sql = "SELECT u.{$f['user_id']} AS id, u.{$f['username']} AS username, u.{$f['password']} AS password, u.{$f['usertbl_group_id']}+100 AS group_id ".
                                           "FROM {$this->usertable} AS u INNER JOIN {$this->groupstable} AS g ON u.{$f['usertbl_group_id']}=g.{$f['grouptbl_group_id']} ".
                                           "WHERE u.{$f['user_id']}='$id'";
                        }

                        $result = cpg_db_query($sql, $this->link_id);

                        if (mysql_num_rows($result)){
                                $row = mysql_fetch_assoc($result);
                                mysql_free_result($result);

                                $db_pass = $this->udb_hash_db($row['password']);
                                if ($db_pass === $cookie_pass) {
                                        $this->load_user_data($row);
                                } else {
                                        $this->load_guest_data();
                                }
                        } else {
                                $this->load_guest_data();
                        }
                }

                $user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';

        $USER_DATA = array_merge($USER_DATA, $this->get_user_data($USER_DATA['groups'][0], $USER_DATA['groups'], $this->guestgroup));

                if ($this->use_post_based_groups){
                        $USER_DATA['has_admin_access'] = (in_array($USER_DATA['groups'][0] - 100,$this->admingroups)) ? 1 : 0;
                } else {
                        $USER_DATA['has_admin_access'] = ($USER_DATA['groups'][0] == 1) ? 1 : 0;
                }

                $USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'];

                // avoids a template error
                if (!$USER_DATA['user_id']) $USER_DATA['can_create_albums'] = 0;

                // For error checking
                $CONFIG['TABLE_USERS'] = '**ERROR**';


                define('USER_ID', $USER_DATA['user_id']);
        define('USER_NAME', addslashes($USER_DATA['user_name']));
        define('USER_GROUP', $USER_DATA['group_name']);
        define('USER_GROUP_SET', $user_group_set);
        define('USER_IS_ADMIN', $USER_DATA['has_admin_access']);
        define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
        define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
        define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
        define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
        define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
        define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
        define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
        define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
        define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);

        //Autocreating albums
        if($USER_DATA['user_id'] != 0)
        {
                $cid = 10000 + $USER_DATA['user_id'];
                $sql = "SELECT aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE category = " . $cid;
                $result = cpg_db_query($sql);
                if(mysql_num_rows($result) == 0)
                {
                        $sql = "INSERT INTO {$CONFIG['TABLE_ALBUMS']} (category, title, uploads, pos) VALUES ('$cid', 'My Album', 'NO',  '1')";
                        cpg_db_query($sql);
                }
                mysql_free_result($result);
        }
                $this->session_update();
        }


Will this code work for phpbb3 as well?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Auto Album creation with cpg1.4 and SMF1.1.4
« Reply #14 on: August 02, 2008, 02:41:45 pm »

Almost certainly not. Spare parts for a Volkswagen hardly ever fit into a Porsche or vice versa.
Logged
Pages: [1]   Go Up
 

Page created in 0.025 seconds with 20 queries.