Skip to content

Commit

Permalink
Merge pull request #7 from shutterstock/version-1.2
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
msmol committed Dec 2, 2020
2 parents d8c00f7 + a7d58f6 commit c3abdd1
Show file tree
Hide file tree
Showing 80 changed files with 1,111 additions and 181 deletions.
11 changes: 9 additions & 2 deletions shutterstock/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: shutterstockplugins
Tags: shutterstock, stock photography, images, editorial images, licensing, media library, stock
Requires at least: 5.5
Tested up to: 5.5
Stable tag: 1.1.1
Tested up to: 5.6
Stable tag: 1.2.0
Requires PHP: 7.1
License: MIT
License URI: http://opensource.org/licenses/mit-license.html
Expand All @@ -25,6 +25,8 @@ Take your ideas for a test run and use our watermarked content on draft posts an
**License**
Love how it looks? License the content and use it directly within your posts and pages.

By default, WordPress sites have access to a limited library of Shutterstock media. **To connect the WordPress plugin to your existing subscription or access our full collection, fill out the form at [https://www.shutterstock.com/design/plugins-wordpress](https://www.shutterstock.com/design/plugins-wordpress).**

This plugin uses the Shutterstock API. For more information, see [https://developers.shutterstock.com](https://developers.shutterstock.com).

== Screenshots ==
Expand All @@ -35,6 +37,8 @@ This plugin uses the Shutterstock API. For more information, see [https://develo

**Prerequisites**

By default, WordPress sites have access to a limited library of Shutterstock media. **To connect the WordPress plugin to your existing subscription or access our full collection, fill out the form at https://www.shutterstock.com/design/plugins-wordpress.**

To install the Shutterstock plugin for WordPress, you need an API application for the Shutterstock API. You can create an application at [https://www.shutterstock.com/account/developers/apps](https://www.shutterstock.com/account/developers/apps).

The plugin works only with API applications that have referrer authentication enabled. In your application, you must specify the host names on which your WordPress site runs.
Expand Down Expand Up @@ -97,6 +101,9 @@ Now that you have the Shutterstock plugin installed and configured, you can use
1. Publish the page as usual. The image appears on the page just like any other image that you add to a page.

== Changelog ==
= 1.2.0 =
Introduced smart image recommendations and license history with re-download functionality

= 1.1.1 =
Add translations

Expand Down
120 changes: 106 additions & 14 deletions shutterstock/includes/class-shutterstock-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Shutterstock_API {

private $api_url = 'https://api.shutterstock.com/v2';

public function __construct($shutterstock, $version) {
public function __construct($shutterstock, $version) {
$this->shutterstock = $shutterstock;
$this->version = $version;
}
Expand All @@ -17,7 +17,7 @@ public function register_routes() {
'permission_callback' => array($this, 'get_permissions_check'),
));

register_rest_route($this->shutterstock, '/images/(?P<id>\w+)', array(
register_rest_route($this->shutterstock, '/images/(?P<id>\d+[a-zA-z]*)', array(
'methods' => 'GET',
'callback' => array($this, 'get_image_details'),
'permission_callback' => array($this, 'get_permissions_check'),
Expand All @@ -35,10 +35,22 @@ public function register_routes() {
'permission_callback' => array($this, 'get_permissions_check'),
));

register_rest_route($this->shutterstock, '/images/licenses', array(
'methods' => 'GET',
'callback' => array($this, 'get_list_image_licenses'),
'permission_callback' => array($this, 'get_permissions_check'),
));

register_rest_route($this->shutterstock, '/images/licenses/(?P<id>\w+)/downloads', array(
'methods' => 'POST',
'callback' => array($this, 'redownload_image'),
'permission_callback' => array($this, 'get_permissions_check'),
));

}
}

public function get_subscriptions($request) {
public function get_subscriptions($request) {
$parameters = $request->get_params();
$media_type = sanitize_text_field($parameters['mediaType']);
$is_editorial = $media_type === 'editorial';
Expand Down Expand Up @@ -83,25 +95,22 @@ public function get_subscriptions($request) {
)
);

return wp_send_json($filtered_subscriptions, $response['response_code']);
return new WP_REST_Response($filtered_subscriptions, $response['response_code']);
}

public function get_image_details($request) {
$image_id = sanitize_text_field($request['id']);
$parameters = $request->get_params();
public function get_image_details($request) {
$image_id = sanitize_text_field($request['id']);
$parameters = $request->get_params();
$media_type = sanitize_text_field($parameters['mediaType']);
$is_editorial = $media_type === 'editorial';
$country = $this->get_editorial_country();

$image_details_route = $is_editorial
? $this->api_url. '/editorial/'. $image_id . '?view=full&country=' . $country
: $this->api_url. '/images/'. $image_id . '?view=full';

$response = $this->do_api_get_request($image_details_route);

$decoded_response_body = json_decode($response['response_body'], true);

return wp_send_json($decoded_response_body, $response['response_code']);
return new WP_REST_Response($decoded_response_body, $response['response_code']);
}

public function get_contributor_details($request) {
Expand All @@ -113,7 +122,20 @@ public function get_contributor_details($request) {

$decoded_response_body = json_decode($response['response_body'], true);

return wp_send_json($decoded_response_body, $response['response_code']);
return new WP_REST_Response($decoded_response_body, $response['response_code']);
}

public function get_list_image_licenses($request) {
$parameters = $request->get_params();
$page = isset($parameters['page']) ? sanitize_text_field($parameters['page']) : 1;
$per_page = isset($parameters['per_page']) ? sanitize_text_field($parameters['per_page']) : 20;
$list_image_licenses_route = $this->api_url. '/images/licenses?per_page='. $per_page .'&page=' . $page;

$response = $this->do_api_get_request($list_image_licenses_route);

$decoded_response_body = json_decode($response['response_body'], true);

return new WP_REST_Response($decoded_response_body, $response['response_code']);
}

public function license_image($request) {
Expand Down Expand Up @@ -230,6 +252,76 @@ public function license_image($request) {
return wp_send_json_success($uploaded_image_url, $response_code);
}

public function redownload_image($request) {
$license_id = sanitize_text_field($request['id']);
$req_body = json_decode($request->get_body(), true);
$size = sanitize_text_field($req_body['size']);

$image_id = sanitize_text_field($req_body['imageId']);
$image_description = sanitize_text_field($req_body['description']);
$contributor_name = sanitize_text_field($req_body['contributorName']);
$media_type = sanitize_text_field($req_body['mediaType']);

$width = sanitize_text_field($req_body['width']);
$height = sanitize_text_field($req_body['height']);

$redownload_url = $this->api_url. '/images/licenses/'. $license_id . '/downloads';
$token = $this->get_api_token();

$body = [
"size" => $size,
];

$args = [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json; charset=utf-8',
'x-shutterstock-application' => 'Wordpress/'. $this->version,
],
'body' => wp_json_encode($body),
'data_format' => 'body',
];

$response = wp_remote_post($redownload_url, $args);
$response_code = wp_remote_retrieve_response_code($response);
$response_body = wp_remote_retrieve_body($response);
$decoded_body = json_decode($response_body, true);

$success_error = isset($decoded_body['data'][0]['error']);

if ($response_code !== 200 || $success_error || isset($decoded_body['errors'])) {
$error = $decoded_body;

// return 200 even if some error occurs. This type of error response returned by editorial.
if ($success_error) {
$error = $decoded_body['data'][0];
$error['message'] = $decoded_body['data'][0]['error'];
}

return wp_send_json_error($error, $response_code);
}

$download_url = $decoded_body['url'];

$filename = 'shutterstock-'. $image_id. '-' .$size. '-redownloaded.jpg';

$post_description = 'Shutterstock ID: '. $image_id . ', Photographer: '. $contributor_name;

$uploaded_image_url = $this->download_upload_image_to_media_library(
$download_url,
$filename,
$size,
$image_description,
$image_id,
$post_description,
$width,
$height
);

return wp_send_json_success($uploaded_image_url, $response_code);

}

private function download_upload_image_to_media_library($download_url, $filename, $size, $title, $image_id, $post_description, $width, $height) {
$response = '';

Expand Down Expand Up @@ -321,10 +413,10 @@ public function get_permissions_check($request) {

if ($request_type === 'GET') {
$parameters = $request->get_params();
$media_type = sanitize_text_field($parameters['mediaType']);
$media_type = isset($parameters['mediaType']) ? sanitize_text_field($parameters['mediaType']) : 'images';
} else if ($request_type === 'POST') {
$req_body = json_decode($request->get_body(), true);
$media_type = sanitize_text_field($req_body['mediaType']);
$media_type = isset($req_body['mediaType']) ? sanitize_text_field($req_body['mediaType']) : 'images';
}

$is_editorial = ($media_type === 'editorial');
Expand Down
2 changes: 1 addition & 1 deletion shutterstock/includes/class-shutterstock.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct() {
if ( defined( 'SHUTTERSTOCK_VERSION' ) ) {
$this->version = SHUTTERSTOCK_VERSION;
} else {
$this->version = '1.1.1';
$this->version = '1.2.0';
}
$this->shutterstock = 'shutterstock';

Expand Down
24 changes: 21 additions & 3 deletions shutterstock/languages/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# This file is distributed under the same license as the Shutterstock plugin.
msgid ""
msgstr ""
"Project-Id-Version: Shutterstock 1.1.0\n"
"Project-Id-Version: Shutterstock 1.1.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/shutterstock\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2020-10-29T12:53:51+00:00\n"
"POT-Creation-Date: 2020-11-20T15:02:27+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.4.0\n"
"X-Domain: shutterstock\n"
Expand All @@ -19,7 +21,7 @@ msgstr "Shutterstock"

#. Description of the plugin
msgid "wordpress:plugin_description"
msgstr "The Shutterstock plugin takes the complexity out of creativity. Save time, whether you're creating a draft or publishing a full article."
msgstr "Access exceptional, royalty-free content straight from WordPress."

#: admin/class-shutterstock-admin.php:191
msgid "wordpress:text_api_key"
Expand Down Expand Up @@ -102,6 +104,10 @@ msgstr "User Type"
msgid "wordpress:text_insert_account_information"
msgstr "Please insert your Shutterstock account information to use this plugin. You can create an app and access token on your <a href=\"%s\" target=\"_blank\">developer apps page</a>."

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:downloading_image"
msgstr "Downloading image. Please wait."

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_something_went_wrong"
msgstr "Something went wrong. Please try again."
Expand All @@ -122,6 +128,10 @@ msgstr "Loading. Please wait."
msgid "wordpress:text_licensing_image_please_wait"
msgstr "Licensing Image. Please wait."

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_dowbload_and_insert"
msgstr "Download and Insert"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_add_shuttersock_content_to_post"
msgstr "Add Shutterstock content to your post"
Expand All @@ -138,6 +148,14 @@ msgstr "Editorial"
msgid "wordpress:text_add_shuttersock_content_to_post"
msgstr "Add Shutterstock content to your post"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_home"
msgstr "Home"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_downloads"
msgstr "Downloads"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_license_this_image"
msgstr "License this image"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"translation-revision-date": "2020-11-09T20:44:52.273Z",
"translation-revision-date": "2020-11-27T12:15:24.276Z",
"generator": "WP-CLI\/2.4.0",
"source": "public\/shutterstock-block\/build\/index.js",
"domain": "messages",
Expand All @@ -10,6 +10,9 @@
"lang": "cs_CZ",
"plural-forms": "nplurals=2; plural=(n != 1);"
},
"wordpress:downloading_image": [
"Prob\u00edh\u00e1 stahov\u00e1n\u00ed sn\u00edmku. \u010cekejte pros\u00edm."
],
"wordpress:text_add_shuttersock_content_to_post": [
"P\u0159idejte obsah slu\u017eby Shutterstock k va\u0161emu p\u0159\u00edsp\u011bvku"
],
Expand All @@ -22,9 +25,18 @@
"wordpress:text_browse": [
"Proch\u00e1zet"
],
"wordpress:text_dowbload_and_insert": [
"St\u00e1hnout a\u00a0vlo\u017eit"
],
"wordpress:text_downloads": [
"Sta\u017een\u00ed"
],
"wordpress:text_editorial": [
"Redak\u010dn\u00ed"
],
"wordpress:text_home": [
"Dom\u016f"
],
"wordpress:text_images": [
"Sn\u00edmky"
],
Expand Down
Binary file modified shutterstock/languages/shutterstock-cs_CZ.mo
Binary file not shown.
26 changes: 21 additions & 5 deletions shutterstock/languages/shutterstock-cs_CZ.po
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
msgid ""
msgstr ""
"Project-Id-Version: Shutterstock 1.1.0\n"
"Project-Id-Version: Shutterstock 1.2.0\n"
"mime-version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Domain: shutterstock\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2\n"
"POT-Creation-Date: 2020-11-09T20:44:52.273Z\n"
"PO-Revision-Date: 2020-11-09T20:44:52.273Z\n"
"POT-Creation-Date: 2020-11-27T12:15:24.276Z\n"
"PO-Revision-Date: 2020-11-27T12:15:24.276Z\n"
"Language: cs_CZ\n"

#: admin/partials/shutterstock-admin-field-shutterstock-login-button.php:29
msgid "wordpress:connected"
msgstr "Připojeno"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:downloading_image"
msgstr "Probíhá stahování snímku. Čekejte prosím."

#: admin/partials/shutterstock-admin-field-shutterstock-login-button.php:18
msgid "wordpress:logging_out"
msgstr "Odhlášení"

msgid "wordpress:plugin_description"
msgstr ""
"Plugin Shutterstock z tvůrčího procesu odstraňuje složitost. Ušetřete čas, "
"ať už tvoříte návrh, nebo publikujete celý článek."
"Získejte přístup k výjimečnému obsahu bez autorských poplatků přímo ze "
"služby WordPress."

msgid "wordpress:plugin_title"
msgstr "Shutterstock"
Expand Down Expand Up @@ -68,6 +72,14 @@ msgstr ""
msgid "wordpress:text_browse"
msgstr "Procházet"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_dowbload_and_insert"
msgstr "Stáhnout a vložit"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_downloads"
msgstr "Stažení"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_editorial"
msgstr "Redakční"
Expand All @@ -82,6 +94,10 @@ msgstr ""
"Zobrazit pouze redakční obsah, který je dostupný pro distribuci v určité "
"zemi (třímístný (ISO 3166 Alpha-3) kód země)."

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_home"
msgstr "Domů"

#: public/shutterstock-block/build/index.js:1
msgid "wordpress:text_images"
msgstr "Snímky"
Expand Down
Loading

0 comments on commit c3abdd1

Please sign in to comment.