[pLog-svn] r5837 - in plog/trunk: class/action/admin class/controller class/file class/misc js/ui/pages locale/admin templates/admin
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sat Aug 18 17:21:39 EDT 2007
Author: oscar
Date: 2007-08-18 17:21:38 -0400 (Sat, 18 Aug 2007)
New Revision: 5837
Added:
plog/trunk/class/action/admin/admincopytemplatesetaction.class.php
plog/trunk/class/file/directorytreeiterator.class.php
plog/trunk/class/file/filtereddirectorytreeiterator.class.php
Modified:
plog/trunk/class/controller/admincontrollermap.properties.php
plog/trunk/class/misc/glob.class.php
plog/trunk/js/ui/pages/templateeditor.js
plog/trunk/locale/admin/locale_en_UK.php
plog/trunk/templates/admin/sitetemplates.template
Log:
Added support for copying an entire template set
Added: plog/trunk/class/action/admin/admincopytemplatesetaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admincopytemplatesetaction.class.php (rev 0)
+++ plog/trunk/class/action/admin/admincopytemplatesetaction.class.php 2007-08-18 21:21:38 UTC (rev 5837)
@@ -0,0 +1,111 @@
+<?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 AdminCopyTemplateSetAction extends AdminAction
+ {
+ var $_templateId;
+ var $_destTemplate;
+
+ function __construct( $actionInfo, $request )
+ {
+ $this->AdminAction( $actionInfo, $request );
+
+ $this->registerFieldValidator( "templateId", new TemplateNameValidator(), false);
+ $this->registerFieldValidator( "destTemplate", new StringValidator(), true );
+ $view = new AdminSiteTemplatesListView( $this->_blogInfo );
+ $view->setErrorMessage( $this->_locale->tr( "error_copying_template_set" ));
+ $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 );
+ }
+
+ // check that the destination template does not exist
+ $this->_destTemplate = $this->_request->getFilteredValue( "destTemplate", new RegexpFilter( "/[^A-Za-z0-9_\/\-]/" ));
+ if( TemplateSets::isTemplate( $this->_destTemplate )) {
+ // show a more specific error message
+ $this->_validationErrorView->setErrorMessage( $this->_locale->tr( "error_template_set_already_exists" ));
+ $this->_form->setFieldValidationStatus( "destTemplate", false );
+ $this->validationErrorProcessing();
+ return( false );
+ }
+
+ // otherwise everything is peachy
+ return( true );
+ }
+
+ function copyTemplateSet()
+ {
+ lt_include( PLOG_CLASS_PATH."class/file/directorytreeiterator.class.php" );
+
+ $path = TemplateSetStorage::getTemplateFolder( $this->_templateId);
+ $newTemplateFolder = TemplateSetStorage::getBaseTemplateFolder() . "/" . $this->_destTemplate;
+ if( !File::createDir( $newTemplateFolder ))
+ return( false );
+
+ $ts = new TemplateSetStorage();
+
+ $dir = new DirectoryTreeIterator( $path );
+ foreach( $dir as $file ) {
+ // prepare the destination file name
+ $destFile = $newTemplateFolder . "/" . str_replace( $path, "", $file );
+
+ // check if the destination folder exists
+ if( !File::exists( dirname( $destFile ))) {
+ if( !File::createDir( dirname( $destFile ), File::FILE_DEFAULT_DIRECTORY_CREATION_MODE, true )) {
+ return false;
+ }
+ }
+
+ // and finally perform the copy
+ if( !File::isDir( $file, $destFile )) {
+ if( !File::copy( $file, $destFile )) {
+ return false;
+ }
+ }
+ }
+
+ // add the new template as a global one
+ $ts->addTemplate( $this->_destTemplate, 0 );
+
+ return( true );
+ }
+
+ function performAjax()
+ {
+ $result = $this->copyTemplateSet();
+
+ 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_set_copied_ok" ));
+ else
+ $this->_view->setErrorMessage( $this->_locale->tr( "error_copying_template_set" ));
+
+ 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 21:32:43 UTC (rev 5836)
+++ plog/trunk/class/controller/admincontrollermap.properties.php 2007-08-18 21:21:38 UTC (rev 5837)
@@ -363,4 +363,5 @@
$actions["newTemplateFolder"] = "AdminNewTemplateFolderAction";
$actions["addTemplateFolder"] = "AdminAddTemplateFolderAction";
$actions["copyTemplateFile"] = "AdminCopyTemplateFileAction";
+ $actions["copyTemplateSet"] = "AdminCopyTemplateSetAction";
?>
\ No newline at end of file
Added: plog/trunk/class/file/directorytreeiterator.class.php
===================================================================
--- plog/trunk/class/file/directorytreeiterator.class.php (rev 0)
+++ plog/trunk/class/file/directorytreeiterator.class.php 2007-08-18 21:21:38 UTC (rev 5837)
@@ -0,0 +1,47 @@
+<?php
+
+ /**
+ *
+ * \ingroup File
+ *
+ * Iterator that recursively loops through the contents of the given folder
+ *
+ * @author The LifeType Project
+ */
+ class DirectoryTreeIterator extends RecursiveIteratorIterator
+ {
+ /**
+ * Construct from a path.
+ * @param $path directory to iterate
+ */
+ function __construct($path)
+ {
+ try {
+ parent::__construct(
+ new RecursiveCachingIterator(
+ new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME
+ ),
+ CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD
+ ),
+ parent::SELF_FIRST
+ );
+ }
+ catch(Exception $e) {
+ echo $e->getMessage();
+ exit;
+ }
+ }
+
+ function current()
+ {
+ if ($this->hasChildren())
+ $this->next();
+ return $this->key();
+ }
+
+ function __call($func, $params)
+ {
+ return call_user_func_array(array($this->getSubIterator(), $func), $params);
+ }
+ }
+?>
\ No newline at end of file
Added: plog/trunk/class/file/filtereddirectorytreeiterator.class.php
===================================================================
--- plog/trunk/class/file/filtereddirectorytreeiterator.class.php (rev 0)
+++ plog/trunk/class/file/filtereddirectorytreeiterator.class.php 2007-08-18 21:21:38 UTC (rev 5837)
@@ -0,0 +1,81 @@
+<?php
+
+ lt_include( PLOG_CLASS_PATH."class/file/directorytreeiterator.class.php" );
+
+ /**
+ * \ingroup File
+ *
+ * Uses the DirectoryTreeIterator class to provide a similar output
+ * but optinally using a regular expression or shell pattern to filter
+ * out the list of results.
+ *
+ * @author The LifeType Project
+ */
+ class FilteredDirectoryTreeIterator extends FilterIterator
+ {
+ private $_filter;
+ private $_patternMode;
+
+ const SHELL_PATTERN = 1;
+ const REGEXP_PATTERN = 2;
+
+ /**
+ * Creates a new iterator
+ *
+ * @param path The path where to start generating the folder tree
+ * @param filter The regular expression or shell pattern that will be used to filter files. It can be
+ * an array.
+ * @param mode Either FilteredDirectoryTree::SHELL_PATTERN to indicate that the $filter parameter is a
+ * shell pattern or FilteredDirectoryTree::REGEXP_PATTERN to indicate that we're dealing with
+ * a regular expression
+ * @return
+ */
+ function __construct( $path, $filter, $mode = FilteredDirectoryTreeIterator::SHELL_PATTERN )
+ {
+ parent::__construct(
+ new DirectoryTreeIterator($path)
+ );
+
+ if( !is_array( $filter ))
+ $this->_filter = Array( $filter );
+ else
+ $this->_filter= $filter;
+
+ $this->_mode = $mode;
+ }
+
+ function accept()
+ {
+ if( $this->_mode == FilteredDirectoryTreeIterator::REGEXP_PATTERN ) {
+ foreach( $this->_filter as $pattern ) {
+ if( preg_match( $pattern, $this->key()))
+ return( true );
+ }
+ }
+ else {
+ lt_include( PLOG_CLASS_PATH."class/misc/glob.class.php" );
+ foreach( $this->_filter as $pattern ) {
+ if( Glob::myFnmatch( $pattern, $this->key()))
+ return( true );
+ }
+ }
+
+ return( false );
+ }
+
+ protected function __clone()
+ {
+ return false;
+ }
+
+ function current()
+ {
+ return parent::key();
+ }
+
+ function key()
+ {
+ return parent::key();
+ }
+ }
+?>
\ No newline at end of file
Modified: plog/trunk/class/misc/glob.class.php
===================================================================
--- plog/trunk/class/misc/glob.class.php 2007-08-17 21:32:43 UTC (rev 5836)
+++ plog/trunk/class/misc/glob.class.php 2007-08-18 21:21:38 UTC (rev 5837)
@@ -88,7 +88,9 @@
* Returns an array with all the files and subdirs that match the given shell expression.
* @param folder Where to start searching.
* @param pattern A shell expression including wildcards '*' and '?' defining which
- * files will match and which will not.
+ * files will match and which will not. It can also be defined as an array of shell expressions,
+ * in which case a file will be considered as 'valid' if it maches any of the patterns provided
+ * in the array.
* @return An array with the matching files and false if error.
*/
function myGlob( $folder = ".", $pattern = "*" )
@@ -101,15 +103,22 @@
if ( $handle = opendir( $folder )) {
$files = Array();
+ if( !is_array( $pattern ))
+ $patternArray = Array( $pattern );
+ else
+ $patternArray = $pattern;
+
while (false !== ($file = readdir($handle))) {
if( $file !="." && $file != ".." ) // ignore '.' and '..'
- if( Glob::fnmatch($pattern,$file)) {
- if( $folder[strlen($folder)-1] != "/")
- $filePath = $folder."/".$file;
- else
- $filePath = $folder.$file;
- array_push( $files, $filePath );
+ foreach( $patternArray as $pat ) {
+ if( Glob::fnmatch( $pat, $file)) {
+ if( $folder[strlen($folder)-1] != "/")
+ $filePath = $folder."/".$file;
+ else
+ $filePath = $folder.$file;
+ array_push( $files, $filePath );
+ }
}
}
Modified: plog/trunk/js/ui/pages/templateeditor.js
===================================================================
--- plog/trunk/js/ui/pages/templateeditor.js 2007-08-17 21:32:43 UTC (rev 5836)
+++ plog/trunk/js/ui/pages/templateeditor.js 2007-08-18 21:21:38 UTC (rev 5837)
@@ -8,6 +8,11 @@
Lifetype.UI.Pages.TemplateEditor.copySourceFile = null;
/**
+ * Same thing when copying an entire template set
+ */
+Lifetype.UI.Pages.TemplateEditor.copySourceTemplate = 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
*/
@@ -51,6 +56,26 @@
var v = Lifetype.UI.Prompt.OkCancelPrompt.show( tr('enter_new_template_file_name'), { handleOk:Lifetype.UI.Pages.TemplateEditor.handleCopyFileOk });
}
+/**
+ * Callback used for the 'copy template set' prompt
+ */
+Lifetype.UI.Pages.TemplateEditor.handleCopyTemplateOk = function( value )
+{
+ if( value != "" ) {
+ var url = '?op=copyTemplateSet&templateId=' + Lifetype.UI.Pages.TemplateEditor.copySourceTemplate +
+ '&destTemplate=' + value;
+ Lifetype.Forms.performUrl( url );
+ }
+
+ Lifetype.UI.Pages.TemplateEditor.copySourceTemplate = null;
+}
+
+Lifetype.UI.Pages.TemplateEditor.showCopyTemplatePrompt = function( sourceTemplate )
+{
+ Lifetype.UI.Pages.TemplateEditor.copySourceTemplate = sourceTemplate;
+ var v = Lifetype.UI.Prompt.OkCancelPrompt.show( tr('enter_new_template_name'), { handleOk:Lifetype.UI.Pages.TemplateEditor.handleCopyTemplateOk });
+}
+
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 21:32:43 UTC (rev 5836)
+++ plog/trunk/locale/admin/locale_en_UK.php 2007-08-18 21:21:38 UTC (rev 5837)
@@ -1318,4 +1318,8 @@
$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';
+$messages['enter_new_template_name'] = 'Enter the name of the destination template set';
+$messages['template_set_copied_ok'] = 'The template set was successfully copied';
+$messages['error_copying_template_set'] = 'There was an error copying the template set';
+$messages['error_template_set_already_exists'] = 'The destination template set already exists';
?>
\ No newline at end of file
Modified: plog/trunk/templates/admin/sitetemplates.template
===================================================================
--- plog/trunk/templates/admin/sitetemplates.template 2007-08-17 21:32:43 UTC (rev 5836)
+++ plog/trunk/templates/admin/sitetemplates.template 2007-08-18 21:21:38 UTC (rev 5837)
@@ -9,31 +9,35 @@
</div>
<br style="clear:both" />
{/check_perms}
+{include file="$admintemplatepath/viewvalidateajax.template"}
<form id="siteTemplates" method="post" action="admin.php">
<div id="list" style="margin-left:30px;">
- {include file="$admintemplatepath/successmessage.template"}
- {include file="$admintemplatepath/errormessage.template"}
-
{foreach from=$templates item=sitetemplate}
<div class="template-screenshot">
<input style="display:none" type="checkbox" name="templateIds[{counter}]" value="{$sitetemplate->getName()}" />
- <img src="{$sitetemplate->getScreenshotUrl()}" style="height:240px;width:320px" alt="{$sitetemplate->getName()}" />
- <a href="javascript:Lifetype.UI.Pages.TemplateChooser.openScreenshotWindow('{$sitetemplate->getScreenshotUrl()}');">{$sitetemplate->getName()}</a> |
+ <span style="font-weight:bold;font-size:1.1em">{$sitetemplate->getName()}</span>
+ {if $sitetemplate->hasScreenshot()}
+ <a href="{$sitetemplate->getScreenshotUrl()}" onClick="Lifetype.UI.Misc.openInNewWindow(this);">
+ <img src="{$sitetemplate->getScreenshotUrl()}" alt="{$sitetemplate->getName()}" />
+ </a>
+ {/if}
+ <br/>
<a href="?op=editTemplate&templateId={$sitetemplate->getName()}">{$locale->tr("edit")}</a> |
- <a href="?op=copyTemplate&templateId={$sitetemplate->getName()}">{$locale->tr("copy")}</a> |
+ <a href="#" onClick="Lifetype.UI.Pages.TemplateEditor.showCopyTemplatePrompt('{$sitetemplate->getName()}');return(false);">{$locale->tr("copy")}</a> |
<a href="?op=tbd">{$locale->tr("delete")}</a>
</div>
{/foreach}
-
- <div class="clearer"></div>
- </div>
- <div id="list_action_bar">
- {check_perms adminperm=update_template}
- <input type="hidden" name="op" value="deleteTemplates" class="submit" />
- <input type="submit" name="{$locale->tr("delete")}" value="{$locale->tr("delete")}"/>
- {/check_perms}
- </div>
- </form>
+</div>
+<br style="clear:both" />
+<br style="clear:both" />
+<br style="clear:both" />
+<div id="list_action_bar">
+ {check_perms adminperm=update_template}
+ <input type="hidden" name="op" value="deleteTemplates" class="submit" />
+ <input type="submit" name="{$locale->tr("delete")}" value="{$locale->tr("delete")}"/>
+ {/check_perms}
+</div>
+</form>
{include file="$blogtemplate/footernavigation.template"}
{include file="$blogtemplate/footer.template"}
More information about the pLog-svn
mailing list