129.cache.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php return '/**
  2. * Gallery
  3. *
  4. * Copyright 2010-2012 by Shaun McCormick <shaun@modx.com>
  5. *
  6. * Gallery is free software; you can redistribute it and/or modify it under the
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation; either version 2 of the License, or (at your option) any later
  9. * version.
  10. *
  11. * Gallery is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  13. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * Gallery; if not, write to the Free Software Foundation, Inc., 59 Temple
  17. * Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * @package gallery
  20. */
  21. /**
  22. * The main Gallery snippet.
  23. *
  24. * @var modX $modx
  25. * @var Gallery $gallery
  26. *
  27. * @package gallery
  28. */
  29. $gallery = $modx->getService(\'gallery\',\'Gallery\',$modx->getOption(\'gallery.core_path\',null,$modx->getOption(\'core_path\').\'components/gallery/\').\'model/gallery/\',$scriptProperties);
  30. if (!($gallery instanceof Gallery)) return \'\';
  31. $modx->lexicon->load(\'gallery:web\');
  32. /* check for REQUEST vars if property set */
  33. $imageGetParam = $modx->getOption(\'imageGetParam\',$scriptProperties,\'galItem\');
  34. $albumRequestVar = $modx->getOption(\'albumRequestVar\',$scriptProperties,\'galAlbum\');
  35. $tagRequestVar = $modx->getOption(\'tagRequestVar\',$scriptProperties,\'galTag\');
  36. if ($modx->getOption(\'checkForRequestAlbumVar\',$scriptProperties,true)) {
  37. if (!empty($_REQUEST[$albumRequestVar])) $scriptProperties[\'album\'] = $_REQUEST[$albumRequestVar];
  38. }
  39. if ($modx->getOption(\'checkForRequestTagVar\',$scriptProperties,true)) {
  40. if (!empty($_REQUEST[$tagRequestVar])) $scriptProperties[\'tag\'] = $_REQUEST[$tagRequestVar];
  41. }
  42. if (empty($scriptProperties[\'album\']) && empty($scriptProperties[\'tag\'])) return \'\';
  43. $data = $modx->call(\'galItem\',\'getList\',array(&$modx,$scriptProperties));
  44. $totalVar = $modx->getOption(\'totalVar\', $scriptProperties, \'total\');
  45. $modx->setPlaceholder($totalVar,$data[\'total\']);
  46. /* load plugins */
  47. $plugin = $modx->getOption(\'plugin\',$scriptProperties,\'\');
  48. if (!empty($plugin)) {
  49. $pluginPath = $modx->getOption(\'pluginPath\',$scriptProperties,\'\');
  50. if (empty($pluginPath)) {
  51. $pluginPath = $gallery->config[\'modelPath\'].\'gallery/plugins/\';
  52. }
  53. /** @var GalleryPlugin $plugin */
  54. if (($className = $modx->loadClass($plugin,$pluginPath,true,true))) {
  55. $plugin = new $className($gallery,$scriptProperties);
  56. $plugin->load();
  57. $scriptProperties = $plugin->adjustSettings($scriptProperties);
  58. } else {
  59. return $modx->lexicon(\'gallery.plugin_err_load\',array(\'name\' => $plugin,\'path\' => $pluginPath));
  60. }
  61. } else {
  62. if ($modx->getOption(\'useCss\',$scriptProperties,true)) {
  63. $modx->regClientCSS($gallery->config[\'cssUrl\'].\'web.css\');
  64. }
  65. }
  66. /* iterate */
  67. $imageProperties = $modx->getOption(\'imageProperties\',$scriptProperties,\'\');
  68. $imageProperties = !empty($imageProperties) ? $modx->fromJSON($imageProperties) : array();
  69. $imageProperties = array_merge(array(
  70. \'w\' => (int)$modx->getOption(\'imageWidth\',$scriptProperties,500),
  71. \'h\' => (int)$modx->getOption(\'imageHeight\',$scriptProperties,500),
  72. \'zc\' => (boolean)$modx->getOption(\'imageZoomCrop\',$scriptProperties,0),
  73. \'far\' => (string)$modx->getOption(\'imageFar\',$scriptProperties,false),
  74. \'q\' => (int)$modx->getOption(\'imageQuality\',$scriptProperties,90),
  75. ),$imageProperties);
  76. $thumbProperties = $modx->getOption(\'thumbProperties\',$scriptProperties,\'\');
  77. $thumbProperties = !empty($thumbProperties) ? $modx->fromJSON($thumbProperties) : array();
  78. $thumbProperties = array_merge(array(
  79. \'w\' => (int)$modx->getOption(\'thumbWidth\',$scriptProperties,100),
  80. \'h\' => (int)$modx->getOption(\'thumbHeight\',$scriptProperties,100),
  81. \'zc\' => (boolean)$modx->getOption(\'thumbZoomCrop\',$scriptProperties,1),
  82. \'far\' => (string)$modx->getOption(\'thumbFar\',$scriptProperties,\'C\'),
  83. \'q\' => (int)$modx->getOption(\'thumbQuality\',$scriptProperties,90),
  84. ),$thumbProperties);
  85. $idx = 0;
  86. $output = array();
  87. $filesUrl = $modx->call(\'galAlbum\',\'getFilesUrl\',array(&$modx));
  88. $filesPath = $modx->call(\'galAlbum\',\'getFilesPath\',array(&$modx));
  89. $itemCls = $modx->getOption(\'itemCls\',$scriptProperties,\'gal-item\');
  90. $imageAttributes = $modx->getOption(\'imageAttributes\',$scriptProperties,\'\');
  91. $linkAttributes = $modx->getOption(\'linkAttributes\',$scriptProperties,\'\');
  92. $linkToImage = $modx->getOption(\'linkToImage\',$scriptProperties,false);
  93. $activeCls = $modx->getOption(\'activeCls\',$scriptProperties,\'gal-item-active\');
  94. $highlightItem = $modx->getOption($imageGetParam,$_REQUEST,false);
  95. $defaultThumbTpl = $modx->getOption(\'thumbTpl\',$scriptProperties,\'galItemThumb\');
  96. /** @var galItem $item */
  97. if (!is_array($data)) return \'\';
  98. // prep for &thumbTpl_N
  99. $keys = array_keys($scriptProperties);
  100. $nthTpls = array();
  101. foreach($keys as $key) {
  102. $keyBits = $gallery->explodeAndClean($key, \'_\');
  103. if (isset($keyBits[0]) && $keyBits[0] === \'thumbTpl\') {
  104. if ($i = (int) $keyBits[1]) $nthTpls[$i] = $scriptProperties[$key];
  105. }
  106. }
  107. ksort($nthTpls);
  108. foreach ($data[\'items\'] as $item) {
  109. $itemArray = $item->toArray();
  110. $itemArray[\'idx\'] = $idx;
  111. $itemArray[\'cls\'] = $itemCls;
  112. if ($itemArray[\'id\'] == $highlightItem) {
  113. $itemArray[\'cls\'] .= \' \'.$activeCls;
  114. }
  115. $itemArray[\'filename\'] = basename($item->get(\'filename\'));
  116. $itemArray[\'image_absolute\'] = $item->get(\'base_url\').$filesUrl.$item->get(\'filename\');
  117. $itemArray[\'fileurl\'] = $itemArray[\'image_absolute\'];
  118. $itemArray[\'filepath\'] = $filesPath.$item->get(\'filename\');
  119. $itemArray[\'filesize\'] = $item->get(\'filesize\');
  120. $itemArray[\'thumbnail\'] = $item->get(\'thumbnail\',$thumbProperties);
  121. $itemArray[\'image\'] = $item->get(\'thumbnail\',$imageProperties);
  122. $itemArray[\'image_attributes\'] = $imageAttributes;
  123. $itemArray[\'link_attributes\'] = $linkAttributes;
  124. if (!empty($scriptProperties[\'album\'])) $itemArray[\'album\'] = $scriptProperties[\'album\'];
  125. if (!empty($scriptProperties[\'tag\'])) $itemArray[\'tag\'] = $scriptProperties[\'tag\'];
  126. $itemArray[\'linkToImage\'] = $linkToImage;
  127. $itemArray[\'url\'] = $item->get(\'url\');
  128. $itemArray[\'imageGetParam\'] = $imageGetParam;
  129. $itemArray[\'albumRequestVar\'] = $albumRequestVar;
  130. $itemArray[\'tagRequestVar\'] = $tagRequestVar;
  131. $itemArray[\'tag\'] = \'\';
  132. if ($plugin) {
  133. $plugin->renderItem($itemArray);
  134. }
  135. $thumbTpl = $defaultThumbTpl;
  136. if (isset($nthTpls[$idx])) {
  137. $thumbTpl = $nthTpls[$idx];
  138. } else {
  139. foreach ($nthTpls as $int => $tpl) {
  140. if ( ($idx % $int) === 0 ) $thumbTpl = $tpl;
  141. }
  142. }
  143. $output[] = $gallery->getChunk($thumbTpl,$itemArray);
  144. $idx++;
  145. }
  146. $output = implode("\\n",$output);
  147. /* if set, place in a container tpl */
  148. $containerTpl = $modx->getOption(\'containerTpl\',$scriptProperties,false);
  149. if (!empty($containerTpl)) {
  150. $ct = $gallery->getChunk($containerTpl,array(
  151. \'thumbnails\' => $output,
  152. \'album_name\' => $data[\'album\'][\'name\'],
  153. \'album_description\' => $data[\'album\'][\'description\'],
  154. \'album_year\' => isset($data[\'album\'][\'year\']) ? $data[\'album\'][\'year\'] : \'\',
  155. \'albumRequestVar\' => $albumRequestVar,
  156. \'albumId\' => $data[\'album\'][\'id\'],
  157. ));
  158. if (!empty($ct)) $output = $ct;
  159. }
  160. /* set to placeholders or output directly */
  161. $toPlaceholder = $modx->getOption(\'toPlaceholder\',$scriptProperties,false);
  162. if (!empty($toPlaceholder)) {
  163. $modx->toPlaceholders(array(
  164. $toPlaceholder => $output,
  165. $toPlaceholder.\'.id\' => $data[\'album\'][\'id\'],
  166. $toPlaceholder.\'.name\' => $data[\'album\'][\'name\'],
  167. $toPlaceholder.\'.year\' => isset($data[\'album\'][\'year\']) ? $data[\'album\'][\'year\'] : \'\',
  168. $toPlaceholder.\'.description\' => $data[\'album\'][\'description\'],
  169. $toPlaceholder.\'.total\' => $data[\'total\'],
  170. $toPlaceholder.\'.next\' => $data[\'album\'][\'id\'] + 1,
  171. $toPlaceholder.\'.prev\' => $data[\'album\'][\'id\'] - 1,
  172. ));
  173. } else {
  174. $placeholderPrefix = $modx->getOption(\'placeholderPrefix\',$scriptProperties,\'gallery.\');
  175. $modx->toPlaceholders(array(
  176. $placeholderPrefix.\'id\' => $data[\'album\'][\'id\'],
  177. $placeholderPrefix.\'name\' => $data[\'album\'][\'name\'],
  178. $placeholderPrefix.\'year\' => isset($data[\'album\'][\'year\']) ? $data[\'album\'][\'year\'] : \'\',
  179. $placeholderPrefix.\'description\' => $data[\'album\'][\'description\'],
  180. $placeholderPrefix.\'total\' => $data[\'total\'],
  181. $placeholderPrefix.\'next\' => $data[\'album\'][\'id\'] + 1,
  182. $placeholderPrefix.\'prev\' => $data[\'album\'][\'id\'] - 1,
  183. ));
  184. return $output;
  185. }
  186. return \'\';
  187. return;
  188. ';