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

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