Exemplo n.º 1
0
 /**
  * Sends the specified object as JSON.
  *
  * @param Mixed $obj Json data to send.
  */
 public function sendJson($obj)
 {
     $this->setHeader('Content-Type', 'application/json');
     $obj = MOXMAN_Util_Json::encode($obj);
     // IE 7 treats application/json download but in case some proxy/server
     // would ignore that content-type and deliver it as HTML trim a few things
     $obj = strtr($obj, array('<' => '\\u003c', '>' => '\\u003e'));
     $this->sendContent($obj);
 }
Exemplo n.º 2
0
 /**
  * Deletes the file.
  *
  * @param boolean $deep If this option is enabled files will be deleted recurive.
  */
 public function delete($deep = false)
 {
     $files = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("favorites.files", "[]"));
     if (preg_match('/\\/([^\\/]+)_\\$\\$\\[([0-9]+)\\]$/', $this->getPath(), $matches)) {
         $name = $matches[1];
         $index = intval($matches[2]);
         if (isset($files[$index]) && basename($files[$index]->path) == $name) {
             array_splice($files, $index, 1);
             MOXMAN::getUserStorage()->put("favorites.files", MOXMAN_Util_Json::encode($files));
         }
     }
     return true;
 }
Exemplo n.º 3
0
 public function remove($params)
 {
     if (isset($params->paths) && is_array($params->paths)) {
         $paths = $params->paths;
         $files = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("uploaded.files", "[]"));
         // Remove existing paths
         for ($i = 0; $i < count($files); $i++) {
             foreach ($paths as $path) {
                 if ($files[$i]->path == $path) {
                     array_splice($files, $i, 1);
                 }
             }
         }
         MOXMAN::getUserStorage()->put("uploaded.files", MOXMAN_Util_Json::encode($files));
     }
     return true;
 }
Exemplo n.º 4
0
 public function remove($params)
 {
     if (isset($params->paths) && is_array($params->paths)) {
         $paths = $params->paths;
         $files = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("favorites.files", "[]"));
         foreach ($paths as $path) {
             for ($i = count($files) - 1; $i >= 0; $i--) {
                 if ($files[$i]->path == $path) {
                     array_splice($files, $i, 1);
                     $i--;
                 }
             }
         }
         MOXMAN::getUserStorage()->put("favorites.files", MOXMAN_Util_Json::encode($files));
     }
     return true;
 }
Exemplo n.º 5
0
 public function remove($params)
 {
     if (MOXMAN::getConfig()->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if (isset($params->paths) && is_array($params->paths)) {
         $paths = $params->paths;
         $files = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("history.files", "[]"));
         for ($i = count($files) - 1; $i >= 0; $i--) {
             foreach ($paths as $path) {
                 if ($files[$i]->path == $path) {
                     array_splice($files, $i, 1);
                     $i--;
                 }
             }
         }
         MOXMAN::getUserStorage()->put("history.files", MOXMAN_Util_Json::encode($files));
     }
     return true;
 }
 /**
  * Disposes the instance.
  */
 public function dispose()
 {
     foreach ($this->metaFileCache as $filePath => $data) {
         $metaFile = $this->fileSystem->getFile($filePath);
         if (!empty($data)) {
             $stream = $metaFile->open("w");
             $stream->write(gzcompress(MOXMAN_Util_Json::encode($data), 9));
             $stream->close();
         } else {
             if ($metaFile->exists()) {
                 $metaFile->delete();
             }
         }
     }
 }
Exemplo n.º 7
0
 /** @ignore */
 private function save()
 {
     if (!is_writable(dirname($this->storagePath))) {
         return $this;
     }
     $json = MOXMAN_Util_Json::encode($this->data, $this->config->get("general.debug"));
     // If there is no data to store remove the storage file
     if ($json === "{}" && file_exists($this->storagePath)) {
         unlink($this->storagePath);
     } else {
         file_put_contents($this->storagePath, $json);
     }
     return $this;
 }
Exemplo n.º 8
0
 /**
  * Sends the specified object as JSON.
  *
  * @param Mixed $obj Json data to send.
  */
 public function sendJson($obj)
 {
     $this->sendContent(MOXMAN_Util_Json::encode($obj));
 }