Support Forums | Demo Gallery [1.x] [2.x] | Downloads | News | Site Map ]
Nuked Gallery
  Create a FREE account or Login   As a guest, you don't have access to our FULL navigation system.
 Forum FAQForum FAQ   StatisticsStatistics   SearchSearch   UsergroupsUsergroups   FavoritesFavorites  

Gallery2 Integration Development

 
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Integration » Gallery 2 Integration View previous topicPrinter friendly versionView next topic
Author Message
drumicube

Beginner
Beginner


Joined: Oct 11, 2004
Posts: 3

PostPosted: Tue Mar 29, 2005 2:15 pm    Post subject: Re: Gallery2 Support at NukedGallery.net Reply with quote

Hi dari, i'm the main author of the G2-Phpnuke module.

I just would like to thank you for your excellent website, and your amazing support. It really helps a lot !

We actually finish the basic features of the modules, except we have not yet setup a dynamic synch mapping between G2 and phpnuke account !
Basically it means, each time a new user register phpnuke, he won't be recognize automatically by G2...
It's now what i'm fully focus on, and we hope to have it soon.

Anyway, if you have any questions concerning the module, it would be a pleasure to answer as far as i can. Your website helps me so much with G1, it's the less i can do !

Cheers.
Back to top
Offline View user's profile Send private message
AdBot
   Post subject: Re: Gallery2 Support at NukedGallery.net  

Back to top
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Tue Mar 29, 2005 2:25 pm    Post subject: Re: Gallery2 Support at NukedGallery.net Reply with quote

Thanks for the kind words, and it was no trouble at all fixing the CSS issue Smile
I've been looking here [sourceforge.net] for the hooks for syncing up users...

also, the current admin hack that is available fails on large user databases (such as the one here). I'm working on a hack to separate large databases into 100-user sections so the import does not fail.
Back to top
Offline View user's profile Send private message Visit poster's website
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Tue Mar 29, 2005 2:31 pm    Post subject: Re: Gallery2 Support at NukedGallery.net Reply with quote

here's a start maybe (from http://cvs.sourceforge.net/viewcvs.py/g ... &view=auto ):
PHP: › <?php /**
 * Implementation of hook_user
 */
