[pLog-svn] r1229 - in plugins/trunk/templateeditor: . class class/action class/file class/file/filecontents class/view js js/editor templates

mark at devel.plogworld.net mark at devel.plogworld.net
Sun Feb 27 16:18:48 GMT 2005


Author: mark
Date: 2005-02-27 16:18:48 +0000 (Sun, 27 Feb 2005)
New Revision: 1229

Added:
   plugins/trunk/templateeditor/class/action/pluginsiteupdatetemplatefileaction.class.php
   plugins/trunk/templateeditor/class/file/
   plugins/trunk/templateeditor/class/file/filecontents/
   plugins/trunk/templateeditor/class/file/filecontents/file_get_contents.php
   plugins/trunk/templateeditor/class/file/filecontents/file_put_contents.php
   plugins/trunk/templateeditor/class/file/myfile.class.php
   plugins/trunk/templateeditor/js/
   plugins/trunk/templateeditor/js/editor/
   plugins/trunk/templateeditor/js/editor/sample.html
   plugins/trunk/templateeditor/js/editor/smartyeditor.css
   plugins/trunk/templateeditor/js/editor/smartyeditor.js
Modified:
   plugins/trunk/templateeditor/class/action/pluginsiteedittemplatefileaction.class.php
   plugins/trunk/templateeditor/class/action/pluginsitetemplatesetslistaction.class.php
   plugins/trunk/templateeditor/class/action/pluginsitetemplateslistaction.class.php
   plugins/trunk/templateeditor/class/view/pluginsiteedittemplatefileview.class.php
   plugins/trunk/templateeditor/plugintemplateeditor.class.php
   plugins/trunk/templateeditor/templates/siteedittemplatefile.template
Log:
1. Add update function to template editor
2. Add MyFile Class to handle file_gets_content and file_puts_content (Also add the compatiable file from pear php_compat project)
3. Add a new SmartyEditor (based on pLogEditor) for add new smarty tag support.

Todo:
1. Error handling when file and not read or write
2. Add smarttag to smartyeditor

Modified: plugins/trunk/templateeditor/class/action/pluginsiteedittemplatefileaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginsiteedittemplatefileaction.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/action/pluginsiteedittemplatefileaction.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -1,20 +1,20 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
 	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsiteedittemplatefileview.class.php" );
 
 	/**
 	 * shows a form with the current configuration
 	 */
