예제 #1
0
 /**
  * See static method
  * @param Repository|null $repository
  * @throws AJXP_Exception|Exception
  * @return AbstractAccessDriver
  */
 private function loadRepositoryDriverInst(&$repository = null)
 {
     $rest = false;
     if ($repository == null) {
         if (isset($this->configs["ACCESS_DRIVER"]) && is_a($this->configs["ACCESS_DRIVER"], "AbstractAccessDriver")) {
             return $this->configs["ACCESS_DRIVER"];
         }
         $this->switchRootDirInst();
         $repository = $this->getRepositoryInst();
         if ($repository == null) {
             throw new Exception("No active repository found for user!");
         }
     } else {
         $rest = true;
         if (isset($repository->driverInstance)) {
             return $repository->driverInstance;
         }
     }
     /**
      * @var AbstractAccessDriver $plugInstance
      */
     $accessType = $repository->getAccessType();
     $pServ = AJXP_PluginsService::getInstance();
     $plugInstance = $pServ->getPluginByTypeName("access", $accessType);
     // TRIGGER BEFORE INIT META
     $metaSources = $repository->getOption("META_SOURCES");
     if (isset($metaSources) && is_array($metaSources) && count($metaSources)) {
         $keys = array_keys($metaSources);
         foreach ($keys as $plugId) {
             if ($plugId == "") {
                 continue;
             }
             $instance = $pServ->getPluginById($plugId);
             if (!is_object($instance)) {
                 continue;
             }
             if (!method_exists($instance, "beforeInitMeta")) {
                 continue;
             }
             try {
                 $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId()));
                 $instance->beforeInitMeta($plugInstance, $repository);
             } catch (Exception $e) {
                 AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage());
                 $this->errors[] = $e->getMessage();
             }
         }
     }
     // INIT MAIN DRIVER
     $plugInstance->init($repository);
     try {
         $plugInstance->initRepository();
         $repository->driverInstance = $plugInstance;
     } catch (Exception $e) {
         if (!$rest) {
             // Remove repositories from the lists
             if (!is_a($e, "AJXP_UserAlertException")) {
                 $this->removeRepositoryFromCache($repository->getId());
             }
             if (isset($_SESSION["PREVIOUS_REPO_ID"]) && $_SESSION["PREVIOUS_REPO_ID"] != $repository->getId()) {
                 $this->switchRootDir($_SESSION["PREVIOUS_REPO_ID"]);
             } else {
                 $this->switchRootDir();
             }
         }
         throw $e;
     }
     AJXP_PluginsService::deferBuildingRegistry();
     $pServ->setPluginUniqueActiveForType("access", $accessType);
     // TRIGGER INIT META
     $metaSources = $repository->getOption("META_SOURCES");
     if (isset($metaSources) && is_array($metaSources) && count($metaSources)) {
         $keys = array_keys($metaSources);
         foreach ($keys as $plugId) {
             if ($plugId == "") {
                 continue;
             }
             $split = explode(".", $plugId);
             $instance = $pServ->getPluginById($plugId);
             if (!is_object($instance)) {
                 continue;
             }
             try {
                 $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId()));
                 if (!method_exists($instance, "initMeta")) {
                     throw new Exception("Meta Source {$plugId} does not implement the initMeta method.");
                 }
                 $instance->initMeta($plugInstance);
             } catch (Exception $e) {
                 AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage());
                 $this->errors[] = $e->getMessage();
             }
             $pServ->setPluginActive($split[0], $split[1]);
         }
     }
     AJXP_PluginsService::flushDeferredRegistryBuilding();
     if (count($this->errors) > 0) {
         $e = new AJXP_Exception("Error while loading repository feature : " . implode(",", $this->errors));
         if (!$rest) {
             // Remove repositories from the lists
             $this->removeRepositoryFromCache($repository->getId());
             if (isset($_SESSION["PREVIOUS_REPO_ID"]) && $_SESSION["PREVIOUS_REPO_ID"] != $repository->getId()) {
                 $this->switchRootDir($_SESSION["PREVIOUS_REPO_ID"]);
             } else {
                 $this->switchRootDir();
             }
         }
         throw $e;
     }
     if ($rest) {
         $ctxId = $this->getContextRepositoryId();
         if ((!empty($ctxId) || $ctxId === 0) && $ctxId == $repository->getId()) {
             $this->configs["REPOSITORY"] = $repository;
             $this->cacheRepository($ctxId, $repository);
         }
     } else {
         $this->configs["ACCESS_DRIVER"] = $plugInstance;
     }
     return $plugInstance;
 }
