I'm updating my site again. I've been working on the core functions / classes. Yes, the CORE part... The major ones are like user authentication and database connection. I've unified all database access under one global variable, avoiding multiple DB connection objects created locally (class/function scope). The good thing about ? it saves memory and I can know how many SQL queries are made to construct a page. Scroll down to the very bottom and you can see how like
"N queries made". Quite surprising though... some pages used like 35 SQL queries... o.O omg... gotna refine them later...
My current approach [ Hide ] -------site_management.php---------------
// The class of "everything", contains db connection
// and other authentication
class site_management
{
var $DB_OBJECT;
function site_management()
{
// Let's say MYSQL_DB is your class that contains
// all functions to access/manipulate the database
$this->DB_OBJECT = new MYSQL_DB();
}
}
-------foo.php--------------------
// Some class that requires access to database
class foo
{
// Internal database connection object
var $_db_object;
function foo()
{
// If global variable $SITE->DB_OBJECT exists, make reference
// to it otherwise instantiate a new copy locally
if (isset($GLOBALS['SITE']) && $GLOBALS['SITE']->DB_OBJECT)
$this->_db_object =& $GLOBALS['SITE']->DB_OBJECT;
else
$this->_db_object = new MYSQL_DB();
}
function bar()
{
// You need to perform sql query here
$this->_db_object->query($sql); // for example
// ...
}
}
------test.php-------------------
// The above two class is located in different files
// and below is also in a seperate script file
<?php
$SITE = new site_management();
$foo_obj = new foo();
$foo_obj->bar();
?>
My old way [ Hide ] -------foo.php--------------------
// Some class that requires access to database
class foo
{
// Internal database connection object
var $_db_object;
function foo()
{
// Instantiate a new copy locally
$this->_db_object = new MYSQL_DB();
}
}
Let me know what you think about this. You can also
leave me a message here.
Read more about referencing global variable:
http://www.php.net/manual/en/language.references.whatdo.php
http://www.obdev.at/developers/articles/00002.html
In authentication part I removed ALL spaghetti-style-redirection when transfering a user through a login/logout. In short, no more hidden values inside <form> to track user, session is used instead. Clean code and it works! Hopefully things will work fine... even though I'm extremely carefully when touching the core part, because almost everything are built on top of it.
You should also have notice the
"N visitor(s) online now" thing on the left navigation menu. Although most of the time there is only 1 visitor, me myself

Talking about the navigation menu, I'm adding options to show/hide the menu with javascript. See that red button with a 'X' ? That's what I'm talking about.
Others updates are misc and minor updates in template/admin control panel.