1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866: 867: 868: 869: 870: 871: 872: 873: 874: 875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887: 888: 889: 890: 891: 892: 893: 894: 895: 896: 897: 898: 899: 900: 901: 902: 903: 904: 905: 906: 907: 908: 909: 910: 911: 912: 913: 914: 915: 916: 917: 918: 919: 920: 921: 922: 923: 924: 925: 926: 927: 928: 929: 930: 931: 932: 933: 934: 935: 936: 937: 938: 939: 940: 941: 942: 943: 944: 945: 946: 947: 948: 949: 950: 951: 952: 953: 954: 955: 956: 957: 958: 959: 960: 961: 962: 963: 964: 965: 966: 967: 968: 969: 970: 971: 972: 973: 974: 975: 976: 977: 978: 979: 980: 981: 982: 983: 984: 985: 986: 987: 988: 989: 990: 991: 992: 993: 994: 995: 996: 997: 998: 999: 1000:
<?php
$plugin_is_filter = 5 | ADMIN_PLUGIN;
$plugin_description = gettext("Provides cache management utilities for Image, HTML, and RSS caches.");
$plugin_author = "Stephen Billard (sbillard), Malte Müller (acrylian)";
$plugin_category = gettext('Admin');
$option_interface = 'cacheManager';
require_once(SERVERPATH . '/' . ZENFOLDER . '/class-feed.php');
zp_register_filter('admin_utilities_buttons', 'cacheManager::overviewbutton');
zp_register_filter('edit_album_utilities', 'cacheManager::albumbutton', -9999);
zp_register_filter('show_change', 'cacheManager::published');
$_zp_cached_feeds = array('RSS');
class cacheManagerFeed extends feed {
protected $feed = NULL;
function __construct($feed) {
$this->feed = $feed;
}
}
class cacheManager {
public static $sizes = array();
public static $enabledsizes = array();
public static $albums_cached = 0;
public static $images_cached = 0;
public static $imagesizes_total = 0;
public static $starttime = 0;
public static $imagesizes_cached = 0;
public static $imagesizes_failed = 0;
public static $missingimages = null;
function __construct() {
self::deleteCacheSizes('admin');
self::addCacheSize('admin', 40, NULL, NULL, 40, 40, NULL, NULL, -1);
self::addCacheSize('admin', 80, NULL, NULL, 80, 80, NULL, NULL, -1);
setOptionDefault('cachemanager_defaultthumb', 1);
setOptionDefault('cachemanager_defaultsizedimage', 1);
setOptionDefault('cachemanager_generationmode', 'classic');
}
function getOptionsSupported() {
$options = array(
gettext('Image caching sizes') => array(
'key' => 'cropImage_list',
'type' => OPTION_TYPE_CUSTOM,
'order' => 1,
'desc' => '<p>' .
gettext('Cropped images will be made in these parameters if the <em>Create image</em> box is checked. Un-check to box to remove the settings.' .
'You can determine the values for these fields by examining your cached images. The file names will look something like these:') .
'<ul>' .
'<li>' . gettext('<code>photo_595.jpg</code>: sized to 595 pixels') . '</li>' .
'<li>' . gettext('<code>photo_w180_cw180_ch80_thumb.jpg</code>: a size of 180px wide and 80px high and it is a thumbnail (<code>thumb</code>)') . '</li>' .
'<li>' . gettext('<code>photo_85_cw72_ch72_thumb_copyright_gray.jpg</code>: sized 85px cropped at about 7.6% (one half of 72/85) from the horizontal and vertical sides with a watermark (<code>copyright</code>) and rendered in grayscale (<code>gray</code>).') . '</li>' .
'<li>' . gettext('<code>photo_w85_h85_cw350_ch350_cx43_cy169_thumb_copyright.jpg</code>: a custom cropped 85px thumbnail with watermark.') . '</li>' .
'</ul>' .
'</p>' .
'<p>' .
gettext('If a field is not represented in the cached name, leave the field blank. Custom crops (those with cx and cy) really cannot be cached easily since each image has unique values. ' .
'See the <em>template-functions</em>::<code>getCustomImageURL()</code> comment block for details on these fields.') .
'</p>' .
'<p>' .
gettext('Some themes use <em>MaxSpace</em> image functions. To cache images referenced by these functions set the <em>width</em> and <em>height</em> parameters to the <em>MaxSpace</em> container size and check the <code>MaxSpace</code> checkbox.') .
'</p>'
)
);
$list = array(
'<em>' . gettext('Albums') . '</em>' => 'cacheManager_albums',
'<em>' . gettext('Images') . '</em>' => 'cacheManager_images');
if (extensionEnabled('zenpage')) {
$list['<em>' . gettext('News') . '</em>'] = 'cacheManager_news';
$list['<em>' . gettext('Pages') . '</em>'] = 'cacheManager_pages';
} else {
setOption('cacheManager_news', 0);
setOption('cacheManager_pages', 0);
}
$options[gettext('Purge cache files')] = array(
'key' => 'cacheManager_items',
'type' => OPTION_TYPE_CHECKBOX_ARRAY,
'order' => 0,
'checkboxes' => $list,
'desc' => gettext('If a <em>type</em> is checked, the HTML and RSS caches for the item will be purged when the published state of an item of <em>type</em> changes.') .
'<div class="notebox">' . gettext('<strong>NOTE:</strong> The entire cache is cleared since there is no way to ascertain if a gallery page contains dependencies on the item.') . '</div>'
);
$options[gettext('Cache default sizes')] = array(
'key' => 'cachemanager_defaultsizes',
'type' => OPTION_TYPE_CHECKBOX_ARRAY,
'order' => 0,
'checkboxes' => array(
gettext('Default thumb size') => 'cachemanager_defaultthumb',
gettext('Default sized image') => 'cachemanager_defaultsizedimage'
),
'desc' => gettext('If enabled the default thumb size (or if set a manual crop) and/or the default sized image as set on the theme options are enabled for caching. Themes or plugins can request to override this option being disabled by defining <code>addThemeDefaultThumbSize()</code> and/or <code>addThemeDefaultSizedImageSize()</code> on their option definitions.')
);
$options[gettext('Pre-caching generation mode')] = array(
'key' => 'cachemanager_generationmode',
'type' => OPTION_TYPE_RADIO,
'order' => 0,
'buttons' => array(
gettext('Classic') => 'classic',
gettext('cURL') => 'curl'
),
'desc' => gettext('Choose the way how the cachemanager generates the cache sizes via its utility.')
. '<ul>'
. '<li>' . gettext('<em>Classic</em> (default) outputs the image sizes to generate directly. This is faster and works basically on all servers but is not always creating all sizes reliably so the process may have to be repeated.') . '</li>'
. '<li>' . gettext('<em>cURL</em> uses PHP cURL requests to generate the images without output. Although processing time and server load is similar to the classic mode, it is actually more reliable in creating the sizes, especially if you have lots of images and albums. However this does not work properly on all servers.') . '</li>'
. '</ul>'
);
return $options;
}
function handleOption($option, $currentValue) {
global $_zp_gallery;
$currenttheme = $_zp_gallery->getCurrentTheme();
$custom = array();
$result = query('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="cacheManager" ORDER BY `aux`');
$key = 0;
while ($row = db_fetch_assoc($result)) {
$theme = $row['aux'];
$data = getSerializedArray($row['data']);
$custom[$theme][] = $data;
}
ksort($custom, SORT_LOCALE_STRING);
$custom[''] = array(array());
$c = 0;
self::printJS();
foreach ($custom as $theme => $themedata) {
$themedata = sortMultiArray($themedata, array('thumb', 'image_size', 'image_width', 'image_height'));
?>
<span class="icons" id="<?php echo $theme; ?>_arrow">
<?php
if ($theme) {
$inputclass = 'hidden';
echo '<em>' . $theme . '</em> (' . count($themedata) . ')';
} else {
$inputclass = 'textbox';
echo '<br />' . gettext('add');
}
?>
<a href="javascript:showTheme('<?php echo $theme; ?>');" title="<?php echo gettext('Show'); ?>">
<img class="icon-position-top4" src="<?php echo WEBPATH . '/' . ZENFOLDER . '/images/arrow_down.png'; ?>" alt="" />
</a>
</span>
<br />
<div id="<?php echo $theme; ?>_list" style="display:none">
<br />
<?php
foreach ($themedata as $cache) {
$key++;
if ($c % 2) {
$class = 'boxb';
} else {
$class = 'box';
}
?>
<div>
<?php
$c++;
if (isset($cache['enable']) && $cache['enable']) {
$allow = ' checked="checked"';
} else {
$allow = '';
}
?>
<div class="<?php echo $class; ?>">
<input type="<?php echo $inputclass; ?>" size="25" name="cacheManager_theme_<?php echo $key; ?>" value="<?php echo $theme; ?>" />
<?php
if ($theme) {
?>
<span class="displayinlineright"><?php echo gettext('Delete'); ?> <input type="checkbox" name="cacheManager_delete_<?php echo $key; ?>" value="1" /></span>
<input type="hidden" name="cacheManager_valid_<?php echo $key; ?>" value="1" />
<?php
}
?>
<br />
<?php
foreach (array('image_size' => gettext('Size'), 'image_width' => gettext('Width'), 'image_height' => gettext('Height'),
'crop_width' => gettext('Crop width'), 'crop_height' => gettext('Crop height'), 'crop_x' => gettext('Crop X axis'),
'crop_y' => gettext('Crop Y axis')) as $what => $display) {
if (isset($cache[$what])) {
$v = $cache[$what];
} else {
$v = '';
}
?>
<span class="nowrap"><?php echo $display; ?> <input type="textbox" size="2" name="cacheManager_<?php echo $what; ?>_<?php echo $key; ?>" value="<?php echo $v; ?>" /></span>
<?php
}
if (isset($cache['wmk'])) {
$wmk = $cache['wmk'];
} else {
$wmk = '';
}
?>
<span class="nowrap"><?php echo gettext('Watermark'); ?> <input type="textbox" size="20" name="cacheManager_wmk_<?php echo $key; ?>" value="<?php echo $wmk; ?>" /></span>
<br />
<span class="nowrap"><?php echo gettext('MaxSpace'); ?><input type="checkbox" name="cacheManager_maxspace_<?php echo $key; ?>" value="1"<?php if (isset($cache['maxspace']) && $cache['maxspace']) echo ' checked="checked"'; ?> /></span>
<span class="nowrap"><?php echo gettext('Thumbnail'); ?><input type="checkbox" name="cacheManager_thumb_<?php echo $key; ?>" value="1"<?php if (isset($cache['thumb']) && $cache['thumb']) echo ' checked="checked"'; ?> /></span>
<span class="nowrap"><?php echo gettext('Grayscale'); ?><input type="checkbox" name="cacheManager_gray_<?php echo $key; ?>" value="gray"<?php if (isset($cache['gray']) && $cache['gray']) echo ' checked="checked"'; ?> /></span>
</div>
<br />
</div>
<?php
}
?>
</div><!-- <?php echo $theme; ?>_list -->
<?php
}
}
static function printJS() {
?>
<script type="text/javascript">
function checkTheme(theme) {
$('.' + theme).prop('checked', $('#' + theme).prop('checked'));
}
function showTheme(theme) {
html = $('#' + theme + '_arrow').html();
if (html.match(/down/)) {
html = html.replace(/_down/, '_up');
html = html.replace(/title = "<?php echo gettext('Show'); ?>/, 'title="<?php echo gettext('Hide');
?>"');
$('#' + theme + '_list').show();
} else {
html = html.replace(/_up/, '_down');
html = html.replace(/title="<?php echo gettext('Hide'); ?>/, 'title="<?php echo gettext('Show'); ?>"');
$('#' + theme + '_list').hide();
}
$('#' + theme + '_arrow').html(html);
}
</script>
<?php
}
function handleOptionSave($themename, $themealbum) {
$cache = array();
foreach ($_POST as $key => $value) {
preg_match('/^cacheManager_(.*)_(.*)/', $key, $matches);
if ($value && !empty($matches)) {
$cache[$matches[2]][$matches[1]] = sanitize(trim($value));
}
}
query('DELETE FROM ' . prefix('plugin_storage') . ' WHERE `type`="cacheManager"');
foreach ($cache as $cacheimage) {
if (!isset($cacheimage['delete']) && count($cacheimage) > 1) {
$cacheimage['theme'] = preg_replace("/[\s\"\']+/", "-", $cacheimage['theme']);
$sql = 'INSERT INTO ' . prefix('plugin_storage') . ' (`type`, `aux`,`data`) VALUES ("cacheManager",' . db_quote($cacheimage['theme']) . ',' . db_quote(serialize($cacheimage)) . ')';
query($sql);
}
}
return false;
}
static function addCacheSize($owner, $size, $width, $height, $cw, $ch, $cx, $cy, $thumb, $watermark = NULL, $effects = NULL, $maxspace = false) {
$cacheSize = serialize(array(
'theme' => $owner,
'apply' => false,
'image_size' => $size,
'image_width' => $width,
'image_height' => $height,
'crop_width' => $cw,
'crop_height' => $ch,
'crop_x' => $cx,
'crop_y' => $cy,
'thumb' => $thumb,
'wmk' => $watermark,
'gray' => $effects,
'maxspace' => $maxspace,
'valid' => 1));
$sql = 'INSERT INTO ' . prefix('plugin_storage') . ' (`type`, `aux`,`data`) VALUES ("cacheManager",' . db_quote($owner) . ',' . db_quote($cacheSize) . ')';
query($sql);
}
static function addThemeCacheSize($theme, $size, $width, $height, $cw, $ch, $cx, $cy, $thumb, $watermark = NULL, $effects = NULL, $maxspace = false) {
if (class_exists('cachemanager_internal_deprecations'))
cachemanager_internal_deprecations::addThemeCacheSize();
self::addCacheSize($theme, $size, $width, $height, $cw, $ch, $cx, $cy, $thumb, $watermark, $effects, $maxspace);
}
static function addDefaultThumbSize() {
setOption('cachemanager_defaultthumb', 1);
}
static function addThemeDefaultThumbSize() {
if (class_exists('cachemanager_internal_deprecations'))
cachemanager_internal_deprecations::addThemeDefaultThumbSize();
cacheManager::addDefaultThumbSize();
}
static function addDefaultSizedImageSize() {
setOption('cachemanager_defaultsizedimage', 1);
}
static function addThemeDefaultSizedImageSize() {
if (class_exists('cachemanager_internal_deprecations'))
cachemanager_internal_deprecations::addThemeDefaultSizedImageSize();
cacheManager::addDefaultSizedImageSize();
;
}
static function published($obj) {
global $_zp_HTML_cache, $_zp_cached_feeds;
if (getOption('cacheManager_' . $obj->table)) {
$_zp_HTML_cache->clearHTMLCache();
foreach ($_zp_cached_feeds as $feed) {
$feeder = new cacheManagerFeed($feed);
$feeder->clearCache();
}
}
return $obj;
}
static function getTitle($table, $row) {
switch ($table) {
case 'images':
$album = query_single_row('SELECT `folder` FROM ' . prefix('albums') . ' WHERE `id`=' . $row['albumid']);
$title = gettext('Missing album');
if ($album) {
$title = sprintf(gettext('%1$s: image %2$s'), $album['folder'], $row['filename']);
}
break;
case 'albums':
$title = sprintf(gettext('album %s'), $row['folder']);
break;
case 'news':
case 'pages':
$title = sprintf(gettext('%1$s: %2$s'), $table, $row['titlelink']);
break;
}
return $title;
}
static function recordMissing($table, $row, $image) {
$obj = getItemByID($table, $row['id']);
if ($obj) {
cacheManager::$missingimages[] = '<a href="' . $obj->getLink() . '">' . $obj->getTitle() . '</a> (' . html_encode($image) . ')<br />';
}
}
static function updateCacheName($text, $target, $update) {
if (is_string($text) && preg_match('/^a:[0-9]+:{/', $text)) {
$text = getSerializedArray($text);
$serial = true;
} else {
$serial = false;
}
if (is_array($text)) {
foreach ($text as $key => $textelement) {
$text[$key] = self::updateCacheName($textelement, $target, $update);
}
if ($serial) {
$text = serialize($text);
}
} else {
$text = str_replace($target, $update, $text);
}
return $text;
}
static function getSizes($mode = 'all') {
$result = query('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type` = "cacheManager" ORDER BY `aux`');
while ($row = db_fetch_assoc($result)) {
$sizes[] = getSerializedArray($row['data']);
}
$sizes = sortMultiArray($sizes, array('theme', 'thumb', 'image_size', 'image_width', 'image_height'));
$sizes_filtered = array();
if ($mode == 'active' || $mode == 'inactive') {
foreach ($sizes as $size) {
if ($mode == 'active') {
if (cacheManager::isValid($size['theme'])) {
$sizes_filtered[] = $size;
}
}
if ($mode == 'inactive') {
if (!cacheManager::isValid($size['theme'])) {
$sizes_filtered[] = $size;
}
}
}
$sizes = $sizes_filtered;
}
return $sizes;
}
static function loadAlbums($albumobj) {
cachemanager::loadAlbum($albumobj);
$subalbums = $albumobj->getAlbums();
foreach ($subalbums as $folder) {
$subalbum = newAlbum($folder);
if (!$subalbum->isDynamic()) {
cachemanager::loadAlbums($subalbum);
}
}
}
static function loadAlbum($albumobj) {
global $_zp_gallery;
$theme = $_zp_gallery->getCurrentTheme();
$id = 0;
$parent = getUrAlbum($albumobj);
$albumtheme = $parent->getAlbumTheme();
if (!empty($albumtheme)) {
$theme = $albumtheme;
$id = $parent->getID();
}
loadLocalOptions($id, $theme);
echo '<li><strong>' . html_encode($albumobj->getTitle()) . '</strong> (' . html_encode($albumobj->name) . ')<ul>';
cacheManager::loadImages($albumobj);
echo '</ul></li>';
cacheManager::$albums_cached++;
?>
<script>
$('.imagecaching_albumcount').text(<?php echo cacheManager::$albums_cached; ?>);
</script>
<?php
}
static function loadImages($albumobj) {
$images = $albumobj->getImages(0);
if (is_array($images) && count($images) > 0) {
foreach ($images as $image) {
$sizes_count = 0;
$sizeuris = array();
$results = array();
$imageobj = newImage($albumobj, $image);
if (isImagePhoto($imageobj)) {
if (array_key_exists('*', cachemanager::$enabledsizes)) {
$uri = getFullImageURL($imageobj);
if (strpos($uri, 'full-image.php?') !== false) {
$sizes_count++;
$sizeuris[] = $uri;
}
}
if (array_key_exists('defaultthumb', cachemanager::$enabledsizes)) {
$thumb = $imageobj->getThumb();
if (strpos($thumb, 'i.php?') !== false) {
$sizes_count++;
$sizeuris[] = $thumb;
}
}
if (array_key_exists('defaultsizedimage', cachemanager::$enabledsizes)) {
$defaultimage = $imageobj->getSizedImage(getOption('image_size'));
if (strpos($defaultimage, 'i.php?') !== false) {
$sizes_count++;
$sizeuris[] = $defaultimage;
}
}
foreach (cacheManager::$sizes as $key => $cacheimage) {
if (array_key_exists($key, cacheManager::$enabledsizes)) {
$size = isset($cacheimage['image_size']) ? $cacheimage['image_size'] : NULL;
$width = isset($cacheimage['image_width']) ? $cacheimage['image_width'] : NULL;
$height = isset($cacheimage['image_height']) ? $cacheimage['image_height'] : NULL;
$thumbstandin = isset($cacheimage['thumb']) ? $cacheimage['thumb'] : NULL;
if ($special = ($thumbstandin === true)) {
list($special, $cw, $ch, $cx, $cy) = $imageobj->getThumbCropping($size, $width, $height);
}
if (!$special) {
$cw = isset($cacheimage['crop_width']) ? $cacheimage['crop_width'] : NULL;
$ch = isset($cacheimage['crop_height']) ? $cacheimage['crop_height'] : NULL;
$cx = isset($cacheimage['crop_x']) ? $cacheimage['crop_x'] : NULL;
$cy = isset($cacheimage['crop_y']) ? $cacheimage['crop_y'] : NULL;
}
$effects = isset($cacheimage['gray']) ? $cacheimage['gray'] : NULL;
if (isset($cacheimage['wmk'])) {
$passedWM = $cacheimage['wmk'];
} else {
if ($thumbstandin) {
$passedWM = getWatermarkParam($imageobj, WATERMARK_THUMB);
} else {
$passedWM = getWatermarkParam($imageobj, WATERMARK_IMAGE);
}
}
if (isset($cacheimage['maxspace'])) {
getMaxSpaceContainer($width, $height, $imageobj, $thumbstandin);
}
$args = array($size, $width, $height, $cw, $ch, $cx, $cy, NULL, $thumbstandin, NULL, $thumbstandin, $passedWM, NULL, $effects);
$args = getImageParameters($args, $albumobj->name);
if ($albumobj->isDynamic()) {
$folder = $imageobj->album->name;
} else {
$folder = $albumobj->name;
}
$uri = getImageURI($args, $folder, $imageobj->filename, $imageobj->filemtime);
if (strpos($uri, 'i.php?') !== false) {
$sizes_count++;
$sizeuris[] = $uri;
}
}
}
$imagetitle = html_encode($imageobj->getTitle()) . ' (' . html_encode($imageobj->filename) . '): ';
echo '<li>';
if ($sizes_count == 0) {
echo $imagetitle;
?>
<em style="color:green"><?php echo gettext('All already cached.'); ?></em>
<?php
} else {
cacheManager::$images_cached++;
echo $imagetitle;
foreach ($sizeuris as $sizeuri) {
cacheManager::generateImage($sizeuri);
$endtime_temp = time();
$time_total_temp = ($endtime_temp - cacheManager::$starttime) / 60;
?>
<script>
$('.imagecaching_imagecount').text(<?php echo cacheManager::$images_cached; ?>);
$('.imagecaching_imagesizes').text(<?php echo cacheManager::$imagesizes_cached; ?>);
$('.imagecaching_imagesizes_failed').text(<?php echo cacheManager::$imagesizes_failed; ?>);
$('.imagecaching_time').text(<?php echo round($time_total_temp, 2); ?>);
</script>
<?php
}
}
echo '</li>';
}
}
} else {
?>
<li><p class="notebox"><em><?php echo gettext('This album does not have any images.'); ?></p></li>
<?php
}
}
static function generateImage($imageuri) {
if (function_exists('curl_init') && getOption('cachemanager_generationmode') == 'curl') {
$success = generateImageCacheFile($imageuri);
if ($success) {
echo '<a href="' . html_encode(pathurlencode($imageuri)) . '&debug"><img class="icon-position-top4" src="' . WEBPATH . '/' . ZENFOLDER . '/images/pass.png" alt="" title="' . html_encode($imageuri) . '"></a>';
cacheManager::$imagesizes_cached++;
} else {
echo '<a href="' . html_encode(pathurlencode($imageuri)) . '&debug"><img src="' . WEBPATH . '/' . ZENFOLDER . '/images/fail.png" alt=""></a>';
cacheManager::$imagesizes_failed++;
}
} else {
?>
<a href="<?php echo html_encode(pathurlencode($imageuri)); ?>&debug"><img src="<?php echo html_encode(pathurlencode($imageuri)); ?>" height="25" alt="x" /></a>';
<?php
cacheManager::$imagesizes_cached++;
}
}
/**
* Used to check and skip cachemanager sizes if
* - their owner (theme or extension) isn't existing or not enabled.
* Also used to sort our default thumb/default sized image
*
* - Checks if this is from an existing theme ("admin" sizes are always valid)
* - Checks if this is from an enabeled extension
* - Checks if this is a custom size (e.g. not one of the non active plugins)
*
* @param string $owner
* @return boolean
*/
static function isValid($owner) {
global $_zp_gallery;
if ($owner == 'admin') {
return true;
}
$themes = $_zp_gallery->getThemes();
foreach($themes as $theme) {
if (strtolower($theme['name']) == strtolower($owner)) {
return true;
}
}
if (extensionEnabled($owner)) {
return true;
}
$allplugins = array_keys(getPluginFiles('*.php'));
if (!in_array($owner, $allplugins)) {
return true;
}
return false;
}
static function printSizesListEntry($value, $checked, $text, $class = null) {
$arrayindex = $value;
if (in_array($value, array('*', 'defaultthumb', 'defaultsizedimage'))) {
$arrayindex = $value;
}
if (!is_null($class)) {
$class = ' class="' . html_encode($class) . '"';
}
if (!empty(cacheManager::$enabledsizes)) {
?>
<input type="hidden" name="enable[<?php echo $arrayindex; ?>]" value="<?php echo $value; ?>" />
<?php
}
?>
<li>
<label>
<input type="checkbox" name="enable[<?php echo $arrayindex; ?>]"<?php echo $class; ?> value="<?php echo $value; ?>"<?php echo $checked; ?> />
<?php echo gettext('Apply'); ?> <code><?php echo $text; ?></code>
</label>
</li>
<?php
}
static function overviewbutton($buttons) {
if (query_single_row('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="cacheManager" LIMIT 1')) {
$enable = true;
$title = gettext('Finds images that have not been cached and creates the cached versions.');
} else {
$enable = false;
$title = gettext('You must first set the plugin options for cached image parameters.');
}
$buttons[] = array(
'category' => gettext('Cache'),
'enable' => $enable,
'button_text' => gettext('Cache manager'),
'formname' => 'cacheManager_button',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/cacheManager/cacheImages.php?page=overview&tab=images',
'icon' => 'images/cache.png',
'alt' => '',
'hidden' => '',
'rights' => ADMIN_RIGHTS,
'title' => $title
);
if (class_exists('RSS')) {
$buttons[] = array(
'XSRFTag' => 'clear_cache',
'category' => gettext('Cache'),
'enable' => true,
'button_text' => gettext('Purge RSS cache'),
'formname' => 'purge_rss_cache.php',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?action=clear_rss_cache',
'icon' => 'images/edit-delete.png',
'alt' => '',
'title' => gettext('Delete all files from the RSS cache'),
'hidden' => '<input type="hidden" name="action" value="clear_rss_cache" />',
'rights' => ADMIN_RIGHTS
);
}
$buttons[] = array(
'XSRFTag' => 'clear_cache',
'category' => gettext('Cache'),
'enable' => true,
'button_text' => gettext('Purge Image cache'),
'formname' => 'purge_image_cache.php',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?action=action=clear_cache',
'icon' => 'images/edit-delete.png',
'alt' => '',
'title' => gettext('Delete all files from the Image cache'),
'hidden' => '<input type="hidden" name="action" value="clear_cache" />',
'rights' => ADMIN_RIGHTS
);
$buttons[] = array(
'category' => gettext('Cache'),
'enable' => true,
'button_text' => gettext('Purge HTML cache'),
'formname' => 'clearcache_button',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?action=clear_html_cache',
'icon' => 'images/edit-delete.png',
'title' => gettext('Clear the static HTML cache. HTML pages will be re-cached as they are viewed.'),
'alt' => '',
'hidden' => '<input type="hidden" name="action" value="clear_html_cache">',
'rights' => ADMIN_RIGHTS,
'XSRFTag' => 'ClearHTMLCache'
);
$buttons[] = array(
'category' => gettext('Cache'),
'enable' => true,
'button_text' => gettext('Purge search cache'),
'formname' => 'clearcache_button',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/admin.php?action=clear_search_cache',
'icon' => 'images/edit-delete.png',
'title' => gettext('Clear the static search cache.'),
'alt' => '',
'hidden' => '<input type="hidden" name="action" value="clear_search_cache">',
'rights' => ADMIN_RIGHTS,
'XSRFTag' => 'ClearSearchCache'
);
$buttons[] = array(
'category' => gettext('Cache'),
'enable' => true,
'button_text' => gettext('Cleanup image cache sizes'),
'formname' => 'clearcache_button',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/cacheManager/cacheImages.php?action=cleanup_cache_sizes',
'icon' => 'images/edit-delete.png',
'title' => gettext('Removes old stored image cache sizes of themes and plugins not existing on this site. It also removes sizes from inactive plugins.'),
'alt' => '',
'hidden' => '<input type="hidden" name="action" value="cleanup_cache_sizes">',
'rights' => ADMIN_RIGHTS,
'XSRFTag' => 'CleanupCacheSizes'
);
return $buttons;
}
static function albumbutton($html, $object, $prefix) {
$html .= '<hr />';
if (query_single_row('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="cacheManager" LIMIT 1')) {
$disable = '';
$title = gettext('Finds images that have not been cached and creates the cached versions.');
} else {
$disable = ' disabled="disabled"';
$title = gettext("You must first set the plugin options for cached image parameters.");
}
$html .= '<div class="button buttons tooltip" title="' . $title . '"><a href="' . WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/cacheManager/cacheImages.php?album=' . html_encode($object->name) . '&XSRFToken=' . getXSRFToken('cacheImages') . '"' . $disable . '><img src="images/cache.png" />' . gettext('Cache album images') . '</a><br class="clearall" /></div>';
return $html;
}
static function deleteCacheSizes($owner) {
query('DELETE FROM ' . prefix('plugin_storage') . ' WHERE `type`="cacheManager" AND `aux`=' . db_quote($owner));
}
static function deleteThemeCacheSizes($owner) {
if (class_exists('cachemanager_internal_deprecations'))
cachemanager_internal_deprecations::deleteThemeCacheSizes();
self::deleteCacheSizes($owner);
}
static function cleanupCacheSizes() {
$sizes = cacheManager::getSizes('inactive');
$sizes_delete = array();
foreach ($sizes as $size) {
if (!cacheManager::isValid($size['theme'])) {
$sizes_delete[] = "'" . $size['theme'] . "'";
}
}
if (!empty($sizes_delete)) {
$delete = implode(',', $sizes_delete);
$query = query('DELETE FROM ' . prefix('plugin_storage') . ' WHERE `type`="cacheManager" AND `aux` IN (' . $delete . ')');
}
}
static function printCurlNote() {
if (!function_exists('curl_init') && getOption('cachemanager_generationmode') == 'curl') {
?>
<p class='warningbox'><?php echo gettext('Your server does not support the native PHP extension <code>cURL</code>. Pre-caching images is much more effective using it.'); ?></p>
<?php
}
}
static function printButtons($returnpage, $alb = '', $hidden = false) {
$class = '';
if ($hidden) {
$class = ' hidden';
}
?>
<p class="buttons buttons_cachefinished clearfix<?php echo $class; ?>">
<a title="<?php echo gettext('Back to the overview'); ?>" href="<?php echo WEBPATH . '/' . ZENFOLDER . $returnpage; ?>"> <img src="<?php echo FULLWEBPATH . '/' . ZENFOLDER; ?>/images/cache.png" alt="" />
<strong><?php echo gettext("Back"); ?> </strong>
</a>
<?php if (is_array(cacheManager::$enabledsizes)) { ?>
<a title="<?php echo gettext('New cache size selection'); ?>" href="<?php echo WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER; ?>/cacheManager/cacheImages.php?page=overview&tab=images&album=<?php echo $alb; ?>"> <img src="<?php echo FULLWEBPATH . '/' . ZENFOLDER; ?>/images/pass.png" alt="" />
<strong><?php echo gettext("New cache size selection"); ?> </strong>
</a>
<?php } ?>
</p>
<?php
}
}