block.module 6.72 KB
Newer Older
Dries's avatar
   
Dries committed
1
<?php
Dries's avatar
   
Dries committed
2

Dries's avatar
   
Dries committed
3
4
function block_help() {
 ?>
Dries's avatar
   
Dries committed
5
6
7
8
  <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>
Dries's avatar
   
Dries committed
9
 <?php
Dries's avatar
   
Dries committed
10
11
}

Dries's avatar
   
Dries committed
12
13
14
15
function block_page() {
  global $theme;

  $result = db_query("SELECT * FROM blocks WHERE status = 1 ORDER BY module");
Dries's avatar
   
Dries committed
16

Dries's avatar
   
Dries committed
17
18
19
20
  $theme->header();
  print "<TABLE BORDER=\"0\">\n";
  while ($block = db_fetch_object($result)) {
    if ($state % 3 == 0) print " <TR>\n";
Dries's avatar
   
Dries committed
21
    print "  <TD ALIGN=\"center\" VALIGN=\"top\" WIDTH=\"33%\">\n";
Dries's avatar
   
Dries committed
22
    $blocks = module_invoke($block->module, "block");
Dries's avatar
   
Dries committed
23
24
25
26
    $theme->box($blocks[$block->offset]["subject"], $blocks[$block->offset]["content"]);
    print " </TD>\n";
    if ($state % 3 == 2) print " </TR>\n";
    $state += 1;
Dries's avatar
   
Dries committed
27
  }
Dries's avatar
   
Dries committed
28
29
30
  print "</TABLE>\n";
  $theme->footer();
}
Dries's avatar
   
Dries committed
31
32
33

function block_admin_save($edit) {
  foreach ($edit as $key=>$value) {
Dries's avatar
   
Dries committed
34
    db_query("UPDATE blocks SET region = '". check_input($value[region]) ."', status = '". check_input($value[status]) ."', weight = '". check_input($value[weight]) ."' WHERE name = '". check_input($key) ."'");
Dries's avatar
   
Dries committed
35
36
37
38
  }
}

function block_admin_display() {
Dries's avatar
   
Dries committed
39
  $result = db_query("SELECT * FROM blocks ORDER BY module");
Dries's avatar
   
Dries committed
40

Dries's avatar
   
Dries committed
41
42
43
  // Generate output:
  $output .= "<FORM ACTION=\"admin.php?mod=block\" METHOD=\"post\">\n";
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
   
Dries committed
44
  $output .= " <TR><TH>block</TH><TH>module</TH><TH>status</TH><TH>weight</TH><TH>region</TH></TR>\n";
Dries's avatar
   
Dries committed
45

Dries's avatar
   
Dries committed
46
  while ($block = db_fetch_object($result)) {
Dries's avatar
   
Dries committed
47
    $module = module_hook($block->module, "admin") ? "<A HREF=\"admin.php?mod=$block->module\">$block->module</A>" : $block->module;
Dries's avatar
   
Dries committed
48

Dries's avatar
   
Dries committed
49
    $status .= "<SELECT NAME=\"edit[$block->name][status]\">\n";
Dries's avatar
   
Dries committed
50
51
    $status .= " <OPTION VALUE=\"2\"". (($block->status == 2) ? " SELECTED" : "") .">enabled: always</OPTION>\n";
    $status .= " <OPTION VALUE=\"1\"". (($block->status == 1) ? " SELECTED" : "") .">enabled: custom</OPTION>\n";
Dries's avatar
   
Dries committed
52
53
54
    $status .= " <OPTION VALUE=\"0\"". (($block->status == 0) ? " SELECTED" : "") .">disabled</OPTION>\n";
    $status .= "</SELECT>\n";

Dries's avatar
   
Dries committed
55
56
57
58
59
60
61
62
63
64
65
66
    $weight .= "<SELECT NAME=\"edit[$block->name][weight]\">\n";
    for ($count = 0; $count < 10; $count++) {
      $weight .= "<OPTION VALUE=\"$count\"". (($block->weight == $count) ? " SELECTED" : "") .">$count</OPTION>\n";
    }
    $weight .= "</SELECT>\n";

    $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";

    $output .= " <TR><TD>". $block->name ."</TD><TD ALIGN=\"center\">$module</TD><TD>$status</TD><TD>$weight</TD><TD>$region</TD></TR>\n";
Dries's avatar
   
Dries committed
67

Dries's avatar
   
Dries committed
68
    unset($status);
Dries's avatar
   
Dries committed
69
70
    unset($weight);
    unset($region);
Dries's avatar
   
Dries committed
71
  }
Dries's avatar
   
Dries committed
72

Dries's avatar
   
Dries committed
73
74
75
76
77
78
79
  $output .= "</TABLE>\n";
  $output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"Save blocks\">\n";
  $output .= "</FORM>\n";

  print $output;
}

