Projet

Général

Profil

Paste
Télécharger (23,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / page.inc @ c304a780

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' => ' &raquo; ' . 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
  elseif ($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
 * Execute a page task.
253
 *
254
 * This is the callback to entries in the Drupal menu system created by the
255
 * page task.
256
 *
257
 * @param $subtask_id
258
 *   The name of the page task used.
259
 * @param ...
260
 *   A number of context objects as specified by the user when
261
 *   creating named arguments in the path.
262
 */
263
function page_manager_page_execute($subtask_id) {
264
  $page = page_manager_page_load($subtask_id);
265
  $task = page_manager_get_task($page->task);
266
  $subtask = page_manager_get_task_subtask($task, $subtask_id);
267

    
268
  // Turn the contexts into a properly keyed array.
269
  $contexts = array();
270
  $args = array();
271
  foreach (func_get_args() as $count => $arg) {
272
    if (is_object($arg) && get_class($arg) == 'ctools_context') {
273
      $contexts[$arg->id] = $arg;
274
      $args[] = $arg->original_argument;
275
    }
276
    elseif ($count) {
277
      $args[] = $arg;
278
    }
279
  }
280

    
281
  $count = 0;
282
  $names = page_manager_page_get_named_arguments($page->path);
283
  $bits = explode('/', $page->path);
284

    
285
  if ($page->arguments) {
286
    foreach ($page->arguments as $name => $argument) {
287
      // Optional arguments must be converted to contexts too, if they exist.
288
      if ($bits[$names[$name]][0] == '!') {
289
        ctools_include('context');
290
        $argument['keyword'] = $name;
291
        if (isset($args[$count])) {
292
          // Hack: use a special argument config variable to learn if we need
293
          // to use menu_tail style behavior:
294
          if (empty($argument['settings']['use_tail'])) {
295
            $value = $args[$count];
296
          }
297
          else {
298
            $value = implode('/', array_slice($args, $count));
299
          }
300

    
301
          $context = ctools_context_get_context_from_argument($argument, $value);
302
        }
303
        else {
304
          // Make sure there is a placeholder context for missing optional contexts.
305
          $context = ctools_context_get_context_from_argument($argument, NULL, TRUE);
306
          // Force the title to blank for replacements.
307
        }
308
        if ($context) {
309
          $contexts[$context->id] = $context;
310
        }
311
      }
312
      $count++;
313
    }
314
  }
315

    
316
  if ($function = ctools_plugin_get_function($task, 'page callback')) {
317
    return call_user_func_array($function, array($page, $contexts, $args));
318
  }
319

    
320
  ctools_include('context-task-handler');
321
  $output = ctools_context_handler_render($task, $subtask, $contexts, $args);
322
  if ($output === FALSE) {
323
    return MENU_NOT_FOUND;
324
  }
325

    
326
  return $output;
327
}
328

    
329
// --------------------------------------------------------------------------
330
// Context type callbacks.
331
/**
332
 * Return a list of arguments used by this task.
333
 */
334
function page_manager_page_get_arguments($task, $subtask) {
335
  return _page_manager_page_get_arguments($subtask['subtask']);
336
}
337

    
338
function _page_manager_page_get_arguments($page) {
339
  $arguments = array();
340
  if (!empty($page->arguments)) {
341
    foreach ($page->arguments as $keyword => $argument) {
342
      if (isset($argument['name'])) {
343
        $argument['keyword'] = $keyword;
344
        $arguments[$keyword] = $argument;
345
      }
346
    }
347
  }
348
  return $arguments;
349
}
350

    
351
/**
352
 * Get a group of context placeholders for the arguments.
353
 */
354
function page_manager_page_get_contexts($task, $subtask) {
355
  ctools_include('context');
356
  return ctools_context_get_placeholders_from_argument(page_manager_page_get_arguments($task, $subtask));
357
}
358

    
359
/**
360
 * Return a list of arguments used by this task.
361
 */
362
function page_manager_page_access_restrictions($task, $subtask, $contexts) {
363
  $page = $subtask['subtask'];
364
  return ctools_access_add_restrictions($page->access, $contexts);
365
}
366

    
367
// --------------------------------------------------------------------------
368
// Page task database info.
369

    
370
/**
371
 * Create a new page with defaults appropriately set from schema.
372
 */
373
function page_manager_page_new() {
374
  ctools_include('export');
375
  return ctools_export_new_object('page_manager_pages');
376
}
377

    
378
/**
379
 * Load a single page subtask.
380
 */
381
function page_manager_page_load($name) {
382
  ctools_include('export');
383
  $result = ctools_export_load_object('page_manager_pages', 'names', array($name));
384
  if (isset($result[$name])) {
385
    return $result[$name];
386
  }
387
}
388

    
389
/**
390
 * Load all page subtasks.
391
 */
392
function page_manager_page_load_all($task = NULL) {
393
  ctools_include('export');
394

    
395
  if (empty($task)) {
396
    return ctools_export_load_object('page_manager_pages');
397
  }
398
  else {
399
    return ctools_export_load_object('page_manager_pages', 'conditions', array('task' => $task));
400
  }
401
}
402

    
403
/**
404
 * Write a page subtask to the database.
405
 */
406
function page_manager_page_save(&$page) {
407
  $update = (isset($page->pid)) ? array('pid') : array();
408
  $task = page_manager_get_task($page->task);
409

    
410
  if ($function = ctools_plugin_get_function($task, 'save')) {
411
    $function($page, $update);
412
  }
413
  drupal_write_record('page_manager_pages', $page, $update);
414

    
415
  // If this was a default page we may need to write default task
416
  // handlers that we provided as well.
417
  if (!$update && isset($page->default_handlers)) {
418
    $handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
419
    foreach ($page->default_handlers as $name => $handler) {
420
      if (!isset($handlers[$name]) || !($handlers[$name]->export_type & EXPORT_IN_DATABASE)) {
421
        // Make sure this is right, as exports can wander a bit.
422
        $handler->subtask = $page->name;
423
        page_manager_save_task_handler($handler);
424
      }
425
    }
426
  }
427
  return $page;
428
}
429

    
430
/**
431
 * Remove a page subtask.
432
 */
433
function page_manager_page_delete($page) {
434
  $task = page_manager_get_task($page->task);
435
  if ($function = ctools_plugin_get_function($task, 'delete')) {
436
    $function($page);
437
  }
438
  if (!empty($task['uses handlers'])) {
439
    $handlers = page_manager_load_task_handlers($task, $page->name);
440
    foreach ($handlers as $handler) {
441
      page_manager_delete_task_handler($handler);
442
    }
443
  }
444
  db_delete('page_manager_pages')
445
    ->condition('name', $page->name)
446
    ->execute();
447
  // Make sure that the cache is reset so that the menu rebuild does not
448
  // rebuild this page again.
449
  ctools_include('export');
450
  ctools_export_load_object_reset('page_manager_pages');
451
  menu_rebuild();
452
}
453

    
454
/**
455
 * Export a page subtask.
456
 */
457
function page_manager_page_export($page, $with_handlers = FALSE, $indent = '') {
458
  $task = page_manager_get_task($page->task);
459
  $append = '';
460

    
461
  if ($function = ctools_plugin_get_function($task, 'export')) {
462
    $append = $function($page, $indent);
463
  }
464

    
465
  ctools_include('export');
466
  $output = ctools_export_object('page_manager_pages', $page, $indent);
467
  $output .= $append;
468

    
469
  if ($with_handlers) {
470
    if (is_array($with_handlers)) {
471
      $handlers = $with_handlers;
472
    }
473
    else {
474
      $handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
475
    }
476
    $output .= $indent . '$page->default_handlers = array();' . "\n";
477
    foreach ($handlers as $handler) {
478
      $output .= page_manager_export_task_handler($handler, $indent);
479
      $output .= $indent . '$page->default_handlers[$handler->name] = $handler;' . "\n";
480
    }
481
  }
482
  return $output;
483
}
484

    
485
/**
486
 * Get a list of named arguments in a page manager path.
487
 *
488
 * @param $path
489
 *   A normal Drupal path.
490
 *
491
 * @return
492
 *   An array of % marked variable arguments, keyed by the argument's name.
493
 *   The value will be the position of the argument so that it can easily
494
 *   be found. Items with a position of -1 have multiple positions.
495
 */
496
function page_manager_page_get_named_arguments($path) {
497
  $arguments = array();
498
  $bits = explode('/', $path);
499
  foreach ($bits as $position => $bit) {
500
    if ($bit && ($bit[0] == '%' || $bit[0] == '!')) {
501
      // Special handling for duplicate path items and substr to remove the %.
502
      $arguments[substr($bit, 1)] = isset($arguments[$bit]) ? -1 : $position;
503
    }
504
  }
505

    
506
  return $arguments;
507
}
508

    
509
/**
510
 * Load a context from an argument for a given page task.
511
 *
512
 * Helper function for pm_arg_load(), which is in page_manager.module because
513
 * drupal's menu system does not allow loader functions to reside in separate
514
 * files.
515
 *
516
 * @param $value
517
 *   The incoming argument value.
518
 * @param $subtask
519
 *   The subtask id.
520
 * @param $argument
521
 *   The numeric position of the argument in the path, counting from 0.
522
 *
523
 * @return
524
 *   A context item if one is configured, the argument if one is not, or
525
 *   FALSE if restricted or invalid.
526
 */
527
function _pm_arg_load($value, $subtask, $argument) {
528
  $page = page_manager_page_load($subtask);
529
  if (!$page) {
530
    return FALSE;
531
  }
532

    
533
  $path = explode('/', $page->path);
534
  if (empty($path[$argument])) {
535
    return FALSE;
536
  }
537

    
538
  $keyword = substr($path[$argument], 1);
539
  if (empty($page->arguments[$keyword])) {
540
    return $value;
541
  }
542

    
543
  $page->arguments[$keyword]['keyword'] = $keyword;
544

    
545
  ctools_include('context');
546
  $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value);
547

    
548
  // Convert false equivalents to false.
549
  return $context ? $context : FALSE;
550
}
551

    
552
/**
553
 * Provide a nice administrative summary of the page so an admin can see at a
554
 * glance what this page does and how it is configured.
555
 */
556
function page_manager_page_admin_summary($task, $subtask) {
557
  $task_name = page_manager_make_task_name($task['name'], $subtask['name']);
558
  $page = $subtask['subtask'];
559
  $output = '';
560

    
561
  $rows = array();
562

    
563
  $rows[] = array(
564
    array('class' => array('page-summary-label'), 'data' => t('Storage')),
565
    array('class' => array('page-summary-data'), 'data' => $subtask['storage']),
566
    array('class' => array('page-summary-operation'), 'data' => ''),
567
  );
568

    
569
  if (!empty($page->disabled)) {
570
    $link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'enable')));
