blog module callbacks

Step 2: Create the events.php inside the "mod_blog" folder. Define the callback functions:

function blog_init() {
	$title = new HtmlElm(
		array(
			"type" => "h2",
			"name" => "blogTitle",
			"parent" => "blog_
			content_main_inner",
		)
	);
	$title->show();
	$div = new HtmlElm(
		array(
			"type" => "div",
			"name" => "blogContent",
			"parent" => "blog_
			content_main_inner",
		)
	);
	$div->show();
	$div->setCSS("padding","10px");
}

function blog_getPost($params=null) {
	$id = $params["id"];
	
	global $db;
	
	$post = $db->query("Select * from posts 
	where postID=$id");
	$post = $post[0];
	
	global $blogContent;
	global $blogTitle;
	$blogTitle->setContent($post["title"]);
	$blogContent->setContent($post["post"]);
}
	

The init() function is called upon module creation. It creates two HTML elements within the "content" area of the window: a title h2 and a content div. Because we've given these elements unique names (blogTitle and blogContent) we can use these variables in the getPost() function below.

In the getPost() function, we simply query for the appropriate blog post, given the ID from the parameters. Then we use the BlogTitle object to change the title and the BlogContent object to change the innerHTML.

Sample Code

a blog module

Step 1: Create the main.php file inside the "mod_blog" folder. Define the blog_run() function as follows:

Step A: Create the main window:

function blog_run() {
	$myWin = new Window("developmentWND",
		array(
			"title" => "Development Blog",
			"width" => 580,
			"height" => 480
		)
	);
	$myWin->show();
	

Notice the simplicity - we are specifying the width and height of the window as well as the title that will show up in the header. The first parameter, developmentWND is a unique name we're giving to this element. In our events.php page, we will be able to declare global $developmentWND and use it to refer to this window object!

Step B: Create a Side Panel

$mySide = new SidePanel();
$mySide->show();
$mySide->addSideList();

global $db;
$posts = $db->query("Select *, MONTH(date) as month 
from posts where blog=3 Group by MONTH(date) Order 
by date DESC");

foreach($posts as $p) {
	$month = $p["month"];
	
	$t = $db->query("Select * from posts where 
	blog=3 and MONTH(date)=$month Order by date DESC");
	
	$mySide->addSideListTree(date("F",mktime(0,0,0,$month,1,2008)));
	
	foreach($t as $q) {
		$mySide->addSideListItem(
			array(
				"icon" => "icons/time.png",
				"text" => date("m/d g:i a",strtotime($q["date"])),
				"onclick" => "getPost",
				"params" => array("id"=>$q["postID"])
			)
		);
	}
}
	

Don't be worried. This may look complicated, but it's not. All we're doing is creating a new side panel and then a list. We use the global database object ($db) to query the database for a certain grouping of blog posts. Then, for each group, we create a new side list tree (which is collapsable and expandable) and fill it with information about each post. Every side panel item consists of the icon, the text to display and the action when clicked. In this case, saying "onclick"=>"getPost" means we should have a "blog_showPost($params)" function on our events.php page.

Step C: How about a Toolbar?

$myTool = new Toolbar(array("height"=>75));
$myTool->show();
$myTool->addIcon(
	array(
		"icon" => "img/createNew.png",
		"text" => "New",
		"onclick" => "ajax",
		"params" => "createNew"
	)
);
	

This little bit of code is enough to create a toolbar in the window which contains one button whose image is specified by icon, caption by text and callback by params (onclick can either be an ajax call or a link to an external site if you use "href")