Projet

Général

Profil

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

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

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
  $func_args = func_get_args();
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_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
    elseif ($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
 * Return a list of arguments used by this task.
334
 */
335
function page_manager_page_get_arguments($task, $subtask) {
336
  return _page_manager_page_get_arguments($subtask['subtask']);
337
}
338

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

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

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

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

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

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

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

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

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

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

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

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

    
459
/**
460
 * Export a page subtask.
461
 */
462
function page_manager_page_export($page, $with_handlers = FALSE, $indent = '') {
463
  $task = page_manager_get_task($page->task);
464
  $append = '';
465

    
466
  if ($function = ctools_plugin_get_function($task, 'export')) {
467
    $append = $function($page, $indent);
468
  }
469

    
470
  ctools_include('export');
471
  $output = ctools_export_object('page_manager_pages', $page, $indent);
472
  $output .= $append;
473

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

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

    
511
  return $arguments;
512
}
513

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

    
538
  $path = explode('/', $page->path);
539
  if (empty($path[$argument])) {
540
    return FALSE;
541
  }
542

    
543
  $keyword = substr($path[$argument], 1);
544
  if (empty($page->arguments[$keyword])) {
545
    return $value;
546
  }
547

    
548
  $page->arguments[$keyword]['keyword'] = $keyword;
549

    
550
  ctools_include('context');
551
  $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value);
552

    
553
  // Convert false equivalents to false.
554
  return $context ? $context : FALSE;
555
}
556

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

    
566
  $rows = array();
567

    
568
  $rows[] = array(
569
    array('class' => array('page-summary-label'), 'data' => t('Storage')),
570
    array('class' => array('page-summary-data'), 'data' => $subtask['storage']),
571
    array('class' => array('page-summary-operation'), 'data' => ''),
572
  );
573

    
574
  if (!empty($page->disabled)) {
575
    $link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'enable')));
576
    $text = t('Disabled');
577
  }
578
  else {
579
    $link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'disable')));
580
    $text = t('Enabled');
581
  }
582

    
583
  $rows[] = array(
584
    array('class' => array('page-summary-label'), 'data' => t('Status')),
585
    array('class' => array('page-summary-data'), 'data' => $text),
586
    array('class' => array('page-summary-operation'), 'data' => $link),
587
  );
588

    
589
  $path = array();
590
  foreach (explode('/', $page->path) as $bit) {
591
    if ($bit[0] != '!') {
592
      $path[] = $bit;
593
    }
594
  }
595

    
596
  $path = implode('/', $path);
597
  $front = variable_get('site_frontpage', 'node');
598

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

    
608
  if ($message) {
609
    $rows[] = array(
610
      array('class' => array('page-summary-data'), 'data' => $message, 'colspan' => 2),
611
      array('class' => array('page-summary-operation'), 'data' => $link),
612
    );
613
  }
614

    
615
  if (strpos($path, '%') === FALSE) {
616
    $path = l('/' . $page->path, $path);
617
  }
618
  else {
619
    $path = '/' . $page->path;
620
  }
621

    
622
  $rows[] = array(
623
    array('class' => array('page-summary-label'), 'data' => t('Path')),
624
    array('class' => array('page-summary-data'), 'data' => $path),
625
    array('class' => array('page-summary-operation'), 'data' => $link),
626
  );
627

    
628
  if (empty($access['plugins'])) {
629
    $access['plugins'] = array();
630
  }
631

    
632
  $contexts = page_manager_page_get_contexts($task, $subtask);
633
  $access = ctools_access_group_summary($page->access, $contexts);
634
  if ($access) {
635
    $access = t('Accessible only if @conditions.', array('@conditions' => $access));
636
  }
637
  else {
638
    $access = t('This page is publicly accessible.');
639
  }
640

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

    
643
  $rows[] = array(
644
    array('class' => array('page-summary-label'), 'data' => t('Access')),
645
    array('class' => array('page-summary-data'), 'data' => $access),
646
    array('class' => array('page-summary-operation'), 'data' => $link),
647
  );
648

    
649
  $menu_options = array(
650
    'none' => t('No menu entry.'),
651
    'normal' => t('Normal menu entry.'),
652
    'tab' => t('Menu tab.'),
653
    'default tab' => t('Default menu tab.'),
654
    'action' => t('Local action'),
655
  );
656

    
657
  if (!empty($page->menu)) {
658
    $menu = $menu_options[$page->menu['type']];
659
    if ($page->menu['type'] != 'none') {
660
      $menu .= ' ' . t('Title: %title.', array('%title' => $page->menu['title']));
661
      switch ($page->menu['type']) {
662
        case 'default tab':
663
          $menu .= ' ' . t('Parent title: %title.', array('%title' => $page->menu['parent']['title']));
664
          break;
665

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

    
679
  $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'menu')));
680
  $rows[] = array(
681
    array('class' => array('page-summary-label'), 'data' => t('Menu')),
682
    array('class' => array('page-summary-data'), 'data' => $menu),
683
    array('class' => array('page-summary-operation'), 'data' => $link),
684
  );
685

    
686
  $output .= theme('table', array('rows' => $rows, 'attributes' => array('id' => 'page-manager-page-summary')));
687
  return $output;
688
}
689

    
690
/**
691
 * Callback to enable/disable the page from the UI.
692
 */
693
function page_manager_page_enable(&$cache, $status) {
694
  $page = &$cache->subtask['subtask'];
695
  ctools_include('export');
696
  ctools_export_set_object_status($page, $status);
697

    
698
  $page->disabled = FALSE;
699
}
700

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

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

    
747
  $cache->task_name = page_manager_make_task_name('page', $page->name);
748
  $cache->task_id = 'page';
749
  $cache->task = page_manager_get_task('page');
750
  $cache->subtask_id = $page->name;
751
  $page->export_type = EXPORT_IN_DATABASE;
752
  $page->type = t('Normal');
753
  $cache->subtask = page_manager_page_build_subtask($cache->task, $page);
754

    
755
  if (isset($cache->handlers)) {
756
    foreach ($cache->handlers as $id => $handler) {
757
      $cache->handler_info[$id]['changed'] = PAGE_MANAGER_CHANGED_DELETED;
758
    }
759
  }
760
  else {
761
    $cache->handlers = array();
762
    $cache->handler_info = array();
763
  }
764

    
765
  if (!empty($page->default_handlers)) {
766
    foreach ($page->default_handlers as $id => $handler) {
767
      page_manager_handler_add_to_page($cache, $handler);
768
    }
769
  }
770

    
771
  $cache->locked = FALSE;
772
  $cache->changed = TRUE;
773
}
774

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