| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: search.inc,v 1.1.2.3 2010/07/16 00:40:13 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * Handle the 'node view' override task. 7 * 8 * This plugin overrides node/%node and reroutes it to the page manager, where 9 * a list of tasks can be used to service this request based upon criteria 10 * supplied by access plugins. 11 */ 12 13 /** 14 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for 15 * more information. 16 */ 17 function page_manager_search_page_manager_tasks() { 18 if (!module_exists('search')) { 19 return; 20 } 21 22 return array( 23 // This is a 'page' task and will fall under the page admin UI 24 'task type' => 'page', 25 'title' => t('Search'), 26 27 // There are multiple search pages, let's override each of them 28 // separately. 29 'subtasks' => TRUE, 30 'subtask callback' => 'page_manager_search_subtask', 31 'subtasks callback' => 'page_manager_search_subtasks', 32 33 // Menu hooks so that we can alter the node/%node menu entry to point to us. 34 'hook menu alter' => 'page_manager_search_menu_alter', 35 36 // This is task uses 'context' handlers and must implement these to give the 37 // handler data it needs. 38 'handler type' => 'context', 39 'get arguments' => 'page_manager_search_get_arguments', 40 'get context placeholders' => 'page_manager_search_get_contexts', 41 42 ); 43 } 44 45 /** 46 * Callback defined by page_manager_search_page_manager_tasks(). 47 * 48 * Alter the search tabs to work with page manager. The search flow is 49 * quite odd, and tracing through the code takes hours to realize 50 * that the tab you click on does not normally actually handle 51 * the search. This tries to account for that. 52 * 53 * Note to module authors: This tends to work a lot better with modules 54 * that override their own search pages if their _alter runs *before* 55 * this one. 56 */ 57 function page_manager_search_menu_alter(&$items, $task) { 58 // We are creating two sets of tabs. One set is for searching without 59 // keywords. A second set is for searching *with* keywords. This 60 // is necessary because search/node/% and search/node need to be 61 // different due to the way the search menu items function. 62 63 // Go through each search module item. 64 foreach (module_implements('search') as $name) { 65 // Do not bother with search menu items that should not have search tabs. 66 if (!module_invoke($name, 'search', 'name')) { 67 continue; 68 } 69 70 // Put these items under the default search tab which is node. 71 $items["search/$name/%menu_tail"]['tab_parent'] = "search/node/%menu_tail"; 72 $items["search/$name/%menu_tail"]['tab_root'] = "search/node/%menu_tail"; 73 74 $callback = $items["search/$name/%menu_tail"]['page callback']; 75 76 // Even if a search page is not implemented, we need to add an extra 77 // entry anyway, for two reasons. 78 // 79 // 1) The 'search' menu entry actually handles all entries by default 80 // and that is going to be bad if the node search is overridden and 81 // 2) We need to have dual entries to make sure that the tabs are right. 82 if (variable_get('page_manager_search_disabled_' . $name, TRUE) || ($callback != 'search_view' && !variable_get('page_manager_override_anyway', FALSE))) { 83 $items["search/$name"] = $items["search/$name/%menu_tail"]; 84 85 // Put these items under the real search tab. 86 $items["search/$name"]['tab_parent'] = 'search'; 87 $items["search/$name"]['tab_root'] = 'search'; 88 89 if ($name == 'node') { 90 $items["search/$name"]['type'] = MENU_DEFAULT_LOCAL_TASK; 91 // The default tab should always be left weighted. Because of the way 92 // menu sorts, this item tends to float around if not weighted. 93 $items["search/$name"]['weight'] = -10; 94 $items["search/$name/%menu_tail"]['weight'] = -10; 95 } 96 97 if ($callback == 'search_view' || variable_get('page_manager_override_anyway', FALSE)) { 98 $items["search/$name/%menu_tail"]['page callback'] = 'page_manager_search_view'; 99 $items["search/$name/%menu_tail"]['file path'] = $task['path']; 100 $items["search/$name/%menu_tail"]['file'] = $task['file']; 101 } 102 103 continue; 104 } 105 106 if ($callback == 'search_view' || variable_get('page_manager_override_anyway', FALSE)) { 107 $items["search/$name/%menu_tail"]['page callback'] = 'page_manager_search_page'; 108 $items["search/$name/%menu_tail"]['file path'] = $task['path']; 109 $items["search/$name/%menu_tail"]['file'] = $task['file']; 110 111 // Add a version that doesn't contain the menu tail for the no keywords 112 // version. Ordinarily this works because the top level 'search' just 113 // passes through. 114 $items["search/$name"] = $items["search/$name/%menu_tail"]; 115 $items["search/$name/%menu_tail"]['page arguments'] = array(1, 2); 116 117 // Put these items under the real search tab. 118 $items["search/$name"]['tab_parent'] = 'search'; 119 $items["search/$name"]['tab_root'] = 'search'; 120 121 // Content search is the default search link, so we have to override 122 // the default task as well. 123 if ($name == 'node') { 124 $items["search/$name"]['type'] = MENU_DEFAULT_LOCAL_TASK; 125 // The default tab should always be left weighted. Because of the way 126 // menu sorts, this item tends to float around if not weighted. 127 $items["search/$name"]['weight'] = -10; 128 $items["search/$name/%menu_tail"]['weight'] = -10; 129 130 $items["search"]['page callback'] = 'page_manager_search_page'; 131 $items["search"]['page arguments'] = array('node'); 132 $items["search"]['file path'] = $task['path']; 133 $items["search"]['file'] = $task['file']; 134 } 135 } 136 else { 137 138 // automatically disable this task if it cannot be enabled. 139 variable_set('page_manager_search_disabled_' . $name, TRUE); 140 if (!empty($GLOBALS['page_manager_enabling_search'])) { 141 drupal_set_message(t('Page manager module is unable to enable search/@name/%menu_tail because some other module already has overridden with %callback.', array('%callback' => $callback, '@name' => $name)), 'error'); 142 } 143 } 144 } 145 } 146 147 /** 148 * Replacement function for normal search view. 149 * 150 * This function resets the active trail because menu system loses track 151 * of it due to the special way we're handling search items. 152 */ 153 function page_manager_search_view($type = 'node') { 154 ctools_include('menu'); 155 menu_set_active_trail(ctools_get_menu_trail('search/' . $type)); 156 157 module_load_include('inc', 'search', 'search.pages'); 158 return search_view($type); 159 } 160 161 /** 162 * Entry point for our overridden node view. 163 * 164 * This function asks its assigned handlers who, if anyone, would like 165 * to run with it. If no one does, it passes through to Drupal core's 166 * node view, which is node_page_view(). 167 */ 168 function page_manager_search_page($type) { 169 ctools_include('menu'); 170 menu_set_active_trail(ctools_get_menu_trail('search/' . $type)); 171 172 // Get the arguments and construct a keys string out of them. 173 $args = func_get_args(); 174 175 // We have to remove the $type. 176 array_shift($args); 177 178 // And implode() it all back together. 179 $keys = $args ? implode('/', $args) : ''; 180 181 // Load my task plugin 182 $task = page_manager_get_task('search'); 183 $subtask = page_manager_get_task_subtask($task, $type); 184 185 // Load the node into a context. 186 ctools_include('context'); 187 ctools_include('context-task-handler'); 188 $contexts = ctools_context_handler_get_task_contexts($task, $subtask, array($keys)); 189 190 $output = ctools_context_handler_render($task, $subtask, $contexts, array($keys)); 191 if ($output !== FALSE) { 192 return $output; 193 } 194 195 $function = 'search_view'; 196 foreach (module_implements('page_manager_override') as $module) { 197 $call = $module . '_page_manager_override'; 198 if (($rc = $call('search')) && function_exists($rc)) { 199 $function = $rc; 200 break; 201 } 202 } 203 204 // Otherwise, fall back. 205 206 // Put the $type back on the arguments. 207 module_load_include('inc', 'search', 'search.pages'); 208 array_unshift($args, $type); 209 return call_user_func_array($function, $args); 210 } 211 212 /** 213 * Callback to get arguments provided by this task handler. 214 * 215 * Since this is the node view and there is no UI on the arguments, we 216 * create dummy arguments that contain the needed data. 217 */ 218 function page_manager_search_get_arguments($task, $subtask_id) { 219 return array( 220 array( 221 'keyword' => 'keywords', 222 'identifier' => t('Keywords'), 223 'id' => 1, 224 'name' => 'string', 225 'settings' => array('use_tail' => TRUE), 226 ), 227 ); 228 } 229 230 /** 231 * Callback to get context placeholders provided by this handler. 232 */ 233 function page_manager_search_get_contexts($task, $subtask_id) { 234 return ctools_context_get_placeholders_from_argument(page_manager_search_get_arguments($task, $subtask_id)); 235 } 236 237 /** 238 * Callback to enable/disable the page from the UI. 239 */ 240 function page_manager_search_enable($cache, $status) { 241 variable_set('page_manager_search_disabled_' . $cache->subtask_id, $status); 242 243 // Set a global flag so that the menu routine knows it needs 244 // to set a message if enabling cannot be done. 245 if (!$status) { 246 $GLOBALS['page_manager_enabling_search'] = TRUE; 247 } 248 } 249 250 /** 251 * Task callback to get all subtasks. 252 * 253 * Return a list of all subtasks. 254 */ 255 function page_manager_search_subtasks($task) { 256 foreach (module_implements('search') as $name) { 257 if(module_invoke($name, 'search', 'name')) { 258 $return[$name] = page_manager_search_build_subtask($task, $name); 259 } 260 } 261 262 return $return; 263 } 264 265 /** 266 * Callback to return a single subtask. 267 */ 268 function page_manager_search_subtask($task, $subtask_id) { 269 return page_manager_search_build_subtask($task, $subtask_id); 270 } 271 272 /** 273 * Build a subtask array for a given page. 274 */ 275 function page_manager_search_build_subtask($task, $name) { 276 $type = module_invoke($name, 'search', 'name', TRUE); 277 $subtask = array( 278 'name' => $name, 279 'admin title' => $type, 280 'admin path' => "search/$name/!keywords", 281 'admin description' => t('Search @type', array('@type' => $type)), 282 'admin type' => t('System'), 283 'row class' => empty($page->disabled) ? 'page-manager-enabled' : 'page-manager-disabled', 284 'storage' => t('In code'), 285 'disabled' => variable_get('page_manager_search_disabled_' . $name, TRUE), 286 // This works for both enable AND disable 287 'enable callback' => 'page_manager_search_enable', 288 ); 289 290 return $subtask; 291 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |