PageRenderTime 36ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_jfusion/plugins/phpbb3/public.php

https://github.com/Truemedia/DFusion
PHP | 356 lines | 234 code | 59 blank | 63 comment | 31 complexity | 672dc0e9d26854caec7019c1e005f361 MD5 | raw file
  1. <?php
  2. /**
  3. * @package JFusion_phpBB3
  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. * JFusion Public Class for phpBB3
  12. * For detailed descriptions on these functions please check the model.abstractpublic.php
  13. * @package JFusion_phpBB3
  14. */
  15. class JFusionPublic_phpbb3 extends JFusionPublic{
  16. function getJname()
  17. {
  18. return 'phpbb3';
  19. }
  20. function getRegistrationURL()
  21. {
  22. return 'ucp.php?mode=register';
  23. }
  24. function getLostPasswordURL()
  25. {
  26. return 'ucp.php?mode=sendpassword';
  27. }
  28. function getLostUsernameURL()
  29. {
  30. return 'ucp.php?mode=sendpassword';
  31. }
  32. /************************************************
  33. * Functions For JFusion Who's Online Module
  34. ***********************************************/
  35. function getOnlineUserQuery()
  36. {
  37. //get a unix time from 5 mintues ago
  38. date_default_timezone_set('UTC');
  39. $active = strtotime("-5 minutes",time());
  40. $query = "SELECT DISTINCT u.user_id AS userid, u.username, u.username AS name FROM #__users AS u INNER JOIN #__sessions AS s ON u.user_id = s.session_user_id WHERE s.session_user_id != 1 AND s.session_time > $active";
  41. return $query;
  42. }
  43. function getNumberOnlineGuests()
  44. {
  45. //get a unix time from 5 mintues ago
  46. date_default_timezone_set('UTC');
  47. $active = strtotime("-5 minutes",time());
  48. $db =& JFusionFactory::getDatabase($this->getJname());
  49. $query = "SELECT COUNT(*) FROM #__sessions WHERE session_user_id = 1 AND session_time > $active";
  50. $db->setQuery($query);
  51. $result = $db->loadResult();
  52. return $result;
  53. }
  54. function getNumberOnlineMembers()
  55. {
  56. //get a unix time from 5 mintues ago
  57. date_default_timezone_set('UTC');
  58. $active = strtotime("-5 minutes",time());
  59. $db =& JFusionFactory::getDatabase($this->getJname());
  60. $query = "SELECT COUNT(*) FROM #__sessions WHERE session_user_id != 1 AND session_time > $active";
  61. $db->setQuery($query);
  62. $result = $db->loadResult();
  63. return $result;
  64. }
  65. /************************************************
  66. * Functions For Frameless Integration
  67. ***********************************************/
  68. function getBuffer(&$data)
  69. {
  70. // Get the path
  71. $params = JFusionFactory::getParams($this->getJname());
  72. $source_path = $params->get('source_path');
  73. //get the filename
  74. $jfile = JRequest::getVar('jfile');
  75. if (!$jfile) {
  76. //use the default index.php
  77. $jfile = 'index.php';
  78. }
  79. //redirect directly to admincp if needed
  80. if ($jfile == 'adm/index.php') {
  81. $url ="Location: " . $params->get('source_url') . 'adm/index.php?' . $_SERVER['QUERY_STRING'] ;
  82. header($url);
  83. }
  84. //redirect for file download requests
  85. if ($jfile == 'file.php') {
  86. $url ="Location: " . $params->get('source_url') . 'download/file.php?' . $_SERVER['QUERY_STRING'] ;
  87. header($url);
  88. }
  89. //combine the path and filename
  90. if (substr($source_path, -1) == DS) {
  91. $index_file = $source_path . basename($jfile);
  92. } else {
  93. $index_file = $source_path . DS . basename($jfile);
  94. }
  95. if (! is_file($index_file) ) {
  96. JError::raiseWarning(500, 'The path to the requested does not exist');
  97. $result = false;
  98. return $result;
  99. }
  100. //set the current directory to phpBB3
  101. chdir($source_path);
  102. /* set scope for variables required later */
  103. global $phpbb_root_path, $phpEx, $db, $config, $user, $auth, $cache, $template, $phpbb_hook, $module, $mode;
  104. //define the phpBB3 hooks
  105. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'plugins'.DS. $this->getJname().DS.'hooks.php');
  106. // Get the output
  107. ob_start();
  108. try {
  109. define('UTF8_STRLEN', true);
  110. define('UTF8_CORE', true);
  111. define('UTF8_CASE', true);
  112. include_once($index_file);
  113. }
  114. catch(Exception $e) {
  115. $data->buffer = ob_get_contents() ;
  116. ob_end_clean();
  117. }
  118. //change the current directory back to Joomla.
  119. chdir(JPATH_SITE);
  120. }
  121. function parseBody(&$data)
  122. {
  123. static $regex_body, $replace_body;
  124. if (! $regex_body || ! $replace_body ) {
  125. // Define our preg arrays
  126. $regex_body = array();
  127. $replace_body = array();
  128. //fix anchors
  129. $regex_body[] = '#\"\#(.*?)\"#mS';
  130. $replace_body[] = '"'.$data->fullURL.'#$1"';
  131. //parse URLS
  132. $regex_body[] = '#href="\.\/(.*?)"#me';
  133. $replace_body[] = '$this->fixUrl("$1","'.$data->baseURL.'")';
  134. //convert relative links from images into absolute links
  135. $regex_body[] = '#(src="|background="|url\(\'?)./(.*?)("|\'?\))#mS';
  136. $replace_body[] = '$1'.$data->integratedURL.'$2$3';
  137. //fix for form actions
  138. $regex_body[] = '#action="(.*?)"(.*?)>#me';
  139. $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL .'")';
  140. }
  141. $data->body = preg_replace($regex_body, $replace_body, $data->body);
  142. }
  143. function fixUrl($q='',$baseURL)
  144. {
  145. if (substr($baseURL, -1) != '/'){
  146. //non-SEF mode
  147. $q = str_replace('?', '&amp;', $q);
  148. $url = $baseURL . '&amp;jfile=' .$q;
  149. } else {
  150. //check to see what SEF mode is selected
  151. $params = JFusionFactory::getParams($this->getJname());
  152. $sefmode = $params->get('sefmode');
  153. if ($sefmode==1) {
  154. //extensive SEF parsing was selected
  155. $url = JFusionFunction::routeURL($q, JRequest::getVar('Itemid'));
  156. } else {
  157. //simple SEF mode, we can just combine both variables
  158. $url = $baseURL . $q;
  159. }
  160. }
  161. return 'href="'. $url . '"';
  162. }
  163. function fixRedirect($url, $baseURL)
  164. {
  165. //JError::raiseWarning(500, $url);
  166. //split up the timeout from url
  167. $parts = explode(';url=', $url);
  168. $timeout = $parts[0];
  169. $uri = new JURI($parts[1]);
  170. $jfile = $uri->getPath();
  171. $jfile = basename($jfile);
  172. $query = $uri->getQuery(false);
  173. if (substr($baseURL, -1) != '/'){
  174. //non-SEF mode
  175. $redirectURL = $baseURL . '&amp;jfile=' .$jfile;
  176. if(!empty($query)){
  177. $redirectURL .= '&amp;' .$query;
  178. }
  179. } else {
  180. //check to see what SEF mode is selected
  181. $params = JFusionFactory::getParams($this->getJname());
  182. $sefmode = $params->get('sefmode');
  183. if ($sefmode==1) {
  184. //extensive SEF parsing was selected
  185. $redirectURL = JFusionFunction::routeURL($q, JRequest::getVar('Itemid'));
  186. } else {
  187. //simple SEF mode, we can just combine both variables
  188. $redirectURL = $baseURL . $jfile;
  189. if(!empty($query)){
  190. $redirectURL .= '?' .$query;
  191. }
  192. }
  193. }
  194. $return = '<meta http-equiv="refresh" content="'.$timeout.';url=' . $redirectURL .'">';
  195. //JError::raiseWarning(500, htmlentities($return));
  196. return $return;
  197. }
  198. function fixAction($url, $extra, $baseURL)
  199. {
  200. //JError::raiseWarning(500, $url);
  201. $url = htmlspecialchars_decode($url);
  202. $Itemid = JRequest::getVar('Itemid');
  203. if (substr($baseURL, -1) != '/'){
  204. //non-SEF mode
  205. $url_details = parse_url($url);
  206. $url_variables = array();
  207. parse_str($url_details['query'], $url_variables);
  208. $jfile = basename($url_details['path']);
  209. //set the correct action and close the form tag
  210. $replacement = 'action="'.$baseURL . '"' . $extra . '>';
  211. $replacement .= '<input type="hidden" name="jfile" value="'. $jfile . '">';
  212. $replacement .= '<input type="hidden" name="Itemid" value="'.$Itemid . '">';
  213. $replacement .= '<input type="hidden" name="option" value="com_jfusion">';
  214. } else {
  215. //check to see what SEF mode is selected
  216. $params = JFusionFactory::getParams($this->getJname());
  217. $sefmode = $params->get('sefmode');
  218. if ($sefmode==1) {
  219. //extensive SEF parsing was selected
  220. $url = JFusionFunction::routeURL($url, $Itemid);
  221. $replacement = 'action="'.$url . '"' . $extra . '>';
  222. return $replacement;
  223. } else {
  224. //simple SEF mode
  225. $url_details = parse_url($url);
  226. $url_variables = array();
  227. parse_str($url_details['query'], $url_variables);
  228. $jfile = basename($url_details['path']);
  229. $replacement = 'action="'.$baseURL . $jfile.'"' . $extra . '>';
  230. }
  231. }
  232. unset($url_variables['option'],$url_variables['jfile'],$url_variables['Itemid']);
  233. //add any other variables
  234. if(is_array($url_variables)){
  235. foreach ($url_variables as $key => $value){
  236. $replacement .= '<input type="hidden" name="'. $key .'" value="'.$value . '">';
  237. }
  238. }
  239. return $replacement;
  240. }
  241. function parseHeader(&$data)
  242. {
  243. static $regex_header, $replace_header;
  244. if (! $regex_header || ! $replace_header ) {
  245. // Define our preg arrays
  246. $regex_header = array();
  247. $replace_header = array();
  248. //convert relative links into absolute links
  249. $regex_header[] = '#(href="|src=")./(.*?")#mS';
  250. $replace_header[] = '$1'.$data->integratedURL.'$2';
  251. //fix for URL redirects
  252. $regex_header[] = '#<meta http-equiv="refresh" content="(.*?)"(.*?)>#me';
  253. $replace_header[] = '$this->fixRedirect("$1","'.$data->baseURL.'")';
  254. }
  255. $data->header = preg_replace($regex_header, $replace_header, $data->header);
  256. }
  257. /************************************************
  258. * For JFusion Search Plugin
  259. ***********************************************/
  260. function cleanUpSearchText($text)
  261. {
  262. //remove phpbb's bbcode uids
  263. $text = preg_replace("#\[(.*?):(.*?)]#si","[$1]",$text);
  264. $text = JFusionFunction::parseCode($text,'html');
  265. return $text;
  266. }
  267. function getSearchQueryColumns()
  268. {
  269. $columns = new stdClass();
  270. $columns->title = "p.post_subject";
  271. $columns->text = "p.post_text";
  272. return $columns;
  273. }
  274. function getSearchQuery()
  275. {
  276. //need to return threadid, postid, title, text, created, section
  277. $query = 'SELECT p.topic_id, p.post_id, p.forum_id, CASE WHEN p.post_subject = "" THEN CONCAT("Re: ",t.topic_title) ELSE p.post_subject END AS title, p.post_text AS text,
  278. FROM_UNIXTIME(p.post_time, "%Y-%m-%d %h:%i:%s") AS created,
  279. CONCAT_WS( "/", f.forum_name, t.topic_title ) AS section
  280. FROM #__posts AS p
  281. INNER JOIN #__topics AS t ON t.topic_id = p.topic_id
  282. INNER JOIN #__forums AS f on f.forum_id = p.forum_id';
  283. return $query;
  284. }
  285. function getSearchCriteria(&$where)
  286. {
  287. $where .= " AND p.post_approved = 1";
  288. }
  289. function filterSearchResults(&$results)
  290. {
  291. }
  292. function getSearchResultLink($post)
  293. {
  294. $forum = JFusionFactory::getForum($this->getJname());
  295. return $forum->getPostURL($post->topic_id,$post->post_id);
  296. }
  297. }