Source for file CMS3_System.php
Documentation is available at CMS3_System.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 CMS3_System
* @author Jonas F. Jensen <jopsen@gmail.com>
* @copyright 2007 Jonas F. Jensen.
* @license http://www.gnu.org/licenses/gpl.txt
*CMS_System is a system plugin that hosts IProvidesEditor, IConfigure and ISystemCallback
//ISystemCallback implementation
//used for system callbacks like logout...
* Handles a callback from ajax application.
* @param string data Data attached to this callback
unset
($_SESSION["loggedin"]);
header("Location: " .
$this->Owner->GetCMS3URL() .
"System/Login");
}elseif($data ==
"SaveDefaultNamespace"){
$Settings["DefaultNamespace"] =
$_POST["DefaultNamespace"];
//Save settings log the error for us.
print
"Unable to save settings, try again or see system log.";
//Save default OutputHandler
}elseif($data ==
"SaveDefaultOutputHandler"){
$Settings["DefaultOutputHandler"] =
$_POST["DefaultOutputHandler"];
//Save settings log the error for us.
print
"Unable to save settings, try again or see system log.";
//Don't know what to do, lets just give it a soft 404...
print
"Error: 404, data not found.";
//IProvidesEditor implementation
//is used to create an abstraction of a controlcenter, in other word just a place to list all IConfigure implementations
* Gets an Ajax guide for modification of the content.
* This implementation of the interface is used to list implemnetations of IConfigure
* @param IEmbedmentOutputHandler EmbedmentOutputHandler Outputhandler the content MUST be parse to.
* @return IEmbedmentOutputHandler
public function &ModifyContent($Identifier =
null, &$EmbedmentOutputHandler){
$Configurations =
$this->Owner->GetImplementations("IConfigure");
$Content =
"<center><br /><br /><div class='ControlCenter'>";
foreach($Configurations as $Configuration){
$Icon =
$Configuration->GetControlCenterIcon();
$Menu =
$Configuration->GetControlCenterMenuEntry();
$Link =
$this->Owner->GetCMS3URL() .
"System/Configure/" .
$Configuration->GetPluginID();
$Content .=
"<a href='$Link'><img src='$Icon' border='0' /><br />$Menu</a>";
$Content .=
"</div></center>";
//TODO content, publish list of IConfigure, don't list system cause it leads here.
$EmbedmentOutputHandler->SetBody($Content);
$EmbedmentOutputHandler->ExtentHeader("<style>.ControlCenter a {display: block; float: left;border: 1px solid #37abc8; background-color: #87cdde; margin: 10px; text-align: center; padding: 2px; font-size: 10px; text-decoration: none; color: black; width: 100px; height: 92px; padding-top: 5px;}\n .ControlCenter a:hover {background-color: #afdde9; text-decoration: none; color: black;} .ControlCenter {width: 55%;}</style>");
return $EmbedmentOutputHandler;
* Gets an absolute address of an icon for this plugin
return $this->Owner->GetCMS3URL() .
"bin/System/preferences-desktop.png";
//IConfigure implementation
* Gets an absolute address of an icon for this plugin
return $this->Owner->GetCMS3URL() .
"bin/System/preferences-desktop.png";
* Gets a dojo based ajax guide for configuration of the plugin.
* @param IEmbedmentOutputHandler OutputHandler
* @return IEmbedmentOutputHandler
public function &Configure($Identifier =
null, &$EmbedmentOutputHandler ){
//Load templates from files
$Query =
"SELECT Namespace FROM CMS3_Namespaces ORDER BY Namespace";
if(mysql_num_rows($Result) !=
0){
while($Row =
mysql_fetch_array($Result, MYSQL_ASSOC))
if($Settings["DefaultNamespace"] ==
$Row["Namespace"]){
$Selected =
" selected=\"selected\"";
$NSOptions .=
"<option value='" .
$Row["Namespace"] .
"'" .
$Selected .
">" .
$Row["Namespace"] .
"</option>\n";
$OutputHandlers =
$this->Owner->GetImplementations("IOutputHandler");
foreach($OutputHandlers as $OutputHandler){
if($Settings["DefaultOutputHandler"] ==
$OutputHandler->GetPluginID()){
$Selected =
" selected=\"selected\"";
$OHOptions .=
"<option value='" .
$OutputHandler->GetPluginID() .
"'" .
$Selected .
">" .
$OutputHandler->GetPluginID() .
"</option>\n";
$EmbedmentOutputHandler->ExtentHeader($Head);
$EmbedmentOutputHandler->SetBody($Body);
return $EmbedmentOutputHandler;
* Print the page of a given identifier.
* @param string identifier Identifier of the requested page.
* @param IOutputHandler OutputHandler OutputHandler used the parse the output. You may disable this OutputHandler with
* OutputHandler->Disable() and print the content manually.
public function &GetPage( $identifier, &$OutputHandler ){
if(!$this->Owner->IsAdmin()){
if($_POST["AjaxRequest"] ==
"true"){
//Repond to Ajax callback
$OutputHandler->Disable();
if($this->Owner->Login($_POST["Username"], $_POST["Password"])){
print
$this->Owner->GetCMS3URL() .
"System/Welcome";
//TODO: Make login site, using outputhandler
$OutputHandler->SetTitle("CMS3 System login");
$OutputHandler->SetBody($Body);
$OutputHandler->ExtentHeader($Header);
//We wont be using this...
$OutputHandler->Disable();
$data =
explode("/", $identifier, 3);
//TODO: i18n and create an overview of what can be done here...
$SysOutput->SetBody("Welcome to CMS3 backend, please use the dock for navigation.");
//Append empty string, if there's only two
if($data[0] ==
"Configure"){
$Configure =
$this->Owner->GetPlugin($data[1]);
$SysOutput =
$Configure->Configure($data[2], $SysOutput);
$Editor =
$this->Owner->GetPlugin($data[1]);
$SysOutput =
$Editor->ModifyContent($data[2], $SysOutput);
if($data[0] ==
"Callback"){
//TODO: Check if interface is implementated
$ICallback =
$this->Owner->GetPlugin($data[1]);
$ICallback->SystemCallback($data[2]);
*Gets an instance of SystemOutputHandler
require_once($this->Owner->GetCMS3Path() .
"lib/System/CMS3_System_SysOutputHandler.php");
$SysOutputHandler->Register($this->Owner);
return $SysOutputHandler;
*Parse SysOutputHandler to HTML
//TODO enable reponse as ajax call, perhaps using hidden http parameter like $_POST["IsAjax"]
print
"<head>" .
$OutputHandler->GetHeader() .
"</head>";
print
"<body>" .
$OutputHandler->GetContent() .
"</body>";
*Referance to a system database handle
* Gets the pluginID of the plugin.
*Set the system database handle of this object
*@param resource Handle System database handle
//Function for saving and loading settings
*Opens the settings file for writting
* NOTE: this method is public because it's linked to CMS3_MainClass
//We're return be referance for performance issues...
$SettingsFile =
$this->Owner->GetCMS3Path() .
"etc/" .
$this->GetPluginID() .
"/Settings.bin"; //.bin since it a binary serialized string
//Deserialize loaded data
*Save settings to files...
$SettingsFile =
$this->Owner->GetCMS3Path() .
"etc/" .
$this->GetPluginID() .
"/Settings.bin"; //.bin since it a binary serialized string
$SettingsPath =
$this->Owner->GetCMS3Path() .
"etc/" .
$this->GetPluginID() .
"/";
//Create dir if not there
if(!mkdir($SettingsPath)){
//Log error if couldn't be created
//Check if file is writeable
//Log error if file isn't writeable
//Open the file for writing
if(!$Handle =
fopen($SettingsFile, "w")){
//Close filestream/handle
//Return true since we've saved the settings, doesn't really matter if file wasn't closed correctly
Documentation generated on Mon, 30 Apr 2007 01:59:10 +0200 by phpDocumentor 1.3.1