context_layouts.module 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Implementation of hook_help().
  4. */
  5. function context_layouts_help($path, $arg) {
  6. switch ($path) {
  7. case 'admin/help#context_layouts':
  8. $output = file_get_contents(drupal_get_path('module', 'context_layouts') .'/README.txt');
  9. return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>'. check_plain($output) .'</pre>';
  10. }
  11. }
  12. /**
  13. * Implementation of hook_context_plugins().
  14. * This is a ctools plugins hook.
  15. */
  16. function context_layouts_context_plugins() {
  17. return array(
  18. 'context_layouts_reaction_block' => array(
  19. 'handler' => array(
  20. 'path' => drupal_get_path('module', 'context_layouts') .'/plugins',
  21. 'file' => 'context_layouts_reaction_block.inc',
  22. 'class' => 'context_layouts_reaction_block',
  23. 'parent' => 'context_reaction_block',
  24. ),
  25. ),
  26. );
  27. }
  28. /**
  29. * Implementation of hook_context_registry_alter().
  30. */
  31. function context_layouts_context_registry_alter(&$registry) {
  32. if (isset($registry['reactions']['block'])) {
  33. $registry['reactions']['block']['plugin'] = 'context_layouts_reaction_block';
  34. }
  35. }
  36. /**
  37. * Implementation of hook_theme().
  38. * Declares each theme's layouts as a page template suggestion.
  39. */
  40. function context_layouts_theme() {
  41. $info = array();
  42. foreach (list_themes() as $theme) {
  43. if (!empty($theme->status) && $layouts = context_layouts_get_layouts($theme->name)) {
  44. foreach ($layouts as $layout) {
  45. if (!empty($layout['template'])) {
  46. $info["page__context_layouts_{$theme->name}_{$layout['layout']}"] = array(
  47. 'template' => $layout['template'],
  48. 'path' => $layout['path'],
  49. );
  50. }
  51. }
  52. }
  53. }
  54. return $info;
  55. }
  56. /**
  57. * Implementation of hook_context_page_reaction().
  58. */
  59. function context_layouts_context_page_reaction() {
  60. $plugin = context_get_plugin('reaction', 'block');
  61. if ($plugin && method_exists($plugin, 'add_layout_stylesheet')) {
  62. $plugin->add_layout_stylesheet();
  63. }
  64. }
  65. /**
  66. * Preprocessor for theme('page').
  67. */
  68. function context_layouts_preprocess_page(&$vars) {
  69. $plugin = context_get_plugin('reaction', 'block');
  70. if ($plugin && method_exists($plugin, 'add_layout_template')) {
  71. $plugin->add_layout_template($vars);
  72. }
  73. }
  74. /**
  75. * Retrieve layouts for the specified theme.
  76. */
  77. function context_layouts_get_layouts($theme = NULL, $reset = FALSE) {
  78. static $layouts = array();
  79. $layouts = $reset ? array() : $layouts;
  80. global $theme_key;
  81. $theme = isset($theme) ? $theme : $theme_key;
  82. if (!isset($layouts[$theme])) {
  83. $info = system_get_info('theme', $theme);
  84. $themes = array();
  85. // Find all our ancestor themes that use layouts.
  86. if (isset($info['base theme'])) {
  87. while (!empty($info['base theme'])) {
  88. $base_theme = $info['base theme'];
  89. $info = system_get_info('theme', $base_theme);
  90. $themes[$base_theme] = $info;
  91. }
  92. }
  93. // Assemble in inheritance order and add the theme on.
  94. $themes = array_reverse($themes);
  95. $themes[$theme] = system_get_info('theme', $theme);
  96. // Merge layout info into a single array.
  97. foreach ($themes as $key => $info) {
  98. $path = drupal_get_path('theme', $key);
  99. if (!empty($info['layouts'])) {
  100. foreach ($info['layouts'] as $layout => $layout_info) {
  101. $layout_info['layout'] = str_replace('-', '_', $layout);
  102. $layout_info['theme'] = $key;
  103. $layout_info['path'] = $path;
  104. $layouts[$theme][$layout] = $layout_info;
  105. }
  106. }
  107. }
  108. }
  109. return isset($layouts[$theme]) ? $layouts[$theme] : FALSE;
  110. }
  111. /**
  112. * Get the active layout for the current page.
  113. */
  114. function context_layouts_get_active_layout($info = TRUE) {
  115. $plugin = context_get_plugin('reaction', 'block');
  116. if ($plugin && method_exists($plugin, 'get_active_layout')) {
  117. return $plugin->get_active_layout($info);
  118. }
  119. }