function gallery_user($op, &$edit, &$user$category) {
  switch (
$op) {
    case 
'insert':
      
_gallery_init();

      
$ret GalleryEmbed::createUser($user->uid,
                                      array(
'username' => $user->name,
                                            
'email' => $user->mail,
                                            
'fullname' => $user->name,
                                            
'language' => $user->language,
                                            
'hashedpassword' => $user->pass,
                                            
'hashmethod' => 'md5'
                                            
));
      if (
$ret->isError()) {
        
drupal_set_message(t('Error creating gallery user'));
      }
      
GalleryEmbed::done();
      break;
    case 
'update':
      
_gallery_init();

      
$ret GalleryEmbed::updateUser($user->uid,
                                      array(
'username' => $edit['name'],
                                            
'email' => $edit['mail']));
      if (
$ret->isError()) {
        
// try to create user then.
        
$ret GalleryEmbed::createUser($user->uid,
                                         array(
'username' => $edit['name'],
                                               
'email' => $edit['mail'],
                                               
'language' => $edit['language'],
                                               ));
        if (
$ret->isError()) {
          
drupal_set_message(t('Error updating gallery user'));
        }
      }
      
GalleryEmbed::done();
      break;
    case 
'delete':
      
_gallery_init();

      
$ret GalleryEmbed::deleteUser($user->uid);
      if (
$ret->isError()) {
        
drupal_set_message(t('Error deleting gallery user'));
      }
      
GalleryEmbed::done();
      break;
  }  
?>
Back to top
Offline View user's profile Send private message Visit poster's website
drumicube

Beginner
Beginner


Joined: Oct 11, 2004
Posts: 3

PostPosted: Thu Mar 31, 2005 6:03 pm    Post subject: Re: Gallery2 Support at NukedGallery.net Reply with quote

I have a first working code for the user creation on the fly !
See it on G2 dev forum...

By the way, thanks for your concern about the database, as you could imagine i don't have access to a thousand users DB... (and certainly not with my website... Laughing )
It's always good to know someone is really testing it in real production situation.

Could you tell me more, i assume this is a Max execution time or Memory exceded Error, no ?
Back to top
Offline View user's profile Send private message
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Apr 01, 2005 7:05 am    Post subject: Re: Gallery2 Support at NukedGallery.net Reply with quote

Max execution time exceeded. My proposed solution is to look at the code for this phpBB mod:

http://www.phpbb.com/phpBB/viewtopic.php?t=83916

That MOD breaks the tables up into chunks of 100, which is probably what should be done for our situation. If you're not a php wiz, I can extract the relevant pieces of code for you, as I had to customize this MOD for my forums anyway.
Back to top
Offline View user's profile Send private message Visit poster's website
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Apr 01, 2005 7:35 am    Post subject: Re: Gallery2 Integration Development Reply with quote

this is the code:
PHP: › <?php for( $i $HTTP_GET_VARS['start_id']; $i $postcount[pcount]; $i++ )
    {

        if (
$i == $HTTP_GET_VARS['start_id'] + 100)
        {
        
$nextpage=1;
        break;
        }
        
$sql "SELECT post_id FROM " POSTS_TEXT_TABLE " LIMIT " $i ",1";
        
$result $db->sql_query($sql);
            if ( !
$result )
            {
                
message_die(GENERAL_ERROR"Could not find posts.""",__LINE____FILE__$sql);
            }
        
$posts $db->sql_fetchrow($result);
        
$activeid $posts['post_id'];
        
$sql "SELECT * FROM " POSTS_TEXT_TABLE " WHERE post_id = " $activeid;
        
$result $db->sql_query($sql);
            if ( !
$result )
            {
                
message_die(GENERAL_ERROR"Could not find posts.""",__LINE____FILE__$sql);
            }

        
$activepost $db->sql_fetchrowset($result);
        
add_search_words('single'$activepost[0]['post_id'], stripslashes($activepost[0]['post_text']), stripslashes($activepost[0]['post_subject']));
    } 
?>


essentially, it just sets the $start variable as a GET variable in the HTTP request, and uses that to increment 100 posts. With a little modification, the same logic can be applied to the phpNuke user database. The important thing to do is have the page refresh after each block of 100 users, since that kicks off another execution of the loop, and thus gets around the max execution time error. It also gives the user some notification of progress.
Back to top
Offline View user's profile Send private message Visit poster's website
dari

Site Admin
Site Admin


Joined: Mar 03, 2003
Posts: 6287
Location: Washington Township, NJ, USA

PostPosted: Fri Apr 01, 2005 8:50 am    Post subject: Re: Gallery2 Integration Development Reply with quote

try this to segment into blocks of 100:
PHP: › <?php function g2_phpnukeTog2UserExport() {
    global 
$db$user_prefix,$Phpnuke2G2Lang;    

    
// init G2 transaction, load G2 API, if not already done so
    
if (!init()) {
        return 
false;
    }
    
// Load all existing phpnuke <-> G2 mappings
    
list ($ret$mapsbyentityid$mapsbyexternalid) = g2getallexternalIdmappings();
    if (!
$ret) {
        return 
false;
    }

    
$sql "SELECT count(*) AS ucount FROM ".$user_prefix."_users";
    
$user_count $db->sql_fetchrow($db->sql_query($sql));
    
$nextpage 0;

    for(
$i $_GET['start']; $i $user_count['ucount']; $i++) {
        if(
$i == $_GET['start']+100) {
            
$nextpage 1;
            break;
        }

        
// Export all phpnuke users (except anonymous) to G2 defaut group if non existant
        
$query='SELECT user_id, name, username, user_password, user_email, user_lang, user_regdate FROM '.$user_prefix."_users WHERE user_id = $i LIMIT 1";
        
$result=$db->sql_query($query);
        if(
$db->sql_numrows($result) != 0) {
            
$sqluserdata $db->sql_fetchrow($result);

            
$nukeuser_id         $sqluserdata['user_id'];
            
$nukeuser_name        $sqluserdata['name'];
            
$nukeuser_cryptpass    $sqluserdata['user_password'];
            
$nukeuser_uname        $sqluserdata['username'];
            
$nukeuser_email        $sqluserdata['user_email'];
            
$nukeuser_lang        $sqluserdata['user_lang'];
            
$g2nukeuser_lang     $Phpnuke2G2Lang[$nukeuser_lang];
            
$nukeuser_regdate    $sqluserdata['user_regdate'];
            list( 
$regmonth$regday$regyear ) = split" "$nukeuser_regdate );
            
$regphpusertimestamp mktime000$regmonth$regday$regyear );

            
// TODO: if the map exists, just update the user data
            
if (isset ($mapsbyexternalid[$nukeuser_id])) {
                
$outputtext .= $nukeuser_uname.' (this user already exists in g2)<br/>';
            }
            else {
                
// Get Arguments for the new user:
                
$args['fullname']      =    $nukeuser_name;
                
$args['name']        =    $nukeuser_uname;
                
$args['username']     =     $nukeuser_uname;
                
$args['hashedpassword'] =    $nukeuser_cryptpass
                
$args['hashmethod'] =     'md5';
                
$args['email']         =    $nukeuser_email;
                
$args['language']    =    $g2nukeuser_lang;
                
$args['creationtimestamp']    =    $regphpusertimestamp;
                
$ret GalleryEmbed :: createUser($nukeuser_id$args);
                if (!
$ret->isSuccess()) {
                    
g2_message('Failed to create G2 user with extId ['.$nukeuser_id.']. Here is the error message from G2: <br />'.$ret->getAsHtml());
                    return 
false;
                }
                if (!
g2addexternalMapEntry($nukeuser_uname$nukeuser_id0)) {
                    return 
false;
                }
                else {
                    
$outputtext .= $nukeuser_uname.' (added to g2 users)<br/>';
                }             
            }
        }
    }
    if(
$nextpage == 1) {
        
$outputtext = ($i-2)." users imported...";
        
// need the proper refresh code here....
    
}

    
g2_message($outputtext );
    return 
