1<?php
2/**
3 * DokuWiki Plugin xcom (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Myron Turner <turnermm02@shaw.ca>
7 */
8
9// must be run within Dokuwiki
10if(!defined('DOKU_INC')) die();
11
12class action_plugin_xcom extends DokuWiki_Action_Plugin {
13
14    /**
15     * Registers a callback function for a given event
16     *
17     * @param Doku_Event_Handler $controller DokuWiki's event controller object
18     * @return void
19     */
20    public function register(Doku_Event_Handler $controller) {
21
22       $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_dokuwiki_started');
23       $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_meta_headers');
24
25    }
26
27    /**
28     * [Custom event handler which performs action]
29     *
30     * @param Doku_Event $event  event object by reference
31     * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
32     *                           handler was registered]
33     * @return void
34     */
35
36    public function handle_dokuwiki_started(Doku_Event &$event, $param) {
37        global $JSINFO, $INFO;
38        $JSINFO['pwdhide'] = $this->getLang('pwdhide');
39        $JSINFO['pwdview'] = $this->getLang('pwdview');
40        $JSINFO['savelocalfile'] = $this->getLang('savelocalfile');
41        $local_url = $this->getConf('local_url') ;
42        if(!empty($local_url))  {
43            $JSINFO['url'] = $local_url;
44        }
45        else   $JSINFO['url'] = DOKU_URL;
46
47        $inidir = trim($this->getConf('inidir'));
48         if(!$inidir) {
49               $inidir = DOKU_PLUGIN . 'xcom/scripts/';
50         }
51         else {
52             $inidir = rtrim($inidir,'/') . '/';
53         }
54        $ini_file = $inidir . 'xcom.ini';
55
56        $JSINFO['xcom_sites'] = array();
57        $ini = parse_ini_file($ini_file,1);
58        foreach ($ini as $name=>$site) {
59            $JSINFO['xcom_sites'][$name] = array('url'=>'','user'=>'','pwd'=>'');
60            foreach($site as $item=>$val) {
61                $JSINFO['xcom_sites'][$name][$item] = $val;
62            }
63    }
64       /* tooltips  for  function select menu */
65        $JSINFO['xcom_qtitles'] = array(
66             'dokuwiki.getPagelist'=>'get pages in given namespace',
67            'dokuwiki.search'=>'fulltext search',
68            'dokuwiki.getTitle'=>'Wiki title',
69            'dokuwiki.appendPage'=>'Append text to wiki page',
70            'wiki.aclCheck'=>false,
71            'wiki.getPage'=>'get raw wiki text',
72            'wiki.getPageVersion'=>'get wiki text for specific revision ',
73            'plugin.xcom.pageVersions'=>'available versions of a wiki page',
74            'plugin.xcom.getPageInfo'=>false,
75            'wiki.getPageHTML'=>'get XHTML body of wiki page',
76            'wiki.putPage'=>'Save page',
77            'wiki.listLinks'=>'all links in page',
78            'wiki.getAllPages'=>'all wiki pages in remote wiki',
79			'wiki.getBackLinks'=>'list of backlinks to selected page',
80			'wiki.getRecentChanges'=>'list of recent changes since given timestamp',
81            'wiki.getAttachments'=>'list media files in namespace',
82            'wiki.getAttachmentInfo'=>'info about a media file',
83            'plugin.acl.addAcl'=>false,
84            'plugin.acl.delAcl'=>false,
85            'plugin.xcom.getMedia'=>'list of all media in wiki page',
86            'plugin.xcom.listNamespaces'=>'list all namespaces, or sub-namespaces of ID'
87        );
88
89    }
90
91    public function handle_meta_headers(Doku_Event $event, $param){
92	    $event->data["script"][] = array (
93           "type" => "text/javascript",
94           "src" => DOKU_BASE."lib/plugins/xcom/scripts/xcom_latinize-cmpr.js",
95            "_data" => ""
96          );
97 	      $event->data["script"][] = array (
98           "type" => "text/javascript",
99           "src" => DOKU_BASE."lib/plugins/xcom/scripts/safeFN_class-cmpr.js",
100            "_data" => ""
101         );
102	}
103}
104
105// vim:ts=4:sw=4:et:
106