From 571dc17b2172b8775ee1b1b0bc8dbecd33a32c1a Mon Sep 17 00:00:00 2001 From: cdujeu Date: Fri, 11 Oct 2013 15:19:47 +0200 Subject: [PATCH] Update zoho-agent with a key. (cherry picked from commit 1cdbca8) --- .../plugins/editor.zoho/agent/save_zoho.php | 61 ++++++++++--- .../plugins/editor.zoho/class.ZohoEditor.php | 89 ++++++++++--------- core/src/plugins/editor.zoho/manifest.xml | 1 + 3 files changed, 94 insertions(+), 57 deletions(-) diff --git a/core/src/plugins/editor.zoho/agent/save_zoho.php b/core/src/plugins/editor.zoho/agent/save_zoho.php index 9ce82ce798..bca7311f09 100644 --- a/core/src/plugins/editor.zoho/agent/save_zoho.php +++ b/core/src/plugins/editor.zoho/agent/save_zoho.php @@ -1,17 +1,52 @@ \ No newline at end of file + +} diff --git a/core/src/plugins/editor.zoho/class.ZohoEditor.php b/core/src/plugins/editor.zoho/class.ZohoEditor.php index ca09492a74..5d2da8376a 100644 --- a/core/src/plugins/editor.zoho/class.ZohoEditor.php +++ b/core/src/plugins/editor.zoho/class.ZohoEditor.php @@ -28,28 +28,29 @@ * @package AjaXplorer_Plugins * @subpackage Editor */ -class ZohoEditor extends AJXP_Plugin { - - public function performChecks(){ - if(!extension_loaded("openssl")){ +class ZohoEditor extends AJXP_Plugin +{ + public function performChecks() + { + if (!extension_loaded("openssl")) { throw new Exception("Zoho plugin requires PHP 'openssl' extension, as posting the document to the Zoho server requires the Https protocol."); } } - public function switchAction($action, $httpVars, $filesVars){ - - if(!isSet($this->actions[$action])) return false; - - $repository = ConfService::getRepository(); - if(!$repository->detectStreamWrapper(true)){ - return false; - } - - $streamData = $repository->streamData; - $destStreamURL = $streamData["protocol"]."://".$repository->getId(); - - if($action == "post_to_zohoserver"){ + public function switchAction($action, $httpVars, $filesVars) + { + if(!isSet($this->actions[$action])) return false; + + $repository = ConfService::getRepository(); + if (!$repository->detectStreamWrapper(true)) { + return false; + } + + $streamData = $repository->streamData; + $destStreamURL = $streamData["protocol"]."://".$repository->getId(); + + if ($action == "post_to_zohoserver") { $sheetExt = explode(",", "xls,xlsx,ods,sxc,csv,tsv"); $presExt = explode(",", "ppt,pps,odp,sxi"); @@ -57,31 +58,31 @@ public function switchAction($action, $httpVars, $filesVars){ require_once(AJXP_BIN_FOLDER."/http_class/http_class.php"); - $file = base64_decode($httpVars["file"]); - $file = SystemTextEncoding::magicDequote(AJXP_Utils::securePath($file)); - $target = base64_decode($httpVars["parent_url"]); - $tmp = call_user_func(array($streamData["classname"], "getRealFSReference"), $destStreamURL.$file); - $tmp = SystemTextEncoding::fromUTF8($tmp); + $file = base64_decode($httpVars["file"]); + $file = SystemTextEncoding::magicDequote(AJXP_Utils::securePath($file)); + $target = base64_decode($httpVars["parent_url"]); + $tmp = call_user_func(array($streamData["classname"], "getRealFSReference"), $destStreamURL.$file); + $tmp = SystemTextEncoding::fromUTF8($tmp); $node = new AJXP_Node($destStreamURL.$file); AJXP_Controller::applyHook("node.read", array($node)); $extension = strtolower(pathinfo(urlencode(basename($file)), PATHINFO_EXTENSION)); - $httpClient = new http_class(); + $httpClient = new http_class(); $httpClient->request_method = "POST"; $secureToken = $httpVars["secure_token"]; $_SESSION["ZOHO_CURRENT_EDITED"] = $destStreamURL.$file; $_SESSION["ZOHO_CURRENT_UUID"] = md5(rand()."-".microtime()); - if($this->getFilteredOption("USE_ZOHO_AGENT", $repository->getId())){ + if ($this->getFilteredOption("USE_ZOHO_AGENT", $repository->getId())) { $saveUrl = $this->getFilteredOption("ZOHO_AGENT_URL", $repository->getId()); - }else{ + } else { $saveUrl = $target."/".AJXP_PLUGINS_FOLDER."/editor.zoho/agent/save_zoho.php"; } - $params = array( + $params = array( 'id' => $_SESSION["ZOHO_CURRENT_UUID"], 'apikey' => $this->getFilteredOption("ZOHO_API_KEY", $repository->getId()), 'output' => 'url', @@ -91,14 +92,14 @@ public function switchAction($action, $httpVars, $filesVars){ 'format' => $extension, 'mode' => 'normaledit', 'saveurl' => $saveUrl - ); + ); $service = "exportwriter"; - if(in_array($extension, $sheetExt)){ + if (in_array($extension, $sheetExt)) { $service = "sheet"; - }else if(in_array($extension, $presExt)){ + } else if (in_array($extension, $presExt)) { $service = "show"; - }else if(in_array($extension, $docExt)){ + } else if (in_array($extension, $docExt)) { $service = "exportwriter"; } $arguments = array(); @@ -108,11 +109,11 @@ public function switchAction($action, $httpVars, $filesVars){ "content" => array("FileName" => $tmp, "Content-Type" => "automatic/name") ); $err = $httpClient->Open($arguments); - if(empty($err)){ + if (empty($err)) { $err = $httpClient->SendRequest($arguments); - if(empty($err)){ + if (empty($err)) { $response = ""; - while(true){ + while (true) { $body = ""; $error = $httpClient->ReadReplyBody($body, 1000); if($error != "" || strlen($body) == 0) break; @@ -121,13 +122,13 @@ public function switchAction($action, $httpVars, $filesVars){ $result = trim($response); $matchlines = explode("\n", $result); $resultValues = array(); - foreach($matchlines as $line){ + foreach ($matchlines as $line) { list($key, $val) = explode("=", $line, 2); $resultValues[$key] = $val; } - if($resultValues["RESULT"] == "TRUE" && isSet($resultValues["URL"])){ + if ($resultValues["RESULT"] == "TRUE" && isSet($resultValues["URL"])) { header("Location: ".$resultValues["URL"]); - }else{ + } else { echo "Zoho API Error ".$resultValues["ERROR_CODE"]." : ".$resultValues["WARNING"]; echo ""; } @@ -135,21 +136,21 @@ public function switchAction($action, $httpVars, $filesVars){ $httpClient->Close(); } - }else if($action == "retrieve_from_zohoagent"){ + } else if ($action == "retrieve_from_zohoagent") { $targetFile = $_SESSION["ZOHO_CURRENT_EDITED"]; $id = $_SESSION["ZOHO_CURRENT_UUID"].".".pathinfo($targetFile, PATHINFO_EXTENSION); $node = new AJXP_Node($targetFile); $node->loadNodeInfo(); AJXP_Controller::applyHook("node.before_change", array(&$node)); - if($this->getFilteredOption("USE_ZOHO_AGENT",$repository->getId()) ){ - $data = AJXP_Utils::getRemoteContent( $this->getFilteredOption("ZOHO_AGENT_URL",$repository->getId())."?ajxp_action=get_file&name=".$id); - if(strlen($data)){ + if ($this->getFilteredOption("USE_ZOHO_AGENT",$repository->getId()) ) { + $data = AJXP_Utils::getRemoteContent( $this->getFilteredOption("ZOHO_AGENT_URL",$repository->getId())."?ajxp_action=get_file&name=".$id."&key=".$this->getFilteredOption("ZOHO_AGENT_URL", $repository->getId())); + if (strlen($data)) { file_put_contents($targetFile, $data); echo "MODIFIED"; } - }else{ - if(is_file(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/editor.zoho/agent/files/".$id)){ + } else { + if (is_file(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/editor.zoho/agent/files/".$id)) { copy(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/editor.zoho/agent/files/".$id, $targetFile); unlink(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/editor.zoho/agent/files/".$id); echo "MODIFIED"; @@ -159,6 +160,6 @@ public function switchAction($action, $httpVars, $filesVars){ } - } - + } + } diff --git a/core/src/plugins/editor.zoho/manifest.xml b/core/src/plugins/editor.zoho/manifest.xml index 716781d7b8..c618c7132a 100644 --- a/core/src/plugins/editor.zoho/manifest.xml +++ b/core/src/plugins/editor.zoho/manifest.xml @@ -6,6 +6,7 @@ +