C_Displayed_Gallery_Source_Manager

The NextGEN Gallery C Displayed Gallery Source Manager class.

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_Source_Manager 
  2. private $_sources = array(); 
  3. private $_entity_types = array(); 
  4. private $_registered_defaults = array(); 
  5. /** @var C_Displayed_Gallery_Source_Manager */ 
  6. static $_instance = NULL; 
  7. static function get_instance() 
  8. if (!isset(self::$_instance)) { 
  9. $klass = get_class(); 
  10. self::$_instance = new $klass(); 
  11. return self::$_instance; 
  12. function register_defaults() 
  13. // Entity types must be registered first!!! 
  14. // ---------------------------------------- 
  15. $this->register_entity_type('gallery', 'galleries'); 
  16. $this->register_entity_type('image', 'images'); 
  17. $this->register_entity_type('album', 'albums'); 
  18. // Galleries 
  19. $galleries = new stdClass(); 
  20. $galleries->name = 'galleries'; 
  21. $galleries->title = __('Galleries', 'nggallery'); 
  22. $galleries->aliases = array('gallery', 'images', 'image'); 
  23. $galleries->returns = array('image'); 
  24. $this->register($galleries->name, $galleries); 
  25. // Albums 
  26. $albums = new stdClass(); 
  27. $albums->name = 'albums'; 
  28. $albums->title = __('Albums', 'nggallery'); 
  29. $albums->aliases = array('album'); 
  30. $albums->returns = array('album', 'gallery'); 
  31. $this->register($albums->name, $albums); 
  32. // Tags 
  33. $tags = new stdClass(); 
  34. $tags->name = 'tags'; 
  35. $tags->title = __('Tags', 'nggallery'); 
  36. $tags->aliases = array('tag', 'image_tags', 'image_tag'); 
  37. $tags->returns = array('image'); 
  38. $this->register($tags->name, $tags); 
  39. // Random Images; 
  40. $random = new stdClass(); 
  41. $random->name = 'random_images'; 
  42. $random->title = __('Random Images', 'nggallery'); 
  43. $random->aliases = array('random', 'random_image'); 
  44. $random->returns = array('image'); 
  45. $random->has_variations = TRUE; 
  46. $this->register($random->name, $random); 
  47. // Recent Images 
  48. $recent = new stdClass(); 
  49. $recent->name = 'recent_images'; 
  50. $recent->title = __('Recent Images', 'nggallery'); 
  51. $recent->aliases = array('recent', 'recent_image'); 
  52. $recent->returns = array('image'); 
  53. $this->register($recent->name, $recent); 
  54. $this->_registered_defaults = TRUE; 
  55. function register($name, $properties) 
  56. // We'll use an object to represent the source 
  57. $object = $properties; 
  58. if (!is_object($properties)) { 
  59. $object = new stdClass(); 
  60. foreach ($properties as $k => $v) { 
  61. $object->{$k} = $v; 
  62. // Set default properties 
  63. $object->name = $name; 
  64. if (!isset($object->title)) { 
  65. $object->title = $name; 
  66. if (!isset($object->returns)) { 
  67. $object->returns = array(); 
  68. if (!isset($object->aliases)) { 
  69. $object->aliases = array(); 
  70. if (!isset($object->has_variations)) { 
  71. $object->has_variations = FALSE; 
  72. // Add internal reference 
  73. $this->_sources[$name] = $object; 
  74. foreach ($object->aliases as $name) { 
  75. $this->_sources[$name] = $object; 
  76. function register_entity_type() 
  77. $aliases = func_get_args(); 
  78. $name = array_shift($aliases); 
  79. $this->_entity_types[] = $name; 
  80. foreach ($aliases as $alias) { 
  81. $this->_entity_types[$alias] = $name; 
  82. function deregister($name) 
  83. if ($source = $this->get($name)) { 
  84. unset($this->_sources[$name]); 
  85. foreach ($source->aliases as $alias) { 
  86. unset($this->_sources[$alias]); 
  87. function deregister_entity_type($name) 
  88. unset($this->_entity_types[$name]); 
  89. function get($name_or_alias) 
  90. if (!$this->_registered_defaults) { 
  91. $this->register_defaults(); 
  92. $retval = NULL; 
  93. if (isset($this->_sources[$name_or_alias])) { 
  94. $retval = $this->_sources[$name_or_alias]; 
  95. return $retval; 
  96. function get_entity_type($name) 
  97. if (!$this->_registered_defaults) { 
  98. $this->register_defaults(); 
  99. $found = array_search($name, $this->_entity_types); 
  100. if ($found) { 
  101. return $this->_entity_types[$found]; 
  102. } else { 
  103. return NULL; 
  104. function get_all() 
  105. if (!$this->_registered_defaults) { 
  106. $this->register_defaults(); 
  107. $retval = array(); 
  108. foreach (array_values($this->_sources) as $source_obj) { 
  109. if (!in_array($source_obj, $retval)) { 
  110. $retval[] = $source_obj; 
  111. usort($retval, array(&$this, '__sort_by_name')); 
  112. return $retval; 
  113. function __sort_by_name($a, $b) 
  114. return strcmp($a->name, $b->name); 
  115. function get_all_entity_types() 
  116. if (!$this->_registered_defaults) { 
  117. $this->register_defaults(); 
  118. return array_unique(array_values($this->_entity_types)); 
  119. function is_registered($name) 
  120. return !is_null($this->get($name)); 
  121. function is_valid_entity_type($name) 
  122. return !is_null($this->get_entity_type($name)); 
  123. function deregister_all() 
  124. $this->_sources = array(); 
  125. $this->_entity_types = array(); 
  126. $this->_registered_defaults = FALSE; 
  127. function is_compatible($source, $display_type) 
  128. $retval = FALSE; 
  129. if ($source = $this->get($source->name)) { 
  130. // Get the real entity type names for the display type 
  131. $display_type_entity_types = array(); 
  132. foreach ($display_type->entity_types as $type) { 
  133. $result = $this->get_entity_type($type); 
  134. if ($result) { 
  135. $display_type_entity_types[] = $result; 
  136. foreach ($source->returns as $entity_type) { 
  137. if (in_array($entity_type, $display_type_entity_types, TRUE)) { 
  138. $retval = TRUE; 
  139. break; 
  140. return $retval;