You may peruse a list of your current panels layouts and edit them, or click add to create a new page.
');
case 'admin/build/panels/add':
return t('
Choose a layout for your new page from the list below.
');
}
}
/**
* Implementation of hook_perm()
*/
function panels_perm() {
return array('create panels');
}
/**
* Implementation of hook_menu()
*/
function panels_menu($may_cache) {
if ($may_cache) {
$access = user_access('create panels');
$items[] = array(
'path' => 'admin/build/panels',
'title' => t('Panels'),
'access' => $access,
'callback' => 'panels_list_page',
'description' => t('Create pages on your site that are 2 or 3 columns'),
);
$items[] = array(
'path' => 'admin/build/panels/list',
'title' => t('List'),
'access' => $access,
'callback' => 'panels_list_page',
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[] = array(
'path' => 'admin/build/panels/add',
'title' => t('Add'),
'access' => $access,
'callback' => 'panels_add_page',
'type' => MENU_LOCAL_TASK,
);
$items[] = array(
'path' => 'admin/build/panels/add/layout',
'title' => t('Add'),
'access' => $access,
'callback' => 'panels_add_layout_page',
'type' => MENU_LOCAL_TASK,
);
$items[] = array(
'path' => 'admin/build/panels/edit',
'title' => t('Edit panels'),
'access' => $access,
'callback' => 'panels_edit_page',
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'admin/build/panels/delete',
'title' => t('Delete panels'),
'access' => $access,
'callback' => 'drupal_get_form',
'callback arguments' => array('panels_delete_confirm'),
'type' => MENU_CALLBACK,
);
$items[] = array(
'path' => 'panels/node/autocomplete',
'title' => t('Autocomplete node'),
'callback' => 'panels_node_autocomplete',
'access' => user_access('access content'),
'type' => MENU_CALLBACK
);
// load panels from database
$result = db_query("SELECT * FROM {panels_info}");
// FIXME: Fow now we're making these all callbacks, but we
// should steal code from Views so they can be normal, tabs,
// etc
while ($panels = db_fetch_object($result)) {
$items[] = array(
'path' => $panels->path,
'title' => $panels->title,
'access' => panels_access(unserialize($panels->access)),
'callback' => 'panels_panels_page',
'callback arguments' => array($panels->did),
'type' => MENU_CALLBACK
);
}
}
return $items;
}
/**
* Determine whether or not the current user has access to this
* panels.
*/
function panels_access($access) {
// for now
return TRUE;
}
/**
* panels path helper function
*/
function panels_get_file_path($module, $file, $base_path = true) {
if ($base_path) {
$output = base_path();
}
return $output . drupal_get_path('module', $module) . '/' . $file;
}
// ---------------------------------------------------------------------------
// panels custom image button
/**
* Custom form element to do our nice images.
*/
function panels_elements() {
$type['panels_imagebutton'] = array('#input' => TRUE, '#button_type' => 'submit',);
return $type;
}
/**
* Theme our image button.
*/
function theme_panels_imagebutton($element) {
return '\n";
}
function panels_imagebutton_value() {
// null function guarantees default_value doesn't get moved to #value.
}
/**
* Add a single button to a form.
*/
function panels_add_button($image, $name, $text) {
$module_path = base_path() . drupal_get_path('module', 'panels');
return array(
'#type' => 'panels_imagebutton',
'#image' => $module_path . '/images/' . $image,
'#title' => $text,
'#default_value' => $name,
);
}
/**
* Set a button to a blank image -- used for placeholders when buttons are
* not relevant but just removing it would be visually unappealing.
*/
function panels_set_blank(&$form) {
$form['#type'] = 'markup';
$form['#value'] = theme('image', drupal_get_path('module', 'panels') . '/images/blank.gif');
}
// ---------------------------------------------------------------------------
// panels administrative pages
/**
* Provide a list of panels, with links to edit or delete them.
*/
function panels_list_page() {
$result = db_query("SELECT * FROM {panels_info} ORDER BY title");
while ($panels = db_fetch_object($result)) {
$item = array();
$item[] = check_plain($panels->title);
$item[] = l($panels->path, $panels->path);
$item[] = implode(' | ', array(
l(t('Edit'), "admin/build/panels/edit/$panels->did"),
l(t('Delete'), "admin/build/panels/delete/$panels->did"),
));
$items[] = $item;
}
$header = array(
t('Panel title'),
t('URL'),
t('Operations'),
);
$output = theme('table', $header, $items);
return $output;
}
/*
* Provide a form to confirm deletion of a panel page.
*/
function panels_delete_confirm($did = '') {
$panels = panels_load_panels($did);
if (!$panels) {
drupal_goto('admin/build/panels');
}
$form['did'] = array('#type' => 'value', '#value' => $panels->did);
return confirm_form( $form,
t('Are you sure you want to delete %title?', array('%title' => $panels->title)),
$_GET['destination'] ? $_GET['destination'] : 'admin/build/panels',
t('This action cannot be undone.'),
t('Delete'), t('Cancel')
);
}
/*
* Handle the submit button to delete a panel page.
*/
function panels_delete_confirm_submit($formid, $form) {
if ($form['confirm']) {
panels_delete_panels((object) $form);
drupal_goto('admin/build/panels');
}
}
/**
* Handle the add panels page
*/
function panels_add_page($layout = NULL) {
$layouts = panels_get_layouts();
drupal_add_css(drupal_get_path('module', 'panels') . '/panels_admin.css');
if (!$layout) {
foreach ($layouts as $id => $layout) {
if (!$default_id) {
// grab the first one for our default.
$default_id = $id;
}
$file = panels_get_file_path($layout['module'], $layout['icon'], false);
$output .= theme('panels_add_image', $layout[title], $id, l(theme('image', $file), $_GET['q'] . '/' . $id, NULL, NULL, NULL, NULL, TRUE));
}
return $output;
}
if (!$layouts[$layout]) {
return drupal_not_found();
}
$panels->layout = $layout;
return drupal_get_form('panels_edit_form', $panels);
}
function theme_panels_add_image($title, $id, $image) {
$output .= '
';
$output .= $image;
$output .= '
' . l($title, $_GET['q'] . '/' . $id) . '
';
$output .= '
';
return $output;
}
// ---------------------------------------------------------------------------
// panels administrative pages
function panels_edit_page($did = NULL) {
if (!$did || !($panels = panels_load_panels($did))) {
return drupal_not_found();
}
return drupal_get_form('panels_edit_form', $panels);
}
/**
* shortcut to ease the syntax of the various form builder tricks we use.
*/
function panels_form_builder(&$form, $form_id = 'panels_edit_form') {
$form['#post'] = $_POST;
$form = form_builder($form_id, $form);
}
/**
* Edit an already loaded panels.
*/
function panels_edit_form($panels) {
drupal_add_css(drupal_get_path('module', 'panels') . '/panels_admin.css');
$layouts = panels_get_layouts();
$layout = $layouts[$panels->layout];
$content_types = panels_get_content_types();
// Process all our add button stuff first so we can add stuff to the
// form semi dynamically.
$form['add'] = array(
'#type' => 'fieldset',
'#title' => t('Add content'),
'#collapsible' => false,
'#description' => t('Select an area to add content to, then select a type of content and click the appropriate button. The content will be added.'),
);
$default_radio = array_shift(array_keys($layout['content areas']));
$form['add']['area'] = array(
'#type' => 'radios',
'#title' => t('Area'),
'#options' => $layout['content areas'],
'#prefix' => '