Skip to content

Commit b267366

Browse files
Added tooltip + updated text of old tooltip.
1 parent 76cc4cb commit b267366

7 files changed

Lines changed: 150 additions & 121 deletions

File tree

composer.phar

1.63 MB
Binary file not shown.

src/config/tiny-config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
class Tiny_Config {
88
/* URL is only used by fopen driver. */
9-
const URL = 'https://api.tinify.com/shrink';
9+
const URL = 'http://webservice/shrink';
1010
const MONTHLY_FREE_COMPRESSIONS = 500;
1111
}

src/css/bulk-optimization.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ div.tiny-bulk-optimization div.available table.totals td.item div.tooltip div.ti
105105
text-align: left;
106106
}
107107

108-
div.tiny-bulk-optimization div.available table.totals td.item div.tooltip:hover div.tip {
109-
display: block;
110-
}
111-
112108
div.tiny-bulk-optimization div.available div.notes {
113109
display: table;
114110
}
@@ -265,6 +261,10 @@ div.tiny-bulk-optimization div.optimize div.progressbar div.progress {
265261
}
266262
}
267263

264+
#tiny-bulk-optimization > div.dashboard > div.statistics td.item.costs > div.cost-currency {
265+
display: inline-block;
266+
}
267+
268268
div.tiny-bulk-optimization div.optimize div.progressbar div.numbers {
269269
position: relative;
270270
z-index: 3;

src/js/bulk-optimization.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,24 @@
211211
}
212212
});
213213

214+
jQuery('.tooltip').on('mouseenter', function(){
215+
jQuery(this).find('.tip').show()
216+
clearTimeout('.tooltip')
217+
})
218+
219+
jQuery('.tooltip').on('mouseleave', function(){
220+
var that = this
221+
toolTip = setTimeout(function() {
222+
if (jQuery(that).find('.tip').is(':visible')) {
223+
jQuery('.tip').hide()
224+
}
225+
}, 150)
226+
})
227+
228+
jQuery('.tip').on('mouseenter', function(){
229+
clearTimeout(toolTip)
230+
})
231+
214232
window.bulkOptimizationAutorun = startBulkOptimization
215233
window.bulkOptimization = prepareBulkOptimization
216234

src/vendor/tinify/Tinify/Client.php

Lines changed: 113 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3,119 +3,117 @@
33
namespace Tinify;
44

