. *
* *
* *
* Contact: subhrajit@gmail.com, http://www.subhrajit.net/ *
* *
* *
******************************************************************************************
*/
/* Syntax:
YAG [option1=o1, option2=o2, ...] { url | caption && url | caption && ... }
See http://www.pmwiki.org/wiki/Cookbook/YAG for more details
*/
Markup(
'YAG',
'fulltext',
"/YAG\\s*\\[(.*?)\\]\\s*\\{(.*?)\\}/esi",
"Keep(YetAnotherGalleryHTML(PSS('$1'),PSS('$2')))" );
// Parameters
SDV($YetAnotherGallery->cache, $FarmD.'/pub/YetAnotherGalleryCache/' );
SDV($YetAnotherGallery->cacheURL, $PubDirUrl.'/YetAnotherGalleryCache/' );
// 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);
// ---------------------------------------------
// 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' => "
",
'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' => "",
'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)
{
global $YetAnotherGallery, $_GET, $YAGoptions, $pagename;
// -------------------------------------------------
// 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'=>'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";
return $outHTML.$outJS;
}
function YetAnotherGalleryReadCache($RawURL)
{
global $YetAnotherGallery, $YAGoptions;
$RawURLmd5 = md5($RawURL);
$CacheFileName = $RawURLmd5.'.'.$YetAnotherGallery->thumbtype;
if ($YAGoptions['refreshcache']=='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 false;
}
// ==================================
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);
}
?>