[pLog-svn] r5834 - in plog/trunk: class/action/admin class/controller class/template/editor js/ui/pages locale/admin templates/admin
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Fri Aug 17 17:18:23 EDT 2007
Author: oscar
Date: 2007-08-17 17:18:22 -0400 (Fri, 17 Aug 2007)
New Revision: 5834
Added:
plog/trunk/class/action/admin/admincopytemplatefileaction.class.php
Modified:
plog/trunk/class/controller/admincontrollermap.properties.php
plog/trunk/class/template/editor/templatetools.class.php
plog/trunk/js/ui/pages/templateeditor.js
plog/trunk/locale/admin/locale_en_UK.php
plog/trunk/templates/admin/edittemplate_table.template
Log:
Implemented template file copy
Added: plog/trunk/class/action/admin/admincopytemplatefileaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincopytemplatefileaction.class.php (rev 0)
+++ plog/trunk/class/action/admin/admincopytemplatefileaction.class.php 2007-08-17 21:18:22 UTC (rev 5834)
@@ -0,0 +1,90 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/validator/templatenamevalidator.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/filter/regexpfilter.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/template/templatesets/templatesets.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/template/editor/templatetools.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/view/admin/adminsitetemplateslistview.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/view/admin/adminerrordialogview.class.php" );
+
+ class AdminCopyTemplateFileAction extends AdminAction
+ {
+ var $_template;
+ var $_path;
+
+ function __construct( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+
+ $this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
+ $this->registerFieldValidator( "path", new StringValidator(), true );
+ $this->registerFieldValidator( "sourceFileName", new StringValidator(), true );
+ $this->registerFieldValidator( "destFileName", new StringValidator(), true );
+ $view = new AdminSiteTemplatesListView( $this->_blogInfo );
+ $view->setErrorMessage( $this->_locale->tr( "error_loading_template" ));
+ $this->setValidationErrorView( $view );
+
+ $this->requireAdminPermission( "edit_global_templates" );
+ }
+
+ function validate()
+ {
+ if( !parent::validate())
+ return false;
+
+ // check that the template really exists
+ $this->_templateId = $this->_request->getFilteredValue( "templateId", new RegexpFilter( "/[^A-Za-z0-9_]/" ));
+ if( !TemplateSets::isTemplate( $this->_templateId )) {
+ $this->_form->setFieldValidationStatus( "templateId", false );
+ $this->validationErrorProcessing();
+ return( false );
+ }
+
+ // if the template exists, check that the path exists too
+ $this->_path = $this->_request->getFilteredValue( "path", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
+ if( !TemplateTools::isValidTemplatePath( $this->_templateId, $this->_path )) {
+ $this->_form->setFieldValidationStatus( "path", false );
+ $this->validationErrorProcessing();
+ return( false );
+ }
+
+ // otherwise everything is peachy
+ return( true );
+ }
+
+ function createFolder()
+ {
+ $sourceFileName = $this->_request->getFilteredValue( "sourceFileName", new RegexpFilter( "/[^A-Za-z0-9_\/\-\.]/" ));
+ $destFileName = $this->_request->getFilteredValue( "destFileName", new RegexpFilter( "/[^A-Za-z0-9_\/\-\.]/" ));
+
+ // clean up all ".." and just leave ".", to avoid potential relative path attacks
+ $sourceFileName = preg_replace( "/\.+/", ".", $sourceFileName );
+ $destFileName = preg_replace( "/\.+/", ".", $destFileName );
+
+ $path = TemplateSetStorage::getTemplateFolder( $this->_templateId) . "/" . $this->_path . "/";
+
+ return(
+ File::copy( $path.$sourceFileName, $path.$destFileName )
+ );
+ }
+
+ function performAjax()
+ {
+ $result = $this->createFolder();
+
+ lt_include( PLOG_CLASS_PATH."class/view/admin/ajax/adminajaxview.class.php" );
+ $this->_view = new AdminAjaxView( $this->_blogInfo );
+
+ $this->_view->setSuccess( $result );
+ if( $result )
+ $this->_view->setSuccessMessage( $this->_locale->tr( "template_file_copied_ok" ));
+ else
+ $this->_view->setErrorMessage( $this->_locale->tr( "error_copying_template_file" ));
+
+ return( true );
+ }
+ }
+
+?>
\ No newline at end of file
Modified: plog/trunk/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/trunk/class/controller/admincontrollermap.properties.php 2007-08-17 10:45:14 UTC (rev 5833)
+++ plog/trunk/class/controller/admincontrollermap.properties.php 2007-08-17 21:18:22 UTC (rev 5834)
@@ -362,4 +362,5 @@
$actions["deleteTemplateFile"] = "AdminDeleteTemplateFileAction";
$actions["newTemplateFolder"] = "AdminNewTemplateFolderAction";
$actions["addTemplateFolder"] = "AdminAddTemplateFolderAction";
+ $actions["copyTemplateFile"] = "AdminCopyTemplateFileAction";
?>
\ No newline at end of file
Modified: plog/trunk/class/template/editor/templatetools.class.php
===================================================================
--- plog/trunk/class/template/editor/templatetools.class.php 2007-08-17 10:45:14 UTC (rev 5833)
+++ plog/trunk/class/template/editor/templatetools.class.php 2007-08-17 21:18:22 UTC (rev 5834)
@@ -48,9 +48,10 @@
if ( !File::isDir($file) ) {
$tmp['name'] = basename($file);
$tmp['size'] = filesize($file);
- $tmp['isEditable'] = TemplateTools::isValidExtension( $tmp['name'] ) && File::isWritable( $file );
+ $tmp['isEditable'] = TemplateTools::isValidExtension( $tmp['name'] ) && File::isWritable( $file ) && File::isReadable( $file );
$tmp['isRemovable'] = File::isWritable( dirname( $file ));
$tmp['isImage'] = TemplateTools::isImage( $tmp['name'] );
+ $tmp['isReadable'] = File::isReadable( $file );
$tmp['url'] = $file;
$tmp['isFile'] = true;
$tmp['isFolder'] = false;
Modified: plog/trunk/js/ui/pages/templateeditor.js
===================================================================
--- plog/trunk/js/ui/pages/templateeditor.js 2007-08-17 10:45:14 UTC (rev 5833)
+++ plog/trunk/js/ui/pages/templateeditor.js 2007-08-17 21:18:22 UTC (rev 5834)
@@ -1,6 +1,13 @@
Lifetype.UI.Pages.TemplateEditor = function() {}
/**
+ * Global variable used to store the original name of the file that is going to be copied.
+ * We need to keep it in a global object or else the 'ok/cancel' callback would not have
+ * access to it
+ */
+Lifetype.UI.Pages.TemplateEditor.copySourceFile = null;
+
+/**
* We are going to use this variable to store the current url, so that we
* can reload the right url when adding or deleting files
*/
@@ -14,7 +21,7 @@
Lifetype.UI.Pages.TemplateEditor.newFolderButtonHandler = function( a )
{
- var v = Lifetype.UI.Prompt.OkCancelPrompt.show( tr('enter_template_folder_name'), {handleOk:Lifetype.UI.Pages.TemplateEditor.handleNewFolderOk} );
+ var v = Lifetype.UI.Prompt.OkCancelPrompt.show( tr('enter_template_folder_name'), { handleOk:Lifetype.UI.Pages.TemplateEditor.handleNewFolderOk });
}
Lifetype.UI.Pages.TemplateEditor.handleNewFolderOk = function( value )
@@ -25,6 +32,26 @@
}
}
+Lifetype.UI.Pages.TemplateEditor.handleCopyFileOk = function( value )
+{
+ if( value != "" ) {
+ var url = '?op=copyTemplateFile&templateId=' + Lifetype.Dom.$( 'templateId' ).value +
+ '&path=' + Lifetype.Dom.$( 'currentPath' ).value +
+ '&sourceFileName=' + Lifetype.UI.Pages.TemplateEditor.copySourceFile +
+ '&destFileName=' + value;
+ Lifetype.Forms.performUrl( url );
+ }
+
+ Lifetype.UI.Pages.TemplateEditor.copySourceFile = null;
+}
+
+
+Lifetype.UI.Pages.TemplateEditor.copyTemplateFileTo = function( sourceFile )
+{
+ Lifetype.UI.Pages.TemplateEditor.copySourceFile = sourceFile;
+ var v = Lifetype.UI.Prompt.OkCancelPrompt.show( tr('enter_new_template_file_name'), { handleOk:Lifetype.UI.Pages.TemplateEditor.handleCopyFileOk });
+}
+
YAHOO.util.Event.addListener( window, "load", function() {
var t = new Lifetype.Effects.Table( "templateFiles" );
t.stripe();
Modified: plog/trunk/locale/admin/locale_en_UK.php
===================================================================
--- plog/trunk/locale/admin/locale_en_UK.php 2007-08-17 10:45:14 UTC (rev 5833)
+++ plog/trunk/locale/admin/locale_en_UK.php 2007-08-17 21:18:22 UTC (rev 5834)
@@ -1311,4 +1311,11 @@
$messages['upload_file'] = 'Upload file';
$messages['editTemplateFile'] = 'Edit Template File';
+
+$messages['template_folder_created_ok'] = 'Template folder successfully created';
+$messages['error_creating_template_folder'] = 'There was an error creating the template folder';
+$messages['enter_template_folder_name'] = 'Enter the name of the new folder';
+$messages['enter_new_template_file_name'] = 'Enter the name of the new file';
+$messages['template_file_copied_ok'] = 'File copied successfully';
+$messages['error_copying_template_file'] = 'There was an error copying the file';
?>
\ No newline at end of file
Modified: plog/trunk/templates/admin/edittemplate_table.template
===================================================================
--- plog/trunk/templates/admin/edittemplate_table.template 2007-08-17 10:45:14 UTC (rev 5833)
+++ plog/trunk/templates/admin/edittemplate_table.template 2007-08-17 21:18:22 UTC (rev 5834)
@@ -73,14 +73,13 @@
{else}
<img src="imgs/admin/icon_empty-16.png" />
{/if}
- {** --copy is not implemented yet--
- {if $file.isEditable}
- <a href="?op=copyTemplateFile&templateId={$template}&path={$path}&file={$file.name}" id="{$file.name}" onClick="Lifetype.UI.Pages.TemplateEditor.copyTemplateFileTo(this.id, '{$template}', '{$currentSubFolder}')" >
+ {if $file.isReadable}
+ <a href="#" id="{$file.name}" onClick="Lifetype.UI.Pages.TemplateEditor.copyTemplateFileTo('{$file.name}');return(false);" >
<img src="imgs/admin/icon_copy-16.png" alt="{$locale->tr("copy")}" />
</a>
{else}
<img src="imgs/admin/icon_empty-16.png" />
- {/if} **}
+ {/if}
{if $file.isImage}
<a href="javascript:Lifetype.UI.Pages.TemplateEditor.openImagePreviewWindow('{$url->getUrl($file.url)}');">
<img src="imgs/admin/icon_image-16.png" alt="Preview" />
More information about the pLog-svn
mailing list