Commit | Line | Data |
---|---|---|
7f254ad8 AE |
1 | <?php |
2 | ||
3 | /** | |
4 | * @file | |
5 | * Handle the 'page' task, which creates pages with arbitrary tasks and lets | |
6 | * handlers decide how they will be rendered. | |
7 | * | |
8 | * This creates subtasks and stores them in the page_manager_pages table. These | |
9 | * are exportable objects, too. | |
10 | * | |
11 | * The render callback for this task type has $handler, $page, $contexts as | |
12 | * parameters. | |
13 | */ | |
14 | ||
15 | /** | |
16 | * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for | |
17 | * more information. | |
18 | */ | |
19 | function page_manager_page_page_manager_tasks() { | |
20 | return array( | |
21 | 'title' => t('Custom pages'), | |
22 | 'description' => t('Administrator created pages that have a URL path, access control and entries in the Drupal menu system.'), | |
23 | 'non-exportable' => TRUE, | |
24 | 'subtasks' => TRUE, | |
25 | 'subtask callback' => 'page_manager_page_subtask', | |
26 | 'subtasks callback' => 'page_manager_page_subtasks', | |
27 | 'save subtask callback' => 'page_manager_page_save_subtask', | |
28 | 'access callback' => 'page_manager_page_access_check', | |
29 | 'hook menu' => array( | |
30 | 'file' => 'page.admin.inc', | |
31 | 'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks', | |
32 | 'function' => 'page_manager_page_menu', | |
33 | ), | |
34 | 'hook theme' => 'page_manager_page_theme', | |
35 | // page only items | |
36 | 'task type' => 'page', | |
37 | 'page operations' => array( | |
38 | array( | |
39 | 'title' => ' » ' . t('Create a new page'), | |
40 | 'href' => 'admin/structure/pages/add', | |
41 | 'html' => TRUE, | |
42 | ), | |
43 | ), | |
44 | 'columns' => array( | |
45 | 'storage' => array( | |
46 | 'label' => t('Storage'), | |
47 | 'class' => 'page-manager-page-storage', | |
48 | ), | |
49 | ), | |
50 | 'page type' => 'custom', | |
51 | ||
52 | // context only items | |
53 | 'handler type' => 'context', | |
54 | 'get arguments' => array( | |
55 | 'file' => 'page.admin.inc', | |
56 | 'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks', | |
57 | 'function' => 'page_manager_page_get_arguments', | |
58 | ), | |
59 | 'get context placeholders' => 'page_manager_page_get_contexts', | |
60 | 'access restrictions' => 'page_manager_page_access_restrictions', | |
61 | 'uses handlers' => TRUE, | |
62 | ); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Task callback to get all subtasks. | |
67 | * | |
68 | * Return a list of all subtasks. | |
69 | */ | |
70 | function page_manager_page_subtasks($task) { | |
71 | $pages = page_manager_page_load_all($task['name']); | |
72 | $return = array(); | |
73 | foreach ($pages as $name => $page) { | |
74 | $return[$name] = page_manager_page_build_subtask($task, $page); | |
75 | } | |
76 | ||
77 | return $return; | |
78 | } | |
79 | ||
80 | /** | |
81 | * Callback to return a single subtask. | |
82 | */ | |
83 | function page_manager_page_subtask($task, $subtask_id) { | |
84 | $page = page_manager_page_load($subtask_id); | |
85 | if ($page) { | |
86 | return page_manager_page_build_subtask($task, $page); | |
87 | } | |
88 | } | |
89 | ||
90 | /** | |
91 | * Call back from the administrative system to save a page. | |
92 | * | |
93 | * We get the $subtask as created by page_manager_page_build_subtask. | |
94 | */ | |
95 | function page_manager_page_save_subtask($subtask) { | |
96 | $page = &$subtask['subtask']; | |
97 | ||
98 | // Ensure $page->arguments contains only real arguments: | |
99 | $arguments = page_manager_page_get_named_arguments($page->path); | |
100 | $args = array(); | |
101 | foreach ($arguments as $keyword => $position) { | |
102 | if (isset($page->arguments[$keyword])) { | |
103 | $args[$keyword] = $page->arguments[$keyword]; | |
104 | } | |
105 | else { | |
106 | $args[$keyword] = array( | |
107 | 'id' => '', | |
108 | 'identifier' => '', | |
109 | 'argument' => '', | |
110 | 'settings' => array(), | |
111 | ); | |
112 | } | |
113 | } | |
114 | page_manager_page_recalculate_arguments($page); | |
115 | // Create a real object from the cache | |
116 | page_manager_page_save($page); | |
117 | ||
118 | // Check to see if we should make this the site frontpage. | |
119 | if (!empty($page->make_frontpage)) { | |
120 | $path = array(); | |
121 | foreach (explode('/', $page->path) as $bit) { | |
122 | if ($bit[0] != '!') { | |
123 | $path[] = $bit; | |
124 | } | |
125 | } | |
126 | ||
127 | $path = implode('/', $path); | |
128 | $front = variable_get('site_frontpage', 'node'); | |
129 | if ($path != $front) { | |
130 | variable_set('site_frontpage', $path); | |
131 | } | |
132 | } | |
133 | } | |
134 | ||
135 | /** | |
136 | * Build a subtask array for a given page. | |
137 | */ | |
138 | function page_manager_page_build_subtask($task, $page) { | |
139 | $operations = array(); | |
140 | $operations['settings'] = array( | |
141 | 'type' => 'group', | |
142 | 'class' => array('operations-settings'), | |
143 | 'title' => t('Settings'), | |
144 | 'children' => array(), | |
145 | ); | |
146 | ||
147 | $settings = &$operations['settings']['children']; | |
148 | ||
149 | $settings['basic'] = array( | |
150 | 'title' => t('Basic'), | |
151 | 'description' => t('Edit name, path and other basic settings for the page.'), | |
152 | 'form' => 'page_manager_page_form_basic', | |
153 | ); | |
154 | ||
155 | $arguments = page_manager_page_get_named_arguments($page->path); | |
156 | if ($arguments) { | |
157 | $settings['argument'] = array( | |
158 | 'title' => t('Arguments'), | |
159 | 'description' => t('Set up contexts for the arguments on this page.'), | |
160 | 'form' => 'page_manager_page_form_argument', | |
161 | ); | |
162 | } | |
163 | ||
164 | $settings['access'] = array( | |
165 | 'title' => t('Access'), | |
166 | 'description' => t('Control what users can access this page.'), | |
167 | 'admin description' => t('Access rules are used to test if the page is accessible and any menu items associated with it are visible.'), | |
168 | 'form' => 'page_manager_page_form_access', | |
169 | ); | |
170 | ||
171 | $settings['menu'] = array( | |
172 | 'title' => t('Menu'), | |
173 | 'description' => t('Provide this page a visible menu or a menu tab.'), | |
174 | 'form' => 'page_manager_page_form_menu', | |
175 | ); | |
176 | ||
177 | $operations['actions']['children']['clone'] = array( | |
178 | 'title' => t('Clone'), | |
179 | 'description' => t('Make a copy of this page'), | |
180 | 'form' => 'page_manager_page_form_clone', | |
181 | ); | |
182 | $operations['actions']['children']['export'] = array( | |
183 | 'title' => t('Export'), | |
184 | 'description' => t('Export this page as code that can be imported or embedded into a module.'), | |
185 | 'form' => 'page_manager_page_form_export', | |
186 | ); | |
187 | if ($page->export_type == (EXPORT_IN_CODE | EXPORT_IN_DATABASE)) { | |
188 | $operations['actions']['children']['delete'] = array( | |
189 | 'title' => t('Revert'), | |
190 | 'description' => t('Remove all changes to this page and revert to the version in code.'), | |
191 | 'form' => 'page_manager_page_form_delete', | |
192 | ); | |
193 | } | |
194 | else if ($page->export_type != EXPORT_IN_CODE) { | |
195 | $operations['actions']['children']['delete'] = array( | |
196 | 'title' => t('Delete'), | |
197 | 'description' => t('Remove this page from your system completely.'), | |
198 | 'form' => 'page_manager_page_form_delete', | |
199 | ); | |
200 | } | |
201 | ||
202 | $subtask = array( | |
203 | 'name' => $page->name, | |
204 | 'admin title' => check_plain($page->admin_title), | |
205 | 'admin description' => filter_xss_admin($page->admin_description), | |
206 | 'admin summary' => 'page_manager_page_admin_summary', | |
207 | 'admin path' => $page->path, | |
208 | 'admin type' => t('Custom'), | |
209 | 'subtask' => $page, | |
210 | 'operations' => $operations, | |
211 | 'operations include' => array( | |
212 | 'file' => 'page.admin.inc', | |
213 | 'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks', | |
214 | ), | |
215 | 'single task' => empty($page->multiple), | |
216 | 'row class' => empty($page->disabled) ? 'page-manager-enabled' : 'page-manager-disabled', | |
217 | 'storage' => $page->type == t('Default') ? t('In code') : $page->type, | |
218 | 'disabled' => !empty($page->disabled), | |
219 | // This works for both enable AND disable | |
220 | 'enable callback' => 'page_manager_page_enable', | |
221 | ); | |
222 | ||
223 | // default handlers may appear from a default subtask. | |
224 | if (isset($page->default_handlers)) { | |
225 | $subtask['default handlers'] = $page->default_handlers; | |
226 | } | |
227 | return $subtask; | |
228 | } | |
229 | ||
230 | /** | |
231 | * Delegated implementation of hook_theme(). | |
232 | */ | |
233 | function page_manager_page_theme(&$items, $task) { | |
234 | $base = array( | |
235 | 'file' => 'page.admin.inc', | |
236 | 'path' => drupal_get_path('module', 'page_manager') . '/plugins/tasks', | |
237 | ); | |
238 | $items['page_manager_page_form_argument_table'] = $base + array( | |
239 | 'render element' => 'form', | |
240 | ); | |
241 | $items['page_manager_page_lock'] = $base + array( | |
242 | 'variables' => array('lock' => array(), 'task_name' => NULL), | |
243 | ); | |
244 | $items['page_manager_page_changed'] = $base + array( | |
245 | 'variables' => array(), | |
246 | ); | |
247 | } | |
248 | ||
249 | // -------------------------------------------------------------------------- | |
250 | // Page execution functions | |
251 | ||
252 | /** | |
253 | * Execute a page task. | |
254 | * | |
255 | * This is the callback to entries in the Drupal menu system created by the | |
256 | * page task. | |
257 | * | |
258 | * @param $subtask_id | |
259 | * The name of the page task used. | |
260 | * @param ... | |
261 | * A number of context objects as specified by the user when | |
262 | * creating named arguments in the path. | |
263 | */ | |
264 | function page_manager_page_execute($subtask_id) { | |
265 | $page = page_manager_page_load($subtask_id); | |
266 | $task = page_manager_get_task($page->task); | |
267 | $subtask = page_manager_get_task_subtask($task, $subtask_id); | |
268 | ||
269 | // Turn the contexts into a properly keyed array. | |
270 | $contexts = array(); | |
271 | $args = array(); | |
272 | foreach (func_get_args() as $count => $arg) { | |
273 | if (is_object($arg) && get_class($arg) == 'ctools_context') { | |
274 | $contexts[$arg->id] = $arg; | |
275 | $args[] = $arg->original_argument; | |
276 | } | |
277 | else if ($count) { | |
278 | $args[] = $arg; | |
279 | } | |
280 | } | |
281 | ||
282 | $count = 0; | |
283 | $names = page_manager_page_get_named_arguments($page->path); | |
284 | $bits = explode('/', $page->path); | |
285 | ||
286 | if ($page->arguments) { | |
287 | foreach ($page->arguments as $name => $argument) { | |
288 | // Optional arguments must be converted to contexts too, if they exist. | |
289 | if ($bits[$names[$name]][0] == '!') { | |
290 | ctools_include('context'); | |
291 | $argument['keyword'] = $name; | |
292 | if (isset($args[$count])) { | |
293 | // Hack: use a special argument config variable to learn if we need | |
294 | // to use menu_tail style behavior: | |
295 | if (empty($argument['settings']['use_tail'])) { | |
296 | $value = $args[$count]; | |
297 | } | |
298 | else { | |
299 | $value = implode('/', array_slice($args, $count)); | |
300 | } | |
301 | ||
302 | $context = ctools_context_get_context_from_argument($argument, $value); | |
303 | } | |
304 | else { | |
305 | // make sure there is a placeholder context for missing optional contexts. | |
306 | $context = ctools_context_get_context_from_argument($argument, NULL, TRUE); | |
307 | // Force the title to blank for replacements | |
308 | } | |
309 | if ($context) { | |
310 | $contexts[$context->id] = $context; | |
311 | } | |
312 | } | |
313 | $count++; | |
314 | } | |
315 | } | |
316 | ||
317 | if ($function = ctools_plugin_get_function($task, 'page callback')) { | |
318 | return call_user_func_array($function, array($page, $contexts, $args)); | |
319 | } | |
320 | ||
321 | ctools_include('context-task-handler'); | |
322 | $output = ctools_context_handler_render($task, $subtask, $contexts, $args); | |
323 | if ($output === FALSE) { | |
324 | return MENU_NOT_FOUND; | |
325 | } | |
326 | ||
327 | return $output; | |
328 | } | |
329 | ||
330 | // -------------------------------------------------------------------------- | |
331 | // Context type callbacks | |
332 | ||
333 | /** | |
334 | * Return a list of arguments used by this task. | |
335 | */ | |
336 | function page_manager_page_get_arguments($task, $subtask) { | |
337 | return _page_manager_page_get_arguments($subtask['subtask']); | |
338 | } | |
339 | ||
340 | function _page_manager_page_get_arguments($page) { | |
341 | $arguments = array(); | |
342 | if (!empty($page->arguments)) { | |
343 | foreach ($page->arguments as $keyword => $argument) { | |
344 | if (isset($argument['name'])) { | |
345 | $argument['keyword'] = $keyword; | |
346 | $arguments[$keyword] = $argument; | |
347 | } | |
348 | } | |
349 | } | |
350 | return $arguments; | |
351 | } | |
352 | ||
353 | /** | |
354 | * Get a group of context placeholders for the arguments. | |
355 | */ | |
356 | function page_manager_page_get_contexts($task, $subtask) { | |
357 | ctools_include('context'); | |
358 | return ctools_context_get_placeholders_from_argument(page_manager_page_get_arguments($task, $subtask)); | |
359 | } | |
360 | ||
361 | /** | |
362 | * Return a list of arguments used by this task. | |
363 | */ | |
364 | function page_manager_page_access_restrictions($task, $subtask, $contexts) { | |
365 | $page = $subtask['subtask']; | |
366 | return ctools_access_add_restrictions($page->access, $contexts); | |
367 | } | |
368 | ||
369 | // -------------------------------------------------------------------------- | |
370 | // Page task database info. | |
371 | ||
372 | /** | |
373 | * Create a new page with defaults appropriately set from schema. | |
374 | */ | |
375 | function page_manager_page_new() { | |
376 | ctools_include('export'); | |
377 | return ctools_export_new_object('page_manager_pages'); | |
378 | } | |
379 | ||
380 | /** | |
381 | * Load a single page subtask. | |
382 | */ | |
383 | function page_manager_page_load($name) { | |
384 | ctools_include('export'); | |
385 | $result = ctools_export_load_object('page_manager_pages', 'names', array($name)); | |
386 | if (isset($result[$name])) { | |
387 | return $result[$name]; | |
388 | } | |
389 | } | |
390 | ||
391 | /** | |
392 | * Load all page subtasks. | |
393 | */ | |
394 | function page_manager_page_load_all($task = NULL) { | |
395 | ctools_include('export'); | |
396 | ||
397 | if (empty($task)) { | |
398 | return ctools_export_load_object('page_manager_pages'); | |
399 | } | |
400 | else { | |
401 | return ctools_export_load_object('page_manager_pages', 'conditions', array('task' => $task)); | |
402 | } | |
403 | } | |
404 | ||
405 | /** | |
406 | * Write a page subtask to the database. | |
407 | */ | |
408 | function page_manager_page_save(&$page) { | |
409 | $update = (isset($page->pid)) ? array('pid') : array(); | |
410 | $task = page_manager_get_task($page->task); | |
411 | ||
412 | if ($function = ctools_plugin_get_function($task, 'save')) { | |
413 | $function($page, $update); | |
414 | } | |
415 | drupal_write_record('page_manager_pages', $page, $update); | |
416 | ||
417 | // If this was a default page we may need to write default task | |
418 | // handlers that we provided as well. | |
419 | if (!$update && isset($page->default_handlers)) { | |
420 | $handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name); | |
421 | foreach ($page->default_handlers as $name => $handler) { | |
422 | if (!isset($handlers[$name]) || !($handlers[$name]->export_type & EXPORT_IN_DATABASE)) { | |
423 | // Make sure this is right, as exports can wander a bit. | |
424 | $handler->subtask = $page->name; | |
425 | page_manager_save_task_handler($handler); | |
426 | } | |
427 | } | |
428 | } | |
429 | return $page; | |
430 | } | |
431 | ||
432 | /** | |
433 | * Remove a page subtask. | |
434 | */ | |
435 | function page_manager_page_delete($page) { | |
436 | $task = page_manager_get_task($page->task); | |
437 | if ($function = ctools_plugin_get_function($task, 'delete')) { | |
438 | $function($page); | |
439 | } | |
440 | if (!empty($task['uses handlers'])) { | |
441 | $handlers = page_manager_load_task_handlers($task, $page->name); | |
442 | foreach ($handlers as $handler) { | |
443 | page_manager_delete_task_handler($handler); | |
444 | } | |
445 | } | |
446 | db_delete('page_manager_pages') | |
447 | ->condition('name', $page->name) | |
448 | ->execute(); | |
449 | // Make sure that the cache is reset so that the menu rebuild does not | |
450 | // rebuild this page again. | |
451 | ctools_include('export'); | |
452 | ctools_export_load_object_reset('page_manager_pages'); | |
453 | menu_rebuild(); | |
454 | } | |
455 | ||
456 | /** | |
457 | * Export a page subtask. | |
458 | */ | |
459 | function page_manager_page_export($page, $with_handlers = FALSE, $indent = '') { | |
460 | $task = page_manager_get_task($page->task); | |
461 | $append = ''; | |
462 | ||
463 | if ($function = ctools_plugin_get_function($task, 'export')) { | |
464 | $append = $function($page, $indent); | |
465 | } | |
466 | ||
467 | ctools_include('export'); | |
468 | $output = ctools_export_object('page_manager_pages', $page, $indent); | |
469 | $output .= $append; | |
470 | ||
471 | if ($with_handlers) { | |
472 | if (is_array($with_handlers)) { | |
473 | $handlers = $with_handlers; | |
474 | } | |
475 | else { | |
476 | $handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name); | |
477 | } | |
478 | $output .= $indent . '$page->default_handlers = array();' . "\n"; | |
479 | foreach ($handlers as $handler) { | |
480 | $output .= page_manager_export_task_handler($handler, $indent); | |
481 | $output .= $indent . '$page->default_handlers[$handler->name] = $handler;' . "\n"; | |
482 | } | |
483 | } | |
484 | return $output; | |
485 | } | |
486 | ||
487 | /** | |
488 | * Get a list of named arguments in a page manager path. | |
489 | * | |
490 | * @param $path | |
491 | * A normal Drupal path. | |
492 | * | |
493 | * @return | |
494 | * An array of % marked variable arguments, keyed by the argument's name. | |
495 | * The value will be the position of the argument so that it can easily | |
496 | * be found. Items with a position of -1 have multiple positions. | |
497 | */ | |
498 | function page_manager_page_get_named_arguments($path) { | |
499 | $arguments = array(); | |
500 | $bits = explode('/', $path); | |
501 | foreach ($bits as $position => $bit) { | |
502 | if ($bit && ($bit[0] == '%' || $bit[0] == '!')) { | |
503 | // special handling for duplicate path items and substr to remove the % | |
504 | $arguments[substr($bit, 1)] = isset($arguments[$bit]) ? -1 : $position; | |
505 | } | |
506 | } | |
507 | ||
508 | return $arguments; | |
509 | } | |
510 | ||
511 | /** | |
512 | * Load a context from an argument for a given page task. | |
513 | * | |
514 | * Helper function for pm_arg_load(), which is in page_manager.module because | |
515 | * drupal's menu system does not allow loader functions to reside in separate | |
516 | * files. | |
517 | * | |
518 | * @param $value | |
519 | * The incoming argument value. | |
520 | * @param $subtask | |
521 | * The subtask id. | |
522 | * @param $argument | |
523 | * The numeric position of the argument in the path, counting from 0. | |
524 | * | |
525 | * @return | |
526 | * A context item if one is configured, the argument if one is not, or | |
527 | * FALSE if restricted or invalid. | |
528 | */ | |
529 | function _pm_arg_load($value, $subtask, $argument) { | |
530 | $page = page_manager_page_load($subtask); | |
531 | if (!$page) { | |
532 | return FALSE; | |
533 | } | |
534 | ||
535 | $path = explode('/', $page->path); | |
536 | if (empty($path[$argument])) { | |
537 | return FALSE; | |
538 | } | |
539 | ||
540 | $keyword = substr($path[$argument], 1); | |
541 | if (empty($page->arguments[$keyword])) { | |
542 | return $value; | |
543 | } | |
544 | ||
545 | $page->arguments[$keyword]['keyword'] = $keyword; | |
546 | ||
547 | ctools_include('context'); | |
548 | $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value); | |
549 | ||
550 | // convert false equivalents to false. | |
551 | return $context ? $context : FALSE; | |
552 | } | |
553 | ||
554 | /** | |
555 | * Provide a nice administrative summary of the page so an admin can see at a | |
556 | * glance what this page does and how it is configured. | |
557 | */ | |
558 | function page_manager_page_admin_summary($task, $subtask) { | |
559 | $task_name = page_manager_make_task_name($task['name'], $subtask['name']); | |
560 | $page = $subtask['subtask']; | |
561 | $output = ''; | |
562 | ||
563 | $rows = array(); | |
564 | ||
565 | $rows[] = array( | |
566 | array('class' => array('page-summary-label'), 'data' => t('Storage')), | |
567 | array('class' => array('page-summary-data'), 'data' => $subtask['storage']), | |
568 | array('class' => array('page-summary-operation'), 'data' => ''), | |
569 | ); | |
570 | ||
571 | if (!empty($page->disabled)) { | |
572 | $link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'enable'))); | |
573 | $text = t('Disabled'); | |
574 | } | |
575 | else { | |
576 | $link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'disable'))); | |
577 | $text = t('Enabled'); | |
578 | } | |
579 | ||
580 | $rows[] = array( | |
581 | array('class' => array('page-summary-label'), 'data' => t('Status')), | |
582 | array('class' => array('page-summary-data'), 'data' => $text), | |
583 | array('class' => array('page-summary-operation'), 'data' => $link), | |
584 | ); | |
585 | ||
586 | ||
587 | $path = array(); | |
588 | foreach (explode('/', $page->path) as $bit) { | |
589 | if ($bit[0] != '!') { | |
590 | $path[] = $bit; | |
591 | } | |
592 | } | |
593 | ||
594 | $path = implode('/', $path); | |
595 | $front = variable_get('site_frontpage', 'node'); | |
596 | ||
597 | $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'basic'))); | |
598 | $message = ''; | |
599 | if ($path == $front) { | |
600 | $message = t('This is your site home page.'); | |
601 | } | |
602 | else if (!empty($page->make_frontpage)) { | |
603 | $message = t('This page is set to become your site home page.'); | |
604 | } | |
605 | ||
606 | if ($message) { | |
607 | $rows[] = array( | |
608 | array('class' => array('page-summary-data'), 'data' => $message, 'colspan' => 2), | |
609 | array('class' => array('page-summary-operation'), 'data' => $link), | |
610 | ); | |
611 | } | |
612 | ||
613 | if (strpos($path, '%') === FALSE) { | |
614 | $path = l('/' . $page->path, $path); | |
615 | } | |
616 | else { | |
617 | $path = '/' . $page->path; | |
618 | } | |
619 | ||
620 | $rows[] = array( | |
621 | array('class' => array('page-summary-label'), 'data' => t('Path')), | |
622 | array('class' => array('page-summary-data'), 'data' => $path), | |
623 | array('class' => array('page-summary-operation'), 'data' => $link), | |
624 | ); | |
625 | ||
626 | if (empty($access['plugins'])) { | |
627 | $access['plugins'] = array(); | |
628 | } | |
629 | ||
630 | $contexts = page_manager_page_get_contexts($task, $subtask); | |
631 | $access = ctools_access_group_summary($page->access, $contexts); | |
632 | if ($access) { | |
633 | $access = t('Accessible only if @conditions.', array('@conditions' => $access)); | |
634 | } | |
635 | else { | |
636 | $access = t('This page is publicly accessible.'); | |
637 | } | |
638 | ||
639 | $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'access'))); | |
640 | ||
641 | $rows[] = array( | |
642 | array('class' => array('page-summary-label'), 'data' => t('Access')), | |
643 | array('class' => array('page-summary-data'), 'data' => $access), | |
644 | array('class' => array('page-summary-operation'), 'data' => $link), | |
645 | ); | |
646 | ||
647 | $menu_options = array( | |
648 | 'none' => t('No menu entry.'), | |
649 | 'normal' => t('Normal menu entry.'), | |
650 | 'tab' => t('Menu tab.'), | |
651 | 'default tab' => t('Default menu tab.'), | |
652 | 'action' => t('Local action'), | |
653 | ); | |
654 | ||
655 | if (!empty($page->menu)) { | |
656 | $menu = $menu_options[$page->menu['type']]; | |
657 | if ($page->menu['type'] != 'none') { | |
658 | $menu .= ' ' . t('Title: %title.', array('%title' => $page->menu['title'])); | |
659 | switch ($page->menu['type']) { | |
660 | case 'default tab': | |
661 | $menu .= ' ' . t('Parent title: %title.', array('%title' => $page->menu['parent']['title'])); | |
662 | break; | |
663 | case 'normal': | |
664 | if (module_exists('menu')) { | |
665 | $menus = menu_get_menus(); | |
666 | $menu .= ' ' . t('Menu block: %title.', array('%title' => $menus[$page->menu['name']])); | |
667 | } | |
668 | break; | |
669 | } | |
670 | } | |
671 | } | |
672 | else { | |
673 | $menu = t('No menu entry'); | |
674 | } | |
675 | ||
676 | $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'menu'))); | |
677 | $rows[] = array( | |
678 | array('class' => array('page-summary-label'), 'data' => t('Menu')), | |
679 | array('class' => array('page-summary-data'), 'data' => $menu), | |
680 | array('class' => array('page-summary-operation'), 'data' => $link), | |
681 | ); | |
682 | ||
683 | $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'page-manager-page-summary'))); | |
684 | return $output; | |
685 | } | |
686 | ||
687 | /** | |
688 | * Callback to enable/disable the page from the UI. | |
689 | */ | |
690 | function page_manager_page_enable(&$cache, $status) { | |
691 | $page = &$cache->subtask['subtask']; | |
692 | ctools_include('export'); | |
693 | ctools_export_set_object_status($page, $status); | |
694 | ||
695 | $page->disabled = FALSE; | |
696 | } | |
697 | ||
698 | /** | |
699 | * Recalculate the arguments when something like the path changes. | |
700 | */ | |
701 | function page_manager_page_recalculate_arguments(&$page) { | |
702 | // Ensure $page->arguments contains only real arguments: | |
703 | $arguments = page_manager_page_get_named_arguments($page->path); | |
704 | $args = array(); | |
705 | foreach ($arguments as $keyword => $position) { | |
706 | if (isset($page->arguments[$keyword])) { | |
707 | $args[$keyword] = $page->arguments[$keyword]; | |
708 | } | |
709 | else { | |
710 | $args[$keyword] = array( | |
711 | 'id' => '', | |
712 | 'identifier' => '', | |
713 | 'argument' => '', | |
714 | 'settings' => array(), | |
715 | ); | |
716 | } | |
717 | } | |
718 | $page->arguments = $args; | |
719 | } | |
720 | ||
721 | /** | |
722 | * When adding or cloning a new page, this creates a new page cache | |
723 | * and adds our page to it. | |
724 | * | |
725 | * This does not check to see if the existing cache is already locked. | |
726 | * This must be done beforehand. | |
727 | * | |
728 | * @param &$page | |
729 | * The page to create. | |
730 | * @param &$cache | |
731 | * The cache to use. If the cache has any existing task handlers, | |
732 | * they will be marked for deletion. This may be a blank object. | |
733 | */ | |
734 | function page_manager_page_new_page_cache(&$page, &$cache) { | |
735 | // Does a page already exist? If so, we are overwriting it so | |
736 | // take its pid. | |
737 | if (!empty($cache->subtask) && !empty($cache->subtask['subtask']) && !empty($cache->subtask['subtask']->pid)) { | |
738 | $page->pid = $cache->subtask['subtask']->pid; | |
739 | } | |
740 | else { | |
741 | $cache->new = TRUE; | |
742 | } | |
743 | ||
744 | $cache->task_name = page_manager_make_task_name('page', $page->name); | |
745 | $cache->task_id = 'page'; | |
746 | $cache->task = page_manager_get_task('page'); | |
747 | $cache->subtask_id = $page->name; | |
748 | $page->export_type = EXPORT_IN_DATABASE; | |
749 | $page->type = t('Normal'); | |
750 | $cache->subtask = page_manager_page_build_subtask($cache->task, $page); | |
751 | ||
752 | if (isset($cache->handlers)) { | |
753 | foreach($cache->handlers as $id => $handler) { | |
754 | $cache->handler_info[$id]['changed'] = PAGE_MANAGER_CHANGED_DELETED; | |
755 | } | |
756 | } | |
757 | else { | |
758 | $cache->handlers = array(); | |
759 | $cache->handler_info = array(); | |
760 | } | |
761 | ||
762 | if (!empty($page->default_handlers)) { | |
763 | foreach ($page->default_handlers as $id => $handler) { | |
764 | page_manager_handler_add_to_page($cache, $handler); | |
765 | } | |
766 | } | |
767 | ||
768 | $cache->locked = FALSE; | |
769 | $cache->changed = TRUE; | |
770 | } | |
771 | ||
772 | /** | |
773 | * Callback to determine if a page is accessible. | |
774 | * | |
775 | * @param $task | |
776 | * The task plugin. | |
777 | * @param $subtask_id | |
778 | * The subtask id | |
779 | * @param $contexts | |
780 | * The contexts loaded for the task. | |
781 | * @return | |
782 | * TRUE if the current user can access the page. | |
783 | */ | |
784 | function page_manager_page_access_check($task, $subtask_id, $contexts) { | |
785 | $page = page_manager_page_load($subtask_id); | |
786 | return ctools_access($page->access, $contexts); | |
787 | } |