]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Add support for phancap website thumbnailer.
authorChristian Weiske <cweiske@cweiske.de>
Wed, 23 Apr 2014 21:12:55 +0000 (23:12 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 23 Apr 2014 21:12:55 +0000 (23:12 +0200)
Drop support for artviper, since their service is gone.

data/config.default.php
data/templates/default/bookmarks-thumbnail.inc.tpl.php
data/templates/default/bottom.inc.php
src/SemanticScuttle/Service.php
src/SemanticScuttle/Service/Thumbnails.php [new file with mode: 0644]
src/SemanticScuttle/Thumbnailer/Null.php [new file with mode: 0644]
src/SemanticScuttle/Thumbnailer/Phancap.php [new file with mode: 0644]
www/themes/default/scuttle.css

index 2f32df70e447d4d61108adad36882bb89d842cd8..5e560a7de5b7339ab0a5da231cbf6ab53aae9e36 100644 (file)
@@ -542,35 +542,27 @@ $defaults['privacy'] = 0;
  */
 
 /**
- * Enable bookmark website thumbnails.
+ * Which thumbnail service type to use.
  *
- * According to artviper.net license, buy a license if you
- * gain profit with your pages.
+ * Currently supported:
+ * - null (no screenshots)
+ * - 'phancap', see http://cweiske.de/phancap.htm
  *
- * @var  boolean
- * @link http://www.websitethumbnail.de/
+ * @var string
  */
-$enableWebsiteThumbnails = false;
+$thumbnailsType = null;
 
 /**
- * User ID from websitethumbnail.de
- *
- * You need to register on
- *  http://www.artviper.net/registerapi.php
- * in order to use thumbnails on your domain
+ * Configuration for thumbnail service.
  *
- * @var  string
- * @link http://www.artviper.net/registerapi.php
- */
-$thumbnailsUserId = null;
-
-/**
- * API key.
- * Sent to you by artviper.net after registration.
+ * Phancap requires an array with the following keys:
+ * - url: URL to phancap's get.php file
+ * - token: user name (if access protected)
+ * - secret: password for the user (if access protected)
  *
- * @var string
+ * @var array
  */
-$thumbnailsKey = null;
+$thumbnailsConfig = array();
 
 
 
index 77cc67f643f9cabad5d79a314ff0fee3dd9701c7..b8770dcf0cfdcf5ea7fac8b744703c1d91af373f 100644 (file)
@@ -5,14 +5,14 @@
  *
  * Expects a $row variable with bookmark data.
  */
-if (!$GLOBALS['enableWebsiteThumbnails']) {
-    return;
-}
-
-$thumbnailHash = md5(
-    $address . $GLOBALS['thumbnailsUserId'] . $GLOBALS['thumbnailsKey']
-);
-//echo '<a href="'. $address .'"'. $rel .' ><img class="thumbnail" src="http://www.artviper.net/screenshots/screener.php?url='.$address.'&w=120&sdx=1280&userID='.$GLOBALS['thumbnailsUserId'].'&hash='.$thumbnailHash.'" />';
-echo '<img class="thumbnail" onclick="window.location.href=\''.htmlspecialchars($address).'\'" src="http://www.artviper.net/screenshots/screener.php?url='.htmlspecialchars($address).'&amp;w=120&amp;sdx=1280&amp;userID='.$GLOBALS['thumbnailsUserId'].'&amp;hash='.$thumbnailHash.'" />';
 
+$thumbnailer = SemanticScuttle_Service_Factory::get('Thumbnails')->getThumbnailer();
+$imgUrl      = $thumbnailer->getThumbnailUrl($address, 120, 90);
+if ($imgUrl !== false) {
+    echo '<a href="' . htmlspecialchars($address) . '">'
+        . '<img class="thumbnail" width="120" height="90" src="'
+        . htmlspecialchars($imgUrl).
+        '" />'
+        . '</a>';
+}
 ?>
\ No newline at end of file
index e48f5937f2ab4843d5e55e6939a7b063c742d474..9e4014cca75af6313313d0b364ce7499f2bc27ff 100644 (file)
@@ -6,11 +6,6 @@ echo '<a href="'.createURL('about').'">'.T_('About').'</a>';
 echo ' - ';
 echo T_("Propulsed by ");
 echo " <a href=\"https://sourceforge.net/projects/semanticscuttle/\">SemanticScuttle</a>";
-
-if($GLOBALS['enableWebsiteThumbnails']) {
-       // Licence to the thumbnails provider (OBLIGATORY IF YOU USE ARTVIPER SERVICE)
-       echo ' (Thumbnails by <a href="http://www.artviper.net">webdesign</a>)';
-}
 ?>
 
 </div>
index 1afb353833042c6de811a4ae807db901e7a48649..cd79f2c92f8e51a642d2ff6a2fb7b26acabd2d12 100644 (file)
@@ -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 (file)
index 0000000..6151254
--- /dev/null
@@ -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 (file)
index 0000000..ec12135
--- /dev/null
@@ -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 (file)
index 0000000..1b76849
--- /dev/null
@@ -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);
+    }
+}
+?>
index f37377d5401104e1d9970f30bc6028b83e846bff..12a88fcca64105842bc70648413c8bdc1a4a20dc 100644 (file)
@@ -195,7 +195,6 @@ img.thumbnail {
     padding: 1px;
     margin-right: 6px;
     margin-bottom:4px;
-    cursor:pointer;
     border:1px solid #AAA;
 }
 div.link a {