You may peruse a list of your current panels layouts and edit them, or click add to create a new page.

'); case 'admin/panels/panel-page/add': return t('

Choose a layout for your new page from the list below.

'); } } /** * Implementation of hook_perm() */ function panels_page_perm() { return array('create panel-pages', 'access all panel-pages'); } /** * Implementation of hook_menu() */ function panels_page_menu($may_cache) { $items = array(); $panels = panels_page_load_all(); if ($may_cache) { $access = user_access('create panel-pages'); $items[] = array( 'path' => 'admin/panels/panel-page', 'title' => t('Panel pages'), 'access' => $access, 'callback' => 'panels_page_list_page', 'description' => t('Create and administer panel-pages (complex layout pages with URLs).'), ); $items[] = array( 'path' => 'admin/panels/panel-page/list', 'title' => t('List'), 'access' => $access, 'callback' => 'panels_page_list_page', 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-page/add', 'title' => t('Add'), 'access' => $access, 'callback' => 'panels_page_add_page', 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-page/import', 'title' => t('Import'), 'access' => $access, 'callback' => 'panels_page_import_page', 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-page/settings', 'title' => t('Settings'), 'access' => $access, 'callback' => 'panels_page_settings', 'weight' => 5, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-page/add/layout', 'title' => t('Add'), 'access' => $access, 'callback' => 'panels_page_add_layout_page', 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-page/disable', 'title' => t('Export'), 'access' => $access, 'callback' => 'panels_page_disable_page', 'weight' => -1, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => 'admin/panels/panel-page/enable', 'title' => t('Export'), 'access' => $access, 'callback' => 'panels_page_enable_page', 'weight' => -1, 'type' => MENU_LOCAL_TASK, ); // Get all panels and, if enabled, create menu items. foreach ($panels as $panel_page) { if (empty($panel_page->disabled)) { // TODO: Verify we don't need this anymore. // $panel_page->access = ($panel_page->access ? explode(', ', $panel_page->access) : array()); // Only create menu items based on the path if it's not a variable path. if (strpos($panel_page->path, '%') === FALSE) { panels_page_menu_items($items, $panel_page->path, $panel_page, FALSE, array($panel_page->name)); } panels_page_menu_items($items, 'admin/panels/panel-page/' . $panel_page->name, $panel_page, TRUE, array($panel_page->name)); } } } else { // Look for panels with variable arguments. // Build an array of $urls because 'real' URLs will take precedence over // argument filled URLs $urls = array(); foreach ($panels as $panel_page) { $url[$panel_page->path] = TRUE; } foreach ($panels as $panel_page) { if (strpos($panel_page->path, '%') !== FALSE) { $path = explode('/', $panel_page->path); $match = TRUE; foreach ($path as $id => $chunk) { if ($chunk != '%' && $chunk != arg($id)) { $match = FALSE; break; } } // It's a MATCH! Construct the URL if ($match) { $args = array($panel_page); foreach ($path as $id => $chunk) { if ($chunk == '%') { // TODO: Here is where we can perform validation $path[$id] = arg($id); $args[] = arg($id); } } panels_page_menu_items($items, implode('/', $path), $panel_page, FALSE, $args); } } } } return $items; } function panels_page_menu_items(&$items, $base, $page, $basic = FALSE, $args = array()) { $view_access = panels_page_access($page); $access = user_access('create panel-pages'); if ($basic) { $items[] = array( 'path' => $base, 'title' => t('View'), 'access' => $view_access, 'callback' => 'panels_page_view_page', 'callback arguments' => $args, 'weight' => -10, 'type' => MENU_CALLBACK, ); } else { _panels_page_create_menu_item($items, $page, $base, $view_access, $args); } $items[] = array( 'path' => $base . '/view', 'title' => t('View'), 'access' => $view_access, 'callback' => 'panels_page_view_page', 'callback arguments' => $args, 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( 'path' => $base . '/edit', 'title' => t('Edit'), 'access' => $access, 'callback' => 'panels_page_edit', 'callback arguments' => array($page->name), 'weight' => -5, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => $base . '/edit/general', 'title' => t('General'), 'access' => $access, 'callback' => 'panels_page_edit', 'callback arguments' => array($page->name), 'weight' => -5, 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array( 'path' => $base . '/edit/advanced', 'title' => t('Advanced'), 'access' => $access, 'callback' => 'panels_page_edit_advanced', 'callback arguments' => array($page->name), 'weight' => -4, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => $base . '/edit/layout', 'title' => t('Layout'), 'access' => $access, 'callback' => 'panels_page_edit_layout', 'callback arguments' => array($page->name), 'weight' => -3, 'type' => MENU_LOCAL_TASK, ); $layout = panels_get_layout($page->display->layout); if (!empty($layout['settings form'])) { $items[] = array( 'path' => $base . '/edit/settings', 'title' => t('Layout settings'), 'access' => $access, 'callback' => 'panels_page_edit_layout_settings', 'callback arguments' => array($page->name), 'weight' => -3, 'type' => MENU_LOCAL_TASK, ); } $items[] = array( 'path' => $base . '/edit/content', 'title' => t('Content'), 'access' => $access, 'callback' => 'panels_page_edit_content', 'callback arguments' => array($page->name), 'weight' => -1, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => $base . '/export', 'title' => t('Export'), 'access' => $access, 'callback' => 'drupal_get_form', 'callback arguments' => array('panels_page_edit_export', $page->name), 'weight' => -1, 'type' => MENU_LOCAL_TASK, ); $items[] = array( 'path' => $base . '/delete', 'title' => t('Delete panel page'), 'access' => $access, 'callback' => 'drupal_get_form', 'callback arguments' => array('panels_page_delete_confirm', $page->name), 'type' => MENU_CALLBACK, ); } // This stuff is lifted pretty much directly from Views. /** * Helper function to add a menu item for a panel. */ /** * Get the title for a panel page, given a context. */ function panels_page_get_title($panel_page, $context = 'page', $default_title = NULL) { if ($context == 'menu-parent' && $panel_page->menu_parent_title) { return $panel_page->menu_parent_title; } if (in_array($context, array('menu', 'menu-parent')) && $panel_page->menu_title) { return $panel_page->menu_title; } if ($panel_page->title) { return $panel_page->title; } if (is_null($default_title)) { return t('No title'); } else { return $default_title; } } /** * Create a menu item for a panel page. */ function _panels_page_create_menu_item(&$items, $panel_page, $path, $access, $args = array()) { $title = filter_xss_admin(panels_page_get_title($panel_page, 'menu')); $type = _panels_page_menu_type($panel_page); if ($type == MENU_LOCAL_TASK || $type == MENU_DEFAULT_LOCAL_TASK) { $weight = $panel_page->menu_tab_weight; } $items[] = _panels_page_menu_item($path, $title, $panel_page, $args, $access, $type, $weight); if ($type == MENU_DEFAULT_LOCAL_TASK && dirname($path) && dirname($path) != '.') { switch ($panel_page->menu_tab_default_parent_type) { case 'tab': $parent_type = MENU_LOCAL_TASK; break; case 'normal': $parent_type = MENU_NORMAL_ITEM; break; default: case 'existing': $parent_type = 0; break; } if ($parent_type) { $title = filter_xss_admin(panels_page_get_title($panel_page, 'menu-parent')); $weight = $panel_page->menu_parent_tab_weight; $items[] = _panels_page_menu_item(dirname($path), $title, $panel_page, $args, $access, $parent_type, $weight); } } } /** * Helper function to create a menu item for a panel. */ function _panels_page_menu_item($path, $title, $panel_page, $args, $access, $type, $weight = NULL) { $retval = array('path' => $path, 'title' => $title, 'callback' => 'panels_page_view_page', 'callback arguments' => $args, 'access' => user_access('access content') && $access, 'type' => $type, ); if ($weight !== NULL) { $retval['weight'] = $weight; } return $retval; } /** * Determine what menu type a panel needs to use. */ function _panels_page_menu_type($panel_page) { if ($panel_page->menu) { if ($panel_page->menu_tab_default) { $type = MENU_DEFAULT_LOCAL_TASK; } else if ($panel_page->menu_tab) { $type = MENU_LOCAL_TASK; } else { $type = MENU_NORMAL_ITEM; } } else { $type = MENU_CALLBACK; } return $type; } /** * Determine if the specified user has access to a panel. */ function panels_page_access($panel_page, $account = NULL) { if (!$account) { global $user; $account = $user; } // Administrator privileges if (user_access('access all panel-pages', $account)) { return TRUE; } // All views with an empty access setting are available to all roles. if (!$panel_page->access || !is_array($panel_page->access)) { return TRUE; } // Otherwise, check roles static $roles = array(); if (!isset($roles[$account->uid])) { $roles[$account->uid] = array_keys($account->roles); $roles[$account->uid][] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; } return array_intersect($panel_page->access, $roles[$account->uid]); } // --------------------------------------------------------------------------- // panel page administrative pages /** * Settings for panel pages */ function panels_page_settings() { require_once drupal_get_path('module', 'panels') . '/panels_common.inc'; return drupal_get_form('panels_common_settings', 'panels_page'); } /** * Provide a list of panels, with links to edit or delete them. */ function panels_page_list_page() { $layouts = panels_get_layouts(); foreach (panels_page_load_all() as $panel_page) { $ops = array( l(t('Edit'), "admin/panels/panel-page/$panel_page->name/edit"), l(t('Export'), "admin/panels/panel-page/$panel_page->name/export"), ); if ($panel_page->type != t('Default')) { $ops[] = l(t('Delete'), "admin/panels/panel-page/$panel_page->name/delete"); } else { if (empty($panel_page->disabled)) { $ops[] = l(t('Disable'), "admin/panels/panel-page/disable/$panel_page->name", NULL, drupal_get_destination()); } else { $ops[] = l(t('Enable'), "admin/panels/panel-page/enable/$panel_page->name", NULL, drupal_get_destination()); } } $path = empty($panel_page->disabled) && strpos($panel_page->path, '%') === FALSE ? l($panel_page->path, $panel_page->path) : check_plain($panel_page->path); $item = array(); $item[] = check_plain(panels_page_get_title($panel_page)); $item[] = $panel_page->type; // this is safe as it's always programmatic $item[] = check_plain($layouts[$panel_page->display->layout]['title']); $item[] = $path; $item[] = implode(' | ', $ops); $items[] = $item; } $header = array( t('Page title'), t('Type'), t('Layout'), t('URL'), t('Operations'), ); $output = theme('table', $header, $items); return $output; } /** * Enable a default panel. */ function panels_page_enable_page($name = NULL) { $defaults = panels_page_default_panels(); if (isset($defaults[$name])) { $status = variable_get('panel_page_defaults', array()); $status[$name] = FALSE; variable_set('panel_page_defaults', $status); menu_rebuild(); drupal_set_message(t('Panel page enabled')); } drupal_goto(); } /** * Disable a default panel. */ function panels_page_disable_page($name = NULL) { $defaults = panels_page_default_panels(); if (isset($defaults[$name])) { $status = variable_get('panel_page_defaults', array()); $status[$name] = TRUE; variable_set('panel_page_defaults', $status); drupal_set_message(t('Panel page disabled')); menu_rebuild(); } drupal_goto(); } /* * Provide a form to confirm deletion of a panel page. */ function panels_page_delete_confirm($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } $form['pid'] = array('#type' => 'value', '#value' => $panel_page->pid); $form['did'] = array('#type' => 'value', '#value' => $panel_page->did); return confirm_form( $form, t('Are you sure you want to delete "@title"?', array('@title' => panels_page_get_title($panel_page))), $_GET['destination'] ? $_GET['destination'] : 'admin/panels/panel-page', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } /* * Handle the submit button to delete a panel page. */ function panels_page_delete_confirm_submit($formid, $form) { if ($form['confirm']) { panels_page_delete((object) $form); // TODO: Is this necessary or did we feed it the location already? return 'admin/panels/panel-page'; } } /** * Handle the add panel-page page */ function panels_page_add_page($layout = NULL) { $layouts = panels_get_layouts(); if ($layout === NULL) { foreach ($layouts as $id => $layout) { $output .= panels_print_layout_link($id, $layout, $_GET['q'] . '/' . $id); } return $output; } if (!$layouts[$layout]) { return drupal_not_found(); } $panel_page->display = panels_new_display(); $panel_page->display->layout = $layout; $panel_page->pid = 'new'; $panel_page->did = 'new'; return panels_page_edit($panel_page); } /** * Edit a panel page. Called from both the add and edit points to provide * for common flow. */ function panels_page_edit($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } drupal_set_title(check_plain(panels_page_get_title($panel_page))); return drupal_get_form('panels_page_edit_form', $panel_page); } /** * The form to edit the page portion of a panel. */ function panels_page_edit_form($panel_page) { drupal_add_css(panels_get_path('css/panels_admin.css')); $layout = panels_get_layout($panel_page->display->layout); $form['pid'] = array( '#type' => 'value', '#value' => $panel_page->pid, ); $form['panel_page'] = array( '#type' => 'value', '#value' => $panel_page ); $form['right'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['left'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['left']['info'] = array( '#type' => 'fieldset', '#title' => t('Page settings'), ); $form['right']['layout'] = array( '#type' => 'fieldset', '#title' => t('Layout'), ); $form['right']['layout']['layout-icon'] = array( '#value' => panels_print_layout_icon($panel_page->display->layout, $layout), ); $form['right']['layout']['layout-display'] = array( '#value' => check_plain($layout['title']), ); $content = '
'; foreach (panels_get_panels($layout, $panel_page->display) as $panel_id => $title) { $content .= "
$title
"; if ($panel_page->display->panels[$panel_id]) { $content .= '
    '; foreach ($panel_page->display->panels[$panel_id] as $pid) { $content .= '
  1. ' . panels_get_pane_title($panel_page->display->content[$pid]) . '
  2. '; } $content .= '
