From 10cd3e8bc11d09934ab4b17002f8ed729a8082f7 Mon Sep 17 00:00:00 2001 From: "R.Brown" Date: Thu, 6 Feb 2014 20:54:00 +0100 Subject: [PATCH] - add Pixelio parser --- credit-tracker.php | 1 + options.php | 22 +++++++++++++++++++++ php/parser/pixelio.php | 43 ++++++++++++++++++++++++++++++++++++++++++ readme.txt | 4 ++-- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 php/parser/pixelio.php diff --git a/credit-tracker.php b/credit-tracker.php index eb94aff..6c23dc3 100755 --- a/credit-tracker.php +++ b/credit-tracker.php @@ -53,6 +53,7 @@ require_once(plugin_dir_path(__FILE__) . '/php/parser/parser.php'); 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'); // 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/options.php b/options.php index 8464946..19879e5 100644 --- a/options.php +++ b/options.php @@ -538,6 +538,11 @@ function ct_get_sources_array() 'caption' => 'Getty Images', 'copyright' => 'get_getty_images_copyright', 'retriever' => 'get_getty_images_metadata' + ), + 'pixelio' => array( + 'caption' => 'Pixelio', + 'copyright' => 'get_pixelio_copyright', + 'retriever' => 'get_pixelio_metadata' ) ); return $sources; @@ -615,4 +620,21 @@ function get_getty_images_metadata($number) return $item; } +/** + * Pixelio: copyright + */ +function get_pixelio_copyright() +{ + return Pixelio::COPYRIGHT; +} + +/** + * Pixelio: metadata + */ +function get_pixelio_metadata($number) +{ + $parser = new Pixelio(); + return $parser->execute($number); +} + ?> diff --git a/php/parser/pixelio.php b/php/parser/pixelio.php new file mode 100644 index 0000000..97bd6a6 --- /dev/null +++ b/php/parser/pixelio.php @@ -0,0 +1,43 @@ + + **/ +class Pixelio extends Parser +{ + + const COPYRIGHT = '© %author% / PIXELIO'; + + const BASE_URL = 'http://www.pixelio.de/media/'; + + function __construct() + { + parent::__construct(); + } + + protected function parse($number) + { + $item = parent::parse($number); + $item['source'] = 'Pixelio'; + $item['publisher'] = 'Pixelio'; + $item['license'] = 'Royalty-free'; + + $url = self::BASE_URL . $number; + $doc = new DOMDocument(); + $html = @$doc->loadHTMLFile($url); + if ($html) { + $xpath = new DOMXPath($doc); + + $tags = $xpath->query("//tr/td[contains(., 'Fotograf:')]/following::td[1]/a"); + if (!is_null($tags) && $tags->length > 0) { + $item['author'] = $tags->item(0)->textContent; + } + } + + return $item; + } + +} diff --git a/readme.txt b/readme.txt index 4a35c75..c685b8a 100644 --- a/readme.txt +++ b/readme.txt @@ -127,11 +127,11 @@ Yes you can! Join in on our [GitHub repository](https://github.com/Labs64/credit == Changelog == = 0.9.9 = -* *TODO* +* Enable Pixelio = 0.9.8 = * Change default fields set at Media Library to Ident-Nr., Source, Author -* Enable Fotolia parser +* Enable Fotolia = 0.9.7 = * Test and approve plugin for WordPress 3.8