Back to vBulletin 3 Articles

Menalto's G2 integration into VB3
by whodah 24 Apr 2005

NOTE: Development for G2.1 and vB 3.5 is on this page: Gallery 2.1 and vBulletin 3.5.X integration

I was about to post this on Menalto's site until i realized that I'd be publicly posting VB3's code... A no-no!!! heh!

So, I'll post the instructions here, and then refer people to this post on how to do it! (obviously they'll have to log on w/ their licensed account to see it)

Ok, here's how to integrate menalto's G2 gallery into VB3.

Menalto's gallery is sweet.
Menalto's gallery is free.
Menalto's gallery is here: http://gallery.menalto.com/index.php



This works on my system of vBulletin 3.0.7 and Gallery 2 Holy Hand Grenade.

Known issues: VB3 has a http://www.vbulletin.com/forum/index.php?t=137036. Thus, this script pushes the users's password plus salt from VB3 into
G2. The outcome - the standalone G2 passwords will not match *just* the user's
password! There is talks of looking into salt'ing in the future w/ G2
integration, but that's the dealio as of this integration technique... If you
are using G2 as 'embedded only', then game on, no worries. If not, then your
users will need to log on through the VB3 install to setup their session, then
can visit the G2 standalone if they wish...

Step 1 - create a new file named 'gallery2.php' as per this thread:
How to create your own vBulletin-powered page! (uses vB templates)
(thx Gary King!!!)