55
class Client {
6-
const API_ENDPOINT = "https://api.tinify.com";
7-
8-
protected $options;
9-
10-
public static function userAgent() {
11-
$curl = curl_version();
12-
return "Tinify/" . VERSION . " PHP/" . PHP_VERSION . " curl/" . $curl["version"];
13-
}
14-
15-
private static function caBundle() {
16-
return __DIR__ . "/../data/cacert.pem";
17-
}
18-
19-
function __construct($key, $appIdentifier = NULL) {
20-
$userAgent = join(" ", array_filter(array(self::userAgent(), $appIdentifier)));
21-
$this->options = array(
22-
CURLOPT_BINARYTRANSFER => true,
23-
CURLOPT_RETURNTRANSFER => true,
24-
CURLOPT_HEADER => true,
25-
CURLOPT_USERPWD => $key ? ("api:" . $key) : NULL,
26-
CURLOPT_CAINFO => self::caBundle(),
27-
CURLOPT_SSL_VERIFYPEER => true,
28-
CURLOPT_USERAGENT => $userAgent,
29-
);
30-
}
31-
32-
function request($method, $url, $body = NULL, $header = array()) {
33-
if (is_array($body)) {
34-
if (!empty($body)) {
35-
$body = json_encode($body);
36-
array_push($header, "Content-Type: application/json");
37-
} else {
38-
$body = NULL;
39-
}
40-
}
41-
42-
$request = curl_init();
43-
curl_setopt_array($request, $this->options);
44-
45-
$url = strtolower(substr($url, 0, 6)) == "https:" ? $url : self::API_ENDPOINT . $url;
46-
curl_setopt($request, CURLOPT_URL, $url);
47-
curl_setopt($request, CURLOPT_CUSTOMREQUEST, strtoupper($method));
48-
49-
if (count($header) > 0) {
50-
curl_setopt($request, CURLOPT_HTTPHEADER, $header);
51-
}
52-
53-
if ($body) {
54-
curl_setopt($request, CURLOPT_POSTFIELDS, $body);
55-
}
56-
57-
$response = curl_exec($request);
58-
59-
if (is_string($response)) {
60-
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
61-
$headerSize = curl_getinfo($request, CURLINFO_HEADER_SIZE);
62-
curl_close($request);
63-
64-
$headers = self::parseHeaders(substr($response, 0, $headerSize));
65-
$body = substr($response, $headerSize);
66-
67-
if (isset($headers["compression-count"])) {
68-
Tinify::setCompressionCount(intval($headers["compression-count"]));
69-
}
70-
71-
$isJson = false;
72-
if (isset($headers["content-type"])) {
73-
/* Parse JSON response bodies. */
74-
list($contentType) = explode(";", $headers["content-type"], 2);
75-
if (strtolower(trim($contentType)) == "application/json") {
76-
$isJson = true;
77-
}
78-
}
79-
80-
/* 1xx and 3xx are unexpected and will be treated as error. */
81-
$isError = $status <= 199 || $status >= 300;
82-
83-
if ($isJson || $isError) {
84-
/* Parse JSON bodies, always interpret errors as JSON. */
85-
$body = json_decode($body);
86-
if (!$body) {
87-
$message = sprintf("Error while parsing response: %s (#%d)",
88-
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : "Error",
89-
json_last_error());
90-
throw Exception::create($message, "ParseError", $status);
91-
}
92-
}
93-
94-
if ($isError) {
95-
throw Exception::create($body->message, $body->error, $status);
96-
}
97-
98-
return (object) array("body" => $body, "headers" => $headers);
99-
} else {
100-
$message = sprintf("%s (#%d)", curl_error($request), curl_errno($request));
101-
curl_close($request);
102-
throw new ConnectionException("Error while connecting: " . $message);
103-
}
104-
}
105-
106-
protected static function parseHeaders($headers) {
107-
if (!is_array($headers)) {
108-
$headers = explode("\r\n", $headers);
109-
}
110-
111-
$result = array();
112-
foreach ($headers as $header) {
113-
if (empty($header)) continue;
114-
$split = explode(":", $header, 2);
115-
if (count($split) === 2) {
116-
$result[strtolower($split[0])] = trim($split[1]);
117-
}
118-
}
119-
return $result;
120-
}
6+
const API_ENDPOINT = 'http://webservice';
7+
8+
private $options;
9+
10+
public static function userAgent() {
11+
$curl = curl_version();
12+
return 'Tinify/' . VERSION . ' PHP/' . PHP_VERSION . ' curl/' . $curl['version'];
13+
}
14+
15+
private static function caBundle() {
16+
return __DIR__ . '/../data/cacert.pem';
17+
}
18+
19+
function __construct($key, $appIdentifier = null) {
20+
$userAgent = join( ' ', array_filter( array( self::userAgent(), $appIdentifier) ) );
21+
$this->options = array(
22+
CURLOPT_BINARYTRANSFER => true,
23+
CURLOPT_RETURNTRANSFER => true,
24+
CURLOPT_HEADER => true,
25+
CURLOPT_USERPWD => $key ? ('api:' . $key) : null,
26+
CURLOPT_USERAGENT => $userAgent,
27+
);
28+
}
29+
30+
function request($method, $url, $body = null, $header = array() ) {
31+
if ( is_array( $body ) ) {
32+
if ( ! empty( $body ) ) {
33+
$body = json_encode( $body );
34+
array_push( $header, 'Content-Type: application/json' );
35+
} else {
36+
$body = null;
37+
}
38+
}
39+
40+
$request = curl_init();
41+
curl_setopt_array( $request, $this->options );
42+
43+
$url = strtolower( substr( $url, 0, 5 ) ) == 'http:' ? $url : self::API_ENDPOINT . $url;
44+
curl_setopt( $request, CURLOPT_URL, $url );
45+
curl_setopt( $request, CURLOPT_HTTPHEADER, $header );
46+
curl_setopt( $request, CURLOPT_CUSTOMREQUEST, strtoupper( $method ) );
47+
48+
if ( $body ) {
49+
curl_setopt( $request, CURLOPT_POSTFIELDS, $body );
50+
}
51+
52+
$response = curl_exec( $request );
53+
54+
if ( is_string( $response ) ) {
55+
$status = curl_getinfo( $request, CURLINFO_HTTP_CODE );
56+
$headerSize = curl_getinfo( $request, CURLINFO_HEADER_SIZE );
57+
curl_close( $request );
58+
59+
$headers = self::parseHeaders( substr( $response, 0, $headerSize ) );
60+
$body = substr( $response, $headerSize );
61+
62+
if ( isset( $headers['compression-count'] ) ) {
63+
Tinify::setCompressionCount( intval( $headers['compression-count'] ) );
64+
}
65+
66+
$isJson = false;
67+
if ( isset( $headers['content-type'] ) ) {
68+
/* Parse JSON response bodies. */
69+
list($contentType) = explode( ';', $headers['content-type'], 2 );
70+
if ( strtolower( trim( $contentType ) ) == 'application/json' ) {
71+
$isJson = true;
72+
}
73+
}
74+
75+
/* 1xx and 3xx are unexpected and will be treated as error. */
76+
$isError = $status <= 199 || $status >= 300;
77+
78+
if ( $isJson || $isError ) {
79+
/* Parse JSON bodies, always interpret errors as JSON. */
80+
$body = json_decode( $body );
81+
if ( ! $body ) {
82+
$message = sprintf('Error while parsing response: %s (#%d)',
83+
PHP_VERSION_ID >= 50500 ? json_last_error_msg() : 'Error',
84+
json_last_error());
85+
throw Exception::create( $message, 'ParseError', $status );
86+
}
87+
}
88+
89+
if ( $isError ) {
90+
throw Exception::create( $body->message, $body->error, $status );
91+
}
92+
93+
return (object) array( 'body' => $body, 'headers' => $headers );
94+
} else {
95+
$message = sprintf( '%s (#%d)', curl_error( $request ), curl_errno( $request ) );
96+
curl_close( $request );
97+
throw new ConnectionException( 'Error while connecting: ' . $message );
98+
}
99+
}
100+
101+
protected static function parseHeaders($headers) {
102+
if ( ! is_array( $headers ) ) {
103+
$headers = explode( "\r\n", $headers );
104+
}
105+
106+
$result = array();
107+
foreach ( $headers as $header ) {
108+
if ( empty( $header ) ) {
109+
continue;
110+
}
111+
112+
$split = explode( ':', $header, 2 );
113+
if ( count( $split ) === 2 ) {
114+
$result[strtolower( $split[0] )] = trim( $split[1] );
115+
}
116+
}
117+
return $result;
118+
}
121119
}

