Support Forum Project Downloads FAQ Documentation About Demo Tutorials
October 11, 2008, 02:06:13 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Coppermine 1.4.19 - Security release
The development team is releasing a security update for Coppermine in order to counter a recently discovered injection vulnerability. It is important that all users who run version cpg1.4.18 or older update to this latest version as soon as possible.
[more]
   Home   Help Search Board rules Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Auto Album creation with cpg1.4 and SMF1.1.4  (Read 2170 times)
0 Members and 1 Guest are viewing this topic.
Hot Rides Topic starter
Coppermine frequent poster
***
Gender: Male
Posts: 101

I am


WWW
« 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:
        // overriding authenticate() as we can let SMF do this all for us.
        function authenticate()
scrol down to just above;
Code:
$this->session_update();

And add;
Code:
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

Posts: 1


« Reply #1 on: June 21, 2008, 03:19:15 PM »

For PhpBB
you must patch phpbb2018.inc.php file

after
Code:
function phpbb2018_udb(){
...
}

add code like this
Code:
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 Topic starter
Coppermine frequent poster
***
Gender: Male
Posts: 101

I am


WWW
« Reply #2 on: June 27, 2008, 07:46:16 PM »

thanks for adding to it!! Grin
Logged
pvisser
Coppermine newbie

Posts: 9


« 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:
// 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

Posts: 9


« Reply #4 on: July 03, 2008, 06:18:33 PM »

no one? Huh
Logged
Nibbler
Dev Team member
Coppermine addict
****
Gender: Male
Posts: 17965



WWW
« 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

I want to believe.
pvisser
Coppermine newbie

Posts: 9


« 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
Dev Team member
Coppermine addict
****
Gender: Male
Posts: 17965



WWW
« Reply #7 on: July 03, 2008, 08:02:04 PM »

Find

Code:
global $USER_DATA, $user_settings;

change to

Code:
global $USER_DATA, $user_settings, $CONFIG;
Logged

I want to believe.
pvisser
Coppermine newbie

Posts: 9


« 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
Dev Team member
Coppermine addict
****
Gender: Male
Posts: 17965



WWW
« Reply #9 on: July 03, 2008, 08:30:16 PM »

Strange. Hardcode your table names instead then.

Change

Code:
{$CONFIG['TABLE_ALBUMS']}

to

Code:
cpg_albums

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

I want to believe.
pvisser
Coppermine newbie

Posts: 9


« 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
Dev Team member
Coppermine addict
****
Gender: Male
Posts: 17965



WWW
« Reply #11 on: July 04, 2008, 12:13:33 PM »

Yeah, you can just add it in.

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

I want to believe.
pvisser
Coppermine newbie

Posts: 9


« Reply #12 on: July 05, 2008, 09:16:02 AM »

I'm so thankfull, I try this part and let you know. Grin
Logged
dannypritchett01
Coppermine newbie

Posts: 7


« Reply #13 on: August 02, 2008, 08:09:47 AM »

For PhpBB
you must patch phpbb2018.inc.php file

after
Code:
function phpbb2018_udb(){
...
}

add code like this
Code:
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
Administrator
Coppermine addict
*****
Gender: Male
Posts: 40060


aka "GauGau"


WWW
« 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

Don't contact me over PM or email unless I asked you to. Instead: post on the proper board. All unrequested messages will be ignored!
Like my avatar? Create a free custom avatar just like mine.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.125 seconds with 19 queries.