diff --git a/credit-tracker.php b/credit-tracker.php index bc25aee..b253316 100755 --- a/credit-tracker.php +++ b/credit-tracker.php @@ -12,7 +12,7 @@ * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt * Requires at least: 3.5.1 - * Tested up to: 3.8.3 + * Tested up to: 3.9 * * @package Credit_Tracker * @author Labs64 <info@labs64.com> @@ -54,6 +54,7 @@ require_once(plugin_dir_path(__FILE__) . '/php/parser/fotolia.php'); require_once(plugin_dir_path(__FILE__) . '/php/parser/istockphoto.php'); require_once(plugin_dir_path(__FILE__) . '/php/parser/pixelio.php'); +require_once(plugin_dir_path(__FILE__) . '/php/parser/flickr.php'); // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively. register_activation_hook(__FILE__, array('Credit_Tracker', 'activate')); diff --git a/css/ct-admin.css b/css/ct-admin.css index 9ac01d8..5c8f337 100755 --- a/css/ct-admin.css +++ b/css/ct-admin.css @@ -37,3 +37,7 @@ p { padding: 5px 10px 5px 10px; margin-top: 40px; } + +.compat-attachment-fields .label { + vertical-align: top; +} diff --git a/options.php b/options.php index 075b8a6..48e67d5 100644 --- a/options.php +++ b/options.php @@ -158,11 +158,18 @@ function get_on_off($opt) } /** - * Print the Section info text + * Print the Common-Section info text */ function print_common_section_info() { - print __('Enter your settings below:', CT_SLUG); +} + +/** + * Print the Retriever-Section info text + */ +function print_retriever_section_info() +{ + print __('Some Image Data Retriever needs additional configuration', CT_SLUG); } /** @@ -296,6 +303,13 @@ function page_init() CT_SLUG // Page ); + add_settings_section( + 'CT_RETRIEVER_SETTINGS', // ID + __('Retriever Settings', CT_SLUG), // Title + 'print_retriever_section_info', // Callback + CT_SLUG // Page + ); + add_settings_field( 'ct_copyright_format', __('Copyright format', CT_SLUG), @@ -320,6 +334,18 @@ function page_init() 'description' => __('Replaces output of standard WordPress [caption] shortcode with improved version (add Image Microdata and Image Credit)', CT_SLUG), ) ); + + add_settings_field( + 'ct_auth_flickr_apikey', + __('Flickr api_key', CT_SLUG), + 'ct_text_field_callback', + CT_SLUG, + 'CT_RETRIEVER_SETTINGS', + array( + 'id' => 'ct_auth_flickr_apikey', + 'description' => __('To use the Flickr data retriever you need to have an Flickr API application key.' . ' <a href="https://www.flickr.com/services/api/misc.api_keys.html" target="_blank">See here</a>' . ' for more details.', CT_SLUG), + ) + ); } /** @@ -337,6 +363,8 @@ function sanitize($input) $input['ct_copyright_format'] = sanitize_text_field($input['ct_copyright_format']); } + $input['ct_auth_flickr_apikey'] = sanitize_text_field($input['ct_auth_flickr_apikey']); + return $input; } @@ -385,6 +413,7 @@ function get_default_options() $default_options = array( 'ct_feature_retriever' => '0', 'ct_copyright_format' => '© %author%', + 'ct_auth_flickr_apikey' => '', 'ct_override_caption_shortcode' => '0' ); return $default_options; @@ -527,12 +556,12 @@ function ct_get_sources_array() 'Shutterstock' => array( 'caption' => 'Shutterstock', 'copyright' => 'get_shutterstock_copyright', - 'retriever' => '' + 'retriever' => 'get_shutterstock_metadata' ), 'Corbis_Images' => array( 'caption' => 'Corbis Images', 'copyright' => 'get_corbis_images_copyright', - 'retriever' => '' + 'retriever' => 'get_corbis_images_metadata' ), 'Getty_Images' => array( 'caption' => 'Getty Images', @@ -543,6 +572,11 @@ function ct_get_sources_array() 'caption' => 'Pixelio', 'copyright' => 'get_pixelio_copyright', 'retriever' => 'get_pixelio_metadata' + ), + 'flickr' => array( + 'caption' => 'Flickr', + 'copyright' => 'get_flickr_copyright', + 'retriever' => 'get_flickr_metadata' ) ); return $sources; @@ -590,6 +624,20 @@ function get_shutterstock_copyright() return '© %author%'; } +/** + * Shutterstock: metadata + */ +function get_shutterstock_metadata($number) +{ + $item = array(); + + $item['author'] = '...not implemented yet...'; + $item['publisher'] = 'Shutterstock'; + $item['license'] = 'Royalty-free'; + + return $item; +} + /** * Corbis Images: copyright */ @@ -598,6 +646,20 @@ function get_corbis_images_copyright() return '© %author%/Corbis'; } +/** + * Corbis Images: metadata + */ +function get_corbis_images_metadata($number) +{ + $item = array(); + + $item['author'] = '...not implemented yet...'; + $item['publisher'] = 'Corbis Images'; + $item['license'] = 'Royalty-free'; + + return $item; +} + /** * Getty Images: copyright */ @@ -613,7 +675,7 @@ function get_getty_images_metadata($number) { $item = array(); - $item['author'] = '' . $number; + $item['author'] = '...not implemented yet...'; $item['publisher'] = 'Getty Images'; $item['license'] = 'Royalty-free'; @@ -637,4 +699,21 @@ function get_pixelio_metadata($number) return $parser->execute($number); } +/** + * Flickr: copyright + */ +function get_flickr_copyright() +{ + return Flickr::COPYRIGHT; +} + +/** + * Flickr: metadata + */ +function get_flickr_metadata($number) +{ + $parser = new Flickr(get_single_option('ct_auth_flickr_apikey')); + return $parser->execute($number); +} + ?> diff --git a/php/parser/flickr.php b/php/parser/flickr.php new file mode 100644 index 0000000..765b34f --- /dev/null +++ b/php/parser/flickr.php @@ -0,0 +1,90 @@ +<?php + +/** + * Flickr parser + * + * @package parser + * @author Labs64 <info@labs64.com> + **/ +class Flickr extends Parser +{ + + const COPYRIGHT = '© %author% - Flickr.com'; + + const BASE_URL = 'https://api.flickr.com/services/rest/'; + + private $apiKey; + + function __construct($apiKey) + { + parent::__construct(); + + $this->apiKey = $apiKey; + } + + protected function parse($number) + { + $item = parent::parse($number); + $item['source'] = 'Flickr'; + $item['publisher'] = 'Flickr'; + $item['license'] = ''; + + $photosGetInfo_resp = $this->photosGetInfo($number); + + if ($photosGetInfo_resp['stat'] == 'ok') { + $realname = $photosGetInfo_resp['photo']['owner']['realname']; + $username = $photosGetInfo_resp['photo']['owner']['username']; + $item['author'] = (empty($realname)) ? $username : $realname; + + $license_id = $photosGetInfo_resp['photo']['license']; + $photosLicensesGetInfo_resp = $this->photosLicensesGetInfo(); + $lic_array = $this->findLicensesById($license_id, $photosLicensesGetInfo_resp['licenses']['license']); + + if (empty($lic_array['url'])) { + $item['license'] = $lic_array['name']; + } else { + $item['license'] = '<a href="' . $lic_array['url'] . '" target="__blank">' . $lic_array['name'] . '</a>'; + } + + } else { + $item['info'] = $photosGetInfo_resp['code'] . ': ' . $photosGetInfo_resp['message']; + // TODO: use only info block as soon as this implemented + $item['author'] = $photosGetInfo_resp['code'] . ': ' . $photosGetInfo_resp['message']; + } + + return $item; + } + + private function photosGetInfo($number) + { + $params = array( + 'method' => 'flickr.photos.getInfo', + 'api_key' => $this->apiKey, + 'photo_id' => $number, + 'format' => 'php_serial', + ); + $response = $this->curl->get(self::BASE_URL, $params); + return unserialize($response->body); + } + + private function photosLicensesGetInfo() + { + $params = array( + 'method' => 'flickr.photos.licenses.getInfo', + 'api_key' => $this->apiKey, + 'format' => 'php_serial', + ); + $response = $this->curl->get(self::BASE_URL, $params); + return unserialize($response->body); + } + + private function findLicensesById($id, $licenses = array()) + { + foreach ($licenses as $license) { + if ($license['id'] == $id) { + return $license; + } + } + } + +} diff --git a/readme.txt b/readme.txt index 5a39e52..fdbf4b1 100644 --- a/readme.txt +++ b/readme.txt @@ -1,8 +1,8 @@ === Plugin Name === Contributors: labs64 -Tags: credit, attribution, legal, copyright, owner, author, media library, media, image, photo, license, royalty-free, RF, Creative Commons, stock, attachment, fotolia, bildnachweis, impressum, imprint, microdata, NetLicensing +Tags: credit, attribution, legal, copyright, owner, author, media library, media, image, photo, license, royalty-free, RF, Creative Commons, stock, attachment, flickr, fotolia, bildnachweis, impressum, imprint, microdata, NetLicensing Requires at least: 3.5.1 -Tested up to: 3.8.3 +Tested up to: 3.9 Stable tag: 0.9.13 License: GPL-2.0+ License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -131,7 +131,8 @@ Yes you can! Join in on our [GitHub repository](https://github.com/Labs64/credit == Changelog == = 0.9.13 = -* ... +* Test and approve plugin for WordPress 3.9 +* Enable Flickr = 0.9.12 = * Add custom sizes at the credit table