Source for file default.php
Documentation is available at default.php
// CMS3 - A Three Content Management System.
// Copyright (C) 2007 Jop... (Jonas F. Jensen).
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*This file defines and executes the CMS3_MainClass
* @author Jonas F. Jensen <jopsen@gmail.com>
* @copyright 2007 Jonas F. Jensen.
* @license http://www.gnu.org/licenses/gpl.txt
*The CMS3 main class, this class hostes all plugins and initiate everything.
* Constructor, loads all plugins
//Include all shared interfaces
foreach($InShare as $Shared){
if($Shared !=
"." &&
$Shared !=
".."){
$InShared =
scandir("./share/" .
$Shared .
"/"); //$InShare
foreach($InShared as $SharedInterface){
if($SharedInterface !=
"." &&
$SharedInterface !=
".."){
//Use output control to avoid problems from bad plugins
require_once($this->GetCMS3Path() .
"share/".
$Shared .
"/" .
$SharedInterface);
foreach($InLib as $Plugin){
//Avoid trying to load .. and .
if($Plugin !=
"." &&
$Plugin !=
".."){
//You could do some testing of is_dir etc. but DONT
* Destructor, closes Database connections
* Main functions start the application
static function Main($Args){
$MainClass->ResolveIdentifier($Args);
* Gets the username of the current user, resturns null if user not loggedin.
if($_SESSION["loggedin"] ==
"TruE"){
return $_SESSION["UserName"];
} // end of member function GetUserName
*@param string Username Username of the user
*@param string Password The users password
*@return bool true if login was successfull
public function Login($Username, $Password){
$Password =
sha1($Password);
$Query =
"Select BackendAccess from CMS3_Users where Username = '$Username' AND Password = '$Password' limit 1";
if(mysql_num_rows($Result) !=
0){
$_SESSION["loggedin"] =
"TruE";
$_SESSION["UserName"] =
$Username;
//TODO cache backend access value, since it's usefull
* Returns true if current user is administrator.
//As of development just return true
//We are using sha1 since it's not completly broken yet.
$Result =
mysql_query("Select BackendAccess from CMS3_Users where Username = '$UserName' limit 1");
//We don't have to check password that should be done in GetUserName
//AND Password = '" . $_COOKIE["CMS3_PasswordHash"] . "' limit 1",);
$BackendAccess =
mysql_fetch_row($Result);
if($BackendAccess[0] ==
"1"){
} // end of member function IsAdmin
* Gets the server path of the CMS3 installation.
return $_SERVER["DOCUMENT_ROOT"] .
"/";
} // end of member function GetCMS3Path
* Gets the URL of the CMS3 toplevel namespace.
return "http://" .
$_SERVER["HTTP_HOST"] .
"/";
} // end of member function GetCMS3URL
* @param string Plugin PluginID of the plugin you wish to load
* @return object Returns the plugin you requested
//Note this could also be done with autoload, but this will cause less conflicts
//Use output control to avoid problems from bad plugins
require_once($this->GetCMS3Path() .
"lib/$Plugin/CMS3_$Plugin.php");
$IPlugin = eval
("return new CMS3_$Plugin();");
$IPlugin->Register($this);
* Gets an instance of a plugin, this returns the one loaded at initialization
* @param string Plugin PluginID of the plugin you wish to load
* @return object The plugin you requested, or false if not there.
//Determine if plugin exists
* Gets all plugins that implements an interface
*@param string Interface Interface the plugins must implement
*@return array Array of objects that implements the interface
$Implementations =
array();
foreach($this->Plugins as $Plugin){
$Implementations[] =
$Plugin;
*Call a method on all plugins that implements an interface
*@param string Interface Interface the plugins must implement to get this call
*@param string Method Method to be called
*@param array Arguments Array of arguments to be passed to the method.
*@return array Returns an array of return values from the different methods
for($i =
0; $i <=
sizeof($Arguments); $i++
){
$StrArgs .=
"\$Arguments['" .
$i .
"']";
$StrArgs .=
", \$Arguments['" .
$i .
"']";
foreach($Implementations as $Implementation){
$Returns[] = eval
("return " .
$Implementation .
"->" .
$Method .
"($Args)");
* Registers a namespace, the plugin that owns this MUST implement IProvidesContent
* @param string Namespace String representation of the namespace, max 255 characters.
* @param string PluginID PluginID of the owner plugin, this must implement IProvidesContent
* @return bool Returns true if registration was successfull.
//System is an integrated part of the CMS3 system, special treatment of it, since it's hardlinked into the system.
if($Namespace ==
"System"){
//We don't have to check if it's already registered, since it's defines as primary key
$Query =
"INSERT INTO CMS3_Namespaces (Namespace, Owner) VALUES ('$Namespace','$PluginID')";
* Unregisters a namespace
* @param string Namespace String representation of the namespace.
* @return bool Returns true if unregistration was successfull.
$Query =
"DELETE FROM CMS3_Namespaces WHERE Namespace = '$Namespace' limit 1";
* Get namespace from owner
* @param string PluginID PluginID of the owner plugin
* @return string Namespace of the plugin or false if nothing was registered.
$Query =
"SELECT Namespace FROM CMS3_Namespaces WHERE Owner='$PluginID' limit 1";
if(mysql_num_rows($Result) !=
0){
$Row =
mysql_fetch_row($Result);
* Handle for the logfile, not always loaded
* Print a message to the logfile, useful for debuggin information.
* Message are both printed to custom logfile in ./data/System/System.log and send to syslogd local0 savedin /var/log/CMS3.log according to installation notes.
* @param string PluginID PluginID of the plugin that wrote this log message.
* @param string msg Message to print to the log. Note: Date and time is printed automaticly.
public function Log( $PluginID, $msg ) {
//Write to custom logfile
//Open connection to syslogd
if(openlog("CMS3" , LOG_CONS |
LOG_PID , LOG_LOCAL0)){
if(!syslog(LOG_ERR , "CMS3 - " .
$PluginID .
" | " .
$msg)){
//Close connection to syslogd:
} // end of member function Log
* Print a message of an mysql error to the logfile, useful for debuggin information.
* @param string PluginID PluginID of the plugin that wrote this log message.
* @param string msg Message to print to the log. Note: Date and time is printed automaticly.
* @param resource mysql resource that the error accoured on.
public function LogMySQL( $PluginID, $msg , &$res) {
$this->Log($PluginID, $msg .
": \n" .
mysql_errno($res) .
": " .
mysql_error($res));
} // end of member function Log
* Handle for the userspace database, not always initialized
* Gets a handle for the userspace database
* @return Returns a MySQL database connection.
require_once($this->GetCMS3Path() .
"/etc/System/mysql.conf.php");
//Make sure it always called...
* Closes the application, with an FatalError log, and print the log messsage to user.
public function FatalError($PluginID, $msg =
"Fatal Error, closing the application."){
$this->Log($PluginID, $msg);
//TODO: Try using outputhandlers print Error: 503
print
"\nFatal Error: \n" .
$PluginID .
": " .
$msg;
//Destruct everything we can:
//Exit and kill all remaining code.
* Handle for the system database, not always initialized
* Gets a handle for the system database
* @return Returns a MySQL database connection.
require_once($this->GetCMS3Path() .
"/etc/System/mysql.conf.php");
$this->FatalError("System", "Mysql connection problems");
//Make sure it always called...
$this->FatalError("System", "Mysql connection problems");
* Resoles an print the content of an identifier.
* @param string Identifier Identifier, including namespace etc.
* @return bool True/false depending on success of failure
//Load system settings and parse the system database handle to System plugin
$SysSettings =
$System->LoadSettings();
//If identifier is zero restore default namespace from CMS3_System
$Identifier =
$SysSettings["DefaultNamespace"];
$data =
explode("/", $Identifier, 2);
$PluginSpecificData =
$data[1];
if(!($OutputHandler =
$this->GetPlugin($SysSettings["DefaultOutputHandler"])))
//Select a random OutputHandler
$OutputHandler =
& $OutputHandlers[0];
$OutputHandler->SetIdentifier($Identifier);
//get owner of the namespace
$Query =
"SELECT Owner from CMS3_Namespaces where Namespace = '" .
$Namespace .
"' limit 1";
if(mysql_num_rows($Result) !=
0){
$Row =
mysql_fetch_row($Result);
$IProvidesContent =
$this->GetPlugin($PluginID);
$IProvidesContent->GetPage($PluginSpecificData, $OutputHandler);
//If namespace wasn't found
$OutputHandler->PrintError("Namespace not found.", "404");
$OutputHandler->PrintError("Namespace not found.", "404");
* Gets an embedment from it unique identifier, returns embedable HTML.
* @param string Identifier Unique identifier.
//$data = explode("/", $Identifier, 2);
//TODO: make this work, remember classes are note coded at singleton
$PluginSpecificData = $data[1];
require_once("OutputHandlers/CMS3_HTMLOutputHandler.php");
$IEmbedable = $this->LoadPlugin($PluginID);
return $IEmbedable->GetEmbedments($PluginSpecificData,$OutputHandler);*/
} // end of member function GetEmbedment
Documentation generated on Mon, 30 Apr 2007 01:59:13 +0200 by phpDocumentor 1.3.1