Beispiel #1
0
 public function listFilesFiltered(MOXMAN_Vfs_IFileFilter $filter)
 {
     $entries = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("uploaded.files", "[]"));
     $files = array();
     foreach ($entries as $entry) {
         $file = new MOXMAN_Uploaded_File($this->fileSystem, $entry->path, $entry);
         if ($filter->accept($file) == MOXMAN_Vfs_IFileFilter::ACCEPTED) {
             $files[] = $file;
         }
     }
     return $files;
 }
Beispiel #2
0
 /** @ignore */
 private function load()
 {
     if (!$this->loaded) {
         if (file_exists($this->storagePath)) {
             $this->data = MOXMAN_Util_Json::decode(file_get_contents($this->storagePath));
         } else {
             $this->data = new stdClass();
         }
         $this->loaded = true;
     }
     return $this->data;
 }
 public function listFilesFiltered(MOXMAN_Vfs_IFileFilter $filter)
 {
     $files = array();
     if ($this->isDirectory()) {
         $fileSystem = $this->getFileSystem();
         $entries = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("uploaded.files", "[]"));
         foreach ($entries as $entry) {
             $file = new MOXMAN_Favorites_File($fileSystem, $entry->path, $entry);
             if ($filter->accept($file)) {
                 $files[] = $file;
             }
         }
     }
     return new MOXMAN_Vfs_FileList($files);
 }
Beispiel #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("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;
 }
Beispiel #5
0
 public function listFilesFiltered(MOXMAN_Vfs_IFileFilter $filter)
 {
     $files = array();
     if ($this->isDirectory()) {
         $fileSystem = $this->getFileSystem();
         $entries = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("history.files", "[]"));
         $index = 0;
         foreach ($entries as $entry) {
             $file = new MOXMAN_History_File($fileSystem, $entry->path, $entry);
             if ($filter->accept($file)) {
                 $entry->name = basename($entry->path) . "_\$\$[" . $index++ . "]";
                 $files[] = $file;
             }
         }
     }
     return new MOXMAN_Vfs_FileList($files);
 }
Beispiel #6
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;
 }
 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;
 }
 /**
  * Saves meta data for the specified file.
  *
  * @param MOXMAN_Vfs_IFile $file File to save the meta data for.
  * @param Array Name/value array with meta data.
  */
 public function saveMetaData(MOXMAN_Vfs_IFile $file, $items)
 {
     $metaFile = $this->getMetaFile($file);
     if ($metaFile !== null) {
         $metaData = array();
         $metaFilePath = $metaFile->getPath();
         // Check if meta data is cached or not
         if (!isset($this->metaFileCache[$metaFilePath])) {
             if ($metaFile->exists()) {
                 // Open meta file
                 $stream = $metaFile->open("r");
                 $metaData = MOXMAN_Util_Json::decode(gzuncompress($stream->readToEnd()));
                 $stream->close();
             }
         } else {
             $metaData = $this->metaFileCache[$metaFilePath];
         }
         // Put in new contents
         if (!empty($items)) {
             $metaData[$file->getName()] = $items;
         } else {
             unset($metaData[$file->getName()]);
         }
         // Save meta file
         if (!empty($metaData)) {
             $stream = $metaFile->open("w");
             $stream->write(gzcompress(MOXMAN_Util_Json::encode($metaData), 9));
             $stream->close();
         } else {
             if ($metaFile->exists()) {
                 $metaFile->delete();
             }
         }
         // Cache meta data
         $this->metaFileCache[$metaFilePath] = $metaData;
     }
 }
 /**
  * Process a request using the specified context.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     $response->disableCache();
     $response->setHeader('Content-type', 'application/json');
     @set_time_limit(5 * 60);
     // 5 minutes execution time
     $id = null;
     try {
         $json = MOXMAN_Util_Json::decode($request->get("json"));
         // Check if we should install
         if ($json && $json->method != "install") {
             $config = MOXMAN::getConfig()->getAll();
             if (empty($config) || !isset($config["general.license"])) {
                 $exception = new MOXMAN_Exception("Installation needed.", MOXMAN_Exception::NEEDS_INSTALLATION);
                 throw $exception;
             }
             if (!preg_match('/^([0-9A-Z]{4}\\-){7}[0-9A-Z]{4}$/', trim($config["general.license"]))) {
                 throw new MOXMAN_Exception("Invalid license: " . $config["general.license"]);
             }
         }
         // Check if the user is authenticated or not
         if (!MOXMAN::getAuthManager()->isAuthenticated()) {
             if (!isset($json->method) || !preg_match('/^(login|logout|install)$/', $json->method)) {
                 $exception = new MOXMAN_Exception("Access denied by authenticator(s).", MOXMAN_Exception::NO_ACCESS);
                 $exception->setData(array("login_url" => MOXMAN::getConfig()->get("authenticator.login_page")));
                 throw $exception;
             }
         }
         if ($json && isset($json->id) && isset($json->method) && isset($json->params)) {
             $id = $json->id;
             $params = $json->params;
             $result = null;
             if (isset($params->access)) {
                 MOXMAN::getAuthManager()->setClientAuthData($params->access);
             }
             $plugins = MOXMAN::getPluginManager()->getAll();
             foreach ($plugins as $plugin) {
                 if ($plugin instanceof MOXMAN_ICommandHandler) {
                     $result = $plugin->execute($json->method, $json->params);
                     if ($result !== null) {
                         break;
                     }
                 }
             }
             if ($result === null) {
                 throw new Exception("Method not found: " . $json->method, -32601);
             }
             $response->sendJson((object) array("jsonrpc" => "2.0", "result" => $result, "id" => $id));
         } else {
             throw new Exception("Invalid Request.", -32600);
         }
         MOXMAN::dispose();
     } catch (Exception $e) {
         MOXMAN::dispose();
         $message = $e->getMessage();
         $data = null;
         if (MOXMAN::getConfig()->get("general.debug")) {
             $message .= "\n\nStacktrace:\n";
             $trace = $e->getTrace();
             array_shift($trace);
             $message .= $e->getFile() . ":" . $e->getLine() . "\n";
             foreach ($trace as $item) {
                 if (isset($item["file"]) && isset($item["line"])) {
                     $message .= $item["file"] . ":" . $item["line"] . "\n";
                 }
             }
         }
         if ($e instanceof MOXMAN_Exception && !$data) {
             $data = $e->getData();
         }
         $response->sendJson((object) array("jsonrpc" => "2.0", "error" => array("code" => $e->getCode(), "message" => $message, "data" => $data), "id" => $id));
     }
 }