Skip to content

Commit

Permalink
- enable Flickr
Browse files Browse the repository at this point in the history
  • Loading branch information
R.Brown committed Apr 21, 2014
1 parent 5a0a996 commit 10c02df
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 9 deletions.
3 changes: 2 additions & 1 deletion credit-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down Expand Up @@ -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'));
Expand Down
4 changes: 4 additions & 0 deletions css/ct-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ p {
padding: 5px 10px 5px 10px;
margin-top: 40px;
}

.compat-attachment-fields .label {
vertical-align: top;
}
89 changes: 84 additions & 5 deletions options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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),
Expand All @@ -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),
)
);
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -385,6 +413,7 @@ function get_default_options()
$default_options = array(
'ct_feature_retriever' => '0',
'ct_copyright_format' => '&copy; %author%',
'ct_auth_flickr_apikey' => '',
'ct_override_caption_shortcode' => '0'
);
return $default_options;
Expand Down Expand Up @@ -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',
Expand All @@ -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;
Expand Down Expand Up @@ -590,6 +624,20 @@ function get_shutterstock_copyright()
return '&copy; %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
*/
Expand All @@ -598,6 +646,20 @@ function get_corbis_images_copyright()
return '&copy; %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
*/
Expand All @@ -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';

Expand All @@ -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);
}

?>
90 changes: 90 additions & 0 deletions php/parser/flickr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/**
* Flickr parser
*
* @package parser
* @author Labs64 <[email protected]>
**/
class Flickr extends Parser
{

const COPYRIGHT = '&copy; %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;
}
}
}

}
7 changes: 4 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 10c02df

Please sign in to comment.