PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.5.0
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.5.0
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.0, at src/class-stockpackquery.php

744 lines 37.8 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 $search = isset( $_REQUEST['search'] ) ? sanitize_title( $_REQUEST['search'] ) : $this->get_domain();
244 $description = isset( $_REQUEST['description'] ) ? sanitize_textarea_field( $_REQUEST['description'] ) : '';
245 $image = $this->image( $id, $post_id, $description, $search, $must_license, $provider );
246
247 if ( is_wp_error( $image ) ) {
248 if ( strpos( $image->get_error_code(), 'limit_reached' ) !== false ) {
249 wp_send_json_error( $image );
250 die();
251 }
252 wp_send_json_error( array( 'message' => $image->get_error_message() ) );
253 }
254
255 wp_send_json_success( wp_prepare_attachment_for_js( $image ) );
256
257 }
258
259
260 /**
261 * @param $data
262 *
263 * @return array
264 */
265 private function format( $data ) {
266 return $data;
267 }
268
269 /**
270 * @param $image
271 *
272 * @return array
273 */
274 private function individual( $image ) {
275 return [
276 'id' => $image->id,
277 'description' => $image->description,
278 'caption' => $image->caption ? $image->caption : '',
279 'url' => $image->assets->huge_thumb->url,
280 'sizes' => [
281 'full' => $this->size( $image, 'huge_thumb' ),
282 'medium' => $this->size( $image, 'preview' ),
283 'thumbnail' => $this->size( $image, 'large_thumb' )
284 ]
285 ];
286 }
287
288 private function size( $image, $format ) {
289 return [
290 'height' => $image->assets->$format->height,
291 'width' => $image->assets->$format->width,
292 'orientation' => ( $image->aspect > 1 ? 'landscape' : 'portrait' ),
293 'url' => $image->assets->$format->url
294 ];
295 }
296
297 private function get_license_cost( $media_id, $provider ) {
298
299 $response = $this->call( 'GET', 'images/license-cost', array(
300 'id' => $media_id,
301 'locale' => get_locale(),
302 'provider' => $provider
303 ) );
304
305 return $response;
306
307
308 }
309
310 private function image( $media_id, $post_id, $description = '', $search = '', $must_license = 0, $provider = 0 ) {
311
312 $image = $this->call( 'GET', 'images/download',
313 array(
314 'id' => $media_id,
315 'must_license' => $must_license,
316 'provider' => $provider
317 )
318 );
319
320 if ( ! isset( $image->data->download ) ) {
321 if ( is_wp_error( $image ) ) {
322 return $image;
323 }
324
325 return $this->handle_download_errors( $image->data );
326 }
327
328 $caption = $image->data->caption ?: '';
329 $attachment_id = $this->upload_remote_image_and_attach( $image->data->download, $post_id, $description, $image->data->name, $search, $caption );
330 if ( is_wp_error( $attachment_id ) ) {
331 return $attachment_id;
332 }
333 if ( ! $attachment_id ) {
334 return new WP_Error( __( 'upload_failure', 'There has been a problem with the upload. Please try again', 'stockpack' ) );
335 }
336
337 update_post_meta( $attachment_id, 'stockpack_id', $media_id );
338
339 return $attachment_id;
340 }
341
342 private function handle_license_errors( $response ) {
343 if ( isset( $response->code ) ) {
344 switch ( $response->code ) {
345 case 'token_expired':
346 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' ) );
347 }
348 }
349
350 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' ) );
351 }
352
353 private function handle_download_errors( $response ) {
354 if ( isset( $response->code ) ) {
355 switch ( $response->code ) {
356 case 'token_expired':
357 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' ) );
358 }
359 }
360
361 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' ) );
362 }
363
364 private function handle_search_errors( $response ) {
365 if ( isset( $response->code ) ) {
366 switch ( $response->code ) {
367 case 'token_expired':
368 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' ) );
369 }
370 }
371
372 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' ) );
373
374 }
375
376 private function images( $query = [] ) {
377
378 return $this->call( 'GET', 'images/search', $query );
379 }
380
381 /**
382 * @param $method
383 * @param $path
384 * @param array $query
385 *
386 * @return mixed|null
387 */
388 private function call( $method, $path, $query = [] ) {
389 /** @var StockPack $stockpack */
390 global $stockpack;
391
392 try {
393 if ( ! isset( $query['key'] ) ) {
394 $api_key = $stockpack->admin->get_api_key();
395 if ( $api_key ) {
396 $query = array_merge( $query,
397 [
398 'api_token' => $api_key
399 ]
400 );
401 } else {
402 $path .= '-trial';
403 }
404 }
405
406 $query = array_merge( $query,
407 [
408 'referral' => get_bloginfo( 'url' ),
409 'safe_search' => $stockpack->admin->get_safe_search(),
410 'user_data' => $stockpack->admin->get_license_state(),
411 ]
412 );
413
414 $response = $this->client()->request( $method, $path,
415 [
416 'query' => $query
417 ]
418 );
419
420 return json_decode( $response->getBody() );
421 } catch ( GuzzleException $exception ) {
422 switch ( $exception->getCode() ) {
423 case 429: // too many requests
424 return $this->limit_exceeded( $exception );
425
426 default:
427 return new WP_Error( 1, __( 'Can\'t connect to StockPack server.', 'stockpack' ) );
428 }
429 }
430 }
431
432 private function limit_exceeded( $exception ) {
433 /** @var StockPack $stockpack */
434 global $stockpack;
435
436 $response = $exception->getResponse();
437 $limit = $response->getHeaderLine( 'x-ratelimit-limit' );
438 $retry_after = $response->getHeaderLine( 'retry-after' );
439 $retry_after = $this->human_seconds( $retry_after );
440 $retry_after = '<span class ="stockpack-timer">' . $retry_after . '</span>';
441 if ( $limit > 50 ) {
442 return new WP_Error( 'premium_limit_reached', __( 'Request limit reached, the reset will be in ', 'stockpack' ) . $retry_after );
443 }
444 $api_key = $stockpack->admin->get_api_key();
445 if ( $api_key ) {
446 return new WP_Error( 'free_limit_reached', __( 'Request limit reached, the reset will be in ', 'stockpack' ) . $retry_after );
447 }
448
449
450 return new WP_Error( 'anonymous_limit_reached', __( 'Request limit reached, the reset will be in ', 'stockpack' ) . $retry_after );
451 }
452
453 /**
454 * @return Client
455 */
456 private function client() {
457
458 if ( ! $this->client ) {
459 $this->client = new Client(
460 [
461 'base_uri' => $this->url . '/' . self::VERSION . '/',
462 ]
463 );
464 }
465
466 return $this->client;
467 }
468
469 private function support_caption_translation( $caption ) {
470 if ( ! $caption ) {
471 return '';
472 }
473
474 $caption = str_replace( 'Photo by', __( 'Photo by', 'stockpack' ), $caption );
475 $caption = str_replace( ' on ', _x( ' on ', 'Make sure to keep the space', 'stockpack' ), $caption );
476
477 return $caption;
478 }
479
480 /**
481 * @param $image_url
482 * @param $parent_id
483 *
484 * @param $description
485 *
486 * @param $name
487 * @param string $search
488 *
489 * @param string $caption
490 *
491 * @return bool|int|WP_Error
492 */
493 private function upload_remote_image_and_attach( $image_url, $parent_id, $description, $name, $search = '', $caption = '' ) {
494
495 $image = $image_url;
496 $get = wp_remote_get( $image, array( 'timeout' => 30 ) );
497 if ( is_wp_error( $get ) ) {
498 return new WP_Error( 100, __( 'Image download failed, please try again. Errors:', 'stockpack' ) . PHP_EOL . $get->get_error_message() );
499 }
500 $type = wp_remote_retrieve_header( $get, 'content-type' );
501 if ( ! $type ) {
502 return new WP_Error( 100, __( 'Image type couldn\'t be determined', 'stockpack' ) );
503 }
504 $name = $this->update_extension( $name, $type );
505
506 $mirror = wp_upload_bits( $name, '', wp_remote_retrieve_body( $get ) );
507 $attachment = array(
508 'post_title' => $name,
509 'post_content' => $description,
510 'post_excerpt' => $this->support_caption_translation( $caption ),
511 'post_mime_type' => $type
512 );
513 $attach_id = wp_insert_attachment( $attachment, $mirror['file'], $parent_id );
514 require_once( ABSPATH . 'wp-admin/includes/image.php' );
515 $attach_data = wp_generate_attachment_metadata( $attach_id, $mirror['file'] );
516 wp_update_attachment_metadata( $attach_id, $attach_data );
517 update_post_meta( $attach_id, '_wp_attachment_image_alt', $description );
518
519 return $attach_id;
520
521 }
522
523 /**
524 * @return mixed
525 */
526 private function get_domain() {
527 $url = get_bloginfo( 'url' );
528 $parse = wp_parse_url( $url );
529
530 return strtok( $parse['host'], '.' );
531 }
532
533
534 private function human_seconds( $seconds, $separator = ":" ) {
535 return sprintf( "%02d%s%02d%s%02d", floor( $seconds / 3600 ), $separator, ( $seconds / 60 ) % 60, $separator, $seconds % 60 );
536 }
537
538 private function update_extension( $name, $mime ) {
539 $name = explode( '.', $name );
540 $extension = $this->mime2ext( $mime );
541 if ( $extension ) {
542 return $name[0] . '.' . $extension;
543 }
544
545 return $name[0] . '.' . $name[1];
546
547 }
548
549 private function mime2ext( $mime ) {
550 $mime = str_replace( ';charset=UTF-8', '', $mime );
551 $mime_map = [
552 'video/3gpp2' => '3g2',
553 'video/3gp' => '3gp',
554 'video/3gpp' => '3gp',
555 'application/x-compressed' => '7zip',
556 'audio/x-acc' => 'aac',
557 'audio/ac3' => 'ac3',
558 'application/postscript' => 'ai',
559 'audio/x-aiff' => 'aif',
560 'audio/aiff' => 'aif',
561 'audio/x-au' => 'au',
562 'video/x-msvideo' => 'avi',
563 'video/msvideo' => 'avi',
564 'video/avi' => 'avi',
565 'application/x-troff-msvideo' => 'avi',
566 'application/macbinary' => 'bin',
567 'application/mac-binary' => 'bin',
568 'application/x-binary' => 'bin',
569 'application/x-macbinary' => 'bin',
570 'image/bmp' => 'bmp',
571 'image/x-bmp' => 'bmp',
572 'image/x-bitmap' => 'bmp',
573 'image/x-xbitmap' => 'bmp',
574 'image/x-win-bitmap' => 'bmp',
575 'image/x-windows-bmp' => 'bmp',
576 'image/ms-bmp' => 'bmp',
577 'image/x-ms-bmp' => 'bmp',
578 'application/bmp' => 'bmp',
579 'application/x-bmp' => 'bmp',
580 'application/x-win-bitmap' => 'bmp',
581 'application/cdr' => 'cdr',
582 'application/coreldraw' => 'cdr',
583 'application/x-cdr' => 'cdr',
584 'application/x-coreldraw' => 'cdr',
585 'image/cdr' => 'cdr',
586 'image/x-cdr' => 'cdr',
587 'zz-application/zz-winassoc-cdr' => 'cdr',
588 'application/mac-compactpro' => 'cpt',
589 'application/pkix-crl' => 'crl',
590 'application/pkcs-crl' => 'crl',
591 'application/x-x509-ca-cert' => 'crt',
592 'application/pkix-cert' => 'crt',
593 'text/css' => 'css',
594 'text/x-comma-separated-values' => 'csv',
595 'text/comma-separated-values' => 'csv',
596 'application/vnd.msexcel' => 'csv',
597 'application/x-director' => 'dcr',
598 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
599 'application/x-dvi' => 'dvi',
600 'message/rfc822' => 'eml',
601 'application/x-msdownload' => 'exe',
602 'video/x-f4v' => 'f4v',
603 'audio/x-flac' => 'flac',
604 'video/x-flv' => 'flv',
605 'image/gif' => 'gif',
606 'application/gpg-keys' => 'gpg',
607 'application/x-gtar' => 'gtar',
608 'application/x-gzip' => 'gzip',
609 'application/mac-binhex40' => 'hqx',
610 'application/mac-binhex' => 'hqx',
611 'application/x-binhex40' => 'hqx',
612 'application/x-mac-binhex40' => 'hqx',
613 'text/html' => 'html',
614 'image/x-icon' => 'ico',
615 'image/x-ico' => 'ico',
616 'image/vnd.microsoft.icon' => 'ico',
617 'text/calendar' => 'ics',
618 'application/java-archive' => 'jar',
619 'application/x-java-application' => 'jar',
620 'application/x-jar' => 'jar',
621 'image/jp2' => 'jp2',
622 'video/mj2' => 'jp2',
623 'image/jpx' => 'jp2',
624 'image/jpm' => 'jp2',
625 'image/jpeg' => 'jpeg',
626 'image/pjpeg' => 'jpeg',
627 'application/x-javascript' => 'js',
628 'application/json' => 'json',
629 'text/json' => 'json',
630 'application/vnd.google-earth.kml+xml' => 'kml',
631 'application/vnd.google-earth.kmz' => 'kmz',
632 'text/x-log' => 'log',
633 'audio/x-m4a' => 'm4a',
634 'application/vnd.mpegurl' => 'm4u',
635 'audio/midi' => 'mid',
636 'application/vnd.mif' => 'mif',
637 'video/quicktime' => 'mov',
638 'video/x-sgi-movie' => 'movie',
639 'audio/mpeg' => 'mp3',
640 'audio/mpg' => 'mp3',
641 'audio/mpeg3' => 'mp3',
642 'audio/mp3' => 'mp3',
643 'video/mp4' => 'mp4',
644 'video/mpeg' => 'mpeg',
645 'application/oda' => 'oda',
646 'audio/ogg' => 'ogg',
647 'video/ogg' => 'ogg',
648 'application/ogg' => 'ogg',
649 'application/x-pkcs10' => 'p10',
650 'application/pkcs10' => 'p10',
651 'application/x-pkcs12' => 'p12',
652 'application/x-pkcs7-signature' => 'p7a',
653 'application/pkcs7-mime' => 'p7c',
654 'application/x-pkcs7-mime' => 'p7c',
655 'application/x-pkcs7-certreqresp' => 'p7r',
656 'application/pkcs7-signature' => 'p7s',
657 'application/pdf' => 'pdf',
658 'application/octet-stream' => 'pdf',
659 'application/x-x509-user-cert' => 'pem',
660 'application/x-pem-file' => 'pem',
661 'application/pgp' => 'pgp',
662 'application/x-httpd-php' => 'php',
663 'application/php' => 'php',
664 'application/x-php' => 'php',
665 'text/php' => 'php',
666 'text/x-php' => 'php',
667 'application/x-httpd-php-source' => 'php',
668 'image/png' => 'png',
669 'image/x-png' => 'png',
670 'application/powerpoint' => 'ppt',
671 'application/vnd.ms-powerpoint' => 'ppt',
672 'application/vnd.ms-office' => 'ppt',
673 'application/msword' => 'doc',
674 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
675 'application/x-photoshop' => 'psd',
676 'image/vnd.adobe.photoshop' => 'psd',
677 'audio/x-realaudio' => 'ra',
678 'audio/x-pn-realaudio' => 'ram',
679 'application/x-rar' => 'rar',
680 'application/rar' => 'rar',
681 'application/x-rar-compressed' => 'rar',
682 'audio/x-pn-realaudio-plugin' => 'rpm',
683 'application/x-pkcs7' => 'rsa',
684 'text/rtf' => 'rtf',
685 'text/richtext' => 'rtx',
686 'video/vnd.rn-realvideo' => 'rv',
687 'application/x-stuffit' => 'sit',
688 'application/smil' => 'smil',
689 'text/srt' => 'srt',
690 'image/svg+xml' => 'svg',
691 'application/x-shockwave-flash' => 'swf',
692 'application/x-tar' => 'tar',
693 'application/x-gzip-compressed' => 'tgz',
694 'image/tiff' => 'tiff',
695 'text/plain' => 'txt',
696 'text/x-vcard' => 'vcf',
697 'application/videolan' => 'vlc',
698 'text/vtt' => 'vtt',
699 'audio/x-wav' => 'wav',
700 'audio/wave' => 'wav',
701 'audio/wav' => 'wav',
702 'application/wbxml' => 'wbxml',
703 'video/webm' => 'webm',
704 'audio/x-ms-wma' => 'wma',
705 'application/wmlc' => 'wmlc',
706 'video/x-ms-wmv' => 'wmv',
707 'video/x-ms-asf' => 'wmv',
708 'application/xhtml+xml' => 'xhtml',
709 'application/excel' => 'xl',
710 'application/msexcel' => 'xls',
711 'application/x-msexcel' => 'xls',
712 'application/x-ms-excel' => 'xls',
713 'application/x-excel' => 'xls',
714 'application/x-dos_ms_excel' => 'xls',
715 'application/xls' => 'xls',
716 'application/x-xls' => 'xls',
717 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
718 'application/vnd.ms-excel' => 'xlsx',
719 'application/xml' => 'xml',
720 'text/xml' => 'xml',
721 'text/xsl' => 'xsl',
722 'application/xspf+xml' => 'xspf',
723 'application/x-compress' => 'z',
724 'application/x-zip' => 'zip',
725 'application/zip' => 'zip',
726 'application/x-zip-compressed' => 'zip',
727 'application/s-compressed' => 'zip',
728 'multipart/x-zip' => 'zip',
729 'text/x-scriptzsh' => 'zsh',
730 'application/illustrator' => 'ai',
731 'application/eps' => 'eps',
732 'application/x-eps' => 'eps',
733 'image/eps' => 'eps',
734 'image/x-eps' => 'eps'
735 ];
736
737 return isset( $mime_map[ $mime ] ) === true ? $mime_map[ $mime ] : false;
738 }
739
740 }
741
742 $GLOBALS['stockpack_query'] = StockpackQuery::get_instance();
743 }
744