fkelly
Former Moderator in Good Standing
Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY
|
Posted:
Tue Nov 18, 2008 8:20 am |
|
In this thread
Only registered users can see links on this board! Get registered or login!
I posted a fix for problems interfacing RN2.3 to Gallery2. That fix is now deprecated and you should take any fixes from this thread instead. I am posting here the full code for header.php and the index.php of the /modules/gallery2 directory to make it easier.
Edit November 19: see note at bottom of this post and refresh your files if you have downloaded from here before this.
The original problem was caused by the fact that the integration (from nukedgallery.net) index.php relied on parsing the header.php of a given *nuke distribution and looking for a "<header" string. In RN 2.30 this string was moved to mimetype.php in the /includes directory. The result was that Gallery2 css and js files never got included.
After "fiddling" with several alternative solutions, including parsing mimetype it occurred to me that the basic approach being taken in the integration index.php was flawed ... or at least that it could be vastly simplified if we just made a couple of simple adjustments to the RN distribution's header.php. The code here has only been tested with RN 2.3 and that's all I have an interest in testing but, in principal it should work with any *nuke distribution if you make the appropriate adjustments to your header.php.
To implement:
1. Make a backup of your /header.php and /modules/gallery2/index.php that you got from the nukedgallery integration package.
2. Copy the code posted here to the appropriate locations on your site using whatever means are at your disposal including a good editor and an FTP program or the like.
3. Test.
If you are not running Gallery2 you don't need to do any of this.
Here is the new header.php:
Code:<?php
/************************************************************************/
/* PHP-NUKE: Advanced Content Management System */
/* ============================================ */
/* */
/* Copyright (c) 2002 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
/************************************************************************/
/* Additional code clean-up, performance enhancements, and W3C and */
/* XHTML compliance fixes by Raven and Montego. */
/************************************************************************/
if (stristr(htmlentities($_SERVER['PHP_SELF']) , 'header.php')) {
Header('Location: index.php');
die();
}
if (!defined('NUKE_HEADER')) define('NUKE_HEADER', true);
require_once 'mainfile.php';
//GT-NExtGEn 0.4/0.5 by Bill Murrin (Audioslaved) http://gt.audioslaved.com (c) 2004
//Modified by montego from http://montegoscripts.com for TegoNuke(tm) ShortLinks
global $tnsl_bUseShortLinks, $tnsl_bAutoTapBlocks, $tnsl_bAutoTapLinks, $tnsl_bDebugShortLinks, $tnsl_sGTFilePath;
if (defined('TNSL_USE_SHORTLINKS')) {
$GLOBALS['tnsl_asGTFilePath'] = tnsl_fPageTapStart();
}
/*
* Include some common header for HTML generation
*/
function head() {
global $slogan, $sitename, $banners, $nukeurl, $Version_Num, $artpage, $topic, $hlpfile, $user, $hr, $theme, $cookie, $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $textcolor1, $textcolor2, $forumpage, $adminpage, $userpage, $pagetitle;
$ThemeSel = get_theme();
// Meta tags cannot be used because they are resolved after the headers are sent - Mantis issue 0000925
// This will allow everything to function as it has been which is acceptable and still allows for future enhancements
if (file_exists('includes/mimetype.php')) include('includes/mimetype.php');
elseif (file_exists('../includes/mimetype.php')) include('../includes/mimetype.php');
else {
header('Content-Type: ' . _MIME . ';charset=' . _CHARSET);
header('Vary: Accept');
/***echo '<?xml version="1.0" encoding="' . _MIME . '"?>';***/
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml" lang="en">', "\n";
echo '<head>', "\n";
}
include_once 'themes/' . $ThemeSel . '/theme.php';
// Tolerant baseURL Hack - VinDSL (Lenon.com)
global $name;
$base_url = $_SERVER['HTTP_HOST'];
//echo '<base href="http://' . $base_url . '/" />';
// Tolerant baseURL Hack - VinDSL (Lenon.com)
//If Dynamic Titles are turned on, use them, otherwise, use default PHP-Nuke page titles
global $useDynamicTitles;
if (isset($useDynamicTitles) && $useDynamicTitles && file_exists(INCLUDE_PATH . 'includes/dynamic_titles.php')) {
include_once INCLUDE_PATH . 'includes/dynamic_titles.php';
} else {
echo '<title>', $sitename, ' ', $pagetitle, '</title>', "\n";
}
//End of Dynamic Titles changes
include_once 'includes/meta.php';
include_once 'includes/javascript.php';
if (defined('G2HEADER_CSS_JS')) {
echo "\n". G2HEADER_CSS_JS;
}
if (file_exists('themes/' . $ThemeSel . '/images/favicon.ico')) {
echo '<link rel="shortcut icon" href="themes/', $ThemeSel, '/images/favicon.ico" type="image/x-icon" />', "\n";
}
echo '<link rel="StyleSheet" href="themes/ravennuke.css" type="text/css" />', "\n";
echo '<link rel="StyleSheet" href="themes/', $ThemeSel, '/style/style.css" type="text/css" />', "\n";
//
// Support custom CSS on a per-module basis (RN0000391)
// Module authors need to define RN_MODULE_CSS to name the external style sheet they want to load
// and we will add a link to their stylesheet file automatically.
//
if (defined('RN_MODULE_CSS')) {
$modCssFile = 'themes/' . $ThemeSel . '/style/' . RN_MODULE_CSS;
if (file_exists($modCssFile)) {
echo '<link rel="StyleSheet" href="', $modCssFile, '" type="text/css" />', "\n";
}
}
include_once 'includes/jquery/jquery.php';
include_once 'includes/tabcontent/tabcontent.php';
include_once 'includes/ajaxtabs/ajaxtabs.php';
include_once 'includes/custom_files/nukeSEO/nukePIEhdr.php';
include_once 'includes/custom_files/nukeSEO/nukeFEEDhdr.php';
if (file_exists('includes/custom_files/custom_head.php')) {
include_once 'includes/custom_files/custom_head.php';
}
echo "\n\n", '</head>', "\n";
if (file_exists('includes/custom_files/custom_header.php')) {
include_once 'includes/custom_files/custom_header.php';
}
global $ab_config;
if ($ab_config['site_switch'] == 1 && isset($_COOKIE['admin']) && is_admin($_COOKIE['admin'])) {
echo '<center><img src="images/nukesentinel/disabled.png" alt="' . _AB_SITEDISABLED . '" title="' . _AB_SITEDISABLED . '" border="0" /></center><br />';
}
if ($ab_config['disable_switch'] == 1 && isset($_COOKIE['admin']) && is_admin($_COOKIE['admin'])) {
echo '<center><img src="images/nukesentinel/inactive.png" alt="' . _AB_NSDISABLED . '" title="' . _AB_NSDISABLED . '" border="0" /></center><br />';
}
if ($ab_config['test_switch'] == 1 && isset($_COOKIE['admin']) && is_admin($_COOKIE['admin'])) {
echo '<center><img src="images/nukesentinel/testmode.png" alt="' . _AB_TESTMODE . '" title="' . _AB_TESTMODE . '" border="0" /></center><br />';
}
themeheader();
}
online();
head();
include_once 'includes/counter.php';
if (defined('HOME_FILE')) {
message_box();
blocks('Center');
}
?>
|
Here is the new /modules/gallery2/index.php
Code:<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2006 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* Gallery 2 index page for PHPNuke.
* @version $Revision: 15219 $ $Date: 2006-11-17 14:49:54 +0100 (Fri, 17 Nov 2006) $
* @author Dariush Molavi <dari@nukedgallery.net>
* This version revised November 2008 by fkelly at ravenphpscripts to be compatible with Ravennuke 2.3
* It has only been tested with RN 2.3 but the approach might be applicable to all *nuke releases
* Instead of parsing header.php it requires changes to header.php to include the css and js files
* the variable g2header_css_js is prepared in this program
*/
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {
die ("You can't access this file directly...");
}
/*********************************************************/
/* Standalone Message Function */
/*********************************************************/
function g2_message($mess) {
global $admin, $bgcolor2, $module_name, $admin_file;
include ("header.php");
OpenTable();
echo "<br><center><a href=\"".$admin_file.".php?op=gallery2\">".
"<img alt='Gallery::your photos on your website' src='modules/$module_name/images/g2.png' border=0></a><H3>Gallery2 Module Administration</H3>".
"<br/><a href=\"".$admin_file.".php?op=gallery2\">Return Home</center>";
CloseTable();
echo "<br/>";
OpenTable();
echo "<center><font class=\"option\">";
echo $mess;
echo "</font></center>";
CloseTable();
include ("footer.php");
}
function checkVersion() {
global $db, $prefix;
$config_sql = "SELECT embedVersion FROM ".$prefix."_g2config";
$config_result = $db->sql_query($config_sql);
list($embedVersion) = $db->sql_fetchrow($config_result);
$current_version = explode('.', $embedVersion);
$minor_revision = (int) $current_version[2];
$errno = 0;
$errstr = $version_info = '';
if ($fsock = @fsockopen('nukedgallery.sourceforge.net', 80, $errno, $errstr, 10)) {
@fputs($fsock, "GET /upgrade.txt HTTP/1.1\r\n");
@fputs($fsock, "HOST: nukedgallery.sourceforge.net\r\n");
@fputs($fsock, "Connection: close\r\n\r\n");
$get_info = false;
while (!@feof($fsock)) {
if ($get_info) {
$version_info .= @fread($fsock, 1024);
}
else {
if (@fgets($fsock, 1024) == "\r\n") {
$get_info = true;
}
}
}
@fclose($fsock);
$version_info = explode("\n", $version_info);
$latest_head_revision = (int) $version_info[0];
$latest_minor_revision = (int) $version_info[2];
$latest_version = (int) $version_info[0] . '.' . (int) $version_info[1] . '.' . (int) $version_info[2];
// UPDATE ME WHEN CHANGING MAJOR REV
if ($latest_head_revision == 0 && $minor_revision == $latest_minor_revision) {
return;
}
else {
$version_text = '<center><p style="color:red">Your integration package is <b>not</b> up to date.';
$version_text .= '<br />Latest version available is <b>' . $latest_version . '</b>. Your installed version is <b>' . $embedVersion . '</b><br />';
$version_text .= 'To see what has changed, read the ChangeLog here: <a href="http://www.nukedgallery.net/postp10252.html#10252">http://www.nukedgallery.net/postp10252.html#10252</a>.<br />';
$version_text .= 'You can download the latest integration package from <a href="http://www.nukedgallery.net/downloads-cat11.html">http://www.nukedgallery.net/downloads-cat11.html</a>.</p></center>';
}
}
else {
if ($errstr) {
$version_text .= '<p style="color:red">Socket connection error: ' . $errstr . '</p></center>';
}
else {
$version_text .= '<p>PHP socket functions have been disabled.</p></center>';
}
}
return $version_text;
}
// --------------------------------------------------------
// Mapping between Phpnuke and Gallery2 language definition
// --------------------------------------------------------
$phpnuke2G2Lang = array('danish' => 'da','dutch' => 'nl','german' => 'de','greek' => 'el','english' => 'en','american' => 'en','spanish' => 'es','finnish' => 'fi','french' => 'fr','irish' => 'ga','italian' => 'it','japanese' => 'ja','norwegian' => 'no','polish' => 'pl','portuguese' => 'pt','swedish' => 'sv','chinese' => 'zh');
global $currentlang, $g2bodyHtml, $db, $user_prefix, $prefix, $g2moddata;
if(!defined('NUKE_EVO')) {
require_once("mainfile.php");
}
else {
$evo_version = explode('.',NUKE_EVO);
if(intval($evo_version[0]) < 1) {
require_once("mainfile.php");
}
}
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
if (is_admin($admin)) {
// we log as an admin
$uid='admin';
$updateCheck = checkVersion();
}
else {
if (is_user($user)) {
// we log as a normal user
cookiedecode($user);
$uid='';
if (is_user($user)) {
$uid = $cookie[0];
}
}
}
if (empty($g2moddata)) {
$config_sql = "SELECT * FROM ".$prefix."_g2config";
$config_result = $db->sql_query($config_sql);
list($embedUri, $g2Uri, $activeUserId, $cookiepath, $showSidebar, $g2configurationDone, $embedVersion) = $db->sql_fetchrow($config_result);
if ($g2configurationDone == 0){
include "header.php";
OpenTable();
echo "<center>"._G2_CONFIGURATION_NOT_DONE."</center>";
CloseTable();
include("footer.php");
return;
}
require_once('embed.php');
$g2currentlang = $phpnuke2G2Lang[$currentlang];
$ret = GalleryEmbed::init(array('embedUri' => $embedUri,'g2Uri' => $g2Uri, 'activeUserId' => "$uid",'activeLanguage' =>$g2currentlang));
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, map create G2 user now
$query='SELECT user_id, name, username, user_password, user_email, user_lang, user_regdate FROM '.$user_prefix."_users WHERE `user_id`='".$uid."'";
$result=$db->sql_query($query);
$sqluserdata = $db->sql_fetchrow($result);
$nukeuser_regdate = $sqluserdata['user_regdate'];
$nukeuser_lang = $sqluserdata['user_lang'];
// Get Arguments for the new user:
$args = array('fullname'=> $sqluserdata['username'], 'username'=> $sqluserdata['username'], 'hashedpassword'=> $sqluserdata['user_password'], 'hashmethod'=> 'md5' , 'email'=> $sqluserdata['user_email'] , 'language' => $phpnuke2G2Lang[$nukeuser_lang], 'creationtimestamp'=> strtotime($nukeuser_regdate));
$retcreate = GalleryEmbed::createUser($sqluserdata['user_id'], $args);
if ($retcreate) {
list($ret,$user) = GalleryCoreApi::fetchUserByUsername($sqluserdata['username']);
$g2userId = $user->getId();
if(!GalleryEmbed::addExternalIdMapEntry($sqluserdata['user_id'], $g2userId, "GalleryUser")) {
echo 'Sorry, but your the following PHPNuke user could not be imported to Gallery 2:<br> '.$nukeuser_uname.'.<p> Here is the error message from G2: <br />'.$retcreate->getAsHtml();
}
}
// Full G2 reinit with the new created user
$ret = GalleryEmbed :: init(array ('embedUri' => $embedUri, 'g2Uri' => $g2Uri, 'activeUserId' => "$uid", 'activeLanguage' => $g2currentlang, 'fullInit' => 'true'));
}
else {
echo 'G2 did not return a success status. Here is the error message from G2: <br />'.$ret->getAsHtml();
}
}
else {
echo 'G2 did not return a success status. Here is the error message from G2: <br />'.$ret->getAsHtml();
}
}
// handle the G2 request
if ($showSidebar) {
GalleryCapabilities::set('showSidebarBlocks', true);
$g2moddata = GalleryEmbed::handleRequest();
if (isset($g2moddata['sidebarBlocksHtml']) && !empty($g2moddata['sidebarBlocksHtml'])) {
$g2bodyHtml = '<div id="gsSidebar" class = "gcBorder1">' . join('', $g2moddata['sidebarBlocksHtml']) . '</div>';
}
}
else {
GalleryCapabilities::set('showSidebarBlocks', false);
$g2moddata = GalleryEmbed::handleRequest();
}
// G2 Header hacking (contribution from dmolavi)
// get the page title, javascript and css links from the <head> html from G2
$title = ''; $javascript = array(); $css = array();
if (isset($g2moddata['headHtml'])) {
list($title, $css, $javascript) = GalleryEmbed::parseHead($g2moddata['headHtml']);
}
if($title != "") {
$pagetitle = "» ".trim($title);
}
$g2header_css_js = '';
foreach($css as $stylesheet) {
$g2header_css_js .= $stylesheet . "\n";
}
foreach($javascript as $script) {
$g2header_css_js .= $script. "\n";
}
if (!empty($g2header_css_js)) {
DEFINE ('G2HEADER_CSS_JS', $g2header_css_js);
}
// show error message if isDone is not defined
if (!isset($g2moddata['isDone'])) {
echo 'isDone is not defined, something very bad must have happened.';
exit;
}
// die if it was a binary data (image) request
if ($g2moddata['isDone']) {
exit; // uploads module does this too
}
// Main G2 error message
if ($ret) {
echo $ret->getAsHtml();
}
$g2bodyHtml = $updateCheck;
$g2bodyHtml .= $g2moddata['bodyHtml'];
}
include('header.php');
OpenTable();
echo $g2bodyHtml;
CloseTable();
include('footer.php');
?>
|
Note: I have made several adjustments since I posted the code in the thread listed at the top of this post. I eliminated several unnecessary variable assignments and one global statement and did a couple of double quote to single quote conversions. I also changed the variable that was used for communicating between index.php and header.php from $rn_header to $g2header_css_js ... I think that's more explanatory to anyone looking in header.php for what's going on. I also added a comment to the index.php.
Edit: November 19 ... based on a suggestion from Mr. M. I have eliminated the variable $g2header_css_js from header.php and only use it for accumulating the css and js info in index.php. Then a constant is defined with the css and js info in it and used in header.php. This eliminates the security risk of a variable injection. If you have downloaded these files before this please redo it to protect yourself. |
|
|