public function save()
 {
     if (trim($this->getName()) == '') {
         throw new Exception('Le nom du widget ne peut etre vide');
     }
     $allowWritePath = config::byKey('allowWriteDir', 'widget');
     if (!hadFileRight($allowWritePath, $this->generatePath())) {
         throw new Exception('Vous n\'etez pas autoriser à écrire : ' . $this->generatePath());
     }
     if (!is_writable($this->generatePath())) {
         //throw new Exception('Fichier/dossier inaccessible en écriture : ' . $this->generatePath());
     }
     file_put_contents($this->generatePath(), $this->getContent());
     if (realpath($this->getPath()) != realpath($this->generatePath())) {
         if (file_exists($this->getPath())) {
             unlink($this->getPath());
         }
     }
     $this->setPath($this->generatePath());
     return true;
 }
Exemple #2
0
 public function save()
 {
     if (trim($this->getName()) == '') {
         throw new Exception(__('Le nom du widget ne peut etre vide', __FILE__));
     }
     $allowWritePath = config::byKey('allowWriteDir', 'widget');
     if (!hadFileRight($allowWritePath, $this->generatePath())) {
         throw new Exception(__('Vous n\'etes pas autoriser à écrire : ', __FILE__) . $this->generatePath());
     }
     file_put_contents($this->generatePath(), $this->getContent());
     if (realpath($this->getPath()) != realpath($this->generatePath())) {
         if (file_exists($this->getPath())) {
             unlink($this->getPath());
             $informations = explode('.', $this->getPath());
             $name = $informations[count($informations) - 2];
             $type = $informations[count($informations) - 4];
             $subtype = $informations[count($informations) - 3];
             $cmds = cmd::searchTemplate('"' . $this->getVersion() . '":"' . $name . '"', null, $type, $subtype);
             foreach ($cmds as $cmd) {
                 $cmd->setTemplate($this->getVersion(), $this->getName());
                 $cmd->save();
             }
         }
         if (is_dir(str_replace('.html', '', $this->getPath()))) {
             if (!rename(str_replace('.html', '', $this->getPath()), str_replace('.html', '', $this->generatePath()))) {
                 throw new Exception(__('Impossible de déplacer : ', __FILE__) . str_replace('.html', '', $this->getPath()) . __(' vers ', __FILE__) . str_replace('.html', '', $this->generatePath()));
             }
         }
     }
     foreach ($this->getUsedBy() as $cmd) {
         $cmd->save();
     }
     return true;
 }
     ajax::success();
 }
 if (init('action') == 'removeScript') {
     $path = init('path');
     if (!file_exists($path)) {
         throw new Exception('Aucune fichier trouvé : ' . $path);
     }
     if (!is_writable($path)) {
         throw new Exception('Impossible d\'écrire dans : ' . $path);
     }
     if (is_dir($path)) {
         throw new Exception('Impossible de supprimer un dossier : ' . $path);
     }
     $allowRemovePath = config::byKey('allowRemoveDir', 'script');
     $allowRemovePath[] = config::byKey('userScriptDir', 'script');
     if (!hadFileRight($allowRemovePath, $path)) {
         throw new Exception('Vous n\'etez pas autoriser supprimer : ' . $path);
     }
     unlink($path);
     ajax::success();
 }
 if (init('action') == 'addUserScript') {
     $path = config::byKey('userScriptDir', 'script') . '/' . init('name');
     if (strpos($path, '/') !== 0 || strpos($path, '\\') !== 0) {
         $path = getRootPath() . '/' . $path;
     }
     if (!touch($path)) {
         throw new Exception('Impossible d\'écrire dans : ' . $path);
     }
     ajax::success($path);
 }