Source for file CMS3_Gallery.php
Documentation is available at CMS3_Gallery.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_Gallery
* @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 ){
//Get the image path and URL
$ImagePath =
$this->Owner->GetCMS3Path() .
"bin/" .
$this->GetPluginID() .
"/Images/";
//Check if null first, gives better performance
if($identifier !=
null &&
file_exists($ImagePath .
$identifier))
//Only view this one image
$body =
"<h1>Image: " .
$identifier .
"</h1><a href='" .
$URL .
$identifier .
"' title='Click here to see this image' target='_blank'><img src='" .
$URL .
$identifier .
"' border='0' style='max-width: 80%;'></a>";
$OutputHandler->SetBody($body);
$OutputHandler->SetTitle("Image: " .
$identifier);
foreach($Images as $Image){
if($Image !=
"." &&
$Image !=
".."){
$bodylist[] =
array("Image: " .
$Image, "<a href='" .
$Vurl .
$Image .
"' title='Click here to see this image'><img src='" .
$URL .
$Image .
"' border='0' style=\"max-height: 300px;\"></a>");
$body =
"<h1>Gallery</h1><i>Click on the images to enlarge them.</i>";
$OutputHandler->SetBody($body, $bodylist);
$OutputHandler->SetTitle("Gallery");
//Implementation of IProvidesEditor
* Gets an Ajax guide for modification of the content.
* @param IEmbedmentOutputHandler EmbedmentOutputHandler Outputhandler the content MUST be parse to.
* @param string Identifier String at the end of the URL
* @return IEmbedmentOutputHandler
public function &ModifyContent($Identifier =
null, &$EmbedmentOutputHandler){
$ImagePath =
$this->Owner->GetCMS3Path() .
"bin/" .
$this->GetPluginID() .
"/Images/";
//Initialize body variable
//Handle possible uploads
if($Identifier ==
"Upload"){
//Check for error on HTTP level
if ($_FILES["image"]["error"] >
0){
/* this is a modification of similar code found here: http://php.net/manual/en/features.file-upload.errors.php */
switch ($_FILES["image"]["error"]) {
case UPLOAD_ERR_INI_SIZE:
$msg =
"The uploaded file exceeds the upload_max_filesize directive (" .
ini_get("upload_max_filesize") .
") in php.ini.";
case UPLOAD_ERR_FORM_SIZE:
$msg =
"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
$msg =
"The uploaded file was only partially uploaded.";
$msg =
"No file was uploaded.";
case UPLOAD_ERR_NO_TMP_DIR:
$msg =
"Missing a temporary folder.";
case UPLOAD_ERR_CANT_WRITE:
$msg =
"Failed to write file to disk";
$msg =
"Unknown File Error";
$body .=
"<div id='info'><b>Upload failure:</b><br /> Filename: " .
$_FILES["image"]["name"] .
"<br />Filesize: " .
($_FILES["image"]["size"] /
1024) .
" KiB<br />".
$msg .
"</div><br />";
//Log the error to system log
$this->Owner->Log($this->GetPluginID(), "Error during upload, HTTP/php error code: " .
$msg);
if(file_exists($ImagePath .
$_FILES["image"]["name"])){
if(!unlink($ImagePath .
$_FILES["image"]["name"])){
$body .=
"<div id='info'><b>Upload failure:</b><br /> Filename: " .
$_FILES["image"]["name"] .
"<br />Filesize: " .
($_FILES["image"]["size"] /
1024) .
" KiB<br />".
$msg .
"</div><br />";
//Error deleting file, log it, continue and see what happens :)
$this->Owner->Log($this->GetPluginID(), "Unable to delete existing file, that prevents upload.");
if(move_uploaded_file($_FILES["image"]["tmp_name"], $ImagePath .
$_FILES["image"]["name"])){
$body .=
"<div id='info'><b>Upload successful:</b><br /> Filename: " .
$_FILES["image"]["name"] .
"<br />Filesize: " .
($_FILES["image"]["size"] /
1024) .
" KiB</div><br />";
$body .=
"<div id='info'><b>Upload failure:</b><br /> Filename: " .
$_FILES["image"]["name"] .
"<br />Filesize: " .
($_FILES["image"]["size"] /
1024) .
" KiB</div><br />";
$this->Owner->Log($this->GetPluginID(), "Unable to move uploaded file to image directory.");
//Handle possible deletes
}elseif(strstr($Identifier,"/")){
//Find filename to delete
$eID =
explode("/" , $Identifier, 2);
if(unlink($ImagePath .
$File)){
$body .=
"<div id='info'><b>Deletion successfyl:</b><br />The file: " .
$File .
" has been deleted.</div>";
$body .=
"<div id='info'><b>Deletion failure:</b><br />Deletion of the file " .
$File .
" has failed.</div>";
//Write an error to system log
$this->Owner->Log($this->GetPluginID(), "Failed to delete " .
$File .
" on request by user.");
$body .=
"<form method='post' enctype=\"multipart/form-data\" action='" .
$this->Owner->GetCMS3URL() .
"System/Edit/" .
$this->GetPluginID() .
"/Upload" .
"'><b>Upload:</b><br /><blockquote><input type='file' name='image' /> <input type='submit' value='Upload' /><br /><i>Settings in php.ini limits the filesize to " .
ini_get("upload_max_filesize") .
"</i></blockquote><br /><b>Delete:</b><br /><blockquote>Click on an image to delete it.</blockquote></form><span id='images'>";
$ShowURL =
$this->Owner->GetCMS3URL() .
"bin/" .
$this->GetPluginID() .
"/Images/";
$DelURL =
$this->Owner->GetCMS3URL() .
"System/Edit/" .
$this->GetPluginID() .
"/Delete/";
foreach($Images as $Image){
if($Image !=
"." &&
$Image !=
".."){
$body .=
"<a href='" .
$DelURL .
$Image .
"' title='Click here to delete this image'><img src='" .
$ShowURL .
$Image .
"' border='0' class='Gallery'></a>";
$Head =
"<style>#info {border: 1px solid #37abc8; background-color: #87cdde; padding: 3px; margin: 5px;}\n #images a:hover img {background-color: #87cdde;}\n #images img {float: left; max-width: 200px; max-height: 200px; margin: 5px; padding: 3px;}form blockquote i {font-size: 12px;}</style>";
$Head .=
"<script type=\"text/javascript\">";
$Head .=
"dojo.require(\"dojo.lfx.*\");";
$Head .=
"function HideStatus(){setTimeout(\"dojo.lfx.html.fadeOut('info', 2000).play()\", 3000);}";
$Head .=
"dojo.addOnLoad(HideStatus);";
$EmbedmentOutputHandler->ExtentHeader($Head);
$EmbedmentOutputHandler->SetBody($body);
return $EmbedmentOutputHandler;
* Gets an absolute address of an icon for this plugin
return $this->Owner->GetCMS3URL() .
"bin/" .
$this->GetPluginID() .
"/icon.png";
//Implementation of IPlugin
* Gets the pluginID of the plugin.
//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 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());
$ImagePath =
$this->Owner->GetCMS3Path() .
"bin/" .
$this->GetPluginID() .
"/Images/";
foreach($Images as $Image){
if($Image !=
"." &&
$Image !=
".."){
$Links[2][] =
array($Image, $URL .
$Image , null);
//Add toplevel array and return it
//Implementation of IRemove
* @return bool True/false depending in success
Documentation generated on Mon, 30 Apr 2007 01:59:03 +0200 by phpDocumentor 1.3.1