in that thread, the first box (the gallery2.php file), the contents will be (this is the section that contains the G2 embeded code which is available on Menalto's site... i'll update this thread w/ direct links once it's in place! *only* the G2 code is on their site, no VB3 code in accordance w/ the VB license agreement! ):
Code:
<?php 
// ####################### SET PHP ENVIRONMENT ########################### 
error_reporting(E_ALL & ~E_NOTICE); 
// #################### DEFINE IMPORTANT CONSTANTS ####################### 
define('NO_REGISTER_GLOBALS', 1); 
define('THIS_SCRIPT', 'gallery2'); // change this depending on your filename 
// ################### PRE-CACHE TEMPLATES AND DATA ###################### 
// get special phrase groups 
$phrasegroups = array( 
); 
// get special data templates from the datastore 
$specialtemplates = array( 
); 
// pre-cache templates used by all actions 
$globaltemplates = array( 
    'galley2', 
); 
// pre-cache templates used by specific actions 
$actiontemplates = array( 
); 
// ######################### REQUIRE BACK-END ############################ 
require_once('./global.php'); 
// ####################################################################### 
// ######################## START MAIN SCRIPT ############################ 
// ####################################################################### 
$navbits = array(); 
$navbits[$parent] = 'Gallery G2'; 
$navbits = construct_navbits($navbits); 
eval('$navbar = "' . fetch_template('navbar') . '";'); 
// ####################################################################### 
// ###################### Begin G2 integration code ######################
// ####################################################################### 
$data = runGallery();
$data['title'] = (isset($data['title']) && !empty($data['title'])) ? $data['title'] : 'Gallery';
function runGallery() {
    global $bbuserinfo;
        require_once('../gallery2/embed.php');
        $data = array();
    // if anonymous user, set g2 activeUser to null
        $uid = $bbuserinfo['userid'] = 0 ? '' : $bbuserinfo['userid']; 
        // initiate G2 
        // you need to edit the following 4 lines to suite your VB3/G2 install!!!
        // this is setup for a install that looks like:
        //     public_html/VB/<vb files>
        //     public_html/gallery2/<gallery2 files>
        // and also setup for a VB3 tempalte name of 'gallery2'. if you have any
        // differences, make those changes here!
        // you might need to change 'loginRedirect' if you have your VB3 setup to 
        // where index.php is not the root page of VB3... i.e. if you've changed it
        // to forums.php or something of the like.
        $ret = GalleryEmbed::init(array('embedUri' => 'gallery2.php',
                    'embedPath' => '/VB',
                        'relativeG2Path' => '../gallery2',
                    'loginRedirect' => 'index.php',
                    'activeUserId' => $uid));
    if ($ret->isError()) 
        { 
           if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) 
           { 
             // check if there's no G2 user mapped to the activeUserId 
             $ret = GalleryEmbed::isExternalIdMapped($uid, 'GalleryUser'); 
             if ($ret->isError() && ($ret->getErrorCode() & ERROR_MISSING_OBJECT)) 
             { 
                 // user not mapped, map create G2 user now 
                 // Get Arguments for the new user: 
                 $args['fullname']     =   $bbuserinfo['username']; 
                 $args['username']    = $bbuserinfo['username']; 
                 $args['hashedpassword'] =   $bbuserinfo['password']; 
                 $args['hashmethod'] =    'md5'; 
                 $args['email']       =   $bbuserinfo['email']; 
                 $args['language']   =   $bbuserinfo['lang_code']; 
                 $args['creationtimestamp']   =   $bbuserinfo['joindate']; 
                 $retcreate = GalleryEmbed :: createUser($uid, $args); 
                 if (!$retcreate->isSuccess()) 
                 { 
                    echo '<HR>line: '.__LINE__.', Failed to create G2 user with extId ['.$uid.']. Here is the error message from G2: <br />'.$retcreate->getAsHtml(); 
                    return false; 
                 } 
                                $ret = GalleryEmbed::checkActiveUser($uid); 
                if ($ret->isError()) { 
                    print $ret->getAsHtml(); 
                    return false; 
                } 
             } 
             else 
             { 
                 echo '<HR>line: '.__LINE__.', G2 did not return a success status. Here is the error message from G2: <br />'.$ret->getAsHtml(); 
                      return false;
                         } 
         } 
         else 
         { 
                         echo '<HR>line: '.__LINE__.', G2 did not return a success status. Here is the error message from G2: <br />'.$ret->getAsHtml(); 
                  return false;
                 } 
       } 
    // user interface: disable sidebar in G2 and get it as separate HTML to put it into a block
    //GalleryCapabilities::set('showSidebar', false);
    // handle the G2 request
    $g2moddata = GalleryEmbed::handleRequest();
    // show error message if isDone is not defined
    if (!isset($g2moddata['isDone'])) {
      $data['bodyHtml'] = 'isDone is not defined, something very bad must have happened.';
      return $data;
    }
    // die if it was a binary data (image) request
    if ($g2moddata['isDone']) {
      exit; /* uploads module does this too */
    }
    // put the body html from G2 into the xaraya template 
    $data['bodyHtml'] = isset($g2moddata['bodyHtml']) ? $g2moddata['bodyHtml'] : '';
    // get the page title, javascript and css links from the <head> html from G2
    $title = ''; $javascript = array();    $css = array();
    if (isset($g2moddata['headHtml'])) {
      list($data['title'], $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
      $data['headHtml'] = $g2moddata['headHtml'];
    }
    /* Add G2 javascript  */
    if (!empty($javascript)) {
      foreach ($javascript as $script) {
         $data['javascript'] .= "\n".$script;
      }
    }
    /* Add G2 css  */
    if (!empty($css)) {
      foreach ($css as $style) {
         $data['css'] .= "\n".$style;
      }
    }
    // sidebar block
    if (isset($g2moddata['sidebarHtml']) && !empty($g2moddata['sidebarHtml'])) {
      $data['sidebarHtml'] = $g2moddata['sidebarHtml'];
    }
    return $data;
} 
// ####################################################################### 
// ####################### End G2 integration code #######################
// ####################################################################### 
eval('print_output("' . fetch_template('gallery2') . '");'); 
?>
in the above, you'll need to edit:
Code:
        $ret = GalleryEmbed::init(array('embedUri' => 'gallery2.php',
                    'embedPath' => '/VB',
                        'relativeG2Path' => '../gallery2',
                    'loginRedirect' => 'index.php',
                    'activeUserId' => $uid));
and
Code:
require_once('../gallery2/embed.php');
to suit your directory structure...

step 2 - creating the template
as per the same thread, How to create your own vBulletin-powered page! (uses vB templates) (2nd code box) create a template named 'gallery2' (no tics) and in it, place the following code:
Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
 <head>
  $headinclude
  $data[headHtml]
 </head>
 <body>
  $header
  $navbar
  <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
   <tr><td class="tcat">Gallery</td></tr>
   <tr><td class="alt1">$data[bodyHtml]</td></tr>
  </table>
  $footer
 </body>
</html>
that's it, enjoy!

oh, forgot to add!

in scouring the net, i've seen a couple of posts where people have offered to pay for this solution. if you are one of them, and are serious, then here's http://gallery.menalto.com/modules.php?op=modload&name=GalleryOldDocs&file=index&req=viewarticle&artid=30&donate_tag=gallery%20website

(nope, i'm not affiliated w/ them... if you wanna donate to me, then i'll redirect you to the donation link to the site that this is for: a non-profit saltwater aquariast club's site! )

edit 2006.01.11
links in navbar don't work w/ rewrite module enabled. you can enable them, but then need to 'hardcode' the links in your navbar templates and do one phrase adjustment. it's still 'dynamic' as the encoding involves vB variables and not your actual url... but a change none the less! see #41 in this thread:

Spoiler (click to open)


an update!

i'm running a nightly build (from June 2nd) w/ core: 0.9.22

this includes the new url rewrite module - which works!

i had to hardcode some links though as the gallery url rewrite takes over the vB relative links.

so i had to make the relative links 'static' in 1 template and hard code a phrase too...

the phrase i had to edit was:
private_messages_nav

from:
Code:
<a href="private.php?{3}">Private Messages</a>: {1}, {2}.
to:
Code:
<a href="http://www.domain.com/private.php?{3}">Private Messages</a>: {1}, {2}.
the template i had to edit was: navbar

and i changed all links that looked like:
Code:
<a href="profile.php?$session[sessionurl]do=editprofile">
to:
Code:
<a href="$vboptions[bburl]/profile.php?$session[sessionurl]do=editprofile">
basically added:
Code:
$vboptions[bburl]/
in front of all of the links in that page that actually go somewhere. (not the # links) there's like 20 of 'em.

you can also do random blocks and such. i'm not sure the cleanest way to do it... i've done it on our site, but it uses vbadvanced. basically, look in the gallery site admin under:
Blocks -> Random/Popular

and note the 'External Image Block' section.

at some point in yer code, you need to call a php variable to get yer random block. since we cannot do this directly from templates, we have to do it in one of the .php files and then reference the variable which introduces a level of difficulty. for instance, as that page indicates, the code:
Code:
<?php @readfile('http://www.cvreefers.org/gallery2.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=owner'); ?>
will generate a random image. as you cannot call php from our templates, i kinda kludged this together w/ vbadvanced's help.

you can then get real jiggy w/ it by calling those links in yer postbit (or postbit_legacy in our case) to produce things like each users latest album or each users random pic.

an example is here, note beneath the posters' avatar:
http://www.cvreefers.org/index.php?t=2614

however, each time u look up a random pic, i get a delay on a p4 3.06 w/ 1 gig of ram. so if u have 10 users browsing 17 posts w/ 10 random pic genreators at once... well... u get the idea. actually read that thread if you want to see the outcome...

so - i'm using a cron job and a hidden field to do the tricks on that page.

i hesitate to mention those above tricks because i know the first thing that's going to be asked is 'how did you do this?' and it's pretty entailed. to get the user's gallery links beneath each user involves naming an album identicle to that user, creating two hidden user profile fields, and setting up a cron job. for the daily random block, another hidden user profile field, and another cron job. i really doubt that i'm doing it 'the right way' nor the most eloquant nor the most effecient way. heck, i'm establishing my own mysql connection on those cron jobs and i'm sure i could mooch off of vB's connection if i researched how, heh! so i just wanted to show that it can be done if that makes sence! i'm sure someone more advanced then i could make it generically fit any vB install.

Close


can you put a 'user's gallery' link near the users' posts? yup, see post #65 in this thread:

Spoiler (click to open)


this is on vB 3.0.x

havn't moved to 3.5 yet.

this will add a link beneath the post count of the user.

however it might not work for your situation. all of my members' galleries are their vB username.

like my username is: whodah
my gallery name is: whodah

i have a user named: nifty_guy
his gallery name is: nifty_guy

u get the idea

i have a cron job that runs nightly (u can run it as often as u want of course) that checks usernames against g2 entities of the same name that are albums. if it exists, it populates a custom field in vB. if that field exists, a link to their album shows up in their posts.

so - u might have to tweak this accordingly, i'm not posting this as a cookie-cutter solution. but should getcha goin!



there are no file modifications with this. there is one file [i]addition[/b]. the rest can be done from the admin control panel.

this involves:
  1. adding a user custom field
  2. adding a Scheduled Task (adding a file and adding the task in vB's admin page)
  3. modifying one postbit template


1: adding a user custom field
in your admin pages, go to: User Profile Fields -> Add New User Profile Field

call it wahtever you want. i titled mine:
Title: Gallery
Description: Does this user have a gallery in CVR_Members? If so, what's the name of the gallery?

you need ot make:
Field Editable by User: No

the rest you can fill out however you want. note the field number it assigns it. if you need to review it, click:
User Profile Fields -> User Profile Field Manager

and the 'Name' column is what you need to make a note of. in my case, it's: field10

2: adding a Scheduled Task
create the file:
includes/cron/gallery_field10.php

(yes, u can name the file whatever you want, just make a note of it)

**note: in the file right below this, replace 'field10' with your field number!

and in it add:
Code:
<?php  
    $whodiag = 0;
		$whomysqlstring = "SELECT * FROM user;";
		if($whodiag) {echo "<BR>line ".__LINE__.": whomysqlstring = $whomysqlstring<BR>"; }
		$results = mysql_query($whomysqlstring) or die ("Error: line ".__LINE__.": $whomysqlstring<BR>");
  	while ($row = mysql_fetch_array($results)) {
  				$whomysqlstring = "SELECT * FROM g2_FileSystemEntity WHERE g_pathComponent='".$row[username]."';";
					if($whodiag) {echo "<BR>line ".__LINE__.": whomysqlstring = $whomysqlstring<BR>"; }
					$results2 = mysql_query($whomysqlstring) or die ("Error: line ".__LINE__.": $whomysqlstring<BR>");
					if(mysql_numrows($results2)) { 
									if($whodiag) {echo "<BR>line ".__LINE__.": Found an album for ".$row[username]."<BR>"; }
									while ($row2 = mysql_fetch_array($results2)) {
  											$whomysqlstring = "UPDATE userfield SET `field10` = '".$row2[g_pathComponent]."' WHERE userid = '".$row[userid]."';";
												if($whodiag) {echo "<BR>line ".__LINE__.": whomysqlstring = $whomysqlstring<BR>"; }
  			  							mysql_query($whomysqlstring) or die ("Error: line ".__LINE__.": $whomysqlstring<BR>");
									}
					}
		}		
?>
go to: Scheduled Tasks -> Add New Scheduled Task
call it:
Title: Gallery Profile Updater
Filename: ./includes/cron/gallery_field10.php
(unless u used a different Filename above... if so, change accordingly)
and run it as often as u want. i run mine nightly. thus if a new user gets a gallery, it won't reflect on their posts til the next day. so for mine, everything is a star except Hour which is:
Hour: 2

after yer done, go ahead and 'Run Now' it.

3: modifying one postbit template
ok, if yer in legacy mode, yer using:
postbit_legacy
if not, it's probably
postbit
(someone correct me if i'm wrong)

so - edit the template yer using. for me, it's postbit_legacy.

in postbit or postbit_legacy (we use legacy), find:
Code:
<div>
					$vbphrase[posts]: $post[posts]
				</div>
below it add:
Code:
				<if condition="$post['field10']">
						<div>
    						<a href="$vboptions[bburl]/v/CVR_members/$post[field10]/">$post[musername]'s Gallery</a>
								<if condition="$blockinfo['whodahuserrandompic']">
        								 <!--  -->
        								 <BR>Their Daily Random Pic:<BR>$post[field14]
    						</if>
						</div>
				</if>
and now u'll get a nifty little link below their posts saying:
whodah's gallery

or

nifty_guy's gallery

ggs!

Close


does it work in 3.5.x as a NON-plugin? yup, if you read through this post, you'll find tidbits here and there on what it takes to get it to work in 3.5.x

does it work in 3.5.x as a plugin? nope, not yet. nobody has coded it as a plugin as of this edit's date.
/edit 2006.01.11

vblts.ru supports vBulletin®, 2022-2024