Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-25-2012, 04:36 AM
rjerina rjerina is offline
 
Join Date: Jan 2004
Location: Cleveland, OH
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Help integrating Menalto Gallery2 with VB4

I am trying to integrate gallery2 with vb4. The guides out there are for vb3.x so I want to try to adapt it with vb4. I tried it the vb3 way, which seemed to be missing some of my navbit just below the header.

Anyways...

I am using the custom page mod as kind of a guide to get this done as they seem somewhat similar.

My code for gallery.php is:

Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'gallery'); // change this depending on your filename
define('CSRF_PROTECTION', true);

// ################### 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(
'gallery2',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################

require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits = array();
$navbits[$parent] = 'Gallery';
error_reporting(E_ALL );

$navbits = construct_navbits($navbits);
$navbar = render_navbar_template($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 $vbulletin, $userinfo;
require_once('/data/www/mywebsite.net/gallery/embed.php');

$data = array();

// If it's an anonymous user, set the g2 activeUser to null
$uid = $vbulletin->userinfo['userid'] = 0 ? '' : $vbulletin->userinfo['userid'];

// initiate G2
// You need to edit the following 4 lines to suit your VB3 & G2 installations
// This is set up for an install that looks like:
// public_html/VB/<vb files>
// public_html/gallery2/<gallery2 files>
// and also setup for a VB3 template 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... Like if you've changed it
// to forums.php or something of the like.

$ret = GalleryEmbed::init(array('embedUri' => '/gallery.php',
'g2Uri' => 'http://www.mywebsite.net/gallery/',
'loginRedirect' => 'index.php',
'activeUserId' => $uid));
if ($ret)
{
if ($ret->getErrorCode() & ERROR_MISSING_OBJECT)
{
// Check if there's no G2 user mapped to the activeUserId
$ret = GalleryEmbed::isExternalIdMapped($uid, 'GalleryUser');
if ($ret && ($ret->getErrorCode() & ERROR_MISSING_OBJECT))
{
// User not mapped, create G2 user now
// Get Arguments for the new user:
$args['fullname'] = $vbulletin->userinfo['username'];
$args['username'] = $vbulletin->userinfo['username'];
$args['hashedpassword'] = $vbulletin->userinfo['password'];
$args['hashmethod'] = 'md5';
$args['email'] = $vbulletin->userinfo['email'];
$args['language'] = $vbulletin->userinfo['lang_code'];
$args['creationtimestamp'] = $vbulletin->userinfo['joindate'];

$retcreate = GalleryEmbed :: createUser($uid, $args);
if ($retcreate)
{
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) {
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') . '");');

?>
gallery2 template is

Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - Gallery</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    
    {vb:raw header}
    
    {vb:raw navbar}

<div class="blockbody">
<div class="blockrow">$data[bodyHtml]</div>
</div>
    {vb:raw footer}
</body>
</html>
500 server error message from apache logs:

Code:
[Wed Apr 25 01:19:05 2012] [error] [client *.*.*.*] PHP Parse error:  syntax error, unexpected T_STRING in /data/www/mywebsite.net/gallery.php(168) : eval()'d code on line 1
My PHP experience is limited. I've made basic stuff before with the help of Google and whatnot. vBulletin experience is a bit more in depth, but not too much on the programming side of things. Any help or guidance would be appreciated
Reply With Quote
  #2  
Old 05-01-2012, 08:11 AM
rjerina rjerina is offline
 
Join Date: Jan 2004
Location: Cleveland, OH
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Again any help is appreciated! I realized I forgot to add the code that they had for vb3. It seems to work, but like a said a few things appear to be missing (navbar tabs) so I am not sure if it needs converted to how vb4 does it, or if I am just missing something obvious.

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>
Reply With Quote
  #3  
Old 05-01-2012, 09:49 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

At the end, instead of the eval(print_output(... line, try:

Code:
$templater = vB_Template::create('gallery2');
$templater->register_page_templates();
$templater->register('bodyHtml', $data['bodyHtml']);
print_output($templater->render());

and then in the gallery2 template, change $data[bodyHtml] to {vb:raw bodyHtml}
Reply With Quote
  #4  
Old 05-01-2012, 10:38 AM
setishock setishock is offline
 
Join Date: Feb 2008
Location: Houma, La.
Posts: 1,177
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Gallery3 is a far superior version to use. I use it on my site for all the picture goodies. But as for integration, I've had no luck. If you get it to work I'd really like to see it.
Reply With Quote
  #5  
Old 05-01-2012, 10:58 AM
rjerina rjerina is offline
 
Join Date: Jan 2004
Location: Cleveland, OH
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by setishock View Post
Gallery3 is a far superior version to use. I use it on my site for all the picture goodies. But as for integration, I've had no luck. If you get it to work I'd really like to see it.
I would love to use Gallery3, but I need users to be able to upload images to it flawlessly. There are a few older people on the forum, some not so computer savvy. Having them sign up for both would just be a support nightmare

--------------- Added [DATE]1335874190[/DATE] at [TIME]1335874190[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
At the end, instead of the eval(print_output(... line, try:

Code:
$templater = vB_Template::create('gallery2');
$templater->register_page_templates();
$templater->register('bodyHtml', $data['bodyHtml']);
print_output($templater->render());

and then in the gallery2 template, change $data[bodyHtml] to {vb:raw bodyHtml}
Thanks! That got rid of the internal server error. It seems to manhandle the gallery though and completely removes all the formatting from it. I'm trying to read up on vB_Template to see if I can figure that out...

Then I imagine the other problem I will still have (that I found earlier with using the vb3 method, but didn't mention) is when I upload a photo through it, it gives me a message about the missing security token. Looks like this isn't going to be as easy as I thought.
Reply With Quote
  #6  
Old 05-01-2012, 01:17 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rjerina View Post
it gives me a message about the missing security token.
If you have a form that posts data, you need to include the security token value as a hidden field in the form data. Or, I think you can put define('CSRF_PROTECTION', false); at the top of your php file (somewhere before global.php in included).
Reply With Quote
  #7  
Old 05-01-2012, 01:48 PM
rjerina rjerina is offline
 
Join Date: Jan 2004
Location: Cleveland, OH
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
If you have a form that posts data, you need to include the security token value as a hidden field in the form data. Or, I think you can put define('CSRF_PROTECTION', false); at the top of your php file (somewhere before global.php in included).
Thanks! That fixed that problem!

Now to figure out why the gallery is all mangled. Again I appreciate it!

--------------- Added [DATE]1335884902[/DATE] at [TIME]1335884902[/TIME] ---------------

I also just noticed the nav bar tabs still are not showing up. haha what a mess this seems to be. I'll have to mess with it some more when I have some time.
Reply With Quote
  #8  
Old 05-02-2012, 01:24 AM
rjerina rjerina is offline
 
Join Date: Jan 2004
Location: Cleveland, OH
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by rjerina View Post
I also just noticed the nav bar tabs still are not showing up. haha what a mess this seems to be. I'll have to mess with it some more when I have some time.
Fixed that! Needed to put the navbar through the $templater. I'm learnin!

I just can't figure out why running that template through stripped all the formatting. For instance, using the vb3 style way looked like the first screen shot. vb4 style is the 2nd. Maybe I'm missing something like another variable. Figured I would upload some screenshots in case something jumps out at someone.

gallery2 css getting stripped out?

edit:

I got it! haha just messing around. Added the following to gallery.php:

Code:
$templater->register('headHtml', $data['headHtml']);
Then added {vb:raw headHtml} into the <head> in the template. Should be okay now I hope. I'll be testing it for sure.

Thanks for all the help once again.
Attached Images
File Type: jpg gallery-vb3-style.jpg (67.5 KB, 0 views)
File Type: jpg gallery-vb4-style.jpg (85.6 KB, 0 views)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:56 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07407 seconds
  • Memory Usage 2,275KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (2)postbit_attachment
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete