C_Displayed_Gallery_Trigger_Manager

The Trigger Manager displays "trigger buttons" for a displayed gallery.

Defined (1)

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

/products/photocrati_nextgen/modules/nextgen_gallery_display/package.module.nextgen_gallery_display.php  
  1. class C_Displayed_Gallery_Trigger_Manager 
  2. static $_instance = NULL; 
  3. private $_triggers = array(); 
  4. private $_trigger_order = array(); 
  5. private $_display_type_handlers = array(); 
  6. private $_default_display_type_handler = NULL; 
  7. private $css_class = 'ngg-trigger-buttons'; 
  8. private $_default_image_types = array('photocrati-nextgen_basic_thumbnails', 'photocrati-nextgen_basic_singlepic', 'photocrati-nextgen_pro_thumbnail_grid', 'photocrati-nextgen_pro_blog_gallery', 'photocrati-nextgen_pro_film'); 
  9. /** 
  10. * @return C_Displayed_Gallery_Trigger_Manager 
  11. */ 
  12. static function get_instance() 
  13. if (!self::$_instance) { 
  14. $klass = get_class(); 
  15. self::$_instance = new $klass(); 
  16. return self::$_instance; 
  17. function __construct() 
  18. $this->_default_display_type_handler = 'C_Displayed_Gallery_Trigger_Handler'; 
  19. foreach ($this->_default_image_types as $display_type) { 
  20. $this->register_display_type_handler($display_type, 'C_Displayed_Gallery_Image_Trigger_Handler'); 
  21. function register_display_type_handler($display_type, $klass) 
  22. $this->_display_type_handlers[$display_type] = $klass; 
  23. function deregister_display_type_handler($display_type) 
  24. unset($this->_display_type_handlers[$display_type]); 
  25. function add($name, $handler) 
  26. $this->_triggers[$name] = $handler; 
  27. $this->_trigger_order[] = $name; 
  28. return $this; 
  29. function remove($name) 
  30. $order = array(); 
  31. unset($this->_triggers[$name]); 
  32. foreach ($this->_trigger_order as $trigger) { 
  33. if ($trigger != $name) { 
  34. $order[] = $trigger; 
  35. $this->_trigger_order = $order; 
  36. return $this; 
  37. function _rebuild_index() 
  38. $order = array(); 
  39. foreach ($this->_trigger_order as $name) { 
  40. $order[] = $name; 
  41. $this->_trigger_order = $order; 
  42. return $this; 
  43. function increment_position($name) 
  44. if (($current_index = array_search($name, $this->_trigger_order)) !== FALSE) { 
  45. $next_index = $current_index += 1; 
  46. // 1, 2, 3, 4, 5 => 1, 2, 4, 3, 5 
  47. if (isset($this->_trigger_order[$next_index])) { 
  48. $next = $this->_trigger_order[$next_index]; 
  49. $this->_trigger_order[$next_index] = $name; 
  50. $this->_trigger_order[$current_index] = $next; 
  51. return $this->position_of($name); 
  52. function decrement_position($name) 
  53. if (($current_index = array_search($name, $this->_trigger_order)) !== FALSE) { 
  54. $previous_index = $current_index -= 1; 
  55. if (isset($this->_trigger_order[$previous_index])) { 
  56. $previous = $this->_trigger_order[$previous_index]; 
  57. $this->_trigger_order[$previous_index] = $name; 
  58. $this->_trigger_order[$current_index] = $previous; 
  59. return $this->position_of($name); 
  60. function position_of($name) 
  61. return array_search($name, $this->_trigger_order); 
  62. function move_to_position($name, $position_index) 
  63. if (($current_index = $this->position_of($name)) !== FALSE) { 
  64. $func = 'increment_position'; 
  65. if ($current_index < $position_index) { 
  66. $func = 'decrement_position'; 
  67. while ($this->position_of($name) != $position_index) { 
  68. $this->{$func}($name); 
  69. return $this->position_of($name); 
  70. function move_to_start($name) 
  71. if ($index = $this->position_of($name)) { 
  72. unset($this->_trigger_order[$index]); 
  73. array_unshift($this->_trigger_order, $name); 
  74. $this->_rebuild_index(); 
  75. return $this->position_of($name); 
  76. function count() 
  77. return count($this->_trigger_order); 
  78. function move_to_end($name) 
  79. $index = $this->position_of($name); 
  80. if ($index !== FALSE or $index != $this->count() - 1) { 
  81. unset($this->_trigger_order[$index]); 
  82. $this->_trigger_order[] = $name; 
  83. $this->_rebuild_index(); 
  84. return $this->position_of($name); 
  85. function get_handler_for_displayed_gallery($displayed_gallery) 
  86. // Find the trigger handler for the current display type. 
  87. // First, check the display settings for the displayed gallery. Some third-party 
  88. // display types might specify their own handler 
  89. $klass = NULL; 
  90. if (isset($displayed_gallery->display_settings['trigger_handler'])) { 
  91. $klass = $displayed_gallery->display_settings['trigger_handler']; 
  92. } else { 
  93. $klass = $this->_default_display_type_handler; 
  94. if (isset($this->_display_type_handlers[$displayed_gallery->display_type])) { 
  95. $klass = $this->_display_type_handlers[$displayed_gallery->display_type]; 
  96. return $klass; 
  97. function render($view, $displayed_gallery) 
  98. if ($klass = $this->get_handler_for_displayed_gallery($displayed_gallery)) { 
  99. $handler = new $klass(); 
  100. $handler->view = $view; 
  101. $handler->displayed_gallery = $displayed_gallery; 
  102. $handler->manager = $this; 
  103. if (method_exists($handler, 'render')) { 
  104. $handler->render(); 
  105. return $view; 
  106. function render_trigger($name, $view, $displayed_gallery) 
  107. $retval = ''; 
  108. if (isset($this->_triggers[$name])) { 
  109. $klass = $this->_triggers[$name]; 
  110. if (call_user_func(array($klass, 'is_renderable'), $name, $displayed_gallery)) { 
  111. $handler = new $klass(); 
  112. $handler->name = $name; 
  113. $handler->view = $this->view = $view; 
  114. $handler->displayed_gallery = $displayed_gallery; 
  115. $retval = $handler->render(); 
  116. return $retval; 
  117. function render_triggers($view, $displayed_gallery) 
  118. $output = FALSE; 
  119. $css_class = esc_attr($this->css_class); 
  120. $retval = array("<div class='{$css_class}'>"); 
  121. foreach ($this->_trigger_order as $name) { 
  122. if ($markup = $this->render_trigger($name, $view, $displayed_gallery)) { 
  123. $output = TRUE; 
  124. $retval[] = $markup; 
  125. if ($output) { 
  126. $retval[] = "</div>"; 
  127. $retval = implode("\n", $retval); 
  128. } else { 
  129. $retval = ''; 
  130. return $retval; 
  131. function enqueue_resources($displayed_gallery) 
  132. if ($handler = $this->get_handler_for_displayed_gallery($displayed_gallery)) { 
  133. wp_enqueue_style('fontawesome'); 
  134. wp_enqueue_style('ngg_trigger_buttons'); 
  135. if (method_exists($handler, 'enqueue_resources')) { 
  136. call_user_func(array($handler, 'enqueue_resources'), $displayed_gallery); 
  137. foreach ($this->_trigger_order as $name) { 
  138. $handler = $this->_triggers[$name]; 
  139. $renderable = TRUE; 
  140. if (method_exists($handler, 'is_renderable')) { 
  141. $renderable = call_user_func($handler, 'is_renderable', $name, $displayed_gallery); 
  142. if ($renderable && method_exists($handler, 'enqueue_resources')) { 
  143. call_user_func(array($handler, 'enqueue_resources', $name, $displayed_gallery));