function FancyZoomImage($Source, $Attributes = array()) { // defaults if (!is_array($Attributes)) { $Attributes = array(); } $NoHiding = GetValue('NoHiding', $Attributes, '', True); $bSaveImage = False; $Hash = Crc32Value($Source, $Attributes); $Filename = pathinfo($Source, PATHINFO_FILENAME); $Extension = pathinfo($Source, PATHINFO_EXTENSION); if (!array_key_exists('SmallImage', $Attributes)) { // make directory $TargetFolder = 'uploads/cached'; // cache directory if (!is_dir($TargetFolder)) { mkdir($TargetFolder, 0777, True); } $SmallImage = GenerateCleanTargetName($TargetFolder, $Filename . '-' . $Hash, $Extension, False, True); $Attributes['SmallImage'] = $SmallImage; if (!file_exists($SmallImage)) { $bSaveImage = True; } } // get attributes $Width = ArrayValue('width', $Attributes, ''); $Height = ArrayValue('height', $Attributes, ''); $Crop = GetValue('Crop', $Attributes, False, True); $SmallImage = GetValue('SmallImage', $Attributes, '', True); $ZoomAttributes = array('id' => 'p' . $Hash); if (!$NoHiding) { $ZoomAttributes['style'] = 'display:none'; } //if (!array_key_exists('alt', $Attributes)) $Attributes['alt'] = $Filename; TouchValue('alt', $Attributes, $Filename); if ($bSaveImage) { Gdn_UploadImage::SaveImageAs($Source, $SmallImage, $Height, $Width, $Crop); } $SmallImage = Img($SmallImage, $Attributes); $ZoomImage = Img($Source, array('alt' => ArrayValue('alt', $Attributes, ''))); return "\n" . Wrap($SmallImage, 'a', array('href' => '#p' . $Hash)) . Wrap($ZoomImage, 'div', $ZoomAttributes); }
function SmallImage($Source, $Attributes = array()) { if (function_exists('Debug') && Debug()) { trigger_error('SmallImage() is deprecated. Use Thumbnail().', E_USER_DEPRECATED); } $Width = ArrayValue('width', $Attributes, ''); $Height = ArrayValue('height', $Attributes, ''); $ImageQuality = GetValue('ImageQuality', $Attributes, 100, True); $Crop = GetValue('Crop', $Attributes, False, True); $Hash = Crc32Value($Source, array($Width, $Height, $ImageQuality, $Crop)); $TargetFolder = 'uploads/cached'; // cache directory if (!is_dir($TargetFolder)) { mkdir($TargetFolder, 0777, True); } $Filename = pathinfo($Source, 8); $Extension = pathinfo($Source, 4); $SmallImage = GenerateCleanTargetName($TargetFolder, $Filename . '-' . $Hash, $Extension, False, True); if (!file_exists($SmallImage)) { Gdn_UploadImage::SaveImageAs($Source, $SmallImage, $Height, $Width, $Crop); } if (GetValue('MakeOnly', $Attributes, False, True)) { if (GetValue('OutOriginalImageSize', $Attributes, False, True)) { // TEMP, TODO: FIX ME $Return = array(); $Return['ImageSize'] = getimagesize($Source); $Return['Result'] = Url($SmallImage); return $Return; } return Url($SmallImage); } TouchValue('alt', $Attributes, $Filename); // Fail. ImageSY expects parameter 1 to be resource //if (!array_key_exists('height', $Attributes)) TouchValue('height', $Attributes, ImageSY($SmallImage)); //if (!array_key_exists('width', $Attributes)) TouchValue('width', $Attributes, ImageSX($SmallImage)); return Img($SmallImage, $Attributes); }
/** * Creates phpQuery document from string or file. * Options: * FixHtml (True|False): Clean content by HtmlFormatter * phpQuery is a server-side, chainable, CSS3 selector driven Document Object Model (DOM), * API based on jQuery JavaScript Library. * More information: http://code.google.com/p/phpquery/ * * @param mixed $Document, string, file or url. * @return PhpQueryDocument object. */ function PqDocument($Document, $Options = False) { if (!function_exists('Pq')) { require_once USEFULFUNCTIONS_VENDORS . '/phpQuery.php'; } $Cache = GetValue('Cache', $Options); if ($Cache) { $Name = Crc32Value($Options); if ($Cache === True) { $Name = Crc32Value($Document, $Name); } $CacheDirectory = PATH_CACHE . '/PqDocument'; if (!is_dir($CacheDirectory)) { mkdir($CacheDirectory, 0777, True); } $CacheFile = $CacheDirectory . DS . $Name . '.php'; if (file_exists($CacheFile)) { $IncludeCache = True; if (is_numeric($Cache)) { $Created = filemtime($CacheFile); $LifeTime = time() - $Created; if ($LifeTime > $Cache) { // Cache expired. $IncludeCache = False; } } if ($IncludeCache) { $Document = (include $CacheFile); return phpQuery::newDocumentXHTML($Document); } } } if (strpos($Document, '<') === False) { if (is_file($Document) || substr($Document, 0, 7) == 'http://') { $Document = file_get_contents($Document); } } if (ArrayValue('ConvertEncoding', $Options)) { $Document = ConvertEncoding($Document); } if (ArrayValue('FixHtml', $Options, True)) { $HtmlFormatter = Gdn::Factory('HtmlFormatter'); if ($HtmlFormatter) { $Document = $HtmlFormatter->Format($Document); } } elseif (ArrayValue('Body', $Options, False)) { $BodyPos1 = strpos($Document, '<body'); $EndTag = '</body>'; $BodyPos2 = strrpos($Document, $EndTag); if ($BodyPos1 !== False) { if ($BodyPos2 === False) { $Document = substr($Document, $BodyPos1); } else { $Document = substr($Document, $BodyPos1, strlen($Document) - $BodyPos1 - strlen($EndTag)); } } } if ($Cache) { $Contents = "<?php if(!defined('APPLICATION')) exit(); \nreturn " . var_export($Document, True) . ';'; file_put_contents($CacheFile, $Contents); } return phpQuery::newDocumentXHTML($Document); }