false;
    return 
true;
?>

note that i haven't gotten the refresh code to work yet.

also, you'll need this code in DisplayMainPage:
PHP: › <?php // -------------- group settings
    
$hidden_input "<input type=\"hidden\" name=\"start\" value=\"2\">";
    
$value _G2USEREXPORT;
    
OpenTable();
    echo 
"<center><font class=\"option\"><b>Export Users to Gallery2</b></font></center><br/>";
    echo 
"$notice<form action=\"admin.php\" method=\"get\">"."<center><table border=\"0\" width=\"100%\">";
    echo 
"<input type=\"hidden\" name=\"op\" value=\"gallery2_user_export\">"."<tr><td align=\"center\"><input type=\"submit\" value=\"$value\">$hidden_input</td></tr>"."</table></center></form>";
    
CloseTable(); ?>

it's essentially the same as what you've got, but tweaked the form method and added in the start value.
Back to top
Offline View user's profile Send private message Visit poster's website
drumicube

Beginner
Beginner


Joined: Oct 11, 2004
Posts: 3

PostPosted: Mon Apr 04, 2005 2:56 pm    Post subject: Re: Gallery2 Integration Development Reply with quote

Thanks to your help, i managed to finish a fully working version.
As you can notice the code had changed from the function you started of, it will also update user now, and the multiple pass by page is working fine.

Code: ›
/*********************************************************/
/* Init G2 API                                           */
/* Exports phpnuke users to g2 and                       */
/* Initial user/group management synchronization.        */
/* Output: False if error
/*         user info text to display if success               */
/*********************************************************/

define("NB_USER_TO_EXPORT_BY_PASS", 3);

