PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/src/site/tmp/install_4a925da139185/admin/plugins/dokuwiki/public.php

https://bitbucket.org/manchas/jrobotz
PHP | 411 lines | 275 code | 61 blank | 75 comment | 72 complexity | 5d21302c03e5b5b8a19c25c01b5f9ac8 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion_dokuwiki
  4. * @author JFusion development team
  5. * @copyright Copyright (C) 2008 JFusion. All rights reserved.
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. */
  8. // no direct access
  9. defined('_JEXEC' ) or die('Restricted access' );
  10. /**
  11. * require the dokuwike framework
  12. */
  13. require_once( dirname(__FILE__). DS .'dokuwiki.php');
  14. /**
  15. * JFusion Public Class for DOKUWIKI 1.1.x
  16. * For detailed descriptions on these functions please check the model.abstractpublic.php
  17. * @package JFusion_dokuwiki
  18. */
  19. class JFusionPublic_dokuwiki extends JFusionPublic {
  20. function getJname()
  21. {
  22. return 'dokuwiki';
  23. }
  24. function getRegistrationURL()
  25. {
  26. return 'doku.php?do=login';
  27. }
  28. function getLostPasswordURL()
  29. {
  30. return 'doku.php?do=resendpwd';
  31. }
  32. /* function getLostUsernameURL()
  33. {
  34. return 'index.php?action=reminder';
  35. }*/
  36. function getBuffer(&$data)
  37. {
  38. // We're going to want a few globals... these are all set later.
  39. global $INFO,$ACT,$ID,$QUERY,$USERNAME,$CLEAR,$QUIET,$USERINFO,$DOKU_PLUGINS,$PARSER_MODES,$TOC,$EVENT_HANDLER,$AUTH,$IMG,$JUMPTO;
  40. global $HTTP_RAW_POST_DATA,$RANGE,$HIGH,$MSG,$DATE,$PRE,$TEXT,$SUF,$AUTH_ACL,$QUIET,$SUM,$SRC,$IMG,$NS,$IDX,$REV,$INUSE,$NS,$AUTH_ACL;
  41. global $UTF8_UPPER_TO_LOWER,$UTF8_LOWER_TO_UPPER,$UTF8_LOWER_ACCENTS,$UTF8_UPPER_ACCENTS,$UTF8_ROMANIZATION,$UTF8_SPECIAL_CHARS,$UTF8_SPECIAL_CHARS2;
  42. global $auth,$plugin_protected,$plugin_types,$conf,$lang,$argv;
  43. global $cache_revinfo,$cache_wikifn,$cache_cleanid,$cache_authname,$cache_metadata,$tpl_configloaded;
  44. global $db_host,$db_name,$db_username,$db_password,$db_prefix,$pun_user,$pun_config;
  45. // Get the path
  46. $params = JFusionFactory::getParams($this->getJname());
  47. $source_path = $params->get('source_path');
  48. $source_url = $params->get('source_url');
  49. $cookie_domain = $params->get('cookie_domain');
  50. $cookie_path = $params->get('cookie_path');
  51. $doku_rel = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $source_url );
  52. $doku_rel = preg_replace('#//+#','/',"/$doku_rel/");
  53. if(!defined('DOKU_REL')) define('DOKU_REL',$doku_rel);
  54. if(!defined('DOKU_URL')) define('DOKU_URL',$source_url);
  55. if(!defined('DOKU_BASE')) define('DOKU_BASE',DOKU_URL);
  56. define('DOKU_COOKIE', 'DW'.md5(DOKU_REL));
  57. $do = JRequest::getVar('do');
  58. if ( $do == 'logout' ) {
  59. $mainframe = &JFactory::getApplication('site');
  60. // logout any joomla users
  61. $mainframe->logout();
  62. //clean up session
  63. $session =& JFactory::getSession();
  64. $session->close();
  65. $session->restart();
  66. } else if ( $do == 'login' ) {
  67. $credentials["username"] = JRequest::getVar('u');
  68. $credentials["password"] = JRequest::getVar('p');
  69. if ( $credentials["username"] && $credentials["password"] ) {
  70. $mainframe = &JFactory::getApplication('site');
  71. $credentials["username"] = JRequest::getVar('u');
  72. $credentials["password"] = JRequest::getVar('p');
  73. $options["remember"] = JRequest::getVar('r');
  74. // $options["return"] = 'http://.......';
  75. // $options["entry_url"] = 'http://.......';
  76. // logout any joomla users
  77. $mainframe->login($credentials,$options);
  78. }
  79. }
  80. if (substr($source_path, -1) == DS) {
  81. $index_file = $source_path .'doku.php';
  82. if ( JRequest::getVar('jfile') == 'detail.php' ) $index_file = $source_path.'lib'.DS.'exe'.DS.'detail.php';
  83. // if ( JRequest::getVar('jfile') == 'fetch.php' ) $index_file = $source_path.'lib'.DS.'exe'.DS.'fetch.php';
  84. // if ( JRequest::getVar('jfile') == 'feed.php' ) $index_file = $source_path .'feed.php';
  85. } else {
  86. $index_file = $source_path .DS.'doku.php';
  87. if ( JRequest::getVar('jfile') == 'detail.php' ) $index_file = $source_path.DS.'lib'.DS.'exe'.DS.'detail.php';
  88. // if ( JRequest::getVar('jfile') == 'fetch.php' ) $index_file = $source_path.DS.'lib'.DS.'exe'.DS.'fetch.php';
  89. // if ( JRequest::getVar('jfile') == 'feed.php' ) $index_file = $source_path .DS.'feed.php';
  90. }
  91. if ( JRequest::getVar('media') ) JRequest::setVar('media',str_replace(':', '-', JRequest::getVar('media')));
  92. //loading the JString, to prevent error!
  93. require_once(JPATH_LIBRARIES.DS.'joomla'.DS.'utilities'.DS.'string.php');
  94. require_once(JPATH_LIBRARIES.DS.'phputf8'.DS.'mbstring'.DS.'strlen.php');
  95. require_once(JPATH_LIBRARIES.DS.'phputf8'.DS.'mbstring'.DS.'case.php');
  96. require_once(JPATH_LIBRARIES.DS.'phputf8'.DS.'mbstring'.DS.'core.php');
  97. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'plugins'.DS.$this->getJname().DS.'hooks.php');
  98. if ( ! is_file($index_file) ) {
  99. JError::raiseWarning(500, 'The path to the DokuWiki index file set in the component preferences does not exist');
  100. return null;
  101. }
  102. //set the current directory to dokuwiki
  103. chdir($source_path);
  104. // Get the output
  105. ob_start();
  106. $rs = include_once($index_file);
  107. $data->buffer = ob_get_contents();
  108. ob_end_clean();
  109. //change the current directory back to Joomla. 5*60
  110. chdir(JPATH_SITE);
  111. // Log an error if we could not include the file
  112. if (!$rs) {
  113. JError::raiseWarning(500, 'Could not find DokuWiki in the specified directory');
  114. }
  115. }
  116. function parseBody(&$data)
  117. {
  118. static $regex_body, $replace_body;
  119. $regex_body = array();
  120. $replace_body = array();
  121. $params = JFusionFactory::getParams($this->getJname());
  122. $source_url = $params->get('source_url');
  123. $doku_path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $source_url );
  124. $doku_path = preg_replace('#//+#','/',"/$doku_path/");
  125. $regex_body[] = '#(href|action|src)=["|\']'.$data->integratedURL.'(.*?)["|\']#mS';
  126. $replace_body[] = '$1="/$2"';
  127. $regex_body[] = '#(href|action|src)=["|\']'.$doku_path.'(.*?)["|\']#mS';
  128. $replace_body[] = '$1="/$2"';
  129. $regex_body[] = '#(href)=["|\']/feed.php["|\']#mS';
  130. $replace_body[] = '$1="'.$data->integratedURL.'feed.php"';
  131. $regex_body[] = '#href=["|\']/(lib/exe/fetch.php)(.*?)["|\']#mS';
  132. $replace_body[] = 'href="'.$data->integratedURL.'$1$2"';
  133. $regex_body[] = '#href=["|\']/(_media/)(.*?)["|\']#mS';
  134. $replace_body[] = 'href="'.$data->integratedURL.'$1$2"';
  135. $regex_body[] = '#href=["|\'](?!\w{0,10}://|\w{0,10}:)(.*?)["|\']#mSie';
  136. $replace_body[] = '\'href="\'.$this->fixUrl("$1","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  137. $regex_body[] = '#(src)=["|\'][./|/](.*?)["|\']#mS';
  138. $replace_body[] = '$1="'.$data->integratedURL.'$2"';
  139. $data->body = preg_replace($regex_body, $replace_body, $data->body);
  140. $this->replaceForm($data);
  141. }
  142. function parseHeader(&$data)
  143. {
  144. static $regex_header, $replace_header;
  145. if ( ! $regex_header || ! $replace_header )
  146. {
  147. // Define our preg arrays
  148. $regex_header = array();
  149. $replace_header = array();
  150. /*
  151. $params = JFusionFactory::getParams($this->getJname());
  152. $source_url = $params->get('source_url');
  153. $doku_path = preg_replace( '#(\w{0,10}://)(.*?)/(.*?)#is' , '$3' , $source_url );
  154. $doku_path = preg_replace('#//+#','/',"/$doku_path/");
  155. $regex_header[] = '#(href|src)=["|\']'.$data->integratedURL.'(.*?)["|\']#mS';
  156. $replace_header[] = '$1="/$2"';
  157. $regex_header[] = '#(href|src)=["|\']'.$doku_path.'(.*?)["|\']#mS';
  158. $replace_header[] = '$1="/$2"';
  159. //convert relative links into absolute links
  160. $regex_header[] = '#(href|src)=["|\'][./|/](.*?)["|\']#mS';
  161. $replace_header[] = '$1="'.$data->integratedURL.'$2"';
  162. */
  163. }
  164. $data->header = preg_replace($regex_header, $replace_header, $data->header);
  165. }
  166. function fixUrl($q='',$baseURL,$fullURL)
  167. {
  168. $q = urldecode($q);
  169. $q = str_replace(':', ';', $q);
  170. if ( strpos($q,'#') === 0 ) {
  171. return $fullURL.$q;
  172. } else {
  173. $q = ltrim( $q , '/' );
  174. }
  175. if ( strpos($q,'_detail/') === 0 || strpos($q,'lib/exe/detail.php') === 0 ) {
  176. if( strpos($q,'_detail/') === 0 ) {
  177. $q = substr($q,strlen('_detail/'));
  178. } else {
  179. $q = substr($q,strlen('lib/exe/detail.php'));
  180. }
  181. if ( strpos($q,'?') === 0 ) {
  182. $url = 'detail.php'.$q;
  183. } else {
  184. $this->trimUrl($q);
  185. $url = 'detail.php?media='.$q;
  186. }
  187. } else if ( ( strpos($q,'_media/') === 0 || strpos($q,'lib/exe/fetch.php') === 0 ) ) {
  188. if( strpos($q,'_media/') === 0 ) {
  189. $q = substr($q,strlen('_media/'));
  190. } else {
  191. $q = substr($q,strlen('lib/exe/fetch.php'));
  192. }
  193. if ( strpos($q,'?') === 0 ) {
  194. $url = 'fetch.php'.$q;
  195. } else {
  196. $this->trimUrl($q);
  197. $url = 'fetch.php?media='.$q;
  198. }
  199. } else if ( strpos($q,'doku.php') === 0 ) {
  200. $q = substr($q,strlen('doku.php'));
  201. if ( strpos($q,'?') === 0 ) {
  202. $url = 'doku.php'.$q;
  203. } else {
  204. $this->trimUrl($q);
  205. if ( strlen($q) ) $url = 'doku.php?id='.$q;
  206. else $url = 'doku.php';
  207. }
  208. } else {
  209. $this->trimUrl($q);
  210. if ( strlen($q) ) $url = 'doku.php?id='.$q;
  211. else $url = 'doku.php';
  212. }
  213. if (substr($baseURL, -1) != '/'){
  214. //non sef URls
  215. $url = str_replace('?', '&amp;', $url);
  216. $url = $baseURL . '&amp;jfile=' .$url;
  217. } else {
  218. $params = JFusionFactory::getParams($this->getJname());
  219. $sefmode = $params->get('sefmode');
  220. if ($sefmode==1) {
  221. $url = JFusionFunction::routeURL($url, JRequest::getVar('Itemid'));
  222. } else {
  223. //we can just append both variables
  224. $url = $baseURL . $url;
  225. }
  226. }
  227. return $url;
  228. }
  229. function trimUrl( &$url ) {
  230. $url = ltrim( $url , '/' );
  231. $order = array('/','?');
  232. $replace = array(';','&');
  233. $url = str_replace($order, $replace, $url);
  234. }
  235. function replaceForm( &$data) {
  236. $pattern = '#<form(.*?)action=["|\'](.*?)["|\'](.*?)>(.*?)</form>#mSsi';
  237. $getData = '';
  238. if (JRequest::getVar('Itemid')) $getData .= '<input name="Itemid" value="'.JRequest::getVar('Itemid').'" type="hidden"/>';
  239. if (JRequest::getVar('option')) $getData .= '<input name="option" value="'.JRequest::getVar('option').'" type="hidden"/>';
  240. if (JRequest::getVar('jname')) $getData .= '<input name="jname" value="'.JRequest::getVar('jname').'" type="hidden"/>';
  241. if (JRequest::getVar('view')) $getData .= '<input name="view" value="'.JRequest::getVar('view').'" type="hidden"/>';
  242. preg_match_all($pattern, $data->body, $links);
  243. foreach ( $links[2] as $key => $value ) {
  244. $method = '#method=["|\']post["|\']#mS';
  245. $is_get = true;
  246. if ( preg_match($method,$links[1][$key]) || preg_match($method,$links[3][$key]) ) $is_get = false;
  247. $value = $this->fixUrl($links[2][$key],$data->baseURL,$data->fullURL);
  248. if( $is_get && substr($value, -1) != DS ) $links[4][$key] = $getData.$links[4][$key];
  249. $data->body = str_replace($links[0][$key], '<form'.$links[1][$key].'action="'.$value.'"'.$links[3][$key].'>'.$links[4][$key].'</form>', $data->body);
  250. }
  251. }
  252. /************************************************
  253. * For JFusion Search Plugin
  254. ***********************************************/
  255. function cleanUpSearchText($text)
  256. {
  257. //remove phpbb's bbcode uids
  258. $text = preg_replace("#\[(.*?):(.*?)]#si","[$1]",$text);
  259. $text = JFusionFunction::parseCode($text,'html');
  260. return $text;
  261. }
  262. /**
  263. * Retrieves the search results to be displayed. Placed here so that plugins that do not use the database can retrieve and return results
  264. * @param $text string text to be searched
  265. * @param $phrase string how the search should be performed exact, all, or any
  266. * @param $pluginParam custom plugin parameters in search.xml
  267. * @param $linkMode what mode to use when creating the URL
  268. * @param $itemid what menu item to use when creating the URL
  269. * @return array of results as objects
  270. * Each result should include:
  271. * $result->title = title of the post/article
  272. * $result->section = (optional) section of the post/article (shows underneath the title; example is Forum Name / Thread Name)
  273. * $result->text = text body of the post/article
  274. * $result->href = link to the content (without this, joomla will not display a title)
  275. * $result->browsernav = 1 opens link in a new window, 2 opens in the same window
  276. * $result->created = (optional) date when the content was created
  277. */
  278. function getSearchResults(&$text, &$phrase, &$pluginParam, $itemid)
  279. {
  280. global $rootFolder;
  281. $params = JFusionFactory::getParams($this->getJname());
  282. $rootFolder = $params->get('source_path');
  283. if (substr($rootFolder, -1) == DS) {
  284. define(DOKU_INC, $rootFolder);
  285. } else {
  286. define(DOKU_INC, $rootFolder.'/');
  287. }
  288. require_once('doku_search.php');
  289. $results = ft_pageSearch($text, &$highlights);
  290. //pass results back to the plugin in case they need to be filtered
  291. $this->filterSearchResults($results);
  292. $rows = array();
  293. $pos = 0;
  294. foreach($results as $key => $index)
  295. {
  296. $rows[$pos]->title = JText::_( $key );
  297. $rows[$pos]->text = $this->getPage($rootFolder,$key);
  298. $rows[$pos]->href = JFusionFunction::routeURL(str_replace(':',';',$this->getSearchResultLink($key)), $itemid);
  299. $rows[$pos]->section = JText::_( $key );
  300. $pos++;
  301. }
  302. return $rows;
  303. }
  304. function getPage($path,$page)
  305. {
  306. $file = $path.DS.'data'.DS.'pages'.DS.str_replace(":", DS, $page).'.txt';
  307. $text = '';
  308. if (file_exists($file)) {
  309. $handle = fopen($file, "r");
  310. while (!feof($handle)) {
  311. $text .= fgets($handle, 4096);
  312. }
  313. fclose($handle);
  314. }
  315. return $text?$text:"Please, follow the given link to get the DokuWiki article where we found one or more keyword(s).";"Please, follow the given link to get the DokuWiki article where we found one or more keyword(s).";
  316. }
  317. function filterSearchResults(&$results)
  318. {
  319. }
  320. function getSearchResultLink($post)
  321. {
  322. return "doku.php?id=" . $post;
  323. }
  324. function getPathWay()
  325. {
  326. if ( JRequest::getVar('id') ) {
  327. $bread = explode(';', JRequest::getVar('id'));
  328. $url = '';
  329. $pathway = array();
  330. $i=0;
  331. foreach($bread as $key ) {
  332. if ($url) $url .= ';'.$key;
  333. else $url = $key;
  334. $path = new stdClass();
  335. $path->title = $key;
  336. $path->url = 'doku.php?id='.$url;
  337. $pathway[] = $path;
  338. }
  339. if ( JRequest::getVar('media') || JRequest::getVar('do') ) {
  340. if ( JRequest::getVar('media') ) $add = JRequest::getVar('media');
  341. else $add = JRequest::getVar('do');
  342. $pathway[count($pathway)-1]->title = $pathway[count($pathway)-1]->title. ' ( '.$add.' )';
  343. }
  344. return $pathway;
  345. }
  346. }
  347. }