1<?php
2class remote_plugin_tagfilter extends DokuWiki_Remote_Plugin {
3    public function _getMethods() {
4        return array(
5            /*'getTagsById'=>array(
6                'args'=>array('id'),
7                'return'=>'array'
8            )*/
9        );
10    }
11
12    public function getTagsByPage($id) {
13        if(auth_quickaclcheck($id) < AUTH_READ){
14            throw new RemoteAccessDeniedException('You are not allowed to read this file', 111);
15        }
16
17        $Htagfilter = $this->loadHelper('tagfilter',false);
18        if(!$Htagfilter) {
19            /*Exeption*/
20            throw new RemoteAccessDeniedException('problem with helper plugin', 99999);
21        }
22        return $Htagfilter->getTagsBySiteID($id);
23    }
24
25    public function getPagesByTags($tags,$ns='') {
26
27        $Htagfilter = $this->loadHelper('tagfilter',false);
28        if(!$Htagfilter) {
29            /*Exeption*/
30            throw new RemoteAccessDeniedException('problem with helper plugin', 99999);
31        }
32
33        $pages =  $Htagfilter->getPagesByTags($ns,$tags);
34
35        //$pages_cleaned = array_intersect_key($pages, array_flip('id','title'));
36        $pages_r = array();
37
38        foreach($pages as $page){
39            $title = p_get_metadata($page, 'title', METADATA_DONT_RENDER);
40            $pages_r[] = array(
41                'title' => $title?$title:$page,
42                'id' => $page,
43                'tags' => $Htagfilter->getTagsBySiteID($page)
44                );
45        }
46
47        return $pages_r;
48    }
49
50	public function getPagesByRegExpTags($tags,$ns='') {
51
52        $Htagfilter = $this->loadHelper('tagfilter',false);
53        if(!$Htagfilter) {
54            /*Exeption*/
55            throw new RemoteAccessDeniedException('problem with helper plugin', 99999);
56        }
57
58
59		$tags_r = $Htagfilter->getTagsByRegExp($tags,$ns);
60		$tags_r = array_keys($tags_r);
61        $pages =  $Htagfilter->getPagesByTags($ns,implode(' ',$tags_r));
62
63        //$pages_cleaned = array_intersect_key($pages, array_flip('id','title'));
64        $pages_r = array();
65
66        foreach($pages as $page){
67            $title = p_get_metadata($page, 'title', METADATA_DONT_RENDER);
68            $pages_r[] = array(
69                'title' => $title?$title:$page,
70                'id' => $page,
71                'tags' => $Htagfilter->getTagsBySiteID($page)
72                );
73        }
74
75        return $pages_r;
76    }
77
78
79
80}
81