| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: features.context.inc,v 1.1.2.19 2010/07/29 21:57:08 yhahn Exp $ 3 4 /** 5 * Determine context major branch version. 6 */ 7 function context_features_get_version() { 8 if (function_exists('context_context_plugins')) { 9 return 3; 10 } 11 return 2; 12 } 13 14 /** 15 * Implementation of hook_features_api(). 16 */ 17 function context_features_api() { 18 $api = array('context' => array()); 19 // 3.x 20 if (context_features_get_version() === 3) { 21 $api['context'] = array( 22 'api' => 'context', 23 'current_version' => 3, 24 'module' => 'context', 25 'default_file' => FEATURES_DEFAULTS_CUSTOM, 26 'default_filename' => 'context', 27 ); 28 } 29 // 2.x 30 $api['context'] += array( 31 'name' => 'Contexts', 32 'feature_source' => TRUE, 33 'default_hook' => 'context_default_contexts' 34 ); 35 return $api; 36 } 37 38 /** 39 * Implementation of hook_features_export_options(); 40 */ 41 function context_features_export_options() { 42 // 3.x 43 if (context_features_get_version() === 3) { 44 return ctools_component_features_export_options('context'); 45 } 46 // 2.x 47 $contexts = context_enabled_contexts(); 48 $options = array(); 49 foreach ($contexts as $identifier => $context) { 50 $options[$identifier] = "{$context->namespace} > {$context->attribute} > {$context->value}"; 51 } 52 return $options; 53 } 54 55 /** 56 * Implementation of hook_features_export(). 57 */ 58 function context_features_export($data, &$export, $module_name = '') { 59 // 3.x 60 if (context_features_get_version() === 3) { 61 $pipe = ctools_component_features_export('context', $data, $export, $module_name); 62 63 $contexts = context_load(); 64 foreach ($data as $identifier) { 65 if (isset($contexts[$identifier])) { 66 $context = $contexts[$identifier]; 67 // Conditions. 68 // Currently only node and views conditions are supported. 69 // @TODO: Should this be delegated to a method on the plugin? 70 foreach (array('node', 'views') as $key) { 71 if (!empty($context->conditions{$key}['values'])) { 72 foreach ($context->conditions{$key}['values'] as $item) { 73 // Special pipe for views 74 if ($key === 'views') { 75 $split = explode(':', $item); 76 $view_name = array_shift($split); 77 $pipe[$key][$view_name] = $view_name; 78 } 79 else { 80 $pipe[$key][$item] = $item; 81 } 82 } 83 } 84 } 85 // Reactions. 86 if (!empty($context->reactions['block']['blocks'])) { 87 foreach ($context->reactions['block']['blocks'] as $block) { 88 $block = (array) $block; 89 $bid = "{$block['module']}-{$block['delta']}"; 90 $pipe['block'][$bid] = $bid; 91 } 92 } 93 } 94 } 95 return $pipe; 96 } 97 98 // 2.x 99 $export['dependencies']['context'] = 'context'; 100 101 // Collect a context to module map 102 $map = features_get_default_map('context', NULL, 'context_features_identifier_2'); 103 $pipe = array(); 104 $contexts = context_enabled_contexts(); 105 foreach ($data as $identifier) { 106 // If this context is already provided by another module, add it 107 // as a dependency and prevent it from becoming a duplicate export. 108 if (isset($map[$identifier]) && $map[$identifier] != $module_name) { 109 if (isset($export['features']['context'][$identifier])) { 110 unset($export['features']['context'][$identifier]); 111 } 112 $module = $map[$identifier]; 113 $export['dependencies'][$module] = $module; 114 } 115 // Otherwise, export it. 116 else if (!empty($contexts[$identifier])) { 117 $export['features']['context'][$identifier] = $identifier; 118 119 $context = $contexts[$identifier]; 120 121 foreach (array('node', 'menu') as $key) { 122 if (!empty($context->{$key})) { 123 if (is_array($context->{$key})) { 124 foreach ($context->{$key} as $item) { 125 $pipe[$key][$item] = $item; 126 } 127 } 128 else { 129 $item = $context->{$key}; 130 $pipe[$key][$item] = $item; 131 } 132 } 133 } 134 135 // Special pipe for views 136 if (!empty($context->views) && is_array($context->views)) { 137 foreach ($context->views as $view_name) { 138 $split = explode(':', $view_name); 139 $view_name = array_shift($split); 140 $pipe['views'][$view_name] = $view_name; 141 } 142 } 143 144 // Special pipe for blocks 145 if (!empty($context->block)) { 146 foreach ($context->block as $block) { 147 $block = (array) $block; 148 $bid = "{$block['module']}-{$block['delta']}"; 149 $pipe['block'][$bid] = $bid; 150 } 151 } 152 } 153 } 154 return $pipe; 155 } 156 157 /** 158 * Implementation of hook_features_export_render(). 159 */ 160 function context_features_export_render($module, $data) { 161 // 3.x 162 if (context_features_get_version() === 3) { 163 return ctools_component_features_export_render('context', $module, $data); 164 } 165 // 2.x 166 $code = array(); 167 $code[] = ' $items = array();'; 168 $code[] = ''; 169 170 foreach ($data as $identifier) { 171 $contexts = context_enabled_contexts(); 172 $context = $contexts[$identifier]; 173 174 // prune system specific information and cast for Drupal's AOP (array oriented programming) 175 $prune = array('cid', 'status', 'system', 'type'); 176 foreach ($prune as $key) { 177 if (isset($context->{$key})) { 178 unset($context->{$key}); 179 } 180 } 181 $context = (array) $context; 182 183 // clean up blocks 184 if (!empty($context['block'])) { 185 foreach ($context['block'] as $bid => $block) { 186 unset($block->bid); 187 $context['block'][$bid] = (array) $block; 188 } 189 } 190 191 $context_identifier = context_var_export($identifier); 192 $context_export = context_var_export($context, ' '); 193 $code[] = " \$items[{$context_identifier}] = {$context_export};"; 194 } 195 196 $code[] = ' return $items;'; 197 $code = implode("\n", $code); 198 return array('context_default_contexts' => $code); 199 } 200 201 /** 202 * Implementation of hook_features_revert(). 203 * 204 * @param $module 205 * name of module to revert content for 206 */ 207 function context_features_revert($module = NULL) { 208 // 3.x 209 if (context_features_get_version() === 3) { 210 $return = ctools_component_features_revert('context', $module); 211 context_invalidate_cache(); 212 return $return; 213 } 214 // 2.x 215 if ($default_contexts = features_get_default('context', $module)) { 216 foreach($default_contexts as $default_context) { 217 $current_context = new StdClass(); 218 $current_context->namespace = $default_context['namespace']; 219 $current_context->attribute = $default_context['attribute']; 220 $current_context->value = $default_context['value']; 221 $context_to_delete = context_load_context($current_context); 222 context_delete_context($context_to_delete); 223 } 224 } 225 } 226 227 /** 228 * 2.x: Callback for generating the context exportable identifier. 229 */ 230 function context_features_identifier_2($object) { 231 return isset($object->namespace, $object->attribute, $object->value) ? "{$object->namespace}-{$object->attribute}-{$object->value}" : FALSE; 232 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |