Creating Blocks

Right now the blocks that come with the script are pretty bare.  I'll be working on beefing them up with more customization options later.  But for those that want to create their own blocks to share with others or just tweak the ones included already, here's the basics.  There are two files needed for each block: blockname.php an init.php.  Technically, if you added the block manually, you wouldn't need the init.php file.  It is only used when the block is first initialized, and can be deleted afterward.  Though I would suggest keeping a backup somewhere, just in case.

The init.php file is very simple composed simply of an array that is added to the $blocks array when the block is initiated.  As in the example below.

<?php
$blocks["categories"] = array("title" => "Main Categories", "status" => "0", "file" => "categories/categories.php");
?>

This also shows the basic parameters needed for a block: title, status, and file.  The title can be an empty string if you don't need a title for that particular block. The file should be a subfolder/file of the blocks folder for the sake of consistency. The status should generally start off as 0 for inactive.  There are 5 status options for blocks:

Status  Associated .tpl file Appears
0 Inactive The block is off. nowhere
1 Active The block is on. anywhere
2 Index only index page only. anywhere on the index page.

 

Any default configuration you want for the block can be included in the init.php as well.  For instance, the categories block currently has two options: one column and multiple columns.  The default is a single column lists.  If I were to change the init file as follows, the default would then become a multiple column list.

<?php
$blocks["categories"] = array("title" => "Main Categories", "status" => "0", "file" => "categories/categories.php", "columns" => "1");
?>

The information in the $blocks array is stored in blocks_config.php.  When you change any of the settings for the blocks from the admin panel this is where the changes are made.

The block.php file creates the content that is placed inside the {blockname_content} variable.  This content is placed inside a variable $content which is then assigned to {blockname_content}  So a very simple example of a block would be:

<?php
$content = "Hello World!";
?>

There are two other optional files.  The first is an admin file which will be called from the admin panel to make changes to the settings in the block.  Creating one of those is for another day.

The second file (or multiple files) is a language file that defines any text you use in your block.  These files take the same format as the main language file in the languages folder and are named similarly.  So for instance, an English language file would be named en.php.  For Spanish, it would be es.php.

Most often, you might need to define some wording for your admin.php file.  If you need to add a language file, use the following code in either admin.php or blockname.php

if(file_exists("blocks/$_GET[admin]/{$language}.php")) include("blocks/$_GET[admin]/{$language}.php");

The if(...) isn't technically necessary, but it will prevent errors if the file ends up missing.  For instance, the site's language is set to Russian, but the block doesn't have a Russian translation.  You might also want to include an else statement to load a default language file you have created if the site's chosen language is missing.