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

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