diff options
author | Christian Weiske <cweiske@cweiske.de> | 2014-04-23 23:12:55 +0200 |
---|---|---|
committer | Christian Weiske <cweiske@cweiske.de> | 2014-04-23 23:12:55 +0200 |
commit | 6b3f1d4bb5c909413f31d7df5bab0e8a4084e29e (patch) | |
tree | fe1ea7bbefe3721bd3bb536da4c9c20bffca35df /src | |
parent | af2a061ecdfb4414ee0e8b500eccdf39a8d8cec5 (diff) | |
download | semanticscuttle-6b3f1d4bb5c909413f31d7df5bab0e8a4084e29e.tar.gz semanticscuttle-6b3f1d4bb5c909413f31d7df5bab0e8a4084e29e.tar.bz2 |
Add support for phancap website thumbnailer.
Drop support for artviper, since their service is gone.
Diffstat (limited to 'src')
-rw-r--r-- | src/SemanticScuttle/Service.php | 2 | ||||
-rw-r--r-- | src/SemanticScuttle/Service/Thumbnails.php | 59 | ||||
-rw-r--r-- | src/SemanticScuttle/Thumbnailer/Null.php | 52 | ||||
-rw-r--r-- | src/SemanticScuttle/Thumbnailer/Phancap.php | 92 |
4 files changed, 204 insertions, 1 deletions
diff --git a/src/SemanticScuttle/Service.php b/src/SemanticScuttle/Service.php index 1afb353..cd79f2c 100644 --- a/src/SemanticScuttle/Service.php +++ b/src/SemanticScuttle/Service.php @@ -51,7 +51,7 @@ class SemanticScuttle_Service { static $instance; if (!isset($instance)) { - $instance = new self($db); + $instance = new static($db); } return $instance; } diff --git a/src/SemanticScuttle/Service/Thumbnails.php b/src/SemanticScuttle/Service/Thumbnails.php new file mode 100644 index 0000000..6151254 --- /dev/null +++ b/src/SemanticScuttle/Service/Thumbnails.php @@ -0,0 +1,59 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * Instantiates the configured website thumbnailer object. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Service_Thumbnails extends SemanticScuttle_Service +{ + /** + * Instantiates the configured website thumbnailer object. + * + * @return object Website thumbnailer + */ + public function getThumbnailer() + { + if (!isset($GLOBALS['thumbnailsType']) + || $GLOBALS['thumbnailsType'] == '' + ) { + $class = 'SemanticScuttle_Thumbnailer_Null'; + } else { + $class = 'SemanticScuttle_Thumbnailer_' + . ucfirst($GLOBALS['thumbnailsType']); + } + if (!class_exists($class)) { + //PEAR classname to filename rule + $file = str_replace('_', '/', $class) . '.php'; + include_once $file; + } + + $thumbnailer = new $class(); + + if (!isset($GLOBALS['thumbnailsConfig']) + || $GLOBALS['thumbnailsConfig'] == '' + ) { + $thumbnailer->setConfig(null); + } else { + $thumbnailer->setConfig($GLOBALS['thumbnailsConfig']); + } + + return $thumbnailer; + } +} +?> diff --git a/src/SemanticScuttle/Thumbnailer/Null.php b/src/SemanticScuttle/Thumbnailer/Null.php new file mode 100644 index 0000000..ec12135 --- /dev/null +++ b/src/SemanticScuttle/Thumbnailer/Null.php @@ -0,0 +1,52 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * Dummy thumbnailer that never returns a thumbnail URL + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ +class SemanticScuttle_Thumbnailer_Null +{ + /** + * Set dummy configuration + * + * @param array $config Dummy configuration + * + * @return void + */ + public function setConfig($config) + { + } + + /** + * Get the URL for a website thumbnail. + * Always returns false. + * + * @param string $bookmarkUrl URL of website to create thumbnail for + * @param integer $width Screenshot width + * @param integer $height Screenshot height + * + * @return mixed FALSE when no screenshot could be obtained, + * string with the URL otherwise + */ + public function getThumbnailUrl($bookmarkUrl, $width, $height) + { + return false; + } +} +?> diff --git a/src/SemanticScuttle/Thumbnailer/Phancap.php b/src/SemanticScuttle/Thumbnailer/Phancap.php new file mode 100644 index 0000000..1b76849 --- /dev/null +++ b/src/SemanticScuttle/Thumbnailer/Phancap.php @@ -0,0 +1,92 @@ +<?php +/** + * SemanticScuttle - your social bookmark manager. + * + * PHP version 5. + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + */ + +/** + * Show website thumbnails/screenshots using phancap + * + * @category Bookmarking + * @package SemanticScuttle + * @author Christian Weiske <cweiske@cweiske.de> + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + * @see http://cweiske.de/phancap.htm + */ +class SemanticScuttle_Thumbnailer_Phancap +{ + /** + * Configuration array. + * Required keys: + * - url + * - token + * - secret + */ + protected $config = array(); + + /** + * Set phancap configuration + * + * @param array $config Phancap configuration + * + * @return void + */ + public function setConfig($config) + { + $this->config = $config; + } + + /** + * Get the URL for a website thumbnail + * + * @param string $bookmarkUrl URL of website to create thumbnail for + * @param integer $width Screenshot width + * @param integer $height Screenshot height + * + * @return mixed FALSE when no screenshot could be obtained, + * string with the URL otherwise + */ + public function getThumbnailUrl($bookmarkUrl, $width, $height) + { + //default parameters for the phancap service + $parameters = array( + 'url' => $bookmarkUrl, + 'swidth' => $width, + 'sheight' => $height, + 'sformat' => 'jpg', + ); + + if (isset($this->config['token']) && $this->config['token'] != '') { + $parameters['atoken'] = $this->config['token']; + $parameters['atimestamp'] = time(); + + //create signature + ksort($parameters); + foreach ($parameters as $key => $value) { + $encparams[] = $key . '=' . rawurlencode($value); + } + $encstring = implode('&', $encparams); + $signature = hash_hmac('sha1', $encstring, $this->config['secret']); + //append signature to parameters + $parameters['asignature'] = $signature; + } + + //url-encode the parameters + $urlParams = array(); + foreach ($parameters as $key => $value) { + $urlParams[] = $key . '=' . urlencode($value); + } + + //final URL + return $this->config['url'] . '?' . implode('&', $urlParams); + } +} +?> |