function g2_phpnukeTog2UserExport()
{
   global $db, $user_prefix,$Phpnuke2G2Lang;   
   
   // init G2 transaction, load G2 API, if not already done so
   if (!init())
   {
      return false;
   }

   // Load all existing phpnuke <-> G2 mappings
   list ($ret, $mapsbyentityid, $mapsbyexternalid) = g2getallexternalIdmappings();
   if (!$ret)
   {
      return false;
   }
   
   // Map the ExternalmapId "admin" to the last phpnuke admin account found
   // TODO: Mapping for multiple admins

   list ($ret, $adminGroupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
   if ($ret->isError())
   {
      g2_message('Enable to fetch the admin group. Here is the error message from G2: <br />'.$ret->getAsHtml());
       return false;
   }
   list ($ret, $adminList) = GalleryCoreApi::fetchUsersForGroup($adminGroupId, 5);
   if ($ret->isError())
   {
      g2_message('Enable to fetch a member in the admin group. Here is the error message from G2: <br />'.$ret->getAsHtml());
       return false;
   }
   
   foreach ($adminList as $adminId => $adminName)
   {
   }
   
   if (!isset ($mapsbyexternalid["admin"]))
   {
      if (!g2addexternalMapEntry("admin", $adminId, 0))
      {
          return false;
      }
      
      $outputtext .="Admin account create<br/><br/>";
   }
   
   // TODO: Update of the admin account if it already exists
         
   // Export all standard phpnuke users (except anonymous: id=1) to G2 defaut group
   // --- dari addon (multiple pass)
   $sql = "SELECT count(*) AS ucount FROM ".$user_prefix."_users";
   $user_count = $db->sql_fetchrow($db->sql_query($sql));
   $nextpage = 0;
   
   $startuser = $_POST['startuser'];
   
  for($i = $startuser; $i <= $user_count['ucount']; $i++)
  {
     
    if($i == $startuser+NB_USER_TO_EXPORT_BY_PASS)
    {
        $nextpage = 1;
        break;
      }
      
      $outputtext .= "UserId($i) ";

      $query='SELECT user_id, name, username, user_password, user_email, user_lang, user_regdate FROM '.$user_prefix."_users WHERE user_id = $i LIMIT 1";
      
      $result=$db->sql_query($query);
      
      if($db->sql_numrows($result) != 0)
      {
         $sqluserdata      = $db->sql_fetchrow($result);
         $nukeuser_id       = $sqluserdata['user_id'];
         $nukeuser_uname      = $sqluserdata['username'];
         $nukeuser_name      = $sqluserdata['name'];
         $nukeuser_cryptpass   = $sqluserdata['user_password'];
         $nukeuser_email      = $sqluserdata['user_email'];
         $nukeuser_lang      = $sqluserdata['user_lang'];
         $g2nukeuser_lang    = $Phpnuke2G2Lang[$nukeuser_lang];
         $nukeuser_regdate   = $sqluserdata['user_regdate'];
         
         list( $regmonth, $regday, $regyear ) = split( " ", $nukeuser_regdate );
         $regphpusertimestamp = mktime( 0, 0, 0, $regmonth, $regday, $regyear );
   
         // Get Arguments for the new user:
         $args['fullname']     =   $nukeuser_name;
         $args['username']    =    $nukeuser_uname;
         $args['hashedpassword'] =   $nukeuser_cryptpass;
         $args['hashmethod'] =    'md5';
         $args['email']       =   $nukeuser_email;
         $args['language']   =   $g2nukeuser_lang;
         $args['creationtimestamp']   =   $regphpusertimestamp;
         
         // if the map exists, just update the user data
         if (isset ($mapsbyexternalid[$nukeuser_id]))
         {
            $ret = GalleryEmbed :: updateUser($nukeuser_id, $args);
            if (!$ret->isSuccess())
            {
               g2_message('Failed to update G2 user with extId ['.$nukeuser_id.']. Here is the error message from G2: <br />'.$ret->getAsHtml());
               return false;
            }
            else
            {
               $outputtext .= $nukeuser_uname.' (has been updated)<br/>';
            }
         }
         //  else we create the user
         else
         {
            $ret = GalleryEmbed :: createUser($nukeuser_id, $args);
            if (!$ret->isSuccess())
            {
               g2_message('Failed to create G2 user with extId ['.$nukeuser_id.']. Here is the error message from G2: <br />'.$ret->getAsHtml());
               return false;
            }
            
            if (!g2addexternalMapEntry($nukeuser_uname, $nukeuser_id, 0))
            {
                 return false;
            }
            else
            {
               $outputtext .= $nukeuser_uname.' (added to g2 users)<br/>';
            }          
         }
      }
   }
   
   $outputtext .= "<br/>".($i-$startuser)." users imported...<br/><br/>";
   
   // Eveything is ok till now, so ask for the next page if needed

  if($nextpage == 1)
  {
      $startUserNextPage = "<input type=\"hidden\" name=\"startuser\" value=\"$i\">";
         $outputtext .="<form action=\"admin.php\" method=\"post\">"."<table border=\"0\">";
         $outputtext .="<input type=\"hidden\" name=\"op\" value=\"gallery2_user_export\">"."<tr><td><input type=\"submit\" value=\""._G2_NEXT_PAGE."\">$startUserNextPage</td></tr>"."</table></form>";
  }
  else
  {
        $outputtext .= _USER_EXPORT_COMPLETED."<br/>";
  }
   
   return $outputtext;

}


I don't release it today as it has to be checked seriously, it will be ok tomorrow i hope !

Anyway, Thanks for your help !
Back to top
Offline View user's profile Send private message
anylinux

Beginner
Beginner


Joined: Dec 27, 2010
Posts: 2

PostPosted: Mon Dec 27, 2010 5:40 am    Post subject: Re: Gallery2 Integration Development Reply with quote

I have a first working code for the user creation on the fly !
See it on G2 dev forum...
Regards,
php web development from india [anylinuxwork.com]
Back to top
Offline View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NukedGallery.net Forum Index » PHP-Nuke Integration » Gallery 2 Integration View previous topicPrinter friendly versionView next topic

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours

Powered by phpBB © phpBB Group



Sponsors: Dedicated ServersDomain NamesWeb HostingDomain Name RegistrationDedicated Web HostingWeb Design New YorkCompare VoIPseo packagesSEO CompanyNew York Yellow PagesFind LocationsVOIP Phone ServiceNeckermannBluetooth HeadsetOnline internetSEOchina factoryDressesRestaurant Locatorandroid tablet

8th year online! 2003-2011
Legal • Use of this site consitutes agreement to the Acceptable Use Policy
Hosted by Implosion WorksSourceForge.net Logo • Theme by TonicMedia