[pLog-svn] r5913 - in plog/trunk: class/action/admin class/controller templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Sep 6 17:37:52 EDT 2007


Author: oscar
Date: 2007-09-06 17:37:51 -0400 (Thu, 06 Sep 2007)
New Revision: 5913

Added:
   plog/trunk/class/action/admin/adminnewblogtemplatefileaction.class.php
   plog/trunk/class/action/admin/adminuploadblogtemplatefileaction.class.php
   plog/trunk/templates/admin/newblogtemplatefile_form.template
Modified:
   plog/trunk/class/controller/admincontrollermap.properties.php
Log:
Implemented file uploads for blog templates.


Added: plog/trunk/class/action/admin/adminnewblogtemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminnewblogtemplatefileaction.class.php	                        (rev 0)
+++ plog/trunk/class/action/admin/adminnewblogtemplatefileaction.class.php	2007-09-06 21:37:51 UTC (rev 5913)
@@ -0,0 +1,35 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
+
+	class AdminNewBlogTemplateFileAction extends AdminBaseTemplateEditorAction
+	{
+	
+		function __construct( $actionInfo, $request )
+		{
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
+			
+			$this->requirePermission( "update_blog_template" );			
+		}
+		
+		function validate()
+		{
+			// we override the default one in AdminBaseTemplateEditorAction::validate()
+			return( true );
+		}
+		
+		function perform()
+		{
+			return( $this->performAjax());
+		}
+		
+		function performAjax()
+		{
+			$this->_view = new AdminTemplatedView( $this->_blogInfo, "newblogtemplatefile_form" );
+			$this->setCommonData();
+			
+			return( true );
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/class/action/admin/adminuploadblogtemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminuploadblogtemplatefileaction.class.php	                        (rev 0)
+++ plog/trunk/class/action/admin/adminuploadblogtemplatefileaction.class.php	2007-09-06 21:37:51 UTC (rev 5913)
@@ -0,0 +1,73 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/action/admin/adminbasetemplateeditoraction.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminedittemplateview.class.php" );
+    lt_include( PLOG_CLASS_PATH."class/file/fileuploads.class.php" );	
+	lt_include( PLOG_CLASS_PATH."class/view/admin/adminblogtemplatesetslistview.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/view/admin/admineditblogtemplateview.class.php" );		
+	lt_include( PLOG_CLASS_PATH."class/data/validator/uploadvalidator.class.php" );
+
+	class AdminUploadBlogTemplateFileAction extends AdminBaseTemplateEditorAction
+	{
+	
+		function __construct( $actionInfo, $request )
+		{
+			$this->AdminBaseTemplateEditorAction( $actionInfo, $request );
+			
+			$this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
+			$this->registerFieldValidator( "path", new StringValidator(), true );
+			$view = new AdminBlogTemplateSetsListView( $this->_blogInfo );
+			$view->setErrorMessage( $this->_locale->tr( "error_uploading_template_file" ));
+			$this->setValidationErrorView( $view );
+			
+			$this->blogId = $this->_blogInfo->getId();
+
+			$this->requirePermission( "update_blog_template" );			
+		}
+		
+		function validate()
+		{
+			return( parent::validate( Array( "templateId", "path" )));
+		}		
+		
+		function perform()
+		{
+			$this->_view = new AdminEditBlogTemplateView( $this->_blogInfo, $this->_templateId, $this->_path );
+
+			// process the files and make sure that we're uploading an allowed file
+            $uploads = new FileUploads();			
+			$v = new UploadValidator();
+			foreach( $uploads as $upload ) {
+				if( $v->validate( $upload ) < 0) {
+					$this->_view->setErrorMessage( $this->_locale->tr("error_file_cannot_be_uploaded" ));
+					$this->setCommonData();
+					return( false );
+				}				
+			}
+
+			// we can now move the uploaded file to the destination folder
+			$folder = TemplateSetStorage::getTemplateFolder( $this->_templateId, $this->_blogInfo->getId()) . "/" . $this->_path . "/";			
+			
+			// check that the destination folder is writable, or else show a different error message
+			if( !File::isWritable( $folder )) {
+				$this->_view->setErrorMessage( $this->_locale->tr("error_cannot_write_to_folder" ));
+				$this->setCommonData();
+				return( false );				
+			}
+			
+			$result = $uploads->process( $folder );
+			
+			// check if the file was correctly saved
+            if( $result[0]->getError() != 0 ) {
+                $this->_view->setErrorMessage( $this->_locale->tr("error_uploading_template_file"));
+				$this->setCommonData();
+                return false;
+            }
+
+			$this->_view->setSuccessMessage( $this->_locale->tr( "template_file_uploaded_ok" ));			
+			$this->setCommonData();
+
+			return true;
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php	2007-09-06 21:36:47 UTC (rev 5912)
+++ plog/trunk/class/controller/admincontrollermap.properties.php	2007-09-06 21:37:51 UTC (rev 5913)
@@ -373,4 +373,6 @@
 	$actions["addBlogTemplateFolder"] = "AdminAddBlogTemplateFolderAction";		
 	$actions["copyBlogTemplateFile"] = "AdminCopyBlogTemplateFileAction";
 	$actions["copyBlogTemplateSet"] = "AdminCopyBlogTemplateSetAction";	
+	$actions["newBlogTemplateFile"] = "AdminNewBlogTemplateFileAction";	
+	$actions["uploadBlogTemplateFile"] = "AdminUploadBlogTemplateFileAction";	
 ?>
\ No newline at end of file

Added: plog/trunk/templates/admin/newblogtemplatefile_form.template
===================================================================
--- plog/trunk/templates/admin/newblogtemplatefile_form.template	                        (rev 0)
+++ plog/trunk/templates/admin/newblogtemplatefile_form.template	2007-09-06 21:37:51 UTC (rev 5913)
@@ -0,0 +1,20 @@
+<form id="newTemplateFile" name="newTemplateFile" action="admin.php" method="post" enctype="multipart/form-data" onSubmit="Lifetype.UI.Pages.TemplateEditor.templateFileUploadHandler(this);">
+  <fieldset class="inputField">
+   <legend>{$locale->tr("newTemplateFile")}</legend>
+   <div class="field" id="fileFields">
+    <label for="resourceFile_1">{$locale->tr("file")}</label>
+	<span class="required">*</span>
+	<div class="formHelp">{$locale->tr("new_template_file_help")}</div>  
+    <input type="file" id="templateFile" name="templateFile" />
+  </div>
+  </fieldset>
+  <div class="buttons" id="buttons">
+    <input type="reset" name="resetButton" value="{$locale->tr("reset")}" />
+    <input type="submit" name="addFile" onclick="showProgressBar('buttons')" value="{$locale->tr("add")}" />
+    <input type="hidden" name="op" value="uploadBlogTemplateFile" />
+  </div>
+  <div class="status_bar" id="status_bar" style="display:none">
+    {$locale->tr("upload_in_progress")}&nbsp;
+    <img src="imgs/admin/spinner_small.gif" alt="Spinner" />    
+  </div>
+ </form>
\ No newline at end of file



More information about the pLog-svn mailing list