Skip to content

Commit 7c1a7b2

Browse files
author
Jacob Middag
committed
Rewrite resize_options to be compatible with PHP 5.2
1 parent 3bfeff7 commit 7c1a7b2

2 files changed

Lines changed: 17 additions & 30 deletions

File tree

src/class-tiny-compress-curl.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,25 @@ protected function shrink($input) {
6363
return array(self::decode(substr($response, $header_size)), $headers, $status_code);
6464
}
6565

66-
protected function output_options($url) {
67-
return array(
66+
protected function output_options($url, $resize) {
67+
$options = array(
6868
CURLOPT_URL => $url,
6969
CURLOPT_RETURNTRANSFER => true,
7070
CURLOPT_HEADER => true,
7171
CURLOPT_CAINFO => self::get_ca_file(),
7272
CURLOPT_SSL_VERIFYPEER => true
7373
);
74-
}
75-
76-
protected function resize_options($resize) {
77-
if (!$resize) {
78-
return array();
74+
if ($resize) {
75+
$options[CURLOPT_USERPWD] = 'api:' . $this->api_key;
76+
$options[CURLOPT_HTTPHEADER] = array('Content-Type: application/json');
77+
$options[CURLOPT_POSTFIELDS] = json_encode(array('resize' => $resize));
7978
}
80-
return array(
81-
CURLOPT_USERPWD => 'api:' . $this->api_key,
82-
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
83-
CURLOPT_POSTFIELDS => json_encode(array('resize' => $resize))
84-
);
79+
return $options;
8580
}
8681

8782
protected function output($url, $resize) {
8883
$request = curl_init();
89-
$options = array_replace_recursive($this->output_options($url), $this->resize_options($resize));
84+
$options = $this->output_options($url, $resize);
9085
curl_setopt_array($request, $options);
9186

9287
$response = curl_exec($request);

src/class-tiny-compress-fopen.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ protected function shrink($input) {
6666
return array(self::decode($response), $headers, $status_code);
6767
}
6868

69-
protected function output_options() {
70-
return array(
69+
protected function output_options($resize) {
70+
$options = array(
7171
'http' => array(
7272
'method' => 'GET',
7373
),
@@ -76,25 +76,17 @@ protected function output_options() {
7676
'verify_peer' => true
7777
)
7878
);
79-
}
80-
81-
protected function resize_options($resize) {
82-
if (!$resize) {
83-
return array();
79+
if ($resize) {
80+
$options['http']['header'] = array(
81+
'Authorization: Basic ' . base64_encode('api:' . $this->api_key),
82+
'Content-Type: application/json'
83+
);
84+
$options['http']['content'] = json_encode(array('resize' => $resize));
8485
}
85-
return array(
86-
'http' => array(
87-
'header' => array(
88-
'Authorization: Basic ' . base64_encode('api:' . $this->api_key),
89-
'Content-Type: application/json'
90-
),
91-
'content' => json_encode(array('resize' => $resize))
92-
)
93-
);
9486
}
9587

9688
protected function output($url, $resize) {
97-
$options = array_replace_recursive($this->output_options(), $this->resize_options($resize));
89+
$options = $this->output_options($resize);
9890
$context = stream_context_create($options);
9991
$request = @fopen($url, 'rb', false, $context);
10092

0 commit comments

Comments
 (0)