-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
R.Brown
committed
Apr 21, 2014
1 parent
5a0a996
commit 10c02df
Showing
5 changed files
with
184 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
@@ -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')); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,7 @@ p { | |
padding: 5px 10px 5px 10px; | ||
margin-top: 40px; | ||
} | ||
|
||
.compat-attachment-fields .label { | ||
vertical-align: top; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = '© %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; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters