[Phpcms-plugins-cvs] admin4phpCMS/modules/editor class.module_editor.php,NONE,1.1 class.module_text_
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-06-18 15:17:11
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/modules/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28241/modules/editor Added Files: class.module_editor.php class.module_text_editor.php class.module_xml_editor.php Log Message: module filemanager and editor included --- NEW FILE: class.module_xml_editor.php --- <?php /** * Editor for XML-files * * <b>License</b> * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2004, Martin Jahn * @version $Id: class.module_xml_editor.php,v 1.1 2004/06/18 15:17:00 mjahn Exp $ * @package admin4phpCMS * @subpackage module_editor **/ /* * $Log: class.module_xml_editor.php,v $ * Revision 1.1 2004/06/18 15:17:00 mjahn * module filemanager and editor included * */ /** * include PEAR:XML_Tree for parsing of XML-files **/ include_once ('XML/Tree.php'); /** * XML editor class * * This class provides an interface for editing XML-files. * * @package admin4phpCMS * @subpackage module_editor * @inheriteddoc **/ class module_xml_editor extends module { function init () { $this->_registerEvent ('DISPLAY_VIEWER', 'doDisplayViewer'); $this->_registerAction ('doDisplayViewer', 'viewFile'); $this->_registerEvent ('DISPLAY_EDITOR', 'doDisplayEditor'); $this->_registerAction ('doDisplayEditor', 'editFile'); $this->_registerEvent ('EDITOR_SAVE_FILE', 'doEditorSaveFile'); $this->_registerAction ('doEditorSaveFile', 'saveFile'); } /** * save the data from the formular into the XML-file * * @param string $actiondata $actiondata['filename'] must provide the filename * @return boolean true if file was saved successful **/ function saveFile (&$actiondata) { $filename = $actiondata ['filename']; if (!isset($filename)) { $actiondata = array ('errortext'=>'Datei '.$filename.' konnte nicht geladen werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } if (!file_exists ($filename)) { $actiondata = array ('errortext'=>'Layoutdatei '.$filename.' konnte nicht geladen werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } $this->filename = $filename; $XML =& new XML_Tree ($this->filename); $this->_file =& $XML->getTreeFromFile (); return true; $fh = @fopen ($filename, 'wb'); if ($fh === false) { fclose ($fh); $actiondata = array ('errortext'=>'Konnte nicht in die Zieldatei '.$this->filename.' schreiben! (fehlende Schreibrechte)'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } fwrite ($fh, $this->_file->get ()); fclose ($fh); return true; } function viewFile (&$actiondata) { $this->filename = $actiondata ['_filename']; $data = file ($this->filename); $i = 0; foreach ($data as $line) { $actiondata = array ('_id'=>'line'.$i, '_root'=>$actiondata ['_root'], '_type'=>'empty', 'class'=>'', 'id'=>'', 'content'=>htmlentities ($line).'<br />'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $i++; } } /** * display the editform for the XML-data * * @param array $actiondata $actiondata ['filename'] must provide the filename **/ function editFile (&$actiondata) { $this->filename = $actiondata ['_filename']; // set container for fileviewer $actiondata = array ('_root'=>$actiondata ['_root'], '_id'=>'columns', '_type'=>'column_block', 'id'=>'spalten', 'class'=>''); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); // set container for XML-Tree $actiondata = array ('_root'=>'columns', '_id'=>'file-edit-tree-column', '_type'=>'column', 'id'=>'', 'class'=>''); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); // set list-container for XML-Tree $actiondata = array ('_root'=>'file-edit-tree-column', '_id'=>'file-edit-tree', '_type'=>'ulist', 'id'=>'', 'class'=>''); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); // set container for input-fields $actiondata = array ('_root'=>'columns', '_id'=>'file-edit-input', '_type'=>'column', 'id'=>'', 'class'=>''); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $XML =& new XML_Tree ($this->filename); $this->_file =& $XML->getTreeFromFile (); //print_r ($this->_file); $this->displayNode ($this->_file, 'file-edit-tree', 'file-edit-tree-0', 'file-edit-input'); } /** * walk recursive through the XML-structure and display the XML-data * * @param XML_Tree $node the element of the XML-Tree * @param string $root the id of the parental-element * @param string $node_id the id of the current node * @param string $input_id the id of the input-field-container **/ function displayNode (&$node, $root, $node_id, $input_id) { if (isset ($node->name) && $node->name != '') { $actiondata = array ('_id'=>$node_id, '_root'=>$root, '_type'=>'list_entry', 'class'=>'', 'id'=>''); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $actiondata = array ('_id'=>$node_id.'-link', '_root'=>$node_id, '_type'=>'link', 'class'=>'', 'id'=>'', 'content'=>$node->name, 'href'=>'#'.$node_id); if (isset ($node->attributes['name'])) { $actiondata ['title'] = $node->attributes['name']; } $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $actiondata = array ('_id'=>$node_id.'-name', '_root'=>$node_id.'-link', '_type'=>'empty', 'class'=>'', 'id'=>'', 'content'=>$node->name); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $actiondata = array ('_id'=>$node_id.'-block', '_root'=>$input_id, '_type'=>'block', 'class'=>'', 'id'=>$node_id); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $actiondata = array ('_id'=>$node_id.'-set', '_root'=>$node_id.'-block', '_type'=>'form_fieldset', 'class'=>'', 'id'=>'', 'title'=>$node->name); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); foreach ($node->attributes as $name=>$value) { $actiondata = array ('_id'=>$node_id.'-'.$name, '_root'=>$node_id.'-set', '_type'=>'form_input_text', 'extra'=>'id="'.$node_id.'-'.$name.'" ', 'name'=>$node_id.'-'.$name, 'value'=>htmlentities ($value), 'label'=>$name); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); } $actiondata = array ('_id'=>$node_id.'-content', '_root'=>$node_id.'-set', '_type'=>'form_textarea', 'name'=>$node_id.'-content', 'extra'=>'id="'.$node_id.'-content" ', 'value'=>htmlentities ($node->content), 'label'=>'content'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); } if (isset ($node->children) && is_array ($node->children) && count ($node->children) > 0) { $actiondata = array ('_id'=>$node_id.'-sub', '_root'=>$node_id, '_type'=>'ulist', 'class'=>'', 'id'=>''); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $num = count ($node->children); for ($i = 0; $i < $num; $i++) { $this->displayNode ($node->children[$i], $node_id.'-sub', $node_id.'-'.$i, $input_id); } } } } /* 12 ma 12 deu 8 bio */ ?> --- NEW FILE: class.module_text_editor.php --- <?php /** * Editor for Text-files * * <b>License</b> * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2004, Martin Jahn * @version $Id: class.module_text_editor.php,v 1.1 2004/06/18 15:17:00 mjahn Exp $ * @package admin4phpCMS * @subpackage module_editor **/ /* * $Log: class.module_text_editor.php,v $ * Revision 1.1 2004/06/18 15:17:00 mjahn * module filemanager and editor included * */ /** * include PEAR:XML_Tree for parsing of XML-files **/ include_once ('XML/Tree.php'); /** * Text editor class * * This class provides an interface for editing Text-files. * * @package admin4phpCMS * @subpackage module_editor * @inheriteddoc **/ class module_text_editor extends module { function init () { $this->_registerEvent ('DISPLAY_VIEWER', 'doDisplayViewer'); $this->_registerAction ('doDisplayViewer', 'viewFile'); $this->_registerEvent ('DISPLAY_EDITOR', 'doDisplayEditor'); $this->_registerAction ('doDisplayEditor', 'editFile'); } /** * Open a XML-file * * @param string $filename Contains the path of the XML-file to edit * @return boolean true if XML-file was opened successful **/ function openfile ($filename) { if (!isset($filename)) { $actiondata = array ('errortext'=>'Datei '.$filename.' konnte nicht geladen werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } if (!file_exists ($filename)) { $actiondata = array ('errortext'=>'Layoutdatei '.$filename.' konnte nicht geladen werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } $this->filename = $filename; $XML =& new XML_Tree ($this->filename); $this->_file =& $XML->getTreeFromFile (); return true; } /** * save the data from the formular into the XML-file * * @param string $filename Contains the path where to save the XML-file * @return boolean true if file was saved successful **/ function savefile ($filename = '') { if (!isset ($this->_file)) { $actiondata = array ('errortext'=>'Keine XML-Daten zum Speichern vorhanden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } if ($filename != '' && file_exists ($filename) && is_writeable ($filename)) { $this->filename = $filename; } $fh = @fopen ($filename, 'wb'); if ($fh === false) { fclose ($fh); $actiondata = array ('errortext'=>'Konnte nicht in die Zieldatei '.$this->filename.' schreiben! (fehlende Schreibrechte)'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return false; } fwrite ($fh, $this->_file->get ()); fclose ($fh); } function viewFile (&$actiondata) { $this->filename = $actiondata ['_filename']; $data = file ($this->filename); $i = 0; foreach ($data as $line) { $actiondata = array ('_id'=>'line'.$i, '_root'=>$actiondata ['_root'], '_type'=>'empty', 'content'=>htmlentities ($line)); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $i++; } } function editFile (&$actiondata) { $this->filename = $actiondata ['_filename']; $data = file ($this->filename); $actiondata = array ('_id'=>'edit-file', '_root'=>$actiondata ['_root'], '_type'=>'form_textarea', 'value'=>join ('', $data)); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); } } ?> --- NEW FILE: class.module_editor.php --- <?php /** * The filemanager-module * * This module is based on the package PEAR::LiveUser. * * <b>License</b> * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2004, Martin Jahn * @version $Id: class.module_editor.php,v 1.1 2004/06/18 15:17:00 mjahn Exp $ * @package admin4phpCMS * @subpackage module_editor **/ /* * $Log: class.module_editor.php,v $ * Revision 1.1 2004/06/18 15:17:00 mjahn * module filemanager and editor included * */ require('classes/CropImage.php'); /** * Editor-class * * @package admin4phpCMS * @subpackage module_editor * @uses file_editor **/ class module_editor extends module { function init () { // connect to actions $this->_registerEvent ('EDITOR_EDIT_FILE', 'doEditFile'); $this->_registerAction ('doEditFile', 'editFile'); $this->_registerAction ('EDITOR_VIEW_FILE', 'doViewFile'); $this->_registerAction ('doViewFile', 'viewFile'); $this->_registerAction ('doParseParam', 'parseParam'); $this->_registerAction ('doProcess', 'process'); $this->docroot = realpath ($_SERVER['DOCUMENT_ROOT']); $actiondata = array ('module'=>'editor'); $this->_callEvent ('CONFIG_GET', $actiondata); $this->CONF =& $actiondata ['config']; } /** * @param array $actiondata **/ function parseParam (&$actiondata) { // check if we have to display our content $this->display = (isset ($actiondata['request']['moduleid']) && $actiondata['request']['moduleid'] == 'editor'); // initialize variables $this->viewfile = ''; $this->editfile = ''; $this->action = ''; // get the action if (isset ($actiondata['request']['action'])) { $this->action = $actiondata['request']['action']; } // get the filename of the file to view if ($this->action == 'viewfile' && isset ($actiondata['request']['file'])) { $this->filename = realpath ($this->docroot.'/'.$actiondata['request']['file']); } // get the filename of the file to edit if ($this->action == 'editfile' && isset ($actiondata['request']['file'])) { $this->filename = realpath ($this->docroot.'/'.$actiondata['request']['file']); } if (isset ($this->filename) && strpos ($this->filename, $this->docroot) === false) { $this->filename = ''; $this->action = ''; $actiondata = array ('errortext'=>'Die Datei befindet sich außerhalb des erlaubten Bereiches!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); } } /** * @param array $actiondata **/ function process (&$actiondata) { $actiondata = array(); $this->_callEvent ('USER_GET_STATUS', $actiondata); $this->_USER = $actiondata; if (!$this->_USER['isLoggedIn']) { return true; } if (!isset ($this->filename) || $this->filename == '') { return true; } // check if the file exists if (!file_exists ($this->filename)) { $actiondata = array ('errortext'=>'Die Datei '.$this->filename.' existiert nicht!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return true; } // check if the file is readable if (!is_readable ($this->filename)) { $actiondata = array ('errortext'=>'Die Datei '.$filename.' kann nicht geöffnet werden!'); $this->_callEvent ('ERROR_NOTICE', $actiondata); return true; } // get the filesystem path to the file $this->webname = str_replace ($this->docroot, '', $this->filename); // extract the extension from filename $this->ext = strtolower (substr ($this->filename, strrpos ($this->filename, '.')+1)); // load correct editor-module into framework switch ($this->ext) { // imagetypes case 'png': case 'jpg': case 'jpeg': case 'gif': case 'bmp': case 'ico': $this->filetype = 'image'; break; case 'xml': $this->filetype = 'xml'; break; default: $this->filetype = 'text'; break; } $actiondata = array ('filename'=>dirname(__FILE__).'/class.module_'.$this->filetype.'_editor.php', 'class'=>'module_'.$this->filetype.'_editor'); $this->_callEvent ('LOAD_MODULE', $actiondata); $actiondata = array ('filename'=>$this->filename); $this->_callEvent ('EDITOR_SAVE_FILE', $actiondata); switch ($this->action) { case 'viewfile': $this->_registerAction ('doParseContent', 'getViewContent'); break; case 'editfile': $this->_registerAction ('doParseContent', 'getEditContent'); break; default: break; } } function getViewContent (&$actiondata) { $actiondata = array ('_id'=>'headline1', '_root'=>$actiondata['_root'], '_type'=>'headline', 'content'=>$this->filename); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); // set container for fileviewer $actiondata = array ('_root'=>$actiondata ['_root'], '_id'=>'fileviewer', '_type'=>'block', 'extra'=>'id="fileviewer"'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $actiondata = array ('_root'=>'fileviewer', '_filename'=>$this->filename); $this->_callEvent ('DISPLAY_VIEWER', $actiondata); } function getEditContent (&$actiondata) { $actiondata = array ('_id'=>'headline1', '_root'=>$actiondata['_root'], '_type'=>'headline', 'content'=>$this->filename); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); // set formular for fileviewer $actiondata = array ('_root'=>$actiondata ['_root'], '_id'=>'file-edit-form', '_type'=>'form', 'action'=>'', 'method'=>'post'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata); $actiondata = array ('_root'=>'file-edit-form', '_filename'=>$this->filename); $this->_callEvent ('DISPLAY_EDITOR', $actiondata); } } ?> |