/products/photocrati_nextgen/modules/nextgen_basic_album/package.module.nextgen_basic_album.php

  1. <?php 
  2. /** 
  3. * Class A_NextGen_Album_Breadcrumbs 
  4. * @mixin C_MVC_View 
  5. * @adapts I_MVC_View 
  6. */ 
  7. class A_NextGen_Album_Breadcrumbs extends Mixin 
  8. public $breadcrumb_cache = array(); 
  9. function are_breadcrumbs_enabled($display_settings) 
  10. $retval = FALSE; 
  11. if (isset($display_settings['enable_breadcrumbs']) && $display_settings['enable_breadcrumbs']) { 
  12. $retval = TRUE; 
  13. } elseif (isset($display_settings['original_settings']) && $this->are_breadcrumbs_enabled($display_settings['original_settings'])) { 
  14. $retval = TRUE; 
  15. return $retval; 
  16. function get_original_album_entities($display_settings) 
  17. $retval = array(); 
  18. if (isset($display_settings['original_album_entities'])) { 
  19. $retval = $display_settings['original_album_entities']; 
  20. } elseif (isset($display_settings['original_settings']) && $this->get_original_album_entities($display_settings['original_settings'])) { 
  21. $retval = $this->get_original_album_entities($display_settings['original_settings']); 
  22. return $retval; 
  23. function render_object() 
  24. $root_element = $this->call_parent('render_object'); 
  25. if ($displayed_gallery = $this->object->get_param('displayed_gallery')) { 
  26. $ds = $displayed_gallery->display_settings; 
  27. if ($this->are_breadcrumbs_enabled($ds) && ($original_entities = $this->get_original_album_entities($ds))) { 
  28. $original_entities = $this->get_original_album_entities($ds); 
  29. if (!empty($ds['original_album_id'])) { 
  30. $ids = $ds['original_album_id']; 
  31. } else { 
  32. $ids = $displayed_gallery->container_ids; 
  33. $breadcrumbs = $this->object->generate_breadcrumb($ids, $original_entities); 
  34. foreach ($root_element->find('nextgen_gallery.gallery_container', TRUE) as $container) { 
  35. $container->insert($breadcrumbs); 
  36. return $root_element; 
  37. function render_legacy_template_breadcrumbs($displayed_gallery, $entities, $gallery_id = FALSE) 
  38. $ds = $displayed_gallery->display_settings; 
  39. if (!empty($entities) && !empty($ds['template']) && $this->are_breadcrumbs_enabled($ds)) { 
  40. if ($gallery_id) { 
  41. if (is_array($gallery_id)) { 
  42. $ids = $gallery_id; 
  43. } else { 
  44. $ids = array($gallery_id); 
  45. } elseif (!empty($ds['original_album_id'])) { 
  46. $ids = $ds['original_album_id']; 
  47. } else { 
  48. $ids = $displayed_gallery->container_ids; 
  49. if (!empty($ds['original_album_entities'])) { 
  50. $breadcrumb_entities = $ds['original_album_entities']; 
  51. } else { 
  52. $breadcrumb_entities = $entities; 
  53. return $this->object->generate_breadcrumb($ids, $breadcrumb_entities); 
  54. } else { 
  55. return ''; 
  56. function find_gallery_parent($gallery_id, $sortorder) 
  57. $map = C_Album_Mapper::get_instance(); 
  58. $found = array(); 
  59. foreach ($sortorder as $order) { 
  60. if (strpos($order, 'a') === 0) { 
  61. $album_id = ltrim($order, 'a'); 
  62. if (empty($this->breadcrumb_cache[$order])) { 
  63. $album = $map->find($album_id); 
  64. $this->breadcrumb_cache[$order] = $album; 
  65. if (in_array($gallery_id, $album->sortorder)) { 
  66. $found[] = $album; 
  67. break; 
  68. } else { 
  69. $found = $this->find_gallery_parent($gallery_id, $album->sortorder, $found); 
  70. if ($found) { 
  71. $found[] = $album; 
  72. break; 
  73. return $found; 
  74. function generate_breadcrumb($gallery_id = NULL, $entities) 
  75. $found = array(); 
  76. $router = C_Router::get_instance(); 
  77. $app = $router->get_routed_app(); 
  78. if (is_array($gallery_id)) { 
  79. $gallery_id = array_shift($gallery_id); 
  80. if (is_array($gallery_id)) { 
  81. $gallery_id = $gallery_id[0]; 
  82. foreach ($entities as $ndx => $entity) { 
  83. $tmpid = (isset($entity->albumdesc) ? 'a' : '') . $entity->{$entity->id_field}; 
  84. $this->breadcrumb_cache[$tmpid] = $entity; 
  85. if (isset($entity->albumdesc) && in_array($gallery_id, $entity->sortorder)) { 
  86. $found[] = $entity; 
  87. break; 
  88. if (empty($found)) { 
  89. foreach ($entities as $entity) { 
  90. if (!empty($entity->sortorder)) { 
  91. $found = $this->object->find_gallery_parent($gallery_id, $entity->sortorder); 
  92. if (!empty($found)) { 
  93. $found[] = $entity; 
  94. break; 
  95. $found = array_reverse($found); 
  96. if (strpos($gallery_id, 'a') === 0) { 
  97. $album_found = FALSE; 
  98. foreach ($found as $found_item) { 
  99. if ($found_item->{$found_item->id_field} == $gallery_id) { 
  100. $album_found = TRUE; 
  101. if (!$album_found) { 
  102. $album_id = ltrim($gallery_id, 'a'); 
  103. $album = C_Album_Mapper::get_instance()->find($album_id); 
  104. $found[] = $album; 
  105. $this->breadcrumb_cache[$gallery_id] = $album; 
  106. } else { 
  107. $gallery_found = FALSE; 
  108. foreach ($entities as $entity) { 
  109. if (isset($entity->is_gallery) && $entity->is_gallery && $gallery_id == $entity->{$entity->id_field}) { 
  110. $gallery_found = TRUE; 
  111. $found[] = $entity; 
  112. break; 
  113. if (!$gallery_found) { 
  114. $gallery = C_Gallery_Mapper::get_instance()->find($gallery_id); 
  115. if ($gallery != null) { 
  116. $found[] = $gallery; 
  117. $this->breadcrumb_cache[$gallery->{$gallery->id_field}] = $gallery; 
  118. $crumbs = array(); 
  119. if (!empty($found)) { 
  120. $end = end($found); 
  121. reset($found); 
  122. foreach ($found as $found_item) { 
  123. $type = isset($found_item->albumdesc) ? 'album' : 'gallery'; 
  124. $id = ($type == 'album' ? 'a' : '') . $found_item->{$found_item->id_field}; 
  125. $entity = $this->breadcrumb_cache[$id]; 
  126. $link = NULL; 
  127. if ($type == 'album') { 
  128. $name = $entity->name; 
  129. if ($entity->pageid > 0) { 
  130. $link = @get_page_link($entity->pageid); 
  131. if (empty($link) && $found_item !== $end) { 
  132. $link = $app->get_routed_url(); 
  133. $link = $app->strip_param_segments($link); 
  134. $link = $app->set_parameter_value('album', $entity->slug, NULL, FALSE, $link); 
  135. } else { 
  136. $name = $entity->title; 
  137. $crumbs[] = array('type' => $type, 'name' => $name, 'url' => $link); 
  138. // free this memory immediately 
  139. $this->breadcrumb_cache = array(); 
  140. $view = new C_MVC_View('photocrati-nextgen_basic_album#breadcrumbs', array('breadcrumbs' => $crumbs, 'divisor' => apply_filters('ngg_breadcrumb_separator', ' » '))); 
  141. return $view->render(TRUE); 
  142. /** 
  143. * Because enqueueing an albums child entities (for use in lightboxes) is slow to do inside of cache_action() and 
  144. * we can't guarantee index_action() will run on every hit (thanks to page caching) we inline those entities into 
  145. * our basic albums templates under a window.load listener. 
  146. * 
  147. * @mixin C_MVC_View 
  148. * @adapts I_MVC_View 
  149. */ 
  150. class A_NextGen_Album_Child_Entities extends Mixin 
  151. protected static $_runonce = FALSE; 
  152. public static $_entities = array(); 
  153. /** 
  154. * The album controller will invoke this filter when its _render_album() method is called 
  155. */ 
  156. function __construct() 
  157. if (!self::$_runonce) { 
  158. add_filter('ngg_album_prepared_child_entity', array($this, 'register_child_gallery'), 10, 2); 
  159. } else { 
  160. self::$_runonce = TRUE; 
  161. /** 
  162. * Register each gallery belonging to the album that has just been rendered, so that when the MVC controller 
  163. * system 'catches up' and runs $this->render_object() that method knows what galleries to inline as JS. 
  164. * 
  165. * @param array $gallery 
  166. * @param $displayed_gallery 
  167. * @return array mixed 
  168. */ 
  169. function register_child_gallery($galleries, $displayed_gallery) 
  170. if (!$this->is_basic_album($displayed_gallery)) { 
  171. return $galleries; 
  172. $id = $displayed_gallery->ID(); 
  173. foreach ($galleries as $gallery) { 
  174. if ($gallery->is_album) { 
  175. continue; 
  176. self::$_entities[$id][] = $gallery; 
  177. return $galleries; 
  178. function is_basic_album($displayed_gallery) 
  179. return in_array($displayed_gallery->display_type, array(NGG_BASIC_COMPACT_ALBUM, NGG_BASIC_EXTENDED_ALBUM)); 
  180. /** 
  181. * Determine if we need to append the JS to the current template. This method static for the basic album controller to access. 
  182. * 
  183. * @param $display_settings 
  184. * @return bool 
  185. */ 
  186. static function are_child_entities_enabled($display_settings) 
  187. $retval = FALSE; 
  188. if (empty($display_settings['open_gallery_in_lightbox'])) { 
  189. $display_settings['open_gallery_in_lightbox'] = 0; 
  190. if ($display_settings['open_gallery_in_lightbox'] == 1) { 
  191. $retval = TRUE; 
  192. return $retval; 
  193. /** 
  194. * Search inside the template for the inside of the container and append our inline JS 
  195. */ 
  196. function render_object() 
  197. $root_element = $this->call_parent('render_object'); 
  198. if ($displayed_gallery = $this->object->get_param('displayed_gallery')) { 
  199. if (!$this->is_basic_album($displayed_gallery)) { 
  200. return $root_element; 
  201. $ds = $displayed_gallery->display_settings; 
  202. if (self::are_child_entities_enabled($ds)) { 
  203. $id = $displayed_gallery->ID(); 
  204. foreach ($root_element->find('nextgen_gallery.gallery_container', TRUE) as $container) { 
  205. $container->append(self::generate_script(self::$_entities[$id])); 
  206. return $root_element; 
  207. /** 
  208. * Generate the JS that will be inserted into the template. This method static for the basic album controller to access. 
  209. * 
  210. * @param array $galleries 
  211. * @return string 
  212. */ 
  213. static function generate_script($galleries) 
  214. $retval = '<script type="text/javascript">window.addEventListener("load", function() {'; 
  215. foreach ($galleries as $gallery) { 
  216. $dg = $gallery->displayed_gallery; 
  217. $id = $dg->id(); 
  218. $retval .= 'galleries.gallery_' . $id . ' = ' . json_encode($dg->get_entity()) . ';'; 
  219. $retval .= 'galleries.gallery_' . $id . '.wordpress_page_root = "' . get_permalink() . '";'; 
  220. $retval .= '}, false);</script>'; 
  221. return $retval; 
  222. /** 
  223. * Class A_NextGen_Album_Descriptions 
  224. * @mixin C_MVC_View 
  225. * @adapts I_MVC_View 
  226. */ 
  227. class A_NextGen_Album_Descriptions extends Mixin 
  228. // When viewing a child gallery the album controller's add_description_to_legacy_templates() method will be 
  229. // called for the gallery and then again for the root album; we only want to run once 
  230. public static $_description_added_once = FALSE; 
  231. function are_descriptions_enabled($display_settings) 
  232. $retval = FALSE; 
  233. if (isset($display_settings['enable_descriptions']) && $display_settings['enable_descriptions']) { 
  234. $retval = TRUE; 
  235. } elseif (isset($display_settings['original_settings']) && $this->are_descriptions_enabled($display_settings['original_settings'])) { 
  236. $retval = TRUE; 
  237. return $retval; 
  238. function render_object() 
  239. $root_element = $this->call_parent('render_object'); 
  240. if ($displayed_gallery = $this->object->get_param('displayed_gallery')) { 
  241. $ds = $displayed_gallery->display_settings; 
  242. if ($this->are_descriptions_enabled($ds)) { 
  243. $description = $this->object->generate_description($displayed_gallery); 
  244. foreach ($root_element->find('nextgen_gallery.gallery_container', TRUE) as $container) { 
  245. // Determine where (to be compatible with breadcrumbs) in the container to insert 
  246. $pos = 0; 
  247. foreach ($container->_list as $ndx => $item) { 
  248. if (is_string($item)) { 
  249. $pos = $ndx; 
  250. } else { 
  251. break; 
  252. $container->insert($description, $pos); 
  253. return $root_element; 
  254. function render_legacy_template_description($displayed_gallery) 
  255. if (!empty($displayed_gallery->display_settings['template']) && $this->are_descriptions_enabled($displayed_gallery->display_settings)) { 
  256. return $this->object->generate_description($displayed_gallery); 
  257. } else { 
  258. return ''; 
  259. function generate_description($displayed_gallery) 
  260. if (self::$_description_added_once) { 
  261. return ''; 
  262. self::$_description_added_once = TRUE; 
  263. $description = $this->get_description($displayed_gallery); 
  264. $view = new C_MVC_View('photocrati-nextgen_basic_album#descriptions', array('description' => $description)); 
  265. return $view->render(TRUE); 
  266. function get_description($displayed_gallery) 
  267. $description = ''; 
  268. // Important: do not array_shift() $displayed_gallery->container_ids as it will affect breadcrumbs 
  269. $container_ids = $displayed_gallery->container_ids; 
  270. if ($displayed_gallery->source == 'galleries') { 
  271. $gallery_id = array_shift($container_ids); 
  272. $gallery = C_Gallery_Mapper::get_instance()->find($gallery_id); 
  273. if ($gallery && !empty($gallery->galdesc)) { 
  274. $description = $gallery->galdesc; 
  275. } else { 
  276. if ($displayed_gallery->source == 'albums') { 
  277. $album_id = array_shift($container_ids); 
  278. $album = C_Album_Mapper::get_instance()->find($album_id); 
  279. if ($album && !empty($album->albumdesc)) { 
  280. $description = $album->albumdesc; 
  281. return $description; 
  282. /** 
  283. * Provides validation for NextGen Basic Albums 
  284. * @mixin C_Album_Mapper 
  285. * @adapts I_Album_Mapper 
  286. */ 
  287. class A_NextGen_Basic_Album extends Mixin 
  288. function validation() 
  289. $ngglegacy_albums = array(NGG_BASIC_COMPACT_ALBUM, NGG_BASIC_EXTENDED_ALBUM); 
  290. if (in_array($this->object->name, $ngglegacy_albums)) { 
  291. $this->object->validates_presence_of('gallery_display_type'); 
  292. $this->object->validates_numericality_of('galleries_per_page'); 
  293. return $this->call_parent('validation'); 
  294. function get_order() 
  295. return NGG_DISPLAY_PRIORITY_BASE + NGG_DISPLAY_PRIORITY_STEP; 
  296. /** 
  297. * Class A_NextGen_Basic_Album_Controller 
  298. * @mixin C_Display_Type_Controller 
  299. * @adapts I_Display_Type_Controller 
  300. */ 
  301. class A_NextGen_Basic_Album_Controller extends Mixin_NextGen_Basic_Pagination 
  302. var $albums = array(); 
  303. /** 
  304. * Renders the front-end for the NextGen Basic Album display type 
  305. * 
  306. * @param $displayed_gallery 
  307. * @param bool $return 
  308. */ 
  309. function index_action($displayed_gallery, $return = FALSE) 
  310. $display_settings = $displayed_gallery->display_settings; 
  311. // We need to fetch the album containers selected in the Attach 
  312. // to Post interface. We need to do this, because once we fetch the 
  313. // included entities, we need to iterate over each entity and assign it 
  314. // a parent_id, which is the album that it belongs to. We need to do this 
  315. // because the link to the gallery, is not /nggallery/gallery--id, but 
  316. // /nggallery/album--id/gallery--id 
  317. $parent_albums = $displayed_gallery->get_albums(); 
  318. // Are we to display a gallery? Ensure our 'gallery' isn't just a paginated album view 
  319. $gallery = $gallery_slug = $this->param('gallery'); 
  320. if ($gallery && strpos($gallery, 'nggpage--') !== 0) { 
  321. // basic albums only support one per post 
  322. if (isset($GLOBALS['nggShowGallery'])) { 
  323. return; 
  324. $GLOBALS['nggShowGallery'] = TRUE; 
  325. // Try finding the gallery by slug first. If nothing is found, we assume that 
  326. // the user passed in a gallery id instead 
  327. $mapper = C_Gallery_Mapper::get_instance(); 
  328. $tmp = $mapper->select()->where(array('slug = %s', $gallery))->limit(1)->run_query(); 
  329. $result = reset($tmp); 
  330. unset($tmp); 
  331. if ($result) { 
  332. $gallery = $result->{$result->id_field}; 
  333. $renderer = C_Displayed_Gallery_Renderer::get_instance('inner'); 
  334. $gallery_params = array('source' => 'galleries', 'container_ids' => array($gallery), 'display_type' => $display_settings['gallery_display_type'], 'original_display_type' => $displayed_gallery->display_type, 'original_settings' => $display_settings, 'original_album_entities' => $parent_albums); 
  335. if (!empty($display_settings['gallery_display_template'])) { 
  336. $gallery_params['template'] = $display_settings['gallery_display_template']; 
  337. add_filter('ngg_displayed_gallery_rendering', array($this, 'add_description_to_legacy_templates'), 8, 2); 
  338. add_filter('ngg_displayed_gallery_rendering', array($this, 'add_breadcrumbs_to_legacy_templates'), 9, 2); 
  339. $output = $renderer->display_images($gallery_params, $return); 
  340. remove_filter('ngg_displayed_gallery_rendering', array($this, 'add_breadcrumbs_to_legacy_templates')); 
  341. remove_filter('ngg_displayed_gallery_rendering', array($this, 'add_description_to_legacy_templates')); 
  342. return $output; 
  343. } else { 
  344. if ($album = $this->param('album')) { 
  345. $mapper = C_Album_Mapper::get_instance(); 
  346. $result = $mapper->select()->where(array('slug = %s', $album))->limit(1)->run_query(); 
  347. $result = array_pop($result); 
  348. $album_sub = $result ? $result->{$result->id_field} : null; 
  349. if ($album_sub != null) { 
  350. $album = $album_sub; 
  351. $displayed_gallery->entity_ids = array(); 
  352. $displayed_gallery->sortorder = array(); 
  353. $displayed_gallery->container_ids = ($album === '0' or $album === 'all') ? array() : array($album); 
  354. $displayed_gallery->display_settings['original_album_id'] = 'a' . $album_sub; 
  355. $displayed_gallery->display_settings['original_album_entities'] = $parent_albums; 
  356. // Get the albums 
  357. // TODO: This should probably be moved to the elseif block above 
  358. $this->albums = $displayed_gallery->get_albums(); 
  359. // None of the above: Display the main album. Get the settings required for display 
  360. $current_page = (int) $this->param('page', $displayed_gallery->id(), 1); 
  361. $offset = $display_settings['galleries_per_page'] * ($current_page - 1); 
  362. $entities = $displayed_gallery->get_included_entities($display_settings['galleries_per_page'], $offset); 
  363. // If there are entities to be displayed 
  364. if ($entities) { 
  365. $pagination_result = $this->object->create_pagination($current_page, $displayed_gallery->get_entity_count(), $display_settings['galleries_per_page'], urldecode($this->object->param('ajax_pagination_referrer'))); 
  366. $display_settings['entities'] = $entities; 
  367. $display_settings['pagination'] = $pagination_result['output']; 
  368. $display_settings['displayed_gallery'] = $displayed_gallery; 
  369. $display_settings = $this->prepare_legacy_album_params($displayed_gallery->get_entity(), $display_settings); 
  370. if (!empty($display_settings['template']) && $display_settings['template'] != 'default') { 
  371. // Add additional parameters 
  372. $this->object->remove_param('ajax_pagination_referrer'); 
  373. $display_settings['current_page'] = $current_page; 
  374. $display_settings['pagination_prev'] = $pagination_result['prev']; 
  375. $display_settings['pagination_next'] = $pagination_result['next']; 
  376. // Legacy templates lack a good way of injecting content at the right time 
  377. $this->object->add_mixin('Mixin_NextGen_Basic_Templates'); 
  378. $this->object->add_mixin('A_NextGen_Album_Breadcrumbs'); 
  379. $this->object->add_mixin('A_NextGen_Album_Descriptions'); 
  380. $breadcrumbs = $this->object->render_legacy_template_breadcrumbs($displayed_gallery, $entities); 
  381. $description = $this->object->render_legacy_template_description($displayed_gallery); 
  382. // If enabled enqueue the child entities as JSON for lightboxes to read 
  383. if (A_NextGen_Album_Child_Entities::are_child_entities_enabled($display_settings)) { 
  384. $script = A_NextGen_Album_Child_Entities::generate_script($entities); 
  385. $retval = $this->object->legacy_render($display_settings['template'], $display_settings, $return, 'album'); 
  386. if (!empty($description)) { 
  387. $retval = $description . $retval; 
  388. if (!empty($breadcrumbs)) { 
  389. $retval = $breadcrumbs . $retval; 
  390. if (!empty($script)) { 
  391. $retval = $retval . $script; 
  392. return $retval; 
  393. } else { 
  394. $params = $display_settings; 
  395. $params = $this->object->prepare_display_parameters($displayed_gallery, $params); 
  396. switch ($displayed_gallery->display_type) { 
  397. case NGG_BASIC_COMPACT_ALBUM: 
  398. $template = 'compact'; 
  399. break; 
  400. case NGG_BASIC_EXTENDED_ALBUM: 
  401. $template = 'extended'; 
  402. break; 
  403. return $this->object->render_view("photocrati-nextgen_basic_album#{$template}", $params, $return); 
  404. } else { 
  405. return $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); 
  406. /** 
  407. * Creates a displayed gallery of a gallery belonging to an album. Shared by index_action() and cache_action() to 
  408. * allow lightboxes to open album children directly. 
  409. * 
  410. * @param $gallery 
  411. * @param $display_settings 
  412. * @return $gallery 
  413. */ 
  414. function make_child_displayed_gallery($gallery, $display_settings) 
  415. $gallery->displayed_gallery = new C_Displayed_Gallery(); 
  416. $gallery->displayed_gallery->container_ids = array($gallery->{$gallery->id_field}); 
  417. $gallery->displayed_gallery->display_settings = $display_settings; 
  418. $gallery->displayed_gallery->returns = 'included'; 
  419. $gallery->displayed_gallery->source = 'galleries'; 
  420. $gallery->displayed_gallery->images_list_count = $gallery->displayed_gallery->get_entity_count(); 
  421. $gallery->displayed_gallery->is_album_gallery = TRUE; 
  422. $gallery->displayed_gallery->to_transient(); 
  423. return $gallery; 
  424. function add_breadcrumbs_to_legacy_templates($html, $displayed_gallery) 
  425. $this->object->add_mixin('A_NextGen_Album_Breadcrumbs'); 
  426. $original_album_entities = array(); 
  427. if (isset($displayed_gallery->display_settings['original_album_entities'])) { 
  428. $original_album_entities = $displayed_gallery->display_settings['original_album_entities']; 
  429. } elseif (isset($displayed_gallery->display_settings['original_settings']) && isset($displayed_gallery->display_settings['original_settings']['original_album_entities'])) { 
  430. $original_album_entities = $displayed_gallery->display_settings['original_settings']['original_album_entities']; 
  431. $breadcrumbs = $this->object->render_legacy_template_breadcrumbs($displayed_gallery, $original_album_entities, $displayed_gallery->container_ids); 
  432. if (!empty($breadcrumbs)) { 
  433. $html = $breadcrumbs . $html; 
  434. return $html; 
  435. function add_description_to_legacy_templates($html, $displayed_gallery) 
  436. $this->object->add_mixin('A_NextGen_Album_Descriptions'); 
  437. $description = $this->object->render_legacy_template_description($displayed_gallery); 
  438. if (!empty($description)) { 
  439. $html = $description . $html; 
  440. return $html; 
  441. /** 
  442. * Gets the parent album for the entity being displayed 
  443. * @param int $entity_id 
  444. * @return stdClass (album) 
  445. */ 
  446. function get_parent_album_for($entity_id) 
  447. $retval = NULL; 
  448. foreach ($this->albums as $album) { 
  449. if (in_array($entity_id, $album->sortorder)) { 
  450. $retval = $album; 
  451. break; 
  452. return $retval; 
  453. function prepare_legacy_album_params($displayed_gallery, $params) 
  454. $image_mapper = C_Image_Mapper::get_instance(); 
  455. $storage = C_Gallery_Storage::get_instance(); 
  456. $image_gen = C_Dynamic_Thumbnails_Manager::get_instance(); 
  457. if (empty($displayed_gallery->display_settings['override_thumbnail_settings'])) { 
  458. // legacy templates expect these dimensions 
  459. $image_gen_params = array('width' => 91, 'height' => 68, 'crop' => TRUE); 
  460. } else { 
  461. // use settings requested by user 
  462. $image_gen_params = array('width' => $displayed_gallery->display_settings['thumbnail_width'], 'height' => $displayed_gallery->display_settings['thumbnail_height'], 'quality' => isset($displayed_gallery->display_settings['thumbnail_quality']) ? $displayed_gallery->display_settings['thumbnail_quality'] : 100, 'crop' => isset($displayed_gallery->display_settings['thumbnail_crop']) ? $displayed_gallery->display_settings['thumbnail_crop'] : NULL, 'watermark' => isset($displayed_gallery->display_settings['thumbnail_watermark']) ? $displayed_gallery->display_settings['thumbnail_watermark'] : NULL); 
  463. // so user templates can know how big the images are expected to be 
  464. $params['image_gen_params'] = $image_gen_params; 
  465. // Transform entities 
  466. $params['galleries'] = $params['entities']; 
  467. unset($params['entities']); 
  468. foreach ($params['galleries'] as &$gallery) { 
  469. // Get the preview image url 
  470. $gallery->previewurl = ''; 
  471. if ($gallery->previewpic && $gallery->previewpic > 0) { 
  472. if ($image = $image_mapper->find(intval($gallery->previewpic))) { 
  473. $gallery->previewpic_image = $image; 
  474. $gallery->previewpic_fullsized_url = $storage->get_image_url($image, 'full'); 
  475. $gallery->previewurl = $storage->get_image_url($image, $image_gen->get_size_name($image_gen_params), TRUE); 
  476. $gallery->previewname = $gallery->name; 
  477. // Get the page link. If the entity is an album, then the url will 
  478. // look like /nggallery/album--slug. 
  479. $id_field = $gallery->id_field; 
  480. if ($gallery->is_album) { 
  481. if ($gallery->pageid > 0) { 
  482. $gallery->pagelink = @get_page_link($gallery->pageid); 
  483. } else { 
  484. $pagelink = $this->object->get_routed_url(TRUE); 
  485. $pagelink = $this->object->remove_param_for($pagelink, 'album'); 
  486. $pagelink = $this->object->remove_param_for($pagelink, 'gallery'); 
  487. $pagelink = $this->object->remove_param_for($pagelink, 'nggpage'); 
  488. $pagelink = $this->object->set_param_for($pagelink, 'album', $gallery->slug); 
  489. $gallery->pagelink = $pagelink; 
  490. } else { 
  491. if ($gallery->pageid > 0) { 
  492. $gallery->pagelink = @get_page_link($gallery->pageid); 
  493. if (empty($gallery->pagelink)) { 
  494. $pagelink = $this->object->get_routed_url(TRUE); 
  495. $parent_album = $this->object->get_parent_album_for($gallery->{$id_field}); 
  496. if ($parent_album) { 
  497. $pagelink = $this->object->remove_param_for($pagelink, 'album'); 
  498. $pagelink = $this->object->remove_param_for($pagelink, 'gallery'); 
  499. $pagelink = $this->object->remove_param_for($pagelink, 'nggpage'); 
  500. $pagelink = $this->object->set_param_for($pagelink, 'album', $parent_album->slug); 
  501. } else { 
  502. if ($displayed_gallery->container_ids === array('0') || $displayed_gallery->container_ids === array('')) { 
  503. $pagelink = $this->object->set_param_for($pagelink, 'album', 'all'); 
  504. } else { 
  505. $pagelink = $this->object->remove_param_for($pagelink, 'nggpage'); 
  506. $pagelink = $this->object->set_param_for($pagelink, 'album', 'album'); 
  507. $gallery->pagelink = $this->object->set_param_for($pagelink, 'gallery', $gallery->slug); 
  508. // Mark the child type 
  509. $gallery->entity_type = isset($gallery->is_gallery) && intval($gallery->is_gallery) ? 'gallery' : 'album'; 
  510. // If this setting is on we need to inject an effect code 
  511. if (!empty($displayed_gallery->display_settings['open_gallery_in_lightbox']) && $gallery->entity_type == 'gallery') { 
  512. $gallery = $this->object->make_child_displayed_gallery($gallery, $displayed_gallery->display_settings); 
  513. if ($this->does_lightbox_support_displayed_gallery($displayed_gallery)) { 
  514. $gallery->displayed_gallery->effect_code = $this->object->get_effect_code($gallery->displayed_gallery); 
  515. // Let plugins modify the gallery 
  516. $gallery = apply_filters('ngg_album_galleryobject', $gallery); 
  517. $params['galleries'] = apply_filters('ngg_album_prepared_child_entity', $params['galleries'], $params['displayed_gallery']); 
  518. $params['album'] = reset($this->albums); 
  519. $params['albums'] = $this->albums; 
  520. // Clean up 
  521. unset($storage); 
  522. unset($image_mapper); 
  523. unset($image_gen); 
  524. unset($image_gen_params); 
  525. return $params; 
  526. function _get_js_lib_url() 
  527. return $this->object->get_static_url('photocrati-nextgen_basic_album#init.js'); 
  528. /** 
  529. * Enqueues all static resources required by this display type 
  530. * 
  531. * @param C_Displayed_Gallery $displayed_gallery 
  532. */ 
  533. function enqueue_frontend_resources($displayed_gallery) 
  534. $this->call_parent('enqueue_frontend_resources', $displayed_gallery); 
  535. wp_enqueue_style('nextgen_basic_album_style', $this->object->get_static_url('photocrati-nextgen_basic_album#nextgen_basic_album.css'), FALSE, NGG_SCRIPT_VERSION); 
  536. wp_enqueue_style('nextgen_pagination_style', $this->get_static_url('photocrati-nextgen_pagination#style.css'), FALSE, NGG_SCRIPT_VERSION); 
  537. wp_enqueue_script('jquery.dotdotdot', $this->object->get_static_url('photocrati-nextgen_basic_album#jquery.dotdotdot-1.5.7-packed.js'), array('jquery'), NGG_SCRIPT_VERSION); 
  538. $ds = $displayed_gallery->display_settings; 
  539. if (!empty($ds['enable_breadcrumbs']) && $ds['enable_breadcrumbs'] || !empty($ds['original_settings']['enable_breadcrumbs']) && $ds['original_settings']['enable_breadcrumbs']) { 
  540. wp_enqueue_style('nextgen_basic_album_breadcrumbs_style', $this->object->get_static_url('photocrati-nextgen_basic_album#breadcrumbs.css'), FALSE, NGG_SCRIPT_VERSION); 
  541. $this->enqueue_ngg_styles(); 
  542. /** 
  543. * Class A_NextGen_Basic_Album_Mapper 
  544. * @mixin C_Display_Type_Mapper 
  545. * @adapts I_Display_Type_Mapper 
  546. */ 
  547. class A_NextGen_Basic_Album_Mapper extends Mixin 
  548. function set_defaults($entity) 
  549. $this->call_parent('set_defaults', $entity); 
  550. if (isset($entity->name) && in_array($entity->name, array(NGG_BASIC_COMPACT_ALBUM, NGG_BASIC_EXTENDED_ALBUM))) { 
  551. // Set defaults for both display (album) types 
  552. $settings = C_NextGen_Settings::get_instance(); 
  553. $this->object->_set_default_value($entity, 'settings', 'galleries_per_page', $settings->galPagedGalleries); 
  554. $this->object->_set_default_value($entity, 'settings', 'enable_breadcrumbs', 1); 
  555. $this->object->_set_default_value($entity, 'settings', 'disable_pagination', 0); 
  556. $this->object->_set_default_value($entity, 'settings', 'enable_descriptions', 0); 
  557. $this->object->_set_default_value($entity, 'settings', 'template', ''); 
  558. $this->object->_set_default_value($entity, 'settings', 'open_gallery_in_lightbox', 0); 
  559. // Thumbnail dimensions -- only used by extended albums 
  560. if ($entity->name == NGG_BASIC_EXTENDED_ALBUM) { 
  561. $this->_set_default_value($entity, 'settings', 'override_thumbnail_settings', 0); 
  562. $this->_set_default_value($entity, 'settings', 'thumbnail_width', $settings->thumbwidth); 
  563. $this->_set_default_value($entity, 'settings', 'thumbnail_height', $settings->thumbheight); 
  564. $this->_set_default_value($entity, 'settings', 'thumbnail_quality', $settings->thumbquality); 
  565. $this->_set_default_value($entity, 'settings', 'thumbnail_crop', $settings->thumbfix); 
  566. $this->_set_default_value($entity, 'settings', 'thumbnail_watermark', 0); 
  567. if (defined('NGG_BASIC_THUMBNAILS')) { 
  568. $this->object->_set_default_value($entity, 'settings', 'gallery_display_type', NGG_BASIC_THUMBNAILS); 
  569. $this->object->_set_default_value($entity, 'settings', 'gallery_display_template', ''); 
  570. $this->object->_set_default_value($entity, 'settings', 'ngg_triggers_display', 'never'); 
  571. /** 
  572. * Class A_NextGen_Basic_Album_Routes 
  573. * @mixin C_Displayed_Gallery_Renderer 
  574. * @adapts I_Displayed_Gallery_Renderer 
  575. */ 
  576. class A_NextGen_Basic_Album_Routes extends Mixin 
  577. function render($displayed_gallery, $return = FALSE, $mode = NULL) 
  578. $do_rewrites = FALSE; 
  579. $app = NULL; 
  580. // Get display types 
  581. $original_display_type = isset($displayed_gallery->display_settings['original_display_type']) ? $displayed_gallery->display_settings['original_display_type'] : ''; 
  582. $display_type = $displayed_gallery->display_type; 
  583. // If we're viewing an album, rewrite the urls 
  584. $regex = "/photocrati-nextgen_basic_\\w+_album/"; 
  585. if (preg_match($regex, $display_type)) { 
  586. $do_rewrites = TRUE; 
  587. // Get router 
  588. $router = C_Router::get_instance(); 
  589. $app = $router->get_routed_app(); 
  590. $slug = '/' . C_NextGen_Settings::get_instance()->router_param_slug; 
  591. $app->rewrite("{*}{$slug}/page/{\\d}{*}", "{1}{$slug}/nggpage--{2}{3}", FALSE, TRUE); 
  592. $app->rewrite("{*}{$slug}/pid--{*}", "{1}{$slug}/pid--{2}", FALSE, TRUE); 
  593. // avoid conflicts with imagebrowser 
  594. $app->rewrite("{*}{$slug}/{\\w}/{\\w}/{\\w}{*}", "{1}{$slug}/album--{2}/gallery--{3}/{4}{5}", FALSE, TRUE); 
  595. $app->rewrite("{*}{$slug}/{\\w}/{\\w}", "{1}{$slug}/album--{2}/gallery--{3}", FALSE, TRUE); 
  596. // TODO: We're commenting this out as it was causing a problem with sub-album requests not 
  597. // working when placed beside paginated galleries. But we still need to figure out why, and fix that 
  598. // $app->rewrite("{*}{$slug}/{\\w}", "{1}{$slug}/album--{2}", FALSE, TRUE); 
  599. } elseif (preg_match($regex, $original_display_type)) { 
  600. $do_rewrites = TRUE; 
  601. // Get router 
  602. $router = C_Router::get_instance(); 
  603. $app = $router->get_routed_app(); 
  604. $slug = '/' . C_NextGen_Settings::get_instance()->router_param_slug; 
  605. $app->rewrite("{*}{$slug}/album--{\\w}", "{1}{$slug}/{2}"); 
  606. $app->rewrite("{*}{$slug}/album--{\\w}/gallery--{\\w}", "{1}{$slug}/{2}/{3}"); 
  607. $app->rewrite("{*}{$slug}/album--{\\w}/gallery--{\\w}/{*}", "{1}{$slug}/{2}/{3}/{4}"); 
  608. // Perform rewrites 
  609. if ($do_rewrites && $app) { 
  610. $app->do_rewrites(); 
  611. return $this->call_parent('render', $displayed_gallery, $return, $mode); 
  612. /** 
  613. * Class A_NextGen_Basic_Album_Urls 
  614. * @mixin C_Routing_App 
  615. * @adapts I_Routing_App 
  616. */ 
  617. class A_NextGen_Basic_Album_Urls extends Mixin 
  618. function create_parameter_segment($key, $value, $id = NULL, $use_prefix = FALSE) 
  619. if ($key == 'nggpage') { 
  620. return 'page/' . $value; 
  621. } elseif ($key == 'album') { 
  622. return $value; 
  623. } elseif ($key == 'gallery') { 
  624. return $value; 
  625. } else { 
  626. return $this->call_parent('create_parameter_segment', $key, $value, $id, $use_prefix); 
  627. function remove_parameter($key, $id = NULL, $url = FALSE) 
  628. $retval = $this->call_parent('remove_parameter', $key, $id, $url); 
  629. $settings = C_NextGen_Settings::get_instance(); 
  630. $param_slug = preg_quote($settings->router_param_slug, '#'); 
  631. if (preg_match("#(/{$param_slug}/.*)album--#", $retval, $matches)) { 
  632. $retval = str_replace($matches[0], $matches[1], $retval); 
  633. if (preg_match("#(/{$param_slug}/.*)gallery--#", $retval, $matches)) { 
  634. $retval = str_replace($matches[0], $matches[1], $retval); 
  635. return $retval; 
  636. /** 
  637. * Class Mixin_NextGen_Basic_Album_Form 
  638. * @mixin C_Form 
  639. */ 
  640. class Mixin_NextGen_Basic_Album_Form extends Mixin_Display_Type_Form 
  641. function _get_field_names() 
  642. return array('nextgen_basic_album_gallery_display_type', 'nextgen_basic_album_galleries_per_page', 'nextgen_basic_album_enable_breadcrumbs', 'nextgen_basic_templates_template', 'nextgen_basic_album_enable_descriptions'); 
  643. /** 
  644. * Renders the Gallery Display Type field 
  645. * @param C_Display_Type $display_type 
  646. */ 
  647. function _render_nextgen_basic_album_gallery_display_type_field($display_type) 
  648. $mapper = C_Display_Type_Mapper::get_instance(); 
  649. return $this->render_partial('photocrati-nextgen_basic_album#nextgen_basic_album_gallery_display_type', array('display_type_name' => $display_type->name, 'gallery_display_type_label' => __('Display galleries as', 'nggallery'), 'gallery_display_type_help' => __('How would you like galleries to be displayed?', 'nggallery'), 'gallery_display_type' => $display_type->settings['gallery_display_type'], 'galleries_per_page_label' => __('Galleries per page', 'nggallery'), 'galleries_per_page' => $display_type->settings['galleries_per_page'], 'display_types' => $mapper->find_by_entity_type('image')), TRUE); 
  650. /** 
  651. * Renders the Galleries Per Page field 
  652. * @param C_Display_Type $display_type 
  653. */ 
  654. function _render_nextgen_basic_album_galleries_per_page_field($display_type) 
  655. return $this->_render_number_field($display_type, 'galleries_per_page', __('Items per page', 'nggallery'), $display_type->settings['galleries_per_page'], __('Maximum number of galleries or sub-albums to appear on a single page', 'nggallery'), FALSE, '', 0); 
  656. function _render_nextgen_basic_album_enable_breadcrumbs_field($display_type) 
  657. return $this->_render_radio_field($display_type, 'enable_breadcrumbs', __('Enable breadcrumbs', 'nggallery'), isset($display_type->settings['enable_breadcrumbs']) ? $display_type->settings['enable_breadcrumbs'] : FALSE); 
  658. function _render_nextgen_basic_album_enable_descriptions_field($display_type) 
  659. return $this->_render_radio_field($display_type, 'enable_descriptions', __('Display descriptions', 'nggallery'), $display_type->settings['enable_descriptions']); 
  660. /** 
  661. * Class A_NextGen_Basic_Extended_Album_Form 
  662. * @mixin C_Form 
  663. * @adapts I_Form for the "photocrati-nextgen_basic_extended_album" context 
  664. */ 
  665. class A_NextGen_Basic_Extended_Album_Form extends Mixin_NextGen_Basic_Album_Form 
  666. function get_display_type_name() 
  667. return NGG_BASIC_EXTENDED_ALBUM; 
  668. /** 
  669. * Returns a list of fields to render on the settings page 
  670. */ 
  671. function _get_field_names() 
  672. $fields = parent::_get_field_names(); 
  673. $fields[] = 'thumbnail_override_settings'; 
  674. return $fields; 
  675. /** 
  676. * Enqueues static resources required by this form 
  677. */ 
  678. function enqueue_static_resources() 
  679. wp_enqueue_script('nextgen_basic_extended_albums_settings_script', $this->object->get_static_url('photocrati-nextgen_basic_album#extended_settings.js'), array('jquery.nextgen_radio_toggle'), NGG_SCRIPT_VERSION); 
  680. $atp = C_Attach_Controller::get_instance(); 
  681. if ($atp != null) { 
  682. $atp->mark_script('nextgen_basic_extended_albums_settings_script'); 
  683. /** 
  684. * Class A_NextGen_Basic_Compact_Album_Form 
  685. * @mixin C_Form 
  686. * @adapts I_Form for the "photocrati-nextgen_basic_compact_album" context 
  687. */ 
  688. class A_NextGen_Basic_Compact_Album_Form extends Mixin_NextGen_Basic_Album_Form 
  689. function get_display_type_name() 
  690. return NGG_BASIC_COMPACT_ALBUM; 
  691. /** 
  692. * Returns a list of fields to render on the settings page 
  693. */ 
  694. function _get_field_names() 
  695. $fields = parent::_get_field_names(); 
  696. $fields[] = 'thumbnail_override_settings'; 
  697. return $fields; 
  698. /** 
  699. * Enqueues static resources required by this form 
  700. */ 
  701. function enqueue_static_resources() 
  702. wp_enqueue_script('nextgen_basic_compact_albums_settings_script', $this->object->get_static_url('photocrati-nextgen_basic_album#compact_settings.js'), array('jquery.nextgen_radio_toggle'), NGG_SCRIPT_VERSION); 
  703. $atp = C_Attach_Controller::get_instance(); 
  704. if ($atp != null) { 
  705. $atp->mark_script('nextgen_basic_compact_albums_settings_script'); 
.