Skip to content

Commit

Permalink
close #11
Browse files Browse the repository at this point in the history
- enable Shutterstock parser
  • Loading branch information
r-brown committed May 2, 2015
1 parent 53dfb28 commit eccac2f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions credit-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
require_once(plugin_dir_path(__FILE__) . '/php/parser/pixelio.php');
require_once(plugin_dir_path(__FILE__) . '/php/parser/flickr.php');
require_once(plugin_dir_path(__FILE__) . '/php/parser/freeimages.php');
require_once(plugin_dir_path(__FILE__) . '/php/parser/shutterstock.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
11 changes: 3 additions & 8 deletions options.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,21 +672,16 @@ function ct_get_istockphoto_metadata($number)
*/
function ct_get_shutterstock_copyright()
{
return '© %author%';
return CTShutterstock::COPYRIGHT;
}

/**
* Shutterstock: metadata
*/
function ct_get_shutterstock_metadata($number)
{
$item = array();

$item['author'] = '...not implemented yet...';
$item['publisher'] = 'Shutterstock';
$item['license'] = 'Royalty-free';

return $item;
$parser = new CTShutterstock();
return $parser->execute($number);
}

/**
Expand Down
46 changes: 46 additions & 0 deletions php/parser/shutterstock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* Shutterstock parser
*
* @package parser
* @author Labs64 <[email protected]>
**/
class CTShutterstock extends CTParser
{

const COPYRIGHT = '&copy; %author%/Shutterstock';

const BASE_URL = 'http://www.shutterstock.com/pic-';

protected function parse($number)
{
$url = self::BASE_URL . $number;

$item = parent::parse($number);
$item['source'] = 'Shutterstock';
$item['publisher'] = 'Shutterstock';
$item['license'] = 'Royalty-free';
$item['link'] = $url;

$doc = new DOMDocument();
$response = $this->curl($url);
$html = @$doc->loadHTML(wp_remote_retrieve_body($response));
if ($html) {
$xpath = new DOMXPath($doc);

$tags = $xpath->query("*/meta[@property='og:url']");
if (!is_null($tags) && $tags->length > 0) {
$item['link'] = $tags->item(0)->getAttribute('content');
}

$tags = $xpath->query("//a[@itemprop='author']");
if (!is_null($tags) && $tags->length > 0) {
$item['author'] = $tags->item(0)->textContent;
}
}

return $item;
}

}
10 changes: 5 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Yes you can! Join in on our [GitHub repository](https://github.com/Labs64/credit
== Changelog ==

= 1.1.0 =
* TODO
* Enable Shutterstock parser [#11](https://github.com/Labs64/credit-tracker/pull/11)

= 1.0.3 =
* Fixed [Wordpress 'caption' shortcode rendering problem #10](https://github.com/Labs64/credit-tracker/issues/10) issue
Expand All @@ -162,7 +162,7 @@ Yes you can! Join in on our [GitHub repository](https://github.com/Labs64/credit
* Fix Flickr *Link* attribute capture

= 0.9.16 =
* Enable Freeimages
* Enable Freeimages parser
* Use original photo URIs for the *Link* attribute
* Add WordPress [caption] shortcode to the 'Shortcodes Reference' section
* Introduce 'text' attribute to the [caption] shortcode; usage - [caption text="image caption"]...[/caption]
Expand All @@ -177,7 +177,7 @@ Yes you can! Join in on our [GitHub repository](https://github.com/Labs64/credit

= 0.9.13 (not-stable) =
* Test and approve plugin for WordPress 3.9
* Enable Flickr
* Enable Flickr parser

= 0.9.12 =
* Add custom sizes at the credit table
Expand All @@ -190,11 +190,11 @@ Yes you can! Join in on our [GitHub repository](https://github.com/Labs64/credit
* French translation by Lilian Ricaud

= 0.9.9 =
* Enable Pixelio
* Enable Pixelio parser

= 0.9.8 =
* Change default fields set at Media Library to Ident-Nr., Source, Author
* Enable Fotolia
* Enable Fotolia parser

= 0.9.7 =
* Test and approve plugin for WordPress 3.8
Expand Down

0 comments on commit eccac2f

Please sign in to comment.