Example #1
0
 /**
  * @role save
  */
 public function save()
 {
     $request = $this->getRequest();
     $code = $request->get('code');
     if ($this->request->get('fileName')) {
         $fileName = $this->request->get('fileName');
         if (strtolower(substr($fileName, -4)) != '.tpl') {
             $fileName .= '.tpl';
         }
         $template = new Template($fileName, $this->request->get('theme'));
     } else {
         $template = new Template($this->getFileName(), $this->request->get('theme'));
     }
     $origPath = $this->getFileName();
     if ($template->isCustomFile() && !$this->request->get('new') && $template->getFileName() != $origPath && !$this->request->get('theme')) {
         $origPath = Template::getCustomizedFilePath($origPath);
         if (file_exists($origPath)) {
             unlink($origPath);
         }
     }
     $template->setCode($code);
     $res = $template->save();
     if ($res) {
         return new JSONResponse(array('template' => $template->toArray(), 'isNew' => $this->request->get('new')), 'success', $this->translate('_template_has_been_successfully_updated'));
     } else {
         return new JSONResponse(false, 'failure', $this->translate('_could_not_update_template'));
     }
 }
Example #2
0
 /**
  * deletes customized template
  *  removes:
  *   customized template file 
  *   customized template file for each theme (if exists)
  *   backups (for customized template file, and each theme)
  */
 public function delete()
 {
     if ($this->isCustomFile() == false) {
         throw new Exception('Only custom files can be deleted');
     }
     $filesToRemove[] = Template::getCustomizedFilePath($this->file);
     $filesToRemove = array_merge($filesToRemove, $this->getBackups(false));
     $otherThemes = $this->getOtherThemes();
     foreach ($otherThemes as $key => $themename) {
         if ($key == '') {
             continue;
         }
         $template = new Template($this->file, $themename);
         $filesToRemove[] = Template::getCustomizedFilePath($template->getFileName());
         $filesToRemove = array_merge($filesToRemove, $template->getBackups(false));
     }
     $filesToRemove = array_values($filesToRemove);
     while ($fn = array_pop($filesToRemove)) {
         if (is_readable($fn)) {
             unlink($fn);
         }
     }
     return true;
 }