/**
  * Renders the view. It simply gets all the parameters we've been adding to it
  * and puts them in the context of the template renderer so that they can be accessed
  * as normal parameters from within the template
  *
  * @return Returns a rendered template
  */
 function render()
 {
     // assign all the values
     $blogSettings = $this->_blogInfo->getSettings();
     $templateSet = $blogSettings->getValue("template");
     $this->_template->assign($this->_params->getAsArray());
     $ts = new TemplateSets();
     $storage = new TemplateSetStorage();
     if ($ts->isBlogTemplate($templateSet, $this->_blogInfo->getId())) {
         $blogTemplate = $storage->getTemplateFolder($templateSet, $this->_blogInfo->getId());
     } else {
         $blogTemplate = $storage->getTemplateFolder($templateSet);
     }
     $this->_template->assign("blogtemplate", $blogTemplate);
     parent::render();
 }
 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, $blogId);
     if (!empty($this->_subFolderId)) {
         $templateFolder = $templateFolder . $this->_subFolderId . "/";
     }
     $backupFolder = $templateFolder . "backups/";
     if (!File::exists($backupFolder)) {
         File::createDir($backupFolder);
     }
     $fileName = $templateFolder . $this->_fileId;
     $backupFileName = $backupFolder . $this->_fileId . "_" . time();
     if (!File::copy($fileName, $backupFileName)) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogEditTemplateFileView($this->_blogInfo, $this->_templateId, $this->_fileId, $this->_backupId);
         } else {
             $this->_view = new PluginBlogEditSubFolderTemplateFileView($this->_blogInfo, $this->_templateId, $this->_subFolderId, $this->_fileId, $this->_backupId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_backup_template_file"));
         $this->setCommonData();
         return false;
     }
     $file = new MyFile($fileName);
     if (!$file->isWritable()) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogEditTemplateFileView($this->_blogInfo, $this->_templateId, $this->_fileId, $this->_backupId);
         } else {
             $this->_view = new PluginBlogEditSubFolderTemplateFileView($this->_blogInfo, $this->_templateId, $this->_subFolderId, $this->_fileId, $this->_backupId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_template_file"));
         $this->setCommonData();
         return false;
     }
     $fileContent = $file->writeFileContent($this->_fileContent);
     // if everything went ok...
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $this->saveSession();
     if (empty($this->_subFolderId)) {
         $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
     } else {
         $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
     }
     $this->_view->setSuccessMessage($this->_locale->tr("templateeditor_file_saved_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 function render()
 {
     $config =& Config::getConfig();
     $maxBackupFiles = $config->getValue("plugin_templateeditor_maxbackupfiles");
     if ($maxBackupFiles == "") {
         $maxBackupFiles = 5;
     }
     // get a list with all the specific template files
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId);
     $templateFolder = $templateFolder . $this->_subFolderId . "/";
     $backupFolder = $templateFolder . "backups/";
     if (!File::exists($backupFolder)) {
         File::createDir($backupFolder);
     }
     if (!$this->_backupId) {
         $filename = $templateFolder . $this->_fileId;
     } else {
         $filename = $backupFolder . $this->_fileId . "_" . $this->_backupId;
     }
     $backupFilePattern = $this->_fileId . "_*";
     $bakFiles = Glob::myGlob($backupFolder, $backupFilePattern);
     sort($bakFiles);
     $backupFiles = array();
     $backupFileCount = 0;
     for ($i = count($bakFiles) - 1; $i >= 0; $i--) {
         $bakFile = $bakFiles[$i];
         if ($backupFileCount < $maxBackupFiles) {
             $bakElements = explode("_", $bakFile);
             $bakId = $bakElements[count($bakElements) - 1];
             $bakTime = strftime("%Y/%m/%d - %H:%M:%S", $bakId);
             $file['time'] = $bakTime;
             $file['backupId'] = basename($bakId);
             array_push($backupFiles, $file);
             $backupFileCount++;
         } else {
             File::delete($bakFile);
         }
     }
     $file = new MyFile($filename);
     $fileContent = $file->readFileContent();
     $this->setValue("backupId", $this->_backupId);
     $this->setValue("backupFiles", $backupFiles);
     $this->setValue("currentTemplate", $this->_templateId);
     $this->setValue("currentSubFolder", $this->_subFolderId);
     $this->setValue("currentFile", $this->_fileId);
     $this->setValue("fileContent", $fileContent);
     parent::render();
 }
 function perform()
 {
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
     if (!empty($this->_subFolderId)) {
         $templateFolder = $templateFolder . $this->_subFolderId . "/";
     }
     // Get template files according extension
     $templateFiles = $this->getTemplateFiles($templateFolder);
     foreach ($templateFiles as $file) {
         if ($file['name'] == $this->_newFileId) {
             if (empty($this->_subFolderId)) {
                 $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
             } else {
                 $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
             }
             $this->_view->setErrorMessage($this->_locale->tr("error_duplicate_templatefile_name"));
             $this->setCommonData();
             return false;
         }
     }
     $sourceFile = $templateFolder . $this->_fileId;
     $newFile = $templateFolder . $this->_newFileId;
     if (!File::copy($sourceFile, $newFile)) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
         } else {
             $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_copying_templatefile"));
         $this->setCommonData();
         return false;
     }
     // if everything went ok...
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $this->saveSession();
     if (empty($this->_subFolderId)) {
         $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
     } else {
         $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
     }
     $this->_view->setSuccessMessage($this->_locale->tr("templateeditor_templatefile_copyed_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }
 function render()
 {
     // get a list with all the global template sets
     $ts = new TemplateSets();
     $blogTemplateSets = $ts->getBlogTemplateSets($this->_blogInfo->getId(), false);
     // get a list with all the specific template files
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
     $templateFolder = $templateFolder . $this->_subFolderId;
     // Get template files according extension
     $templateFiles = $this->getTemplateFiles($templateFolder);
     $this->setValue("currentTemplate", $this->_templateId);
     $this->setValue("currentSubFolder", $this->_subFolderId);
     $this->setValue("templateSets", $blogTemplateSets);
     $this->setValue("templateFiles", $templateFiles);
     parent::render();
 }
 function perform()
 {
     // uploads the file and moves it to the correct folder
     $uploads = new FileUploads($this->_files);
     // make sure were it should go
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $destFolder = $ts->getTemplateFolder($this->_templateId, $blogId);
     if (!empty($this->_subFolderId)) {
         $destFolder = $destFolder . $this->_subFolderId . "/";
     }
     // and move it there
     $processedUploads = $uploads->process($destFolder);
     // check for the different error conditions we can have
     if ($processedUploads == FILE_UPLOADS_NOT_ENABLED) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
         } else {
             $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_uploads_disabled"));
         $this->setCommonData();
         return false;
     }
     $fileResult = $processedUploads[0];
     if ($fileResult->getError()) {
         if (empty($this->_subFolderId)) {
             $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
         } else {
             $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
         }
         $this->_view->setErrorMessage($this->_locale->tr("error_adding_template_file"));
         $this->setCommonData();
         return false;
     }
     if (empty($this->_subFolderId)) {
         $this->_view = new PluginBlogTemplatesListView($this->_blogInfo, $this->_templateId);
     } else {
         $this->_view = new PluginBlogTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
     }
     $this->_view->setSuccessMessage($this->_locale->pr("template_file_added_ok", $this->_templateId));
     $this->setCommonData();
     return true;
 }
 function _deleteFiles()
 {
     $ts = new TemplateSetStorage();
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId);
     if (!empty($this->_subFolderId)) {
         $templateFolder = $templateFolder . $this->_subFolderId . "/";
     }
     foreach ($this->_fileIds as $fileId) {
         $filename = $templateFolder . $fileId;
         // if it's not the default, then try to really remove it from disk
         if (!File::delete($filename)) {
             $errorMessage .= $this->_locale->pr("error_removing_template_file", $fileId) . "<br/>";
         } else {
             $totalOk++;
             if ($totalOk < 2) {
                 $successMessage = $this->_locale->pr("template_file_removed_ok", $fileId);
             } else {
                 $successMessage = $this->_locale->pr("template_files_removed_ok", $totalOk);
             }
         }
     }
     // create the view and show some feedback
     if (empty($this->_subFolderId)) {
         $this->_view = new PluginSiteTemplatesListView($this->_blogInfo, $this->_templateId);
     } else {
         $this->_view = new PluginSiteTemplateSubFolderListView($this->_blogInfo, $this->_templateId, $this->_subFolderId);
     }
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     return true;
 }
 function render()
 {
     // get a list with all the global template sets
     $ts = new TemplateSets();
     $globalTemplates = $ts->getGlobalTemplateSets();
     // Add rss & summary templateset to beginning of templatesets
     $rssTemplate =& new TemplateSet("rss", TEMPLATE_SET_GLOBAL, 0);
     $summaryTemplate =& new TemplateSet("summary", TEMPLATE_SET_GLOBAL, 0);
     array_unshift($globalTemplates, $rssTemplate, $summaryTemplate);
     // get a list with all the specific template files
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $templateFolder = $ts->getTemplateFolder($this->_templateId);
     $templateFolder = $templateFolder . $this->_subFolderId;
     // Get template files according extension
     $templateFiles = $this->getTemplateFiles($templateFolder);
     $this->setValue("currentTemplate", $this->_templateId);
     $this->setValue("currentSubFolder", $this->_subFolderId);
     $this->setValue("templateSets", $globalTemplates);
     $this->setValue("templateFiles", $templateFiles);
     parent::render();
 }
 function perform()
 {
     // get a list with all the global template sets
     $ts = new TemplateSets();
     $globalTemplates = $ts->getGlobalTemplateSets();
     foreach ($globalTemplates as $template) {
         if ($template->getName() == $this->_newTemplateId) {
             $this->_view = new PluginSiteTemplateSetsListView($this->_blogInfo);
             $this->_view->setErrorMessage($this->_locale->tr("error_duplicate_templateset_name"));
             $this->setCommonData();
             return false;
         }
     }
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $sourceTemplateFolder = $ts->getTemplateFolder($this->_templateId);
     $newTemplateFolder = $ts->getBaseTemplateFolder() . "/" . $this->_newTemplateId;
     if (MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder)) {
         $ts->addTemplate($this->_newTemplateId);
     } else {
         File::deleteDir($newTemplateFolder);
         $this->_view = new PluginSiteTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_copying_templateset"));
         $this->setCommonData();
         return false;
     }
     // if everything went ok...
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $this->saveSession();
     $this->_view = new PluginSiteTemplateSetsListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->tr("templateeditor_templateset_copyed_ok"));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     return true;
 }