/**
  * Carries out the specified action
  * @private
  */
 function _deleteTemplates()
 {
     $ts = new TemplateSetStorage();
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     $blogTemplate = $this->_blogInfo->getTemplateSet();
     foreach ($this->_templateIds as $templateId) {
         // we can't remove the current template!
         if ($blogTemplate->getName() == $templateId) {
             $errorMessage .= $this->_locale->pr("error_template_is_current", $templateId) . "<br/>";
         } else {
             // otherwise, let's proceed
             if (!$ts->removeTemplate($templateId, $this->_blogInfo->getId())) {
                 $errorMessage .= $this->_locale->pr("error_removing_template", $templateId) . "<br/>";
             } else {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage = $this->_locale->pr("template_removed_ok", $templateId);
                 } else {
                     $successMessage = $this->_locale->pr("templates_removed_ok", $totalOk);
                 }
             }
         }
     }
     $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     return true;
 }
 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 perform()
 {
     $this->_templateId = $this->_request->getValue("templateId");
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $baseTemplateFolder = $ts->getBaseTemplateFolder();
     $templateArchive = new zip_file($this->_templateId . ".zip");
     $templateArchive->set_options(array('basedir' => $baseTemplateFolder, 'overwrite' => 1, 'inmemory' => 1));
     $templateArchive->add_files($this->_templateId);
     $templateArchive->create_archive();
     $templateArchive->download_file();
     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 RssView($blogInfo, $profile, $data = array())
 {
     $this->BlogView($blogInfo, "", SMARTY_VIEW_CACHE_CHECK, $data);
     $ts = new TemplateSetStorage();
     if (!$ts->templateExists($this->_profile, 'rss')) {
         // if not, then we will use the default one
         $this->_profile = RSS_VIEW_DEFAULT_PROFILE;
     }
     // we need to overwrite the $this->_template object with the Template object of our choice...
     $this->_profile = $profile;
     $templateService = new TemplateService();
     $this->_template = $templateService->CachedTemplate($this->_profile, 'rss', $this->_blogInfo);
     // set the correct content type
     $this->setContentType('text/xml');
 }
 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 perform()
 {
     $this->_view = new AdminTemplatedView($this->_blogInfo, "newglobaltemplate");
     $this->_view->setValue("templateFolder", TemplateSetStorage::getBaseTemplateFolder());
     $this->setCommonData();
     return true;
 }
 /**
  * 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();
 }
 /**
  * constructor
  *
  * @param templateFolder Starting folder where we will look for files. If none
  * is specified, the default ./templates folder will be used (or the one that has
  * been configured in the "templates_folder" parameter in the plog_config table
  * @see FileFinder::FileFinder
  */
 function TemplateFinder($templateFolder = null)
 {
     // if there is no template folder, use the default one
     if ($templateFolder == null) {
         $templateFolder = TemplateSetStorage::getBaseTemplateFolder();
     }
     $this->_templateFolder = $templateFolder;
     $this->FileFinder($templateFolder);
 }
 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 perform()
 {
     if ($this->_config->getValue("users_can_add_templates") == true) {
         $this->_view = new AdminTemplatedView($this->_blogInfo, "newblogtemplate");
         $this->_view->setValue("templateFolder", TemplateSetStorage::getBlogBaseTemplateFolder($this->_blogInfo->getId()));
         $this->setCommonData();
     } else {
         $this->_view = new AdminErrorView($this->_blogInfo);
         $this->_view->setMessage($this->_locale->tr("error_add_template_disabled"));
         $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 _deleteTemplates()
 {
     $ts = new TemplateSetStorage();
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     // get the id of the default template
     $blogTemplate = $this->_blogInfo->getTemplateSet();
     foreach ($this->_templateIds as $templateId) {
         // we can't remove the default template
         if ($blogTemplate->getName() == $templateId) {
             $errorMessage .= $this->_locale->pr("error_template_is_current", $templateId) . "<br/>";
         } else {
             // if it's not the default, then try to really remove it from disk
             if (!$ts->removeTemplate($templateId, $this->_blogInfo->getId())) {
                 $errorMessage .= $this->_locale->pr("error_removing_template", $templateId) . "<br/>";
             } else {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage = $this->_locale->pr("template_removed_ok", $templateId);
                 } else {
                     $successMessage = $this->_locale->pr("templates_removed_ok", $totalOk);
                 }
             }
         }
     }
     // create the view and show some feedback
     $this->_view = new PluginBlogTemplateSetsListView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     return true;
 }
 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;
 }
 /**
  * scans the templates folder looking for new files
  *
  * @private
  */
 function _performScanTemplateFolder()
 {
     $this->_errorMessage = "";
     $this->_successMessage = "";
     // set up the view
     $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
     // and tell the template finder to find any new template file...
     $tf = new TemplateFinder(TemplateSetStorage::getBlogBaseTemplateFolder($this->_blogInfo->getId()));
     $newTemplates = $tf->find(TemplateSets::getBlogTemplates($this->_blogInfo->getId()));
     $this->_errorMessage = "";
     $this->_successMessage = "";
     if (count($newTemplates) == 0) {
         // no new templates found
         $this->_errorMessage = $this->_locale->tr('error_no_new_templates_found');
     } else {
         // now add each one of the new ones
         foreach ($newTemplates as $newTemplate) {
             $this->_addTemplateCode($newTemplate);
         }
     }
     // set the success and error messages, if any
     if ($this->_errorMessage != '') {
         $this->_view->setErrorMessage($this->_errorMessage);
     }
     if ($this->_successMessage != '') {
         $this->_view->setSuccessMessage($this->_successMessage);
     }
     $this->setCommonData();
     return true;
 }
 /**
  * returns the path where the admin templates are stored
  *
  * @return a path
  */
 function getAdminTemplateFolder()
 {
     $templatePath = TemplateSetStorage::getBaseTemplateFolder() . "/admin";
     return $templatePath;
 }
 /**
  * calculates and returns the full path to the screenshot of the template set
  * regardless of whether it is global or blog specific
  *
  * @return The url to the screenshot
  */
 function getScreenshotUrl()
 {
     $ts = new TemplateSetStorage();
     return $ts->getScreenshotUrl($this->getName(), $this->getBlogId());
 }
 function _addTemplateCode($templateName)
 {
     $ts = new TemplateSetStorage();
     // make sure that the template is valid
     $templateSandbox = new TemplateSandbox();
     $valid = $templateSandbox->checkTemplateFolder($templateName, $ts->getBaseTemplateFolder());
     if ($valid < 0) {
         $this->_errorMessage = $this->_locale->pr('error_installing_template', $templateName) . ': ' . $this->_checkTemplateSandboxResult($valid) . '<br/>';
         $result = false;
     } else {
         // otherwise, we can add it without problems
         $ts->addTemplate($templateName);
         $this->_successMessage = $this->_locale->pr('template_installed_ok', $templateName) . '<br/>';
         $result = true;
     }
     $this->setCommonData();
     return $result;
 }
 /**
  * Returns a CachedTemplate object loaded from a plugin template
  * Plugins are different in the sense that they store their templates in the
  * plugins/xxx/templates, where 'xxx' is the plugin identifier
  *
  * @param pluginId The id of the plugin, which matches the name of a folder
  * under the plugins/ folder.
  * @param templateName Name of the template, without the .template extension
  * @param blogInfo
  * @return a CachedTemplate object
  */
 function PluginCachedTemplate($pluginId, $templateName, $blogInfo = null)
 {
     // define the template file name
     $templateFolder = TemplateSetStorage::getPluginTemplateFolder($pluginId);
     $templateFileName = $templateFolder . $templateName . '.template';
     $t = new CachedTemplate($templateFileName);
     $t->setTemplateDir($templateFolder);
     $t->assign('templatename', $templateName);
     $t->assign('admintemplatepath', TemplateSetStorage::getAdminTemplateFolder());
     $t->assign('plugintemplatepath', $templateFolder);
     // change a few things...
     $t = $this->_configureTemplateSettings($t, $blogInfo);
     return $t;
 }