View Full Version : Can someone help?
Mijae
01-31-2004, 04:12 AM
This should be easy for someone who knows some php...
Well, at my site, I currently run a gallery, I can't even call it a script, but it works.
<?
if(isset($page)){
if(is_file('/home/xxx/php/'.$page.'.php')) {
include('/home/xxx/php/'.$page.'.php');
$file=$page.'.php';
}
elseif(is_file('/home/xxx/php/'.$page)) {
include('/home/xxx/php/'.$page);
$file=$page;
}
else {
echo "<font face=verdana size=1><b>Page \"$page\" is invalid.";
}
}
else {
include('/home/xxx/php/1.php');
$file='home';
}
?>
Thats the main php code...I have other pages stored in a specified folder which get called by this script (pages 1-10, each has 25 images).
What I wanted to do was add vB3's template system to it, but I couldnt get it to work.
Would anyone kindly help me integrate the footer/header from vB3? I tried reading a guide posted here, but the way my "gallery" works gives me a hard time to make it work :)
Boofo
01-31-2004, 04:58 AM
Here's what I have at the top of my chat.php file, if this will help.
<?php
error_reporting(E_ALL & ~E_NOTICE);
// pre-cache templates used by all actions
$globaltemplates = array('header,navbar,chat');
// ## Grabs global.php ##
require("./global.php");
// ## yeap what it says ##
define('NO_REGISTER_GLOBALS', 1);
// ## defines this script as chat if you use phpinclude_start for this page at all ##
define('THIS_SCRIPT', 'chat');
and then I call the navbar template like this (right above the call I make for the chat template):
eval('$navbar = "' . fetch_template('navbar') . '";');
Then just make a template for what you want to have in it with the standard headinclude, header and footer in it and that should get you on your way.
Mijae
01-31-2004, 01:45 PM
Here's what I have at the top of my chat.php file, if this will help.
<?php
error_reporting(E_ALL & ~E_NOTICE);
// pre-cache templates used by all actions
$globaltemplates = array('header,navbar,chat');
// ## Grabs global.php ##
require("./global.php");
// ## yeap what it says ##
define('NO_REGISTER_GLOBALS', 1);
// ## defines this script as chat if you use phpinclude_start for this page at all ##
define('THIS_SCRIPT', 'chat');
and then I call the navbar template like this (right above the call I make for the chat template):
eval('$navbar = "' . fetch_template('navbar') . '";');
Then just make a template for what you want to have in it with the standard headinclude, header and footer in it and that should get you on your way.
Thats what I tried, and it didnt work :(
Mijae
01-31-2004, 02:01 PM
Thats what I tried, and it didnt work :(
Ok, images will only show up if I add the template call after the code, which doesnt work right because the images are shown before the header.
<?
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
define('THIS_SCRIPT', 'gallery');
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('gallery_main') . '");');
if(isset($page)){
if(is_file('/home/xxx/php/'.$page.'.php')) {
include('/home/xxx/php/'.$page.'.php');
$file=$page.'.php';
}
elseif(is_file('/home/xxx/php/'.$page)) {
include('/home/xxx/php/'.$page);
$file=$page;
}
else {
echo "<font face=verdana size=1><b>Page \"$page\" is invalid.";
}
}
else {
include('/home/xxx/php/1.php');
$file='home';
}
?>
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Cache-Control" content="no-cache" />
<!-- end no cache headers -->
<title><phrase 1="$vboptions[bbtitle]">$vbphrase[x_powered_by_vbulletin]</phrase></title>
$headinclude
</head>
<body>
$header
$navbar
Boofo
01-31-2004, 02:18 PM
This is what you need to have it as:
<?
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
define('THIS_SCRIPT', 'gallery');
if(isset($page)){
if(is_file('/home/xxx/php/'.$page.'.php')) {
include('/home/xxx/php/'.$page.'.php');
$file=$page.'.php';
}
elseif(is_file('/home/xxx/php/'.$page)) {
include('/home/xxx/php/'.$page);
$file=$page;
}
else {
echo "<font face=verdana size=1><b>Page \"$page\" is invalid.";
}
}
else {
include('/home/xxx/php/1.php');
$file='home';
}
eval('print_output("' . fetch_template('gallery_main') . '");');
eval('$navbar = "' . fetch_template('navbar') . '";');
?>
Then put your code above this in the template:
$header
$navbar
Mijae
01-31-2004, 02:38 PM
This is what you need to have it as:
<?
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
define('THIS_SCRIPT', 'gallery');
if(isset($page)){
if(is_file('/home/xxx/php/'.$page.'.php')) {
include('/home/xxx/php/'.$page.'.php');
$file=$page.'.php';
}
elseif(is_file('/home/xxx/php/'.$page)) {
include('/home/xxx/php/'.$page);
$file=$page;
}
else {
echo "<font face=verdana size=1><b>Page \"$page\" is invalid.";
}
}
else {
include('/home/xxx/php/1.php');
$file='home';
}
eval('print_output("' . fetch_template('gallery_main') . '");');
eval('$navbar = "' . fetch_template('navbar') . '";');
?>
Then put your code above this in the template:
$header
$navbar
I still can't get it to work because the way my script works.
What it does is call a php file with the image thumbnails and links from another folder (say /php/1.php), and then loads the content of it. Then if you click on a link (gallery.php?page=2), it will call 2.php and load the next 25 images. I know its primitive, but its been working fine for over a year now :P
Thats whats keeping me from adding the code to the templates, because I have 10 php files, for a total of 250 images.
Mijae
01-31-2004, 06:35 PM
I still can't get it to work because the way my script works.
What it does is call a php file with the image thumbnails and links from another folder (say /php/1.php), and then loads the content of it. Then if you click on a link (gallery.php?page=2), it will call 2.php and load the next 25 images. I know its primitive, but its been working fine for over a year now :P
Thats whats keeping me from adding the code to the templates, because I have 10 php files, for a total of 250 images.
Here is another gallery I tried to make work, but it just wont:
<?
require_once('./global.php');
define('THIS_SCRIPT', 'gallery_test');
eval('print_output("' . fetch_template('gallery_main') . '");');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Invoid's Anime Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
<!--
/* Default styles incase you don't have an external css. */
body { background-color: #ffffff; color: rgb(180,180,180); font: 82% verdana, arial, sans-serif
}
table { font-size: inherit }
p, td, div { color: rgb(180,180,180); font-family: verdana, arial, sans-serif }
h2 { font-size: 1.2em; font-weight: bold }
h2, p { text-align: center }
a:link, a:active, a:visited { color: #708090; text-decoration: none; font-size: 12px }
a:hover { text-decoration: underline }
/* the following styles must be included somewhere, since they controll all formatting */
#photo { text-align: center }
#photo table {text-align: center; margin-right: auto; margin-left: auto }
#photo table td { padding: 10px 10px 10px 10px }
#photo .fulltitle { margin-bottom: 0px; padding-bottom: 0px }
#photo .series { margin-top: 0px; padding-top: 0px }
br.hideme { visibility: hidden; volume: silent }
/* hidden from netscape 4: */
div#photo img { border: 1px solid #708090 }
div#photo .caption { text-align: left; width: 500px; margin-right: auto; margin-left: auto }
.tborder
{
background: #ffffff;
color: #000000;
border: 1px solid #6C87B0;
}
-->
</style>
</head>
<body>
<!-- start of image gallery "stuff" -->
<div id="photo">
<?
//error_reporting (E_ALL);
/************************************************** *********************
* Start Configuration
************************************************** *********************/
// 1 for XHTML or 0 for HTML?
$xhtml = 1;
// thumbnail directory name
$thumbs_dir = '../anime/thumbs';
// full size image directory name
$full_dir = '../anime/images_sdlncvkjhs';
// captions directory name (captions are option, ignore if you dont' have any)
$captions_dir = 'captions';
// thumbnails title (1 to show, 0 to hide)
$thumb_title = 1;
// full size images title (1 to show, 0 to hide)
$full_title = 1;
// kill beginning numbers for the title (1 to hide, 0 to show)
// hiding would make 0005_baby_pic.jpg have a title of 'Baby pic'
$kill_title_nums = 1;
// how many thumbnails should appear per row? (3 usually looks best)
$cols = 5;
// how many thumbnails per page? (a multiple of $cols, or 0 for all)
$max_thumbs = 25;
// extension name (if your server is not set for "index.$ext to be the index page, put 0)
$ext = 'php';
// captions extension
$cext = 'inc'; // use whatever you're comfortable with
// show random option for single page view (1 to show, 0 to hide)
$showrand = 1;
// closing (X)HTML options
// if you use a function to close your code, put that in, otherwise leave as is
$print_footer = 'print_footer';
/************************************************** *********************
* End Configuration
************************************************** *********************/
// figure out this script's name
$self = $_SERVER['PHP_SELF'];
if (basename($self) == "index.$ext") {
$self = str_replace(basename($self), '', $self);
}
// do you have an existing function to close your page? if not, use this default...
if (!function_exists($print_footer)) {
function print_gallery_footer() {
?>
</body>
</html>
<?
}
$print_footer = 'print_gallery_footer';
}
// our error function, cleanly exits the script on user errors
function imgerror($error) {
global $print_footer;
print "<p><b>$error</b></p>\n\n";
$print_footer();
exit();
}
// check to see which kind of closing tag we should use
$close_tag = !empty($xhtml) ? ' />' : '>';
// check for directories
if (!is_dir($thumbs_dir)) {
imgerror('Directory "'.$thumbs_dir.'" does not exist.');
}
if (!is_dir($full_dir)) {
imgerror('Directory "'.$full_dir.'" does not exist.');
}
// get contents of $thumbs_dir
$dir = @opendir($thumbs_dir) or imgerror('Can\'t open ' . $thumbs_dir . ' directory');
while (($thumb = readdir($dir)) !== false) {
if (preg_match('/((?i)jpg|jpeg|gif|tif|bmp|png)$/', $thumb))
$thumbs[] = $thumb;
}
natcasesort($thumbs);
$thumbs_size = sizeof($thumbs);
// lowest displayed image in the array
// use http_get_vars incase register_globals is off in php.ini
$i = !empty($_GET['i']) ? $_GET['i'] : 0;
$random = array_rand($thumbs, 2);
$i = $i === 'rand' ? $thumbs[$random[rand(0, 1)]] : $i;
// check to see if all thumbs are meant to be displayed on one page
if ($max_thumbs == 0) {
$max_thumbs = $thumbs_size;
$mt_check = 1;
}
// thumbnail view
if (is_numeric($i)) {
// check to see which thumbnail to start with
$start = empty($mt_check) && $i > 0 ? $max_thumbs * ($i - 1) : 0;
// are they looking for thumbs pages that don't exist?
if ($start >= $thumbs_size) {
print '<a href="' . $self . '">index</a>' . "\n\n";
imgerror('Sorry, there are no images to display on this page');
}
?>
<table class="tborder" cellpadding="6" cellspacing="1" border="0" align="center">
<tr>
<?
// loop through $thumbs and display $max_thumbs per page
for ($count = 1; $count <= $max_thumbs; $start++) {
// break if past max_thumbs
if ($start >= $thumbs_size) {
break;
}
// print new row after predefined number of thumbnails
if (($count % $cols == 1) && $count != 1 && $cols > 1) {
print "</tr>\n\n<tr>\n";
} elseif ($cols == 1) {
print "</tr>\n\n<tr>\n";
}
// open cell
print '<td bgcolor="#E9EDF3" style="width:100px">';
// insert thumb
print '<a href="' . $self . '?i=' . rawurlencode($thumbs[$start]) . '">';
print '<img src="' . $thumbs_dir . '/' . rawurlencode($thumbs[$start]) . '" ';
list($width, $height) = getimagesize("$thumbs_dir/$thumbs[$start]");
print 'width="' . $width . '" height="' . $height . '"';
// alt information
print ' alt="Link to full sized version of ' . $thumbs[$start] . '"' .
$close_tag .'</a>';
// image title
if ($thumb_title) {
if ($kill_title_nums) {
$title = ltrim(ltrim(str_replace('_', ' ', $thumbs[$start]),
"0..9"));
} else {
$title = ltrim(str_replace('_', ' ', $thumbs[$start]));
}
$title = explode(".", ucfirst($title));
print '<br' . $close_tag . "\n" . $title[0];
}
// close cell
// supress line break for screen readers, but force a line break for lynx
print '</td>' . "\n";
$count++;
}
?>
</tr>
</table>
<?
// thumbs page nav
if (!$mt_check) {
print "\n<p>";
// how many total thumbs pages, including a "remainder" page if needed
$pages = ceil($thumbs_size / $max_thumbs);
for ($count = 1; $count <= $pages; $count++) {
if ($count == 1) {
if ($count == $i || $i == 0) {
print $count;
} else {
print "<a href=\"$self\">$count</a>";
}
} else {
if ($count == $i) {
print " | $count</a>";
} else {
print " | <a href=\"$self?i=$count\">$count</a>";
}
}
}
print '</p>';
}
}
// single image view
else if (file_exists("$full_dir/$i")) {
// find where it is in the array
$key = array_search($i, $thumbs);
if (is_null($key)) {
$key = -1;
}
// navigation
print '<p>';
// previous
print $key >= 1 ? '<a href="' . $self . '?i=' . rawurlencode($thumbs[$key - 1]) . '">' :
'';
print '« previous';
print $key >= 1 ? '</a>' : '';
print ' | ';
// index
print '<a href="' . $self . '">index</a>';
print ' | ';
// random
if ($showrand != 0) {
print '<a href="' . $self . '?i=rand">random</a>';
print ' | ';
}
// next
print $key < $thumbs_size - 1 ? '<a href="' . $self . '?i=' . rawurlencode($thumbs[$key
+ 1]) . '">' : '';
print 'next »';
print $key < $thumbs_size - 1 ? '</a>' : '';
print "</p>\n\n";
// image
print '<img src="' . $full_dir . '/' . rawurlencode($i) . '" ';
list($width, $height) = GetImageSize("$full_dir/$i");
print 'width="' . $width . '" height="' . $height . '"';
// alt information
print ' alt="';
if (!$full_title) {
print $i;
}
print "\"$close_tag\n\n";
if ($full_title) {
if ($kill_title_nums) {
$title = $title = ltrim(ltrim(str_replace('_', ' ', $i), "0..9"));
} else {
$title = ltrim(str_replace('_', ' ', $i));
}
$title = explode('.', ucfirst($title));
print "<div class=\"fulltitle\">$title[0]</div>\n\n";
}
// numerically show what image it is in the series; hide this if image isn't in the
series
if ($key >= 0) {
// add 1 so that the first image is image 1 in the series, not 0
print '<div class="series">' . ($key + 1) . ' of ' . $thumbs_size .
"</div>\n\n";
}
// caption (optional)
if (file_exists("$captions_dir/$i.$cext")) {
print '<div class="caption">' . "\n";
require("$captions_dir/$i.$cext");
print "\n</div>\n";
}
} else { // no image found
?><p><a href="<?=$self?>">index</a></p>
<?
imgerror('Sorry, that image does not exist...');
}
?>
</div>
<!-- end of image gallery "stuff" -->
</body>
</html>
If I add the eval at the bottom, the images will show up before the header. It wont work for any gallery I try to make >_<
How hard can adding header/footer be >_<
Boofo
01-31-2004, 06:42 PM
Ok, I misunderstood you before. I thought you said you WANTED the pictures to show up before the header. Sorry about that. With your original script, use this:
<?
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
define('THIS_SCRIPT', 'gallery');
if(isset($page)){
if(is_file('/home/xxx/php/'.$page.'.php')) {
include('/home/xxx/php/'.$page.'.php');
$file=$page.'.php';
}
elseif(is_file('/home/xxx/php/'.$page)) {
include('/home/xxx/php/'.$page);
$file=$page;
}
else {
echo "<font face=verdana size=1><b>Page \"$page\" is invalid.";
}
}
else {
include('/home/xxx/php/1.php');
$file='home';
}
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('gallery_main') . '");');
?>
Then in the template 'gallery_main', add your code BELOW this:
$header
$navbar
Mijae
01-31-2004, 07:27 PM
Ok, I misunderstood you before. I thought you said you WANTED the pictures to show up before the header. Sorry about that. With your original script, use this:
<?
error_reporting(E_ALL & ~E_NOTICE);
require_once('./global.php');
define('THIS_SCRIPT', 'gallery');
if(isset($page)){
if(is_file('/home/xxx/php/'.$page.'.php')) {
include('/home/xxx/php/'.$page.'.php');
$file=$page.'.php';
}
elseif(is_file('/home/xxx/php/'.$page)) {
include('/home/xxx/php/'.$page);
$file=$page;
}
else {
echo "<font face=verdana size=1><b>Page \"$page\" is invalid.";
}
}
else {
include('/home/xxx/php/1.php');
$file='home';
}
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('gallery_main') . '");');
?>
Then in the template 'gallery_main', add your code BELOW this:
$header
$navbar
There isnt any code to add, its stored in 10 files (1 through 10), each file contains links to 25 images...so I cant do that with one template. I am not sure how I could make it work.
Mijae
01-31-2004, 08:12 PM
This is harder then I thought. Is there any other way to add the header/footer to a php file?
Arg.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.