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

Commit e331ce6

Browse files
committed
Fix "Pixlr" plugin because they switch to "https"
1 parent 190b849 commit e331ce6

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

core/src/plugins/editor.pixlr/class.PixlrEditor.php

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
*/
2929
class PixlrEditor extends AJXP_Plugin
3030
{
31-
public function switchAction($action, $httpVars, $filesVars)
32-
{
33-
if(!isSet($this->actions[$action])) return false;
34-
35-
$repository = ConfService::getRepository();
36-
if (!$repository->detectStreamWrapper(true)) {
37-
return false;
38-
}
31+
public function switchAction($action, $httpVars, $filesVars)
32+
{
33+
$repository = ConfService::getRepository();
34+
if (!$repository->detectStreamWrapper(true)) {
35+
return false;
36+
}
3937

4038
$selection = new UserSelection($repository, $httpVars);
4139
$selectedNode = $selection->getUniqueNode();
@@ -49,18 +47,14 @@ public function switchAction($action, $httpVars, $filesVars)
4947
$selectedNode = new AJXP_Node($selection->currentBaseUrl().$legacyFilePath);
5048
$selectedNodeUrl = $selectedNode->getUrl();
5149
}
52-
$target = base64_decode($httpVars["parent_url"])."/plugins/editor.pixlr";
50+
51+
$target = rtrim(base64_decode($httpVars["parent_url"]), '/') ."/plugins/editor.pixlr";
5352
$tmp = AJXP_MetaStreamWrapper::getRealFSReference($selectedNodeUrl);
5453
$tmp = SystemTextEncoding::fromUTF8($tmp);
55-
$fData = array("tmp_name" => $tmp, "name" => urlencode(basename($selectedNodeUrl)), "type" => "image/jpg");
5654
$this->logInfo('Preview', 'Sending content of '.$selectedNodeUrl.' to Pixlr server.');
5755
AJXP_Controller::applyHook("node.read", array($selectedNode));
5856

5957

60-
$httpClient = new HttpClient("apps.pixlr.com");
61-
//$httpClient->setDebug(true);
62-
$postData = array();
63-
$httpClient->setHandleRedirects(false);
6458
$saveTarget = $target."/fake_save_pixlr.php";
6559
if ($this->getFilteredOption("CHECK_SECURITY_TOKEN", $repository->getId())) {
6660
$saveTarget = $target."/fake_save_pixlr_".md5($httpVars["secure_token"]).".php";
@@ -76,12 +70,35 @@ public function switchAction($action, $httpVars, $filesVars)
7670
"locktitle" => "true",
7771
"locktype" => "source"
7872
);
79-
$httpClient->postFile("/editor/", $params, "image", $fData);
80-
$loc = $httpClient->getHeader("location");
81-
header("Location:$loc");
73+
74+
require_once(AJXP_BIN_FOLDER."/http_class/http_class.php");
75+
$arguments = array();
76+
$httpClient = new http_class();
77+
$httpClient->request_method = "POST";
78+
$httpClient->GetRequestArguments("https://pixlr.com/editor/", $arguments);
79+
$arguments["PostValues"] = $params;
80+
$arguments["PostFiles"] = array(
81+
"image" => array("FileName" => $tmp, "Content-Type" => "automatic/name"));
82+
83+
$err = $httpClient->Open($arguments);
84+
if (empty($err)) {
85+
$err = $httpClient->SendRequest($arguments);
86+
if (empty($err)) {
87+
$response = "";
88+
while (true) {
89+
$header = array();
90+
$error = $httpClient->ReadReplyHeaders($header, 1000);
91+
if ($error != "" || $header != null) break;
92+
$response .= $header;
93+
}
94+
}
95+
}
96+
97+
header("Location: {$header['location']}"); //$response");
8298

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

110127
$orig = fopen($image, "r");
111-
$target = fopen($selectedNodeUrl, "w");
128+
$target = fopen($selectedNode->getUrl(), "w");
112129
if(is_resource($orig) && is_resource($target)){
113130
while (!feof($orig)) {
114131
fwrite($target, fread($orig, 4096));
115132
}
116133
fclose($orig);
117134
fclose($target);
118135
}
119-
clearstatcache(true, $selectedNodeUrl);
136+
clearstatcache(true, $selectedNode->getUrl());
120137
$selectedNode->loadNodeInfo(true);
121138
AJXP_Controller::applyHook("node.change", array(&$selectedNode, &$selectedNode));
122-
123139
}
124140

125141
}

0 commit comments

Comments
 (0)