Эх сурвалжийг харах

multiple display options initial commit

Fernando Ribeiro 9 жил өмнө
parent
commit
a11e747fc1

+ 5 - 0
conf/default.php

@@ -6,3 +6,8 @@
  */
 
 //$conf['fixme']    = 'FIXME';
+
+
+$conf['networks']   = 'Twitter Facebook Google+ Linkedin Pinterest Tumblr Reddit';
+
+$conf['display']    = 'name';

+ 4 - 1
conf/metadata.php

@@ -5,6 +5,9 @@
  * @author Fernando Ribeiro <pinguim.ribeiro@gmail.com>
  */
 
-
 //$meta['fixme'] = array('string');
 
+
+$meta['networks']   = array('string', '_pattern' => '/^[a-zA-Z\+\s]*$/');
+
+$meta['display']    = array('multichoice','_choices' => array('name', 'text', 'icon'));

+ 7 - 3
lang/en/lang.php

@@ -11,6 +11,10 @@
 // custom language strings for the plugin
 // $lang['fixme'] = 'FIXME';
 
-
-
-//Setup VIM: ex: et ts=4 :
+$lang['twitter_text']    = 'Tweet this';
+$lang['facebook_text']   = 'Share on Facebook';
+$lang['google+_text']    = 'Plus on Google+';
+$lang['linkedin_text']   = 'Share on LinkedIn';
+$lang['pinterest_text']  = 'Pin on Pinterest';
+$lang['tumblr_text']     = 'Share on Tumblr';
+$lang['reddit_text']     = 'Share on Reddit';

+ 3 - 2
lang/en/settings.php

@@ -8,6 +8,7 @@
 // keys need to match the config setting name
 // $lang['fixme'] = 'FIXME';
 
+$lang['networks']   = 'List of your favorite social buttons, space separated and in order of appearance.';
+$lang['networks']  .= ' Valid names are: twitter facebook google+ linkedin pinterest tumblr reddit';
 
-
-//Setup VIM: ex: et ts=4 :
+$lang['display']    = 'Display options: share on network, the name of network or just the icon';

+ 12 - 0
lang/pt/settings.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * english language file for lsb plugin
+ *
+ * @author Fernando Ribeiro <pinguim.ribeiro@gmail.com>
+ */
+
+// keys need to match the config setting name
+// $lang['fixme'] = 'FIXME';
+
+$lang['networks']   = 'A lista dos teus botões sociais favoritos, ordenados e separados por espaços.';
+$lang['networks']  .= ' Os nomes válidos são: twitter facebook google+ linkedin pinterest tumblr reddit';

+ 30 - 17
syntax/button.php

