summaryrefslogtreecommitdiff
path: root/modules/block.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/block.module')
-rw-r--r--modules/block.module314
1 files changed, 169 insertions, 145 deletions
diff --git a/modules/block.module b/modules/block.module
index a2f79c0e7..047e3bf64 100644
--- a/modules/block.module
+++ b/modules/block.module
@@ -1,12 +1,13 @@
<?php
// $Id$
-function block_help($section = "admin/help#block") {
- $output = "";
-
+/**
+ * Implementation of hook_help().
+ */
+function block_help($section) {
switch ($section) {
case 'admin/help#block':
- $output = t("
+ return t("
<p>Blocks are the boxes visible in the sidebar(s) of your web site. These are usually generated automatically by modules (e.g. recent forum topics), but you can also create your own blocks using either static HTML or dynamic PHP content.</p>
<p>The sidebar each block appears in depends on both which theme you're using (some are left-only, some right, some both), and on the settings in block management.</p><p>Whether a block is visible in the first place depends on four things:</p><ul><li>It must have its \"enabled\" box checked in block management.</li><li>If it has its \"custom\" box checked in block management, the user must have chosen to display it in their user preferences.</li><li>If the \"path\" field in block management is set, the visitor must be on a page that matches the path specification (more on this later).</li><li>If the block has its throttle box checked, the user will only see the block if the site throttle level is low.</li></ul>
<p>The block management screen also lets you specify the vertical sort-order of the blocks within a sidebar. You do this by assigning a <strong>weight</strong> to each block. Lighter blocks (smaller weight) \"float up\" towards the top of the sidebar. Heavier ones \"sink down\" towards the bottom of it. Once you've positioned things just so, you can preview what the layout will look like in different types of themes by clicking the preview placement link in the menu to the left.</p>
@@ -34,31 +35,30 @@ function block_help($section = "admin/help#block") {
return t(\"Welcome visitor, ... welcome message goes here ...\");
}
</pre></blockquote>
-<p>For more in-depth examples, we recommend that you check the existing boxes and use them as a starting point.</p>", array("%pcre" => "http://php.net/pcre/"));
- break;
+<p>For more in-depth examples, we recommend that you check the existing boxes and use them as a starting point.</p>", array('%pcre' => 'http://php.net/pcre/'));
case 'admin/system/modules#description':
- $output = t("Controls the boxes that are displayed around the main content.");
- break;
+ return t('Controls the boxes that are displayed around the main content.');
case 'admin/system/block':
- $output = t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the choosen theme. They are created by <strong>active</strong> Drupal modules. The 'enabled' checkbox sets the default status of the block. Only enabled blocks are shown. When the 'custom' checkbox is checked, your users can show or hide the block using their account settings. In that case, the 'enabled' checkbox signifies the block's default status. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the <a href=\"%createblock\">new block</a> link in the menu to the left. Edit and delete links will become active below for these admin-defined blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking throttle. The auto-throttle functionality must be enabled on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.", array("%createblock" => url("admin/system/block/add"), "%throttle" => url("admin/system/modules/throttle")));
- break;
+ return t("Blocks are the boxes in the left- and right- side bars of the web site, depending on the chosen theme. They are created by <strong>active</strong> Drupal modules. The \"enabled\" checkbox sets the default status of the block. Only enabled blocks are shown. When the \"custom\" checkbox is checked, your users can show or hide the block using their account settings. In that case, the 'enabled' checkbox signifies the block's default status. You can assign the block's placement by giving it a region and a weight. The region specifies which side of the page the block is on, and the weight sorts blocks within a region. Lighter (smaller weight value) blocks \"float up\" towards the top of the page. The path setting lets you define which pages you want a block to be shown on. You can also create your own blocks, where you specify the content of the block rather than its being generated by a module (you can even use PHP in these). You can create one of these by clicking the <a href=\"%createblock\">new block</a> link in the menu to the left. Edit and delete links will become active below for these admin-defined blocks. Blocks can automatically be temporarily disabled to reduce server load when your site becomes extremely busy by checking throttle. The auto-throttle functionality must be enabled on the <a href=\"%throttle\">throttle configuration page</a> after having enabled the throttle module.", array('%createblock' => url('admin/system/block/add'), '%throttle' => url('admin/system/modules/throttle')));
case 'admin/system/block/add':
- $output = t("Here you can create a new block. Once you have created this block you must make it active, and give it a place on the page using <a href=\"%overview\">blocks</a>. The title is used when displaying the block. The description is used in the \"block\" column on the <a href=\"%overview\">blocks</a> page. If you are going to place PHP code in the block, and you have <strong>create php content</strong> permission (see the <a href=\"%permission\">permissions</a> page) you <strong>must</strong> change the type to PHP to make your code active.", array("%overview" => url("admin/system/block"), "%permission" => url("admin/user/permission")));
- break;
+ return t("Here you can create a new block. Once you have created this block you must make it active and give it a place on the page using <a href=\"%overview\">blocks</a>. The title is used when displaying the block. The description is used in the \"block\" column on the <a href=\"%overview\">blocks</a> page. If you are going to place PHP code in the block, and you have the <strong>create php content</strong> permission (see the <a href=\"%permission\">permissions</a> page), you <strong>must</strong> change the type to PHP to make your code active.", array('%overview' => url('admin/system/block'), '%permission' => url('admin/user/permission')));
case 'admin/system/block/preview':
- $output = t("This page show you the placement of your blocks in different themes types. The numbers are the weight of each block, which is used to sort them within the sidebars.");
- break;
+ return t('This page shows you the placement of your blocks in different theme types. The numbers are the weights of each block, which are used to sort them within the sidebars.');
}
-
- return $output;
}
+/**
+ * Menu callback. Presents the block-specific information from admin/help.
+ */
function block_help_page() {
- print theme("page", block_help());
+ print theme('page', block_help('admin/help#block'));
}
+/**
+ * Implementation of hook_perm().
+ */
function block_perm() {
- return array("administer blocks");
+ return array('administer blocks');
}
/**
@@ -67,24 +67,31 @@ function block_perm() {
function block_link($type) {
if ($type == 'system') {
menu('admin/system/block', t('blocks'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3);
- menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 2);
- menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin' : MENU_DENIED, 3);
+ menu('admin/system/block/add', t('new block'), user_access('administer blocks') ? 'block_box_edit' : MENU_DENIED, 2);
+ menu('admin/system/block/edit', t('edit block'), user_access('administer blocks') ? 'block_box_edit' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
+ menu('admin/system/block/delete', t('delete block'), user_access('administer blocks') ? 'block_box_delete' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED);
+ menu('admin/system/block/preview', t('preview placement'), user_access('administer blocks') ? 'block_admin_preview' : MENU_DENIED, 3);
menu('admin/system/block/help', t('help'), user_access('administer blocks') ? 'block_help_page' : MENU_DENIED, 9);
}
}
-function block_block($op = "list", $delta = 0) {
- if ($op == "list") {
- $result = db_query("SELECT bid, title, info FROM {boxes} ORDER BY title");
+/**
+ * Implementation of hook_block().
+ *
+ * Generates the administrator-defined blocks for display.
+ */
+function block_block($op = 'list', $delta = 0) {
+ if ($op == 'list') {
+ $result = db_query('SELECT bid, title, info FROM {boxes} ORDER BY title');
while ($block = db_fetch_object($result)) {
- $blocks[$block->bid]["info"] = $block->info;
+ $blocks[$block->bid]['info'] = $block->info;
}
return $blocks;
}
else {
- $block = db_fetch_object(db_query("SELECT * FROM {boxes} WHERE bid = %d", $delta));
- $data["subject"] = $block->title;
- $data["content"] = ($block->type == 1) ? eval($block->body) : $block->body;
+ $block = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid = %d', $delta));
+ $data['subject'] = $block->title;
+ $data['content'] = ($block->type == 1) ? eval($block->body) : $block->body;
return $data;
}
}
@@ -93,52 +100,53 @@ function block_admin_save($edit) {
foreach ($edit as $module => $blocks) {
foreach ($blocks as $delta => $block) {
db_query("UPDATE {blocks} SET region = %d, status = %d, custom = %d, path = '%s', weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s'",
- $block["region"], $block["status"], $block["custom"], $block["path"], $block["weight"], $block["throttle"], $module, $delta);
+ $block['region'], $block['status'], $block['custom'], $block['path'], $block['weight'], $block['throttle'], $module, $delta);
}
}
- return t("the block settings have been updated.");
+ return t('the block settings have been updated.');
}
/**
- * update blocks db table with blocks currently exported by modules
+ * Update the 'blocks' DB table with the blocks currently exported by modules.
*
* @param $order_by php <a
* href="http://www.php.net/manual/en/function.array-multisort.php">array_multisort()</a>
* style sort ordering, eg. "weight", SORT_ASC, SORT_STRING.
*
- * @return blocks currently exported by modules, sorted by $order_by
+ * @return
+ * Blocks currently exported by modules, sorted by $order_by.
*/
-function _block_rehash($order_by = array("weight")) {
- $result = db_query("SELECT * FROM {blocks} ");
+function _block_rehash($order_by = array('weight')) {
+ $result = db_query('SELECT * FROM {blocks} ');
while ($old_block = db_fetch_object($result)) {
$old_blocks[$old_block->module][$old_block->delta] = $old_block;
}
- db_query("DELETE FROM {blocks} ");
+ db_query('DELETE FROM {blocks} ');
foreach (module_list() as $module) {
- $module_blocks = module_invoke($module, "block", "list");
+ $module_blocks = module_invoke($module, 'block', 'list');
if ($module_blocks) {
foreach ($module_blocks as $delta => $block) {
- $block["module"] = $module;
- $block["delta"] = $delta;
+ $block['module'] = $module;
+ $block['delta'] = $delta;
if ($old_blocks[$module][$delta]) {
- $block["status"] = $old_blocks[$module][$delta]->status;
- $block["weight"] = $old_blocks[$module][$delta]->weight;
- $block["region"] = $old_blocks[$module][$delta]->region;
- $block["path"] = $old_blocks[$module][$delta]->path;
- $block["custom"] = $old_blocks[$module][$delta]->custom;
- $block["throttle"] = $old_blocks[$module][$delta]->throttle;
+ $block['status'] = $old_blocks[$module][$delta]->status;
+ $block['weight'] = $old_blocks[$module][$delta]->weight;
+ $block['region'] = $old_blocks[$module][$delta]->region;
+ $block['path'] = $old_blocks[$module][$delta]->path;
+ $block['custom'] = $old_blocks[$module][$delta]->custom;
+ $block['throttle'] = $old_blocks[$module][$delta]->throttle;
}
else {
- $block["status"] = $block["weight"] = $block["region"] = $block["custom"] = 0;
- $block["path"] = "";
+ $block['status'] = $block['weight'] = $block['region'] = $block['custom'] = 0;
+ $block['path'] = '';
}
// reinsert blocks into table
db_query("INSERT INTO {blocks} (module, delta, status, weight, region, path, custom, throttle) VALUES ('%s', '%s', %d, %d, %d, '%s', %d, %d)",
- $block["module"], $block["delta"], $block["status"], $block["weight"], $block["region"], $block["path"], $block["custom"], $block["throttle"]);
+ $block['module'], $block['delta'], $block['status'], $block['weight'], $block['region'], $block['path'], $block['custom'], $block['throttle']);
$blocks[] = $block;
@@ -154,177 +162,193 @@ function _block_rehash($order_by = array("weight")) {
return $blocks;
}
+/**
+ * Prepare the main block administration form.
+ */
function block_admin_display() {
$blocks = _block_rehash();
- $header = array(t("block"), t("enabled"), t("custom"), t("throttle"), t("weight"), t("region"), t("path"), array("data" => t("operations"), "colspan" => 2));
+ $header = array(t('block'), t('enabled'), t('custom'), t('throttle'), t('weight'), t('region'), t('path'), array('data' => t('operations'), 'colspan' => 2));
foreach ($blocks as $block) {
- if ($block["module"] == "block") {
- $edit = l(t("edit"), "admin/system/block/edit/". $block["delta"]);
- $delete = l(t("delete"), "admin/system/block/delete/". $block["delta"]);
+ if ($block['module'] == 'block') {
+ $edit = l(t('edit'), 'admin/system/block/edit/'. $block['delta']);
+ $delete = l(t('delete'), 'admin/system/block/delete/'. $block['delta']);
}
else {
- $edit = "";
- $delete = "";
+ $edit = '';
+ $delete = '';
}
- $rows[] = array($block["info"], array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][status", 1, $block["status"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][custom", 1, $block["custom"]), "align" => "center"), array("data" => form_checkbox(NULL, $block["module"] ."][". $block["delta"] ."][throttle", 1, $block["throttle"], NULL, module_exist('throttle') ? NULL : array("disabled" => "disabled")), "align" => "center"), form_weight(NULL, $block["module"] ."][". $block["delta"] ."][weight", $block["weight"]), form_radios(NULL, $block["module"] ."][". $block["delta"] ."][region", $block["region"], array(t("left"), t("right"))), form_textfield(NULL, $block["module"] ."][". $block["delta"] ."][path", $block["path"], 10, 255),
+ $rows[] = array($block['info'], array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][status', 1, $block['status']), 'align' => 'center'), array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][custom', 1, $block['custom']), 'align' => 'center'), array('data' => form_checkbox(NULL, $block['module'] .']['. $block['delta'] .'][throttle', 1, $block['throttle'], NULL, module_exist('throttle') ? NULL : array('disabled' => 'disabled')), 'align' => 'center'), form_weight(NULL, $block['module'] .']['. $block['delta'] .'][weight', $block['weight']), form_radios(NULL, $block['module'] .']['. $block['delta'] .'][region', $block['region'], array(t('left'), t('right'))), form_textfield(NULL, $block['module'] .']['. $block['delta'] .'][path', $block['path'], 10, 255),
$edit, $delete);
}
- $output = theme("table", $header, $rows);
- $output .= form_submit(t("Save blocks"));
+ $output = theme('table', $header, $rows);
+ $output .= form_submit(t('Save blocks'));
- return form($output);
+ return form($output, 'post', url('admin/system/block'));
}
+/**
+ * Menu callback. Displays the block layout as it will appear when themed.
+ */
function block_admin_preview() {
-
- $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight");
+ $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 0 ORDER BY weight');
$lblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) {
- $block_data = module_invoke($block->module, "block", "list");
- $name = $block_data[$block->delta]["info"];
- $lblocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n";
+ $block_data = module_invoke($block->module, 'block', 'list');
+ $name = $block_data[$block->delta]['info'];
+ $lblocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n";
}
$lblocks .= "</table>\n";
- $result = db_query("SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight");
+ $result = db_query('SELECT * FROM {blocks} WHERE status > 0 AND region = 1 ORDER BY weight');
$rblocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) {
- $block_data = module_invoke($block->module, "block", "list");
- $name = $block_data[$block->delta]["info"];
- $rblocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n";
+ $block_data = module_invoke($block->module, 'block', 'list');
+ $name = $block_data[$block->delta]['info'];
+ $rblocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n";
}
$rblocks .= "</table>\n";
- $output .= "<h3>". t("Themes with both left and right sidebars") .":</h3>\n";
+ $output .= '<h3>'. t('Themes with both left and right sidebars') .":</h3>\n";
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
- $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("header") ."</td></tr>\n";
- $output .= " <tr><td>\n". ($lblocks ? $lblocks : "&nbsp;") ."</td><td style=\"width: 300px;\">&nbsp;</td><td>\n". ($rblocks ? $rblocks : "&nbsp;") ."</td></tr>\n";
- $output .= " <tr><td colspan=\"3\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n";
+ $output .= ' <tr><td colspan="3" style="text-align: center;">'. t('header') ."</td></tr>\n";
+ $output .= " <tr><td>\n". ($lblocks ? $lblocks : '&nbsp;') ."</td><td style=\"width: 300px;\">&nbsp;</td><td>\n". ($rblocks ? $rblocks : '&nbsp;') ."</td></tr>\n";
+ $output .= ' <tr><td colspan="3" style="text-align: center;">'. t('footer') ."</td></tr>\n";
$output .= "</table>\n";
- $result = db_query("SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight");
+ $result = db_query('SELECT * FROM {blocks} WHERE status > 0 ORDER BY weight');
$blocks .= "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n";
while ($block = db_fetch_object($result)) {
- $block_data = module_invoke($block->module, "block", "list");
- $name = $block_data[$block->delta]["info"];
- $blocks .= " <tr><td>". ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n";
+ $block_data = module_invoke($block->module, 'block', 'list');
+ $name = $block_data[$block->delta]['info'];
+ $blocks .= ' <tr><td>'. ($block->status == 2 ? "<strong>$name</strong>" : $name) ."</td><td>$block->weight</td></tr>\n";
}
$blocks .= "</table>\n";
- $output .= "<h3>". t("Themes with right-sidebar only") .":</h3>\n";
+ $output .= '<h3>'. t('Themes with right sidebar only') .":</h3>\n";
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
- $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("header") ."</td></tr>\n";
- $output .= " <tr><td style=\"width: 400px;\">&nbsp;</td><td>\n". ($blocks ? $blocks : "&nbsp;") ."</td></tr>\n";
- $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n";
+ $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('header') ."</td></tr>\n";
+ $output .= " <tr><td style=\"width: 400px;\">&nbsp;</td><td>\n". ($blocks ? $blocks : '&nbsp;') ."</td></tr>\n";
+ $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('footer') ."</td></tr>\n";
$output .= "</table>\n";
- $output .= "<h3>". t("Themes with left-sidebar only") .":</h3>\n";
+ $output .= '<h3>'. t('Themes with left sidebar only') .":</h3>\n";
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
- $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("header") ."</td></tr>\n";
- $output .= " <tr><td>\n". ($blocks ? $blocks : "&nbsp;") ."</td><td style=\"width: 400px;\">&nbsp;</td></tr>\n";
- $output .= " <tr><td colspan=\"2\" style=\"text-align: center;\">". t("footer") ."</td></tr>\n";
+ $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('header') ."</td></tr>\n";
+ $output .= " <tr><td>\n". ($blocks ? $blocks : '&nbsp;') ."</td><td style=\"width: 400px;\">&nbsp;</td></tr>\n";
+ $output .= ' <tr><td colspan="2" style="text-align: center;">'. t('footer') ."</td></tr>\n";
$output .= "</table>\n";
- return $output;
+ print theme('page', $output);
}
function block_box_get($bid) {
- return db_fetch_array(db_query("SELECT * FROM {boxes} WHERE bid = %d", $bid));
+ return db_fetch_array(db_query('SELECT * FROM {boxes} WHERE bid = %d', $bid));
+}
+
+/**
+ * Menu callback. Displays the block editing form, or saves changes and
+ * displays the block overview.
+ */
+function block_box_edit($bid = 0) {
+ $edit = $_POST['edit'];
+ $op = $_POST['op'];
+
+ if ($op == t('Save block')) {
+ drupal_set_message(block_box_save($edit));
+ cache_clear_all();
+ $output = block_admin_display();
+ }
+ else {
+ if ($bid) {
+ $output = block_box_form(block_box_get($bid));
+ }
+ else {
+ $output = block_box_form();
+ }
+ }
+
+ print theme('page', $output);
}
function block_box_form($edit = array()) {
- $type = array(0 => "HTML", 1 => "PHP");
+ $type = array(0 => 'HTML', 1 => 'PHP');
- $form = form_textfield(t("Title"), "title", $edit["title"], 50, 64);
- $form .= form_textfield(t("Description"), "info", $edit["info"], 50, 64);
- $form .= form_textarea(t("Body"), "body", $edit["body"], 70, 10);
- if (user_access("create php content")) {
- $form .= form_select(t("Type"), "type", $edit["type"], $type);
+ $form = form_textfield(t('Title'), 'title', $edit['title'], 50, 64);
+ $form .= form_textfield(t('Description'), 'info', $edit['info'], 50, 64);
+ $form .= form_textarea(t('Body'), 'body', $edit['body'], 70, 10);
+ if (user_access('create php content')) {
+ $form .= form_select(t('Type'), 'type', $edit['type'], $type);
}
- if ($edit["bid"]) {
- $form .= form_hidden("bid", $edit["bid"]);
+ if ($edit['bid']) {
+ $form .= form_hidden('bid', $edit['bid']);
}
- $form .= form_submit(t("Save block"));
+ $form .= form_submit(t('Save block'));
return form($form);
}
function block_box_save($edit) {
- if (!user_access("create php content")) {
- $edit["type"] = 0;
+ if (!user_access('create php content')) {
+ $edit['type'] = 0;
}
- if ($edit["bid"]) {
- db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit["title"], $edit["body"], $edit["info"], $edit["type"], $edit["bid"]);
- return t("the block has been updated.");
+ if ($edit['bid']) {
+ db_query("UPDATE {boxes} SET title = '%s', body = '%s', info = '%s', type = %d WHERE bid = %d", $edit['title'], $edit['body'], $edit['info'], $edit['type'], $edit['bid']);
+ return t('the block has been updated.');
}
else {
- db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit["title"], $edit["body"], $edit["info"], $edit["type"]);
- return t("the new block has been added.");
+ db_query("INSERT INTO {boxes} (title, body, info, type) VALUES ('%s', '%s', '%s', %d)", $edit['title'], $edit['body'], $edit['info'], $edit['type']);
+ return t('the new block has been added.');
}
}
-function block_box_delete($bid) {
+/**
+ * Menu callback. Deletes a custom box, then displays the overview page.
+ */
+function block_box_delete($bid = 0) {
if ($bid) {
- db_query("DELETE FROM {boxes} WHERE bid = %d", $bid);
- return t("the block has been deleted.");
+ db_query('DELETE FROM {boxes} WHERE bid = %d', $bid);
+ drupal_set_message(t('the block has been deleted.'));
+ cache_clear_all();
}
+ print theme('page', block_admin_display());
}
+/**
+ * Menu callback. Displays the block overview page.
+ */
function block_admin() {
- $op = $_POST["op"];
- $edit = $_POST["edit"];
+ $edit = $_POST['edit'];
+ $op = $_POST['op'];
- if (empty($op)) {
- $op = arg(3);
+ if ($op == t('Save blocks')) {
+ drupal_set_message(block_admin_save($edit));
+ cache_clear_all();
}
-
- switch ($op) {
- case "preview":
- $output = block_admin_preview();
- break;
- case "add":
- $output = block_box_form();
- break;
- case "edit":
- $output = block_box_form(block_box_get(arg(4)));
- break;
- case "delete":
- drupal_set_message(block_box_delete(arg(4)));
- cache_clear_all();
- $output .= block_admin_display();
- break;
- case t("Save block"):
- drupal_set_message(block_box_save($edit));
- cache_clear_all();
- $output .= block_admin_display();
- break;
- case t("Save blocks"):
- drupal_set_message(block_admin_save($edit));
- cache_clear_all();
- // fall through
- default:
- $output .= block_admin_display();
- }
-
- print theme("page", $output);
+ print theme('page', block_admin_display());
}
+/**
+ * Implementation of hook_user().
+ *
+ * Allow users to decide which custom blocks to display when they visit
+ * the site.
+ */
function block_user($type, $edit, &$user) {
switch ($type) {
- case "edit":
- $result = db_query("SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta", 1);
+ case 'edit':
+ $result = db_query('SELECT * FROM {blocks} WHERE custom = %d ORDER BY module, delta', 1);
while ($block = db_fetch_object($result)) {
- $data = module_invoke($block->module, "block", "list");
- if ($data[$block->delta]["info"]) {
+ $data = module_invoke($block->module, 'block', 'list');
+ if ($data[$block->delta]['info']) {
$form .= form_checkbox($data[$block->delta]['info'], "block][$block->module][$block->delta", 1, isset($user->block[$block->module][$block->delta]) ? $user->block[$block->module][$block->delta] : $block->status);
}
}
@@ -334,9 +358,9 @@ function block_user($type, $edit, &$user) {
}
break;
- case "validate":
- if (!$edit["block"]) {
- $edit["block"] = array();
+ case 'validate':
+ if (!$edit['block']) {
+ $edit['block'] = array();
}
return $edit;
}
@@ -361,7 +385,7 @@ function block_list($region) {
if (!isset($blocks[$region])) {
$blocks[$region] = array();
- $result = db_query("SELECT * FROM {blocks} WHERE (status = '1' OR custom = '1') ". ($region != "all" ? "AND region = %d " : "") ."ORDER BY weight, module", $region == "left" ? 0 : 1);
+ $result = db_query('SELECT * FROM {blocks} WHERE (status = 1 OR custom = 1) '. ($region != 'all' ? 'AND region = %d ' : '') .'ORDER BY weight, module', $region == 'left' ? 0 : 1);
while ($result && ($block = db_fetch_array($result))) {
// When the user's account setting is empty, we use the block's regular 'status' (which is the default)
@@ -374,7 +398,7 @@ function block_list($region) {
** Check the current throttle status and see if block should be displayed
** based on server load.
*/
- if (!($block['throttle'] && (module_invoke("throttle", "status") > 4))) {
+ if (!($block['throttle'] && (module_invoke('throttle', 'status') > 4))) {
$block = array_merge($block, module_invoke($block['module'], 'block', 'view', $block['delta']));
}
if (isset($block['content']) && $block['content']) {