예제 #2
0
 /**
  * See static method
  * @param Repository $repository
  * @throws AJXP_Exception|Exception
  * @return AbstractAccessDriver
  */
 public function loadRepositoryDriverREST(&$repository)
 {
     if (isset($repository->driverInstance)) {
         return $repository->driverInstance;
     }
     $accessType = $repository->getAccessType();
     $pServ = AJXP_PluginsService::getInstance();
     $plugInstance = $pServ->getPluginByTypeName("access", $accessType);
     // TRIGGER BEFORE INIT META
     $metaSources = $repository->getOption("META_SOURCES");
     if (isset($metaSources) && is_array($metaSources) && count($metaSources)) {
         $keys = array_keys($metaSources);
         foreach ($keys as $plugId) {
             if ($plugId == "") {
                 continue;
             }
             $instance = $pServ->getPluginById($plugId);
             if (!is_object($instance)) {
                 continue;
             }
             if (!method_exists($instance, "beforeInitMeta")) {
                 continue;
             }
             try {
                 $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId()));
                 $instance->beforeInitMeta($plugInstance, $repository);
             } catch (Exception $e) {
                 AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage());
                 $this->errors[] = $e->getMessage();
             }
         }
     }
     // INIT MAIN DRIVER
     $plugInstance->init($repository);
     try {
         $plugInstance->initRepository();
     } catch (Exception $e) {
         throw $e;
     }
     AJXP_PluginsService::deferBuildingRegistry();
     $pServ->setPluginUniqueActiveForType("access", $accessType);
     // TRIGGER INIT META
     $metaSources = $repository->getOption("META_SOURCES");
     if (isset($metaSources) && is_array($metaSources) && count($metaSources)) {
         $keys = array_keys($metaSources);
         foreach ($keys as $plugId) {
             if ($plugId == "") {
                 continue;
             }
             $split = explode(".", $plugId);
             $instance = $pServ->getPluginById($plugId);
             if (!is_object($instance)) {
                 continue;
             }
             try {
                 $instance->init(AuthService::filterPluginParameters($plugId, $metaSources[$plugId], $repository->getId()));
                 if (!method_exists($instance, "initMeta")) {
                     throw new Exception("Meta Source {$plugId} does not implement the initMeta method.");
                 }
                 $instance->initMeta($plugInstance);
             } catch (Exception $e) {
                 AJXP_Logger::error(__CLASS__, 'Meta plugin', 'Cannot instanciate Meta plugin, reason : ' . $e->getMessage());
                 $this->errors[] = $e->getMessage();
             }
             $pServ->setPluginActive($split[0], $split[1]);
         }
     }
     AJXP_PluginsService::flushDeferredRegistryBuilding();
     if (count($this->errors) > 0) {
         $e = new AJXP_Exception("Error while loading repository feature : " . implode(",", $this->errors));
         throw $e;
     }
     $repository->driverInstance = $plugInstance;
     if (isset($_SESSION["REPO_ID"]) && $_SESSION["REPO_ID"] == $repository->getId()) {
         $this->configs["REPOSITORY"] = $repository;
         if (is_array($this->configs["REPOSITORIES"])) {
             $this->configs["REPOSITORIES"][$_SESSION['REPO_ID']] = $repository;
         }
     }
     return $plugInstance;
 }