571
    $text = t('Disabled');
572
  }
573
  else {
574
    $link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'disable')));
575
    $text = t('Enabled');
576
  }
577

    
578
  $rows[] = array(
579
    array('class' => array('page-summary-label'), 'data' => t('Status')),
580
    array('class' => array('page-summary-data'), 'data' => $text),
581
    array('class' => array('page-summary-operation'), 'data' => $link),
582
  );
583

    
584
  $path = array();
585
  foreach (explode('/', $page->path) as $bit) {
586
    if ($bit[0] != '!') {
587
      $path[] = $bit;
588
    }
589
  }
590

    
591
  $path = implode('/', $path);
592
  $front = variable_get('site_frontpage', 'node');
593

    
594
  $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'basic')));
595
  $message = '';
596
  if ($path == $front) {
597
    $message = t('This is your site home page.');
598
  }
599
  elseif (!empty($page->make_frontpage)) {
600
    $message = t('This page is set to become your site home page.');
601
  }
602

    
603
  if ($message) {
604
    $rows[] = array(
605
      array('class' => array('page-summary-data'), 'data' => $message, 'colspan' => 2),
606
      array('class' => array('page-summary-operation'), 'data' => $link),
607
    );
608
  }
609

    
610
  if (strpos($path, '%') === FALSE) {
611
    $path = l('/' . $page->path, $path);
612
  }
