C_Image_Wrapper

This class provides a lazy-loading wrapper to the NextGen-Legacy "nggImage" class for use in legacy style templates.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/nextgen_data/package.module.nextgen_data.php  
  1. class C_Image_Wrapper 
  2. public $_cache; 
  3. // cache of retrieved values 
  4. public $_settings; 
  5. // I_Settings_Manager cache 
  6. public $_storage; 
  7. // I_Gallery_Storage cache 
  8. public $_galleries; 
  9. // cache of I_Gallery_Mapper (plural) 
  10. public $_orig_image; 
  11. // original provided image 
  12. public $_orig_image_id; 
  13. // original image ID 
  14. public $_cache_overrides; 
  15. // allow for forcing variable values 
  16. public $_legacy = FALSE; 
  17. public $_displayed_gallery; 
  18. // cached object 
  19. /** 
  20. * Constructor. Converts the image class into an array and fills from defaults any missing values 
  21. * @param object $gallery Individual result from displayed_gallery->get_entities() 
  22. * @param object $displayed_gallery Displayed gallery -- MAY BE NULL 
  23. * @param bool $legacy Whether the image source is from NextGen Legacy or NextGen 
  24. * @return void 
  25. */ 
  26. public function __construct($image, $displayed_gallery = NULL, $legacy = FALSE) 
  27. // for clarity 
  28. if ($displayed_gallery && isset($displayed_gallery->display_settings['number_of_columns'])) { 
  29. $columns = $displayed_gallery->display_settings['number_of_columns']; 
  30. } else { 
  31. $columns = 0; 
  32. // Public variables 
  33. $defaults = array('errmsg' => '', 'error' => FALSE, 'imageURL' => '', 'thumbURL' => '', 'imagePath' => '', 'thumbPath' => '', 'href' => '', 'thumbPrefix' => 'thumbs_', 'thumbFolder' => '/thumbs/', 'galleryid' => 0, 'pid' => 0, 'filename' => '', 'description' => '', 'alttext' => '', 'imagedate' => '', 'exclude' => '', 'thumbcode' => '', 'name' => '', 'path' => '', 'title' => '', 'pageid' => 0, 'previewpic' => 0, 'style' => $columns > 0 ? 'style="width:' . floor(100 / $columns) . '%;"' : '', 'hidden' => FALSE, 'permalink' => '', 'tags' => ''); 
  34. // convert the image to an array and apply the defaults 
  35. $this->_orig_image = $image; 
  36. $image = (array) $image; 
  37. foreach ($defaults as $key => $val) { 
  38. if (!isset($image[$key])) { 
  39. $image[$key] = $val; 
  40. // cache the results 
  41. ksort($image); 
  42. $id_field = !empty($image['id_field']) ? $image['id_field'] : 'pid'; 
  43. $this->_cache = (array) apply_filters('ngg_image_object', (object) $image, $image[$id_field]); 
  44. $this->_orig_image_id = $image[$id_field]; 
  45. $this->_legacy = $legacy; 
  46. $this->_displayed_gallery = $displayed_gallery; 
  47. public function __set($name, $value) 
  48. $this->_cache[$name] = $value; 
  49. public function __isset($name) 
  50. return isset($this->_cache[$name]); 
  51. public function __unset($name) 
  52. unset($this->_cache[$name]); 
  53. /** 
  54. * Lazy-loader for image variables. 
  55. * @param string $name Parameter name 
  56. * @return mixed 
  57. */ 
  58. public function __get($name) 
  59. if (isset($this->_cache_overrides[$name])) { 
  60. return $this->_cache_overrides[$name]; 
  61. // at the bottom we default to returning $this->_cache[$name]. 
  62. switch ($name) { 
  63. case 'alttext': 
  64. $this->_cache['alttext'] = empty($this->_cache['alttext']) ? ' ' : html_entity_decode(stripslashes($this->_cache['alttext'])); 
  65. return $this->_cache['alttext']; 
  66. case 'author': 
  67. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  68. $this->_cache['author'] = $gallery->name; 
  69. return $this->_cache['author']; 
  70. case 'caption': 
  71. $caption = html_entity_decode(stripslashes($this->__get('description'))); 
  72. if (empty($caption)) { 
  73. $caption = ' '; 
  74. $this->_cache['caption'] = $caption; 
  75. return $this->_cache['caption']; 
  76. case 'description': 
  77. $this->_cache['description'] = empty($this->_cache['description']) ? ' ' : html_entity_decode(stripslashes($this->_cache['description'])); 
  78. return $this->_cache['description']; 
  79. case 'galdesc': 
  80. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  81. $this->_cache['galdesc'] = $gallery->name; 
  82. return $this->_cache['galdesc']; 
  83. case 'gid': 
  84. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  85. $this->_cache['gid'] = $gallery->{$gallery->id_field}; 
  86. return $this->_cache['gid']; 
  87. case 'href': 
  88. return $this->__get('imageHTML'); 
  89. case 'id': 
  90. return $this->_orig_image_id; 
  91. case 'imageHTML': 
  92. $tmp = '<a href="' . $this->__get('imageURL') . '" title="' . htmlspecialchars(stripslashes($this->__get('description'))) . '" ' . $this->get_thumbcode($this->__get('name')) . '>' . '<img alt="' . $this->__get('alttext') . '" src="' . $this->__get('imageURL') . '"/>' . '</a>'; 
  93. $this->_cache['href'] = $tmp; 
  94. $this->_cache['imageHTML'] = $tmp; 
  95. return $this->_cache['imageHTML']; 
  96. case 'imagePath': 
  97. $storage = $this->get_storage(); 
  98. $this->_cache['imagePath'] = $storage->get_image_abspath($this->_orig_image, 'full'); 
  99. return $this->_cache['imagePath']; 
  100. case 'imageURL': 
  101. $storage = $this->get_storage(); 
  102. $this->_cache['imageURL'] = $storage->get_image_url($this->_orig_image, 'full'); 
  103. return $this->_cache['imageURL']; 
  104. case 'linktitle': 
  105. $this->_cache['linktitle'] = htmlspecialchars(stripslashes($this->__get('description'))); 
  106. return $this->_cache['linktitle']; 
  107. case 'name': 
  108. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  109. $this->_cache['name'] = $gallery->name; 
  110. return $this->_cache['name']; 
  111. case 'pageid': 
  112. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  113. $this->_cache['pageid'] = $gallery->name; 
  114. return $this->_cache['pageid']; 
  115. case 'path': 
  116. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  117. $this->_cache['path'] = $gallery->name; 
  118. return $this->_cache['path']; 
  119. case 'permalink': 
  120. $this->_cache['permalink'] = $this->__get('imageURL'); 
  121. return $this->_cache['permalink']; 
  122. case 'pid': 
  123. return $this->_orig_image_id; 
  124. case 'id_field': 
  125. $this->_cache['id_field'] = !empty($this->_orig_image->id_field) ? $this->_orig_image->id_field : 'pid'; 
  126. return $this->_cache['id_field']; 
  127. case 'pidlink': 
  128. $application = C_Router::get_instance()->get_routed_app(); 
  129. $controller = C_Display_Type_Controller::get_instance(); 
  130. $this->_cache['pidlink'] = $controller->set_param_for($application->get_routed_url(TRUE), 'pid', $this->__get('image_slug')); 
  131. return $this->_cache['pidlink']; 
  132. case 'previewpic': 
  133. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  134. $this->_cache['previewpic'] = $gallery->name; 
  135. return $this->_cache['previewpic']; 
  136. case 'size': 
  137. $w = 0; 
  138. $h = 0; 
  139. if ($this->_displayed_gallery && isset($this->_displayed_gallery->display_settings)) { 
  140. $ds = $this->_displayed_gallery->display_settings; 
  141. if (isset($ds['override_thumbnail_settings']) && $ds['override_thumbnail_settings']) { 
  142. $w = $ds['thumbnail_width']; 
  143. $h = $ds['thumbnail_height']; 
  144. if (!$w || !$h) { 
  145. if (is_string($this->_orig_image->meta_data)) { 
  146. $this->_orig_image = C_Image_Mapper::get_instance()->unserialize($this->_orig_image->meta_data); 
  147. if (!isset($this->_orig_image->meta_data['thumbnail'])) { 
  148. $storage = $this->get_storage(); 
  149. $storage->generate_thumbnail($this->_orig_image); 
  150. $w = $this->_orig_image->meta_data['thumbnail']['width']; 
  151. $h = $this->_orig_image->meta_data['thumbnail']['height']; 
  152. return "width='{$w}' height='{$h}'"; 
  153. case 'slug': 
  154. $gallery = $this->get_legacy_gallery($this->__get('galleryid')); 
  155. $this->_cache['slug'] = $gallery->name; 
  156. return $this->_cache['slug']; 
  157. case 'tags': 
  158. $this->_cache['tags'] = wp_get_object_terms($this->__get('id'), 'ngg_tag', 'fields=all'); 
  159. return $this->_cache['tags']; 
  160. case 'thumbHTML': 
  161. $tmp = '<a href="' . $this->__get('imageURL') . '" title="' . htmlspecialchars(stripslashes($this->__get('description'))) . '" ' . $this->get_thumbcode($this->__get('name')) . '>' . '<img alt="' . $this->__get('alttext') . '" src="' . $this->thumbURL . '"/>' . '</a>'; 
  162. $this->_cache['href'] = $tmp; 
  163. $this->_cache['thumbHTML'] = $tmp; 
  164. return $this->_cache['thumbHTML']; 
  165. case 'thumbPath': 
  166. $storage = $this->get_storage(); 
  167. $this->_cache['thumbPath'] = $storage->get_image_abspath($this->_orig_image, 'thumbnail'); 
  168. return $this->_cache['thumbPath']; 
  169. case 'thumbnailURL': 
  170. $storage = $this->get_storage(); 
  171. $thumbnail_size_name = 'thumbnail'; 
  172. if ($this->_displayed_gallery && isset($this->_displayed_gallery->display_settings)) { 
  173. $ds = $this->_displayed_gallery->display_settings; 
  174. if (isset($ds['override_thumbnail_settings']) && $ds['override_thumbnail_settings']) { 
  175. $dynthumbs = C_Component_Registry::get_instance()->get_utility('I_Dynamic_Thumbnails_Manager'); 
  176. $dyn_params = array('width' => $ds['thumbnail_width'], 'height' => $ds['thumbnail_height']); 
  177. if ($ds['thumbnail_quality']) { 
  178. $dyn_params['quality'] = $ds['thumbnail_quality']; 
  179. if ($ds['thumbnail_crop']) { 
  180. $dyn_params['crop'] = TRUE; 
  181. if ($ds['thumbnail_watermark']) { 
  182. $dyn_params['watermark'] = TRUE; 
  183. $thumbnail_size_name = $dynthumbs->get_size_name($dyn_params); 
  184. $this->_cache['thumbnailURL'] = $storage->get_image_url($this->_orig_image, $thumbnail_size_name); 
  185. return $this->_cache['thumbnailURL']; 
  186. case 'thumbcode': 
  187. if ($this->_displayed_gallery && isset($this->_displayed_gallery->display_settings) && isset($this->_displayed_gallery->display_settings['use_imagebrowser_effect']) && $this->_displayed_gallery->display_settings['use_imagebrowser_effect'] && !empty($this->_orig_image->thumbcode)) { 
  188. $this->_cache['thumbcode'] = $this->_orig_image->thumbcode; 
  189. } else { 
  190. $this->_cache['thumbcode'] = $this->get_thumbcode($this->__get('name')); 
  191. return $this->_cache['thumbcode']; 
  192. case 'thumbURL': 
  193. return $this->__get('thumbnailURL'); 
  194. case 'title': 
  195. $this->_cache['title'] = stripslashes($this->__get('name')); 
  196. return $this->_cache['title']; 
  197. case 'url': 
  198. $storage = $this->get_storage(); 
  199. $this->_cache['url'] = $storage->get_image_url($this->_orig_image, 'full'); 
  200. return $this->_cache['url']; 
  201. default: 
  202. return $this->_cache[$name]; 
  203. // called on initial nggLegacy image at construction. not sure what to do with it now. 
  204. function construct_ngg_Image($gallery) 
  205. do_action_ref_array('ngg_get_image', array(&$this)); 
  206. unset($this->tags); 
  207. /** 
  208. * Retrieves and caches an I_Settings_Manager instance 
  209. * @return mixed 
  210. */ 
  211. function get_settings() 
  212. if (is_null($this->_settings)) { 
  213. $this->_settings = C_NextGen_Settings::get_instance(); 
  214. return $this->_settings; 
  215. /** 
  216. * Retrieves and caches an I_Gallery_Storage instance 
  217. * @return mixed 
  218. */ 
  219. function get_storage() 
  220. if (is_null($this->_storage)) { 
  221. $this->_storage = C_Gallery_Storage::get_instance(); 
  222. return $this->_storage; 
  223. /** 
  224. * Retrieves I_Gallery_Mapper instance. 
  225. * @param int $gallery_id Gallery ID 
  226. * @return mixed 
  227. */ 
  228. function get_gallery($gallery_id) 
  229. if (isset($this->container) && method_exists($this->container, 'get_gallery')) { 
  230. return $this->container->get_gallery($gallery_id); 
  231. return C_Gallery_Mapper::get_instance()->find($gallery_id); 
  232. /** 
  233. * Retrieves I_Gallery_Mapper instance. 
  234. * @param int $gallery_id Gallery ID 
  235. * @return mixed 
  236. */ 
  237. function get_legacy_gallery($gallery_id) 
  238. return C_Gallery_Mapper::get_instance()->find($gallery_id); 
  239. /** 
  240. * Get the thumbnail code (to add effects on thumbnail click) 
  241. * Applies the filter 'ngg_get_thumbcode' 
  242. */ 
  243. function get_thumbcode($gallery_name = '') 
  244. if (empty($this->_displayed_gallery)) { 
  245. $effect_code = C_NextGen_Settings::get_instance()->thumbCode; 
  246. $effect_code = str_replace('%GALLERY_ID%', $gallery_name, $effect_code); 
  247. $effect_code = str_replace('%GALLERY_NAME%', $gallery_name, $effect_code); 
  248. $retval = $effect_code; 
  249. } else { 
  250. $controller = C_Display_Type_Controller::get_instance(); 
  251. $retval = $controller->get_effect_code($this->_displayed_gallery); 
  252. // This setting requires that we disable the effect code 
  253. $ds = $this->_displayed_gallery->display_settings; 
  254. if (isset($ds['use_imagebrowser_effect']) && $ds['use_imagebrowser_effect']) { 
  255. $retval = ''; 
  256. $retval = apply_filters('ngg_get_thumbcode', $retval, $this); 
  257. // ensure some additional data- fields are added; provides Pro-Lightbox compatibility 
  258. $retval .= ' data-image-id="' . $this->__get('id') . '"'; 
  259. $retval .= ' data-src="' . $this->__get('imageURL') . '"'; 
  260. $retval .= ' data-thumbnail="' . $this->__get('thumbnailURL') . '"'; 
  261. $retval .= ' data-title="' . esc_attr($this->__get('alttext')) . '"'; 
  262. $retval .= ' data-description="' . esc_attr($this->__get('description')) . '"'; 
  263. $this->_cache['thumbcode'] = $retval; 
  264. return $retval; 
  265. /** 
  266. * For compatibility support 
  267. * @return mixed 
  268. */ 
  269. function get_href_link() 
  270. return $this->__get('imageHTML'); 
  271. /** 
  272. * For compatibility support 
  273. * @return mixed 
  274. */ 
  275. function get_href_thumb_link() 
  276. return $this->__get('thumbHTML'); 
  277. /** 
  278. * Function exists for legacy support but has been gutted to not do anything 
  279. * @param int $width 
  280. * @param int $height 
  281. * @param string $mode could be watermark | web20 | crop 
  282. * @return the url for the image or false if failed 
  283. */ 
  284. function cached_singlepic_file($width = '', $height = '', $mode = '') 
  285. $dynthumbs = C_Dynamic_Thumbnails_Manager::get_instance(); 
  286. $storage = $this->get_storage(); 
  287. // determine what to do with 'mode' 
  288. $display_reflection = FALSE; 
  289. $display_watermark = FALSE; 
  290. if (!is_array($mode)) { 
  291. $mode = explode(', ', $mode); 
  292. if (in_array('web20', $mode)) { 
  293. $display_reflection = TRUE; 
  294. if (in_array('watermark', $mode)) { 
  295. $display_watermark = TRUE; 
  296. // and go for it 
  297. $params = array('width' => $width, 'height' => $height, 'watermark' => $display_watermark, 'reflection' => $display_reflection); 
  298. return $storage->get_image_url((object) $this->_cache, $dynthumbs->get_size_name($params)); 
  299. /** 
  300. * Get the tags associated to this image 
  301. */ 
  302. function get_tags() 
  303. return $this->__get('tags'); 
  304. /** 
  305. * Get the permalink to the image 
  306. * TODO: Get a permalink to a page presenting the image 
  307. */ 
  308. function get_permalink() 
  309. return $this->__get('permalink'); 
  310. /** 
  311. * Returns the _cache array; used by nggImage 
  312. * @return array 
  313. */ 
  314. function _get_image() 
  315. return $this->_cache;