context_layouts.module

Go to the documentation of this file.
00001 <?php
00002 
00003 /**
00004  * Implementation of hook_help().
00005  */
00006 function context_layouts_help($path, $arg) {
00007   switch ($path) {
00008     case 'admin/help#context_layouts':
00009       $output = file_get_contents(drupal_get_path('module', 'context_layouts') .'/README.txt');
00010       return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>'. check_plain($output) .'</pre>';
00011   }
00012 }
00013 
00014 /**
00015  * Implementation of hook_context_plugins().
00016  * This is a ctools plugins hook.
00017  */
00018 function context_layouts_context_plugins() {
00019   return array(
00020     'context_layouts_reaction_block' => array(
00021       'handler' => array(
00022         'path' => drupal_get_path('module', 'context_layouts') .'/plugins',
00023         'file' => 'context_layouts_reaction_block.inc',
00024         'class' => 'context_layouts_reaction_block',
00025         'parent' => 'context_reaction_block',
00026       ),
00027     ),
00028   );
00029 }
00030 
00031 /**
00032  * Implementation of hook_context_registry_alter().
00033  */
00034 function context_layouts_context_registry_alter(&$registry) {
00035   if (isset($registry['reactions']['block'])) {
00036     $registry['reactions']['block']['plugin'] = 'context_layouts_reaction_block';
00037   }
00038 }
00039 
00040 /**
00041  * Implementation of hook_theme().
00042  * Declares each theme's layouts as a page template suggestion.
00043  */
00044 function context_layouts_theme() {
00045   $info = array();
00046   foreach (list_themes() as $theme) {
00047     if (!empty($theme->status) && $layouts = context_layouts_get_layouts($theme->name)) {
00048       foreach ($layouts as $layout) {
00049         if (!empty($layout['template'])) {
00050           $info["page__context_layouts_{$theme->name}_{$layout['layout']}"] = array(
00051             'template' => $layout['template'],
00052             'path' => drupal_get_path('theme', $theme->name),
00053           );
00054         }
00055       }
00056     }
00057   }
00058   return $info;
00059 }
00060 
00061 /**
00062  * Implementation of hook_context_page_reaction().
00063  */
00064 function context_layouts_context_page_reaction() {
00065   $plugin = context_get_plugin('reaction', 'block');
00066   if ($plugin && method_exists($plugin, 'add_layout_stylesheet')) {
00067     $plugin->add_layout_stylesheet();
00068   }
00069 }
00070 
00071 /**
00072  * Preprocessor for theme('page').
00073  */
00074 function context_layouts_preprocess_page(&$vars) {
00075   $plugin = context_get_plugin('reaction', 'block');
00076   if ($plugin && method_exists($plugin, 'add_layout_template')) {
00077     $plugin->add_layout_template($vars);
00078   }
00079 }
00080 
00081 /**
00082  * Retrieve layouts for the specified theme.
00083  */
00084 function context_layouts_get_layouts($theme = NULL, $reset = FALSE) {
00085   static $layouts = array();
00086   $layouts = $reset ? array() : $layouts;
00087 
00088   global $theme_key;
00089   $theme = isset($theme) ? $theme : $theme_key;
00090 
00091   if (!isset($layouts[$theme])) {
00092     $info = system_get_info('theme', $theme);
00093     $themes = array();
00094 
00095     // Find all our ancestor themes that use layouts.
00096     if (isset($info['base theme'])) {
00097       while (!empty($info['base theme'])) {
00098         $base_theme = $info['base theme'];
00099         $info = system_get_info('theme', $base_theme);
00100         $themes[$base_theme] = $info;
00101       }
00102     }
00103 
00104     // Assemble in inheritance order and add the theme on.
00105     $themes = array_reverse($themes);
00106     $themes[$theme] = system_get_info('theme', $theme);
00107 
00108     // Merge layout info into a single array.
00109     foreach ($themes as $key => $info) {
00110       if (!empty($info['layouts'])) {
00111         foreach ($info['layouts'] as $layout => $layout_info) {
00112           $layout_info['layout'] = str_replace('-', '_', $layout);
00113           $layout_info['theme'] = $key;
00114           $layouts[$theme][$layout] = $layout_info;
00115         }
00116       }
00117     }
00118   }
00119   return isset($layouts[$theme]) ? $layouts[$theme] : FALSE;
00120 }
00121 
00122 /**
00123  * Get the active layout for the current page.
00124  */
00125 function context_layouts_get_active_layout($info = TRUE) {
00126   $plugin = context_get_plugin('reaction', 'block');
00127   if ($plugin && method_exists($plugin, 'get_active_layout')) {
00128     return $plugin->get_active_layout($info);
00129   }
00130 }

Generated on Thu May 23 02:23:48 2013 for Context by  doxygen 1.4.7