-	class PluginSiteEditTemplateFileAction extends AdminAction
+	class PluginSiteEditTemplateFileAction extends SiteAdminAction
 	{
         var $_templateId;        
         var $_fileId;
         		
 		function PluginSiteEditTemplateFileAction( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->SiteAdminAction( $actionInfo, $request );
 		}
 		
 		function perform()

Modified: plugins/trunk/templateeditor/class/action/pluginsitetemplatesetslistaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginsitetemplatesetslistaction.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/action/pluginsitetemplatesetslistaction.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -1,18 +1,18 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
 	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsitetemplatesetslistview.class.php" );
 
 	/**
 	 * shows a form with the current configuration
 	 */
-	class PluginSiteTemplateSetsListAction extends AdminAction
+	class PluginSiteTemplateSetsListAction extends SiteAdminAction
 	{
 		
 		function PluginSiteTemplateSetsListAction( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->SiteAdminAction( $actionInfo, $request );
 		}
 		
 		function perform()

Modified: plugins/trunk/templateeditor/class/action/pluginsitetemplateslistaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginsitetemplateslistaction.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/action/pluginsitetemplateslistaction.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -1,19 +1,19 @@
 <?php
 
-	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
 	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsitetemplateslistview.class.php" );
 
 	/**
 	 * shows a form with the current configuration
 	 */
-	class PluginSiteTemplatesListAction extends AdminAction
+	class PluginSiteTemplatesListAction extends SiteAdminAction
 	{
         var $_templateId;
         		
 		function PluginSiteTemplatesListAction( $actionInfo, $request )
 		{
-			$this->AdminAction( $actionInfo, $request );
+			$this->SiteAdminAction( $actionInfo, $request );
 		}
 		
 		function perform()

Added: plugins/trunk/templateeditor/class/action/pluginsiteupdatetemplatefileaction.class.php
===================================================================
--- plugins/trunk/templateeditor/class/action/pluginsiteupdatetemplatefileaction.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/action/pluginsiteupdatetemplatefileaction.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,64 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsiteedittemplatefileview.class.php" );
+	include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/view/pluginsitetemplateslistview.class.php" );
+	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
+    include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );	
+    include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );	
+
+	/**
+	 * shows a form with the current configuration
+	 */
+	class PluginSiteUpdateTemplateFileAction extends SiteAdminAction
+	{
+        var $_fileContent;
+        var $_templateId;        
+        var $_fileId;
+        		
+		function PluginSiteUpdateTemplateFileAction( $actionInfo, $request )
+		{
+			$this->SiteAdminAction( $actionInfo, $request );
+			
+            $this->_templateId = $this->_request->getValue( "templateId" );
+            $this->_fileId = $this->_request->getValue( "fileId" );
+
+			$this->registerFieldValidator( "fileContent", new StringValidator());
+			$this->registerFieldValidator( "templateId", new StringValidator());
+			$this->registerFieldValidator( "fileId", new StringValidator());
+
+        	$view = new PluginSiteEditTemplateFileView( $this->_blogInfo, $this->_templateId, $this->_fileId );
+        	$view->setErrorMessage( $this->_locale->tr("error_updating_post"));
+        	$this->setValidationErrorView( $view );			
+		}
+		
+		function perform()
+		{
+			$this->_fileContent = $this->_request->getValue( "fileContent" );
+			
+			// get a list with all the specific template files 
+        	$ts = new TemplateSetStorage();
+            
+            $blogId = $this->_blogInfo->getId();
+            $templateFolder = $ts->getTemplateFolder($this->_templateId);
+            
+            $filename = $templateFolder . $this->_fileId;
+        	$file = new MyFile($filename);
+            $fileContent = $file->writeFileContent( stripslashes($this->_fileContent) );
+
+			// if everything went ok...
+            $this->_session->setValue( "blogInfo", $this->_blogInfo );
+            $this->saveSession();
+            
+			$this->_view = new PluginSiteTemplatesListView( $this->_blogInfo, $this->_templateId );
+			$this->_view->setSuccessMessage( $this->_locale->tr("templateeditor_file_saved_ok"));
+			$this->setCommonData();
+			
+			// clear the cache
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+            
+            return true;
+		}
+	}
+?>
\ No newline at end of file

Added: plugins/trunk/templateeditor/class/file/filecontents/file_get_contents.php
===================================================================
--- plugins/trunk/templateeditor/class/file/filecontents/file_get_contents.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/file/filecontents/file_get_contents.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,56 @@
+<?php
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license,       |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/3_0.txt.                                  |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license at php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Authors: Aidan Lister <aidan at php.net>                                |
+// +----------------------------------------------------------------------+
+//
+// $Id: file_get_contents.php,v 1.20 2004/11/14 16:10:50 aidan Exp $
+
+
+/**
+ * Replace file_get_contents()
+ *
+ * @category    PHP
+ * @package     PHP_Compat
+ * @link        http://php.net/function.file_get_contents
+ * @author      Aidan Lister <aidan at php.net>
+ * @version     $Revision: 1.20 $
+ * @internal    resource_context is not supported
+ * @since       PHP 5
+ * @require     PHP 4.0.1 (trigger_error)
+ */
+if (!function_exists('file_get_contents')) {
+    function file_get_contents($filename, $incpath = false, $resource_context = null)
+    {
+        if (false === $fh = fopen($filename, 'rb', $incpath)) {
+            trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
+            return false;
+        }
+
+        clearstatcache();
+        if ($fsize = @filesize($filename)) {
+            $data = fread($fh, $fsize);
+        } else {
+            $data = '';
+            while (!feof($fh)) {
+                $data .= fread($fh, 8192);
+            }
+        }
+
+        fclose($fh);
+        return $data;
+    }
+}
+
+?>
\ No newline at end of file

Added: plugins/trunk/templateeditor/class/file/filecontents/file_put_contents.php
===================================================================
--- plugins/trunk/templateeditor/class/file/filecontents/file_put_contents.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/file/filecontents/file_put_contents.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,102 @@
+<?php
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 3.0 of the PHP license,       |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/3_0.txt.                                  |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license at php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Authors: Aidan Lister <aidan at php.net>                                |
+// +----------------------------------------------------------------------+
+//
+// $Id: file_put_contents.php,v 1.22 2004/11/14 16:10:50 aidan Exp $
+
+
+if (!defined('FILE_USE_INCLUDE_PATH')) {
+    define('FILE_USE_INCLUDE_PATH', 1);
+}
+
+if (!defined('FILE_APPEND')) {
+    define('FILE_APPEND', 8);
+}
+
+
+/**
+ * Replace file_put_contents()
+ *
+ * @category    PHP
+ * @package     PHP_Compat
+ * @link        http://php.net/function.file_put_contents
+ * @author      Aidan Lister <aidan at php.net>
+ * @version     $Revision: 1.22 $
+ * @internal    resource_context is not supported
+ * @since       PHP 5
+ * @require     PHP 4.0.1 (trigger_error)
+ */
+if (!function_exists('file_put_contents')) {
+    function file_put_contents($filename, $content, $flags = null, $resource_context = null)
+    {
+        // If $content is an array, convert it to a string
+        if (is_array($content)) {
+            $content = implode('', $content);
+        }
+
+        // If we don't have a string, throw an error
+        if (!is_scalar($content)) {
+            trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING);
+            return false;
+        }
+
+        // Get the length of date to write
+        $length = strlen($content);
+
+        // Check what mode we are using
+        $mode = ($flags & FILE_APPEND) ?
+                    $mode = 'a' :
+                    $mode = 'w';
+
+        // Check if we're using the include path
+        $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ?
+                    true :
+                    false;
+
+        // Open the file for writing
+        if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) {
+            trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING);
+            return false;
+        }
+
+        // Write to the file
+        $bytes = 0;
+        if (($bytes = @fwrite($fh, $content)) === false) {
+            $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s',
+                            $length,
+                            $filename);
+            trigger_error($errormsg, E_USER_WARNING);
+            return false;
+        }
+
+        // Close the handle
+        @fclose($fh);
+
+        // Check all the data was written
+        if ($bytes != $length) {
+            $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.',
+                            $bytes,
+                            $length);
+            trigger_error($errormsg, E_USER_WARNING);
+            return false;
+        }
+
+        // Return length
+        return $bytes;
+    }
+}
+
+?>
\ No newline at end of file

