. * * * * * * Contact: subhrajit@gmail.com, http://www.subhrajit.net/ * * * * * ****************************************************************************************** */ /* Syntax: YAG [option1=o1, option2=o2, ...] { url_or_path | caption && url_or_path | caption && ... } See http://www.pmwiki.org/wiki/Cookbook/YAG for more details */ Markup( 'YAG', 'cache, $FarmD.'/pub/YetAnotherGalleryCache/' ); $AlansPubDirUrl='http://'.$_SERVER['HTTP_HOST'].'/wiki/pub'; SDV($YetAnotherGallery->cacheURL, $PubDirUrl.'/YetAnotherGalleryCache/' ); // Advanced path and folder options #Original SDV($YetAnotherGallery->fetchLocalFileLocally, true ); // If an image file appears to be local, try to fetch it as a local file instead of a URL. SDV($YetAnotherGallery->fetchLocalFileLocally, true ); // If an image file appears to be local, try to fetch it as a local file instead of a URL. SDV($YetAnotherGallery->ShellPWD, trim(shell_exec("pwd")) ); // Default values SDV($YetAnotherGallery->cols, 4); SDV($YetAnotherGallery->maxrows, 5); SDV($YetAnotherGallery->imgmaxwidth, 150); SDV($YetAnotherGallery->imgmaxheight, 250); SDV($YetAnotherGallery->convertoptions, "-resize {imgmaxwidth}x{imgmaxheight}" ); SDV($YetAnotherGallery->thumbtype, "jpg" ); SDV($YetAnotherGallery->containerwidth, 500 ); // Effective only for 'popup' and 'div' SDV($YetAnotherGallery->containerheight, 600 ); // Effective only for 'popup' and 'div' SDV($YetAnotherGallery->style, "hiddencaption,popup" ); // Do not use 'default' in this list SDV($YetAnotherGallery->captiontype, 'linked,basichtml'); // Allowed values: 'linked'/'free' & 'nohtml'/'wiki'/'basichtml'/'fullhtml' SDV($YetAnotherGallery->allowUserCaptiontype, true); SDV($YetAnotherGallery->allowCustomPHPhandler, false); // Allow use of custom. WARNING: Potential hazzard if enabled. SDV($YetAnotherGallery->allowRefreshCacheInGETparam, false); // Allows passing of per-page GET parameter 'YAGrefresh=yes' to refresh cache for the page // --------------------------------------------- // CSS styles SDVA($YetAnotherGallery->cellStyle, array( 'default' => "border: solid 2px #cccccc;" ) ); SDVA($YetAnotherGallery->imgDivStyle, array( 'default' => "text-align: center; vertical-align: middle; margin: 0; padding: 0; cursor:hand; cursor:pointer; ", 'rightcaption' => "text-align: center; vertical-align: middle; margin: 0; padding: 0; display:inline" ) ); SDVA($YetAnotherGallery->imgStyle, array( 'default' => "border: 1px solid; border-color: #aaaabb #bbbbcc #bbbbcc #aaaabb; ", 'rightcaption' => "border: 1px solid; border-color: #aaaabb #bbbbcc #bbbbcc #aaaabb; float:left;" ) ); SDVA($YetAnotherGallery->captionDiv, array( 'default' => "", 'hiddencaption' => "
\$Caption
", 'rightcaption' => "
\$Caption
" ) ); // On-page Javascripts SDVA($YetAnotherGallery->imgMouseOverJavascript, array( 'default' => "void(0);", 'hiddencaption' => "this.getElementsByTagName('img')[0].style.opacity=0.6; this.getElementsByTagName('img')[0].style.filter='alpha(opacity=60)'; this.getElementsByTagName('div')[0].getElementsByTagName('div')[0].style.display='block';" ) ); SDVA($YetAnotherGallery->imgMouseOutJavascript, array( 'default' => "void(0);", 'hiddencaption' => "this.getElementsByTagName('img')[0].style.opacity=1.0; this.getElementsByTagName('img')[0].style.filter='alpha(opacity=100)'; this.getElementsByTagName('div')[0].getElementsByTagName('div')[0].style.display='none';" ) ); // Header and footer of gallery SDVA($YetAnotherGallery->GalleryDivContainerFmt, array( 'default' => "", 'div' => "

