2001-03-10 11:07:52 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2000-12-23 15:20:10 +00:00
2001-01-13 16:33:19 +00:00
function block_help() {
?>
2001-10-22 12:55:41 +00:00
<p>Blocks are the boxes visible in the side bars on the left- and right-hand side of the website. They are either exported by the engine or by any of the active modules. To really get your teeth into a drupal website, you are going to have to deal with blocks and administering blocks in a fairly sophisticated fashion. This means you will need to understand how the block placement strategy works.</p>
<p>The placement of blocks is delegated to the administrator. In most cases (i.e., the "custom" blocks), the user has complete control -- using preferences -- over whether or not they are enabled.</p>
<p>An administrator can lay out and arrange the available blocks to fit in two regions: "left" and "right". Regions simply contain blocks. In addition, an administrator can assign each block (within a region) a weight to sort them vertically. The heavier blocks will sink and the lighter blocks will be positioned nearer the top.</p>
<p>As mentioned, blocks may be arranged to fit in two regions: left and right. For theme builders, each region is identified by a corresponding constant: "left" and "right".</p>
<p>The path setting lets you define which pages you want the specific blocks to be shown. If you leave the path blank it will show on all pages. The path uses a regular expression syntax so remember to escape special characters!<br />Examples:
<ul><li>Only show on node pages: ^/node\.php</li><li>Only show on the user page: ^/module\.php\?mod=user</li><li>Show in main page and blog page: ^/(index\.php|module\.php\?mod=blog)</li></ul>
2001-03-10 11:07:52 +00:00
<?php
2001-01-13 16:33:19 +00:00
}
2001-06-20 20:00:40 +00:00
function block_perm() {
2001-06-29 22:08:57 +00:00
return array("administer blocks");
}
function block_link($type) {
2001-07-07 14:58:54 +00:00
if ($type == "admin" && user_access("administer blocks")) {
2001-06-29 22:08:57 +00:00
$links[] = "<a href=\"admin.php?mod=block\">blocks</a>";
}
return $links ? $links : array();
2001-06-20 20:00:40 +00:00
}
2000-12-23 15:20:10 +00:00
function block_admin_save($edit) {
foreach ($edit as $key=>$value) {
2001-11-17 15:44:21 +00:00
db_query("UPDATE blocks SET region = '". check_input($value["region"]) ."', status = '". check_input($value["status"]) ."', path = '". check_input($value["path"]) ."', weight = '". check_input($value["weight"]) ."' WHERE name = '". check_input($key) ."'");
2000-12-23 15:20:10 +00:00
}
}
function block_admin_display() {
2000-12-24 15:44:29 +00:00
$result = db_query("SELECT * FROM blocks ORDER BY module");
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
// Generate output:
2001-10-22 12:55:41 +00:00
$output .= "<form action=\"admin.php?mod=block\" method=\"post\">\n";
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
$output .= " <tr><th>block</th><th>module</th><th>status</th><th>weight</th><th>region</th><th>path</th></tr>\n";
2001-01-26 13:38:46 +00:00
2000-12-23 15:20:10 +00:00
while ($block = db_fetch_object($result)) {
2001-05-05 13:57:29 +00:00
$module = module_hook($block->module, "admin") ? "<A HREF=\"admin.php?mod=$block->module\">$block->module</A>" : $block->module;
2000-12-23 15:20:10 +00:00
2001-10-22 12:55:41 +00:00
$status = "<select name=\"edit[$block->name][status]\">\n";
$status .= " <option value=\"2\"". (($block->status == 2) ? " selected" : "") .">enabled: always</option>\n";
$status .= " <option value=\"1\"". (($block->status == 1) ? " selected" : "") .">enabled: custom</option>\n";
$status .= " <option value=\"0\"". (($block->status == 0) ? " selected" : "") .">disabled</option>\n";
$status .= "</select>\n";
2000-12-23 15:20:10 +00:00
2001-10-22 12:55:41 +00:00
$weight = "<select name=\"edit[$block->name][weight]\">\n";
2001-01-13 16:33:19 +00:00
for ($count = 0; $count < 10; $count++) {
2001-10-22 12:55:41 +00:00
$weight .= "<option value=\"$count\"". (($block->weight == $count) ? " selected" : "") .">$count</option>\n";
2001-01-13 16:33:19 +00:00
}
2001-10-22 12:55:41 +00:00
$weight .= "</select>\n";
2001-01-13 16:33:19 +00:00
2001-10-22 12:55:41 +00:00
$region = "<select name=\"edit[$block->name][region]\">\n";
$region .= " <option value=\"0\"". (($block->region == 0) ? " selected" : "") .">left</option>\n";
$region .= " <option value=\"1\"". (($block->region == 1) ? " selected" : "") .">right</option>\n";
$region .= "</select>\n";
2001-11-01 11:00:51 +00:00
2001-10-22 12:55:41 +00:00
$path = "<input name=\"edit[$block->name][path]\" value=\"$block->path\">\n";
2001-01-13 16:33:19 +00:00
2001-10-22 12:55:41 +00:00
$output .= " <tr><td>". $block->name ."</td><td align=\"center\">$module</td><td>$status</td><td>$weight</td><td>$region</td><td>$path</td></tr>\n";
2000-12-23 15:20:10 +00:00
}
2001-01-26 13:38:46 +00:00
2001-10-22 12:55:41 +00:00
$output .= "</table>\n";
$output .= "<input name=\"op\" type=\"submit\" value=\"Save blocks\">\n";
$output .= "</form>\n";
2000-12-23 15:20:10 +00:00
print $output;
}
2001-06-18 18:00:13 +00:00
function block_admin_preview() {
2001-01-13 16:33:19 +00:00
$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)) $lblocks .= " <TR><TD NOWRAP>". ($block->status == 2 ? "<B>$block->name</B>" : $block->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");
$rblocks .= "<TABLE BORDER=\"0\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
while ($block = db_fetch_object($result)) $rblocks .= " <TR><TD NOWRAP>". ($block->status == 2 ? "<B>$block->name</B>" : $block->name) ."</TD><TD>$block->weight</TD></TR>\n";
$rblocks .= "</TABLE>\n";
2001-01-26 13:38:46 +00:00
2001-06-18 18:00:13 +00:00
$output .= "<H3>layout scheme #1:</H3>\n";
2001-01-13 16:33:19 +00:00
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"3\">header</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TD>\n". ($lblocks ? $lblocks : " ") ."</TD><TD WIDTH=\"300\"> </TD><TD>\n". ($rblocks ? $rblocks : " ") ."</TD></TR>\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"3\">footer</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= "</TABLE>\n";
$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)) $blocks .= " <TR><TD NOWRAP>". ($block->status == 2 ? "<B>$block->name</B>" : $block->name) ."</TD><TD>$block->weight</TD></TR>\n";
$blocks .= "</TABLE>\n";
2001-06-18 18:00:13 +00:00
$output .= "<H3>layout scheme #2:</H3>\n";
2001-01-13 16:33:19 +00:00
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">header</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TD WIDTH=\"400\"> </TD><TD>\n". ($blocks ? $blocks : " ") ."</TD></TR>\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">footer</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= "</TABLE>\n";
2001-06-18 18:00:13 +00:00
$output .= "<H3>layout scheme #3:</H3>\n";
2001-01-13 16:33:19 +00:00
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">header</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= " <TR><TD>\n". ($blocks ? $blocks : " ") ."</TD><TD WIDTH=\"400\"> </TD></TR>\n";
2001-04-06 14:14:16 +00:00
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">footer</TD></TR>\n";
2001-01-13 16:33:19 +00:00
$output .= "</TABLE>\n";
print $output;
}
2001-06-23 11:09:40 +00:00
function block_init() {
2001-10-16 20:13:22 +00:00
2001-06-23 11:09:40 +00:00
$result = db_query("SELECT * FROM modules");
while ($module = db_fetch_object($result)) {
module_rehash($module->name);
}
foreach (module_list() as $name) {
module_rehash($name);
}
}
2000-12-23 15:20:10 +00:00
function block_admin() {
2001-06-29 22:08:57 +00:00
global $op, $edit;
2001-06-20 20:00:40 +00:00
2001-06-29 22:08:57 +00:00
if (user_access("administer blocks")) {
2001-06-23 11:09:40 +00:00
2001-06-20 20:00:40 +00:00
print "<SMALL><A HREF=\"admin.php?mod=block\">configure</A> | <A HREF=\"admin.php?mod=block&op=preview\">preview</A> | <A HREF=\"admin.php?mod=block&op=help\">help</A></SMALL><HR>\n";
2001-06-23 11:09:40 +00:00
block_init();
2001-06-20 20:00:40 +00:00
switch ($op) {
case "help":
block_help();
break;
case "preview":
block_admin_preview();
break;
case "Save blocks":
block_admin_save($edit);
// fall through
default:
block_admin_display();
}
}
else {
print message_access();
2000-12-23 15:20:10 +00:00
}
}
2001-11-01 11:00:51 +00:00
2000-12-23 15:20:10 +00:00
?>