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