28
28
*/
29
29
class PixlrEditor extends AJXP_Plugin
30
30
{
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
+ }
39
37
40
38
$ selection = new UserSelection ($ repository , $ httpVars );
41
39
$ selectedNode = $ selection ->getUniqueNode ();
@@ -49,18 +47,14 @@ public function switchAction($action, $httpVars, $filesVars)
49
47
$ selectedNode = new AJXP_Node ($ selection ->currentBaseUrl ().$ legacyFilePath );
50
48
$ selectedNodeUrl = $ selectedNode ->getUrl ();
51
49
}
52
- $ target = base64_decode ($ httpVars ["parent_url " ])."/plugins/editor.pixlr " ;
50
+
51
+ $ target = rtrim (base64_decode ($ httpVars ["parent_url " ]), '/ ' ) ."/plugins/editor.pixlr " ;
53
52
$ tmp = AJXP_MetaStreamWrapper::getRealFSReference ($ selectedNodeUrl );
54
53
$ tmp = SystemTextEncoding::fromUTF8 ($ tmp );
55
- $ fData = array ("tmp_name " => $ tmp , "name " => urlencode (basename ($ selectedNodeUrl )), "type " => "image/jpg " );
56
54
$ this ->logInfo ('Preview ' , 'Sending content of ' .$ selectedNodeUrl .' to Pixlr server. ' );
57
55
AJXP_Controller::applyHook ("node.read " , array ($ selectedNode ));
58
56
59
57
60
- $ httpClient = new HttpClient ("apps.pixlr.com " );
61
- //$httpClient->setDebug(true);
62
- $ postData = array ();
63
- $ httpClient ->setHandleRedirects (false );
64
58
$ saveTarget = $ target ."/fake_save_pixlr.php " ;
65
59
if ($ this ->getFilteredOption ("CHECK_SECURITY_TOKEN " , $ repository ->getId ())) {
66
60
$ saveTarget = $ target ."/fake_save_pixlr_ " .md5 ($ httpVars ["secure_token " ]).".php " ;
@@ -76,12 +70,35 @@ public function switchAction($action, $httpVars, $filesVars)
76
70
"locktitle " => "true " ,
77
71
"locktype " => "source "
78
72
);
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");
82
98
83
99
} else if ($ action == "retrieve_pixlr_image " ) {
84
100
$ file = AJXP_Utils::decodeSecureMagic ($ httpVars ["original_file " ]);
101
+ $ selectedNode = new AJXP_Node ($ selection ->currentBaseUrl () . $ file );
85
102
$ selectedNode ->loadNodeInfo ();
86
103
$ this ->logInfo ('Edit ' , 'Retrieving content of ' .$ file .' from Pixlr server. ' );
87
104
AJXP_Controller::applyHook ("node.before_change " , array (&$ selectedNode ));
@@ -108,18 +125,17 @@ public function switchAction($action, $httpVars, $filesVars)
108
125
if ($ content_length != 0 ) AJXP_Controller::applyHook ("node.before_change " , array (&$ selectedNode , $ content_length ));
109
126
110
127
$ orig = fopen ($ image , "r " );
111
- $ target = fopen ($ selectedNodeUrl , "w " );
128
+ $ target = fopen ($ selectedNode -> getUrl () , "w " );
112
129
if (is_resource ($ orig ) && is_resource ($ target )){
113
130
while (!feof ($ orig )) {
114
131
fwrite ($ target , fread ($ orig , 4096 ));
115
132
}
116
133
fclose ($ orig );
117
134
fclose ($ target );
118
135
}
119
- clearstatcache (true , $ selectedNodeUrl );
136
+ clearstatcache (true , $ selectedNode -> getUrl () );
120
137
$ selectedNode ->loadNodeInfo (true );
121
138
AJXP_Controller::applyHook ("node.change " , array (&$ selectedNode , &$ selectedNode ));
122
-
123
139
}
124
140
125
141
}
0 commit comments