PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/_app/core/api/theme.php

https://bitbucket.org/sirestudios/fortis-wellness
PHP | 145 lines | 33 code | 17 blank | 95 comment | 0 complexity | bad9302efe36738aa4baad76bacde0a5 MD5 | raw file
Possible License(s): JSON
  1. <?php
  2. /**
  3. * Theme
  4. * API for interacting with the site's themes
  5. *
  6. * @author Jack McDade
  7. * @author Fred LeBlanc
  8. * @author Mubashar Iqbal
  9. * @package API
  10. * @copyright 2013 Statamic
  11. */
  12. class Theme
  13. {
  14. // theme
  15. // ------------------------------------------------------------------------
  16. /**
  17. * Returns the current theme folder name
  18. *
  19. * @return string
  20. */
  21. public static function getName()
  22. {
  23. return Config::getTheme();
  24. }
  25. /**
  26. * Returns the path to the current theme
  27. *
  28. * @return string
  29. */
  30. public static function getPath()
  31. {
  32. return Config::getCurrentThemePath();
  33. }
  34. // templates
  35. // ------------------------------------------------------------------------
  36. /**
  37. * Fetches the contents of a template
  38. *
  39. * @param string $template Name of template to retrieve
  40. * @return string
  41. */
  42. public static function getTemplate($template)
  43. {
  44. return File::get(self::getTemplatePath() . $template . '.html');
  45. }
  46. /**
  47. * Returns a given $template parsed with given $data
  48. *
  49. * @param string $template Template to parse
  50. * @param array $data Associative array of data to fill into template
  51. * @return string
  52. */
  53. public static function getParsedTemplate($template, Array $data=array())
  54. {
  55. $parser = new Lex\Parser();
  56. $template_path = Config::getTemplatesPath() . '/templates/' . ltrim($template, '/') . '.html';
  57. return $parser->parse(File::get($template_path, ""), $data, array('statamic_view', 'callback'));
  58. }
  59. /**
  60. * Returns a list of templates for this theme
  61. *
  62. * @param string $theme Optional theme to list from, otherwise, current theme
  63. * @return array
  64. */
  65. public static function getTemplates($theme=NULL)
  66. {
  67. $templates = array();
  68. $list = glob("_themes/" . Helper::pick($theme, Config::getTheme()) . "/templates/*");
  69. if ($list) {
  70. foreach ($list as $name) {
  71. if (is_dir($name)) {
  72. $folder_array = explode('/',rtrim($name,'/'));
  73. $folder_name = end($folder_array);
  74. $sub_list = glob($name.'/*');
  75. foreach ($sub_list as $sub_name) {
  76. $start = strrpos($sub_name, "/")+1;
  77. $end = strrpos($sub_name, ".");
  78. $templates[] = $folder_name.'/'.substr($sub_name, $start, $end-$start);
  79. }
  80. } else {
  81. $start = strrpos($name, "/")+1;
  82. $end = strrpos($name, ".");
  83. $templates[] = substr($name, $start, $end-$start);
  84. }
  85. }
  86. return $templates;
  87. }
  88. return array();
  89. }
  90. /**
  91. * Returns the path to the current theme's template directory
  92. *
  93. * @return string
  94. */
  95. public static function getTemplatePath()
  96. {
  97. return self::getPath() . 'templates/';
  98. }
  99. // layouts
  100. // ------------------------------------------------------------------------
  101. /**
  102. * Returns a list of layouts for a given $theme, or current theme if no $theme passed
  103. *
  104. * @param mixed $theme Theme to list layouts from, or current if none is passed
  105. * @return array
  106. */
  107. public static function getLayouts($theme=NULL)
  108. {
  109. $layouts = array();
  110. $list = glob("_themes/" . Helper::pick($theme, Config::getTheme()) . "/layouts/*");
  111. if ($list) {
  112. foreach ($list as $name) {
  113. $start = strrpos($name, "/")+1;
  114. $end = strrpos($name, ".");
  115. $layouts[] = substr($name, $start, $end-$start);
  116. }
  117. }
  118. return $layouts;
  119. }
  120. }