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 perform()
 {
     $this->_templateId = $this->_request->getValue("templateId");
     $ts = new TemplateSetStorage();
     $blogId = $this->_blogInfo->getId();
     $baseBlogTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId);
     $templateArchive = new zip_file($this->_templateId . ".zip");
     $templateArchive->set_options(array('basedir' => $baseBlogTemplateFolder, 'overwrite' => 1, 'inmemory' => 1));
     $templateArchive->add_files($this->_templateId);
     $templateArchive->create_archive();
     $templateArchive->download_file();
     return true;
 }
 function perform()
 {
     // get a list with all the global template sets
     if ($this->_type == 1) {
         $ts = new TemplateSets();
         $blogTemplateSets = $ts->getBlogTemplateSets($this->_blogInfo->getId(), false);
         foreach ($blogTemplateSets as $template) {
             if ($template->getName() == $this->_newTemplateId) {
                 $this->_view = new PluginBlogTemplateSetsListView($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->getBlogBaseTemplateFolder($blogId) . $this->_newTemplateId;
         if (MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder)) {
             $ts->addTemplate($this->_newTemplateId, $blogId);
         } else {
             File::deleteDir($newTemplateFolder);
             $this->_view = new PluginBlogTemplateSetsListView($this->_blogInfo);
             $this->_view->setErrorMessage($this->_locale->tr("error_copying_templateset"));
             $this->setCommonData();
             return false;
         }
     } else {
         $ts = new TemplateSets();
         $blogTemplateSets = $ts->getBlogTemplateSets($this->_blogInfo->getId(), false);
         foreach ($blogTemplateSets as $template) {
             if ($template->getName() == $this->_newTemplateId) {
                 $this->_view = new PluginBlogTemplateSetsListView($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, $blogId);
         $newTemplateFolder = $ts->getBlogBaseTemplateFolder($blogId) . $this->_newTemplateId;
         if (MyFile::copyDir($sourceTemplateFolder, $newTemplateFolder)) {
             $ts->addTemplate($this->_newTemplateId, $blogId);
         } else {
             File::deleteDir($newTemplateFolder);
             $this->_view = new PluginBlogTemplateSetsListView($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 PluginBlogTemplateSetsListView($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;
 }