PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/components/com_jfusionplugins/phpbb3/public.php

http://jfusion.googlecode.com/
PHP | 741 lines | 537 code | 101 blank | 103 comment | 124 complexity | c1f04e03126c40f629bb3c01c82d6970 MD5 | raw file
Possible License(s): Apache-2.0
  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. return 'phpbb3';
  18. }
  19. function getRegistrationURL() {
  20. return 'ucp.php?mode=register';
  21. }
  22. function getLostPasswordURL() {
  23. return 'ucp.php?mode=sendpassword';
  24. }
  25. function getLostUsernameURL() {
  26. return 'ucp.php?mode=sendpassword';
  27. }
  28. function getViewNewMessagesURL() {
  29. return 'search.php?search_id=newposts';
  30. }
  31. function getProfileURL($uid) {
  32. return 'memberlist.php?mode=viewprofile&u=' . $uid;
  33. }
  34. function getPrivateMessageURL() {
  35. return 'ucp.php?i=pm&folder=inbox';
  36. }
  37. function prepareText(&$text, $for = 'jfusion', $params = '', $object = '') {
  38. $status = array();
  39. if ($for == 'forum') {
  40. //first thing is to remove all joomla plugins
  41. preg_match_all('/\{(.*)\}/U', $text, $matches);
  42. //find each thread by the id
  43. foreach ($matches[1] AS $plugin) {
  44. //replace plugin with nothing
  45. $text = str_replace('{' . $plugin . '}', "", $text);
  46. }
  47. JFusionFunction::parseCode($text, 'bbcode');
  48. } elseif ($for == 'joomla' || ($for == 'activity' && $params->get('parse_text') == 'html')) {
  49. //remove phpbb's bbcode uids
  50. $text = preg_replace("#\[(.*?):(.*?)]#si", "[$1]", $text);
  51. //encode &nbsp; prior to decoding as somehow it is getting added into phpBB without getting encoded
  52. $text = str_replace('&nbsp;', '&amp;nbsp;', $text);
  53. //decode html entities
  54. $text = html_entity_decode($text);
  55. if (strpos($text, 'SMILIES_PATH') !== false) {
  56. //must convert smilies
  57. $db = & JFusionFactory::getDatabase($this->getJname());
  58. $query = "SELECT config_value FROM #__config WHERE config_name = 'smilies_path'";
  59. $db->setQuery($query);
  60. $smilie_path = $db->loadResult();
  61. $jfparams = & JFusionFactory::getParams($this->getJname());
  62. $source_url = $jfparams->get('source_url');
  63. $text = preg_replace('#<!-- s(.*?) --><img src="\{SMILIES_PATH\}\/(.*?)" alt="(.*?)" title="(.*?)" \/><!-- s\\1 -->#si', "<img src='{$source_url}{$smilie_path}/$2' alt='$3' />", $text);
  64. }
  65. //parse bbcode to html
  66. $options = array();
  67. $options['parse_smileys'] = false;
  68. if (!empty($params) && $params->get('character_limit', false)) {
  69. $status['limit_applied'] = 1;
  70. $options['character_limit'] = $params->get('character_limit');
  71. }
  72. JFusionFunction::parseCode($text, 'html', $options);
  73. } elseif ($for == 'discuss') {
  74. //remove phpbb's bbcode uids
  75. $text = preg_replace("#\[(.*?):(.*?)]#si", "[$1]", $text);
  76. //decode html entities
  77. $text = html_entity_decode($text);
  78. } elseif ($for == 'activity' || $for == 'search') {
  79. $text = preg_replace("#\[(.*?):(.*?)]#si", "[$1]", $text);
  80. $text = html_entity_decode($text);
  81. if ($for == 'activity') {
  82. if ($params->get('parse_text') == 'plaintext') {
  83. $options = array();
  84. $options['plaintext_line_breaks'] = 'space';
  85. if ($params->get('character_limit')) {
  86. $status['limit_applied'] = 1;
  87. $options['character_limit'] = $params->get('character_limit');
  88. }
  89. JFusionFunction::parseCode($text, 'plaintext', $options);
  90. }
  91. } else {
  92. JFusionFunction::parseCode($text, 'plaintext');
  93. }
  94. }
  95. return $status;
  96. }
  97. /* * **********************************************
  98. * Functions For JFusion Who's Online Module
  99. * ********************************************* */
  100. function getOnlineUserQuery($limit, $usergroups = '') {
  101. $limiter = (!empty($limit)) ? "LIMIT 0,$limit" : '';
  102. $usergroup_query = '';
  103. if (!empty($usergroups)) {
  104. if (is_array($usergroups)) {
  105. $usergroups = implode(',', $usergroups);
  106. $usergroup_query .= "AND u.group_id IN ($usergroups)";
  107. } else {
  108. $usergroup_query .= "AND u.group_id = $usergroups";
  109. }
  110. }
  111. //get a unix time from 5 mintues ago
  112. date_default_timezone_set('UTC');
  113. $active = strtotime("-5 minutes", time());
  114. $query = "SELECT DISTINCT u.user_id AS userid, u.username_clean AS username, u.username AS name, u.user_email as email FROM #__users AS u INNER JOIN #__sessions AS s ON u.user_id = s.session_user_id WHERE s.session_viewonline =1 AND s.session_user_id != 1 AND s.session_time > $active $usergroup_query $limiter";
  115. return $query;
  116. }
  117. function getNumberOnlineGuests() {
  118. //get a unix time from 5 mintues ago
  119. date_default_timezone_set('UTC');
  120. $active = strtotime("-5 minutes", time());
  121. $db = & JFusionFactory::getDatabase($this->getJname());
  122. $query = "SELECT COUNT(DISTINCT(session_ip)) FROM #__sessions WHERE session_user_id = 1 AND session_time > $active";
  123. $db->setQuery($query);
  124. $result = $db->loadResult();
  125. return $result;
  126. }
  127. function getNumberOnlineMembers($usergroups = '', $total = 1) {
  128. //get a unix time from 5 mintues ago
  129. date_default_timezone_set('UTC');
  130. $active = strtotime("-5 minutes", time());
  131. $usergroup_query = '';
  132. if (!empty($usergroups) && empty($total)) {
  133. if (is_array($usergroups)) {
  134. $usergroups = implode(',', $usergroups);
  135. $usergroup_query .= "AND u.group_id IN ($usergroups)";
  136. } else {
  137. $usergroup_query .= "AND u.group_id = $usergroups";
  138. }
  139. }
  140. $db = & JFusionFactory::getDatabase($this->getJname());
  141. $query = "SELECT COUNT(DISTINCT(s.session_user_id)) FROM #__sessions AS s INNER JOIN #__users AS u ON s.session_user_id = u.user_id WHERE s.session_viewonline = 1 AND s.session_user_id != 1 AND s.session_time > $active $usergroup_query";
  142. $db->setQuery($query);
  143. $result = $db->loadResult();
  144. return $result;
  145. }
  146. /* * **********************************************
  147. * Functions For Frameless Integration
  148. * ********************************************* */
  149. function getBuffer(&$jfdata) {
  150. // Get the path
  151. $params = JFusionFactory::getParams($this->getJname());
  152. global $source_url;
  153. $source_url = $params->get('source_url');
  154. $source_path = $params->get('source_path');
  155. //get the filename
  156. $jfile = JRequest::getVar('jfile');
  157. if (!$jfile) {
  158. //use the default index.php
  159. $jfile = 'index.php';
  160. }
  161. //redirect for file download requests
  162. if ($jfile == 'file.php') {
  163. $url = "Location: " . $params->get('source_url') . 'download/file.php?' . $_SERVER['QUERY_STRING'];
  164. header($url);
  165. }
  166. //combine the path and filename
  167. if (substr($source_path, -1) == DS) {
  168. $index_file = $source_path . basename($jfile);
  169. } else {
  170. $index_file = $source_path . DS . basename($jfile);
  171. }
  172. if (!is_file($index_file)) {
  173. JError::raiseWarning(500, 'The path to the requested does not exist');
  174. $result = false;
  175. return $result;
  176. }
  177. //set the current directory to phpBB3
  178. chdir($source_path);
  179. /* set scope for variables required later */
  180. global $phpbb_root_path, $phpEx, $db, $config, $user, $auth, $cache, $template, $phpbb_hook, $module, $mode;
  181. if ($jfile == 'mcp.php') {
  182. //must globalize these to make sure urls are generated correctly via extra_url() in mcp.php
  183. global $forum_id, $topic_id, $post_id, $report_id, $user_id;
  184. }
  185. //see if we need to force the database to use a new connection
  186. if ($params->get('database_new_link', 0) && !defined('PHPBB_DB_NEW_LINK')) {
  187. define('PHPBB_DB_NEW_LINK', 1);
  188. }
  189. //define the phpBB3 hooks
  190. require_once(JFUSION_PLUGIN_PATH . DS . $this->getJname() . DS . 'hooks.php');
  191. // Get the output
  192. ob_start();
  193. //we need to hijack $_SERVER['PHP_SELF'] so that phpBB correctly utilizes it such as correctly noted the page a user is browsing
  194. $php_self = $_SERVER['PHP_SELF'];
  195. $juri = new JURI($source_url);
  196. $_SERVER['PHP_SELF'] = $juri->getPath() . $jfile;
  197. try {
  198. defined('UTF8_STRLEN') or define('UTF8_STRLEN', true);
  199. defined('UTF8_CORE') or define('UTF8_CORE', true);
  200. defined('UTF8_CASE') or define('UTF8_CASE', true);
  201. include_once($index_file);
  202. } catch (Exception $e) {
  203. $jfdata->buffer = ob_get_contents();
  204. ob_end_clean();
  205. }
  206. //restore $_SERVER['PHP_SELF']
  207. $_SERVER['PHP_SELF'] = $php_self;
  208. //change the current directory back to Joomla.
  209. chdir(JPATH_SITE);
  210. //show more smileys without the Joomla frame
  211. $jfmode = JRequest::getVar('mode');
  212. $jfform = JRequest::getVar('form');
  213. if ($jfmode == 'smilies' || ($jfmode == 'searchuser' && !empty($jfform) || $jfmode == 'contact')) {
  214. $pattern = '#<head[^>]*>(.*?)<\/head>.*?<body[^>]*>(.*)<\/body>#si';
  215. preg_match($pattern, $jfdata->buffer, $temp);
  216. $jfdata->header = $temp[1];
  217. $jfdata->body = $temp[2];
  218. $this->parseHeader($jfdata);
  219. $this->parseBody($jfdata);
  220. die('<html><head>' . $jfdata->header . '</head><body>' . $jfdata->body . '</body></html>');
  221. }
  222. }
  223. function parseBody(&$data) {
  224. static $regex_body, $replace_body;
  225. if (!$regex_body || !$replace_body) {
  226. // Define our preg arrays
  227. $regex_body = array();
  228. $replace_body = array();
  229. //fix anchors
  230. $regex_body[] = '#\"\#(.*?)\"#mS';
  231. $replace_body[] = '"' . $data->fullURL . '#$1"';
  232. //parse URLS
  233. $regex_body[] = '#href="\.\/(.*?)"#me';
  234. $replace_body[] = '$this->fixUrl("$1","' . $data->baseURL . '","' . $data->integratedURL . '")';
  235. //convert relative links from images into absolute links
  236. $regex_body[] = '#(src="|background="|url\(\'?)./(.*?)("|\'?\))#mS';
  237. $replace_body[] = '$1' . $data->integratedURL . '$2$3';
  238. //fix for form actions
  239. $regex_body[] = '#action="(.*?)"(.*?)>#me';
  240. $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL . '")';
  241. //convert relative popup links to full url links
  242. $regex_body[] = '#popup\(\'\.\/(.*?)\'#mS';
  243. $replace_body[] = 'popup(\'' . $data->integratedURL . '$1\'';
  244. //fix for mcp links
  245. $jfile = JRequest::getVar('jfile');
  246. if ($jfile == 'mcp.php') {
  247. $topicid = JRequest::getInt('t');
  248. //fix for merge thread
  249. $regex_body[] = '#(&|&amp;)to_topic_id#mS';
  250. $replace_body[] = '$1t=' . $topicid . '$1to_topic_id';
  251. $regex_body[] = '#/to_topic_id#mS';
  252. $replace_body[] = '/t,' . $topicid . '/to_topic_id';
  253. //fix for merge posts
  254. $regex_body[] = '#(&|&amp;)action=merge_select#mS';
  255. $replace_body[] = '$1t=' . $topicid . '$1action=merge_select';
  256. $regex_body[] = '#/action=merge_select#mS';
  257. $replace_body[] = '/t,' . $topicid . '/action=merge_select';
  258. }
  259. //go ahead and parse any absolute links to index.php
  260. $regex_body[] = '#href="' . $data->integratedURL . 'index.php(.*?)"#me';
  261. $replace_body[] = '$this->fixUrl("index.php$1","' . $data->baseURL . '","' . $data->integratedURL . '")';
  262. }
  263. $data->body = preg_replace($regex_body, $replace_body, $data->body);
  264. }
  265. function fixUrl($q='', $baseURL, $integratedURL) {
  266. //allow for direct downloads and admincp access
  267. if (strstr($q, 'download/') || strstr($q, 'adm/')) {
  268. $url = $integratedURL . $q;
  269. return 'href="' . $url . '"';
  270. }
  271. //these are custom links that are based on modules and thus no as easy to replace as register and lost password links in the hooks.php file so we'll just parse them
  272. $params = & JFusionFactory::getParams($this->getJname());
  273. $edit_account_url = $params->get('edit_account_url');
  274. if (strstr($q, 'mode=reg_details') && !empty($edit_account_url)) {
  275. $url = $edit_account_url;
  276. return 'href="' . $url . '"';
  277. }
  278. $edit_profile_url = $params->get('edit_profile_url');
  279. if (!empty($edit_profile_url)) {
  280. if (strstr($q, 'mode=profile_info')) {
  281. $url = $edit_profile_url;
  282. return 'href="' . $url . '"';
  283. }
  284. static $profile_mod_id;
  285. if (empty($profile_mod_id)) {
  286. //the first item listed in the profile module is the edit profile link so must rewrite it to go to signature instead
  287. $db = & JFusionFactory::getDatabase($this->getJname());
  288. $query = "SELECT module_id FROM #__modules WHERE module_langname = 'UCP_PROFILE'";
  289. $db->setQuery($query);
  290. $profile_mod_id = $db->loadResult();
  291. }
  292. if (!empty($profile_mod_id) && strstr($q, 'i=' . $profile_mod_id)) {
  293. $url = 'ucp.php?i=profile&mode=signature';
  294. $url = JFusionFunction::routeURL($url, JRequest::getInt('Itemid'), $this->getJname());
  295. return 'href="' . $url . '"';
  296. }
  297. }
  298. $edit_avatar_url = $params->get('edit_avatar_url');
  299. if (strstr($q, 'mode=avatar') && !empty($edit_avatar_url)) {
  300. $url = $edit_avatar_url;
  301. return 'href="' . $url . '"';
  302. }
  303. if (substr($baseURL, -1) != '/') {
  304. //non-SEF mode
  305. $q = str_replace('?', '&amp;', $q);
  306. $url = $baseURL . '&amp;jfile=' . $q;
  307. } else {
  308. //check to see what SEF mode is selected
  309. $params = JFusionFactory::getParams($this->getJname());
  310. $sefmode = $params->get('sefmode');
  311. if ($sefmode == 1) {
  312. //extensive SEF parsing was selected
  313. $url = JFusionFunction::routeURL($q, JRequest::getInt('Itemid'));
  314. } else {
  315. //simple SEF mode, we can just combine both variables
  316. $url = $baseURL . $q;
  317. }
  318. }
  319. return 'href="' . $url . '"';
  320. }
  321. function fixRedirect($url, $baseURL) {
  322. //JError::raiseWarning(500, $url);
  323. //split up the timeout from url
  324. $parts = explode(';url=', $url);
  325. $timeout = $parts[0];
  326. $uri = new JURI($parts[1]);
  327. $jfile = $uri->getPath();
  328. $jfile = basename($jfile);
  329. $query = $uri->getQuery(false);
  330. $fragment = $uri->getFragment();
  331. if (substr($baseURL, -1) != '/') {
  332. //non-SEF mode
  333. $redirectURL = $baseURL . '&amp;jfile=' . $jfile;
  334. if (!empty($query)) {
  335. $redirectURL .= '&amp;' . $query;
  336. }
  337. } else {
  338. //check to see what SEF mode is selected
  339. $params = JFusionFactory::getParams($this->getJname());
  340. $sefmode = $params->get('sefmode');
  341. if ($sefmode == 1) {
  342. //extensive SEF parsing was selected
  343. $redirectURL = $jfile;
  344. if (!empty($query)) {
  345. $redirectURL .= '?' . $query;
  346. }
  347. $redirectURL = JFusionFunction::routeURL($redirectURL, JRequest::getInt('Itemid'));
  348. } else {
  349. //simple SEF mode, we can just combine both variables
  350. $redirectURL = $baseURL . $jfile;
  351. if (!empty($query)) {
  352. $redirectURL .= '?' . $query;
  353. }
  354. }
  355. }
  356. if (!empty($fragment)) {
  357. $redirectURL .= "#$fragment";
  358. }
  359. $return = '<meta http-equiv="refresh" content="' . $timeout . ';url=' . $redirectURL . '">';
  360. //JError::raiseWarning(500, htmlentities($return));
  361. return $return;
  362. }
  363. function fixAction($url, $extra, $baseURL) {
  364. $url = htmlspecialchars_decode($url);
  365. $Itemid = JRequest::getInt('Itemid');
  366. //strip any leading dots
  367. if (substr($url, 0, 2) == './') {
  368. $url = substr($url, 2);
  369. }
  370. if (substr($baseURL, -1) != '/') {
  371. //non-SEF mode
  372. $url_details = parse_url($url);
  373. $url_variables = array();
  374. if (!empty($url_details['query'])) {
  375. parse_str($url_details['query'], $url_variables);
  376. }
  377. $jfile = basename($url_details['path']);
  378. //set the correct action and close the form tag
  379. $replacement = 'action="' . $baseURL . '"' . $extra . '>';
  380. $replacement .= '<input type="hidden" name="jfile" value="' . $jfile . '"/>';
  381. $replacement .= '<input type="hidden" name="Itemid" value="' . $Itemid . '"/>';
  382. $replacement .= '<input type="hidden" name="option" value="com_jfusion"/>';
  383. } else {
  384. //check to see what SEF mode is selected
  385. $params = JFusionFactory::getParams($this->getJname());
  386. $sefmode = $params->get('sefmode');
  387. if ($sefmode == 1) {
  388. //extensive SEF parsing was selected
  389. $url = JFusionFunction::routeURL($url, $Itemid);
  390. $replacement = 'action="' . $url . '"' . $extra . '>';
  391. return $replacement;
  392. } else {
  393. //simple SEF mode
  394. $url_details = parse_url($url);
  395. $url_variables = array();
  396. if (!empty($url_details['query'])) {
  397. parse_str($url_details['query'], $url_variables);
  398. }
  399. $jfile = basename($url_details['path']);
  400. $replacement = 'action="' . $baseURL . $jfile . '"' . $extra . '>';
  401. }
  402. }
  403. unset($url_variables['option'], $url_variables['jfile'], $url_variables['Itemid']);
  404. //add any other variables
  405. if (is_array($url_variables)) {
  406. foreach ($url_variables as $key => $value) {
  407. $replacement .= '<input type="hidden" name="' . $key . '" value="' . $value . '"/>';
  408. }
  409. }
  410. return $replacement;
  411. }
  412. function parseHeader(&$data) {
  413. static $regex_header, $replace_header;
  414. if (!$regex_header || !$replace_header) {
  415. // Define our preg arrays
  416. $regex_header = array();
  417. $replace_header = array();
  418. //convert relative links into absolute links
  419. $regex_header[] = '#(href="|src=")./(.*?")#mS';
  420. $replace_header[] = '$1' . $data->integratedURL . '$2';
  421. //fix for URL redirects
  422. $regex_header[] = '#<meta http-equiv="refresh" content="(.*?)"(.*?)>#me';
  423. $replace_header[] = '$this->fixRedirect("$1","' . $data->baseURL . '")';
  424. //fix pm popup URL to be absolute for some phpBB templates
  425. $regex_header[] = "#var url = '\.\/(.*?)';#mS";
  426. $replace_header[] = "var url = '{$data->integratedURL}$1';";
  427. //convert relative popup links to full url links
  428. $regex_header[] = '#popup\(\'\.\/(.*?)\'#mS';
  429. $replace_header[] = 'popup(\'' . $data->integratedURL . '$1\'';
  430. }
  431. $data->header = preg_replace($regex_header, $replace_header, $data->header);
  432. }
  433. function parseRoute(&$vars) {
  434. foreach ($vars as $k => $v) {
  435. //must undo Joomla's parsing that changes dashes to colons so that PM browsing works correctly
  436. if ($k == 'f') {
  437. $vars[$k] = str_replace(':', '-', $v);
  438. } elseif ($k == 'redirect') {
  439. $vars[$k] = base64_decode($v);
  440. }
  441. }
  442. }
  443. function buildRoute(&$segments) {
  444. if (is_array($segments)) {
  445. foreach ($segments as $k => $v) {
  446. if (strstr($v, 'redirect,./')) {
  447. //need to encode the redirect to prevent issues with SEF
  448. $url = substr($v, 9);
  449. $segments[$k] = 'redirect,' . base64_encode($url);
  450. }
  451. }
  452. }
  453. }
  454. function getPathway() {
  455. $mainframe = &JFactory::getApplication('site');
  456. $db =& JFusionFactory::getDatabase($this->getJname());
  457. $pathway = array();
  458. $forum_id = JRequest::getInt('f');
  459. if (!empty($forum_id)) {
  460. //get the forum's info
  461. $query = "SELECT forum_name, parent_id, left_id, right_id, forum_parents FROM #__forums WHERE forum_id = $forum_id";
  462. $db->setQuery($query);
  463. $forum_info = $db->loadObject();
  464. //get forum parents
  465. $query = "SELECT forum_id, forum_name FROM #__forums WHERE left_id < {$forum_info->left_id} AND right_id > {$forum_info->right_id} ORDER BY left_id ASC";
  466. $db->setQuery($query);
  467. $forum_parents = $db->loadObjectList();
  468. if (!empty($forum_parents)) {
  469. foreach ($forum_parents as $k => $data) {
  470. $crumb = new stdClass();
  471. $crumb->title = $data->forum_name;
  472. $crumb->url = "viewforum.php?f={$data->forum_id}";
  473. $pathway[] = $crumb;
  474. }
  475. }
  476. $crumb = new stdClass();
  477. $crumb->title = $forum_info->forum_name;
  478. $crumb->url = "viewforum.php?f=" . $forum_id;
  479. $pathway[] = $crumb;
  480. }
  481. $topic_id = JRequest::getInt('t');
  482. if (!empty($topic_id)) {
  483. $query = "SELECT topic_title FROM #__topics WHERE topic_id = $topic_id";
  484. $db->setQuery($query);
  485. $topic_title = $db->loadObject();
  486. $crumb = new stdClass();
  487. $crumb->title = $topic_title->topic_title;
  488. $crumb->url = "viewtopic.php?f=$forum_id&amp;t=$topic_id";
  489. $pathway[] = $crumb;
  490. }
  491. return $pathway;
  492. }
  493. function getAvatar($puser_id) {
  494. if ($puser_id) {
  495. $dbparams = JFusionFactory::getParams($this->getJname());
  496. $db = JFusionFactory::getDatabase($this->getJname());
  497. $db->setQuery('SELECT user_avatar, user_avatar_type FROM #__users WHERE user_id=' . $puser_id);
  498. $db->query();
  499. $result = $db->loadObject();
  500. if (!empty($result)) {
  501. if ($result->user_avatar_type == 1) {
  502. // AVATAR_UPLOAD
  503. $url = $dbparams->get('source_url') . 'download/file.php?avatar=' . $result->user_avatar;
  504. } else if ($result->user_avatar_type == 3) {
  505. // AVATAR_GALLERY
  506. $db->setQuery("SELECT config_value FROM #__config WHERE config_name='avatar_gallery_path'");
  507. $db->query();
  508. $path = $db->loadResult();
  509. if (!empty($path)) {
  510. $url = $dbparams->get('source_url') . $path . '/' . $result->user_avatar;
  511. } else {
  512. $url = '';
  513. }
  514. } else if ($result->user_avatar_type == 2) {
  515. // AVATAR REMOTE URL
  516. $url = $result->user_avatar;
  517. } else {
  518. $url = '';
  519. }
  520. return $url;
  521. }
  522. }
  523. return 0;
  524. }
  525. function getPrivateMessageCounts($puser_id) {
  526. if ($puser_id) {
  527. // read pm counts
  528. $db = JFusionFactory::getDatabase($this->getJname());
  529. // read unread count
  530. $db->setQuery('SELECT COUNT(msg_id)
  531. FROM #__privmsgs_to
  532. WHERE pm_unread = 1
  533. AND folder_id <> -2
  534. AND user_id = ' . $puser_id);
  535. $unreadCount = $db->loadResult();
  536. // read total pm count
  537. $db->setQuery('SELECT COUNT(msg_id)
  538. FROM #__privmsgs_to
  539. WHERE folder_id NOT IN (-1, -2)
  540. AND user_id = ' . $puser_id);
  541. $totalCount = $db->loadResult();
  542. return array('unread' => $unreadCount, 'total' => $totalCount);
  543. }
  544. return array('unread' => 0, 'total' => 0);
  545. }
  546. function getActivityQuery($usedforums, $result_order, $result_limit) {
  547. //filter forums based on user permissions
  548. $forum = & JFusionFactory::getForum($this->getJname());
  549. $forumids = $forum->filterForumList($usedforums);
  550. if (empty($forumids)) {
  551. $forumids = array(0);
  552. }
  553. $where = ' WHERE a.forum_id IN (' . implode(',', $forumids) . ') AND a.topic_approved = 1 AND b.post_approved = 1';
  554. $end = $result_order . " LIMIT 0," . $result_limit;
  555. $numargs = func_num_args();
  556. if ($numargs > 3) {
  557. $db = & JFusionFactory::getDatabase($this->getJname());
  558. $filters = func_get_args();
  559. $i = 3;
  560. for ($i = 3; $i < $numargs; $i++) {
  561. if ($filters[$i][0] == 'userid') {
  562. $where.= ' HAVING userid = ' . $db->Quote($filters[$i][1]);
  563. }
  564. }
  565. }
  566. $query = array(
  567. //LAT with first post info
  568. LAT . '0' => "SELECT a.topic_id AS threadid, a.topic_first_post_id AS postid, a.topic_first_poster_name AS name, CASE WHEN b.poster_id = 1 AND a.topic_first_poster_name != '' THEN a.topic_first_poster_name ELSE c.username_clean END as username, a.topic_poster AS userid, CASE WHEN b.poster_id = 1 THEN 1 ELSE 0 END AS guest, a.topic_title AS subject, a.topic_time AS dateline, a.forum_id as forum_specific_id, a.topic_last_post_time as last_post_dateline FROM `#__topics` as a INNER JOIN `#__posts` as b ON a.topic_first_post_id = b.post_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY a.topic_last_post_time $end",
  569. //LAT with latest post info
  570. LAT . '1' => "SELECT a.topic_id AS threadid, a.topic_last_post_id AS postid, a.topic_last_poster_name AS name, CASE WHEN b.poster_id = 1 AND a.topic_last_poster_name != '' THEN a.topic_last_poster_name ELSE c.username_clean END as username, a.topic_last_poster_id AS userid, CASE WHEN a.topic_last_poster_id = 1 THEN 1 ELSE 0 END AS guest, a.topic_title AS subject, a.topic_last_post_time AS dateline, a.forum_id as forum_specific_id, a.topic_last_post_time as last_post_dateline FROM `#__topics` as a INNER JOIN `#__posts` as b ON a.topic_last_post_id = b.post_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY a.topic_last_post_time $end",
  571. //LCT
  572. LCT => "SELECT a.topic_id AS threadid, a.topic_first_post_id AS postid, a.topic_first_poster_name AS name, CASE WHEN a.topic_poster = 1 AND a.topic_first_poster_name != '' THEN a.topic_first_poster_name ELSE c.username_clean END as username, a.topic_poster AS userid, CASE WHEN a.topic_poster = 1 THEN 1 ELSE 0 END AS guest, a.topic_title AS subject, b.post_text AS body, a.topic_time AS dateline, a.forum_id as forum_specific_id, a.topic_last_post_time as last_post_dateline FROM `#__topics` as a INNER JOIN `#__posts` as b ON a.topic_first_post_id = b.post_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY a.topic_time $end",
  573. //LCP
  574. LCP => "SELECT b.topic_id AS threadid, b.post_id AS postid, CASE WHEN b.poster_id = 1 AND b.post_username!='' THEN b.post_username ELSE c.username END AS name, CASE WHEN b.poster_id = 1 AND b.post_username != '' THEN b.post_username ELSE c.username_clean END as username, b.poster_id AS userid, CASE WHEN b.poster_id = 1 THEN 1 ELSE 0 END AS guest, b.post_subject AS subject, b.post_text AS body, b.post_time AS dateline, b.post_time as last_post_dateline, b.forum_id as forum_specific_id FROM `#__topics` as a INNER JOIN `#__posts` AS b ON a.topic_id = b.topic_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY b.post_time $end");
  575. return $query;
  576. }
  577. /* * **********************************************
  578. * For JFusion Search Plugin
  579. * ********************************************* */
  580. function getSearchQueryColumns() {
  581. $columns = new stdClass();
  582. $columns->title = "p.post_subject";
  583. $columns->text = "p.post_text";
  584. return $columns;
  585. }
  586. function getSearchQuery(&$pluginParam) {
  587. //need to return threadid, postid, title, text, created, section
  588. $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,
  589. FROM_UNIXTIME(p.post_time, "%Y-%m-%d %h:%i:%s") AS created,
  590. CONCAT_WS( "/", f.forum_name, t.topic_title ) AS section,
  591. t.topic_views AS hits
  592. FROM #__posts AS p
  593. INNER JOIN #__topics AS t ON t.topic_id = p.topic_id
  594. INNER JOIN #__forums AS f on f.forum_id = p.forum_id';
  595. return $query;
  596. }
  597. function getSearchCriteria(&$where, &$pluginParam, $ordering) {
  598. $where.= " AND p.post_approved = 1";
  599. $forum = & JFusionFactory::getForum($this->getJname());
  600. if ($pluginParam->get('forum_mode', 0)) {
  601. $selected_ids = $pluginParam->get('selected_forums', array());
  602. $forumids = $forum->filterForumList($selected_ids);
  603. } else {
  604. $db = & JFusionFactory::getDatabase($this->getJname());
  605. //no forums were selected so pull them all then filter
  606. $query = "SELECT forum_id FROM #__forums WHERE forum_type = 1 ORDER BY left_id";
  607. $db->setQuery($query);
  608. $forumids = $db->loadResultArray();
  609. $forumids = $forum->filterForumList($forumids);
  610. }
  611. if (empty($forumids)) {
  612. $forumids = array(0);
  613. }
  614. //determine how to sort the results which is required for accurate results when a limit is placed
  615. switch ($ordering) {
  616. case 'oldest':
  617. $sort = 'p.post_time ASC';
  618. break;
  619. case 'category':
  620. $sort = 'section ASC';
  621. break;
  622. case 'popular':
  623. $sort = 't.topic_views DESC, p.post_time DESC';
  624. case 'alpha':
  625. $sort = 'title ASC';
  626. break;
  627. case 'newest':
  628. default:
  629. $sort = 'p.post_time DESC';
  630. break;
  631. }
  632. $where.= " AND p.forum_id IN (" . implode(',', $forumids) . ") ORDER BY $sort";
  633. }
  634. function filterSearchResults(&$results, &$pluginParam) {
  635. }
  636. function getSearchResultLink($post) {
  637. $forum = JFusionFactory::getForum($this->getJname());
  638. return $forum->getPostURL($post->topic_id, $post->post_id);
  639. }
  640. }