Mixin_Mvc_View_Instance_Methods

The NextGEN Gallery Mixin Mvc View Instance Methods class.

Defined (1)

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

/products/photocrati_nextgen/modules/mvc/package.module.mvc.php  
  1. class Mixin_Mvc_View_Instance_Methods extends Mixin 
  2. /** 
  3. * Returns the variables to be used in the template 
  4. * @return array 
  5. */ 
  6. function get_template_vars() 
  7. $retval = array(); 
  8. foreach ($this->object->_params as $key => $value) { 
  9. if (strpos($key, '_template') !== FALSE) { 
  10. $value = $this->object->get_template_abspath($value); 
  11. $retval[$key] = $value; 
  12. return $retval; 
  13. /** 
  14. * Returns the abspath of the template to be rendered 
  15. * @param string $key 
  16. * @return string 
  17. */ 
  18. function get_template_abspath($value = NULL) 
  19. if (!$value) { 
  20. $value = $this->object->_template; 
  21. if ($value[0] == '/' && @file_exists($value)) { 
  22. // key is already abspath 
  23. } else { 
  24. $value = $this->object->find_template_abspath($value); 
  25. return $value; 
  26. /** 
  27. * Renders the view (template) 
  28. * @param string $__return 
  29. * @return string|NULL 
  30. */ 
  31. function render($return = FALSE) 
  32. $element = $this->object->render_object(); 
  33. $content = $this->object->rasterize_object($element); 
  34. if (!$return) { 
  35. echo $content; 
  36. return $content; 
  37. function render_object() 
  38. // We use underscores to prefix local variables to avoid conflicts wth 
  39. // template vars 
  40. $__element = $this->start_element($this->object->_template, 'template', $this->object); 
  41. extract($this->object->get_template_vars()); 
  42. include $this->object->get_template_abspath(); 
  43. $this->end_element(); 
  44. return $__element; 
  45. function rasterize_object($element) 
  46. return $element->rasterize(); 
  47. function start_element($id, $type = null, $context = null) 
  48. if ($type == null) { 
  49. $type = 'element'; 
  50. $count = count($this->object->_queue); 
  51. $element = new C_MVC_View_Element($id, $type); 
  52. if ($context != null) { 
  53. if (!is_array($context)) { 
  54. $context = array('object' => $context); 
  55. foreach ($context as $context_name => $context_value) { 
  56. $element->set_context($context_name, $context_value); 
  57. $this->object->_queue[] = $element; 
  58. if ($count > 0) { 
  59. $old_element = $this->object->_queue[$count - 1]; 
  60. $content = ob_get_contents(); 
  61. ob_clean(); 
  62. $old_element->append($content); 
  63. $old_element->append($element); 
  64. ob_start(); 
  65. return $element; 
  66. function end_element() 
  67. $content = ob_get_clean(); 
  68. $element = array_pop($this->object->_queue); 
  69. if ($content != null) { 
  70. $element->append($content); 
  71. return $element; 
  72. /** 
  73. * Renders a sub-template for the view 
  74. * @param string $__template 
  75. * @param array $__params 
  76. * @param string $__return 
  77. * @return NULL 
  78. */ 
  79. function include_template($__template, $__params = null, $__return = FALSE) 
  80. // We use underscores to prefix local variables to avoid conflicts wth 
  81. // template vars 
  82. if ($__params == null) { 
  83. $__params = array(); 
  84. $__params['template_origin'] = $this->object->_template; 
  85. $__target = $this->object->get_template_abspath($__template); 
  86. $__origin_target = $this->object->get_template_abspath($this->object->_template); 
  87. $__image_before_target = $this->object->get_template_abspath('photocrati-nextgen_gallery_display#image/before'); 
  88. $__image_after_target = $this->object->get_template_abspath('photocrati-nextgen_gallery_display#image/after'); 
  89. if ($__origin_target != $__target) { 
  90. if ($__target == $__image_before_target) { 
  91. $__image = isset($__params['image']) ? $__params['image'] : null; 
  92. $this->start_element('nextgen_gallery.image_panel', 'item', $__image); 
  93. if ($__target == $__image_after_target) { 
  94. $this->end_element(); 
  95. extract($__params); 
  96. include $__target; 
  97. if ($__target == $__image_before_target) { 
  98. $__image = isset($__params['image']) ? $__params['image'] : null; 
  99. $this->start_element('nextgen_gallery.image', 'item', $__image); 
  100. if ($__target == $__image_after_target) { 
  101. $this->end_element(); 
  102. /** 
  103. * Gets the absolute path of an MVC template file 
  104. * @param string $path 
  105. * @param string $module 
  106. * @return string 
  107. */ 
  108. function find_template_abspath($path, $module = FALSE) 
  109. $fs = C_Fs::get_instance(); 
  110. $settings = C_NextGen_Settings::get_instance(); 
  111. // We also accept module_name#path, which needs parsing. 
  112. if (!$module) { 
  113. list($path, $module) = $fs->parse_formatted_path($path); 
  114. // Append the suffix 
  115. $path = $path . '.php'; 
  116. // First check if the template is in the override dir 
  117. if (!($retval = $this->object->get_template_override_abspath($module, $path))) { 
  118. $retval = $fs->join_paths($this->object->get_registry()->get_module_dir($module), $settings->mvc_template_dirname, $path); 
  119. if (!@file_exists($retval)) { 
  120. throw new RuntimeException("{$retval} is not a valid MVC template"); 
  121. return $retval; 
  122. function get_template_override_dir($module = NULL) 
  123. $fs = C_Fs::get_instance(); 
  124. $dir = $fs->join_paths(WP_CONTENT_DIR, 'ngg'); 
  125. if (!@file_exists($dir)) { 
  126. wp_mkdir_p($dir); 
  127. $dir = $fs->join_paths($dir, 'modules'); 
  128. if (!@file_exists($dir)) { 
  129. wp_mkdir_p($dir); 
  130. if ($module) { 
  131. $dir = $fs->join_paths($dir, $module); 
  132. if (!@file_exists($dir)) { 
  133. wp_mkdir_p($dir); 
  134. $dir = $fs->join_paths($dir, 'templates'); 
  135. if (!@file_exists($dir)) { 
  136. wp_mkdir_p($dir); 
  137. return $dir; 
  138. function get_template_override_abspath($module, $filename) 
  139. $fs = C_Fs::get_instance(); 
  140. $retval = NULL; 
  141. $abspath = $fs->join_paths($this->object->get_template_override_dir($module), $filename); 
  142. if (@file_exists($abspath)) { 
  143. $retval = $abspath; 
  144. return $retval; 
  145. /** 
  146. * Adds a template parameter 
  147. * @param $key 
  148. * @param $value 
  149. */ 
  150. function set_param($key, $value) 
  151. $this->object->_params[$key] = $value; 
  152. /** 
  153. * Removes a template parameter 
  154. * @param $key 
  155. */ 
  156. function remove_param($key) 
  157. unset($this->object->_params[$key]); 
  158. /** 
  159. * Gets the value of a template parameter 
  160. * @param $key 
  161. * @param null $default 
  162. * @return mixed 
  163. */ 
  164. function get_param($key, $default = NULL) 
  165. if (isset($this->object->_params[$key])) { 
  166. return $this->object->_params[$key]; 
  167. } else { 
  168. return $default;