Source for file CMS3_Wiki.php
Documentation is available at CMS3_Wiki.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_Wiki
* @author Jonas F. Jensen <jopsen@gmail.com>
* @copyright 2007 Jonas F. Jensen.
* @license http://www.gnu.org/licenses/gpl.txt
* Very simple plugin that allows creation of an image gallery
//Implementation of IProvidesContent
* 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 ){
//Initialize body variable
//Use the first string before the first slash
$identifier =
substr($identifier,5); //Cut of the Edit/
$head =
"<script language='javascript' type='text/javascript' src='" .
$this->Owner->GetCMS3URL() .
"bin/Wiki/tiny_mce/tiny_mce.js'></script>";
$head .=
"<script language='javascript' type='text/javascript'>tinyMCE.init({mode : 'textareas', theme : 'simple' });</script>";
$OutputHandler->ExtentHeader($head);
//Select the latest revision of the page requested
$Query =
"SELECT Content From CMS3_Wiki WHERE Identifier = '" .
$identifier .
"' ORDER BY Revision DESC LIMIT 1";
$dbh =
$this->Owner->GetDatabaseHandle();
if(!$Result =
mysql_query($Query, $dbh)){
$this->Owner->LogMySQL($this->GetPluginID(), "Error while trying to get wikipage: $identifier for editing", $dbh);
$body .=
"<form action='" .
$Url .
"Save/" .
$identifier .
"' method='post'>";
if(mysql_num_rows($Result) !=
0){
$body .=
"<h1>Edit: " .
($identifier ==
"" ?
"Wiki" :
$identifier) .
"</h1>";
//Parse the content to body variable
$Row =
mysql_fetch_row($Result);
$body .=
"<textarea style='width: 98%; min-height: 300px;' name='Content'>" .
$Row[0] .
"</textarea>";
$body .=
"<h1>Create: " .
$identifier .
"</h1>";
$body .=
"<textarea style='width: 98%; min-height: 300px;' name='Content'>Create a new page...<br /></textarea>";
$body .=
"<br/ ><input type='submit' value='Save' /></form>";
$identifier =
substr($identifier,8); //Cut of the History/
//List old revision of this identifier
//Select a list of revisions of the page requested
$Query =
"SELECT Revision, Created From CMS3_Wiki WHERE Identifier = '" .
$identifier .
"' ORDER BY Revision DESC";
$dbh =
$this->Owner->GetDatabaseHandle();
if(!$Result =
mysql_query($Query, $dbh)){
$this->Owner->LogMySQL($this->GetPluginID(), "Error while trying to get revision: $identifier", $dbh);
if(mysql_num_rows($Result) !=
0){
$body .=
"<h1>History of " .
($identifier ==
"" ?
"Wiki" :
$identifier) .
"</h1>";
//Parse the content to body variable
while($Row =
mysql_fetch_array($Result, MYSQL_ASSOC)){
$body .=
"<a href='" .
$Url .
"Revision/" .
$Row["Revision"] .
"'>Revision: " .
$Row["Revision"] .
" - " .
date(DATE_RFC822, $Row["Created"]) .
"</a><br>";
header("Location: " .
$Url .
"Edit/" .
$identifier);
$identifier =
substr($identifier,9); //Cut of the Revision/
//Select the revision requested
$Query =
"SELECT Content, Created, Identifier From CMS3_Wiki WHERE Revision = '" .
$identifier .
"' LIMIT 1";
$dbh =
$this->Owner->GetDatabaseHandle();
if(!$Result =
mysql_query($Query, $dbh)){
$this->Owner->LogMySQL($this->GetPluginID(), "Error while trying to get revision: $identifier", $dbh);
if(mysql_num_rows($Result) !=
0){
//Parse the content to body variable
$Row =
mysql_fetch_row($Result);
$body .=
"<h1>" .
($Row[2] ==
"" ?
"Wiki" :
$Row[2]) .
"</h1><i>Revision: " .
$identifier .
", created " .
$Row[1] .
"</i><p>" .
$Row[0] .
"</p>";
//Make the cut of the Save/ part, make it parseable for default
$identifier =
substr($identifier,5);
$Query =
"INSERT INTO CMS3_Wiki (Identifier, Content) VALUES ('" .
$identifier .
"', '" .
$_POST["Content"] .
"')";
$dbh =
$this->Owner->GetDatabaseHandle();
if(!$Result =
mysql_query($Query, $dbh)){
$this->Owner->LogMySQL($this->GetPluginID(), "Error while trying to get wikipage: $identifier", $dbh);
default:
//just display the page the identifier is identifing :)
//Select the latest revision of the page requested
$Query =
"SELECT Content, Created, Revision From CMS3_Wiki WHERE Identifier = '" .
$identifier .
"' ORDER BY Revision DESC LIMIT 1";
$dbh =
$this->Owner->GetDatabaseHandle();
if(!$Result =
mysql_query($Query, $dbh)){
$this->Owner->LogMySQL($this->GetPluginID(), "Error while trying to get wikipage: $identifier", $dbh);
if(mysql_num_rows($Result) !=
0){
//Parse the content to body variable
$Row =
mysql_fetch_row($Result);
$body .=
"<h1>" .
($identifier ==
"" ?
"Wiki" :
$identifier) .
"</h1><i>Revision: " .
$Row[2] .
", created " .
$Row[1] .
"</i><p>" .
$Row[0] .
"</p>";
header("Location: " .
$Url .
"Edit/" .
$identifier);
//Add a little toolbar at the top of the wiki page
$body =
"<div style=\"float: right;\"><a href=\"" .
$Url .
$identifier .
"\">Article</a> | <a href=\"" .
$Url .
"Edit/" .
$identifier .
"\">Edit</a> | <a href=\"" .
$Url .
"History/" .
$identifier .
"\">History</a></div><br />" .
$body;
$OutputHandler->SetTitle($identifier);
$OutputHandler->SetBody($body);
//Implementation of IPlugin
* Gets the pluginID of the plugin.
//Implementation of ILinkable
* Gets a list of links that the plugins exposes
* Each entry in the array is an array with 3 fields, one for the display name, one for the URL of the page, and one for an array of sub entries. Each sub entry consits of 3 fields, just like the toplevel entries.
$URL =
$this->Owner->GetCMS3URL() .
$Namespace .
"/";
$Links =
array($Namespace,$URL, array());
$Query =
"SELECT DISTINCT Identifier FROM CMS3_Wiki ORDER by Identifier";
$Result =
mysql_query($Query, $this->Owner->GetDatabaseHandle());
if(mysql_num_rows($Result) !=
0){
while($Row =
mysql_fetch_array($Result, MYSQL_ASSOC))
//Default page is representated as plugin entry
if($Row["Identifier"] !=
"")
$Links[2][] =
array($Row["Identifier"], $URL .
$Row["Identifier"] , null);
//Add toplevel array and return it
//IConfigure implementation
* Gets an absolute address of an icon for this plugin
return $this->Owner->GetCMS3URL() .
"bin/" .
$this->GetPluginID() .
"/icon.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
$EmbedmentOutputHandler->ExtentHeader($Head);
$EmbedmentOutputHandler->SetBody($Body);
return $EmbedmentOutputHandler;
//ISystemCallback implementation
* Handles a callback from ajax application.
* @param string data Data attached to this callback
if($data ==
"SaveNamespace"){
//Does old namespace exist?
//TODO: remove illegal chars...
//Try to register new namespace
print
"Registration failed, make sure you have chosen a unique namespace.";
//Unregister current namespace (should not be able to fail)
if($this->Owner->UnregisterNamespace($OldNS)) //NOTE: a plugin can't have two namespaces due to database layout.
//TODO: remove illegal chars...
//Try to register new namespace
//Try to reregister old namespace
print
"Registration failed, make sure you have chosen a unique namespace. You still have the old namespace.";
print
"Registration failed, make sure you have chosen a unique namespace. You don't have any namespace now.";
//Not owning any namespace
//Could not unregister current namespace
$msg =
"Unregistration of current namespace failed.";
//If identifier doesn't identify the request just give a soft 404..
print
"Error: 404, data not found.";
//Implementation of IInstall
* Runs a script to complet installation
* This creates database tables, and default data.
* @return bool True if installations script went okay, otherwise return false.
$dbh =
$this->Owner->GetDatabaseHandle();
if(!mysql_query("CREATE TABLE IF NOT EXISTS `CMS3_Wiki` ( `Revision` int(11) NOT NULL auto_increment, `Identifier` varchar(255) NOT NULL, `Content` text NOT NULL, `Created` timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (`Revision`), KEY `Identifier` (`Identifier`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 AUTO_INCREMENT=5", $dbh ))
$this->Owner->LogMySQL($this->GetPluginID(), "Error during creating of tables ", $dbh);
//Implementation of IRemove
* Removes files and databases created after fysical installation
* @return bool true/false depending on success
$sql =
'DROP TABLE CMS3_Wiki';
$dbh =
$this->Owner->GetDatabaseHandle();
if(mysql_query($sql, $dbh))
$this->Owner->LogMySQL($this->GetPluginID(), "Error during deletion of database table " ,$dbh);
Documentation generated on Mon, 30 Apr 2007 01:59:11 +0200 by phpDocumentor 1.3.1