Added: plugins/trunk/templateeditor/class/file/myfile.class.php
===================================================================
--- plugins/trunk/templateeditor/class/file/myfile.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/file/myfile.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,30 @@
+<?php
+     include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/filecontents/file_get_contents.php" );
+     include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/filecontents/file_put_contents.php" );
+     include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+
+     class MyFile extends File
+     {
+
+         function MyFile( $fileName )
+         {
+             $this->File($fileName);
+         }
+         
+         function readFileContent()
+         {
+             //$contents = file_get_contents( $this->_fileName );
+             $contents = $this->readFile();
+             $contents = implode("\n" , $contents);
+                          
+             return $contents;
+         }
+         
+         function writeFileContent( $contents )
+         {
+             $bytes = file_put_contents( $this->_fileName, $contents );
+             
+             return $bytes;
+         }
+     }
+?>

Modified: plugins/trunk/templateeditor/class/view/pluginsiteedittemplatefileview.class.php
===================================================================
--- plugins/trunk/templateeditor/class/view/pluginsiteedittemplatefileview.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/class/view/pluginsiteedittemplatefileview.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -2,7 +2,7 @@
 	
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
 	include_once( PLOG_CLASS_PATH."class/template/templatesets/templatesetstorage.class.php" );		
-    include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
+    include_once( PLOG_CLASS_PATH."plugins/templateeditor/class/file/myfile.class.php" );
 
 	/**
 	 * implements the main view of the feed reader plugin
@@ -30,11 +30,11 @@
             
             $filename = $templateFolder . $this->_fileId;
 			// get a list with all the global template sets
-        	$file = new File($filename);
+        	$file = new MyFile($filename);
             
-            $fileContent = $file->readFile();
+            $fileContent = $file->readFileContent();
             
-            $fileContent = implode("\n" , $fileContent);
+            //$fileContent = implode("\n" , $fileContent);
 
             $this->setValue( "currentTemplate", $this->_templateId );
             $this->setValue( "currentFile", $this->_fileId );

Added: plugins/trunk/templateeditor/js/editor/sample.html
===================================================================
--- plugins/trunk/templateeditor/js/editor/sample.html	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/js/editor/sample.html	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,22 @@
+<html>
+<head>
+<link rel="stylesheet" href="plogeditor.css" type="text/css">
+<script type="text/javascript" src="plogeditor.js"></script>
+<script type="text/javascript">
+ // our images are located somewhere else...
+ var baseImageFolder='/devel/js/htmlarea/images';
+</script>
+</head>
+<body>
+<h1>pLogEditor Javascript Sample</h1>
+<form name="textEditor" id="textEditor">
+text1:<br/>
+<script type="text/javascript">ed1 = new pLogEditor('text1', 'ed1');</script>
+<textarea id="text1" name="text1" rows="8" cols="60"></textarea>
+<br/>text2:<br/>
+<script type="text/javascript">ed2 = new pLogEditor('text2', 'ed2');</script>
+<textarea id="text2" name="text1" rows="8" cols="60"></textarea>
+</form>
+</body>
+</script>
+</html>

Added: plugins/trunk/templateeditor/js/editor/smartyeditor.css
===================================================================
--- plugins/trunk/templateeditor/js/editor/smartyeditor.css	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/js/editor/smartyeditor.css	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,61 @@
+.textEditorToolbar {
+  cursor: default;
+  background: ButtonFace;
+  padding: 1px 1px 1px 1px;
+  border: 1px solid;
+  border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
+  width: 100%;
+  height: 20px;
+}
+
+.pressedButton {
+  border: 1px solid;
+  border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
+  margin-left:2px;
+  margin-bottom: 2px;
+  color: ButtonText;  
+  padding: 0px;  
+  width: 18px;
+  height: 18px;
+}
+
+.normalButton {
+  border: 1px ButtonFace solid;
+  margin-left:3px;
+  margin-bottom: 3px;  		
+  color: ButtonText;  
+  padding: 0px;
+  width: 18px;
+  height: 18px;    
+}
+
+.buttonHover {
+  border: 1px solid;
+  border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
+  margin-left:3px;
+  margin-bottom: 3px;  
+  padding: 0px;
+  width: 18px;
+  height: 18px;    
+}
+
+.separator {
+  margin-bottom: 3px;
+  margin-left: 3px;
+  margin-right: 3px;
+  margin-top: 0px;
+  border-left: 1px solid ButtonShadow;
+  border-right: 1px solid ButtonHighlight;
+  width: 0px;
+  height: 16px;
+  padding: 0px;
+  position:relative;
+  top: -9px;
+}
+
+.editorDropDownList {
+ position: relative;
+ top: -9px;
+ padding: 0px;
+ margin: 0px;
+}

Added: plugins/trunk/templateeditor/js/editor/smartyeditor.js
===================================================================
--- plugins/trunk/templateeditor/js/editor/smartyeditor.js	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/js/editor/smartyeditor.js	2005-02-27 16:18:48 UTC (rev 1229)
@@ -0,0 +1,731 @@
+/**
+ * SmartyEditor.js (Based on pLogEditor.js)
+ *
+ * Non-wysiwyg javascript-based editor for textarea controls in browsers. It works in
+ * exactly the same as HTMLArea control but instead of graphically showing the contents
+ * of the post, works based on raw html code. It does not offer as many features as
+ * htmlarea but it does offer some other things as customizable toolbars, support
+ * for text selections and ranges, etc. It should work in every major browser with
+ * some support for DOM and DHTML.
+ * It is very loosely based on Alex King's js_quicktags.js which is also used in Wordpress.
+ * However, js_quicktags has the limitation that it can only work with one textarea per page
+ * and plog for example needs two in the "new post" page. The code is javascript with OOP
+ * so it might look a bit weird at first...
+ * This code is licensed under the terms of the GPL license.
+ *
+ * -- Installation and usage --
+ *
+ * Place this file somewhere in your web server tree and from your html files, call it like
+ * <html>
+ *  <head>
+ *   <link rel="stylesheet" href="smartyeditor.css" type="text/css">
+ *   <script type="text/javascript" src="smartyeditor.js"></script>
+ *   <script type="text/javascript">
+ *    // define where your images are...
+ *    var baseImageFolder='/devel/js/htmlarea/images';
+ *   </script>
+ *  </head>
+ *  <body>
+ *   <h1>SmartyEditor Javascript Sample</h1>
+ *   <form name="textEditor" id="textEditor">
+ *    text1:<br/>
+ *    <script type="text/javascript">ed1 = new SmartyEditor('text1', 'ed1');</script>
+ *    <textarea id="text1" name="text1" rows="8" cols="60"></textarea>
+ *    <br/>text2:<br/>
+ *    <script type="text/javascript">ed2 = new SmartyEditor('text2', 'ed2');</script>
+ *    <textarea id="text2" name="text1" rows="8" cols="60"></textarea>
+ *   </form>
+ *  </body>
+ * </html>
+ *
+ * Create a new SmartyEditor object in the place where you would like to show the 
+ * toolbar of the editor. The first paramter for the constructor is the value of the 'id'
+ * attribute of the textarea that will be the content area for the toolbar. The second parameter
+ * is the name of the object itself, so if you are creating an editor called 'myEditor', the second
+ * parameter will be 'myEditor'
+ *
+ * Please set the value of baseImageFolder to the base path where your icons are stored.
+ */
+ 
+ 
+/**
+ * please change this if your icons are somewhere else!
+ */
+var baseImageFolder = 'js/htmlarea/images/';
+
+/**
+ * represents a button from our toolbar
+ *
+ * @param id
+ * @param display
+ * @param tagStart
+ * @param tagEnd
+ * @param icon
+ * @param open
+ */
+edButton = function(id, display, tagStart, tagEnd, icon, open) 
+{
+	this.id = id;				// used to name the toolbar button
+	this.display = display;		// label on button
+	this.tagStart = tagStart; 	// open tag
+	this.tagEnd = tagEnd;		// close tag
+	this.open = open;			// set to -1 if tag does not need to be closed
+	this.isOpen = false;
+	this.icon = icon;
+	this.htmlId = '';
+	this.currentStatus = 'normalButton';
+	
+	/**
+	 * renders the button
+	 *
+	 * @param txtId
+	 * @return nothing
+	 */
+	this.show = function(txtId, objName)
+	{
+		// a very simple document.write...
+		this.htmlId = txtId + '_' + this.id;
+		var buttonText = '<img src="'+baseImageFolder+'/'+this.icon+'" id="' + txtId + '_' + this.id + '" class="normalButton" onmouseout="'+objName+'.mouseOut(\'' + txtId + '\', \'' + this.id + '\');" onmouseover="'+objName+'.mouseOver(\'' + txtId + '\', \'' + this.id + '\');" onclick="'+objName+'.execute(\'' + txtId + '\', \'' + this.id + '\', null );" alt = "' + this.display + '" />';
+		
+		return(buttonText);
+	}
+	
+	/**
+	 * returns the html element to which this button is associated
+	 *
+	 * @return an html element
+	 */
+	this.getHtmlButton = function()
+	{
+		return document.getElementById( this.htmlId );	
+	}
+	
+	/**
+	 * whether this button needs to be closed or not
+	 *
+	 * @return True whether it needs to be closed or false otherwise
+	 */
+	this.needsClose = function()
+	{
+		return( this.open != -1 );
+	}
+	
+	/**
+	 * handler for the onMouseOver event, changes the colour of the borders
+	 */
+	this.mouseOver = function()
+	{
+		htmlButton = this.getHtmlButton();
+		htmlButton.className = 'buttonHover';
+	}
+	
+	/** 
+	 * handler for the onMouseOut event, returns the button to its original state
+	 */
+	this.mouseOut = function()
+	{
+		htmlButton = htmlButton = this.getHtmlButton();		
+		htmlButton.className = this.currentStatus;
+	}
+	
+	/**
+	 * checks/unchecks the button
+	 */
+	this.toggle = function()
+	{
+		htmlButton = this.getHtmlButton();
+
+	 	// change its class and save it for later use...
+	 	if( this.currentStatus == 'pressedButton' )
+	 		this.currentStatus = 'normalButton';
+	 	else
+	 		this.currentStatus = 'pressedButton';
+	 		
+	 	htmlButton.className = this.currentStatus;
+	}
+	
+	/**
+	 * performs the button's action
+	 *
+	 * @param txtId
+	 * @return nothing
+	 */
+	this.execute = function( txtId, param )
+	{
+		var text = '';
+		
+		// check if the tag needs a closing tag
+		if( this.open == -1 ) {
+			// it doesnt...
+			text = this.tagStart;
+		}
+		else {
+			// it does...
+			if( this.isOpen )
+				text = this.tagEnd;
+			else
+				text = this.tagStart;
+			
+			// change the status of the button
+			this.isOpen = !this.isOpen;			
+		}
+		
+		// change the look of the button
+		if( this.open != -1 ) {
+		    this.toggle();
+		}
+
+		// return the text to be added
+		return text;
+	}
+
+	/**
+	 * special callback function that is executed when the main editor would like to 
+	 * surround the current selection in the browser
+	 *
+	 * @param txtId the textarea id
+	 */	
+	this.surround = function( txtId, param )
+	{
+		surroundInfo = Array()
+		surroundInfo['start'] = this.tagStart;
+		surroundInfo['end'] = this.tagEnd;
+		
+		return surroundInfo;
+	}
+	
+	this.toString = function()
+	{
+		objSignature = this.id + ' Button';
+		return( objSignature );
+	}
+}
+
+/**
+ * visual separators for the toolbar are also implemented as buttons, but they do
+ * do nothing and only show a vertical bar anyway with some margin on both sides...
+ */ 
+edButtonSeparator = function()
+{
+	this.prototype = new edButton('separator', '', '', '', '', -1 );
+	this.prototype.constructor = edButton;
+	this.superclass = edButton;
+	
+	this.superclass('separator', '', '', '', '', -1 );
+	
+	/**
+	 * draws a vertical line
+	 */
+	this.show = function( txtId, objName )
+	{
+		separatorCode = '<span class="separator"></span>';
+		
+		return( separatorCode );
+	}
+}
+
+/**
+ * special button that only adds a link
+ *
+ * @param id
+ * @param display
+ * @param icon
+ */
+edButtonLink = function(id, display, icon) 
+{
+	//
+	// strange javascript thingies used for object inheritance...
+	//
+	this.prototype = new edButton(id, display, '', '', icon, -1 );
+	this.prototype.constructor = edButton;
+	this.superclass = edButton;
+	
+	this.superclass(id, display, '', '', icon, -1 );
+
+	/**
+	 * function redefined from above so that users can type links
+	 *
+	 * @param txtId
+	 */
+	this.execute = function( txtId, param )
+	{		
+		this.toggle();
+		
+		linkText = prompt('Enter the link text: ');
+		if( linkText == null ) {
+			this.toggle();
+			return '';
+		}
+		
+		linkDest = prompt('Enter the destination for the link:');
+		if( linkDest == null ) {
+			this.toggle();
+			return '';
+		}
+
+		this.toggle();		
+
+		// if everything went fine, add the link and return
+		var linkTag = '<a href="' + linkDest + '">' + linkDest + '</a>'; 
+		return linkTag;
+	}
+	
+	/**
+	 * special behaviour for this function... It will only ask for the link destination
+	 * and surround the current selection with the user's input
+	 *
+	 * @param txtId
+	 */
+	this.surround = function( txtId, param )
+	{
+		surroundInfo = Array();
+		surroundInfo['start'] = '';
+		surroundInfo['end'] = '';		
+		
+		this.toggle();
+		linkDest = prompt('Enter the destination for the link:');
+		if( linkDest == null ) {
+			this.toggle();
+			return surroundInfo;
+		}
+		
+		surroundInfo['start'] = '<a href="' + linkDest + '">';
+		surroundInfo['end'] = '</a>';
+		
+		this.toggle();
+		
+		return surroundInfo;
+	}
+}
+
+/**
+ * special button that only adds a link
+ *
+ * @param id
+ * @param display
+ * @param icon
+ */
+edButtonBr = function(id, display, icon) 
+{
+	//
+	// strange javascript thingies used for object inheritance...
+	//
+	this.prototype = new edButton(id, display, '', '', icon, -1 );
+	this.prototype.constructor = edButton;
+	this.superclass = edButton;
+	
+	this.superclass(id, display, '<br />', '', icon, -1 );
+
+	/**
+	 * special behaviour for this function... It will only ask for the link destination
+	 * and surround the current selection with the user's input
+	 *
+	 * @param txtId
+	 */
+	this.surround = function( txtId, param )
+	{
+		surroundInfo = Array();
+		surroundInfo['start'] = '<p>';
+		surroundInfo['end'] = '</p>';
+		this.toggle();
+		
+		return surroundInfo;
+	}
+}
+
+/**
+ * special button that only adds an image
+ *
+ * @param id
+ * @param display
+ * @param icon
+ */
+edButtonImage = function(id, display, icon) 
+{
+	//
+	// strange javascript thingies used for object inheritance...
+	//
+	this.prototype = new edButton(id, display, '', '', icon, -1 );
+	this.prototype.constructor = edButton;
+	this.superclass = edButton;
+	
+	this.superclass(id, display, '', '', icon, -1 );
+
+	/**
+	 * reimplemented from edButton so that we can ask for an image url and a description
+	 *
+	 * @param txtId
+	 */
+	this.execute = function( txtId, param )
+	{
+		textArea = document.getElementById(txtId);
+		
+		this.toggle();
+		
+		imgSrc = prompt('Enter the image source: ');
+		if( imgSrc == null ) {
+			this.toggle();
+			return '';
+		}
+		
+		imgAlt = prompt('Enter an image description:');
+		if( imgAlt == null ) {
+			this.toggle();
+			return '';
+		}
+		
+		this.toggle();
+
+		// if everything went fine, add the link and return
+		var imgTag = '<img src="' + imgSrc + '" alt="' + imgAlt + '" />';
+		return imgTag;
+	}
+}
+
+/**
+ * implements drop-down lists
+ */
+edButtonList = function( id, options )
+{
+	//
+	// strange javascript thingies used for object inheritance...
+	//
+	this.prototype = new edButton(id, '', '', '', '', -1 );
+	this.prototype.constructor = edButton;
+	this.superclass = edButton;
+	
+	this.options = options;
+	
+	this.superclass(id, '', '', '', '', -1 );
+	
+	/**
+	 * renders the button. In our case, creates a drop-down list with the available options
+	 *
+	 * @param txtId
+	 * @returns the markup that is going to be written to the document
+	 */
+	this.show = function(txtId, objName)
+	{
+		selectBox = '<select class="editorDropDownList" name=\''+this.id+'\' onChange="'+objName+'.execute(\'' + txtId + '\', \'' + this.id + '\', this);">';
+		for( var key in this.options ) {
+			selectBox += '<option value=\''+key+'\'>'+this.options[key]+'</option>';
+		}
+		selectBox += '</select>';
+		
+		return( selectBox );
+	}
+	
+	/**
+	 * reimplement this method for lists that should behave in a particular way when an option
+	 * is selected
+	 */
+	this.execute = function( txtId, param )
+	{
+		// param is the drop-down list that generated the event, so we can easily learn
+		// more about what was selected by 
+		opt = param.selectedIndex;
+	
+		return( param.options[opt].value );
+	}
+	
+	/**
+	 * does nothing
+	 */
+	this.surround = function( txtId, param )
+	{
+		surroundInfo = Array();
+		return( surroundInfo );
+	}
+
+}
+
+/**
+ * button that shows a list with different font sizes
+ */
+edFontSizeList = function( id, options )
+{
+	//
+	// strange javascript thingies used for object inheritance...
+	//
+	this.prototype = new edButtonList(id, options );
+	this.prototype.constructor = edButtonList;
+	this.superclass = edButtonList;
+	
+	this.superclass(id, options );
+	
+	/**
+	 * returns the right <span style=...></span> markup
+	 */
+	this.execute = function( txtId, param )
+	{
+		// param is the drop-down list that generated the event, so we can easily learn
+		// more about what was selected in the dropdown list
+		opt = param.selectedIndex;
+		fontSizePt = param.options[opt].value;
+		
+		spanCode = '<span style="font-size: '+fontSizePt+'pt;"></span>';
+	
+		return( spanCode );
+	}
+	
+	/**
+	 * surrouns the selected text with the right <span>...</span> tags
+	 */
+	this.surround = function( txtId, param )
+	{
+		opt = param.selectedIndex;
+		fontSizePt = param.options[opt].value;	
+	
+		surroundInfo = Array();
+		surroundInfo['start'] = '<span style="font-size: '+fontSizePt+'pt;">';
+		surroundInfo['end'] = '</span>';
+		return( surroundInfo );
+	}
+}
+
+
+/**
+ * main class
+ *
+ */
+SmartyEditor = function(txtId, objName) 
+{
+
+  // class attributes	
+  this.txtId = txtId;
+  this.objName = objName;
+  
+  // array with all the open tags that haven't been closed
+  this.tagStack = new Array();
+  
+  this.debug = false;
+  
+  // --
+  // our very own toolbar
+  // --
+  this.toolBar = Array();
+  options = new Array();
+  options['8'] = '8 pt';
+  options['10'] = '10 pt';
+  options['12'] = '12 pt';
+  options['14'] = '14 pt';
+  options['18'] = '18 pt';
+  options['24'] = '24 pt';  
+  options['36'] = '36 pt';
+  this.toolBar['list_font_size'] = new edFontSizeList( 'list_font_size', options );
+  this.toolBar['1_but_b']  = new edButton( '1_but_b', 'bold', '<strong>', '</strong>', 'ed_format_bold.gif', 1 );
+  this.toolBar['2_but_i']  = new edButton( '2_but_i', 'italics', '<em>', '</em>', 'ed_format_italic.gif', 1 );
+  this.toolBar['3_but_u']  = new edButton( '3_but_u', 'underline', '<span style="text-decoration:underline">', '</span>', 'ed_format_underline.gif', 1 );
+  this.toolBar['4_but_strikethrough'] = new edButton( '4_but_strikethrough', 'strikethrough', '<span style="text-decoration: line-through;">', '</span>', 'ed_format_strike.gif', 1 );
+  this.toolBar['but_sep1'] =  new edButtonSeparator();
+  this.toolBar['but_align_left'] = new edButton( 'but_align_left', 'align center', '<div style="text-align: left;">', '</div>', 'ed_align_left.gif' );
+  this.toolBar['but_align_center'] = new edButton( 'but_align_center', 'align center', '<div style="text-align: center;">', '</div>', 'ed_align_center.gif' );
+  this.toolBar['but_align_right'] = new edButton( 'but_align_right', 'align center', '<div style="text-align: right;">', '</div>', 'ed_align_right.gif' );
+  this.toolBar['but_align_justify'] = new edButton( 'but_align_justify', 'align center', '<div style="text-align: justify;">', '</div>', 'ed_align_justify.gif' );
+  this.toolBar['but_sep2'] =  new edButtonSeparator();
+  this.toolBar['but_ordered_list'] = new edButton( 'but_ordered_list', 'ordered list', '<ol><li></li></ol>', '', 'ed_list_num.gif', -1 );
+  this.toolBar['but_unordered_list'] = new edButton( 'but_unordered_list', 'unordered list', '<ul><li></li></ul>', '', 'ed_list_bullet.gif', -1 );  
+  this.toolBar['5_but_a']  = new edButtonLink( '5_but_a', 'anchor', 'ed_link.gif' );
+  this.toolBar['6_but_img']= new edButtonImage( '6_but_img', 'image', 'ed_image.gif' );
+  
+  /**
+   * returns whether our browser supports the features that we are going
+   * to use or not
+   *
+   * @return true if supported, false if not
+   */
+  this.isSupportedBrowser = function()
+  {
+	 return( document.getElementById || document.all );
+  }
+  
+  /**
+   * draws the buttons. Takes no parameters
+   *
+   * @return nothing
+   */
+  this.showToolbar = function() {
+	  
+	  // first of all, check for unsupported browsers. If the browser
+	  // is not supported, we will silently not do anything... since we won't
+	  // even print the toolbar! (and nothing will happen without a toolbar)
+	  if( !this.isSupportedBrowser())
+	  	return;
+		
+	  markup = '';
+	  
+	  this.toolBar.sort();
+	  document.write('<div class="textEditorToolbar" id="textEditorToolbar">');
+	  for( var buttonId in this.toolBar ) {
+		  button = this.toolBar[buttonId];
+		  markup += button.show(this.txtId, this.objName);
+	  }
+	  document.write(markup);
+	  document.write('</div>');
+	  
+	  if( this.debug ) {
+		document.write('<textarea>'+markup+'</textarea>');
+	  }
+  }
+  
+  // after initializing the buttons, we can generate the toolbar
+  // we can't call this method after defining it!! :)
+  this.showToolbar();    
+  
+  /**
+   * calls the edButton.execute() callback
+   *
+   * @param txtId
+   * @param buttonId
+   * @return nothing
+   */
+  this.execute = function( txtId, buttonId, param )
+  {
+	  // get the button from the array
+	  var edButton = this.toolBar[buttonId];
+	  
+	  // execute the button
+	  if( !this.selectionExists()) {
+	  	result = edButton.execute( txtId, param );
+		if( result != 'undefined' )
+			this.insertText( result );
+  	  }
+  	  else {
+	  	 surroundInfo = edButton.surround( txtId, param ); 
+	     this.surroundText( surroundInfo['start'], surroundInfo['end'] );	  
+      }
+  }
+  
+  /**
+   * returns the textarea object associated to this editor
+   *
+   * @return a textarea object
+   */
+  this.getTextArea = function()
+  {
+	  textArea = document.getElementById( this.txtId );
+	  return textArea;
+  }
+  
+  /** 
+   * calls the onMouseOver handler for this button
+   *
+   * @param txtId
+   * @param buttonId
+   */
+  this.mouseOver = function( txtId, buttonId )
+  {
+	  var edButton = this.toolBar[buttonId];
+	  edButton.mouseOver();
+  }
+  
+  /**
+   * calls the onMouseOut handler for this button
+   *
+   * @param txtId
+   * @param buttonId
+   */
+  this.mouseOut = function( txtId, buttonId )
+  {
+	  var edButton = this.toolBar[buttonId];
+	  edButton.mouseOut();	  
+  }
+  
+	/**
+ 	 * inserts text where the cursor is
+ 	 * 
+ 	 * @param myField
+ 	 * @param myValue
+ 	 * @return nothing
+ 	 */
+	this.insertText = function(myValue) 
+	{
+		myField = this.getTextArea();
+		
+		//IE support
+		if (document.selection) {
+			myField.focus();
+			sel = document.selection.createRange();
+			sel.text = myValue;
+			myField.focus();
+		}
+		//MOZILLA/NETSCAPE support
+		else if (myField.selectionStart || myField.selectionStart == '0') {
+			var startPos = myField.selectionStart;
+			var endPos = myField.selectionEnd;
+			myField.value = myField.value.substring(0, startPos)
+		    	          + myValue 
+                	      + myField.value.substring(endPos, myField.value.length);
+			myField.focus();
+			myField.selectionStart = startPos + myValue.length;
+			myField.selectionEnd = startPos + myValue.length;
+		} else {
+			myField.value += myValue;
+			myField.focus();
+		}
+	}  
+	
+	/**
+	 * surrounds the current selection with the given opening and closing texts
+	 *
+	 * @param myValueOpen
+	 * @param myValueClose
+	 */
+	this.surroundText = function( myValueOpen, myValueClose )
+  	{
+		myField = this.getTextArea();
+		if (document.selection) {
+			myField.focus();
+			sel = document.selection.createRange();
+			sel.text = myValueOpen + sel.text + myValueClose;
+			myField.focus();
+		}
+		else if (myField.selectionStart || myField.selectionStart == '0') {
+			var startPos = myField.selectionStart;
+			var endPos = myField.selectionEnd;
+			var cursorPos = endPos;		
+			myField.value = myField.value.substring(0, startPos)
+		              + myValueOpen
+		              + myField.value.substring(startPos, endPos)
+		              + myValueClose
+                      + myField.value.substring(endPos, myField.value.length);
+			cursorPos += myValueOpen.length + myValueClose.length;		
+			myField.selectionStart = cursorPos;
+			myField.selectionEnd = cursorPos;
+			myField.focus();		
+		} 
+		else {
+			myField.value += myValueOpen;
+			myField.focus();
+		}	  
+  	}
+  
+  /**
+   * returns whether there is a user selection in the given editor
+   *
+   * @return True if there is a selection or false otherwise
+   */
+  this.selectionExists = function()
+  {
+	var selection = false;
+	var myField = this.getTextArea();
+	  
+	if (document.selection) {
+		// for IE
+		myField.focus();
+		sel = document.selection.createRange();
+		selection = (sel.text != '' );
+		myField.focus();
+	}
+	else if (myField.selectionStart || myField.selectionStart == '0') {
+		// for Mozilla
+		selection = (myField.selectionEnd > myField.selectionStart)
+	}
+	else {
+		// for everybody else...
+		selection = false;
+	}
+
+	return selection;
+  }
+}
\ No newline at end of file

