Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fix "Pixlr" plugin because they switch to "https"
Browse files Browse the repository at this point in the history
  • Loading branch information
isma91 committed Oct 13, 2015
1 parent 190b849 commit e331ce6
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions core/src/plugins/editor.pixlr/class.PixlrEditor.php
Expand Up @@ -28,14 +28,12 @@
*/
class PixlrEditor extends AJXP_Plugin
{
public function switchAction($action, $httpVars, $filesVars)
{
if(!isSet($this->actions[$action])) return false;

$repository = ConfService::getRepository();
if (!$repository->detectStreamWrapper(true)) {
return false;
}
public function switchAction($action, $httpVars, $filesVars)
{
$repository = ConfService::getRepository();
if (!$repository->detectStreamWrapper(true)) {
return false;
}

$selection = new UserSelection($repository, $httpVars);
$selectedNode = $selection->getUniqueNode();
Expand All @@ -49,18 +47,14 @@ public function switchAction($action, $httpVars, $filesVars)
$selectedNode = new AJXP_Node($selection->currentBaseUrl().$legacyFilePath);
$selectedNodeUrl = $selectedNode->getUrl();
}
$target = base64_decode($httpVars["parent_url"])."/plugins/editor.pixlr";

$target = rtrim(base64_decode($httpVars["parent_url"]), '/') ."/plugins/editor.pixlr";
$tmp = AJXP_MetaStreamWrapper::getRealFSReference($selectedNodeUrl);
$tmp = SystemTextEncoding::fromUTF8($tmp);
$fData = array("tmp_name" => $tmp, "name" => urlencode(basename($selectedNodeUrl)), "type" => "image/jpg");
$this->logInfo('Preview', 'Sending content of '.$selectedNodeUrl.' to Pixlr server.');
AJXP_Controller::applyHook("node.read", array($selectedNode));


$httpClient = new HttpClient("apps.pixlr.com");
//$httpClient->setDebug(true);
$postData = array();
$httpClient->setHandleRedirects(false);
$saveTarget = $target."/fake_save_pixlr.php";
if ($this->getFilteredOption("CHECK_SECURITY_TOKEN", $repository->getId())) {
$saveTarget = $target."/fake_save_pixlr_".md5($httpVars["secure_token"]).".php";
Expand All @@ -76,12 +70,35 @@ public function switchAction($action, $httpVars, $filesVars)
"locktitle" => "true",
"locktype" => "source"
);
$httpClient->postFile("/editor/", $params, "image", $fData);
$loc = $httpClient->getHeader("location");
header("Location:$loc");

require_once(AJXP_BIN_FOLDER."/http_class/http_class.php");
$arguments = array();
$httpClient = new http_class();
$httpClient->request_method = "POST";
$httpClient->GetRequestArguments("https://pixlr.com/editor/", $arguments);
$arguments["PostValues"] = $params;
$arguments["PostFiles"] = array(
"image" => array("FileName" => $tmp, "Content-Type" => "automatic/name"));

$err = $httpClient->Open($arguments);
if (empty($err)) {
$err = $httpClient->SendRequest($arguments);
if (empty($err)) {
$response = "";
while (true) {
$header = array();
$error = $httpClient->ReadReplyHeaders($header, 1000);
if ($error != "" || $header != null) break;
$response .= $header;
}
}
}

header("Location: {$header['location']}"); //$response");

} else if ($action == "retrieve_pixlr_image") {
$file = AJXP_Utils::decodeSecureMagic($httpVars["original_file"]);
$selectedNode = new AJXP_Node($selection->currentBaseUrl() . $file);
$selectedNode->loadNodeInfo();
$this->logInfo('Edit', 'Retrieving content of '.$file.' from Pixlr server.');
AJXP_Controller::applyHook("node.before_change", array(&$selectedNode));
Expand All @@ -108,18 +125,17 @@ public function switchAction($action, $httpVars, $filesVars)
if($content_length != 0) AJXP_Controller::applyHook("node.before_change", array(&$selectedNode, $content_length));

$orig = fopen($image, "r");
$target = fopen($selectedNodeUrl, "w");
$target = fopen($selectedNode->getUrl(), "w");
if(is_resource($orig) && is_resource($target)){
while (!feof($orig)) {
fwrite($target, fread($orig, 4096));
}
fclose($orig);
fclose($target);
}
clearstatcache(true, $selectedNodeUrl);
clearstatcache(true, $selectedNode->getUrl());
$selectedNode->loadNodeInfo(true);
AJXP_Controller::applyHook("node.change", array(&$selectedNode, &$selectedNode));

}

}
Expand Down

0 comments on commit e331ce6

Please sign in to comment.