Auto Album creation with cpg1.4 and SMF1.1.4 Auto Album creation with cpg1.4 and SMF1.1.4
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Auto Album creation with cpg1.4 and SMF1.1.4

Started by Hot Rides, April 18, 2008, 12:08:40 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

Hot Rides

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;

        // overriding authenticate() as we can let SMF do this all for us.
        function authenticate()

scrol down to just above;

$this->session_update();


And add;

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.

Debugger

For PhpBB
you must patch phpbb2018.inc.php file

after
function phpbb2018_udb(){
...
}


add code like this
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();
        }


Hot Rides


pvisser

I Try to do it but i haven an FATAL ERROR: and i white page.
See my codin now.

// 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.


Nibbler

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

pvisser

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

Nibbler

Find

global $USER_DATA, $user_settings;

change to

global $USER_DATA, $user_settings, $CONFIG;

pvisser

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

Nibbler

Strange. Hardcode your table names instead then.

Change

{$CONFIG['TABLE_ALBUMS']}

to

cpg_albums

or whatever prefix your chose during installation. Read the debug output if you don't know what you chose.

pvisser

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.

Nibbler

Yeah, you can just add it in.

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

pvisser

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

dannypritchett01

Quote from: Debugger on June 21, 2008, 03:19:15 PM
For PhpBB
you must patch phpbb2018.inc.php file

after
function phpbb2018_udb(){
...
}


add code like this
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?

Joachim Müller

Almost certainly not. Spare parts for a Volkswagen hardly ever fit into a Porsche or vice versa.