[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/ctools/page_manager/plugins/tasks/ -> page.inc (source)

   1  <?php
   2  // $Id: page.inc,v 1.17.2.4 2010/08/30 22:07:52 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Handle the 'page' task, which creates pages with arbitrary tasks and lets
   7   * handlers decide how they will be rendered.
   8   *
   9   * This creates subtasks and stores them in the page_manager_pages table. These
  10   * are exportable objects, too.
  11   *
  12   * The render callback for this task type has $handler, $page, $contexts as
  13   * parameters.
  14   */
  15  
  16  /**
  17   * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
  18   * more information.
  19   */
  20  function page_manager_page_page_manager_tasks() {
  21    return array(
  22      'title' => t('Custom pages'),
  23      'description' => t('Administrator created pages that have a URL path, access control and entries in the Drupal menu system.'),
  24      'non-exportable' => TRUE,
  25      'subtasks' => TRUE,
  26      'subtask callback' => 'page_manager_page_subtask',
  27      'subtasks callback' => 'page_manager_page_subtasks',
  28      'save subtask callback' => 'page_manager_page_save_subtask',
  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/build/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' => '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      'arguments' => array('form' => NULL),
 240    );
 241    $items['page_manager_page_lock'] = $base + array(
 242      'arguments' => array('lock' => array(), 'task_name' => NULL),
 243    );
 244    $items['page_manager_page_changed'] = $base + array(
 245      'arguments' => 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            $plugin = ctools_get_argument($argument['name']);
 295            // to use menu_tail style behavior:
 296            if (empty($argument['settings']['use_tail'])) {
 297              $value = $args[$count];
 298            }
 299            else {
 300              $value = implode('/', array_slice($args, $count));
 301            }
 302  
 303            $context = ctools_context_get_context_from_argument($argument, $value);
 304          }
 305          else {
 306            // make sure there is a placeholder context for missing optional contexts.
 307            $context = ctools_context_get_context_from_argument($argument, NULL, TRUE);
 308            // Force the title to blank for replacements
 309          }
 310          if ($context) {
 311            $contexts[$context->id] = $context;
 312          }
 313        }
 314        $count++;
 315      }
 316    }
 317  
 318    // Add a fake tab for 'View' so that edit tabs can be added.
 319    if (user_access('administer page manager') && (!isset($page->menu['type']) || !in_array($page->menu['type'], array('tab', 'default tab')))) {
 320      ctools_include('menu');
 321      ctools_menu_add_tab(array(
 322        'title' => t('View'),
 323        'href' => $_GET['q'],
 324        'type' => MENU_DEFAULT_LOCAL_TASK,
 325        'weight' => -10,
 326      ));
 327    }
 328  
 329  
 330    if ($function = ctools_plugin_get_function($task, 'page callback')) {
 331      return call_user_func_array($function, array($page, $contexts, $args));
 332    }
 333  
 334    ctools_include('context-task-handler');
 335    $output = ctools_context_handler_render($task, $subtask, $contexts, $args);
 336    if ($output === FALSE) {
 337      return drupal_not_found();
 338    }
 339  
 340    return $output;
 341  }
 342  
 343  // --------------------------------------------------------------------------
 344  // Context type callbacks
 345  
 346  /**
 347   * Return a list of arguments used by this task.
 348   */
 349  function page_manager_page_get_arguments($task, $subtask) {
 350    return _page_manager_page_get_arguments($subtask['subtask']);
 351  }
 352  
 353  function _page_manager_page_get_arguments($page) {
 354    $arguments = array();
 355    if (!empty($page->arguments)) {
 356      foreach ($page->arguments as $keyword => $argument) {
 357        if (isset($argument['name'])) {
 358          $argument['keyword'] = $keyword;
 359          $arguments[$keyword] = $argument;
 360        }
 361      }
 362    }
 363    return $arguments;
 364  }
 365  
 366  /**
 367   * Get a group of context placeholders for the arguments.
 368   */
 369  function page_manager_page_get_contexts($task, $subtask) {
 370    ctools_include('context');
 371    return ctools_context_get_placeholders_from_argument(page_manager_page_get_arguments($task, $subtask));
 372  }
 373  
 374  /**
 375   * Return a list of arguments used by this task.
 376   */
 377  function page_manager_page_access_restrictions($task, $subtask, $contexts) {
 378    $page = $subtask['subtask'];
 379    return ctools_access_add_restrictions($page->access, $contexts);
 380  }
 381  
 382  // --------------------------------------------------------------------------
 383  // Page task database info.
 384  
 385  /**
 386   * Create a new page with defaults appropriately set from schema.
 387   */
 388  function page_manager_page_new() {
 389    ctools_include('export');
 390    return ctools_export_new_object('page_manager_pages');
 391  }
 392  
 393  /**
 394   * Load a single page subtask.
 395   */
 396  function page_manager_page_load($name) {
 397    ctools_include('export');
 398    $result = ctools_export_load_object('page_manager_pages', 'names', array($name));
 399    if (isset($result[$name])) {
 400      return $result[$name];
 401    }
 402  }
 403  
 404  /**
 405   * Load all page subtasks.
 406   */
 407  function page_manager_page_load_all($task = NULL) {
 408    ctools_include('export');
 409  
 410    if (empty($task)) {
 411      return ctools_export_load_object('page_manager_pages');
 412    }
 413    else {
 414      return ctools_export_load_object('page_manager_pages', 'conditions', array('task' => $task));
 415    }
 416  }
 417  
 418  /**
 419   * Write a page subtask to the database.
 420   */
 421  function page_manager_page_save(&$page) {
 422    $update = (isset($page->pid)) ? array('pid') : array();
 423    $task = page_manager_get_task($page->task);
 424  
 425    if ($function = ctools_plugin_get_function($task, 'save')) {
 426      $function($page, $update);
 427    }
 428    drupal_write_record('page_manager_pages', $page, $update);
 429  
 430    // If this was a default page we may need to write default task
 431    // handlers that we provided as well.
 432    if (!$update && isset($page->default_handlers)) {
 433      $handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
 434      foreach ($page->default_handlers as $name => $handler) {
 435        if (!isset($handlers[$name]) || !($handlers[$name]->export_type & EXPORT_IN_DATABASE)) {
 436          // Make sure this is right, as exports can wander a bit.
 437          $handler->subtask = $page->name;
 438          page_manager_save_task_handler($handler);
 439        }
 440      }
 441    }
 442    return $page;
 443  }
 444  
 445  /**
 446   * Remove a page subtask.
 447   */
 448  function page_manager_page_delete($page) {
 449    $task = page_manager_get_task($page->task);
 450    if ($function = ctools_plugin_get_function($task, 'delete')) {
 451      $function($page);
 452    }
 453    if (!empty($task['uses handlers'])) {
 454      $handlers = page_manager_load_task_handlers($task, $page->name);
 455      foreach ($handlers as $handler) {
 456        page_manager_delete_task_handler($handler);
 457      }
 458    }
 459    db_query("DELETE FROM {page_manager_pages} WHERE name = '%s'", $page->name);
 460    // Make sure that the cache is reset so that the menu rebuild does not
 461    // rebuild this page again.
 462    ctools_include('export');
 463    ctools_export_load_object_reset('page_manager_pages');
 464    menu_rebuild();
 465  }
 466  
 467  /**
 468   * Export a page subtask.
 469   */
 470  function page_manager_page_export($page, $with_handlers = FALSE, $indent = '') {
 471    $task = page_manager_get_task($page->task);
 472    $append = '';
 473  
 474    if ($function = ctools_plugin_get_function($task, 'export')) {
 475      $append = $function($page, $indent);
 476    }
 477  
 478    ctools_include('export');
 479    $output = ctools_export_object('page_manager_pages', $page, $indent);
 480    $output .= $append;
 481  
 482    if ($with_handlers) {
 483      if (is_array($with_handlers)) {
 484        $handlers = $with_handlers;
 485      }
 486      else {
 487        $handlers = page_manager_load_task_handlers(page_manager_get_task('page'), $page->name);
 488      }
 489      $output .= $indent . '$page->default_handlers = array();' . "\n";
 490      foreach ($handlers as $handler) {
 491        $output .= page_manager_export_task_handler($handler, $indent);
 492        $output .= $indent . '$page->default_handlers[$handler->name] = $handler;' . "\n";
 493      }
 494    }
 495    return $output;
 496  }
 497  
 498  /**
 499   * Get a list of named arguments in a page manager path.
 500   *
 501   * @param $path
 502   *   A normal Drupal path.
 503   *
 504   * @return
 505   *   An array of % marked variable arguments, keyed by the argument's name.
 506   *   The value will be the position of the argument so that it can easily
 507   *   be found. Items with a position of -1 have multiple positions.
 508   */
 509  function page_manager_page_get_named_arguments($path) {
 510    $arguments = array();
 511    $bits = explode('/', $path);
 512    foreach ($bits as $position => $bit) {
 513      if ($bit && ($bit[0] == '%' || $bit[0] == '!')) {
 514        // special handling for duplicate path items and substr to remove the %
 515        $arguments[substr($bit, 1)] = isset($arguments[$bit]) ? -1 : $position;
 516      }
 517    }
 518  
 519    return $arguments;
 520  }
 521  
 522  /**
 523   * Load a context from an argument for a given page task.
 524   *
 525   * Helper function for pm_arg_load(), which is in page_manager.module because
 526   * drupal's menu system does not allow loader functions to reside in separate
 527   * files.
 528   *
 529   * @param $value
 530   *   The incoming argument value.
 531   * @param $subtask
 532   *   The subtask id.
 533   * @param $argument
 534   *   The numeric position of the argument in the path, counting from 0.
 535   *
 536   * @return
 537   *   A context item if one is configured, the argument if one is not, or
 538   *   FALSE if restricted or invalid.
 539   */
 540  function _pm_arg_load($value, $subtask, $argument) {
 541    $page = page_manager_page_load($subtask);
 542    if (!$page) {
 543      return FALSE;
 544    }
 545  
 546    $path = explode('/', $page->path);
 547    if (empty($path[$argument])) {
 548      return FALSE;
 549    }
 550  
 551    $keyword = substr($path[$argument], 1);
 552    if (empty($page->arguments[$keyword])) {
 553      return $value;
 554    }
 555  
 556    $page->arguments[$keyword]['keyword'] = $keyword;
 557  
 558    ctools_include('context');
 559    $context = ctools_context_get_context_from_argument($page->arguments[$keyword], $value);
 560  
 561    // convert false equivalents to false.
 562    return $context ? $context : FALSE;
 563  }
 564  
 565  /**
 566   * Provide a nice administrative summary of the page so an admin can see at a
 567   * glance what this page does and how it is configured.
 568   */
 569  function page_manager_page_admin_summary($task, $subtask) {
 570    $task_name = page_manager_make_task_name($task['name'], $subtask['name']);
 571    $page = $subtask['subtask'];
 572    $output = '';
 573  
 574    $rows = array();
 575  
 576    $rows[] = array(
 577      array('class' => t('page-summary-label'), 'data' => t('Storage')),
 578      array('class' => t('page-summary-data'), 'data' => $subtask['storage']),
 579      array('class' => t('page-summary-operation'), 'data' => ''),
 580    );
 581  
 582    if (!empty($page->disabled)) {
 583      $link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'enable')));
 584      $text = t('Disabled');
 585    }
 586    else {
 587      $link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $page->name, 'actions', 'disable')));
 588      $text = t('Enabled');
 589    }
 590  
 591    $rows[] = array(
 592      array('class' => t('page-summary-label'), 'data' => t('Status')),
 593      array('class' => t('page-summary-data'), 'data' => $text),
 594      array('class' => t('page-summary-operation'), 'data' => $link),
 595    );
 596  
 597  
 598    $path = array();
 599    foreach (explode('/', $page->path) as $bit) {
 600      if ($bit[0] != '!') {
 601        $path[] = $bit;
 602      }
 603    }
 604  
 605    $path = implode('/', $path);
 606    $front = variable_get('site_frontpage', 'node');
 607  
 608    $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'basic')));
 609    $message = '';
 610    if ($path == $front) {
 611      $message = t('This is your site home page.');
 612    }
 613    else if (!empty($page->make_frontpage)) {
 614      $message = t('This page is set to become your site home page.');
 615    }
 616  
 617    if ($message) {
 618      $rows[] = array(
 619        array('class' => t('page-summary-data'), 'data' => $message, 'colspan' => 2),
 620        array('class' => t('page-summary-operation'), 'data' => $link),
 621      );
 622    }
 623  
 624    if (strpos($path, '%') === FALSE) {
 625      $path = l('/' . $page->path, $path);
 626    }
 627    else {
 628      $path = '/' . $page->path;
 629    }
 630  
 631    $rows[] = array(
 632      array('class' => t('page-summary-label'), 'data' => t('Path')),
 633      array('class' => t('page-summary-data'), 'data' => $path),
 634      array('class' => t('page-summary-operation'), 'data' => $link),
 635    );
 636  
 637    if (empty($access['plugins'])) {
 638      $access['plugins'] = array();
 639    }
 640  
 641    $contexts = page_manager_page_get_contexts($task, $subtask);
 642    $access = ctools_access_group_summary($page->access, $contexts);
 643    if ($access) {
 644      $access = t('Accessible only if @conditions.', array('@conditions' => $access));
 645    }
 646    else {
 647      $access = t('This page is publicly accessible.');
 648    }
 649  
 650    $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'access')));
 651  
 652    $rows[] = array(
 653      array('class' => t('page-summary-label'), 'data' => t('Access')),
 654      array('class' => t('page-summary-data'), 'data' => $access),
 655      array('class' => t('page-summary-operation'), 'data' => $link),
 656    );
 657  
 658    $menu_options = array(
 659      'none' => t('No menu entry.'),
 660      'normal' => t('Normal menu entry.'),
 661      'tab' => t('Menu tab.'),
 662      'default tab' => t('Default menu tab.'),
 663    );
 664  
 665    if (!empty($page->menu)) {
 666      $menu = $menu_options[$page->menu['type']];
 667      if ($page->menu['type'] != 'none') {
 668        $menu .= ' ' . t('Title: %title.', array('%title' => $page->menu['title']));
 669        switch ($page->menu['type']) {
 670          case 'default tab':
 671            $menu .= ' ' . t('Parent title: %title.', array('%title' => $page->menu['parent']['title']));
 672            break;
 673          case 'normal':
 674            if (module_exists('menu')) {
 675              $menus = menu_get_menus();
 676              $menu .= ' ' . t('Menu block: %title.', array('%title' => $menus[$page->menu['name']]));
 677            }
 678            break;
 679        }
 680      }
 681    }
 682    else {
 683      $menu = t('No menu entry');
 684    }
 685  
 686    $link = l(t('Edit'), page_manager_edit_url($task_name, array('settings', 'menu')));
 687    $rows[] = array(
 688      array('class' => t('page-summary-label'), 'data' => t('Menu')),
 689      array('class' => t('page-summary-data'), 'data' => $menu),
 690      array('class' => t('page-summary-operation'), 'data' => $link),
 691    );
 692  
 693    $output .= theme('table', array(), $rows, array('id' => 'page-manager-page-summary'));
 694    return $output;
 695  }
 696  
 697  /**
 698   * Callback to enable/disable the page from the UI.
 699   */
 700  function page_manager_page_enable(&$cache, $status) {
 701    $page = &$cache->subtask['subtask'];
 702    ctools_include('export');
 703    ctools_export_set_object_status($page, $status);
 704  
 705    $page->disabled = FALSE;
 706  }
 707  
 708  /**
 709   * Recalculate the arguments when something like the path changes.
 710   */
 711  function page_manager_page_recalculate_arguments(&$page) {
 712    // Ensure $page->arguments contains only real arguments:
 713    $arguments = page_manager_page_get_named_arguments($page->path);
 714    $args = array();
 715    foreach ($arguments as $keyword => $position) {
 716      if (isset($page->arguments[$keyword])) {
 717        $args[$keyword] = $page->arguments[$keyword];
 718      }
 719      else {
 720        $args[$keyword] = array(
 721          'id' => '',
 722          'identifier' => '',
 723          'argument' => '',
 724          'settings' => array(),
 725        );
 726      }
 727    }
 728    $page->arguments = $args;
 729  }
 730  
 731  /**
 732   * When adding or cloning a new page, this creates a new page cache
 733   * and adds our page to it.
 734   *
 735   * This does not check to see if the existing cache is already locked.
 736   * This must be done beforehand.
 737   *
 738   * @param &$page
 739   *   The page to create.
 740   * @param &$cache
 741   *   The cache to use. If the cache has any existing task handlers,
 742   *   they will be marked for deletion. This may be a blank object.
 743   */
 744  function page_manager_page_new_page_cache(&$page, &$cache) {
 745    // Does a page already exist? If so, we are overwriting it so
 746    // take its pid.
 747    if (!empty($cache->subtask) && !empty($cache->subtask['subtask']) && !empty($cache->subtask['subtask']->pid)) {
 748      $page->pid = $cache->subtask['subtask']->pid;
 749    }
 750    else {
 751      $cache->new = TRUE;
 752    }
 753  
 754    $cache->task_name = page_manager_make_task_name('page', $page->name);
 755    $cache->task_id = 'page';
 756    $cache->task = page_manager_get_task('page');
 757    $cache->subtask_id = $page->name;
 758    $page->export_type = EXPORT_IN_DATABASE;
 759    $page->type = t('Normal');
 760    $cache->subtask = page_manager_page_build_subtask($cache->task, $page);
 761  
 762    if (isset($cache->handlers)) {
 763      foreach($cache->handlers as $id => $handler) {
 764        $cache->handler_info[$id]['changed'] = PAGE_MANAGER_CHANGED_DELETED;
 765      }
 766    }
 767    else {
 768      $cache->handlers = array();
 769      $cache->handler_info = array();
 770    }
 771  
 772    if (!empty($page->default_handlers)) {
 773      foreach ($page->default_handlers as $id => $handler) {
 774        page_manager_handler_add_to_page($cache, $handler);
 775      }
 776    }
 777  
 778    $cache->locked = FALSE;
 779    $cache->changed = TRUE;
 780  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7