613
  else {
614
    $path = '/' . $page->path;
615
  }
616

    
617
  $rows[] = array(
618
    array('class' => array('page-summary-label'), 'data' => t('Path')),
619
    array('class' => array('page-summary-data'), 'data' => $path),
620
    array('class' => array('page-summary-operation'), 'data' => $link),
621
  );
622

    
623
  if (empty($access['plugins'])) {
624
    $access['plugins'] = array();
625
  }
626

    
627
  $contexts = page_manager_page_get_contexts($task, $subtask);
628
  $access = ctools_access_group_summary($page->access, $contexts);
629
  if ($access) {
630
    $access = t('Accessible only if @conditions.', array('@conditions' => $access));
631
  }
632
  else {
633
    $access = t('This page is publicly accessible.');
634
  }
635

    
636
  $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'access')));
637

    
638
  $rows[] = array(
639
    array('class' => array('page-summary-label'), 'data' => t('Access')),
640
    array('class' => array('page-summary-data'), 'data' => $access),
641
    array('class' => array('page-summary-operation'), 'data' => $link),
642
  );
643

    
644
  $menu_options = array(
645
    'none' => t('No menu entry.'),
646
    'normal' => t('Normal menu entry.'),
647
    'tab' => t('Menu tab.'),
648
    'default tab' => t('Default menu tab.'),
649
    'action' => t('Local action'),
650
  );