@@ -74,10 +74,11 @@ class syntax_plugin_lsb_button extends DokuWiki_Syntax_Plugin {
 
         if($mode != 'xhtml') return false;
 
+        $renderer->doc .= '<ul class="lsb">';
+
         // validation list of available social networks
         $protected = array('twitter', 'facebook', 'google+', 'linkedin', 'pinterest', 'tumblr', 'reddit');
 
-        $renderer->doc .= '<ul class="lsb">';
 
         foreach ($data as $network) {
             if (in_array($network, $protected)) {
@@ -99,13 +100,11 @@ class syntax_plugin_lsb_button extends DokuWiki_Syntax_Plugin {
         global $ID;
         global $INFO;
 
-        $xhtml = '';
-
         $url      = rawurlencode(wl($ID,'',true));
-        $title    = hsc(($INFO['meta']['title']) ? $INFO['meta']['title'] : $meta);
-        $abstract = hsc($INFO['meta']['description']['abstract']);
-
-        $xhtml = '<li class="lsb-item">';
+        $title    = rawurlencode(($INFO['meta']['title']) ? $INFO['meta']['title'] : $meta);
+        $abstract = rawurlencode($INFO['meta']['description']['abstract']);
+        $text     = $this->lsb_getText($network);
+        $class    = 'ico-' . $network;
 
         // see: https://github.com/cferdinandi/social-sharing
         // <a href="https://twitter.com/intent/tweet?text=YOUR-TITLE&url=YOUR-URL&via=TWITTER-HANDLE">Tweet</a>
@@ -117,35 +116,49 @@ class syntax_plugin_lsb_button extends DokuWiki_Syntax_Plugin {
         // <a href="https://www.xing-share.com/app/user?op=share;sc_p=xing-share;url=YOUR-URL">Share on Xing</a>
         // <a href="http://www.tumblr.com/share/link?url=YOUR-URL&description=YOUR-DESCRIPTION">Share on Tumblr</a>
         // <a href="http://www.reddit.com/submit?url=YOUR_URL&title=YOUR_TITLE">Share on Reddit</a>
-
+ 
         switch ($network) {
             case 'twitter':
-                $xhtml .= '<a class="lsb-link ico-twitter" href="https://twitter.com/intent/tweet?url=' . $url . '&text='. $title .'&via=TWITTER-HANDLE">' . $this->getLang('twitter_title') . '</a>';
+                $href = 'https://twitter.com/intent/tweet?url=' . $url . '&text='. $title .'&via=TWITTER-HANDLE';
                 break;
             case 'facebook':
-                $xhtml .= '<a class="lsb-link ico-facebook" href="http://www.facebook.com/sharer.php?u='. $url .'">' . $this->getLang('facebook_title') . '</a>';
+                $href = 'http://www.facebook.com/sharer.php?u='. $url;
                 break;
             case 'google+':
-                $xhtml .= '<a class="lsb-link ico-google" href="https://plus.google.com/share?url='. $url .'">' . $this->getLang('google+_title') . '</a>';
+                $href = 'https://plus.google.com/share?url='. $url;
                 break;
             case 'linkedin':
-                $xhtml .= '<a class="lsb-link ico-linkedin" href="https://www.linkedin.com/shareArticle?url='. $url .'&title=' . $title . '&summary=' . $abstract . '&mini=true&source=YOUR-URL">' . $this->getLang('linkedin_title') . '</a>';
+                $href = 'href="https://www.linkedin.com/shareArticle?url='. $url .'&title=' . $title . '&summary=' . $abstract . '&mini=true&source=' . $url;
                 break;
             case 'pinterest':
-                $xhtml .= '<a class="lsb-link ico-pinterest" href="https://pinterest.com/pin/create/button/?url='. $url .'&description=' . $abstract . '&media=YOUR-IMAGE-SRC">' . $this->getLang('pinterest_title') . '</a>';
+                $href = 'https://pinterest.com/pin/create/button/?url='. $url .'&description=' . $abstract . '&media=YOUR-IMAGE-SRC';
                 break;
             case 'tumblr':
-                $xhtml .= '<a class="lsb-link ico-tumblr" href="http://www.tumblr.com/share/link?url='. $url .'&description=' . $abstract . '">' . $this->getLang('tumblr_title') . '</a>';
+                $href = 'http://www.tumblr.com/share/link?url='. $url .'&description=' . $abstract;
                 break;
             case 'reddit':
-                $xhtml .= '<a class="lsb-link ico-reddit" href="http://www.reddit.com/submit?url='. $url .'&title=' . $title . '">' . $this->getLang('reddit_title') . '</a>';
+                $href = 'http://www.reddit.com/submit?url='. $url .'&title=' . $title;
                 break;
         }
 
+        $xhtml  = '<li class="lsb-item">';
+        $xhtml .= '<a class="lsb-link ' . $class . '" href="' . $href . '">' . $text . '</a>';
         $xhtml .= '</li>';
 
         return $xhtml;
     }
-}
 
-// vim:ts=4:sw=4:et:
+
+    protected function lsb_getText($network) {
+
+        $display = $this->getConf('display');
+        if ($display == 'name') {
+            return $network;
+        } elseif ($display == 'text') {
+            return $this->getLang($network.'_text');
+        } else {
+            return '';
+        }
+    }
+
+}

+ 150 - 0
syntax/button_0.php

@@ -0,0 +1,150 @@
+<?php
+/**
+ * DokuWiki Plugin lsb (Syntax Component)
+ *
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author  Fernando Ribeiro <pinguim.ribeiro@gmail.com>
+ */
+
+// must be run within Dokuwiki
+if (!defined('DOKU_INC')) die();
+
+class syntax_plugin_lsb_button extends DokuWiki_Syntax_Plugin {
+    /**
+     * @return string Syntax mode type
+     */
+    public function getType() {
+        return 'substition';
+    }
+    /**
+     * @return string Paragraph type
+     */
+    public function getPType() {
+        return 'normal';
+    }
+    /**
+     * @return int Sort order - Low numbers go before high numbers
+     */
+    public function getSort() {
+        return 999;
+    }
+
+    /**
+     * Connect lookup pattern to lexer.
+     *
+     * @param string $mode Parser mode
+     */
+    public function connectTo($mode) {
+        $this->Lexer->addSpecialPattern('~~LSB\b.*?~~',$mode,'plugin_lsb_button');
+//        $this->Lexer->addEntryPattern('<FIXME>',$mode,'plugin_lsb_button');
+    }
+
+//    public function postConnect() {
+//        $this->Lexer->addExitPattern('</FIXME>','plugin_lsb_button');
+//    }
+
+    /**
+     * Handle matches of the lsb syntax
+     *
+     * @param string $match The match of the syntax
+     * @param int    $state The state of the handler
+     * @param int    $pos The position in the document
+     * @param Doku_Handler    $handler The handler
+     * @return array Data for the renderer
+     */
+    public function handle($match, $state, $pos, Doku_Handler &$handler){
+        $match = strtolower(trim(substr($match, 5, -2))); // strip markup
+
+        if (empty($match)) {
+            $match = strtolower(trim($this->getConf('networks')));
+        }
+
+        return explode(' ', $match);
+    }
+
+    /**
+     * Render xhtml output or metadata
+     *
+     * @param string         $mode      Renderer mode (supported modes: xhtml)
+     * @param Doku_Renderer  $renderer  The renderer
+     * @param array          $data      The data from the handler() function
+     * @return bool If rendering was successful.
+     */
+    public function render($mode, Doku_Renderer &$renderer, $data) {
+
+        if($mode != 'xhtml') return false;
+
+        $renderer->doc .= '<ul class="lsb">';
+
+        // validation list of available social networks
+        $protected = array('twitter', 'facebook', 'google+', 'linkedin', 'pinterest', 'tumblr', 'reddit');
+
+
+        foreach ($data as $network) {
+            if (in_array($network, $protected)) {
+                $renderer->doc .= $this->lsb_button($network);
+            }
+        }
+        $renderer->doc .= '</ul>';
+
+        return true;
+    }
+
+    /**
+     * Render xhtml output for facebook share button
+     *
+     * @param string $network The social network to render the button to
+     * @return string Xhtml code for button.
+     */
+    protected function lsb_button ($network) {
+        global $ID;
+        global $INFO;
+
+        $url      = rawurlencode(wl($ID,'',true));
+        $title    = hsc(($INFO['meta']['title']) ? $INFO['meta']['title'] : $meta);
+        $abstract = hsc($INFO['meta']['description']['abstract']);
+
+        // see: https://github.com/cferdinandi/social-sharing
+        // <a href="https://twitter.com/intent/tweet?text=YOUR-TITLE&url=YOUR-URL&via=TWITTER-HANDLE">Tweet</a>
+        // <a href="https://www.facebook.com/sharer/sharer.php?u=YOUR-URL">Share on Facebook</a>
+        // <a href="https://plus.google.com/share?url=YOUR-URL">Plus on Google+</a>
+        // <a href="https://www.linkedin.com/shareArticle?mini=true&url=YOUR-URL&title=YOUR-TITLE&summary=YOUR-SUMMARY&source=YOUR-URL">Share on LinkedIn</a>
+        // <a href="https://pinterest.com/pin/create/button/?url=YOUR-URL&description=YOUR-DESCRIPTION&media=YOUR-IMAGE-SRC">Pin on Pinterest</a>
+        // <a href="https://vk.com/share.php?url=YOUR-URL&title=YOUR-TITLE&description=YOUR-DESCRIPTION&image=YOUR-IMAGE-SRC&noparse=true">Share on VK</a>
+        // <a href="https://www.xing-share.com/app/user?op=share;sc_p=xing-share;url=YOUR-URL">Share on Xing</a>
+        // <a href="http://www.tumblr.com/share/link?url=YOUR-URL&description=YOUR-DESCRIPTION">Share on Tumblr</a>
+        // <a href="http://www.reddit.com/submit?url=YOUR_URL&title=YOUR_TITLE">Share on Reddit</a>
+
+        $xhtml = '<li class="lsb-item">';
+
+        switch ($network) {
+            case 'twitter':
+                $xhtml .= '<a class="lsb-link ico-twitter" href="https://twitter.com/intent/tweet?url=' . $url . '&text='. $title .'&via=TWITTER-HANDLE">' . $this->getLang('twitter_name') . '</a>';
+                break;
+            case 'facebook':
+                $xhtml .= '<a class="lsb-link ico-facebook" href="http://www.facebook.com/sharer.php?u='. $url .'">' . $this->getLang('facebook_name') . '</a>';
+                break;
+            case 'google+':
+                $xhtml .= '<a class="lsb-link ico-google" href="https://plus.google.com/share?url='. $url .'">' . $this->getLang('google+_name') . '</a>';
+                break;
+            case 'linkedin':
+                $xhtml .= '<a class="lsb-link ico-linkedin" href="https://www.linkedin.com/shareArticle?url='. $url .'&title=' . $title . '&summary=' . $abstract . '&mini=true&source=YOUR-URL">' . $this->getLang('linkedin_name') . '</a>';
+                break;
+            case 'pinterest':
+                $xhtml .= '<a class="lsb-link ico-pinterest" href="https://pinterest.com/pin/create/button/?url='. $url .'&description=' . $abstract . '&media=YOUR-IMAGE-SRC">' . $this->getLang('pinterest_name') . '</a>';
+                break;
+            case 'tumblr':
+                $xhtml .= '<a class="lsb-link ico-tumblr" href="http://www.tumblr.com/share/link?url='. $url .'&description=' . $abstract . '">' . $this->getLang('tumblr_name') . '</a>';
+                break;
+            case 'reddit':
+                $xhtml .= '<a class="lsb-link ico-reddit" href="http://www.reddit.com/submit?url='. $url .'&title=' . $title . '">' . $this->getLang('reddit_name') . '</a>';
+                break;
+        }
+
+        $xhtml .= '</li>';
+
+        return $xhtml;
+    }
+
+
+}