コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 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;
 }