651

    
652
  if (!empty($page->menu)) {
653
    $menu = $menu_options[$page->menu['type']];
654
    if ($page->menu['type'] != 'none') {
655
      $menu .= ' ' . t('Title: %title.', array('%title' => $page->menu['title']));
656
      switch ($page->menu['type']) {
657
        case 'default tab':
658
          $menu .= ' ' . t('Parent title: %title.', array('%title' => $page->menu['parent']['title']));
659
          break;
660

    
661
        case 'normal':
662
          if (module_exists('menu')) {
663
            $menus = menu_get_menus();
664
            $menu .= ' ' . t('Menu block: %title.', array('%title' => $menus[$page->menu['name']]));
665
          }
666
          break;
667
      }
668
    }
669
  }
670
  else {
671
    $menu = t('No menu entry');
672
  }
673

    
674
  $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'menu')));
675
  $rows[] = array(
676
    array('class' => array('page-summary-label'), 'data' => t('Menu')),
677
    array('class' => array('page-summary-data'), 'data' => $menu),
678
    array('class' => array('page-summary-operation'), 'data' => $link),
679
  );
680

    
681
  $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'page-manager-page-summary')));
682
  return $output;
683
}
684

    
685
/**
686
 * Callback to enable/disable the page from the UI.
687
 */
688
function page_manager_page_enable(&$cache, $status) {
689
  $page = &$cache->subtask['subtask'];
690
  ctools_include('export');
691
  ctools_export_set_object_status($page, $status);
692

    
693
  $page->disabled = FALSE;
694
}
695

    
696
/**
697
 * Recalculate the arguments when something like the path changes.
698
 */
699
function page_manager_page_recalculate_arguments(&$page) {
700
  // Ensure $page->arguments contains only real arguments:
701
  $arguments = page_manager_page_get_named_arguments($page->path);
702
  $args = array();
703
  foreach ($arguments as $keyword => $position) {
704
    if (isset($page->arguments[$keyword])) {
705
      $args[$keyword] = $page->arguments[$keyword];
706
    }
707
    else {
708
      $args[$keyword] = array(
709
        'id' => '',
710
        'identifier' => '',
711
        'argument' => '',
712
        'settings' => array(),
713
      );
714
    }
715
  }
716
  $page->arguments = $args;
717
}
718

    
719
/**
720
 * When adding or cloning a new page, this creates a new page cache
721
 * and adds our page to it.
722
 *
723
 * This does not check to see if the existing cache is already locked.
724
 * This must be done beforehand.
725
 *
726
 * @param &$page
727
 *   The page to create.
728
 * @param &$cache
729
 *   The cache to use. If the cache has any existing task handlers,
730
 *   they will be marked for deletion. This may be a blank object.
731
 */
732
function page_manager_page_new_page_cache(&$page, &$cache) {
733
  // Does a page already exist? If so, we are overwriting it so
734
  // take its pid.
735
  if (!empty($cache->subtask) && !empty($cache->subtask['subtask']) && !empty($cache->subtask['subtask']->pid)) {
736
    $page->pid = $cache->subtask['subtask']->pid;
737
  }
738
  else {
739
    $cache->new = TRUE;
740
  }
741

    
742
  $cache->task_name = page_manager_make_task_name('page', $page->name);
743
  $cache->task_id = 'page';
744
  $cache->task = page_manager_get_task('page');
745
  $cache->subtask_id = $page->name;
746
  $page->export_type = EXPORT_IN_DATABASE;
747
  $page->type = t('Normal');
748
  $cache->subtask = page_manager_page_build_subtask($cache->task, $page);
749

    
750
  if (isset($cache->handlers)) {
751
    foreach ($cache->handlers as $id => $handler) {
752
      $cache->handler_info[$id]['changed'] = PAGE_MANAGER_CHANGED_DELETED;
753
    }
754
  }
755
  else {
756
    $cache->handlers = array();
757
    $cache->handler_info = array();
758
  }
759

    
760
  if (!empty($page->default_handlers)) {
761
    foreach ($page->default_handlers as $id => $handler) {
762
      page_manager_handler_add_to_page($cache, $handler);
763
    }
764
  }
765

    
766
  $cache->locked = FALSE;
767
  $cache->changed = TRUE;
768
}
769

    
770
/**
771
 * Callback to determine if a page is accessible.
772
 *
773
 * @param $task
774
 *   The task plugin.
775
 * @param $subtask_id
776
 *   The subtask id
777
 * @param $contexts
778
 *   The contexts loaded for the task.
779
 *
780
 * @return
781
 *   TRUE if the current user can access the page.
782
 */
783
function page_manager_page_access_check($task, $subtask_id, $contexts) {
784
  $page = page_manager_page_load($subtask_id);
785
  return ctools_access($page->access, $contexts);
786
}