Modified: plugins/trunk/templateeditor/plugintemplateeditor.class.php
===================================================================
--- plugins/trunk/templateeditor/plugintemplateeditor.class.php	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/plugintemplateeditor.class.php	2005-02-27 16:18:48 UTC (rev 1229)
@@ -28,6 +28,7 @@
             $this->registerAdminAction( "siteDeleteTemplateFile", "PluginSiteDeleteTemplateFilesAction" );
             $this->registerAdminAction( "siteDeleteTemplateFiles", "PluginSiteDeleteTemplateFilesAction" );
             $this->registerAdminAction( "siteEditTemplateFile", "PluginSiteEditTemplateFileAction" );
+            $this->registerAdminAction( "siteUpdateTemplateFile", "PluginSiteUpdateTemplateFileAction" );
 			
 			$this->addMenuEntry( "/menu/adminSettings/Templates", "templateEditor", "admin.php?op=siteTemplateSetsList", "templateEditor", false, true );
 		}

Modified: plugins/trunk/templateeditor/templates/siteedittemplatefile.template
===================================================================
--- plugins/trunk/templateeditor/templates/siteedittemplatefile.template	2005-02-27 16:10:16 UTC (rev 1228)
+++ plugins/trunk/templateeditor/templates/siteedittemplatefile.template	2005-02-27 16:18:48 UTC (rev 1229)
@@ -19,7 +19,9 @@
  </fieldset>  
 
  <div class="buttons">
-  <input type="hidden" name="op" value="updateNoFollowConfig" />
+  <input type="hidden" name="templateId" value="{$currentTemplate}" />
+  <input type="hidden" name="fileId" value="{$currentFile}" />
+  <input type="hidden" name="op" value="siteUpdateTemplateFile" />
   <input type="reset" name="{$locale->tr("reset")}" />    
   <input type="submit" name="{$locale->tr("update_settings")}" value="{$locale->tr("update")}" />
  </div>




More information about the pLog-svn mailing list