Dries's avatar
   
Dries committed
80
81
82
83
84
85
86
87
88
89
90
function block_admin_overview() {

  $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";
Dries's avatar
   
Dries committed
91

Dries's avatar
   
Dries committed
92
93
  $output .= "<P><B>layout 1:</B></P>\n";
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
   
Dries committed
94
  $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"3\">header</TD></TR>\n";
Dries's avatar
   
Dries committed
95
  $output .= " <TR><TD>\n". ($lblocks ? $lblocks : "&nbsp;") ."</TD><TD WIDTH=\"300\">&nbsp;</TD><TD>\n". ($rblocks ? $rblocks : "&nbsp;") ."</TD></TR>\n";
Dries's avatar
   
Dries committed
96
  $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"3\">footer</TD></TR>\n";
Dries's avatar
   
Dries committed
97
98
99
100
101
102
103
104
105
  $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";

  $output .= "<P><B>layout 2:</B></P>\n";
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
   
Dries committed
106
  $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">header</TD></TR>\n";
Dries's avatar
   
Dries committed
107
  $output .= " <TR><TD WIDTH=\"400\">&nbsp;</TD><TD>\n". ($blocks ? $blocks : "&nbsp;") ."</TD></TR>\n";
Dries's avatar
   
Dries committed
108
  $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">footer</TD></TR>\n";
Dries's avatar
   
Dries committed
109
110
111
112
  $output .= "</TABLE>\n";

  $output .= "<P><B>layout 3:</B></P>\n";
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
   
Dries committed
113
  $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">header</TD></TR>\n";
Dries's avatar
   
Dries committed
114
  $output .= " <TR><TD>\n". ($blocks ? $blocks : "&nbsp;") ."</TD><TD WIDTH=\"400\">&nbsp;</TD></TR>\n";
Dries's avatar
   
Dries committed
115
  $output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"2\">footer</TD></TR>\n";
Dries's avatar
   
Dries committed
116
117
118
119
120
  $output .= "</TABLE>\n";

  print $output;
}

Dries's avatar
   
Dries committed
121
122
function block_admin() {
  global $op, $edit;
Dries's avatar
   
Dries committed
123

Dries's avatar
   
Dries committed
124
  print "<SMALL><A HREF=\"admin.php?mod=block\">configure</A> | <A HREF=\"admin.php?mod=block&op=overview\">overview</A> | <A HREF=\"admin.php?mod=block&op=help\">help</A></SMALL><HR>\n";
Dries's avatar
   
Dries committed
125
126

  switch ($op) {
Dries's avatar
   
Dries committed
127
128
129
130
131
132
    case "help":
      block_help();
      break;
    case "overview":
      block_admin_overview();
      break;
Dries's avatar
   
Dries committed
133
134
    case "Save blocks":
      block_admin_save($edit);
Dries's avatar
   
Dries committed
135
136
137
      // fall through
    default:
      block_admin_display();
Dries's avatar
   
Dries committed
138
  }
Dries's avatar
   
Dries committed
139

Dries's avatar
   
Dries committed
140
141
142
}

?>