'24', 'id' => '1', 'show' => 'all', 'border' => '1', 'titleprefix' => 'Image-', 'wrap' => '5')); // Init xGalleryVars (fixed by admin) global $pagename; //global $UploadPrefixFmt; // = "/$Group/"; $Group = FmtPageName('$Group', $pagename); $Title = FmtPageName('$Title', $pagename); // set these incase upload.php has not been yet loaded global $UploadUrlFmt, $ScriptUrl, $UploadDir, $UploadPrefixFmt; ### NEED TO FIX THE NEXT TWO LINES SOME HOW (WORKS FOR NOW) $UploadUrlFmt = preg_replace("#/[^/]*\$#", "/$UploadDir", $ScriptUrl, 1); // $UploadPrefixFmt = "/$Group.$Title/"; $UploadPrefixFmt = "/$pagename/"; // die ("pagename is $pagename, and uploadprefixfmt is $UploadPrefixFmt"); $xGalleryVars = array( 'images_dir' => "$UploadDir$UploadPrefixFmt", 'images_url' => "$UploadUrlFmt$UploadPrefixFmt", 'thumbs_dir' => "$UploadDir$UploadPrefixFmt" . "thumbs/", 'thumbs_url' => "$UploadUrlFmt$UploadPrefixFmt" . "thumbs/", 'group' => "$Group", 'title' => "$Title", 'image_types' => "jpg, JPG", 't_width' => "100", 't_height' => "75"); $xGalleryVars['output_template'] = '!!{{[[$Groupspaced]]}} / {{$Album}} [[notitle]] ||table width=100% || %border=3%$image_url || || [+[[$Titlespaced]]+] || [[x-comment:]]'; return; } //---------------------------------------------------------------------- function xGallery($input) { //---------------------------------------------------------------------- xGallery_Init($xGalleryVars, $xGalleryParams); $html = "\n\n"; $html .= xGallery_UpdateThumbnails($xGalleryVars, $xGalleryParams); // update thumbs (and create pages) if needed $html .= xGallery_ShowThumbnails($xGalleryVars, $xGalleryParams); // display thumbs $html .= "\n\n\n"; return $html; } //---------------------------------------------------------------------- function xGallery_UpdateThumbnails(& $xGalleryVars, &$xGalleryParams) { //---------------------------------------------------------------------- $html = ''; $images_dir = $xGalleryVars['images_dir']; $thumbs_dir = $xGalleryVars['thumbs_dir']; $existing_images = xGallery_Directory($images_dir, $xGalleryVars['image_types']); if (sizeof($existing_images) == 0) { global $pagename; $PageUrl = FmtPageName('$PageUrl', $pagename); $html .= "X-Gallery Error: There are no images available in $images_dir. " . "Try [[$PageUrl?action=upload uploading]] some."; } else // if needed, create new thumbnails and/or WikiPages { if (!file_exists($thumbs_dir)) { if (!mkdir($thumbs_dir)) { $html .= "Error creating thumbs directory"; } } if (file_exists($thumbs_dir)) { $Gallery = $xGalleryVars['group']; $Album = $xGalleryVars['title']; foreach ($existing_images as $image_name) { if (!file_exists("$thumbs_dir/$image_name")) { $html .= xGallery_CreateThumbnail ("$images_dir/$image_name", "$thumbs_dir/$image_name", $xGalleryVars['t_width'], $xGalleryVars['t_height']); } $Title = $xGalleryParams['titleprefix'] . xGallery_Wikify($image_name); if (!PageExists("$Gallery.$Title")) { $template = $xGalleryVars['output_template']; $template = str_replace("\$Gallery", $Gallery, $template); $template = str_replace("\$Album", $Album, $template); $template = str_replace("\$image_url", $xGalleryVars['images_url'] . rawurlencode($image_name), $template); $_POST['text'] = $template; xGallery_CreateImagePage("$Gallery.$Title"); } } } } return $html; } //---------------------------------------------------------------------- function xGallery_CreateImagePage($pagename) { //---------------------------------------------------------------------- // This is just a cut-and-paste of the original HandlePost function // with the last line (a Redirect) removed. global $WikiDir,$DeleteKeyWord,$RecentChanges,$RCDelimPattern,$Now, $TimeFmt,$CurrentTime,$PageFileFmt,$DiffKeepDays,$Author,$PostFields, $DiffFunction; $CurrentTime = strftime($TimeFmt,$Now); foreach($PostFields as $k) {if (isset($_POST[$k])) {$new[$k]=str_replace("\r","",stripmagic($_POST[$k])); }} Lock(2); $page = RetrieveAuthPage($pagename,"edit"); if (!$page) { Abort("?cannot post $pagename"); } $pagename = FmtPageName('$PageName',$pagename); if ($new['text']==$page['text']) { Redirect($pagename); return; } $diffclass=preg_replace('/\\W/','',@$_POST['diffclass']); if ($page["time"]>0) $new["diff:$Now:".$page['time'].":$diffclass"] = $DiffFunction($new['text'],$page['text']); $new['author'] = $Author; $new["author:$Now"] = $Author; $new["host:$Now"] = $_SERVER['REMOTE_ADDR']; foreach($new as $k=>$v) { if ($k=='pagename' || $k=='action') continue; $page[$k] = $v; } $keepgmt = $Now-$DiffKeepDays*86400; $keys = array_keys($page); foreach ($keys as $k) if (preg_match("/^\\w+:(\\d+)/",$k,$match)) if ($match[1] < $keepgmt) unset($page[$k]); $pagefile = FmtPageName($PageFileFmt,$pagename); if ($page['text']==$DeleteKeyWord) { @rename("$WikiDir/$pagefile","$WikiDir/$pagefile,$Now"); } else WritePage($pagename,$page); foreach($RecentChanges as $rcfmt => $pgfmt) { $rcname=FmtPageName($rcfmt,$pagename); if (!$rcname) continue; $pgtext=FmtPageName($pgfmt,$pagename); if (!$pgtext) continue; if (@$seen[$rcname]++) continue; $rcpage = ReadPage($rcname,""); $rcelim = preg_quote(preg_replace("/$RCDelimPattern.*$/",' ',$pgtext),'/'); $rcpage['text'] = preg_replace("/[^\n]*$rcelim.*\n/","",$rcpage['text']); if (!preg_match("/$RCDelimPattern/",$rcpage['text'])) $rcpage['text'] .= "$pgtext\n"; else $rcpage['text'] = preg_replace("/([^\n]*$RCDelimPattern.*\n)/", "$pgtext\n$1",$rcpage['text'],1); WritePage($rcname,$rcpage); } } //---------------------------------------------------------------------- function xGallery_Directory($dir,$filters) { //---------------------------------------------------------------------- if (!file_exists($dir)) {return NULL;} $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} if ($filters != "all"){ $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0;$f $width) { $t_height = $max_y; $t_width = $t_height * $width / $height;} // else{$t_width = $max_x; $t_height = $t_width * $height / $width;} $thumb = @imagecreatetruecolor ($t_width, $t_height) or $html .= "Error: Could not create the thumbnail (w=$t_width, h=$t_height)
"; @imagecopyresized($thumb, $pic, 0, 0, 0, 0, $t_width, $t_height, $width, $height); @ImageJPEG($thumb,$destination_name,75); @imagedestroy($thumb); @imagedestroy($pic); } else {die ("No \$pic");} /* size the image so the width is = to t_width after that, check to see if the (resulting) image height is more than t_height. if it is, re-do the resize, but this time, resize according to the height. */ return $html; } //---------------------------------------------------------------------- function xGallery_Wikify($str) { //---------------------------------------------------------------------- $str = preg_replace("/(jpg|JPG)$/", '', "$str"); // $str = preg_replace('/^[0-9]/', "$prefix$0", $str); $str = preg_replace('/[^-\\w ]/','',$str); $str = preg_replace('/_+/', '-', $str); $str = preg_replace('/--+/', '-', $str); $str = preg_replace('/\\s+/', '', $str); global $xGalleryParams; $str = $xGalleryParams['titleprefix'] . $str; $str = ucfirst($str); // may be redundant, but still be required return $str; } //---------------------------------------------------------------------- function xGallery_ShowThumbnails(& $xGalleryVars, & $xGalleryParams) { //---------------------------------------------------------------------- $thumbs_list = xGallery_Directory($xGalleryVars['thumbs_dir'], $xGalleryVars['image_types']); $Group = $xGalleryVars['group']; $num_images = sizeof($thumbs_list); $images_url = $xGalleryVars['images_url']; $thumbs_url = $xGalleryVars['thumbs_url']; $wrap = $xGalleryParams['wrap']; $show = $xGalleryParams['show']; if ($show=='all') {$show = $num_images;} $start = $xGalleryParams['id']; $end = $start + $show-1; if ($end > $num_images) {$end = num_images;} $count = 0; while (($num_images > 0) && ($count < $end)) { if ($count % $wrap == 0) { if ($count > 0) {$html .= "
";} $html .= "\n
" . ""; } global $ScriptUrl, $pagename; $Group = FmtPageName('$Group', $pagename); $PgName = $ScriptUrl . "?pagename=" . $Group ."/". $xGalleryParams['titleprefix'] . xGallery_Wikify($thumbs_list[$count]); // $PgName = $xGalleryParams['group'] ."/". $xGalleryParams['titleprefix'] . xGallery_Wikify($thumbs_list[$count]); $html .= "\n "; $count++; } if ($count > 0) { // in case there are 0 images, this should not get displayed $html .= "
"; $html .= "

"; $PageUrl = FmtPageName('$PageUrl', $pagename); $html .= "" . "UPLOAD IMAGE"; } return Keep($html); } ?>