'; } else { $content .= t('Empty'); } $content .= '
'; } $content .= '
'; $form['right']['layout']['layout-content'] = array( '#value' => $content, ); $form['left']['info']['name'] = array( '#type' => 'textfield', '#size' => 35, '#default_value' => $panel_page->name, '#title' => t('Panel name'), '#description' => t('A unique name used to identify this panel page internally. It must be only be alpha characters and underscores. No spaces, numbers or uppercase characters.'), ); $form['left']['info']['title'] = array( '#type' => 'textfield', '#size' => 35, '#default_value' => $panel_page->title, '#title' => t('Page title'), '#description' => t('The page title for this panels layout'), ); $form['left']['info']['css_id'] = array( '#type' => 'textfield', '#size' => 35, '#default_value' => $panel_page->css_id, '#title' => t('CSS ID'), '#description' => t('The CSS ID to apply to this page'), ); $form['left']['info']['path'] = array( '#type' => 'textfield', '#size' => 35, '#default_value' => $panel_page->path, '#title' => t('Path'), '#description' => t('The URL path to give this page, i.e, path/to/page. You may use "%" as an argument placeholder: i.e, node/%/panel'), '#required' => TRUE, ); $label = ($panel_page->pid == 'new') ? t('Next') : t('Save'); $form['submit'] = array( '#type' => 'submit', '#value' => $label, ); return $form; } /** * Validate a panel page edit form */ function panels_page_edit_form_validate($form_id, $form_values, $form) { // Test uniqueness of name: $query = "SELECT pid FROM {panels_page} WHERE name = '%s'"; if (!empty($form_values['pid']) && is_numeric($form_values['pid'])) { $query .= " AND pid != $form_values[pid]"; } if (db_result(db_query($query, $form_values['name']))) { form_error($form['left']['info']['name'], t('Panel name must be unique.')); } if (!$form_values['path']) { form_error($form['left']['info']['path'], t('Path is required.')); } else { $result = db_result(db_query("SELECT pid FROM {panels_page} WHERE path = '%s' AND pid <> %d", $form_values['path'], $form_values['pid'])); if ($result) { form_error($form['left']['info']['path'], t('Path may not be the same as another panel page path.')); } } } /** * Process submission of the panel page edit form */ function panels_page_edit_form_submit($form_id, $form_values) { $panel_page = $form_values['panel_page']; $panel_page->title = $form_values['title']; $panel_page->name = $form_values['name']; $panel_page->css_id = $form_values['css_id']; $panel_page->path = $form_values['path']; if ($panel_page->pid == 'new') { unset($_SESSION['pp_import']); $pid = panels_page_save($panel_page); $GLOBALS['form_values']['pid'] = $pid; $layout = panels_get_layout($panel_page->display->layout); if ($layout['settings form']) { return "admin/panels/panel-page/$panel_page->name/edit/settings/next"; } return "admin/panels/panel-page/$panel_page->name/edit/content"; } else { drupal_set_message(t('Your changes have been saved.')); panels_page_save($panel_page); } } function panels_page_edit_advanced($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } drupal_set_title(check_plain(panels_page_get_title($panel_page))); return drupal_get_form('panels_page_advanced_form', $panel_page); } /** * The form to edit the advanced settings of a panel page */ function panels_page_advanced_form($panel_page) { drupal_add_css(panels_get_path('css/panels_admin.css')); $layout = panels_get_layout($panel_page->display->layout); $form['pid'] = array( '#type' => 'value', '#value' => $panel_page->pid, ); $form['panel_page'] = array( '#type' => 'value', '#value' => $panel_page ); $form['right'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['left'] = array( '#prefix' => '
', '#suffix' => '
', ); $form['right']['advanced'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Advanced settings'), ); $form['right']['advanced'] = array( '#type' => 'fieldset', '#collapsible' => FALSE, '#collapsed' => FALSE, '#title' => t('Advanced settings'), ); $form['right']['advanced']['no_blocks'] = array( '#type' => 'checkbox', '#default_value' => $panel_page->no_blocks, '#title' => t('Disable Drupal blocks/regions'), '#description' => t('Check this to have the panel page disable all regions displayed in the theme.'), ); $rids = array(); $result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name"); while ($obj = db_fetch_object($result)) { $rids[$obj->rid] = $obj->name; } $form['right']['advanced']['access'] = array( '#type' => 'checkboxes', '#title' => t('Access'), '#default_value' => $panel_page->access, '#options' => $rids, '#description' => t('Only the checked roles will be able to see this panel in any form; if no roles are checked, access will not be restricted.'), ); $form['right']['advanced']['css'] = array( '#type' => 'textarea', '#title' => t('CSS code'), '#description' => t('Enter well-formed CSS code here; this code will be embedded into the page, and should only be used for minor adjustments; it is usually better to try to put CSS for the page into the theme if possible.'), '#default_value' => $panel_page->css, ); $form['left']['menu-info'] = array( '#type' => 'fieldset', '#collapsible' => FALSE, '#title' => t('Menu'), ); $form['left']['menu-info']['menu'] = array( '#type' => 'checkbox', '#title' => t('Provide Menu'), '#return_value' => 1, '#default_value' => $panel_page->menu, '#description' => t('If checked this panel be given a menu entry in the Drupal menu system. If not checked the data in this group will be ignored.'), ); $form['left']['menu-info']['menu_tab'] = array( '#type' => 'checkbox', '#title' => t('Provide Menu as Tab'), '#return_value' => 1, '#default_value' => $panel_page->menu_tab, '#description' => t("If checked this panel's menu entry will be provided as a tab rather than in the main menu system."), ); $form['left']['menu-info']['menu_tab_weight'] = array( '#type' => 'textfield', '#title' => t('Tab Weight'), '#default_value' => $panel_page->menu_tab_weight, '#size' => 5, '#description' => t('If this is a menu tab, select the weight; lower numbers will be further to the left.'), ); $form['left']['menu-info']['menu_title'] = array( '#type' => 'textfield', '#title' => t('Menu Title'), '#default_value' => $panel_page->menu_title, '#size' => 35, '#maxlength' => 255, '#description' => t('Enter the title to use for the menu entry or tab. If blank, the page title will be used.'), ); $form['left']['menu-info']['default-tab'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Default Menu Tab'), ); $form['left']['menu-info']['default-tab']['menu_tab_default'] = array( '#type' => 'checkbox', '#title' => t('Make Default Menu Tab'), '#return_value' => 1, '#default_value' => $panel_page->menu_tab_default, '#description' => t("If checked this panel's menu entry will be provided as a tab, and will be the default tab for that URL path. For example, if the URL is 'tracker/all' and it is set as the default menu tab, it will be put into the menu as 'tracker' and 'tracker/all' will be the default tab. The following settings allow you to customize the parent item, for example 'tracker'. For tabs to work properly, one tab in the group must be set as the default."), ); $form['left']['menu-info']['default-tab']['menu_tab_default_parent_type'] = array( '#type' => 'select', '#title' => t('Parent Menu Item Type'), '#default_value' => $panel_page->menu_tab_default_parent_type, '#options' => array( 'tab' => t("Tab"), 'normal' => t("Normal menu item"), 'existing' => t("Already exists (don't create)"), ), '#description' => t("Select type of parent item to use for this default menu tab. You can either specify the parent should be a tab (the default), a normal menu item, or to use the menu item that already exists at the specified URL. For example, if the URL for the default tab is 'tracker/all', then 'tracker' would already have to be a valid menu item to use this final choice."), ); $form['left']['menu-info']['default-tab']['menu_parent_tab_weight'] = array( '#type' => 'textfield', '#title' => t('Tab Weight'), '#default_value' => $panel_page->menu_parent_tab_weight, '#size' => 5, '#description' => t('If the parent menu item is a tab, select the weight; lower numbers will be further to the left.'), ); $form['left']['menu-info']['default-tab']['menu_parent_title'] = array( '#type' => 'textfield', '#title' => t('Parent Menu Item Title'), '#default_value' => $panel_page->menu_parent_title, '#size' => 35, '#maxlength' => 255, '#description' => t('If the Parent Menu Item is being defined by this panel (if you set the %type_field to either %tab or %menu), you can specify its title here. If blank, the menu title will be used if that is defined, or the page title if not.', array('%type_field' => t('Parent Menu Item Type'), '%tab' => t('Tab'), '%menu' => t('Normal menu item'))), ); $label = ($panel_page->pid == 'new') ? t('Next') : t('Save'); $form['submit'] = array( '#type' => 'submit', '#value' => $label, ); return $form; } /** * Process submission of the panel page edit form */ function panels_page_advanced_form_submit($form_id, $form_values) { $panel_page = $form_values['panel_page']; $panel_page->css = $form_values['css']; $panel_page->no_blocks = $form_values['no_blocks']; $panel_page->menu = $form_values['menu']; $panel_page->menu_tab = $form_values['menu_tab']; $panel_page->menu_tab_weight = $form_values['menu_tab_weight']; $panel_page->menu_title = $form_values['menu_title']; $panel_page->menu_tab_default = $form_values['menu_tab_default']; $panel_page->menu_tab_default_parent_type = $form_values['menu_tab_default_parent_type']; $panel_page->menu_parent_title = $form_values['menu_parent_title']; $panel_page->menu_parent_tab_weight = $form_values['menu_parent_tab_weight']; $panel_page->access = array_keys(array_filter($form_values['access'])); drupal_set_message(t('Your changes have been saved.')); panels_page_save($panel_page); } /** * Pass through to the panels layout editor. */ function panels_page_edit_layout($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } // If we visit this page on a default panel, we have to make it real. if ($panel_page->pid == 'new') { $pid = panels_page_save($panel_page); // reload because not everything gets properly reset on save and we need // ids that were created. $panel_page = panels_page_load($pid); } drupal_set_title(check_plain(panels_page_get_title($panel_page))); return panels_edit_layout($panel_page->display, t('Save'), "admin/panels/panel-page/$panel_page->name/edit/layout"); } /** * Pass through to the panels layout settings editor. */ function panels_page_edit_layout_settings($panel_page, $next = NULL) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } // If we visit this page on a default panel, we have to make it real. if ($panel_page->pid == 'new') { $pid = panels_page_save($panel_page); // reload because not everything gets properly reset on save and we need // ids that were created. $panel_page = panels_page_load($pid); } drupal_set_title(check_plain(panels_page_get_title($panel_page))); if (empty($next)) { $button = t('Save'); $dest = "admin/panels/panel-page/$panel_page->name/edit/settings"; } else { $button = t('Next'); $dest = "admin/panels/panel-page/$panel_page->name/edit/content"; } return panels_edit_layout_settings($panel_page->display, $button, $dest); } /** * Pass through to the panels content editor. */ function panels_page_edit_content($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } // If we visit this page on a default panel, we have to make it real. if ($panel_page->pid == 'new') { $pid = panels_page_save($panel_page); // reload because not everything gets properly reset on save and we need // ids that were created. $panel_page = panels_page_load($pid); } require_once drupal_get_path('module', 'panels') . '/panels_common.inc'; $content_types = panels_common_get_allowed_types('panels_page'); // Print this with theme('page') so that blocks are disabled while editing a display. // This is important because negative margins in common block layouts (i.e, Garland) // messes up the drag & drop. drupal_set_title(check_plain(panels_page_get_title($panel_page))); print theme('page', panels_edit($panel_page->display, "admin/panels/panel-page/$panel_page->name/edit/content", $content_types), FALSE); } /** * Page callback to export a panel page to PHP code. */ function panels_page_edit_export($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } drupal_set_title(check_plain($panel_page->title)); $code = panels_page_export($panel_page); $lines = substr_count($code, "\n"); $form['code'] = array( '#type' => 'textarea', '#title' => $panel_page->title, '#default_value' => $code, '#rows' => $lines); return $form; } /* * Page callback to import a panel page from PHP code. */ function panels_page_import_page() { if ($_POST['form_id'] == 'panels_page_edit_form') { $panel_page = $_SESSION['pp_import']; drupal_set_title(t('Import panel page "@s"', array('@s' => $panel_page->title))); return panels_page_edit($panel_page); } return drupal_get_form('panels_page_import_form'); } /* * Form to for the panel page import */ function panels_page_import_form() { $form['panel_page'] = array( '#type' => 'textarea', '#title' => t('Panel page code'), '#cols' => 60, '#rows' => 6, '#description' => t('Cut and paste the results of an Export Panel Page here.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t("Submit"), ); $form['#redirect'] = NULL; return $form; } /* * Handle the submit button on importing a panel page. */ function panels_page_import_form_submit($formid, $form) { ob_start(); eval($form['panel_page']); ob_end_clean(); if (isset($page)) { drupal_set_title(t('Import panel page "@s"', array('@s' => $page->title))); $_SESSION['pp_import'] = $page; $output = drupal_get_form('panels_page_edit_form', $page); print theme('page', $output); exit; } else { drupal_set_message(t('Unable to get a panel page out of that.')); } } // --------------------------------------------------------------------------- // view panels page /** * Page callback to view a panel page. */ function panels_page_view_page($panel_page) { if (!is_object($panel_page)) { $panel_page = panels_page_load($panel_page); } if (!$panel_page) { return drupal_not_found(); } $panel_page->display->args = func_get_args(); array_shift($panel_page->display->args); // remove the pid. $panel_page->display->css_id = $panel_page->css_id; $output = panels_render_display($panel_page->display); // set title afterward to ensure title is retained. if ($output == NULL) { watchdog('panels', t('Unable to find requested layout %s', array('%s' => check_plain($panel_page->display->layout)))); return drupal_not_found(); } drupal_set_title(filter_xss_admin(panels_page_get_title($panel_page, 'page', ''))); if ($panel_page->css) { drupal_set_html_head("\n"); } if ($panel_page->no_blocks) { print theme('page', $output, FALSE); } else { return $output; } } // --------------------------------------------------------------------------- // Database functions /** * Fetch all panel pages in the system. This function does not cache. */ function panels_page_load_all($displays = TRUE, $page_size = 0) { $pages = $dids = array(); $query = "SELECT * FROM {panels_page}"; if ($page_size) { $result = pager_query($query, $page_size); } else { $result = db_query($query); } while ($page = db_fetch_object($result)) { $page->access = ($page->access ? explode(', ', $page->access) : array()); $page->type = t('Local'); $pages[$page->name] = $page; $dids[] = $page->did; } if ($displays && $dids) { $displays = panels_load_displays($dids); foreach ($pages as $name => $page) { if (!empty($displays[$page->did])) { $pages[$name]->display = $displays[$page->did]; } } } $status = variable_get('panel_page_defaults', array()); foreach (panels_page_default_panels() as $page) { // Determine if default panel is enabled or disabled. if (isset($status[$page->name])) { $page->disabled = $status[$page->name]; } if (!empty($pages[$page->name])) { $pages[$page->name]->type = t('Overridden'); } else { $page->type = t('Default'); $pages[$page->name] = $page; } } return $pages; } /** * Load a panel page and its associated display */ function panels_page_load($pid) { static $cache = array(); if (!array_key_exists($pid, $cache)) { if (!is_numeric($pid)) { $where = "name = '%s'"; } else { $where = 'pid = %d'; } $cache[$pid] = db_fetch_object(db_query("SELECT * FROM {panels_page} WHERE $where", $pid)); if (!$cache[$pid]) { $defaults = panels_page_default_panels(); if (isset($defaults[$pid])) { $cache[$pid] = $defaults[$pid]; return $cache[$pid]; } return; } $cache[$pid]->access = ($cache[$pid]->access ? explode(', ', $cache[$pid]->access) : array()); $cache[$pid]->display = panels_load_display($cache[$pid]->did); } return $cache[$pid]; } /** * A list of the fields used in the panel_page table. */ function panels_page_fields() { return array( "name" => "'%s'", "title" => "'%s'", "access" => "'%s'", "path" => "'%s'", "css_id" => "'%s'", "css" => "'%s'", "no_blocks" => "%d", "menu" => "%d", "menu_tab" => "%d", "menu_tab_weight" => "%d", "menu_title" => "'%s'", "menu_tab_default" => "%d", "menu_tab_default_parent_type" => "'%s'", "menu_parent_title" => "'%s'", "menu_parent_tab_weight" => "%d", ); } /** * Save a panel page. */ function panels_page_save($panel_page) { // Save the display. $display = panels_save_display($panel_page->display); // serialize the access string. $panel_page->access = implode(', ', $panel_page->access); // Create strings for our query from the list of fields. $fields = panels_page_fields(); foreach ($fields as $field => $value) { if (isset($panel_page->$field)) { $f[] = $field; $q[] = $value; $v[] = $panel_page->$field; } } if ($panel_page->pid && $panel_page->pid != 'new') { if (empty($panel_page->name)) { $panel_page->name = 'panel_page_' . $panel_page->pid; } $query = ''; foreach ($f as $id => $field) { if ($query) { $query .= ', '; } $query .= "$f[$id] = " . $q[$id]; } $v[] = $panel_page->pid; db_query("UPDATE {panels_page} SET $query WHERE pid = %d", $v); } else { $panel_page->pid = db_next_id("{panels_page}_pid"); // Tack our pid and did onto the query. These aren't listed as 'fields' because // they can't be updated; once set they are permanent. $v[] = $panel_page->pid; $v[] = $display->did; if (empty($panel_page->name)) { $panel_page->name = 'panel_page_' . $panel_page->pid; } // Yes, this is kind of long but it's a lot easier to match up values. db_query("INSERT INTO {panels_page} ( " . implode(', ', $f) . ", pid, did) VALUES (" . implode(', ', $q) . ", %d, %d)", $v); } menu_rebuild(); return $panel_page->pid; } /** * Delete a panel page and its associated display. */ function panels_page_delete($panel_page) { db_query("DELETE FROM {panels_page} WHERE pid = %d", $panel_page->pid); menu_rebuild(); return panels_delete_display($panel_page->did); } /** * Export a panel page into PHP code for use in import. The code returned from * can be used directly in panels_page_save(). */ function panels_page_export($panel_page) { $output = ''; $fields = panels_page_fields(); $output .= '$page = new stdClass()' . ";\n"; $output .= '$page->pid = \'new\'' . ";\n"; foreach ($fields as $field => $q) { $output .= ' $page->' . $field . ' = ' . var_export($panel_page->$field, TRUE) . ";\n"; } $output .= panels_export_display($panel_page->display); $output .= '$page->display = $display' . ";\n"; return $output; } /** * Get all 'default' panels. */ function panels_page_default_panels() { $panels = module_invoke_all('default_panel_pages'); if (!is_array($panels)) { $panels = array(); } return $panels; }