예제 #3
0
 public static function loadMinisite($data, $hash = '', $error = null)
 {
     if (isset($data["SECURITY_MODIFIED"]) && $data["SECURITY_MODIFIED"] === true) {
         $mess = ConfService::getMessages();
         $error = $mess['share_center.164'];
     }
     $repository = $data["REPOSITORY"];
     AJXP_PluginsService::getInstance()->initActivePlugins();
     $shareCenter = AJXP_PluginsService::findPlugin("action", "share");
     $confs = $shareCenter->getConfigs();
     $minisiteLogo = "plugins/gui.ajax/PydioLogo250.png";
     if (!empty($confs["CUSTOM_MINISITE_LOGO"])) {
         $logoPath = $confs["CUSTOM_MINISITE_LOGO"];
         if (strpos($logoPath, "plugins/") === 0 && is_file(AJXP_INSTALL_PATH . "/" . $logoPath)) {
             $minisiteLogo = $logoPath;
         } else {
             $minisiteLogo = "index_shared.php?get_action=get_global_binary_param&binary_id=" . $logoPath;
         }
     }
     // Default value
     if (isset($data["AJXP_TEMPLATE_NAME"])) {
         $templateName = $data["AJXP_TEMPLATE_NAME"];
         if ($templateName == "ajxp_film_strip" && AJXP_Utils::userAgentIsMobile()) {
             $templateName = "ajxp_shared_folder";
         }
     }
     if (!isset($templateName)) {
         $repoObject = ConfService::getRepositoryById($repository);
         if (!is_object($repoObject)) {
             $mess = ConfService::getMessages();
             $error = $mess["share_center.166"];
             $templateName = "ajxp_unique_strip";
         } else {
             $filter = $repoObject->getContentFilter();
             if (!empty($filter) && count($filter->virtualPaths) == 1) {
                 $templateName = "ajxp_unique_strip";
             } else {
                 $templateName = "ajxp_shared_folder";
             }
         }
     }
     // UPDATE TEMPLATE
     $html = file_get_contents(AJXP_INSTALL_PATH . "/" . AJXP_PLUGINS_FOLDER . "/action.share/res/minisite.php");
     AJXP_Controller::applyHook("tpl.filter_html", array(&$html));
     $html = AJXP_XMLWriter::replaceAjxpXmlKeywords($html);
     $html = str_replace("AJXP_MINISITE_LOGO", $minisiteLogo, $html);
     $html = str_replace("AJXP_APPLICATION_TITLE", ConfService::getCoreConf("APPLICATION_TITLE"), $html);
     $html = str_replace("PYDIO_APP_TITLE", ConfService::getCoreConf("APPLICATION_TITLE"), $html);
     if (isset($repository)) {
         $html = str_replace("AJXP_START_REPOSITORY", $repository, $html);
         $html = str_replace("AJXP_REPOSITORY_LABEL", ConfService::getRepositoryById($repository)->getDisplay(), $html);
     }
     $html = str_replace('AJXP_HASH_LOAD_ERROR', isset($error) ? $error : '', $html);
     $html = str_replace("AJXP_TEMPLATE_NAME", $templateName, $html);
     $html = str_replace("AJXP_LINK_HASH", $hash, $html);
     $guiConfigs = AJXP_PluginsService::findPluginById("gui.ajax")->getConfigs();
     $html = str_replace("AJXP_THEME", $guiConfigs["GUI_THEME"], $html);
     if (isset($_GET["dl"]) && isset($_GET["file"])) {
         AuthService::$useSession = false;
     } else {
         session_name("AjaXplorer_Shared" . str_replace(".", "_", $hash));
         session_start();
         AuthService::disconnect();
     }
     if (!empty($data["PRELOG_USER"])) {
         AuthService::logUser($data["PRELOG_USER"], "", true);
         $html = str_replace("AJXP_PRELOGED_USER", "ajxp_preloged_user", $html);
     } else {
         if (isset($data["PRESET_LOGIN"])) {
             $_SESSION["PENDING_REPOSITORY_ID"] = $repository;
             $_SESSION["PENDING_FOLDER"] = "/";
             $html = str_replace("AJXP_PRELOGED_USER", $data["PRESET_LOGIN"], $html);
         } else {
             $html = str_replace("AJXP_PRELOGED_USER", "ajxp_legacy_minisite", $html);
         }
     }
     if (isset($hash)) {
         $_SESSION["CURRENT_MINISITE"] = $hash;
     }
     if (isset($_GET["dl"]) && isset($_GET["file"]) && (!isset($data["DOWNLOAD_DISABLED"]) || $data["DOWNLOAD_DISABLED"] === false)) {
         ConfService::switchRootDir($repository);
         ConfService::loadRepositoryDriver();
         AJXP_PluginsService::deferBuildingRegistry();
         AJXP_PluginsService::getInstance()->initActivePlugins();
         AJXP_PluginsService::flushDeferredRegistryBuilding();
         $errMessage = null;
         try {
             $params = $_GET;
             $ACTION = "download";
             if (isset($_GET["ct"])) {
                 $mime = pathinfo($params["file"], PATHINFO_EXTENSION);
                 $editors = AJXP_PluginsService::searchAllManifests("//editor[contains(@mimes,'{$mime}') and @previewProvider='true']", "node", true, true, false);
                 if (count($editors)) {
                     foreach ($editors as $editor) {
                         $xPath = new DOMXPath($editor->ownerDocument);
                         $callbacks = $xPath->query("//action[@contentTypedProvider]", $editor);
                         if ($callbacks->length) {
                             $ACTION = $callbacks->item(0)->getAttribute("name");
                             if ($ACTION == "audio_proxy") {
                                 $params["file"] = "base64encoded:" . base64_encode($params["file"]);
                             }
                             break;
                         }
                     }
                 }
             }
             AJXP_Controller::registryReset();
             AJXP_Controller::findActionAndApply($ACTION, $params, null);
         } catch (Exception $e) {
             $errMessage = $e->getMessage();
         }
         if ($errMessage == null) {
             return;
         }
         $html = str_replace('AJXP_HASH_LOAD_ERROR', $errMessage, $html);
     }
     if (isset($_GET["lang"])) {
         $loggedUser =& AuthService::getLoggedUser();
         if ($loggedUser != null) {
             $loggedUser->setPref("lang", $_GET["lang"]);
         } else {
             setcookie("AJXP_lang", $_GET["lang"]);
         }
     }
     if (!empty($data["AJXP_APPLICATION_BASE"])) {
         $tPath = $data["AJXP_APPLICATION_BASE"];
     } else {
         $tPath = !empty($data["TRAVEL_PATH_TO_ROOT"]) ? $data["TRAVEL_PATH_TO_ROOT"] : "../..";
     }
     // Update Host dynamically if it differ from registered one.
     $registeredHost = parse_url($tPath, PHP_URL_HOST);
     $currentHost = parse_url(AJXP_Utils::detectServerURL("SERVER_URL"), PHP_URL_HOST);
     if ($registeredHost != $currentHost) {
         $tPath = str_replace($registeredHost, $currentHost, $tPath);
     }
     $html = str_replace("AJXP_PATH_TO_ROOT", rtrim($tPath, "/") . "/", $html);
     HTMLWriter::internetExplorerMainDocumentHeader();
     HTMLWriter::charsetHeader();
     echo $html;
 }