1<?php 2 3 4use ComboStrap\Auth; 5use ComboStrap\LowQualityPage; 6use ComboStrap\Page; 7use ComboStrap\PageProtection; 8 9require_once(__DIR__ . '/../class/LowQualityPage.php'); 10require_once(__DIR__ . '/../class/PageProtection.php'); 11 12/** 13 * 14 */ 15class action_plugin_combo_pageprotection extends DokuWiki_Action_Plugin 16{ 17 18 19 public function register(Doku_Event_Handler $controller) 20 { 21 22 23 $securityConf = $this->getConf(PageProtection::CONF_PAGE_PROTECTION_MODE); 24 if (empty($securityConf)) { 25 $securityConf = $this->getConf(LowQualityPage::CONF_LOW_QUALITY_PAGE_PROTECTION_MODE); 26 } 27 if ($securityConf == PageProtection::CONF_VALUE_HIDDEN) { 28 /** 29 * https://www.dokuwiki.org/devel:event:pageutils_id_hidepage 30 */ 31 $controller->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'handleHiddenCheck', array()); 32 } else { 33 /** 34 * https://www.dokuwiki.org/devel:event:auth_acl_check 35 */ 36 $controller->register_hook('AUTH_ACL_CHECK', 'AFTER', $this, 'handleAclCheck', array()); 37 } 38 39 /** 40 * https://www.dokuwiki.org/devel:event:search_query_pagelookup 41 */ 42 $controller->register_hook('SEARCH_QUERY_PAGELOOKUP', 'AFTER', $this, 'handleSearchPageLookup', array()); 43 44 /** 45 * https://www.dokuwiki.org/devel:event:search_query_fullpage 46 */ 47 $controller->register_hook('SEARCH_QUERY_FULLPAGE', 'AFTER', $this, 'handleSearchFullPage', array()); 48 /** 49 * https://www.dokuwiki.org/devel:event:feed_data_process 50 */ 51 $controller->register_hook('FEED_DATA_PROCESS', 'AFTER', $this, 'handleRssFeed', array()); 52 53 /** 54 * Add logged in 55 */ 56 $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handleAnonymousJsIndicator'); 57 58 59 } 60 61 /** 62 * Set a low page has hidden 63 * @param $event 64 * @param $param 65 */ 66 function handleHiddenCheck(&$event, $param) 67 { 68 69 $id = $event->data['id']; 70 $page = new Page($id); 71 72 if ($page->isProtected()) { 73 $event->data['hidden'] = true; 74 } 75 76 } 77 78 /** 79 * Make the authorization to NONE for low page 80 * @param $event 81 * @param $param 82 */ 83 function handleAclCheck(&$event, $param) 84 { 85 86 $id = $event->data['id']; 87 if (Page::isDirectoryId($id)){ 88 return; 89 } else { 90 $user = $event->data['user']; 91 $page = new Page($id); 92 if ($page->isProtected($user)) { 93 $event->result = AUTH_NONE; 94 } 95 } 96 97 } 98 99 /** 100 * @param $event 101 * @param $param 102 * The autocomplete do a search on page name 103 */ 104 function handleSearchPageLookup(&$event, $param) 105 { 106 $this->excludePageFromSearch($event); 107 } 108 109 /** 110 * @param $event 111 * @param $param 112 * The search page do a search on page name 113 */ 114 function handleSearchFullPage(&$event, $param) 115 { 116 117 $this->excludePageFromSearch($event); 118 } 119 120 /** 121 * 122 * @param $event 123 * @param $param 124 * The Rss 125 * https://www.dokuwiki.org/syndication 126 * Example 127 * https://example.com/feed.php?type=rss2&num=5 128 */ 129 function handleRssFeed(&$event, $param) 130 { 131 $this->excludePageFromSearch($event); 132 } 133 134 /** 135 * @param $event 136 */ 137 private 138 function excludePageFromSearch(&$event) 139 { 140 141 $result = $event->result; 142 /** 143 * The value is always an array 144 * but as we got this error: 145 * ``` 146 * array_keys() expects parameter 1 to be array 147 * ``` 148 */ 149 if (is_array($result)) { 150 foreach (array_keys($result) as $idx) { 151 $page = new Page($idx); 152 if ($page->isProtected()) { 153 unset($result[$idx]); 154 } 155 } 156 } 157 158 } 159 160 function handleAnonymousJsIndicator(&$event, $param) 161 { 162 163 global $JSINFO; 164 $JSINFO[PageProtection::JS_IS_PUBLIC_NAVIGATION_INDICATOR] = !Auth::isLoggedIn(); 165 166 167 } 168 169} 170