1<?php
2/*
3 *
4 * @license    MIT
5 * @author     Alexandru Radovici <msg4alex@gmail.com>
6 */
7
8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once(DOKU_PLUGIN.'syntax.php');
11
12
13class syntax_plugin_profiles extends DokuWiki_Syntax_Plugin {
14
15    var $links = array ("facebook" => "https://www.facebook.com/", "github" => "https://github.com/", "googleplus" => "https://plus.google.com/", "linkedin" => "http://www.linkedin.com/", "twitter" => "https://twitter.com/", "bitbucket" => "https://bitbucket.org/", "blog" => "http://", "web" => "http://");
16
17    function getInfo(){
18        return confToHash(dirname(__FILE__).'/info.txt');
19    }
20
21
22    function getType(){ return 'substition'; }
23    function getPType(){ return 'normal'; }
24    function getAllowedTypes() {
25        return array('substition');
26    }
27    function getSort(){
28      return 305;
29    }
30
31    function connectTo($mode) {
32        $this->Lexer->addSpecialPattern('{{(?:facebook|github|googleplus|linkedin|twitter|blog|bitbucket|web)(?:|\..*?):.*?}}',$mode,'plugin_profiles');
33    }
34
35    function handle($match, $state, $pos, &$handler){
36
37        switch ($state) {
38
39          case DOKU_LEXER_SPECIAL :
40            preg_match ('/{{(?P<service>facebook|github|googleplus|linkedin|twitter|blog|bitbucket|web)(?P<type>|\..*?):(?P<parameter>.*?)}}/', $match, $data);
41            $params = array ();
42            $params["service"] = $data["service"];
43            $params["type"] = $data["type"];
44            $params["parameter"] = $data["parameter"];
45
46            return $params;
47
48          default:
49            return "";
50        }
51    }
52
53    function render($mode, &$renderer, $indata) {
54
55        if($mode == 'xhtml'){
56
57              $service = $indata["service"];
58              $type = $indata["type"];
59              if (strlen ($type)>0) $type = substr ($type, 1);
60              $p = explode ("|", $indata["parameter"]);
61              $parameter = htmlspecialchars($p[0]);
62              if (strlen ($p[1])==0) $name = htmlspecialchars($p[0]);
63              else $name = htmlspecialchars($p[1]);
64              $ahref = $this->links[$service];
65              if ($type == "link") $ahref = $parameter;
66              else
67              if ($service=="facebook")
68              {
69                if ($type == "profile" || $type == "page" || $type == "") $ahref = $ahref.$parameter;
70              }
71              else
72              if ($service=="github")
73              {
74                $ahref = $ahref.$parameter;
75              }
76              else
77              if ($service=="googleplus")
78              {
79                $ahref = $ahref.$parameter;
80              }
81              else
82              if ($service=="linkedin")
83              {
84                if ($type == "profile" || $type == "") $ahref = $ahref."in/".$parameter;
85                else if ($type == "page") $ahref = $ahref.$parameter;
86              }
87              else
88              if ($service=="twitter")
89              {
90                if ($type != "link") $ahref = $ahref.$parameter;
91              }
92              else
93              if ($service=="bitbucket")
94              {
95                if ($type != "link") $ahref = $ahref.$parameter;
96              }
97              else
98              if ($service=="blog"||$service=="web")
99              {
100                if ($type != "link") $ahref = $ahref.$parameter;
101              }
102              $renderer->doc .= '<a href='.$ahref.' target="_blank"><img src="' . DOKU_BASE . 'lib/plugins/profiles/images/'.$service.'_icon.png" alt="'.$service.'" border="0"> '.$name.'</a>';
103
104              return true;
105        }
106
107        return false;
108    }
109}
110
111?>
112