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

/components/com_jfusionplugins/smf2/public.php

http://jfusion.googlecode.com/
PHP | 1041 lines | 782 code | 128 blank | 131 comment | 135 complexity | f65bd41d1690c8aedce2fa12994707d9 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion_SMF
  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 SMF 1.1.x
  12. * For detailed descriptions on these functions please check the model.abstractpublic.php
  13. * @package JFusion_SMF
  14. */
  15. class JFusionPublic_smf2 extends JFusionPublic{
  16. var $callbackdata = null;
  17. var $callbackbypass = null;
  18. function getJname()
  19. {
  20. return 'smf2';
  21. }
  22. function getRegistrationURL()
  23. {
  24. return 'index.php?action=register';
  25. }
  26. function getLostPasswordURL()
  27. {
  28. return 'index.php?action=reminder';
  29. }
  30. function getLostUsernameURL()
  31. {
  32. return 'index.php?action=reminder';
  33. }
  34. function getProfileURL($uid)
  35. {
  36. return 'index.php?action=profile&u='.$uid;
  37. }
  38. function getPrivateMessageURL()
  39. {
  40. return 'index.php?action=pm';
  41. }
  42. function getViewNewMessagesURL()
  43. {
  44. return 'index.php?action=unread';
  45. }
  46. /**
  47. * Prepares text for various areas
  48. *
  49. * @param string &$text Text to be modified
  50. * @param string $for (optional) Determines how the text should be prepared.
  51. * Options for $for as passed in by JFusion's plugins and modules are:
  52. * joomla (to be displayed in an article; used by discussion bot)
  53. * forum (to be published in a thread or post; used by discussion bot)
  54. * activity (displayed in activity module; used by the activity module)
  55. * search (displayed as search results; used by search plugin)
  56. * @param object $params (optional) Joomla parameter object passed in by JFusion's module/plugin
  57. * @param object $object (optional) Object with information for the specific element the text is from
  58. *
  59. * @return array $status Information passed back to calling script such as limit_applied
  60. */
  61. function prepareText(&$text, $for = 'forum', $params = '', $object = '')
  62. {
  63. $status = array();
  64. if($for == 'forum') {
  65. static $bbcode;
  66. //first thing is to remove all joomla plugins
  67. preg_match_all('/\{(.*)\}/U',$text,$matches);
  68. //find each thread by the id
  69. foreach($matches[1] AS $plugin) {
  70. //replace plugin with nothing
  71. $text = str_replace('{'.$plugin.'}',"",$text);
  72. }
  73. if(!is_array($bbcode)) {
  74. $bbcode = array();
  75. //pattens to run in begening
  76. $bbcode[0][] = "#<a[^>]*href=['|\"](ftp://)(.*?)['|\"][^>]*>(.*?)</a>#si";
  77. $bbcode[1][] = "[ftp=$1$2]$3[/ftp]";
  78. //pattens to run in end
  79. $bbcode[2][] = '#<table[^>]*>(.*?)<\/table>#si';
  80. $bbcode[3][] = '[table]$1[/table]';
  81. $bbcode[2][] = '#<tr[^>]*>(.*?)<\/tr>#si';
  82. $bbcode[3][] = '[tr]$1[/tr]';
  83. $bbcode[2][] = '#<td[^>]*>(.*?)<\/td>#si';
  84. $bbcode[3][] = '[td]$1[/td]';
  85. $bbcode[2][] = '#<strong[^>]*>(.*?)<\/strong>#si';
  86. $bbcode[3][] = '[b]$1[/b]';
  87. $bbcode[2][] = '#<(strike|s)>(.*?)<\/\\1>#sim';
  88. $bbcode[3][] = '[s]$2[/s]';
  89. }
  90. $options = array();
  91. $options['bbcode_patterns'] = $bbcode;
  92. JFusionFunction::parseCode($text,'bbcode',$options);
  93. } elseif ($for == 'joomla' || ($for == 'activity' && $params->get('parse_text') == 'html')) {
  94. $options = array();
  95. //convert smilies so they show up in Joomla as images
  96. static $custom_smileys;
  97. if (!is_array($custom_smileys)) {
  98. $custom_smileys = array();
  99. $db =& JFusionFactory::getDatabase($this->getJname());
  100. $query = "SELECT value, variable FROM #__settings WHERE variable = 'smileys_url' OR variable = 'smiley_sets_default'";
  101. $db->setQuery($query);
  102. $settings = $db->loadObjectList('variable');
  103. $query = "SELECT code, filename FROM #__smileys ORDER BY smileyOrder";
  104. $db->setQuery($query);
  105. $smilies = $db->loadObjectList();
  106. if(!empty($smilies)) {
  107. foreach($smilies as $s) {
  108. $custom_smileys[$s->code] = "{$settings['smileys_url']->value}/{$settings['smiley_sets_default']->value}/{$s->filename}";
  109. }
  110. }
  111. }
  112. $options['custom_smileys'] = $custom_smileys;
  113. $options['parse_smileys'] = true;
  114. //parse bbcode to html
  115. if (!empty($params) && $params->get('character_limit', false)) {
  116. $status['limit_applied'] = 1;
  117. $options['character_limit'] = $params->get('character_limit');
  118. }
  119. //add smf bbcode rules
  120. $options['html_patterns'] = array();
  121. $options['html_patterns']['li'] = array('simple_start' => "<li>", 'simple_end' => "</li>\n", 'class' => 'listitem', 'allow_in' => array('list'), 'end_tag' => 0, 'before_tag' => "s", 'after_tag' => "s", 'before_endtag' => "sns", 'after_endtag' => "sns", 'plain_start' => "\n * ", 'plain_end' => "\n");
  122. $bbcodes = array('size', 'glow', 'shadow', 'move', 'pre', 'hr', 'flash', 'ftp', 'table', 'tr', 'td', 'tt', 'abbr', 'anchor', 'black', 'blue', 'green', 'iurl', 'html', 'ltr', 'me', 'nobbc', 'php', 'red', 'rtl', 'time', 'white', 'o', 'O', '0', '@', '*', '=', '@', '+', 'x', '#');
  123. foreach($bbcodes as $bb) {
  124. if (in_array($bb, array('ftp', 'iurl'))) {
  125. $class = 'link';
  126. } elseif (in_array($bb, array('o', 'O', '0', '@', '*', '=', '@', '+', 'x', '#'))) {
  127. $class = 'listitem';
  128. } elseif ($bb == 'table') {
  129. $class = 'table';
  130. } else {
  131. $class = 'inline';
  132. }
  133. if (in_array($bb, array('o', 'O', '0', '@', '*', '=', '@', '+', 'x', '#'))) {
  134. $allow_in = array('list');
  135. } elseif (in_array($bb, array('td', 'tr'))) {
  136. $allow_in = array('table');
  137. } else {
  138. $allow_in = array('listitem', 'block', 'columns', 'inline', 'link');
  139. }
  140. $options['html_patterns'][$bb] = array('mode' => 1, 'content' => 0, 'method' => array($this, 'parseCustomBBCode'), 'class' => $class, 'allow_in' => $allow_in);
  141. }
  142. JFusionFunction::parseCode($text,'html',$options);
  143. } elseif ($for == 'search') {
  144. JFusionFunction::parseCode($text, 'plaintext');
  145. } elseif ($for == 'activity') {
  146. if ($params->get('parse_text') == 'plaintext') {
  147. $options = array();
  148. $options['plaintext_line_breaks'] = 'space';
  149. if ($params->get('character_limit')) {
  150. $status['limit_applied'] = 1;
  151. $options['character_limit'] = $params->get('character_limit');
  152. }
  153. JFusionFunction::parseCode($text, 'plaintext', $options);
  154. }
  155. }
  156. return $status;
  157. }
  158. function getBuffer(&$data)
  159. {
  160. $action = JRequest::getVar('action');
  161. $params = JFusionFactory::getParams($this->getJname());
  162. if ($action=='logout') {
  163. $mainframe = &JFactory::getApplication();
  164. // logout any joomla users
  165. $mainframe->logout();
  166. // clean up session
  167. $session =& JFactory::getSession();
  168. $session->close();
  169. JFusionFunction::addCookie($params->get('cookie_name'), '',0,$params->get('cookie_path'),$params->get('cookie_domain'),$params->get('secure'),$params->get('httponly'));
  170. $mainframe->redirect(str_replace('&amp;', '&', $data->baseURL));
  171. exit();
  172. }
  173. // We're going to want a few globals... these are all set later.
  174. global $time_start, $maintenance, $msubject, $mmessage, $mbname, $language;
  175. global $boardurl, $boarddir, $sourcedir, $webmaster_email, $cookiename;
  176. global $db_connection, $db_server, $db_name, $db_user, $db_prefix, $db_persist, $db_error_send, $db_last_error;
  177. global $modSettings, $context, $sc, $user_info, $topic, $board, $txt;
  178. global $scripturl, $ID_MEMBER, $func;
  179. global $settings, $options, $board_info, $attachments, $messages_request ,$memberContext, $db_character_set;
  180. // new in smf 2
  181. global $smcFunc, $mysql_set_mode,$cachedir,$db_passwd,$db_type, $ssi_db_user, $ssi_db_passwd,$board_info, $options;
  182. // Required to avoid a warning about a license violation even though this is not the case
  183. global $forum_version;
  184. // Get the path
  185. $source_path = $params->get('source_path');
  186. if (substr($source_path, -1) == DS) {
  187. $index_file = $source_path .'index.php';
  188. } else {
  189. $index_file = $source_path .DS.'index.php';
  190. }
  191. if ( ! is_file($index_file) ) {
  192. JError::raiseWarning(500, 'The path to the SMF index file set in the component preferences does not exist');
  193. return null;
  194. }
  195. //set the current directory to SMF
  196. chdir($source_path);
  197. $this->callbackdata = $data;
  198. $this->callbackbypass = false;
  199. // Get the output
  200. ob_start(array($this, 'callback'));
  201. $h = ob_list_handlers();
  202. $rs = include_once($index_file);
  203. // die if popup
  204. if ( $action == 'findmember' || $action == 'helpadmin' || $action == 'spellcheck' || $action == 'requestmembers' || strpos($action ,'xml') !== false ) {
  205. exit();
  206. } else {
  207. $this->callbackbypass = true;
  208. }
  209. while( in_array( get_class($this).'::callback' , $h) ) {
  210. $data->buffer .= ob_get_contents();
  211. ob_end_clean();
  212. $h = ob_list_handlers();
  213. }
  214. //change the current directory back to Joomla.
  215. chdir(JPATH_SITE);
  216. // Log an error if we could not include the file
  217. if (!$rs) {
  218. JError::raiseWarning(500, 'Could not find SMF in the specified directory');
  219. }
  220. }
  221. function parseBody(&$data)
  222. {
  223. $regex_body = array();
  224. $replace_body = array();
  225. //fix for form actions
  226. $regex_body[] = '#action="'.$data->integratedURL.'index.php(.*?)"(.*?)>#me';
  227. $replace_body[] = '$this->fixAction("index.php$1","$2","' . $data->baseURL .'")';
  228. $regex_body[] = '#href="'.$data->integratedURL.'index.php(.*?)"#Sise';
  229. $replace_body[] = '\'href="\'.$this->fixUrl("index.php$1","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  230. $regex_body[] = '#href="\#(.*?)"#Sise';
  231. $replace_body[] = '\'href="\'.$this->fixUrl("#$1","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  232. $regex_body[] = '#sScriptUrl: \'http://joomla.fanno.dk/smf2/index.php\'#mSsi';
  233. $replace_body[] = 'sScriptUrl: \''.$data->baseURL.'\'';
  234. // Chaptcha fix
  235. $regex_body[] = '#\"'.$data->integratedURL.'(index.php\?)(action=verificationcode;vid=register;rand=)(.*?)\"#sie';
  236. $replace_body[] = '\'"\'.$this->fixUrl("index.php?$2$3","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  237. $data->body = preg_replace($regex_body, $replace_body, $data->body);
  238. }
  239. function parseHeader(&$data)
  240. {
  241. static $regex_header, $replace_header;
  242. if ( ! $regex_header || ! $replace_header )
  243. {
  244. $params = JFusionFactory::getParams('joomla_int');
  245. $joomla_url = $params->get('source_url');
  246. $baseURLnoSef = 'index.php?option=com_jfusion&Itemid=' . JRequest::getInt('Itemid');
  247. if (substr($joomla_url, -1) == '/') $baseURLnoSef = $joomla_url . $baseURLnoSef;
  248. else $baseURLnoSef = $joomla_url . '/' . $baseURLnoSef;
  249. // Define our preg arrays
  250. $regex_header = array();
  251. $replace_header = array();
  252. //convert relative links into absolute links
  253. $regex_header[] = '#(href|src)=("./|"/)(.*?)"#mS';
  254. $replace_header[] = '$1="'.$data->integratedURL.'$3"';
  255. //$regex_header[] = '#(href|src)="(.*)"#mS';
  256. //$replace_header[] = 'href="'.$data->integratedURL.'$2"';
  257. //convert relative links into absolute links
  258. $regex_header[] = '#(href|src)=("./|"/)(.*?)"#mS';
  259. $replace_header[] = '$1="'.$data->integratedURL.'$3"';
  260. $regex_header[] = '#var smf_scripturl = ["|\'](.*?)["|\'];#mS';
  261. $replace_header[] = 'var smf_scripturl = "'.$baseURLnoSef.'&";';
  262. //fix for URL redirects
  263. $regex_header[] = '#<meta http-equiv="refresh" content="(.*?)"(.*?)>#me';
  264. $replace_header[] = '$this->fixRedirect("$1","' . $data->baseURL . '")';
  265. }
  266. $data->header = preg_replace($regex_header, $replace_header, $data->header);
  267. }
  268. function fixUrl($q='',$baseURL,$fullURL)
  269. {
  270. //SMF uses semi-colons to seperate vars as well. Convert these to normal ampersands
  271. $q = str_replace(';','&amp;',$q);
  272. if ( strpos($q,'#') === 0 ) return $fullURL.$q;
  273. if (substr($baseURL, -1) != '/'){
  274. //non sef URls
  275. $q = str_replace('?', '&amp;', $q);
  276. $url = $baseURL . '&amp;jfile=' .$q;
  277. } else {
  278. $params = JFusionFactory::getParams($this->getJname());
  279. $sefmode = $params->get('sefmode');
  280. if ($sefmode==1) {
  281. $url = JFusionFunction::routeURL($q, JRequest::getInt('Itemid'));
  282. } else {
  283. //we can just append both variables
  284. $url = $baseURL . $q;
  285. }
  286. }
  287. return $url;
  288. }
  289. function fixAction($url, $extra, $baseURL)
  290. {
  291. //JError::raiseWarning(500, $url);
  292. $url = htmlspecialchars_decode($url);
  293. $Itemid = JRequest::getInt('Itemid');
  294. $extra = stripslashes( $extra );
  295. $url = str_replace(';','&amp;',$url);
  296. if (substr($baseURL, -1) != '/'){
  297. //non-SEF mode
  298. $url_details = parse_url($url);
  299. $url_variables = array();
  300. $jfile = basename($url_details['path']);
  301. if ( isset($url_details['query']) ) {
  302. parse_str($url_details['query'], $url_variables);
  303. $baseURL .= '&amp;'.$url_details['query'];
  304. }
  305. //set the correct action and close the form tag
  306. $replacement = 'action="'.$baseURL . '"' . $extra . '>';
  307. $replacement .= '<input type="hidden" name="jfile" value="'. $jfile . '"/>';
  308. $replacement .= '<input type="hidden" name="Itemid" value="'.$Itemid . '"/>';
  309. $replacement .= '<input type="hidden" name="option" value="com_jfusion"/>';
  310. } else {
  311. //check to see what SEF mode is selected
  312. $params = JFusionFactory::getParams($this->getJname());
  313. $sefmode = $params->get('sefmode');
  314. if ($sefmode==1) {
  315. //extensive SEF parsing was selected
  316. $url = JFusionFunction::routeURL($url, $Itemid);
  317. $replacement = 'action="'.$url . '"' . $extra . '>';
  318. return $replacement;
  319. } else {
  320. //simple SEF mode
  321. $url_details = parse_url($url);
  322. $url_variables = array();
  323. $jfile = basename($url_details['path']);
  324. if ( isset($url_details['query']) ) {
  325. parse_str($url_details['query'], $url_variables);
  326. $jfile .= '?'.$url_details['query'];
  327. }
  328. $replacement = 'action="'.$baseURL . $jfile.'"' . $extra . '>';
  329. }
  330. }
  331. unset($url_variables['option'],$url_variables['jfile'],$url_variables['Itemid']);
  332. //add any other variables
  333. /* Commented out because of problems with wrong variables being set
  334. if(is_array($url_variables)){
  335. foreach ($url_variables as $key => $value){
  336. $replacement .= '<input type="hidden" name="'. $key .'" value="'.$value . '"/>';
  337. }
  338. }
  339. */
  340. return $replacement;
  341. }
  342. function fixRedirect($url, $baseURL) {
  343. //JError::raiseWarning(500, $url);
  344. //split up the timeout from url
  345. $parts = explode(';url=', $url);
  346. $timeout = $parts[0];
  347. $uri = new JURI($parts[1]);
  348. $jfile = $uri->getPath();
  349. $jfile = basename($jfile);
  350. $query = $uri->getQuery(false);
  351. $fragment = $uri->getFragment();
  352. if (substr($baseURL, -1) != '/') {
  353. //non-SEF mode
  354. $redirectURL = $baseURL . '&amp;jfile=' . $jfile;
  355. if (!empty($query)) {
  356. $redirectURL.= '&amp;' . $query;
  357. }
  358. } else {
  359. //check to see what SEF mode is selected
  360. $params = JFusionFactory::getParams($this->getJname());
  361. $sefmode = $params->get('sefmode');
  362. if ($sefmode == 1) {
  363. //extensive SEF parsing was selected
  364. $redirectURL = $jfile;
  365. if (!empty($query)) {
  366. $redirectURL.= '?' . $query;
  367. }
  368. $redirectURL = JFusionFunction::routeURL($redirectURL, JRequest::getInt('Itemid'));
  369. } else {
  370. //simple SEF mode, we can just combine both variables
  371. $redirectURL = $baseURL . $jfile;
  372. if (!empty($query)) {
  373. $redirectURL.= '?' . $query;
  374. }
  375. }
  376. }
  377. if (!empty($fragment)) {
  378. $redirectURL .= "#$fragment";
  379. }
  380. $return = '<meta http-equiv="refresh" content="' . $timeout . ';url=' . $redirectURL . '">';
  381. //JError::raiseWarning(500, htmlentities($return));
  382. return $return;
  383. }
  384. function getPathWay()
  385. {
  386. $db = JFusionFactory::getDatabase($this->getJname());
  387. $pathway = array();
  388. list ($board_id ) = split ( '.' , JRequest::getVar('board'),1 );
  389. list ($topic_id ) = split ( '.' , JRequest::getVar('topic'),1 );
  390. list ($action ) = split ( ';' , JRequest::getVar('action'),1 );
  391. $msg = JRequest::getVar('msg');
  392. $query = 'SELECT id_topic,id_board, subject '.
  393. 'FROM #__messages '.
  394. 'WHERE id_topic = ' . $db->Quote($topic_id);
  395. $db->setQuery($query );
  396. $topic = $db->loadObject();
  397. if ($topic) {
  398. $board_id = $topic->id_board;
  399. }
  400. if ($board_id) {
  401. $boards = array();
  402. // Loop while the parent is non-zero.
  403. while ($board_id != 0)
  404. {
  405. $query = 'SELECT b.id_parent , b.id_board, b.id_cat, b.name , c.name as catname '.
  406. 'FROM #__boards AS b INNER JOIN #__categories AS c ON b.id_cat = c.id_cat '.
  407. 'WHERE id_board = ' . $db->Quote($board_id);
  408. $db->setQuery($query );
  409. $result = $db->loadObject();
  410. $board_id = 0;
  411. if ($result) {
  412. $board_id = $result->id_parent;
  413. $boards[] = $result;
  414. }
  415. }
  416. $boards = array_reverse($boards);
  417. $cat_id = 0;
  418. foreach($boards as $board) {
  419. $path = new stdClass();
  420. if ( $board->id_cat != $cat_id ) {
  421. $cat_id = $board->id_cat;
  422. $path->title = $board->catname;
  423. $path->url = 'index.php#'.$board->id_cat;
  424. $pathway[] = $path;
  425. $path = new stdClass();
  426. $path->title = $board->name;
  427. $path->url = 'index.php?board='.$board->id_board.'.0';
  428. } else {
  429. $path->title = $board->name;
  430. $path->url = 'index.php?board='.$board->id_board.'.0';
  431. }
  432. $pathway[] = $path;
  433. }
  434. }
  435. switch ($action) {
  436. case 'post':
  437. $path = new stdClass();
  438. if ( JRequest::getVar('board') ) {
  439. $path->title = 'Modify Toppic ( Start new topic )';
  440. $path->url = 'index.php?action=post&board='.$board_id.'.0';;
  441. } else if ( $msg ) {
  442. $path->title = 'Modify Toppic ( '.$topic->subject.' )';
  443. $path->url = 'index.php?action=post&topic='.$topic_id.'.msg'.$msg.'#msg'.$msg;
  444. } else {
  445. $path->title = 'Post reply ( Re: '.$topic->subject.' )';
  446. $path->url = 'index.php?action=post&topic='.$topic_id;
  447. }
  448. $pathway[] = $path;
  449. break;
  450. case 'pm':
  451. $path = new stdClass();
  452. $path->title = 'Personal Messages';
  453. $path->url = 'index.php?action=pm';
  454. $pathway[] = $path;
  455. $path = new stdClass();
  456. if ( JRequest::getVar('sa')=='send' ) {
  457. $path->title = 'New Message';
  458. $path->url = 'index.php?action=pm&sa=send';
  459. $pathway[] = $path;
  460. } elseif ( JRequest::getVar('sa')=='search' ) {
  461. $path->title = 'Search Messages';
  462. $path->url = 'index.php?action=pm&sa=search';
  463. $pathway[] = $path;
  464. } elseif ( JRequest::getVar('sa')=='prune' ) {
  465. $path->title = 'Prune Messages';
  466. $path->url = 'index.php?action=pm&sa=prune';
  467. $pathway[] = $path;
  468. } elseif ( JRequest::getVar('sa')=='manlabels' ) {
  469. $path->title = 'Manage Labels';
  470. $path->url = 'index.php?action=pm&sa=manlabels';
  471. $pathway[] = $path;
  472. } elseif ( JRequest::getVar('f')=='outbox' ) {
  473. $path->title = 'Outbox';
  474. $path->url = 'index.php?action=pm&f=outbox';
  475. $pathway[] = $path;
  476. } else {
  477. $path->title = 'Inbox';
  478. $path->url = 'index.php?action=pm';
  479. $pathway[] = $path;
  480. }
  481. break;
  482. case 'search2':
  483. $path = new stdClass();
  484. $path->title = 'Search';
  485. $path->url = 'index.php?action=search';
  486. $pathway[] = $path;
  487. $path = new stdClass();
  488. $path->title = 'Search Results';
  489. $path->url = 'index.php?action=search';
  490. $pathway[] = $path;
  491. break;
  492. case 'search':
  493. $path = new stdClass();
  494. $path->title = 'Search';
  495. $path->url = 'index.php?action=search';
  496. $pathway[] = $path;
  497. break;
  498. case 'unread':
  499. $path = new stdClass();
  500. $path->title = 'Recent Unread Topics';
  501. $path->url = 'index.php?action=unread';
  502. $pathway[] = $path;
  503. break;
  504. case 'unreadreplies':
  505. $path = new stdClass();
  506. $path->title = 'Updated Topics';
  507. $path->url = 'index.php?action=unreadreplies';
  508. $pathway[] = $path;
  509. break;
  510. default:
  511. if ( $topic_id ) {
  512. $path = new stdClass();
  513. $path->title = $topic->subject;
  514. $path->url = 'index.php?topic='.$topic_id;
  515. $pathway[] = $path;
  516. }
  517. }
  518. return $pathway;
  519. }
  520. function getPrivateMessageCounts($userid)
  521. {
  522. if ($userid) {
  523. // initialise some objects
  524. $db = JFusionFactory::getDatabase($this->getJname());
  525. // read unread count
  526. $db->setQuery('SELECT unreadMessages FROM #__members WHERE id_member = '.$userid);
  527. $unreadCount = $db->loadResult();
  528. // read total pm count
  529. $db->setQuery('SELECT instantMessages FROM #__members WHERE id_member = '.$userid);
  530. $totalCount = $db->loadResult();
  531. return array('unread' => $unreadCount, 'total' => $totalCount);
  532. }
  533. return array('unread' => 0, 'total' => 0);
  534. }
  535. function getAvatar($puser_id)
  536. {
  537. if ($puser_id) {
  538. // Get SMF Params and get an instance of the database
  539. $params = JFusionFactory::getParams($this->getJname());
  540. $db = JFusionFactory::getDatabase($this->getJname());
  541. // Load member params from database "mainly to get the avatar"
  542. $db->setQuery('SELECT * FROM #__members WHERE id_member='.$puser_id);
  543. $db->query();
  544. $result = $db->loadObject();
  545. if (!empty($result)) {
  546. $url = '';
  547. // SMF has a wierd way of holding attachments. Get instance of the attachments table
  548. $db->setQuery('SELECT * FROM #__attachments WHERE id_member='.$puser_id);
  549. $db->query();
  550. $attachment = $db->loadObject();
  551. // See if the user has a specific attachment ment for an avatar
  552. if(!empty($attachment) && $attachment->id_thumb == 0 && $attachment->id_msg == 0 && empty($result->avatar)) {
  553. $url = $params->get('source_url').'index.php?action=dlattach;attach='.$attachment->id_attach.';type=avatar';
  554. // If user didnt, check to see if the avatar specified in the first query is a url. If so use it.
  555. } else if(preg_match("/http(s?):\/\//",$result->avatar)){
  556. $url = $result->avatar;
  557. } else if($result->avatar) {
  558. // If the avatar specified in the first query is not a url but is a file name. Make it one
  559. $db->setQuery('SELECT * FROM #__settings WHERE variable = "avatar_url"');
  560. $avatarurl = $db->loadObject();
  561. // Check for trailing slash. If there is one DONT ADD ONE!
  562. if(substr($avatarurl->value, -1) == DS){
  563. $url = $avatarurl->value.$result->avatar;
  564. // I like redundancy. Recheck to see if there isnt a trailing slash. If there isnt one, add one.
  565. } else if(substr($avatarurl->value, -1) !== DS){
  566. $url = $avatarurl->value."/".$result->avatar;
  567. }
  568. }
  569. return $url;
  570. }
  571. }
  572. }
  573. /************************************************
  574. * For JFusion Search Plugin
  575. ***********************************************/
  576. function getSearchQueryColumns()
  577. {
  578. $columns = new stdClass();
  579. $columns->title = "p.subject";
  580. $columns->text = "p.body";
  581. return $columns;
  582. }
  583. function getSearchQuery(&$pluginParam)
  584. {
  585. //need to return threadid, postid, title, text, created, section
  586. $query = 'SELECT p.id_topic, p.id_msg, p.id_board, CASE WHEN p.subject = "" THEN CONCAT("Re: ",fp.subject) ELSE p.subject END AS title, p.body AS text,
  587. FROM_UNIXTIME(p.poster_time, "%Y-%m-%d %h:%i:%s") AS created,
  588. CONCAT_WS( "/", f.name, fp.subject ) AS section,
  589. t.num_views as hits
  590. FROM #__messages AS p
  591. INNER JOIN #__topics AS t ON t.id_topic = p.id_topic
  592. INNER JOIN #__messages AS fp ON fp.id_msg = t.id_first_msg
  593. INNER JOIN #__boards AS f on f.id_board = p.id_board';
  594. return $query;
  595. }
  596. /**
  597. * Add on a plugin specific clause;
  598. * @param object &$pluginParam custom plugin parameters in search.xml
  599. * @param $where reference to where clause already generated by search bot; add on plugin specific criteria
  600. */
  601. function getSearchCriteria(&$where, &$pluginParam, $ordering)
  602. {
  603. $db = JFusionFactory::getDatabase($this->getJname());
  604. $userPlugin = JFusionFactory::getUser($this->getJname());
  605. $user =& JFactory::getUser();
  606. $userid = $user->get('id');
  607. if ($userid) {
  608. $userlookup = JFusionFunction::lookupUser($this->getJname(),$userid,true);
  609. $existinguser = $userPlugin->getUser($userlookup);
  610. $group_id = $existinguser->group_id;
  611. } else {
  612. $group_id = '-1';
  613. }
  614. if ($pluginParam->get('forum_mode', 0)) {
  615. $forumids = $pluginParam->get('selected_forums', array());
  616. $selected_boards = " WHERE id_board IN (" . implode(',', $forumids) . ")";
  617. } else {
  618. $selected_boards = '';
  619. }
  620. $query = 'SELECT member_groups, id_board FROM #__boards' . $selected_boards;
  621. $db->setQuery($query);
  622. $boards = $db->loadObjectList();
  623. $list = array();
  624. foreach( $boards as $key => $value ) {
  625. $member_groups = explode( ',' , $value->member_groups );
  626. if ( in_array($group_id, $member_groups) || $group_id == 1) {
  627. $list[] = $value->id_board;
  628. }
  629. }
  630. //determine how to sort the results which is required for accurate results when a limit is placed
  631. switch ($ordering) {
  632. case 'oldest':
  633. $sort = 'p.poster_time ASC';
  634. break;
  635. case 'category':
  636. $sort = 'section ASC';
  637. break;
  638. case 'popular':
  639. $sort = 't.num_views DESC, p.poster_time DESC';
  640. case 'alpha':
  641. $sort = 'title ASC';
  642. break;
  643. case 'newest':
  644. default:
  645. $sort = 'p.poster_time DESC';
  646. break;
  647. }
  648. $where .= ' AND p.id_board IN ('.implode(',',$list).') ORDER BY ' . $sort;
  649. }
  650. function filterSearchResults(&$results, &$pluginParam)
  651. {
  652. $db =& JFusionFactory::getDatabase($this->getJname());
  653. $query = "SELECT value FROM #__settings WHERE variable='censor_vulgar'";
  654. $db->setQuery($query);
  655. $vulgar = $db->loadResult();
  656. $db =& JFusionFactory::getDatabase($this->getJname());
  657. $query = "SELECT value FROM #__settings WHERE variable='censor_proper'";
  658. $db->setQuery($query);
  659. $proper = $db->loadResult();
  660. $vulgar = explode ( ',' , $vulgar );
  661. $proper = explode ( ',' , $proper );
  662. foreach($results as $rkey => $result) {
  663. foreach( $vulgar as $key => $value ) {
  664. $results[$rkey]->subject = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->subject );
  665. $results[$rkey]->body = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->body );
  666. }
  667. }
  668. }
  669. function getSearchResultLink($post)
  670. {
  671. $forum = JFusionFactory::getForum($this->getJname());
  672. return $forum->getPostURL($post->id_topic,$post->id_msg);
  673. }
  674. /************************************************
  675. * Functions For JFusion Who's Online Module
  676. ***********************************************/
  677. /**
  678. * Returns a query to find online users
  679. * Make sure columns are named as userid, username, username_clean (if applicable), name (of user), and email
  680. **/
  681. function getOnlineUserQuery($limit, $usergroups = '')
  682. {
  683. $usergroup_query = "";
  684. if($usergroups!='') {
  685. if(is_array($usergroups)) {
  686. $usergroups = implode(',',$usergroups);
  687. $usergroup_query .= "AND (u.id_group IN ($usergroups) OR u.id_post_group IN ($usergroups)";
  688. foreach($usergroups AS $u) {
  689. $usergroup_query .= " OR FIND_IN_SET(" . intval($u) . ", u.additional_groups)";
  690. }
  691. $usergroup_query .= ")";
  692. } else {
  693. $usergroup_query .= "AND (u.id_group = $usergroups OR u.id_post_group = $usergroups OR FIND_IN_SET($usergroups, u.additional_groups))";
  694. }
  695. }
  696. $limiter = (!empty($limit)) ? "LIMIT 0,$limit" : '';
  697. return "SELECT DISTINCT u.id_member AS userid, u.member_name AS username, u.real_name AS name, u.email_address as email FROM #__members AS u INNER JOIN #__log_online AS s ON u.id_member = s.id_member WHERE s.id_member != 0 $usergroup_query $limiter";
  698. }
  699. /**
  700. * Returns number of guests
  701. * @return int
  702. */
  703. function getNumberOnlineGuests()
  704. {
  705. $db =& JFusionFactory::getDatabase($this->getJname());
  706. $query = "SELECT COUNT(DISTINCT(ip)) FROM #__log_online WHERE id_member = 0";
  707. $db->setQuery($query);
  708. return $db->loadResult();
  709. }
  710. /**
  711. * Returns number of logged in users
  712. * @return int
  713. */
  714. function getNumberOnlineMembers($usergroups = '', $total = 1)
  715. {
  716. $usergroup_query = "";
  717. if($usergroups!='' && empty($total)) {
  718. if(is_array($usergroups)) {
  719. $usergroups = implode(',',$usergroups);
  720. $usergroup_query .= "AND (u.id_group IN ($usergroups) OR u.id_post_group IN ($usergroups)";
  721. foreach($usergroups AS $u) {
  722. $usergroup_query .= " OR FIND_IN_SET(" . intval($u) . ", u.additional_groups)";
  723. }
  724. $usergroup_query .= ")";
  725. } else {
  726. $usergroup_query .= "AND (u.id_group = $usergroups OR u.id_post_group = $usergroups OR FIND_IN_SET($usergroups, u.additional_groups))";
  727. }
  728. }
  729. $db =& JFusionFactory::getDatabase($this->getJname());
  730. $query = "SELECT COUNT(DISTINCT(l.ip)) FROM #__log_online AS l JOIN #__members AS u ON l.id_member = u.id_member WHERE l.id_member != 0 $usergroup_query";
  731. $db->setQuery($query);
  732. return $db->loadResult();
  733. }
  734. function getActivityQuery($usedforums, $result_order, $result_limit)
  735. {
  736. $db = & JFusionFactory::getDatabase($this->getJname());
  737. $userPlugin = & JFusionFactory::getUser($this->getJname());
  738. $user =& JFactory::getUser();
  739. $userid = $user->get('id');
  740. if ($userid) {
  741. $userlookup = JFusionFunction::lookupUser($this->getJname(),$userid,true);
  742. $existinguser = $userPlugin->getUser($userlookup);
  743. $group_id = $existinguser->group_id;
  744. } else {
  745. $group_id = '-1';
  746. }
  747. $query = 'SELECT member_groups, id_board FROM #__boards';
  748. $db->setQuery($query);
  749. $boards = $db->loadObjectList();
  750. $list = array();
  751. foreach( $boards as $key => $value ) {
  752. $member_groups = explode( ',' , $value->member_groups );
  753. if ( in_array($group_id, $member_groups) || $group_id == 1) {
  754. $list[] = $value->id_board;
  755. }
  756. }
  757. $where = (!empty($usedforums)) ? ' WHERE b.id_board IN (' . $usedforums .') AND a.id_board IN ('.implode(',',$list).')' : ' WHERE a.id_board IN ('.implode(',',$list).')';
  758. $end = $result_order." LIMIT 0,".$result_limit;
  759. $numargs = func_num_args();
  760. if ($numargs > 3) {
  761. $filters = func_get_args();
  762. $i = 3;
  763. for ($i = 3; $i < $numargs; $i++) {
  764. if ($filters[$i][0] == 'userid') {
  765. $where.= ' HAVING userid = ' . $db->Quote($filters[$i][1]);
  766. }
  767. }
  768. }
  769. //setup the guest where clause to be used in union query
  770. $guest_where = (empty($where)) ? " WHERE b.id_member = 0" : " AND b.id_member = 0";
  771. $query = array(
  772. //LAT with first post info
  773. LAT . '0' =>
  774. "(SELECT a.id_topic AS threadid, a.id_last_msg AS postid, b.poster_name AS username, d.real_name AS name, b.id_member AS userid, b.subject AS subject, b.poster_time AS dateline, a.id_board as forumid, c.poster_time as last_post_date
  775. FROM `#__topics` as a
  776. INNER JOIN `#__messages` as b ON a.id_first_msg = b.id_msg
  777. INNER JOIN `#__messages` as c ON a.id_last_msg = c.id_msg
  778. INNER JOIN `#__members` as d ON b.id_member = d.id_member
  779. $where)
  780. UNION
  781. (SELECT a.id_topic AS threadid, a.id_last_msg AS postid, b.poster_name AS username, b.poster_name AS name, b.id_member AS userid, b.subject AS subject, b.poster_time AS dateline, a.id_board as forumid, c.poster_time as last_post_date
  782. FROM `#__topics` as a
  783. INNER JOIN `#__messages` as b ON a.id_first_msg = b.id_msg
  784. INNER JOIN `#__messages` as c ON a.id_last_msg = c.id_msg
  785. $where $guest_where)
  786. ORDER BY last_post_date $end",
  787. //LAT with latest post info
  788. LAT . '1' =>
  789. "(SELECT a.id_topic AS threadid, a.id_last_msg AS postid, b.poster_name AS username, d.real_name as name, b.id_member AS userid, c.subject AS subject, b.poster_time AS dateline, a.id_board as forumid, b.poster_time as last_post_date
  790. FROM `#__topics` as a
  791. INNER JOIN `#__messages` as b ON a.id_last_msg = b.id_msg
  792. INNER JOIN `#__messages` as c ON a.id_first_msg = c.id_msg
  793. INNER JOIN `#__members` as d ON b.id_member = d.id_member
  794. $where)
  795. UNION
  796. (SELECT a.id_topic AS threadid, a.id_last_msg AS postid, b.poster_name AS username, b.poster_name as name, b.id_member AS userid, c.subject AS subject, b.poster_time AS dateline, a.id_board as forumid, b.poster_time as last_post_date
  797. FROM `#__topics` as a
  798. INNER JOIN `#__messages` as b ON a.id_last_msg = b.id_msg
  799. INNER JOIN `#__messages` as c ON a.id_first_msg = c.id_msg
  800. $where $guest_where)
  801. ORDER BY last_post_date $end",
  802. //LCT
  803. LCT =>
  804. "(SELECT a.id_topic AS threadid, b.id_msg AS postid, b.poster_name AS username, d.real_name as name, b.id_member AS userid, b.subject AS subject, b.body, b.poster_time AS dateline, a.id_board as forumid, b.poster_time as topic_date
  805. FROM `#__topics` as a
  806. INNER JOIN `#__messages` as b ON a.id_first_msg = b.id_msg
  807. INNER JOIN `#__messages` as c ON a.id_last_msg = c.id_msg
  808. INNER JOIN `#__members` as d ON b.id_member = d.id_member
  809. $where)
  810. UNION
  811. (SELECT a.id_topic AS threadid, b.id_msg AS postid, b.poster_name AS username, b.poster_name as name, b.id_member AS userid, b.subject AS subject, b.body, b.poster_time AS dateline, a.id_board as forumid, b.poster_time as topic_date
  812. FROM `#__topics` as a
  813. INNER JOIN `#__messages` as b ON a.id_first_msg = b.id_msg
  814. INNER JOIN `#__messages` as c ON a.id_last_msg = c.id_msg
  815. $where $guest_where)
  816. ORDER BY topic_date $end",
  817. //LCP
  818. LCP => "
  819. (SELECT b.id_topic AS threadid, b.id_msg AS postid, b.poster_name AS username, d.real_name as name, b.id_member AS userid, b.subject AS subject, b.body, b.poster_time AS dateline, b.id_board as forumid, b.poster_time as last_post_date
  820. FROM `#__messages` as b
  821. INNER JOIN `#__members` as d ON b.id_member = d.id_member
  822. $where)
  823. UNION
  824. (SELECT b.id_topic AS threadid, b.id_msg AS postid, b.poster_name AS username, b.poster_name as name, b.id_member AS userid, b.subject AS subject, b.body, b.poster_time AS dateline, b.id_board as forumid, b.poster_time as last_post_date
  825. FROM `#__messages` as b
  826. $where $guest_where)
  827. ORDER BY last_post_date $end");
  828. return $query;
  829. }
  830. /**
  831. * Filter forums from a set of results sent in / useful if the plugin needs to restrict the forums visible to a user
  832. * @param $results set of results from query
  833. * @param $limit int limit results parameter as set in the module's params; used for plugins that cannot limit using a query limiter
  834. */
  835. function filterActivityResults(&$results, $limit=0)
  836. {
  837. $db =& JFusionFactory::getDatabase($this->getJname());
  838. $query = "SELECT value FROM #__settings WHERE variable='censor_vulgar'";
  839. $db->setQuery($query);
  840. $vulgar = $db->loadResult();
  841. $db =& JFusionFactory::getDatabase($this->getJname());
  842. $query = "SELECT value FROM #__settings WHERE variable='censor_proper'";
  843. $db->setQuery($query);
  844. $proper = $db->loadResult();
  845. $vulgar = explode ( ',' , $vulgar );
  846. $proper = explode ( ',' , $proper );
  847. foreach($results as $rkey => $result) {
  848. foreach( $vulgar as $key => $value ) {
  849. $results[$rkey]->subject = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->subject );
  850. if (isset($results[$rkey]->body)) {
  851. $results[$rkey]->body = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->body );
  852. }
  853. }
  854. }
  855. }
  856. /**
  857. * Function called by sh404sef for url building
  858. * @param array with titles for url
  859. * @param array global pointer to sh404sef remaning $_GET values from the url
  860. */
  861. function sh404sef(&$title,&$get)
  862. {
  863. if( isset($get['action'] ) ) {
  864. $title[] = $get['action'];
  865. shRemoveFromGETVarsList('action');
  866. }
  867. foreach( $get as $key => $value ) {
  868. $title[] = $key.$value;
  869. shRemoveFromGETVarsList($key);
  870. }
  871. }
  872. function callback($buffer) {
  873. $data = $this->callbackdata;
  874. $headers_list = headers_list();
  875. foreach($headers_list as $key => $value) {
  876. if(stripos($value,'location') === 0 ) {
  877. $regex_location[] = '#Location: '.$data->integratedURL.'index\.php\?(.*?)\z#Sise';
  878. $replace_location[] = '\'Location: \'.$this->fixUrlNoAmp("index.php?$1","'.$data->baseURL.'","'.$data->fullURL.'").\'\'';
  879. $regex_location[] = '#Location: '.$data->integratedURL.'index\.php\z#Sise';
  880. $replace_location[] = '\'Location: \'.$this->fixUrlNoAmp("index.php","'.$data->baseURL.'","'.$data->fullURL.'").\'\'';
  881. $value = preg_replace($regex_location, $replace_location, $value);
  882. header($value);
  883. return $buffer;
  884. } else if (stripos($value, 'Refresh') === 0) {
  885. $regex_location[] = '#Refresh: (.*?) URL=' . $data->integratedURL . 'index\.php\?(.*?)\z#Sise';
  886. $replace_location[] = '\'Refresh: $1 \'.$this->fixUrlNoAmp("index.php?$2","' . $data->baseURL . '","' . $data->fullURL . '").\'\'';
  887. $regex_location[] = '#Refresh: (.*?) URL=' . $data->integratedURL . 'index\.php\z#Sise';
  888. $replace_location[] = '\'Refresh: $1 \'.$this->fixUrlNoAmp("index.php","' . $data->baseURL . '","' . $data->fullURL . '").\'\'';
  889. $value = preg_replace($regex_location, $replace_location, $value);
  890. header($value);
  891. return $buffer;
  892. }
  893. }
  894. if ( $this->callbackbypass ) return $buffer;
  895. global $context;
  896. if ( isset($context['get_data']) ) {
  897. if ( $context['get_data'] && strpos( $context['get_data'] , 'jFusion_Route' ) ) {
  898. $buffer = str_replace ($context['get_data'],'?action=admin',$buffer);
  899. }
  900. }
  901. //fix for form actions
  902. $data->buffer = $buffer;
  903. ini_set('pcre.backtrack_limit',strlen($data->buffer)*2);
  904. $this->parseBuffer($data);
  905. if ( !strlen($data->header) || !strlen($data->body) ) {
  906. return $buffer;
  907. } else {
  908. $this->parseHeader($data);
  909. $this->parseBody($data);
  910. return '<html><head>'.$data->header.'</head><body>'.$data->body.'</body></html>';
  911. }
  912. }
  913. }