array('create mini panels'), 'file' => 'panels_mini.admin.inc', ); $items['admin/panels/panel-mini'] = array( 'title' => 'Mini panels', 'page callback' => 'panels_mini_list_page', 'description' => 'Create and administer mini panels (panels exposed as blocks).', ) + $base; $items['admin/panels/panel-mini/list'] = array( 'title' => 'List', 'page callback' => 'panels_mini_list_page', 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/add'] = array( 'title' => 'Add', 'page callback' => 'panels_mini_add_page', 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/import'] = array( 'title' => 'Import', 'page callback' => 'panels_mini_import_mini', 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/settings'] = array( 'title' => 'Settings', 'page callback' => 'panels_mini_settings', 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/disable'] = array( 'page callback' => 'panels_mini_disable_page', 'weight' => -1, 'type' => MENU_CALLBACK, ) + $base; $items['admin/panels/panel-mini/enable'] = array( 'page callback' => 'panels_mini_enable_page', 'weight' => -1, 'type' => MENU_CALLBACK, ) + $base; $base['access arguments'] = array('administer mini panels'); $items['admin/panels/panel-mini/%panels_mini_admin'] = array( 'title' => 'Preview', 'page callback' => 'panels_mini_preview_panel', 'page arguments' => array(3), 'weight' => -10, 'type' => MENU_CALLBACK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/preview'] = array( 'title' => 'Preview', 'page callback' => 'panels_mini_preview_panel', 'page arguments' => array(3), 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/edit-layout'] = array( 'title' => 'Layout', 'page callback' => 'panels_mini_edit_layout', 'page arguments' => array(3), 'weight' => -9, 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/edit-general'] = array( 'title' => 'Settings', 'page callback' => 'panels_mini_edit', 'page arguments' => array(3), 'weight' => -5, 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/edit-settings'] = array( 'title' => 'Layout settings', 'page callback' => 'panels_mini_edit_layout_settings', 'page arguments' => array(3), 'weight' => -3, 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/edit-context'] = array( 'title' => 'Context', 'page callback' => 'panels_mini_edit_context', 'page arguments' => array(3), 'weight' => -2, 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/edit-content'] = array( 'title' => 'Content', 'page callback' => 'panels_mini_edit_content', 'page arguments' => array(3), 'weight' => -1, 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/export'] = array( 'title' => 'Export', 'page callback' => 'drupal_get_form', 'page arguments' => array('panels_mini_edit_export', 3), 'weight' => 0, 'type' => MENU_LOCAL_TASK, ) + $base; $items['admin/panels/panel-mini/%panels_mini_admin/delete'] = array( 'title' => 'Delete mini panel', 'page callback' => 'drupal_get_form', 'page arguments' => array('panels_mini_delete_confirm', 3), 'type' => MENU_CALLBACK, ) + $base; return $items; } /** * Settings for mini panels. */ function panels_mini_settings() { return ('TODO'); panels_load_include('common'); return drupal_get_form('panels_common_settings', 'panels_mini'); } /** * Provide a list of mini panels, with links to edit or delete them. */ function panels_mini_list_page() { panels_load_include('plugins'); $layouts = panels_get_layouts(); $items = array(); $sorts = array(); $header = array( array('data' => t('Title'), 'field' => 'title'), array('data' => t('Name'), 'field' => 'name', 'sort' => 'asc'), array('data' => t('Type'), 'field' => 'type'), t('Layout'), t('Operations'), ); // Load all mini panels and their displays. $panel_minis = panels_mini_load_all(); $dids = array(); foreach ($panel_minis as $panel_mini) { if (empty($panel_mini->display)) { $dids[] = $panel_mini->did; } } $displays = panels_load_displays($dids); if (empty($displays)) { return t('There are currently no mini panels.'); } foreach ($panel_minis as $panel_mini) { $ops = array(); if (empty($panel_mini->disabled)) { $ops[] = l(t('Edit'), "admin/panels/panel-mini/$panel_mini->name/edit-general"); $ops[] = l(t('Export'), "admin/panels/panel-mini/$panel_mini->name/export"); } if ($panel_mini->type != t('Default')) { $text = ($panel_mini->type == t('Overridden')) ? t('Revert') : t('Delete'); $ops[] = l($text, "admin/panels/panel-mini/$panel_mini->name/delete"); } else { if (empty($panel_mini->disabled)) { $ops[] = l(t('Disable'), "admin/panels/panel-mini/disable/$panel_mini->name", array('query' => drupal_get_destination())); } else { $ops[] = l(t('Enable'), "admin/panels/panel-mini/enable/$panel_mini->name", array('query' => drupal_get_destination())); } } $item = array(); $item[] = check_plain($panel_mini->title); $item[] = check_plain($panel_mini->name); // this is safe as it's always programmatic $item[] = $panel_mini->type; if (empty($panel_mini->display)) { $panel_mini->display = $displays[$panel_mini->did]; } $item[] = check_plain($layouts[$panel_mini->display->layout]['title']); $item[] = implode(' | ', $ops); $items[] = $item; $ts = tablesort_init($header); switch ($ts['sql']) { case 'title': $sorts[] = $item[0]; break; case 'name': default: $sorts[] = $item[1]; break; case 'type': $sorts[] = $panel_mini->type . $item[0]; break; } } if (drupal_strtolower($ts['sort']) == 'desc') { arsort($sorts); } else { asort($sorts); } $i = array(); foreach ($sorts as $id => $title) { $i[] = $items[$id]; } $output = theme('table', $header, $i); return $output; } /** * Provide a form to confirm deletion of a mini panel. */ function panels_mini_delete_confirm(&$form_state, $panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } $form['pid'] = array('#type' => 'value', '#value' => $panel_mini->pid); $form['did'] = array('#type' => 'value', '#value' => $panel_mini->did); return confirm_form($form, t('Are you sure you want to delete the mini panel "@title"?', array('@title' => $panel_mini->title)), $_GET['destination'] ? $_GET['destination'] : 'admin/panels/panel-mini', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } /** * Handle the submit button to delete a mini panel. */ function panels_mini_delete_confirm_submit($form, &$form_state) { panels_mini_delete((object) $form_state['values']); $form_state['redirect'] = 'admin/panels/panel-mini'; } /** * Provide an administrative preview of a mini panel. */ function panels_mini_preview_panel($mini) { $mini->display->args = array(); $mini->display->css_id = panels_mini_get_id($mini->name); panels_load_include('plugins'); $mini->context = $mini->display->context = panels_context_load_contexts($mini); drupal_set_title(filter_xss_admin($mini->title)); return panels_render_display($mini->display); } /** * Page callback to export a mini panel to PHP code. */ function panels_mini_edit_export(&$form_state, $panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } drupal_set_title(check_plain($panel_mini->title)); $code = panels_mini_export($panel_mini); $lines = substr_count($code, "\n"); $form['code'] = array( '#type' => 'textarea', '#title' => $panel_mini->title, '#default_value' => $code, '#rows' => $lines, ); return $form; } /** * Page callback to import a mini panel from PHP code. */ function panels_mini_import_mini() { if ($_POST['form_id'] == 'panels_mini_edit_form') { $panel_mini = unserialize($_SESSION['pm_import']); drupal_set_title(t('Import panel mini "@s"', array('@s' => $panel_mini->title))); return drupal_get_form('panels_mini_edit_form', $panel_mini); } return drupal_get_form('panels_mini_import_form'); } /** * Form for the mini panel import. */ function panels_mini_import_form() { $form['panel_mini'] = array( '#type' => 'textarea', '#title' => t('Panel mini code'), '#cols' => 60, '#rows' => 15, '#description' => t('Cut and paste the results of an exported mini panel here.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Import'), ); $form['#redirect'] = NULL; return $form; } /** * Handle the submit button on importing a mini panel. */ function panels_mini_import_form_submit($form, &$form_state) { ob_start(); eval($form_state['values']['panel_mini']); ob_end_clean(); if (isset($mini)) { drupal_set_title(t('Import mini panel "@s"', array('@s' => $mini->title))); // As $mini contains non-stdClass objects, // it needs to be serialized before being stored in the session variable. $_SESSION['pm_import'] = serialize($mini); $output = drupal_get_form('panels_mini_edit_form', $mini); print theme('page', $output); exit; } else { drupal_set_message(t('Unable to get a mini panel out of that.')); } } /** * Handle the add mini panel page. */ function panels_mini_add_page($layout = NULL) { panels_load_include('plugins'); $layouts = panels_get_layouts(); $output = ''; 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_mini = new stdClass(); $panel_mini->display = panels_new_display(); $panel_mini->display->layout = $layout; $panel_mini->pid = 'new'; $panel_mini->did = 'new'; $panel_mini->title = ''; $panel_mini->name = ''; $panel_mini->category = ''; drupal_set_title(t('Add mini panel')); return panels_mini_edit($panel_mini); } /** * Edit a mini panel. * * Called from both the add and edit points to provide for common flow. */ function panels_mini_edit($panel_mini) { if (!is_object($panel_mini)) { $panel_mini = panels_mini_load($panel_mini); } if ($panel_mini) { drupal_set_title(check_plain($panel_mini->title)); } return drupal_get_form('panels_mini_edit_form', $panel_mini); } /** * Form to edit the settings of a mini panel. */ function panels_mini_edit_form(&$form_state, $panel_mini) { panels_load_include('common'); drupal_add_css(panels_get_path('css/panels_admin.css')); $form['pid'] = array( '#type' => 'value', '#value' => $panel_mini->pid, ); $form['panel_mini'] = array( '#type' => 'value', '#value' => $panel_mini, ); $form['right'] = array( '#prefix' => '