Mixin_Legacy_Template_Locator

Provides instance methods for the legacy template locator.

Defined (1)

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

/products/photocrati_nextgen/modules/nextgen_basic_templates/package.module.nextgen_basic_templates.php  
  1. class Mixin_Legacy_Template_Locator extends Mixin 
  2. /** 
  3. * Returns an array of template storing directories 
  4. * @return array Template storing directories 
  5. */ 
  6. function get_template_directories() 
  7. return apply_filters('ngg_legacy_template_directories', array('Child Theme' => get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'nggallery' . DIRECTORY_SEPARATOR, 'Parent Theme' => get_template_directory() . DIRECTORY_SEPARATOR . 'nggallery' . DIRECTORY_SEPARATOR, 'NextGEN Legacy' => NGGALLERY_ABSPATH . 'view' . DIRECTORY_SEPARATOR, 'NextGEN Overrides' => implode(DIRECTORY_SEPARATOR, array(WP_CONTENT_DIR, 'ngg', 'legacy', 'templates')))); 
  8. /** 
  9. * Returns an array of all available template files 
  10. * @return array All available template files 
  11. */ 
  12. function find_all($prefix = FALSE) 
  13. $files = array(); 
  14. foreach ($this->object->get_template_directories() as $label => $dir) { 
  15. $tmp = $this->object->get_templates_from_dir($dir, $prefix); 
  16. if (!$tmp) { 
  17. continue; 
  18. $files[$label] = $tmp; 
  19. return $files; 
  20. /** 
  21. * Recursively scans $dir for files ending in .php 
  22. * @param string $dir Directory 
  23. * @return array All php files in $dir 
  24. */ 
  25. function get_templates_from_dir($dir, $prefix = FALSE) 
  26. if (!is_dir($dir)) { 
  27. return; 
  28. $dir = new RecursiveDirectoryIterator($dir); 
  29. $iterator = new RecursiveIteratorIterator($dir); 
  30. // convert single-item arrays to string 
  31. if (is_array($prefix) && count($prefix) <= 1) { 
  32. $prefix = end($prefix); 
  33. // we can filter results by allowing a set of prefixes, one prefix, or by showing all available files 
  34. if (is_array($prefix)) { 
  35. $str = implode('|', $prefix); 
  36. $regex_iterator = new RegexIterator($iterator, "/({$str})-.+\\.php\$/i", RecursiveRegexIterator::GET_MATCH); 
  37. } elseif (is_string($prefix)) { 
  38. $regex_iterator = new RegexIterator($iterator, "#(.*)[/\\\\]{$prefix}\\-?.*\\.php\$#i", RecursiveRegexIterator::GET_MATCH); 
  39. } else { 
  40. $regex_iterator = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH); 
  41. $files = array(); 
  42. foreach ($regex_iterator as $filename) { 
  43. $files[] = reset($filename); 
  44. return $files; 
  45. /** 
  46. * Find a particular template by name 
  47. * @param $template 
  48. */ 
  49. function find($template_name) 
  50. $template_abspath = FALSE; 
  51. // hook into the render feature to allow other plugins to include templates 
  52. $custom_template = apply_filters('ngg_render_template', FALSE, $template_name); 
  53. if ($custom_template === FALSE) { 
  54. $custom_template = $template_name; 
  55. // Ensure we have a PHP extension 
  56. if (strpos($custom_template, '.php') === FALSE) { 
  57. $custom_template .= '.php'; 
  58. // Find the abspath of the template to render 
  59. if (!@file_exists($custom_template)) { 
  60. foreach ($this->object->get_template_directories() as $dir) { 
  61. if ($template_abspath) { 
  62. break; 
  63. $filename = implode(DIRECTORY_SEPARATOR, array(rtrim($dir, "/\\"), $custom_template)); 
  64. if (@file_exists($filename)) { 
  65. $template_abspath = $filename; 
  66. } elseif (strpos($custom_template, '-template') === FALSE) { 
  67. $filename = implode(DIRECTORY_SEPARATOR, array(rtrim($dir, "/\\"), str_replace('.php', '', $custom_template) . '-template.php')); 
  68. if (@file_exists($filename)) { 
  69. $template_abspath = $filename; 
  70. } else { 
  71. // An absolute path was already given 
  72. $template_abspath = $custom_template; 
  73. return $template_abspath;