* Copyright (C) 2001 Neale Pickett * Copyright (C) 2000 Robert A. Holak * * 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., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ $version = "0.4"; @include("config.inc"); #phpinfo(); #error_log("common.inc: php_self is $PHP_SELF "); #error_log("common.inc: path is $PATH_INFO "); $pagepath = substr($PHP_SELF, strlen($PHP_SELF) - strlen($PATH_INFO)); $page = $PATH_INFO; #error_log(" Parameters are $pagepath $page "); $pcnt = 0; $page = urldecode($page); $page = str_replace("\\","", $page); #error_log(" New Parameters are $pagepath $page "); $calltype = "SHOW"; if (strpos($page,"index.html")) { $calltype = "INDEX"; } elseif (strpos($page,"/html/")) { $calltype = "VIEW"; } if ($page == "index.php" || $page == "" || $page == "/") { $calltype = "INDEX"; } $page = substr($page, 1); if (strpos($page,"/size") !== FALSE) { // Get the album first (ends in /size instead of /) $parms[$pcnt] = substr($page, 0 , strpos($page, "/size")); $page = substr($page, strpos($page,"/size")+5); } else { $parms[0] = ""; $page = ""; } error_log("( $pcnt: $parms[$pcnt] )"); $pcnt++; while ($page != "") { if (strpos($page, "/") != FALSE) { $parms[$pcnt] = substr($page, 0 , strpos($page, "/")); } else { $parms[$pcnt] = $page; } $page = substr($page, strlen($parms[$pcnt])+1); if (strpos($parms[$pcnt],"=") != FALSE) { $parms[$pcnt] = substr($parms[$pcnt], strpos($parms[$pcnt],"=")+1); } error_log("( $pcnt: $parms[$pcnt] )"); $pcnt++; } // Ok. Now parms holds our parameters // Order is as follows: // 0 - Album // 1 - DisplaySize // 2 - "html" or Picture Name for show.php // 3 - start.index.html or Picture name for view.php $album = $parms[0]; $dispsize = $parms[1]; if ($calltype == "SHOW") { $pic = $parms[2]; } if ($calltype == "INDEX") { $start = substr($parms[3],0,strpos($parms[3], "index.html")); }; if ($calltype == "VIEW") { $pic = substr($parms[3],0,strpos($parms[3], "__view.html")); } if (!defined("CONFIG")) { $notsetupyet = 1; } else { $notsetupyet = 0; } ## This is stuff they all need to do # print("SF = $SCRIPT_FILENAME"); preg_match("/(.*\/).*$/",$SCRIPT_FILENAME,$matches); chdir($matches[1]); preg_match("/(.*\/).*$/",$SCRIPT_NAME,$htmlmatches); # set up the variables for user = use this way we can change the method of # getting the user var and won't have to change the code much. #variables: # $scriptbase -> where the script is. (includes /) # $realpixbase -> Where the pics are (includes /) # $realdescbase -> Where the descs are (includes /) # $userbase -> the user's public html dir (includes /) # $htmlbase -> the scripts html base. (includes /) # $htmluserbase -> the user's html base. (includes /) # $username -> the username of the user we're accessing. # $userstring -> how we pass on the username. # $usercachebase -> Where in the cache the images are located. $scriptbase = "$matches[1]"; $realpixbase = $scriptbase.$pix_base."/"; $realdescbase = $scriptbase.$desc_base."/"; $userbase = "$scriptbase"; $htmlbase = "$htmlmatches[1]"; $htmluserbase = "$htmlmatches[1]"; $username = ""; $userstring = "/"; $usercachebase = ""; if ($enable_users) { if ($user == '') { if ($PATH_INFO != '') { $user = substr($PATH_INFO, 1); } } if ($user != '') { # Turn off error reporting, we don't care if the username doesn't exist $error = error_reporting(0); $userinfo = posix_getpwnam($user); error_reporting($error); if ($userinfo['uid'] > 100) { $userbase = $userinfo['dir']."/".$public_html."/"; $realpixbase = $userbase.$pix_base."/"; $realdescbase = $userbase.$desc_base."/"; $htmluserbase = "/~${user}/"; $username = $user; $userstring = "/${username}/"; $usercachebase = "${username}/"; } } } if ($dispsize == '') $dispsize = $default_size; if ($start == '') $start = 0; if (preg_match("/(^|\/)\.\.(\/|$)/", $album)) { # Never attribute to malice what can be adequately explained by # stupidity. $album = ""; } if (preg_match("/(^|\/)\.\.(\/|$)/", $pic)) { $pic = ""; } # Get a list of filenames if (file_exists($realpixbase.$album)) { $configoverride = FindFileDownPath($realpixbase.$album, ".config", $realpixbase.$album); if ($configoverride) { include($configoverride); } $handle=opendir($realpixbase.$album); while (($file = readdir($handle)) != '') { if (!ereg("^\.|\.htt$|\.db$|\.ini$", basename($file))) { if (is_dir($realpixbase.$album."/".$file)) { if (($file != ".") and ($file != "..")) { $dirlist[] = $file; } } else { if (($file != "style.css") && (! strstr($file, "__desc.txt"))) { $filelist[] = $file; } } } } $stylesheet = FindFileDownPath($realpixbase.$album, "style.css", $realpixbase); if ($userbase != "") { $stylesheet = str_replace($userbase, "", $stylesheet); # may be kludgy. if ($stylesheet[0] == '/') { $stylesheet = ""; } } if ($stylesheet != '') { $stylesheet = $htmluserbase . $stylesheet; } } if (is_array($dirlist)) { sort($dirlist); } if (is_array($filelist)) { sort($filelist); $totalfiles = sizeof($filelist); } else { $totalfiles = 0; } function FindFileDownPath($path, $filename, $stop) { $filepath = $path; $returned = ""; $stopped = 0; while (($pos = strrpos($filepath, "/")) && !$stopped) { # print "$pos - $filepath - $filename - $stop
"; if (file_exists($filepath."/".$filename)) { $returned = $filepath."/".$filename; $stopped = 1; } if ($filepath."/" == $stop) { $stopped = 1; # print "Stopped - $filepath - $stop
"; } $filepath = substr($filepath, 0, $pos); } return $returned; } # Escape a directory path function diresc($path) { $path = str_replace(" ", "+", $path); $path = str_replace("'", '%27', $path); return $path; # $parts = split("/", $path); # reset($parts); # while (list(, $dirname) = each($parts)) { # $url .= "/" . rawurlencode($dirname); # } # return substr($url, 1); } $colcounter = 0; function MakeImgPath($album, $pic) { global $realpixbase; global $scriptbase; if ($album == "NONE") { return "$scriptbase/$pic"; } else { return "$realpixbase/$album/$pic"; } } function DisplayImg2($href, $album, $pic, $dispsize, $desc=0, $class='body', $top_text='', $table = 1) { global $colcounter; global $display_cols; global $imageview; global $user; global $htmlbase; $width = 0; $height = 0; $image = MakeImgPath($album, $pic); $error = error_reporting(0); $srcsize = GetImageSize("$image"); error_reporting($error); if ($srcsize[0]) { $width = $srcsize[0]; $height = $srcsize[1]; } else { $album="NONE"; $pic="unknown.gif"; $dispsize = 'Original'; } if ($dispsize != 'Original') { if ($width > $height) { $new_width = $dispsize; $new_height = ceil($dispsize * $height / $width); } else { $new_height = $dispsize; $new_width = ceil($dispsize * $width / $height); } $width = $new_width; $height = $new_height; } if ($table) { if ($colcounter == $display_cols) { print "\n"; $colcounter = 0; } print "\n"; } if ($top_text) { if ($href) { print ""; } print $top_text; if ($href) { print "\n"; } print "
\n"; } if ($href) { print ""; } print "" . htmlentities($desc,ENT_QUOTES) . ""; if ($href) { print "\n"; } if ($desc) { print "
\n"; if ($href) { print ""; } print htmlentities($desc,ENT_QUOTES); if ($href) { print "\n"; } } if ($table) { print "\n"; $colcounter += 1; } } function PadTable($class="") { global $colcounter; global $display_cols; global $thumb_size; global $htmlbase; global $albumpath; while ($colcounter != $display_cols) { print "\n"; print "\n"; print "\n"; $colcounter += 1; } $colcounter = 0; print "\n"; } # Checks directory existence along $pathname and create them as necessary # Not sure if it's not over complicated function checkdir($pathname) { $darray = split("/",$pathname); $chckdir = $darray[0]; for ($x=1; $xHome\n"; } if ($show_albums != 0) { if ($sitehome != '') { print " > "; } print "Albums\n"; } $doo = split("/",$path); $prepath = ''; $st = 0; while (list($foo,$filename) = each($doo)) { if ($filename) { if ($prepath) { $fullname = $prepath . "/" . $filename; } else { $fullname = $filename; } print " > "; if ($filename == $endpoint) { print ""; $st = $start; } print "$filename"; if ($filename == $endpoint) { print ""; } print "\n"; $prepath = $fullname; } } } function StandardLinks($mode,$path,$start,$picindex="") { $endpoint = basename("/" . $path); global $dispsize; global $sitehome; global $albumpath; global $show_albums; global $userstring; global $htmlbase; global $filelist; global $viewpath; global $items_per_page; global $totalfiles; if ($sitehome != '') { print "\n"; } if ($show_albums != 0) { print "\n"; } if ($mode == "view") { print "\n"; $start_url = $htmlbase.$viewpath.$userstring."$path/size$dispsize/html/" . $filelist[0] . "__view.html"; print "\n"; if ($filelist[($picindex-1)]) { $prev_url = $htmlbase.$viewpath.$userstring."$path/size$dispsize/html/" . $filelist[$picindex-1] . "__view.html"; print "\n"; } if ($filelist[($picindex+1)]) { $next_url = $htmlbase.$viewpath.$userstring."$path/size$dispsize/html/" . $filelist[$picindex+1] . "__view.html"; print "\n"; } $end_url = $htmlbase.$viewpath.$userstring."$path/size$dispsize/html/" . $filelist[$totalfiles-1] . "__view.html"; print "\n"; } else { if ($endpoint == $path) { print "\n"; } else { print "\n"; } $thisbase = $htmlbase.$albumpath.$userstring."$path/size$dispsize/html"; print "\n"; if ($start > 0) { print "\n"; } # XXX: Gah, hack, bleh. for ($x = $start; $x < $start + $items_per_page and $filelist[$x]; $x++); if ($totalfiles > $x) { print "\n"; } print "\n"; } } function GetPicIndex( $filelist ) { global $pic; $index = -1; $found = FALSE; while (($found == FALSE) && ($index < sizeof($filelist))) { $index++; $found = ($filelist[$index] == $pic); } if ($found == TRUE) { return $index; } else { return FALSE; } } ?>