", 'lfloat'=> "
" ) ); SDVA($YetAnotherGallery->GalleryHeaderFmt, array( 'default' => "
Displaying page \$PageNo of \$PagesCount
", 'nohead' => "" ) ); SDVA($YetAnotherGallery->GalleryFooterFmt, array( 'default' => array('start'=>" 
Pages: ", 'page-prefix'=>" ", 'page-suffix'=>" ", 'current-page-prefix'=>" ", 'current-page-suffix'=>" ", 'end'=>""), 'nofoot' => array('start'=>"
", 'page-prefix'=>"", 'page-suffix'=>"", 'current-page-prefix'=>"", 'current-page-suffix'=>"", 'end'=>"
") ) ); // Constants SDVA($YetAnotherGallery->URLcharacters, array('!', '*', "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "?", "%", "#", "[", "]", "<", ">") ); SDVA($YetAnotherGallery->URLcodes, array('%21', '%2A', '%27', '%28', '%29', '%3B', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%3F', '%25', '%23', '%5B', '%5D', '%3C', '%3E') ); // ============================================== // JavaScripts for handling the gallery show SDVA($YetAnotherGallery->HandleClick_FunctionContent, array ( // variables: url, caption, num, GalleryName 'default' => " window.location = url; ", 'popup' => " var thepop = window.open(url,'YAGwindow', ". " 'top=0,left=0,width=\$containerwidth,height=\$containerheight,". " location=1,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0' ); ". " thepop.focus(); " , 'self' => " window.location = url; ", 'div' => " var containerImg = document.getElementById('YAGdivContainerImg_'+GalleryName); ". " var containerCaption = document.getElementById('YAGdivContainerCaption_'+GalleryName); ". " containerImg.style.opacity=0.4; containerImg.style.filter='alpha(opacity=40)'; ". " containerCaption.innerHTML='Loading image...'; ". " var pic = new Image(); pic.src = url;". " if(pic.complete) donePic(); else pic.onload= donePic;". " function donePic() { containerImg.src = pic.src; ". " containerImg.style.opacity=1.0; containerImg.style.filter='alpha(opacity=100)'; ". " containerCaption.innerHTML = caption; } ", 'lfloat' => " var containerImg = document.getElementById('YAGdivContainerImg_'+GalleryName); ". " var containerCaption = document.getElementById('YAGdivContainerCaption_'+GalleryName); ". " containerImg.style.opacity=0.4; containerImg.style.filter='alpha(opacity=40)'; ". " containerCaption.innerHTML='Loading image...'; ". " var pic = new Image(); pic.src = url;". " if(pic.complete) donePic(); else pic.onload= donePic;". " function donePic() { containerImg.src = pic.src; ". " containerImg.style.opacity=1.0; containerImg.style.filter='alpha(opacity=100)'; ". " containerCaption.innerHTML = caption; } " ) ); // ============================================== function YetAnotherGalleryHTML($optionString, $imagesString, $pagename) { global $YetAnotherGallery, $_GET, $ScriptUrl, $UploadDir, $UploadPrefixFmt; SDV($YetAnotherGallery->PmwikiUrl, dirname($ScriptUrl) ); // ------------------------------------------------- // Parse the markup $YAGoptions = array('cols'=>''.$YetAnotherGallery->cols, 'maxrows'=>''.$YetAnotherGallery->maxrows, 'imgmaxwidth'=>''.$YetAnotherGallery->imgmaxwidth, 'imgmaxheight'=>''.$YetAnotherGallery->imgmaxheight, 'convertoptions'=>$YetAnotherGallery->convertoptions, 'style'=>$YetAnotherGallery->style, 'containerwidth'=>$YetAnotherGallery->containerwidth, 'containerheight'=>$YetAnotherGallery->containerheight, 'captiontype'=>$YetAnotherGallery->captiontype, 'urlbase'=>'', 'refreshcache'=>'yes' ); # 'refreshcache'=>'no' ); $optionsarray = ParseArgs_YAG($optionString); foreach ($optionsarray as $k=>$v) $YAGoptions[$k] = $v; // Version compatibility: if( isset($optionsarray['container']) && !isset($optionsarray['style']) ) $YAGoptions['style'] = $YAGoptions['style'] . $optionsarray['container']; // security checks $YAGoptions['cols'] = "".intval($YAGoptions['cols']); $YAGoptions['maxrows'] = "".intval($YAGoptions['maxrows']); $YAGoptions['imgmaxwidth'] = "".intval($YAGoptions['imgmaxwidth']); $YAGoptions['imgmaxheight'] = "".intval($YAGoptions['imgmaxheight']); $YAGoptions['convertoptions'] = str_replace(';','',$YAGoptions['convertoptions']); $YAGoptions['containerwidth'] = "".intval($YAGoptions['containerwidth']); $YAGoptions['containerheight'] = "".intval($YAGoptions['containerheight']); $YAGoptions['refreshcache'] = str_replace(';','',$YAGoptions['refreshcache']); if ( !$YetAnotherGallery->allowUserCaptiontype ) $YAGoptions['captiontype']=$YetAnotherGallery->captiontype; $YAGoptions['convertoptionsFull'] = str_replace( array("{imgmaxwidth}","{imgmaxheight}"), array($YAGoptions['imgmaxwidth'],$YAGoptions['imgmaxheight']), $YAGoptions['convertoptions'] ); if ( !isset($YAGoptions['name']) ) $YAGoptions['name'] = ""; if ( isset($_GET["YAGpage_".$YAGoptions['name']]) ) $YAGpageno = $_GET["YAGpage_".$YAGoptions['name']]; else $YAGpageno = 1; $PageNo = $YAGpageno; $GalleryName = $YAGoptions['name']; $containerheight = $YAGoptions['containerheight']; $containerwidth = $YAGoptions['containerwidth']; // Check and set styles $YAGoptions['style'] = $YAGoptions['style']; foreach(array("cellStyle", "imgDivStyle", "imgStyle", "captionDiv", "imgMouseOverJavascript", "imgMouseOutJavascript", "GalleryDivContainerFmt", "GalleryHeaderFmt", "GalleryFooterFmt", "HandleClick_FunctionContent") as $p) { $YAGstyleVars->{$p} = $YetAnotherGallery->{$p}['default']; foreach($YetAnotherGallery->{$p} as $k=>$v) if (strrpos($YAGoptions['style'], $k)!==false) $YAGstyleVars->{$p} = $v; } $containerHTML = $YAGstyleVars->GalleryDivContainerFmt; $YAGcols = intval($YAGoptions['cols']); $YAGmaxrows = intval($YAGoptions['maxrows']); if ($YAGmaxrows <=0 ) $YAGmatrixCount = 10000000; else $YAGmatrixCount = $YAGcols * $YAGmaxrows; $YAGcolwidth = 100 / $YAGcols; // ------------------------------------------------- // Initiate the JavaScript $outJS = "\n\n"; // --------------------------------------------------------------------------------------- if ( $YetAnotherGallery->allowCustomPHPhandler && isset($YAGoptions['customPHPhandler']) ) { // $YAGoptions['customPHPhandler'] is a function name of the form: fun( &$images, &$options ) // $images is an array of objects with keys 'URL', 'Caption' and 'thumbURL' return ( $YAGoptions['customPHPhandler']($YAGimages, $YAGoptions) ); } else return $outHTML.$outJS; } function YetAnotherGalleryReadCache($RawURL, &$YAGoptions) // Can be used as an independent function! { global $YetAnotherGallery; $RawURLmd5 = md5($RawURL.$YAGoptions['name']); $CacheFileName = $RawURLmd5.'.'.$YetAnotherGallery->thumbtype; if ($YAGoptions['refreshcache']=='yes' || (array_key_exists('YAGrefresh',$_GET) && $_GET['YAGrefresh']="yes")) $ForceRefresh = true; else $ForceRefresh = false; if ($ForceRefresh && file_exists($YetAnotherGallery->cache.$CacheFileName)) @unlink($YetAnotherGallery->cache.$CacheFileName); if ($ForceRefresh || !file_exists($YetAnotherGallery->cache.$CacheFileName)) { $sysCommand = "convert ".$RawURL." ". $YAGoptions['convertoptionsFull']. " ".$YetAnotherGallery->cache.$CacheFileName. " 2>&1"; $shellOut = shell_exec($sysCommand); } if (file_exists($YetAnotherGallery->cache.$CacheFileName)) return ($YetAnotherGallery->cacheURL.$CacheFileName); else return "ERROR: ".$shellOut; } // ================================== function ParseArgs_YAG($x, $optpat = "(?>(\\w+)\\s*[:=]\\s*)", $valpat = "(\"[^\"]*\"|'[^']*'|[^,;]+|\\S+)", $stripquotepat = "/^\\s*(['\"])?(.*)\\1\\s*[,;]?\\s*$/" ) { $z = array(); preg_match_all("/($optpat|[-+])$valpat/", $x, $terms, PREG_SET_ORDER); foreach($terms as $t) { $v = preg_replace($stripquotepat, '$2', $t[3]); if ($t[2]) { $z['#'][] = $t[2]; $z[$t[2]] = $v; } else { $z['#'][] = $t[1]; $z[$t[1]][] = $v; } $z['#'][] = $v; } return $z; } // ================================== function ParseWildcard_YAG($sprintfStr, $CardStr) { $CardParts = explode(":", $CardStr); $params = explode(",", $CardParts[1]); foreach ($params as $k=>$v) { $params[$k] = trim($params[$k]); if (is_numeric($params[$k])) eval("\$params[".$k."] = ".$params[$k].";"); } $arr = array(); switch (strtolower(trim($CardParts[0]))) { case "range": // range: start, end, step if (count($params) >= 3) $arr = range($params[0],$params[1],$params[2]); else $arr = range($params[0],$params[1]); break; case "list": // list: item1, item2, item3, ... foreach ($params as $v) $arr[]=$v; break; } $outArr = array(); foreach ($arr as $a) $outArr[] = sprintf($sprintfStr, $a); return ($outArr); } // ================================== function GetAbsShellPathFromURL_YAG($RawURL, $check_exist=false) { global $YetAnotherGallery; $RawURL = trim(urldecode($RawURL)); if ( substr($RawURL,0,strlen($YetAnotherGallery->PmwikiUrl)) == $YetAnotherGallery->PmwikiUrl ) $LocalPath = $YetAnotherGallery->ShellPWD . substr($RawURL, strlen($YetAnotherGallery->PmwikiUrl)); else $LocalPath = false; if ($check_exist && !file_exists($LocalPath)) $LocalPath = false; return $LocalPath; } function GetURLfromShellPath_YAG($RawPath) { global $YetAnotherGallery, $EnableDirectDownload, $UploadUrlFmt, $UploadPrefixFmt; if ( substr($RawPath,0,strlen($YetAnotherGallery->ShellPWD)) == $YetAnotherGallery->ShellPWD ) $RawPath = substr($RawPath,strlen($YetAnotherGallery->ShellPWD)); $RawPath = trim($RawPath, "/\\"); $downURL = $YetAnotherGallery->PmwikiUrl ."/". $RawPath; $downURLparts = pathinfo($downURL); // Test if this is the upload folder if ( substr($downURLparts['dirname'],0,strlen("$UploadUrlFmt/"))=="$UploadUrlFmt/" ) $returl = FmtPageName( IsEnabled($EnableDirectDownload, 1)? "$UploadUrlFmt$UploadPrefixFmt/": "\$PageUrl?action=download&upname=", substr($downURLparts['dirname'],strlen("$UploadUrlFmt/")) ) . $downURLparts['basename']; else $returl = $downURL; return $returl; } ?>