View source
<?php
define('EMPTY_PAGE_PERM_ADMIN_CALLBACKS', 'administer empty page callbacks');
function empty_page_permission() {
$permissions = array(
EMPTY_PAGE_PERM_ADMIN_CALLBACKS => array(
'title' => 'Administer Empty Page callbacks',
'description' => 'Perform management tasks for Empty Page callbacks.',
),
);
return $permissions;
}
function empty_page_menu() {
$items = array();
$items['admin/structure/empty-page'] = array(
'title' => 'Empty Page callbacks',
'description' => 'Manage Empty Page menu callbacks.',
'page callback' => 'empty_page_admin_overview',
'access arguments' => array(
EMPTY_PAGE_PERM_ADMIN_CALLBACKS,
),
'file' => 'empty_page.admin.inc',
);
$items['admin/structure/empty-page/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/empty-page/add'] = array(
'title' => 'Add Callback',
'description' => 'Create an empty page.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'empty_page_callbacks_form',
),
'access arguments' => array(
EMPTY_PAGE_PERM_ADMIN_CALLBACKS,
),
'type' => MENU_LOCAL_ACTION,
'file' => 'empty_page.admin.inc',
'weight' => 1,
);
$items['admin/structure/empty-page/%/edit'] = array(
'title' => 'Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'empty_page_callbacks_form',
3,
),
'access arguments' => array(
EMPTY_PAGE_PERM_ADMIN_CALLBACKS,
),
'type' => MENU_CALLBACK,
'file' => 'empty_page.admin.inc',
);
$items['admin/structure/empty-page/%/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'empty_page_admin_delete_form',
3,
),
'access arguments' => array(
EMPTY_PAGE_PERM_ADMIN_CALLBACKS,
),
'type' => MENU_CALLBACK,
'file' => 'empty_page.admin.inc',
);
foreach (empty_page_get_callbacks() as $cid => $callback) {
$items[$callback->path] = array(
'title' => t($callback->page_title),
'page callback' => 'empty_page_empty',
'access callback' => TRUE,
'type' => MENU_SUGGESTED_ITEM,
);
}
return $items;
}
function empty_page_theme(&$existing, $type, $theme, $path) {
$hooks = array();
$hooks['empty_page_callbacks_manage_render'] = array(
'file' => 'empty_page.admin.inc',
);
return $hooks;
}
function empty_page_empty() {
return ' ';
}
function empty_page_get_callbacks() {
$callbacks = array();
$results = db_select('empty_page')
->fields('empty_page', array(
'cid',
'path',
'page_title',
'data',
'changed',
'created',
))
->orderBy('changed', 'DESC')
->execute();
foreach ($results as $callback) {
$callbacks[$callback->cid] = $callback;
}
return $callbacks;
}
function empty_page_get_callback($cid) {
$callback = db_select('empty_page')
->fields('empty_page', array(
'cid',
'path',
'page_title',
'data',
'changed',
'created',
))
->condition('cid', $cid)
->execute()
->fetchObject();
return $callback;
}
function empty_page_save_callback($callback) {
if (property_exists($callback, 'cid')) {
db_update('empty_page')
->fields(array(
'path' => $callback->path,
'page_title' => $callback->page_title,
'changed' => REQUEST_TIME,
))
->condition('cid', $callback->cid)
->execute();
$ret = $callback->cid;
}
else {
$id = db_insert('empty_page')
->fields(array(
'path' => $callback->path,
'page_title' => $callback->page_title,
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
))
->execute();
$ret = $id;
}
return $ret;
}
function empty_page_delete_callback($cid) {
if (is_numeric($cid)) {
db_delete('empty_page')
->condition('cid', $cid)
->execute();
}
}
function empty_page_clear_menu_cache() {
menu_rebuild();
}