base.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /**
  3. * @file
  4. * Container class for theme configuration.
  5. */
  6. class alpha_theme_container {
  7. var $theme;
  8. var $settings;
  9. var $css;
  10. var $grid;
  11. var $grids;
  12. var $libraries;
  13. var $sections;
  14. var $zones;
  15. var $regions;
  16. var $page;
  17. /**
  18. * @todo
  19. */
  20. function __construct($theme, $delta = NULL) {
  21. $this->theme = $theme;
  22. $this->delta = $delta;
  23. if ($cache = alpha_cache_get($theme, $delta)) {
  24. foreach ($cache->data as $key => $item) {
  25. $this->$key = $item;
  26. }
  27. }
  28. foreach ($this->cacheable() as $item => $required) {
  29. if ($required && !isset($this->$item)) {
  30. $this->init();
  31. alpha_alter('alpha_pre_cache', $this, $theme, $delta);
  32. alpha_cache_set($this);
  33. return;
  34. }
  35. }
  36. alpha_alter('alpha', $this, $theme, $delta);
  37. }
  38. /**
  39. * @todo
  40. */
  41. function init() {
  42. $this->settings();
  43. $this->sections();
  44. $this->zones();
  45. $this->regions();
  46. $this->grids();
  47. $this->grid();
  48. $this->css();
  49. $this->libraries();
  50. }
  51. /**
  52. * @todo
  53. */
  54. function settings() {
  55. if (!isset($this->settings)) {
  56. $this->settings = array(
  57. 'grid' => alpha_theme_get_setting('alpha_grid', 'default', $this->theme),
  58. 'css' => alpha_theme_get_setting('alpha_css', array(), $this->theme),
  59. 'libraries' => alpha_theme_get_setting('alpha_libraries', array(), $this->theme),
  60. 'exclude' => alpha_theme_get_setting('alpha_exclude', array(), $this->theme),
  61. 'responsive' => alpha_theme_get_setting('alpha_responsive', FALSE, $this->theme),
  62. 'toggle' => array(),
  63. 'hidden' => array(),
  64. 'viewport' => array(
  65. 'enabled' => alpha_theme_get_setting('alpha_viewport', FALSE, $this->theme),
  66. 'initial' => alpha_theme_get_setting('alpha_viewport_initial_scale', 1, $this->theme),
  67. 'min' => alpha_theme_get_setting('alpha_viewport_min_scale', 1, $this->theme),
  68. 'max' => alpha_theme_get_setting('alpha_viewport_max_scale', 1, $this->theme),
  69. 'user' => alpha_theme_get_setting('alpha_viewport_user_scaleable', TRUE, $this->theme),
  70. ),
  71. 'debug' => array(
  72. 'block' => alpha_theme_get_setting('alpha_debug_block_toggle', FALSE, $this->theme),
  73. 'block_active' => alpha_theme_get_setting('alpha_debug_block_active', FALSE, $this->theme),
  74. 'grid' => alpha_theme_get_setting('alpha_debug_grid_toggle', FALSE, $this->theme),
  75. 'grid_active' => alpha_theme_get_setting('alpha_debug_grid_active', FALSE, $this->theme),
  76. 'roles' => array_keys(array_filter(alpha_theme_get_setting('alpha_debug_grid_roles', array(), $this->theme))),
  77. ),
  78. );
  79. foreach (alpha_toggle() as $item => $title) {
  80. $this->settings['toggle'][$item] = alpha_theme_get_setting('alpha_toggle_' . $item, TRUE, $this->theme);
  81. }
  82. foreach (alpha_visibility() as $item => $title) {
  83. $this->settings['hidden'][$item] = alpha_theme_get_setting('alpha_hidden_' . $item, FALSE, $this->theme);
  84. }
  85. alpha_alter('alpha_settings', $this->settings, $this->theme);
  86. }
  87. return $this->settings;
  88. }
  89. /**
  90. * @todo
  91. */
  92. function grids() {
  93. if (!isset($this->grids)) {
  94. $this->settings();
  95. $this->grids = alpha_retrieve_grids($this->theme);
  96. }
  97. return $this->grids;
  98. }
  99. /**
  100. * @todo
  101. */
  102. function grid() {
  103. if (!isset($this->grid)) {
  104. $this->grids();
  105. if (isset($this->grids[$this->settings['grid']])) {
  106. $this->grid = alpha_grid_css($this->theme, $this->grids[$this->settings['grid']], $this->settings['responsive']);
  107. }
  108. else {
  109. $this->grid = array();
  110. }
  111. }
  112. return $this->grid;
  113. }
  114. /**
  115. * @todo
  116. */
  117. function css() {
  118. if (!isset($this->css)) {
  119. $this->css = alpha_retrieve_css($this->theme);
  120. }
  121. return $this->css;
  122. }
  123. /**
  124. * @todo
  125. */
  126. function libraries() {
  127. if (!isset($this->libraries)) {
  128. $this->libraries = alpha_retrieve_libraries($this->theme);
  129. }
  130. return $this->libraries;
  131. }
  132. /**
  133. * @todo
  134. */
  135. function sections() {
  136. if (!isset($this->sections)) {
  137. $this->sections = array(
  138. 'header' => t('Header'),
  139. 'content' => t('Content'),
  140. 'footer' => t('Footer'),
  141. );
  142. }
  143. return $this->sections;
  144. }
  145. /**
  146. * @todo
  147. */
  148. function zones() {
  149. if (!isset($this->zones)) {
  150. $this->sections();
  151. $this->zones = array();
  152. if ($zones = alpha_info('zones', $this->theme)) {
  153. foreach ($zones as $zone => $title) {
  154. $section = alpha_zone_get_setting('section', $zone, NULL, $this->theme);
  155. $section = isset($this->sections[$section]) ? $section : NULL;
  156. $this->zones[$zone] = array(
  157. 'zone' => $zone,
  158. 'name' => $title,
  159. 'enabled' => isset($this->sections[$section]),
  160. 'force' => alpha_zone_get_setting('force', $zone, FALSE, $this->theme),
  161. 'columns' => alpha_zone_get_setting('columns', $zone, 0, $this->theme),
  162. 'section' => $section,
  163. 'weight' => alpha_zone_get_setting('weight', $zone, 0, $this->theme),
  164. 'wrapper' => alpha_zone_get_setting('wrapper', $zone, FALSE, $this->theme),
  165. 'wrapper_css' => alpha_zone_get_setting('wrapper_css', $zone, NULL, $this->theme),
  166. 'primary' => alpha_zone_get_setting('primary', $zone, NULL, $this->theme),
  167. 'order' => alpha_zone_get_setting('order', $zone, FALSE, $this->theme),
  168. 'css' => alpha_zone_get_setting('css', $zone, NULL, $this->theme),
  169. );
  170. }
  171. }
  172. uasort($this->zones, 'drupal_sort_weight');
  173. alpha_alter('alpha_zones', $this->zones, $this->theme);
  174. }
  175. return $this->zones;
  176. }
  177. /**
  178. * @todo
  179. */
  180. function regions() {
  181. if (!isset($this->regions)) {
  182. $this->zones();
  183. $this->sections();
  184. $this->regions = array();
  185. $exclude = alpha_regions_exclude();
  186. foreach (system_region_list($this->theme) as $region => $title) {
  187. if (!in_array($region, $exclude)) {
  188. $zone = alpha_region_get_setting('zone', $region, NULL, $this->theme);
  189. $prefix = alpha_region_get_setting('prefix', $region, 0, $this->theme);
  190. $columns = alpha_region_get_setting('columns', $region, 1, $this->theme);
  191. $suffix = alpha_region_get_setting('suffix', $region, 0, $this->theme);
  192. $zone = isset($zone) && isset($this->zones[$zone]) ? $zone : NULL;
  193. $section = isset($zone) && isset($this->zones[$zone]['section']) ? $this->zones[$zone]['section'] : NULL;
  194. $this->regions[$region] = array(
  195. 'region' => $region,
  196. 'name' => $title,
  197. 'zone' => $zone,
  198. 'section' => $section,
  199. 'enabled' => isset($zone),
  200. 'force' => alpha_region_get_setting('force', $region, FALSE, $this->theme),
  201. 'prefix' => $prefix,
  202. 'columns' => $columns,
  203. 'suffix' => $suffix,
  204. 'width' => $prefix + $columns + $suffix,
  205. 'push' => 0,
  206. 'pull' => 0,
  207. 'wrapper_css' => alpha_region_get_setting('css', $region, NULL, $this->theme),
  208. 'weight' => alpha_region_get_setting('weight', $region, 0, $this->theme),
  209. 'position' => alpha_region_get_setting('position', $region, 0, $this->theme),
  210. 'primary' => isset($zone) && $this->zones[$zone]['primary'] == $region,
  211. );
  212. }
  213. }
  214. uasort($this->regions, 'drupal_sort_weight');
  215. alpha_alter('alpha_regions', $this->regions, $this->theme);
  216. }
  217. return $this->regions;
  218. }
  219. /**
  220. * @todo
  221. */
  222. function cacheable() {
  223. $cacheable = array_fill_keys(array('settings', 'libraries', 'css', 'grids', 'grid', 'regions', 'zones', 'sections'), TRUE);
  224. alpha_alter('alpha_cacheable', $cacheable, $this->theme);
  225. return $cacheable;
  226. }
  227. }