PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.2
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.2
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / src / class-stockpackquery.php

class-stockpackquery.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 2.5.2, at src/class-stockpackquery.php

753 lines 38.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 use GuzzleHttp\Client;
5 use GuzzleHttp\Cookie\CookieJar;
6 use GuzzleHttp\Exception\GuzzleException;
7 use GuzzleHttp\TransferStats;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 if ( ! class_exists( 'StockpackQuery' ) ) {
13 class StockpackQuery {
14 /**
15 * @var Singleton The reference the *Singleton* instance of this class
16 */
17 private static $instance;
18
19 /**
20 * Api url
21 */
22 private $url = 'https://api.stockpack.co/api';
23 /**
24 * Api version
25 */
26 const VERSION = 'v1';
27
28 /**
29 * @var string
30 */
31 private $api_key;
32
33 /**
34 * @var Client
35 */
36 private $client;
37
38 public static function get_instance() {
39 if ( null === self::$instance ) {
40 self::$instance = new self();
41 }
42
43 return self::$instance;
44 }
45
46 /**
47 * StockPack constructor.
48 */
49 protected function __construct() {
50 if ( ! defined( 'STOCKPACK_URL' ) ) {
51 $this->url = 'https://api.stockpack.co/api';
52 } else {
53 $this->url = STOCKPACK_URL;
54 }
55
56 $this->api_key =
57 add_action( 'plugins_loaded', array( $this, 'init' ) );
58 }
59
60 /**
61 *
62 */
63 public function init() {
64 $this->actions();
65 }
66
67
68 /**
69 *
70 */
71 public function actions() {
72 add_action( 'wp_ajax_query-stockpack', array( $this, 'query' ) ); // executed when logged in
73 add_action( 'wp_ajax_license_cost-stockpack', array(
74 $this,
75 'license_cost'
76 ) ); // executed when logged in
77 add_action( 'wp_ajax_download-stockpack', array( $this, 'download' ) ); // executed when logged in
78 add_action( 'wp_ajax_cache-stockpack', array( $this, 'cache' ) ); // executed when logged in
79 add_action( 'wp_ajax_validate-stockpack', array( $this, 'validate' ) ); // executed when logged in
80 add_action( 'wp_ajax_terms-stockpack', array( $this, 'terms' ) ); // executed when logged in
81 add_action( 'wp_ajax_token-stockpack', array( $this, 'token' ) ); // executed when logged in
82 }
83
84 public function terms() {
85 check_ajax_referer( 'stockpack_terms', 'security' );
86
87 $provider = '';
88 if ( isset( $_REQUEST['provider'] ) ) {
89 $provider = sanitize_key( $_REQUEST['provider'] );
90 }
91
92 wp_send_json_success( update_option( 'terms_accepted_' . $provider, true ) );
93 }
94
95 public function license_cost() {
96 check_ajax_referer( 'stockpack_license_cost', 'security' );
97 $media_id = '';
98 if ( isset( $_REQUEST['media_id'] ) ) {
99 $media_id = sanitize_text_field( $_REQUEST['media_id'] );
100 }
101
102 $provider = 0;
103 if ( isset( $_REQUEST['provider'] ) ) {
104 $provider = sanitize_text_field( $_REQUEST['provider'] );
105 }
106
107 $response = $this->get_license_cost( $media_id, $provider );
108
109 if ( isset( $response->data->error ) ) {
110 wp_send_json_error( $this->handle_license_errors( $response->data ) );
111 die();
112 }
113
114 if ( is_wp_error( $response ) ) {
115 wp_send_json_error( $this->handle_license_errors( $response ) );
116 die();
117 }
118
119 if ( $response->data->cost == - 1 ) {
120 $response->data->cost_message = __( 'You already own the asset, you can proceed without additional cost', 'stockpack' );
121 }
122
123 if ( $response->data->cost == 1 && ! $response->data->cost_message ) {
124 $response->data->cost_message = __( 'You will be charged for one image on you provider account', 'stockpack' );
125 }
126
127 wp_send_json_success( $response->data, true );
128 }
129
130 public function token() {
131 global $stockpack;
132 check_ajax_referer( 'stockpack_token', 'security' );
133 $token = '';
134 if ( isset( $_REQUEST['token'] ) ) {
135 $token = sanitize_text_field( $_REQUEST['token'] );
136 }
137 wp_send_json_success( $stockpack->admin->set_api_key( $token ), true );
138 }
139
140 /**
141 *
142 */
143 public function validate() {
144 check_ajax_referer( 'stockpack_validate', 'security' );
145 $key = '';
146 if ( isset( $_REQUEST['key'] ) ) {
147 $key = sanitize_key( $_REQUEST['key'] );
148 }
149 wp_send_json_success( $this->call( 'GET', 'validate/token', array( 'key' => $key ) ) );
150 }
151
152 /**
153 *
154 */
155 public function query() {
156 check_ajax_referer( 'stockpack_query', 'security' );
157 if ( ! current_user_can( 'upload_files' ) ) {
158 wp_send_json_error();
159 }
160 $query = array();
161 if ( isset( $_REQUEST['query'] ) ) {
162 $query = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['query'] ) );
163 }
164
165 if ( ! $query['query'] ) {
166 return wp_send_json_success( array() );
167 }
168
169 $images = $this->images( $query );
170 if ( is_wp_error( $images ) ) {
171 /** @var WP_Error $images */
172 wp_send_json_error( $images );
173 die();
174 }
175
176 if ( isset( $images->data->error ) ) {
177 wp_send_json_error( $this->handle_search_errors( $images->data ) );
178 die();
179 }
180
181 wp_send_json_success( $this->format( $images->data ) );
182 }
183
184 /**
185 *
186 */
187 public function cache() {
188 check_ajax_referer( 'stockpack_cache', 'security' );
189
190 if ( ! current_user_can( 'upload_files' ) ) {
191 wp_send_json_error();
192 }
193 $id = 0;
194
195 if ( isset( $_REQUEST['media_id'] ) ) {
196 $id = sanitize_text_field( $_REQUEST['media_id'] );
197 }
198 $args = array(
199 'post_type' => 'attachment',
200 'post_status' => 'inherit',
201 'meta_query' => array(
202 array(
203 'key' => 'stockpack_id',
204 'value' => $id
205 )
206 )
207 );
208 $query = new WP_Query( $args );
209 if ( ! $query->have_posts() ) {
210 wp_send_json_error( array( 'message' => __( 'Image not found in cache', 'stockpack' ) ) );
211 }
212
213 wp_send_json_success( wp_prepare_attachment_for_js( $query->post->ID ) );
214
215 }
216
217 /**
218 *
219 */
220 public function download() {
221 check_ajax_referer( 'stockpack_download', 'security' );
222 if ( ! current_user_can( 'upload_files' ) ) {
223 wp_send_json_error( array( 'message' => __( 'You are not allowed to upload files', 'stockpack' ) ) );
224 }
225
226 $id = 0;
227 if ( isset( $_REQUEST['media_id'] ) ) {
228 $id = sanitize_text_field( $_REQUEST['media_id'] );
229 }
230 $post_id = 0;
231 if ( isset( $_REQUEST['post_id'] ) ) {
232 $post_id = sanitize_text_field( $_REQUEST['post_id'] );
233 }
234 $provider = 0;
235 if ( isset( $_REQUEST['provider'] ) ) {
236 $provider = sanitize_text_field( $_REQUEST['provider'] );
237 }
238 $must_license = false;
239 if ( isset( $_REQUEST['must_license'] ) ) {
240 $must_license = sanitize_text_field( $_REQUEST['must_license'] );
241 }
242
243 if ( isset( $_REQUEST['new_filename'] ) ) {
244 $new_filename = sanitize_text_field( $_REQUEST['new_filename'] );
245 }
246 $search = isset( $_REQUEST['search'] ) ? sanitize_title( $_REQUEST['search'] ) : $this->get_domain();
247 $description = isset( $_REQUEST['description'] ) ? sanitize_textarea_field( $_REQUEST['description'] ) : '';
248 $image = $this->image( $id, $post_id, $description, $search, $must_license, $provider, $new_filename );
249
250 if ( is_wp_error( $image ) ) {
251 if ( strpos( $image->get_error_code(), 'limit_reached' ) !== false ) {
252 wp_send_json_error( $image );
253 die();
254 }
255 wp_send_json_error( array( 'message' => $image->get_error_message() ) );
256 }
257
258 wp_send_json_success( wp_prepare_attachment_for_js( $image ) );
259
260 }
261
262
263 /**
264 * @param $data
265 *
266 * @return array
267 */
268 private function format( $data ) {
269 return $data;
270 }
271
272 /**
273 * @param $image
274 *
275 * @return array
276 */
277 private function individual( $image ) {
278 return [
279 'id' => $image->id,
280 'description' => $image->description,
281 'caption' => $image->caption ? $image->caption : '',
282 'url' => $image->assets->huge_thumb->url,
283 'sizes' => [
284 'full' => $this->size( $image, 'huge_thumb' ),
285 'medium' => $this->size( $image, 'preview' ),
286 'thumbnail' => $this->size( $image, 'large_thumb' )
287 ]
288 ];
289 }
290
291 private function size( $image, $format ) {
292 return [
293 'height' => $image->assets->$format->height,
294 'width' => $image->assets->$format->width,
295 'orientation' => ( $image->aspect > 1 ? 'landscape' : 'portrait' ),
296 'url' => $image->assets->$format->url
297 ];
298 }
299
300 private function get_license_cost( $media_id, $provider ) {
301
302 $response = $this->call( 'GET', 'images/license-cost', array(
303 'id' => $media_id,
304 'locale' => get_locale(),
305 'provider' => $provider
306 ) );
307
308 return $response;
309
310
311 }
312
313 private function image( $media_id, $post_id, $description = '', $search = '', $must_license = 0, $provider = 0, $new_filename = '' ) {
314
315 $image = $this->call( 'GET', 'images/download',
316 array(
317 'id' => $media_id,
318 'must_license' => $must_license,
319 'provider' => $provider
320 )
321 );
322
323 if ( ! isset( $image->data->download ) ) {
324 if ( is_wp_error( $image ) ) {
325 return $image;
326 }
327
328 return $this->handle_download_errors( $image->data );
329 }
330
331 $filename = $image->data->name;
332
333 if ( $new_filename ) {
334 $filename = $new_filename;
335 }
336
337 $caption = $image->data->caption ?: '';
338 $attachment_id = $this->upload_remote_image_and_attach( $image->data->download, $post_id, $description, $filename, $search, $caption );
339 if ( is_wp_error( $attachment_id ) ) {
340 return $attachment_id;
341 }
342 if ( ! $attachment_id ) {
343 return new WP_Error( __( 'upload_failure', 'There has been a problem with the upload. Please try again', 'stockpack' ) );
344 }
345
346 update_post_meta( $attachment_id, 'stockpack_id', $media_id );
347
348 return $attachment_id;
349 }
350
351 private function handle_license_errors( $response ) {
352 if ( isset( $response->code ) ) {
353 switch ( $response->code ) {
354 case 'token_expired':
355 return new WP_Error( 'license_cost_failure', __( 'Please reconnect the account on StockPack, the permissions have expired. Go the providers page on stockpack.co/providers', 'stockpack' ) );
356 }
357 }
358
359 return new WP_Error( 'license_cost_failure', __( 'There has been a problem fetching the cost. Please try to reconnect the account on the providers page on stockpack.co/providers', 'stockpack' ) );
360 }
361
362 private function handle_download_errors( $response ) {
363 if ( isset( $response->code ) ) {
364 switch ( $response->code ) {
365 case 'token_expired':
366 return new WP_Error( 'download_failure', __( 'Please reconnect the account on StockPack, the permissions have expired. Go the providers page on stockpack.co/providers', 'stockpack' ) );
367 }
368 }
369
370 return new WP_Error( 'download_failure', __( 'There has been a problem with the download. Try to reconnect the account for the provider on StockPack. If the issue persists, contact stockpack support.', 'stockpack' ) );
371 }
372
373 private function handle_search_errors( $response ) {
374 if ( isset( $response->code ) ) {
375 switch ( $response->code ) {
376 case 'token_expired':
377 return new WP_Error( 'search_failure', __( 'Please reconnect the account on stockpack, the permissions have expired. Go to the providers page on stockpack.co/providers', 'stockpack' ) );
378 }
379 }
380
381 return new WP_Error( 'search_failure', __( 'There has been a problem with the api, please check the accounts on the providers page in stockpack.co/providers', 'stockpack' ) );
382
383 }
384
385 private function images( $query = [] ) {
386
387 return $this->call( 'GET', 'images/search', $query );
388 }
389
390 /**
391 * @param $method
392 * @param $path
393 * @param array $query
394 *
395 * @return mixed|null
396 */
397 private function call( $method, $path, $query = [] ) {
398 /** @var StockPack $stockpack */
399 global $stockpack;
400
401 try {
402 if ( ! isset( $query['key'] ) ) {
403 $api_key = $stockpack->admin->get_api_key();
404 if ( $api_key ) {
405 $query = array_merge( $query,
406 [
407 'api_token' => $api_key
408 ]
409 );
410 } else {
411 $path .= '-trial';
412 }
413 }
414
415 $query = array_merge( $query,
416 [
417 'referral' => get_bloginfo( 'url' ),
418 'safe_search' => $stockpack->admin->get_safe_search(),
419 'user_data' => $stockpack->admin->get_license_state(),
420 ]
421 );
422
423 $response = $this->client()->request( $method, $path,
424 [
425 'query' => $query
426 ]
427 );
428
429 return json_decode( $response->getBody() );
430 } catch ( GuzzleException $exception ) {
431 switch ( $exception->getCode() ) {
432 case 429: // too many requests
433 return $this->limit_exceeded( $exception );
434
435 default:
436 return new WP_Error( 1, __( 'Can\'t connect to StockPack server.', 'stockpack' ) );
437 }
438 }
439 }
440
441 private function limit_exceeded( $exception ) {
442 /** @var StockPack $stockpack */
443 global $stockpack;
444
445 $response = $exception->getResponse();
446 $limit = $response->getHeaderLine( 'x-ratelimit-limit' );
447 $retry_after = $response->getHeaderLine( 'retry-after' );
448 $retry_after = $this->human_seconds( $retry_after );
449 $retry_after = '<span class ="stockpack-timer">' . $retry_after . '</span>';
450 if ( $limit > 50 ) {
451 return new WP_Error( 'premium_limit_reached', __( 'Request limit reached, the reset will be in ', 'stockpack' ) . $retry_after );
452 }
453 $api_key = $stockpack->admin->get_api_key();
454 if ( $api_key ) {
455 return new WP_Error( 'free_limit_reached', __( 'Request limit reached, the reset will be in ', 'stockpack' ) . $retry_after );
456 }
457
458
459 return new WP_Error( 'anonymous_limit_reached', __( 'Request limit reached, the reset will be in ', 'stockpack' ) . $retry_after );
460 }
461
462 /**
463 * @return Client
464 */
465 private function client() {
466
467 if ( ! $this->client ) {
468 $this->client = new Client(
469 [
470 'base_uri' => $this->url . '/' . self::VERSION . '/',
471 ]
472 );
473 }
474
475 return $this->client;
476 }
477
478 private function support_caption_translation( $caption ) {
479 if ( ! $caption ) {
480 return '';
481 }
482
483 $caption = str_replace( 'Photo by', __( 'Photo by', 'stockpack' ), $caption );
484 $caption = str_replace( ' on ', _x( ' on ', 'Make sure to keep the space', 'stockpack' ), $caption );
485
486 return $caption;
487 }
488
489 /**
490 * @param $image_url
491 * @param $parent_id
492 *
493 * @param $description
494 *
495 * @param $name
496 * @param string $search
497 *
498 * @param string $caption
499 *
500 * @return bool|int|WP_Error
501 */
502 private function upload_remote_image_and_attach( $image_url, $parent_id, $description, $name, $search = '', $caption = '' ) {
503
504 $image = $image_url;
505 $get = wp_remote_get( $image, array( 'timeout' => 30 ) );
506 if ( is_wp_error( $get ) ) {
507 return new WP_Error( 100, __( 'Image download failed, please try again. Errors:', 'stockpack' ) . PHP_EOL . $get->get_error_message() );
508 }
509 $type = wp_remote_retrieve_header( $get, 'content-type' );
510 if ( ! $type ) {
511 return new WP_Error( 100, __( 'Image type couldn\'t be determined', 'stockpack' ) );
512 }
513 $name = $this->update_extension( $name, $type );
514
515 $mirror = wp_upload_bits( $name, '', wp_remote_retrieve_body( $get ) );
516 $attachment = array(
517 'post_title' => $name,
518 'post_content' => $description,
519 'post_excerpt' => $this->support_caption_translation( $caption ),
520 'post_mime_type' => $type
521 );
522 $attach_id = wp_insert_attachment( $attachment, $mirror['file'], $parent_id );
523 require_once( ABSPATH . 'wp-admin/includes/image.php' );
524 $attach_data = wp_generate_attachment_metadata( $attach_id, $mirror['file'] );
525 wp_update_attachment_metadata( $attach_id, $attach_data );
526 update_post_meta( $attach_id, '_wp_attachment_image_alt', $description );
527
528 return $attach_id;
529
530 }
531
532 /**
533 * @return mixed
534 */
535 private function get_domain() {
536 $url = get_bloginfo( 'url' );
537 $parse = wp_parse_url( $url );
538
539 return strtok( $parse['host'], '.' );
540 }
541
542
543 private function human_seconds( $seconds, $separator = ":" ) {
544 return sprintf( "%02d%s%02d%s%02d", floor( $seconds / 3600 ), $separator, ( $seconds / 60 ) % 60, $separator, $seconds % 60 );
545 }
546
547 private function update_extension( $name, $mime ) {
548 $name = explode( '.', $name );
549 $extension = $this->mime2ext( $mime );
550 if ( $extension ) {
551 return $name[0] . '.' . $extension;
552 }
553
554 return $name[0] . '.' . $name[1];
555
556 }
557
558 private function mime2ext( $mime ) {
559 $mime = str_replace( ';charset=UTF-8', '', $mime );
560 $mime_map = [
561 'video/3gpp2' => '3g2',
562 'video/3gp' => '3gp',
563 'video/3gpp' => '3gp',
564 'application/x-compressed' => '7zip',
565 'audio/x-acc' => 'aac',
566 'audio/ac3' => 'ac3',
567 'application/postscript' => 'ai',
568 'audio/x-aiff' => 'aif',
569 'audio/aiff' => 'aif',
570 'audio/x-au' => 'au',
571 'video/x-msvideo' => 'avi',
572 'video/msvideo' => 'avi',
573 'video/avi' => 'avi',
574 'application/x-troff-msvideo' => 'avi',
575 'application/macbinary' => 'bin',
576 'application/mac-binary' => 'bin',
577 'application/x-binary' => 'bin',
578 'application/x-macbinary' => 'bin',
579 'image/bmp' => 'bmp',
580 'image/x-bmp' => 'bmp',
581 'image/x-bitmap' => 'bmp',
582 'image/x-xbitmap' => 'bmp',
583 'image/x-win-bitmap' => 'bmp',
584 'image/x-windows-bmp' => 'bmp',
585 'image/ms-bmp' => 'bmp',
586 'image/x-ms-bmp' => 'bmp',
587 'application/bmp' => 'bmp',
588 'application/x-bmp' => 'bmp',
589 'application/x-win-bitmap' => 'bmp',
590 'application/cdr' => 'cdr',
591 'application/coreldraw' => 'cdr',
592 'application/x-cdr' => 'cdr',
593 'application/x-coreldraw' => 'cdr',
594 'image/cdr' => 'cdr',
595 'image/x-cdr' => 'cdr',
596 'zz-application/zz-winassoc-cdr' => 'cdr',
597 'application/mac-compactpro' => 'cpt',
598 'application/pkix-crl' => 'crl',
599 'application/pkcs-crl' => 'crl',
600 'application/x-x509-ca-cert' => 'crt',
601 'application/pkix-cert' => 'crt',
602 'text/css' => 'css',
603 'text/x-comma-separated-values' => 'csv',
604 'text/comma-separated-values' => 'csv',
605 'application/vnd.msexcel' => 'csv',
606 'application/x-director' => 'dcr',
607 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
608 'application/x-dvi' => 'dvi',
609 'message/rfc822' => 'eml',
610 'application/x-msdownload' => 'exe',
611 'video/x-f4v' => 'f4v',
612 'audio/x-flac' => 'flac',
613 'video/x-flv' => 'flv',
614 'image/gif' => 'gif',
615 'application/gpg-keys' => 'gpg',
616 'application/x-gtar' => 'gtar',
617 'application/x-gzip' => 'gzip',
618 'application/mac-binhex40' => 'hqx',
619 'application/mac-binhex' => 'hqx',
620 'application/x-binhex40' => 'hqx',
621 'application/x-mac-binhex40' => 'hqx',
622 'text/html' => 'html',
623 'image/x-icon' => 'ico',
624 'image/x-ico' => 'ico',
625 'image/vnd.microsoft.icon' => 'ico',
626 'text/calendar' => 'ics',
627 'application/java-archive' => 'jar',
628 'application/x-java-application' => 'jar',
629 'application/x-jar' => 'jar',
630 'image/jp2' => 'jp2',
631 'video/mj2' => 'jp2',
632 'image/jpx' => 'jp2',
633 'image/jpm' => 'jp2',
634 'image/jpeg' => 'jpeg',
635 'image/pjpeg' => 'jpeg',
636 'application/x-javascript' => 'js',
637 'application/json' => 'json',
638 'text/json' => 'json',
639 'application/vnd.google-earth.kml+xml' => 'kml',
640 'application/vnd.google-earth.kmz' => 'kmz',
641 'text/x-log' => 'log',
642 'audio/x-m4a' => 'm4a',
643 'application/vnd.mpegurl' => 'm4u',
644 'audio/midi' => 'mid',
645 'application/vnd.mif' => 'mif',
646 'video/quicktime' => 'mov',
647 'video/x-sgi-movie' => 'movie',
648 'audio/mpeg' => 'mp3',
649 'audio/mpg' => 'mp3',
650 'audio/mpeg3' => 'mp3',
651 'audio/mp3' => 'mp3',
652 'video/mp4' => 'mp4',
653 'video/mpeg' => 'mpeg',
654 'application/oda' => 'oda',
655 'audio/ogg' => 'ogg',
656 'video/ogg' => 'ogg',
657 'application/ogg' => 'ogg',
658 'application/x-pkcs10' => 'p10',
659 'application/pkcs10' => 'p10',
660 'application/x-pkcs12' => 'p12',
661 'application/x-pkcs7-signature' => 'p7a',
662 'application/pkcs7-mime' => 'p7c',
663 'application/x-pkcs7-mime' => 'p7c',
664 'application/x-pkcs7-certreqresp' => 'p7r',
665 'application/pkcs7-signature' => 'p7s',
666 'application/pdf' => 'pdf',
667 'application/octet-stream' => 'pdf',
668 'application/x-x509-user-cert' => 'pem',
669 'application/x-pem-file' => 'pem',
670 'application/pgp' => 'pgp',
671 'application/x-httpd-php' => 'php',
672 'application/php' => 'php',
673 'application/x-php' => 'php',
674 'text/php' => 'php',
675 'text/x-php' => 'php',
676 'application/x-httpd-php-source' => 'php',
677 'image/png' => 'png',
678 'image/x-png' => 'png',
679 'application/powerpoint' => 'ppt',
680 'application/vnd.ms-powerpoint' => 'ppt',
681 'application/vnd.ms-office' => 'ppt',
682 'application/msword' => 'doc',
683 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
684 'application/x-photoshop' => 'psd',
685 'image/vnd.adobe.photoshop' => 'psd',
686 'audio/x-realaudio' => 'ra',
687 'audio/x-pn-realaudio' => 'ram',
688 'application/x-rar' => 'rar',
689 'application/rar' => 'rar',
690 'application/x-rar-compressed' => 'rar',
691 'audio/x-pn-realaudio-plugin' => 'rpm',
692 'application/x-pkcs7' => 'rsa',
693 'text/rtf' => 'rtf',
694 'text/richtext' => 'rtx',
695 'video/vnd.rn-realvideo' => 'rv',
696 'application/x-stuffit' => 'sit',
697 'application/smil' => 'smil',
698 'text/srt' => 'srt',
699 'image/svg+xml' => 'svg',
700 'application/x-shockwave-flash' => 'swf',
701 'application/x-tar' => 'tar',
702 'application/x-gzip-compressed' => 'tgz',
703 'image/tiff' => 'tiff',
704 'text/plain' => 'txt',
705 'text/x-vcard' => 'vcf',
706 'application/videolan' => 'vlc',
707 'text/vtt' => 'vtt',
708 'audio/x-wav' => 'wav',
709 'audio/wave' => 'wav',
710 'audio/wav' => 'wav',
711 'application/wbxml' => 'wbxml',
712 'video/webm' => 'webm',
713 'audio/x-ms-wma' => 'wma',
714 'application/wmlc' => 'wmlc',
715 'video/x-ms-wmv' => 'wmv',
716 'video/x-ms-asf' => 'wmv',
717 'application/xhtml+xml' => 'xhtml',
718 'application/excel' => 'xl',
719 'application/msexcel' => 'xls',
720 'application/x-msexcel' => 'xls',
721 'application/x-ms-excel' => 'xls',
722 'application/x-excel' => 'xls',
723 'application/x-dos_ms_excel' => 'xls',
724 'application/xls' => 'xls',
725 'application/x-xls' => 'xls',
726 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
727 'application/vnd.ms-excel' => 'xlsx',
728 'application/xml' => 'xml',
729 'text/xml' => 'xml',
730 'text/xsl' => 'xsl',
731 'application/xspf+xml' => 'xspf',
732 'application/x-compress' => 'z',
733 'application/x-zip' => 'zip',
734 'application/zip' => 'zip',
735 'application/x-zip-compressed' => 'zip',
736 'application/s-compressed' => 'zip',
737 'multipart/x-zip' => 'zip',
738 'text/x-scriptzsh' => 'zsh',
739 'application/illustrator' => 'ai',
740 'application/eps' => 'eps',
741 'application/x-eps' => 'eps',
742 'image/eps' => 'eps',
743 'image/x-eps' => 'eps'
744 ];
745
746 return isset( $mime_map[ $mime ] ) === true ? $mime_map[ $mime ] : false;
747 }
748
749 }
750
751 $GLOBALS['stockpack_query'] = StockpackQuery::get_instance();
752 }
753