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