"box_help", "block" => "box_block", "admin" => "box_admin"); function box_help() { ?>

The content of the site can be almost entirely altered through boxes. Simply put, boxes are small bits of text, HTML or PHP code which will get plugged into the site just like any other block. Boxes are typically used to add custom blocks to the site.

Each box consists of a subject and an associated block of text, HTML or PHP code which can be as long as you want it to be and that will 'render' the content of the box.

PHP boxes

If you know how to script in PHP, PHP boxes are pretty easy to create. Don't worry if you're no PHP-wizard: simply use ASCII or HTML boxes instead.

You can use any piece of PHP code to make up the content of a PHP box: this implies that you can declare and use functions, consult the SQL database, access configuration settings and much more. A PHP box's code is stored in the database and the engine will dynamically embed the PHP code just-in-time for execution.

There are however some factors to keep in mind when using and creating PHP boxes: PHP boxes can be extremely useful and flexible, yet they can be dangerous and insecure if not properly used. If you are not familiar with PHP, SQL or even with the site engine for that matter, avoid experimenting with PHP boxes because you can - and you probably will - corrupt your database or even render your site unusable! If you don't plan to do fancy stuff with boxes then you're probably better off with ASCII or HTML boxes.

Remember that the code within each PHP box must be valid PHP code, including things like terminating statements with a semicolon so the parser won't die. Therefore, it is highly recommended to test your boxes separately using a simple test script on top of a test database before migrating to your production environment running your real database.

Note that you can use global variables such as configuration parameters within the scope of a PHP box. Also keep in mind that variables that have been given values in a PHP box will retain these values in the engine or module afterwards.

You can use the return statement to return the actual content for your block as well.

A basic example:

Given the box with subject "Welcome", used to create a "Welcome"-box. The content for this box could be created by using:

   return "Welcome visitor, ... welcome message goes here ...";
  

If we are however dealing with a registered user, we can customize the message by using:

   if ($user->userid) {
     return "Welcome $user->userid, ... welcome message goes here ...";
   }
   else {
     return "Welcome visitor, ... welcome message goes here ...";
   }
  

For a more in-depth example, we recommend you to check the existing boxes and to use them as a start.

subject); $blocks[$i]["content"] = ($block->type == 2) ? eval($block->content) : check_output($block->content, ($block->type == 1) ? 0 : 1); $blocks[$i]["info"] = check_output($block->info); $blocks[$i]["link"] = check_output($block->link); $i++; } return $blocks; } function box_admin_display() { $type = array(0 => "ASCII", 1 => "HTML", 2 => "PHP"); $result = db_query("SELECT * FROM boxes"); while ($block = db_fetch_object($result)) { $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Subject:". format_data($block->subject) ."
Content:". nl2br(htmlentities($block->content)) ."
Type:". $type[$block->type] ."
Description:". format_data($block->info) ."
Link:". format_url($block->link) ."
Operations:id\">edit, id\">delete
\n"; $output .= "

\n"; } print $output; } function box_admin_new() { $type = array(0 => "ASCII", 1 => "HTML", 2 => "PHP"); foreach ($type as $key=>$value) { $selection .= " \n"; } $output .= "
\n"; $output .= "\n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= " \n"; $output .= "
Subject:
Content:
Type:
Description:
Link:
Operations:
\n"; $output .= "
\n"; print $output; } function box_admin_add($subject, $content, $info, $link, $type) { db_query("INSERT INTO boxes (subject, content, info, link, type) VALUES ('". check_input($subject) ."', '". check_code($content) ."', '". check_input($info) ."', '". check_input($link) ."', '". check_input($type) ."')"); } function box_admin_delete($id) { db_query("DELETE FROM boxes WHERE id = $id"); } function box_admin_rehash() { global $repository; module_rehash_blocks("box", $repository["box"]); } function box_admin_edit($id) { $type = array(0 => "ASCII", 1 => "HTML", 2 => "PHP"); $result = db_query("SELECT * FROM boxes WHERE id = $id"); if ($block = db_fetch_object($result)) { $output .= "
\n"; $output .= "

\n"; $output .= " Subject:
\n"; $output .= " subject) ."\">\n"; $output .= "

\n"; $output .= "

\n"; $output .= " Content:
\n"; $output .= " \n"; $output .= "

\n"; $output .= "

\n"; $output .= " Type:
\n"; $output .= " \n"; $output .= "

\n"; $output .= "

\n"; $output .= " Description:
\n"; $output .= " info\">\n"; $output .= "

\n"; $output .= "

\n"; $output .= " Link:
\n"; $output .= " link\">\n"; $output .= "

\n"; $output .= "

\n"; $output .= " \n"; $output .= "
\n"; $output .= "

\n"; $output .= "
\n"; } print $output; } function box_admin_save($id, $subject, $content, $info, $link, $type) { db_query("UPDATE boxes SET subject = '". check_input($subject) ."', content = '". check_code($content) ."', info = '". check_input($info) ."', link = '". check_input($link) ."', type = '". check_input($type) ."' WHERE id = '$id'"); watchdog("message", "modified box `$subject'"); } function box_admin() { global $op, $id, $subject, $content, $info, $link, $type; print "add new box | overview | help
\n"; switch ($op) { case "Add box": box_admin_add($subject, $content, $info, $link, $type); box_admin_display(); box_admin_rehash(); break; case "Save box": box_admin_save($id, $subject, $content, $info, $link, $type); box_admin_display(); box_admin_rehash(); break; case "help": box_help(); break; case "add": box_admin_new(); break; case "edit": box_admin_edit($id); break; case "delete": box_admin_delete($id); box_admin_rehash(); // fall through default: box_admin_display(); } } ?>