src/views/bulk-optimization.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
}
115115
?>
116116
</p>
117+
<p><b>1 image = <?php echo sizeof( $active_tinify_sizes ) ?> compressions</b></p><p> <a href="/wp-admin/options-media.php#tiny-compress-images">Change Settings</a></p>
117118
</div>
118119
</div>
119120
</td>
@@ -122,7 +123,15 @@
122123
<?php echo wp_kses( __( 'Estimated <br> cost', 'tiny-compress-images' ), array( 'br' => array() ) ) ?>
123124
</h3>
124125
<span id="estimated-cost">$ <?php echo number_format( $estimated_costs, 2 ) ?></span>
125-
USD
126+
<div class="cost-currency">USD</div>
127+
128+
<div class="tooltip">
129+
<span class="dashicons dashicons-info"></span>
130+
<div class="tip">
131+
<p>If you wish to compress more than <b>500 images a month</b> and you are still on a free account <a href="https://tinypng.com/developers">upgrade here.</a></p>
132+
</div>
133+
</div>
134+
126135
</td>
127136
</tr>
128137
</table>

test/integration/BulkOptimizationIntegrationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,8 @@ public function test_start_bulk_optimization_should_optimize_remaining_images()
7777

7878
$this->assertEquals( '9 / 9 (100%)', $this->find( '#compression-progress-bar' )->getText() );
7979
}
80+
81+
public function test_should_display_tooltips() {
82+
$this->assertEquals( '2', sizeof($this->find_all( 'div.tip' )));
83+
}
8084
}

0 commit comments

Comments
 (0)