appName = $AppName; $this->config = \OC::$server->getConfig(); $this->logger = \OC::$server->getLogger(); } /** * Save the document service address to the application configuration * * @param string $documentServer - document service address */ public function SetDocumentServerUrl($documentServer) { $documentServer = strtolower(trim($documentServer)); if (strlen($documentServer) > 0) { $documentServer = rtrim($documentServer, "/") . "/"; if (!preg_match("/(^https?:\/\/)|^\//i", $documentServer)) { $documentServer = "http://" . $documentServer; } } $this->logger->info("SetDocumentServerUrl: " . $documentServer, array("app" => $this->appName)); $this->config->setAppValue($this->appName, $this->_documentserver, $documentServer); } /** * Get the document service address from the application configuration * * @return string */ public function GetDocumentServerUrl() { $url = $this->config->getAppValue($this->appName, $this->_documentserver, ""); if (empty($url)) { $url = $this->predefDocumentServerUrl; } if (empty($url) && !empty($this->config->getSystemValue($this->appName))) { $url = $this->config->getSystemValue($this->appName)[$this->_documentserver]; } if ($url !== "/") { $url = rtrim($url, "/"); if (strlen($url) > 0) { $url = $url . "/"; } } return $url; } /** * Save the document service address available from ownCloud to the application configuration * * @param string $documentServer - document service address */ public function SetDocumentServerInternalUrl($documentServerInternal) { $documentServerInternal = strtolower(rtrim(trim($documentServerInternal), "/")); if (strlen($documentServerInternal) > 0) { $documentServerInternal = $documentServerInternal . "/"; if (!preg_match("/^https?:\/\//i", $documentServerInternal)) { $documentServerInternal = "http://" . $documentServerInternal; } } $this->logger->info("SetDocumentServerInternalUrl: " . $documentServerInternal, array("app" => $this->appName)); $this->config->setAppValue($this->appName, $this->_documentserverInternal, $documentServerInternal); } /** * Get the document service address available from ownCloud from the application configuration * * @return string */ public function GetDocumentServerInternalUrl($origin) { $url = $this->config->getAppValue($this->appName, $this->_documentserverInternal, ""); if (empty($url)) { $url = $this->predefDocumentServerInternalUrl; } if (empty($url) && !empty($this->config->getSystemValue($this->appName))) { $url = $this->config->getSystemValue($this->appName)[$this->_documentserverInternal]; } if (!$origin && empty($url)) { $url = $this->GetDocumentServerUrl(); } return $url; } /** * Save the ownCloud address available from document server to the application configuration * * @param string $documentServer - document service address */ public function SetStorageUrl($storageUrl) { $storageUrl = strtolower(rtrim(trim($storageUrl), "/")); if (strlen($storageUrl) > 0) { $storageUrl = $storageUrl . "/"; if (!preg_match("/^https?:\/\//i", $storageUrl)) { $storageUrl = "http://" . $storageUrl; } } $this->logger->info("SetStorageUrl: " . $storageUrl, array("app" => $this->appName)); $this->config->setAppValue($this->appName, $this->_storageUrl, $storageUrl); } /** * Get the ownCloud address available from document server from the application configuration * * @return string */ public function GetStorageUrl() { $url = $this->config->getAppValue($this->appName, $this->_storageUrl, ""); if (empty($url)) { $url = $this->predefStorageUrl; } if (empty($url) && !empty($this->config->getSystemValue($this->appName))) { $url = $this->config->getSystemValue($this->appName)[$this->_storageUrl]; } return $url; } /** * Save the document service secret key to the application configuration * * @param string $secret - secret key */ public function SetDocumentServerSecret($secret) { if (empty($secret)) { $this->logger->info("Clear secret key", array("app" => $this->appName)); } else { $this->logger->info("Set secret key", array("app" => $this->appName)); } $this->config->setAppValue($this->appName, $this->_secret, $secret); } /** * Get the document service secret key from the application configuration * * @return string */ public function GetDocumentServerSecret() { $secret = $this->config->getAppValue($this->appName, $this->_secret, ""); if (empty($secret)) { $secret = $this->predefDocumentServerSecret; } if (empty($secret) && !empty($this->config->getSystemValue($this->appName))) { $secret = $this->config->getSystemValue($this->appName)[$this->_secret]; } return $secret; } /** * Get the secret key from the application configuration * * @return string */ public function GetSKey() { $skey = $this->config->getAppValue($this->appName, $this->_cryptSecret, ""); if (empty($skey)) { $skey = number_format(round(microtime(true) * 1000), 0, ".", ""); $this->config->setAppValue($this->appName, $this->_cryptSecret, $skey); } return $skey; } /** * Regenerate the secret key */ public function DropSKey() { $this->config->setAppValue($this->appName, $this->_cryptSecret, ""); } /** * Save the formats array with default action * * @param array $formats - formats with status */ public function SetDefaultFormats($formats) { $value = json_encode($formats); $this->logger->info("Set default formats: " . $value, array("app" => $this->appName)); $this->config->setAppValue($this->appName, $this->_defFormats, $value); } /** * Get the formats array with default action * * @return array */ public function GetDefaultFormats() { $value = $this->config->getAppValue($this->appName, $this->_defFormats, ""); if (empty($value)) { return array(); } return json_decode($value, true); } /** * Save the opening setting in a same tab * * @param boolean $value - same tab */ public function SetSameTab($value) { $this->logger->info("Set opening in a same tab: " . $value, array("app" => $this->appName)); $this->config->setAppValue($this->appName, $this->_sameTab, $value); } /** * Get the opening setting in a same tab * * @return boolean */ public function GetSameTab() { return $this->config->getAppValue($this->appName, $this->_sameTab, "false") === "true"; } /** * Additional data about formats * * @var array */ public $formats = [ "docx" => [ "mime" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "type" => "text", "edit" => true, "def" => true ], "xlsx" => [ "mime" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "type" => "spreadsheet", "edit" => true, "def" => true ], "pptx" => [ "mime" => "application/vnd.openxmlformats-officedocument.presentationml.presentation", "type" => "presentation", "edit" => true, "def" => true ], "ppsx" => [ "mime" => "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "type" => "presentation", "edit" => true, "def" => true ], "txt" => [ "mime" => "text/plain", "type" => "text", "edit" => true ], "csv" => [ "mime" => "text/csv", "type" => "spreadsheet", "edit" => true ], "odt" => [ "mime" => "application/vnd.oasis.opendocument.text", "type" => "text", "conv" => true ], "ods" => [ "mime" => "application/vnd.oasis.opendocument.spreadsheet", "type" => "spreadsheet", "conv" => true ], "odp" => [ "mime" => "application/vnd.oasis.opendocument.presentation", "type" => "presentation", "conv" => true ], "doc" => [ "mime" => "application/msword", "type" => "text", "conv" => true ], "xls" => [ "mime" => "application/vnd.ms-excel", "type" => "spreadsheet", "conv" => true ], "ppt" => [ "mime" => "application/vnd.ms-powerpoint", "type" => "presentation", "conv" => true ], "pps" => [ "mime" => "application/vnd.ms-powerpoint", "type" => "presentation", "conv" => true ], "epub" => [ "mime" => "application/epub+zip", "type" => "text", "conv" => true ], "rtf" => [ "mime" => "text/rtf", "type" => "text", "type" => "text", "conv" => true ], "mht" => [ "mime" => "message/rfc822", "conv" => true ], "html" => [ "mime" => "text/html", "type" => "text", "conv" => true ], "htm" => [ "mime" => "text/html", "type" => "text", "conv" => true ], "xps" => [ "mime" => "application/vnd.ms-xpsdocument", "type" => "text" ], "pdf" => [ "mime" => "application/pdf", "type" => "text" ], "djvu" => [ "mime" => "image/vnd.djvu", "type" => "text" ] ]; }