// Folderblog 1.1
// (c) 2004 Donald Tetto.
// http://folderblog.tetto.org/
include_once("vars.php");// Import variables
include($template . "_settings.php");
$tags=array();
$image=$_GET["image"];
$comments=$_GET["comments"];
$menu=$_GET["menu"];
umask(0);
// Thumbnail code generation
function thumb($image,$format) {
global $show_thumbs,$thumb_format,$thumb_dates,$thumbs_directory,$comments_directory,$captions_directory,$file_extension,$thumb_maxwidth;
if($image) {
$size=@getimagesize($thumbs_directory . $image . $file_extension);
if($thumb_maxwidth&&$size[0]>$thumb_maxwidth) $thumbsize='width="' . $thumb_maxwidth . '" height="' . ($size[1]/$size[0]) * $thumb_maxwidth . '"';
else $thumbsize=$size[3];
if(strpos($format,"<#fbdate#>")!==FALSE||strpos($format,"<#fbcaption#>")!==FALSE) {
if($caption=@implode("",@file($captions_directory . $image . ".txt"))) list($date,$caption)=explode("\n",$caption,2);
}
if(strpos($format,"<#fbcomcount#>")) {
if($comments=@file($comments_directory . $image . "_com.txt")) $count=count($comments);
else $count=0;
}
}
$tags=array(
"<#fblink#>"=>"?image=" . $image,
"<#fbimage#>"=>$image ? '' : "",
"<#fbcomcount#>"=>$count,
"<#fbdate#>"=>$thumb_dates ? $date : "",
"<#fbcaption#>"=>$caption
);
return str_replace(array_keys($tags),$tags,$format);
}
if(isset($menu)) {
$dir=opendir($index_directory);
while ($file=readdir($dir)) if(strrchr($file,".")==$file_extension) $files[]=$file;
closedir($dir);
if($sort) sort($files, SORT_STRING);
$template=$menu_template;
$thumbs_perpage=$thumbs_perrow*$rows_perpage;
$total=count($files);
$pages=ceil($total/$thumbs_perpage);
if($reverse==1&&$menu==0) $menu=1;
elseif($menu==0) $menu=$pages;
$i=($menu-1)*$thumbs_perpage;
$imax=$menu*$thumbs_perpage;
$cells.='
';
while($files[$i]&&$i<$imax) {
$files[$i]=substr($files[$i],0,strrpos($files[$i],'.'));
$cells.='';
if($files[$i]) $cells.=thumb($files[$i],$menuthumb_format);
$cells.=' | ';
if($total==$i+1) $cells.='
';
elseif(($i+1)%$thumbs_perrow==0) $cells.='';
$i++;
}
unset($files);
for($p=1;$p<=$pages;$p++) {
$menupages.=' ';
if($menu!=$p) $menupages.='';
$menupages.=$p;
if($menu!=$p) $menupages.='';
$menupages.=' ';
}
$tags+=array(
"<#fbcells#>"=>$cells,
"<#fbpages#>"=>$menupages,
"<#fbprev#>"=>$menu==1 ? "" : str_replace("<#fblink#>","?menu=" . ($menu-1),$previous_link),
"<#fbnext#>"=>$menu==$pages ? "" : str_replace("<#fblink#>","?menu=" . ($menu+1),$next_link),
"<#fbrange#>"=>($imax-$thumbs_perpage+1) . " - " . ($menu==$pages ? $total : $imax),
"<#fbtotal#>"=>$total,
);
}
else {
if((!$comments&&!$delcom)||$template==$comments_template) { // if main
if($comments) $image=$comments;
$dir=opendir($index_directory);
while ($file=readdir($dir)) if(strrchr($file,".")==$file_extension) $files[]=$file;
closedir($dir);
if($sort) sort($files, SORT_STRING);
$total=count($files);
if(!$image&&$reverse==0) $image=$total-1;
elseif(!$image) $image=0;
else $image=array_search($image . $file_extension,$files);
for($i=0;$i<7;$i++) $images[$i]=$files[$image+($i-3)];
mt_srand($image*16);
$k=0;
for($i=0;$i<$rand_thumbs;$i++) {
$rand[$i]=$files[mt_rand(0,$total-1)];
if($k<15&&(array_search($rand[$i],$rand)!=$i||(array_search($rand[$i],$images)!=NULL&&array_search($rand[$i],$images)!==FALSE))) $i--;
elseif($k>=15) $rands.=thumb("",$randthumb_format);
else $rands.=thumb(substr($rand[$i],0,strrpos($rand[$i],'.')),$randthumb_format);
$k++;
}
unset($files);
for($i=0;$i<7;$i++) $images[$i]=substr($images[$i],0,strrpos($images[$i],'.'));
if($show_thumbs) {
for($i=(7-$show_thumbs)/2;$i<(7-(7-$show_thumbs)/2);$i++) {
$format=($i==3 ? $thisthumb_format : $thumb_format);
$thumbs.=thumb($images[$i],$format);
}
}
if($caption=@implode("",@file($captions_directory . $images[3] . ".txt"))) list($date,$caption)=explode("\n",$caption,2);
$size=@getimagesize($photo_directory . $images[3] . $file_extension);
if($image_maxwidth&&$size[0]>$image_maxwidth) $imagesize='width="' . $image_maxwidth . '" height="' . ($size[1]/$size[0]) * $image_maxwidth . '"';
else $imagesize=$size[3];
$fbimage='';
if($image_link) $fbimage='' . $fbimage . '';
$tags+=array(
"<#fbthis#>"=>$images[3],
"<#fbdate#>"=>$post ? str_replace("<#fbdate#>",$date,$datepost_format) : $date,
"<#fbimage#>"=>$fbimage,
"<#fbcaption#>"=>$post ? str_replace("<#fbcaption#>",$caption,$captionpost_format) : $caption,
"<#fbprev#>"=>$images[2] ? str_replace("<#fblink#>","?image=" . $images[2],$previous_link) : "",
"<#fbnext#>"=>$images[4] ? str_replace("<#fblink#>","?image=" . $images[4],$next_link) : "",
"<#fbnumber#>"=>$image+1,
"<#fbtotal#>"=>$total,
"<#fbmenu#>"=>"?menu=0",
"<#fbthumbs#>"=>$thumbs,
"<#fbrand#>"=>$rands,
"<#fbbuttons#>"=>$post ? str_replace("<#fbpass#>",$_POST["pass"],$buttons_format) : "",
"<#fbpost#>"=>($images[4] ? "?image=" . $images[4] : "?image=" . $images[3]) . "&lastimage=" . $images[3]
);
}
if($comments||$template==$comments_template) {// if comments
if($comments) {
$images[3]=$comments;
$template=$comments_template;
}
// Comments code generation
function comments($image) {
global $comment_format, $comments_directory, $post;
$comments=@file($comments_directory . $image . "_com.txt");
if($comments) {
$i=0;
foreach($comments as $comment) {
$thiscomment=str_replace(array("<#fbcomment#>","<#fbauthor#>","<#fbdate#>"),explode('<>',$comment),$comment_format);
$thiscomment=str_replace("<#fbcheckbox#>",($post ? '' : ""),$thiscomment);
$string.=$thiscomment;
}
}
return $string;
}
// Post comment
if(strlen(trim($_POST["comment"]))&&strlen(trim($_POST["name"]))) {
$nameval=$name=$_POST["name"];
$urlval=$url=$_POST["url"];
$comment = preg_replace("/<((?!\/?(a|b|u|br|p)\b)[^>]*)>/xis", "", ' ' . $_POST["comment"]);
$comment = str_replace("\n", '
', $comment);
$comment = trim(eregi_replace('[^\"](http:\/\/[^[:space:]<>]*)', ' \\1', $comment));
$comment = eregi_replace('(
[[:space:]]*){2,}', '
', $comment);
$comment = eregi_replace('[[:space:]]+', ' ', $comment);
if(strlen(trim($url))&&$url!="http://") $name='' . $name . '';
$date = date('F j, Y g:ia');
$ip = getenv('REMOTE_ADDR');
$file=fopen($comments_directory . $images[3] . "_com.txt", 'a');
$thiscomment=$comment . '<>' . $name . '<>' . $date . "\n";
fwrite($file, stripslashes($thiscomment));
fclose($file);
if($email) {
$message="This is an automated message to notify you of a new comment by " . $nameval . " on your image " . $images[3] . ". To go to the image, visit the link below.\n\nhttp://" . getenv("SERVER_NAME") . getenv("SCRIPT_NAME") . "?image=" . $images[3] . "\n\nYou can disable this feature in your folderblog's vars.php.";
mail($email,$blog_title . " comment", $message,
"From: folderblog <" . $email . ">\n" .
"Reply-To: " . $email . "\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/plain; charset=iso-8859-1\n" .
"X-Priority: 3\n" .
"X-MSmail-Priority: Normal\n" .
"X-Mailer: PHP/" . phpversion());
}
if($_POST["cookie"]==1) setcookie('folderblog', $nameval . "::" . $urlval, time() + 31536000,"/");
elseif($_COOKIE['folderblog']) {
setcookie('folderblog', "", time() + 31536000,"/");
$_POST["cookie"]=-1;
unset($nameval,$urlval);
}
}
if($_POST["cookie"]!=-1&&$_COOKIE['folderblog']) list($nameval, $urlval)=explode('::', $_COOKIE['folderblog']);
if($_POST["cookie"]!=-1&&($_POST["cookie"]==1||$_COOKIE['folderblog'])) $checked="checked";
$tags+=array(
"<#fbcomthumb#>"=>$show_thumbs ? thumb($images[3],$comthumb_format) : "",
"<#fbcomments#>"=>comments($images[3]),
"<#fbchecked#>"=>$checked,
"<#fbnameval#>"=>$nameval,
"<#fbcombuttons#>"=>$post ? str_replace("<#fbpass#>",$_POST["pass"],$combuttons_format) : "",
"<#fburlval#>"=>$urlval ? $urlval : "http://"
);
}
if($comments=@file($comments_directory . $images[3] . "_com.txt")) $count=count($comments);
else $count=0;
$tags+=array(
"<#fbcomcount#>"=>$count,
"<#fbcomlink#>"=>$comments_on ? str_replace(array("<#fblink#>","<#fbcomcount#>"),array('?comments=' . $images[3],$count),$comment_link) : "",
"<#fbpostcom#>"=>'?comments=' . $images[3]
);
}
// Do output
$tags+=array(
"<#fbtitle#>"=>$blog_title,
"<#fbfront#>"=>'?'
);
echo str_replace(array_keys($tags),$tags,@implode("",file($template)));
?>