/**
  * installs an uploaded template
  */
 function _performUploadTemplate()
 {
     // handle the uploaded file
     $files = HttpVars::getFiles();
     $uploads = new FileUploads($files);
     if (count($files) == 0 || $files["templateFile"]["name"] == "") {
         $this->_view = new AdminTemplatedView($this->_blogInfo, "newglobaltemplate");
         $this->_view->setValue("templateFolder", TemplateSetStorage::getBaseTemplateFolder());
         $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file"));
         $this->setCommonData();
         return false;
     }
     $config =& Config::getConfig();
     $tmpFolder = $config->getValue('temp_folder');
     // move it to the temporary folder
     $result = $uploads->process($tmpFolder);
     // and from there, unpack it
     $upload = new FileUpload($files['templateFile']);
     $templateSandbox = new TemplateSandbox();
     $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . '/');
     if ($valid < 0) {
         $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_checkTemplateSandboxResult($valid));
         $this->setCommonData();
         return false;
     }
     // the template was ok, so then we can proceed and move it to the main
     // template folder, add it to our array of templates
     //
     // :KLUDGE:
     //
     // maybe we should simply move the files rather than unpacking the whole
     // thing again, but this indeed makes things easier! ;)
     $unpacker = new Unpacker();
     $templateFolder = $config->getValue('template_folder');
     $fileToUnpack = $tmpFolder . '/' . $upload->getFileName();
     if (!$unpacker->unpack($fileToUnpack, $templateFolder)) {
         $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
         $tf = new Textfilter();
         $this->_view->setErrorMessage($this->_locale->pr('error_installing_template', $tf->filterAllHtml($upload->getFileName())));
         $this->setCommonData();
         return false;
     }
     // if the template set was installed ok in the template folder, we can record
     // it as a valid set
     $ts = new TemplateSetStorage();
     $fileParts = explode(".", $upload->getFileName());
     $templateName = $fileParts[0];
     $ts->addTemplate($templateName);
     $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr('template_installed_ok', $templateName));
     $this->setCommonData();
     return true;
 }
 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 _performUploadLocale()
 {
     // since we are here, the file name was validated to be ok, so we can
     // continue with the operation
     $files = HttpVars::getFiles();
     $uploads = new FileUploads($files);
     $this->_view = new AdminSiteLocalesListView($this->_blogInfo);
     // we can first of all move the file to the destionation folder
     $result = $uploads->process($this->_config->getValue("locale_folder"));
     // the only thing that can happen is that the file was not correctly saved
     if ($result[0]->getError() != 0) {
         $this->_view->setErrorMessage($this->_locale->tr("error_saving_locale"));
         return false;
     }
     // and once it's there, we can do as if we were adding a locale code
     $upload = new FileUpload($files["localeFile"]);
     $res = preg_match(REGEXP_VALID_LOCALE, $upload->getFileName(), $matches);
     $localeCode = $matches[1];
     // add the file to the list of locales
     $locales = new Locales();
     $locales->addLocale($localeCode);
     $this->_view->setSuccessMessage($this->_locale->pr("locale_added_ok", $localeCode));
     return true;
 }
 function _performUploadTemplate()
 {
     // get the temporary folder
     $config =& Config::getConfig();
     $tmpFolder = $config->getValue("temp_folder");
     // move it to the temporary folder
     $files = HttpVars::getFiles();
     if (count($files) == 0 || $files["templateFile"]["name"] == "") {
         $this->_view = new AdminTemplatedView($this->_blogInfo, "newblogtemplate");
         $this->_view->setValue("templateFolder", TemplateSetStorage::getBlogBaseTemplateFolder($this->_blogInfo->getId()));
         $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file"));
         $this->setCommonData();
         return false;
     }
     $uploads = new FileUploads($files);
     $result = $uploads->process($tmpFolder);
     if ($result < 0) {
         $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_uploads_disabled"));
         $this->setCommonData();
         return false;
     }
     $upload = new FileUpload($files["templateFile"]);
     // and make it go through the template sandbox to check if
     // we're dealing with a 'healthy' file
     $templateSandbox = new TemplateSandbox();
     $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . "/");
     if ($valid < 0) {
         $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage(AdminAddTemplateAction::_checkTemplateSandboxResult($valid));
         $this->setCommonData();
         return false;
     }
     //
     // :KLUDGE:
     //
     // maybe we should simply move the files rather than unpacking the whole
     // thing again, but this indeed makes things easier! ;)
     //
     // since it is a local template, the path has to be $template_folder/blog_x/$templateName
     $ts = new TemplateSetStorage();
     $blogTemplateFolder = $ts->createBlogTemplateFolder($this->_blogInfo->getId());
     // it should be there now... we can continue
     $destFolder = $blogTemplateFolder . "/";
     $unpacker = new Unpacker();
     if (!$unpacker->unpack($tmpFolder . "/" . $upload->getFileName(), $destFolder)) {
         $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_installing_template"));
         $this->setCommonData();
         // remove the file before returning!
         File::delete($tmpFolder . "/" . $upload->getFileName());
         return false;
     }
     // if the template set was installed ok in the template folder, we can record
     // it as a valid set
     $fileParts = explode(".", $upload->getFileName());
     $templateName = $fileParts[0];
     $ts->addTemplate($templateName, $this->_blogInfo->getId());
     // remove the file
     File::delete($tmpFolder . "/" . $upload->getFileName());
     $this->_view = new AdminBlogTemplateSetsListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("template_installed_ok", $templateName));
     $this->setCommonData();
     return true;
 }