PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_jfusionplugins/smf/public.php

http://jfusion.googlecode.com/
PHP | 1225 lines | 914 code | 163 blank | 148 comment | 146 complexity | 3ce498713b7f48d1dbf4aae85e5faa2d 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_smf extends JFusionPublic{
  16. var $callbackdata = null;
  17. var $callbackbypass = null;
  18. function getJname()
  19. {
  20. return 'smf';
  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 getViewNewMessagesURL()
  35. {
  36. return 'index.php?action=unread';
  37. }
  38. function getProfileURL($uid)
  39. {
  40. return 'index.php?action=profile&u='.$uid;
  41. }
  42. function getPrivateMessageURL()
  43. {
  44. return 'index.php?action=pm';
  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. // Required to avoid a warning about a license violation even though this is not the case
  181. global $forum_version;
  182. // require_once(JFUSION_PLUGIN_PATH.DS.$this->getJname().DS.'hooks.php');
  183. $source_path = $params->get('source_path');
  184. if (substr($source_path, -1) == DS) {
  185. $index_file = $source_path .'index.php';
  186. } else {
  187. $index_file = $source_path .DS.'index.php';
  188. }
  189. if ( ! is_file($index_file) ) {
  190. JError::raiseWarning(500, 'The path to the SMF index file set in the component preferences does not exist');
  191. return null;
  192. }
  193. //set the current directory to SMF
  194. chdir($source_path);
  195. $this->callbackdata = $data;
  196. $this->callbackbypass = false;
  197. // Get the output
  198. ob_start(array($this, 'callback'));
  199. $h = ob_list_handlers();
  200. $rs = include_once($index_file);
  201. // die if popup
  202. if ( $action == 'findmember' || $action == 'helpadmin' || $action == 'spellcheck' || $action == 'requestmembers' || strpos($action ,'xml') !== false ) {
  203. exit();
  204. } else {
  205. $this->callbackbypass = true;
  206. }
  207. while( in_array( get_class($this).'::callback' , $h) ) {
  208. $data->buffer .= ob_get_contents();
  209. ob_end_clean();
  210. $h = ob_list_handlers();
  211. }
  212. //change the current directory back to Joomla.
  213. chdir(JPATH_SITE);
  214. // Log an error if we could not include the file
  215. if (!$rs) {
  216. JError::raiseWarning(500, 'Could not find SMF in the specified directory');
  217. }
  218. $document = JFactory::getDocument();
  219. $document->addScript(JFusionFunction::getJoomlaURL().JFUSION_PLUGIN_DIR_URL.'smf/js/script.js');
  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. //Jump Related fix
  233. $regex_body[] = '#<select name="jumpto" id="jumpto".*?">(.*?)</select>#mSsie';
  234. $replace_body[] = '$this->fixJump("$1")';
  235. $regex_body[] = '#<input (.*?) window.location.href = \'(.*?)\' \+ this.form.jumpto.options(.*?)>#mSsi';
  236. $replace_body[] = '<input $1 window.location.href = jf_scripturl + this.form.jumpto.options$3>';
  237. $regex_body[] = '#smf_scripturl \+ \"\?action#mSsi';
  238. $replace_body[] = 'jf_scripturl + "&action';
  239. $regex_body[] = '#<a (.*?) onclick="doQuote(.*?)>#mSsi';
  240. $replace_body[] = '<a $1 onclick="jfusion_doQuote$2>';
  241. $regex_body[] = '#<a (.*?) onclick="modify_msg(.*?)>#mSsi';
  242. $replace_body[] = '<a $1 onclick="jfusion_modify_msg$2>';
  243. $regex_body[] = '#modify_save\(#mSsi';
  244. $replace_body[] = 'jfusion_modify_save(';
  245. // Chaptcha fix
  246. $regex_body[] = '#\"'.$data->integratedURL.'(index.php\?)(action=verificationcode;rand=)(.*?)\"#sie';
  247. $replace_body[] = '\'"\'.$this->fixUrl("index.php?$2$3","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  248. //Fix auto member search
  249. $regex_body[] = '#toComplete\.source = \"'.$data->integratedURL.'(.*?)\"#sie';
  250. $replace_body[] = '\'toComplete.source = "\'.$this->fixUrlNoAmp("$1","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  251. $regex_body[] = '#bccComplete\.source = \"'.$data->integratedURL.'(.*?)\"#sie';
  252. $replace_body[] = '\'bccComplete.source = "\'.$this->fixUrlNoAmp("$1","'.$data->baseURL.'","'.$data->fullURL.'").\'"\'';
  253. $data->body = preg_replace($regex_body, $replace_body, $data->body);
  254. }
  255. function parseHeader(&$data)
  256. {
  257. static $regex_header, $replace_header;
  258. if ( ! $regex_header || ! $replace_header )
  259. {
  260. $params = JFusionFactory::getParams('joomla_int');
  261. $joomla_url = $params->get('source_url');
  262. $baseURLnoSef = 'index.php?option=com_jfusion&Itemid=' . JRequest::getInt('Itemid');
  263. if (substr($joomla_url, -1) == '/') $baseURLnoSef = $joomla_url . $baseURLnoSef;
  264. else $baseURLnoSef = $joomla_url . '/' . $baseURLnoSef;
  265. // Define our preg arrays
  266. $regex_header = array();
  267. $replace_header = array();
  268. //convert relative links into absolute links
  269. $regex_header[] = '#(href|src)=("./|"/)(.*?)"#mS';
  270. $replace_header[] = '$1="'.$data->integratedURL.'$3"';
  271. //$regex_header[] = '#(href|src)="(.*)"#mS';
  272. //$replace_header[] = 'href="'.$data->integratedURL.'$2"';
  273. //convert relative links into absolute links
  274. $regex_header[] = '#(href|src)=("./|"/)(.*?)"#mS';
  275. $replace_header[] = '$1="'.$data->integratedURL.'$3"';
  276. $regex_header[] = '#var smf_scripturl = ["|\'](.*?)["|\'];#mS';
  277. $replace_header[] = 'var smf_scripturl = "$1"; var jf_scripturl = "'.$baseURLnoSef.'";';
  278. //fix for URL redirects
  279. $regex_header[] = '#<meta http-equiv="refresh" content="(.*?)"(.*?)>#me';
  280. $replace_header[] = '$this->fixRedirect("$1","' . $data->baseURL . '")';
  281. }
  282. $data->header = preg_replace($regex_header, $replace_header, $data->header);
  283. }
  284. function fixUrl($q='',$baseURL,$fullURL)
  285. {
  286. //SMF uses semi-colons to seperate vars as well. Convert these to normal ampersands
  287. $q = str_replace(';','&amp;',$q);
  288. if ( strpos($q,'#') === 0 ) return $fullURL.$q;
  289. if (substr($baseURL, -1) != '/'){
  290. //non sef URls
  291. $q = str_replace('?', '&amp;', $q);
  292. $url = $baseURL . '&amp;jfile=' .$q;
  293. } else {
  294. $params = JFusionFactory::getParams($this->getJname());
  295. $sefmode = $params->get('sefmode');
  296. if ($sefmode==1) {
  297. $url = JFusionFunction::routeURL($q, JRequest::getInt('Itemid'));
  298. } else {
  299. //we can just append both variables
  300. $url = $baseURL . $q;
  301. }
  302. }
  303. return $url;
  304. }
  305. /**
  306. * Fix url with no amps
  307. *
  308. * @param string $q start url
  309. * @param string $baseURL base url
  310. * @param string $fullURL full url
  311. *
  312. * @return string url
  313. */
  314. function fixUrlNoAmp($q, $baseURL, $fullURL)
  315. {
  316. $url = $this->fixUrl($q, $baseURL, $fullURL);
  317. $url = str_replace('&amp;', '&', $url);
  318. return $url;
  319. }
  320. function fixAction($url, $extra, $baseURL)
  321. {
  322. //JError::raiseWarning(500, $url);
  323. $url = htmlspecialchars_decode($url);
  324. $Itemid = JRequest::getInt('Itemid');
  325. $extra = stripslashes( $extra );
  326. $url = str_replace(';','&amp;',$url);
  327. if (substr($baseURL, -1) != '/'){
  328. //non-SEF mode
  329. $url_details = parse_url($url);
  330. $url_variables = array();
  331. $jfile = basename($url_details['path']);
  332. if ( isset($url_details['query']) ) {
  333. parse_str($url_details['query'], $url_variables);
  334. $baseURL .= '&amp;'.$url_details['query'];
  335. }
  336. //set the correct action and close the form tag
  337. $replacement = 'action="'.$baseURL . '"' . $extra . '>';
  338. $replacement .= '<input type="hidden" name="jfile" value="'. $jfile . '"/>';
  339. $replacement .= '<input type="hidden" name="Itemid" value="'.$Itemid . '"/>';
  340. $replacement .= '<input type="hidden" name="option" value="com_jfusion"/>';
  341. } else {
  342. //check to see what SEF mode is selected
  343. $params = JFusionFactory::getParams($this->getJname());
  344. $sefmode = $params->get('sefmode');
  345. if ($sefmode==1) {
  346. //extensive SEF parsing was selected
  347. $url = JFusionFunction::routeURL($url, $Itemid);
  348. $replacement = 'action="'.$url . '"' . $extra . '>';
  349. return $replacement;
  350. } else {
  351. //simple SEF mode
  352. $url_details = parse_url($url);
  353. $url_variables = array();
  354. $jfile = basename($url_details['path']);
  355. if ( isset($url_details['query']) ) {
  356. parse_str($url_details['query'], $url_variables);
  357. $jfile .= '?'.$url_details['query'];
  358. }
  359. $replacement = 'action="'.$baseURL . $jfile.'"' . $extra . '>';
  360. }
  361. }
  362. unset($url_variables['option'],$url_variables['jfile'],$url_variables['Itemid']);
  363. //add any other variables
  364. /* Commented out because of problems with wrong variables being set
  365. if(is_array($url_variables)){
  366. foreach ($url_variables as $key => $value){
  367. $replacement .= '<input type="hidden" name="'. $key .'" value="'.$value . '"/>';
  368. }
  369. }
  370. */
  371. return $replacement;
  372. }
  373. function fixJump($content)
  374. {
  375. $find = '#<option value="[?](.*?)">(.*?)</option>#mSsi';
  376. $replace = '<option value="&$1">$2</option>';
  377. $content = preg_replace($find, $replace, $content);
  378. return '<select name="jumpto" id="jumpto" onchange="if (this.selectedIndex > 0 && this.options[this.selectedIndex].value && this.options[this.selectedIndex].value.length) window.location.href = jf_scripturl + this.options[this.selectedIndex].value;">'.$content.'</select>';
  379. }
  380. function fixRedirect($url, $baseURL) {
  381. //JError::raiseWarning(500, $url);
  382. //split up the timeout from url
  383. $parts = explode(';url=', $url);
  384. $timeout = $parts[0];
  385. $uri = new JURI($parts[1]);
  386. $jfile = $uri->getPath();
  387. $jfile = basename($jfile);
  388. $query = $uri->getQuery(false);
  389. $fragment = $uri->getFragment();
  390. if (substr($baseURL, -1) != '/') {
  391. //non-SEF mode
  392. $redirectURL = $baseURL . '&amp;jfile=' . $jfile;
  393. if (!empty($query)) {
  394. $redirectURL.= '&amp;' . $query;
  395. }
  396. } else {
  397. //check to see what SEF mode is selected
  398. $params = JFusionFactory::getParams($this->getJname());
  399. $sefmode = $params->get('sefmode');
  400. if ($sefmode == 1) {
  401. //extensive SEF parsing was selected
  402. $redirectURL = $jfile;
  403. if (!empty($query)) {
  404. $redirectURL.= '?' . $query;
  405. }
  406. $redirectURL = JFusionFunction::routeURL($redirectURL, JRequest::getInt('Itemid'));
  407. } else {
  408. //simple SEF mode, we can just combine both variables
  409. $redirectURL = $baseURL . $jfile;
  410. if (!empty($query)) {
  411. $redirectURL.= '?' . $query;
  412. }
  413. }
  414. }
  415. if (!empty($fragment)) {
  416. $redirectURL .= "#$fragment";
  417. }
  418. $return = '<meta http-equiv="refresh" content="' . $timeout . ';url=' . $redirectURL . '">';
  419. //JError::raiseWarning(500, htmlentities($return));
  420. return $return;
  421. }
  422. function getPathWay()
  423. {
  424. $db = JFusionFactory::getDatabase($this->getJname());
  425. $pathway = array();
  426. list ($board_id ) = split ( '.' , JRequest::getVar('board'),1 );
  427. list ($topic_id ) = split ( '.' , JRequest::getVar('topic'),1 );
  428. list ($action ) = split ( ';' , JRequest::getVar('action'),1 );
  429. $msg = JRequest::getVar('msg');
  430. $query = 'SELECT ID_TOPIC,ID_BOARD, subject '.
  431. 'FROM #__messages '.
  432. 'WHERE ID_TOPIC = ' . $db->Quote($topic_id);
  433. $db->setQuery($query );
  434. $topic = $db->loadObject();
  435. if ($topic) {
  436. $board_id = $topic->ID_BOARD;
  437. }
  438. if ($board_id) {
  439. $boards = array();
  440. // Loop while the parent is non-zero.
  441. while ($board_id != 0)
  442. {
  443. $query = 'SELECT b.ID_PARENT , b.ID_BOARD, b.ID_CAT, b.name , c.name as catname '.
  444. 'FROM #__boards AS b INNER JOIN #__categories AS c ON b.ID_CAT = c.ID_CAT '.
  445. 'WHERE ID_BOARD = ' . $db->Quote($board_id);
  446. $db->setQuery($query );
  447. $result = $db->loadObject();
  448. $board_id = 0;
  449. if ($result) {
  450. $board_id = $result->ID_PARENT;
  451. $boards[] = $result;
  452. }
  453. }
  454. $boards = array_reverse($boards);
  455. $cat_id = 0;
  456. foreach($boards as $board) {
  457. $path = new stdClass();
  458. if ( $board->ID_CAT != $cat_id ) {
  459. $cat_id = $board->ID_CAT;
  460. $path->title = $board->catname;
  461. $path->url = 'index.php#'.$board->ID_CAT;
  462. $pathway[] = $path;
  463. $path = new stdClass();
  464. $path->title = $board->name;
  465. $path->url = 'index.php?board='.$board->ID_BOARD.'.0';
  466. } else {
  467. $path->title = $board->name;
  468. $path->url = 'index.php?board='.$board->ID_BOARD.'.0';
  469. }
  470. $pathway[] = $path;
  471. }
  472. }
  473. switch ($action) {
  474. case 'post':
  475. $path = new stdClass();
  476. if ( JRequest::getVar('board') ) {
  477. $path->title = 'Modify Toppic ( Start new topic )';
  478. $path->url = 'index.php?action=post&board='.$board_id.'.0';;
  479. } else if ( $msg ) {
  480. $path->title = 'Modify Toppic ( '.$topic->subject.' )';
  481. $path->url = 'index.php?action=post&topic='.$topic_id.'.msg'.$msg.'#msg'.$msg;
  482. } else {
  483. $path->title = 'Post reply ( Re: '.$topic->subject.' )';
  484. $path->url = 'index.php?action=post&topic='.$topic_id;
  485. }
  486. $pathway[] = $path;
  487. break;
  488. case 'pm':
  489. $path = new stdClass();
  490. $path->title = 'Personal Messages';
  491. $path->url = 'index.php?action=pm';
  492. $pathway[] = $path;
  493. $path = new stdClass();
  494. if ( JRequest::getVar('sa')=='send' ) {
  495. $path->title = 'New Message';
  496. $path->url = 'index.php?action=pm&sa=send';
  497. $pathway[] = $path;
  498. } elseif ( JRequest::getVar('sa')=='search' ) {
  499. $path->title = 'Search Messages';
  500. $path->url = 'index.php?action=pm&sa=search';
  501. $pathway[] = $path;
  502. } elseif ( JRequest::getVar('sa')=='prune' ) {
  503. $path->title = 'Prune Messages';
  504. $path->url = 'index.php?action=pm&sa=prune';
  505. $pathway[] = $path;
  506. } elseif ( JRequest::getVar('sa')=='manlabels' ) {
  507. $path->title = 'Manage Labels';
  508. $path->url = 'index.php?action=pm&sa=manlabels';
  509. $pathway[] = $path;
  510. } elseif ( JRequest::getVar('f')=='outbox' ) {
  511. $path->title = 'Outbox';
  512. $path->url = 'index.php?action=pm&f=outbox';
  513. $pathway[] = $path;
  514. } else {
  515. $path->title = 'Inbox';
  516. $path->url = 'index.php?action=pm';
  517. $pathway[] = $path;
  518. }
  519. break;
  520. case 'search2':
  521. $path = new stdClass();
  522. $path->title = 'Search';
  523. $path->url = 'index.php?action=search';
  524. $pathway[] = $path;
  525. $path = new stdClass();
  526. $path->title = 'Search Results';
  527. $path->url = 'index.php?action=search';
  528. $pathway[] = $path;
  529. break;
  530. case 'search':
  531. $path = new stdClass();
  532. $path->title = 'Search';
  533. $path->url = 'index.php?action=search';
  534. $pathway[] = $path;
  535. break;
  536. case 'unread':
  537. $path = new stdClass();
  538. $path->title = 'Recent Unread Topics';
  539. $path->url = 'index.php?action=unread';
  540. $pathway[] = $path;
  541. break;
  542. case 'unreadreplies':
  543. $path = new stdClass();
  544. $path->title = 'Updated Topics';
  545. $path->url = 'index.php?action=unreadreplies';
  546. $pathway[] = $path;
  547. break;
  548. default:
  549. if ( $topic_id ) {
  550. $path = new stdClass();
  551. $path->title = $topic->subject;
  552. $path->url = 'index.php?topic='.$topic_id;
  553. $pathway[] = $path;
  554. }
  555. }
  556. return $pathway;
  557. }
  558. function getPrivateMessageCounts($userid)
  559. {
  560. if ($userid) {
  561. // initialise some objects
  562. $db = JFusionFactory::getDatabase($this->getJname());
  563. // read unread count
  564. $db->setQuery('SELECT unreadMessages FROM #__members WHERE ID_MEMBER = '.$userid);
  565. $unreadCount = $db->loadResult();
  566. // read total pm count
  567. $db->setQuery('SELECT instantMessages FROM #__members WHERE ID_MEMBER = '.$userid);
  568. $totalCount = $db->loadResult();
  569. return array('unread' => $unreadCount, 'total' => $totalCount);
  570. }
  571. return array('unread' => 0, 'total' => 0);
  572. }
  573. function getAvatar($puser_id)
  574. {
  575. if ($puser_id) {
  576. // Get SMF Params and get an instance of the database
  577. $params = JFusionFactory::getParams($this->getJname());
  578. $db = JFusionFactory::getDatabase($this->getJname());
  579. // Load member params from database "mainly to get the avatar"
  580. $db->setQuery('SELECT * FROM #__members WHERE ID_MEMBER='.$puser_id);
  581. $db->query();
  582. $result = $db->loadObject();
  583. if (!empty($result)) {
  584. $url = '';
  585. // SMF has a wierd way of holding attachments. Get instance of the attachments table
  586. $db->setQuery('SELECT * FROM #__attachments WHERE ID_MEMBER='.$puser_id);
  587. $db->query();
  588. $attachment = $db->loadObject();
  589. // See if the user has a specific attachment ment for an avatar
  590. if(!empty($attachment) && $attachment->ID_THUMB == 0 && $attachment->ID_MSG == 0 && empty($result->avatar)) {
  591. $url = $params->get('source_url').'index.php?action=dlattach;attach='.$attachment->ID_ATTACH.';type=avatar';
  592. // If user didnt, check to see if the avatar specified in the first query is a url. If so use it.
  593. } else if(preg_match("/http(s?):\/\//",$result->avatar)){
  594. $url = $result->avatar;
  595. } else if($result->avatar) {
  596. // If the avatar specified in the first query is not a url but is a file name. Make it one
  597. $db->setQuery('SELECT * FROM #__settings WHERE variable = "avatar_url"');
  598. $avatarurl = $db->loadObject();
  599. // Check for trailing slash. If there is one DONT ADD ONE!
  600. if(substr($avatarurl->value, -1) == DS){
  601. $url = $avatarurl->value.$result->avatar;
  602. // I like redundancy. Recheck to see if there isnt a trailing slash. If there isnt one, add one.
  603. } else if(substr($avatarurl->value, -1) !== DS){
  604. $url = $avatarurl->value."/".$result->avatar;
  605. }
  606. }
  607. return $url;
  608. }
  609. }
  610. }
  611. /************************************************
  612. * For JFusion Search Plugin
  613. ***********************************************/
  614. function getSearchQueryColumns()
  615. {
  616. $columns = new stdClass();
  617. $columns->title = "p.subject";
  618. $columns->text = "p.body";
  619. return $columns;
  620. }
  621. function getSearchQuery(&$pluginParam)
  622. {
  623. //need to return threadid, postid, title, text, created, section
  624. $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,
  625. FROM_UNIXTIME(p.posterTime, "%Y-%m-%d %h:%i:%s") AS created,
  626. CONCAT_WS( "/", f.name, fp.subject ) AS section,
  627. t.numViews AS hits
  628. FROM #__messages AS p
  629. INNER JOIN #__topics AS t ON t.ID_TOPIC = p.ID_TOPIC
  630. INNER JOIN #__messages AS fp ON fp.ID_MSG = t.ID_FIRST_MSG
  631. INNER JOIN #__boards AS f on f.ID_BOARD = p.ID_BOARD';
  632. return $query;
  633. }
  634. /**
  635. * Add on a plugin specific clause;
  636. * @param object &$pluginParam custom plugin parameters in search.xml
  637. * @param $where reference to where clause already generated by search bot; add on plugin specific criteria
  638. */
  639. function getSearchCriteria(&$where, &$pluginParam, $ordering)
  640. {
  641. $db = JFusionFactory::getDatabase($this->getJname());
  642. $userPlugin = JFusionFactory::getUser($this->getJname());
  643. $user =& JFactory::getUser();
  644. $userid = $user->get('id');
  645. if ($userid) {
  646. $userlookup = JFusionFunction::lookupUser($this->getJname(),$userid,true);
  647. $existinguser = $userPlugin->getUser($userlookup);
  648. $group_id = $existinguser->group_id;
  649. } else {
  650. $group_id = '-1';
  651. }
  652. if ($pluginParam->get('forum_mode', 0)) {
  653. $forumids = $pluginParam->get('selected_forums', array());
  654. $selected_boards = " WHERE ID_BOARD IN (" . implode(',', $forumids) . ")";
  655. } else {
  656. $selected_boards = '';
  657. }
  658. $query = 'SELECT memberGroups, ID_BOARD FROM #__boards' . $selected_boards;
  659. $db->setQuery($query);
  660. $boards = $db->loadObjectList();
  661. $list = array();
  662. foreach( $boards as $key => $value ) {
  663. $member_groups = explode( ',' , $value->memberGroups );
  664. if ( in_array($group_id, $member_groups) || $group_id == 1) {
  665. $list[] = $value->ID_BOARD;
  666. }
  667. }
  668. //determine how to sort the results which is required for accurate results when a limit is placed
  669. switch ($ordering) {
  670. case 'oldest':
  671. $sort = 'p.posterTime ASC';
  672. break;
  673. case 'category':
  674. $sort = 'section ASC';
  675. break;
  676. case 'popular':
  677. $sort = 't.numViews DESC, p.posterTime DESC';
  678. case 'alpha':
  679. $sort = 'title ASC';
  680. break;
  681. case 'newest':
  682. default:
  683. $sort = 'p.posterTime DESC';
  684. break;
  685. }
  686. $where .= ' AND p.ID_BOARD IN ('.implode(',',$list).') ORDER BY ' . $sort;
  687. }
  688. function filterSearchResults(&$results, &$pluginParam)
  689. {
  690. $db =& JFusionFactory::getDatabase($this->getJname());
  691. $query = "SELECT value FROM #__settings WHERE variable='censor_vulgar'";
  692. $db->setQuery($query);
  693. $vulgar = $db->loadResult();
  694. $db =& JFusionFactory::getDatabase($this->getJname());
  695. $query = "SELECT value FROM #__settings WHERE variable='censor_proper'";
  696. $db->setQuery($query);
  697. $proper = $db->loadResult();
  698. $vulgar = explode ( ',' , $vulgar );
  699. $proper = explode ( ',' , $proper );
  700. foreach($results as $rkey => $result) {
  701. foreach( $vulgar as $key => $value ) {
  702. $results[$rkey]->subject = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->subject );
  703. $results[$rkey]->body = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->body );
  704. }
  705. }
  706. }
  707. function getSearchResultLink($post)
  708. {
  709. $forum = JFusionFactory::getForum($this->getJname());
  710. return $forum->getPostURL($post->ID_TOPIC,$post->ID_MSG);
  711. }
  712. /************************************************
  713. * Functions For JFusion Who's Online Module
  714. ***********************************************/
  715. /**
  716. * Returns a query to find online users
  717. * Make sure columns are named as userid, username, username_clean (if applicable), name (of user), and email
  718. **/
  719. function getOnlineUserQuery($limit, $usergroups = '')
  720. {
  721. $usergroup_query = "";
  722. if($usergroups!='') {
  723. if(is_array($usergroups)) {
  724. $usergroups = implode(',',$usergroups);
  725. $usergroup_query .= "AND (u.ID_GROUP IN ($usergroups) OR u.ID_POST_GROUP IN ($usergroups)";
  726. foreach($usergroups AS $u) {
  727. $usergroup_query .= " OR FIND_IN_SET(" . intval($u) . ", u.additionalGroups)";
  728. }
  729. $usergroup_query .= ")";
  730. } else {
  731. $usergroup_query .= "AND (u.ID_GROUP = $usergroups OR u.ID_POST_GROUP = $usergroups OR FIND_IN_SET($usergroups, u.additionalGroups))";
  732. }
  733. }
  734. $limiter = (!empty($limit)) ? "LIMIT 0,$limit" : '';
  735. return "SELECT DISTINCT u.ID_MEMBER AS userid, u.memberName AS username, u.realName AS name, u.emailAddress 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";
  736. }
  737. /**
  738. * Returns number of guests
  739. * @return int
  740. */
  741. function getNumberOnlineGuests()
  742. {
  743. $db =& JFusionFactory::getDatabase($this->getJname());
  744. $query = "SELECT COUNT(DISTINCT(ip)) FROM #__log_online WHERE ID_MEMBER = 0";
  745. $db->setQuery($query);
  746. return $db->loadResult();
  747. }
  748. /**
  749. * Returns number of logged in users
  750. * @return int
  751. */
  752. function getNumberOnlineMembers($usergroups = '', $total = 1)
  753. {
  754. $db =& JFusionFactory::getDatabase($this->getJname());
  755. $usergroup_query = "";
  756. if($usergroups!='' && empty($total)) {
  757. if(is_array($usergroups)) {
  758. $usergroups = implode(',',$usergroups);
  759. $usergroup_query .= "AND (u.ID_GROUP IN ($usergroups) OR u.ID_POST_GROUP IN ($usergroups)";
  760. foreach($usergroups AS $u) {
  761. $usergroup_query .= " OR FIND_IN_SET(" . intval($u) . ", u.additionalGroups)";
  762. }
  763. $usergroup_query .= ")";
  764. } else {
  765. $usergroup_query .= "AND (u.ID_GROUP = $usergroups OR u.ID_POST_GROUP = $usergroups OR FIND_IN_SET($usergroups, u.additionalGroups))";
  766. }
  767. }
  768. $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";
  769. $db->setQuery($query);
  770. return $db->loadResult();
  771. }
  772. /************************************************
  773. * Functions For JFusion Activity Module
  774. ***********************************************/
  775. /**
  776. * Returns the an array with SQL statements used by the activity module
  777. * @return array
  778. */
  779. function getActivityQuery($usedforums, $result_order, $result_limit)
  780. {
  781. $db = & JFusionFactory::getDatabase($this->getJname());
  782. $userPlugin = & JFusionFactory::getUser($this->getJname());
  783. $user =& JFactory::getUser();
  784. $userid = $user->get('id');
  785. if ($userid) {
  786. $userlookup = JFusionFunction::lookupUser($this->getJname(),$userid,true);
  787. $existinguser = $userPlugin->getUser($userlookup);
  788. $group_id = $existinguser->group_id;
  789. } else {
  790. $group_id = '-1';
  791. }
  792. $query = 'SELECT memberGroups, ID_BOARD FROM #__boards';
  793. $db->setQuery($query);
  794. $boards = $db->loadObjectList();
  795. $list = array();
  796. foreach( $boards as $key => $value ) {
  797. $member_groups = explode( ',' , $value->memberGroups );
  798. if ( in_array($group_id, $member_groups) || $group_id == 1) {
  799. $list[] = $value->ID_BOARD;
  800. }
  801. }
  802. $where = (!empty($usedforums)) ? ' WHERE b.ID_BOARD IN (' . $usedforums .') AND a.ID_BOARD IN ('.implode(',',$list).')' : ' WHERE a.ID_BOARD IN ('.implode(',',$list).')';
  803. $end = $result_order." LIMIT 0,".$result_limit;
  804. $numargs = func_num_args();
  805. if ($numargs > 3) {
  806. $filters = func_get_args();
  807. $i = 3;
  808. for ($i = 3; $i < $numargs; $i++) {
  809. if ($filters[$i][0] == 'userid') {
  810. $where.= ' HAVING userid = ' . $db->Quote($filters[$i][1]);
  811. }
  812. }
  813. }
  814. //setup the guest where clause to be used in union query
  815. $guest_where = (empty($where)) ? " WHERE b.ID_MEMBER = 0" : " AND b.ID_MEMBER = 0";
  816. $query = array(
  817. //LAT with first post info
  818. LAT . '0' =>
  819. "(SELECT a.ID_TOPIC AS threadid, a.ID_LAST_MSG AS postid, b.posterName AS username, d.realName AS name, b.ID_MEMBER AS userid, b.subject AS subject, b.posterTime AS dateline, a.ID_BOARD as forumid, c.posterTime as last_post_date
  820. FROM `#__topics` as a
  821. INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG
  822. INNER JOIN `#__messages` as c ON a.ID_LAST_MSG = c.ID_MSG
  823. INNER JOIN `#__members` as d ON b.ID_MEMBER = d.ID_MEMBER
  824. $where)
  825. UNION
  826. (SELECT a.ID_TOPIC AS threadid, a.ID_LAST_MSG AS postid, b.posterName AS username, b.posterName AS name, b.ID_MEMBER AS userid, b.subject AS subject, b.posterTime AS dateline, a.ID_BOARD as forumid, c.posterTime as last_post_date
  827. FROM `#__topics` as a
  828. INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG
  829. INNER JOIN `#__messages` as c ON a.ID_LAST_MSG = c.ID_MSG
  830. $where $guest_where)
  831. ORDER BY last_post_date $end",
  832. //LAT with latest post info
  833. LAT . '1' =>
  834. "(SELECT a.ID_TOPIC AS threadid, a.ID_LAST_MSG AS postid, b.posterName AS username, d.realName as name, b.ID_MEMBER AS userid, c.subject AS subject, b.posterTime AS dateline, a.ID_BOARD as forumid, b.posterTime as last_post_date
  835. FROM `#__topics` as a
  836. INNER JOIN `#__messages` as b ON a.ID_LAST_MSG = b.ID_MSG
  837. INNER JOIN `#__messages` as c ON a.ID_FIRST_MSG = c.ID_MSG
  838. INNER JOIN `#__members` as d ON b.ID_MEMBER = d.ID_MEMBER
  839. $where)
  840. UNION
  841. (SELECT a.ID_TOPIC AS threadid, a.ID_LAST_MSG AS postid, b.posterName AS username, b.posterName as name, b.ID_MEMBER AS userid, c.subject AS subject, b.posterTime AS dateline, a.ID_BOARD as forumid, b.posterTime as last_post_date
  842. FROM `#__topics` as a
  843. INNER JOIN `#__messages` as b ON a.ID_LAST_MSG = b.ID_MSG
  844. INNER JOIN `#__messages` as c ON a.ID_FIRST_MSG = c.ID_MSG
  845. $where $guest_where)
  846. ORDER BY last_post_date $end",
  847. //LCT
  848. LCT =>
  849. "(SELECT a.ID_TOPIC AS threadid, b.ID_MSG AS postid, b.posterName AS username, d.realName as name, b.ID_MEMBER AS userid, b.subject AS subject, b.body, b.posterTime AS dateline, a.ID_BOARD as forumid, b.posterTime as topic_date
  850. FROM `#__topics` as a
  851. INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG
  852. INNER JOIN `#__messages` as c ON a.ID_LAST_MSG = c.ID_MSG
  853. INNER JOIN `#__members` as d ON b.ID_MEMBER = d.ID_MEMBER
  854. $where)
  855. UNION
  856. (SELECT a.ID_TOPIC AS threadid, b.ID_MSG AS postid, b.posterName AS username, b.posterName as name, b.ID_MEMBER AS userid, b.subject AS subject, b.body, b.posterTime AS dateline, a.ID_BOARD as forumid, b.posterTime as topic_date
  857. FROM `#__topics` as a
  858. INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG
  859. INNER JOIN `#__messages` as c ON a.ID_LAST_MSG = c.ID_MSG
  860. $where $guest_where)
  861. ORDER BY topic_date $end",
  862. //LCP
  863. LCP => "
  864. (SELECT b.ID_TOPIC AS threadid, b.ID_MSG AS postid, b.posterName AS username, d.realName as name, b.ID_MEMBER AS userid, b.subject AS subject, b.body, b.posterTime AS dateline, b.ID_BOARD as forumid, b.posterTime as last_post_date
  865. FROM `#__messages` as b
  866. INNER JOIN `#__members` as d ON b.ID_MEMBER = d.ID_MEMBER
  867. $where)
  868. UNION
  869. (SELECT b.ID_TOPIC AS threadid, b.ID_MSG AS postid, b.posterName AS username, b.posterName as name, b.ID_MEMBER AS userid, b.subject AS subject, b.body, b.posterTime AS dateline, b.ID_BOARD as forumid, b.posterTime as last_post_date
  870. FROM `#__messages` as b
  871. $where $guest_where)
  872. ORDER BY last_post_date $end");
  873. return $query;
  874. }
  875. /**
  876. * Filter forums from a set of results sent in / useful if the plugin needs to restrict the forums visible to a user
  877. * @param $results set of results from query
  878. * @param $limit int limit results parameter as set in the module's params; used for plugins that cannot limit using a query limiter
  879. */
  880. function filterActivityResults(&$results, $limit=0)
  881. {
  882. $db =& JFusionFactory::getDatabase($this->getJname());
  883. $query = "SELECT value FROM #__settings WHERE variable='censor_vulgar'";
  884. $db->setQuery($query);
  885. $vulgar = $db->loadResult();
  886. $db =& JFusionFactory::getDatabase($this->getJname());
  887. $query = "SELECT value FROM #__settings WHERE variable='censor_proper'";
  888. $db->setQuery($query);
  889. $proper = $db->loadResult();
  890. $vulgar = explode ( ',' , $vulgar );
  891. $proper = explode ( ',' , $proper );
  892. foreach($results as $rkey => $result) {
  893. foreach( $vulgar as $key => $value ) {
  894. $results[$rkey]->subject = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->subject );
  895. if (isset($results[$rkey]->body)) {
  896. $results[$rkey]->body = preg_replace ( '#\b'.$value.'\b#is' , $proper[$key] , $result->body );
  897. }
  898. }
  899. }
  900. }
  901. /**
  902. * Function called by sh404sef for url building
  903. * @param array with titles for url
  904. * @param array global pointer to sh404sef remaning $_GET values from the url
  905. */
  906. function sh404sef(&$title,&$get)
  907. {
  908. if( isset($get['action'] ) ) {
  909. $title[] = $get['action'];
  910. shRemoveFromGETVarsList('action');
  911. }
  912. foreach( $get as $key => $value ) {
  913. $title[] = $key.$value;
  914. shRemoveFromGETVarsList($key);
  915. }
  916. }
  917. function callback($buffer) {
  918. $data = $this->callbackdata;
  919. $headers_list = headers_list();
  920. foreach($headers_list as $key => $value) {
  921. if(stripos($value,'location') === 0 ) {
  922. $regex_location[] = '#Location: '.$data->integratedURL.'index\.php\?(.*?)\z#Sise';
  923. $replace_location[] = '\'Location: \'.$this->fixUrlNoAmp("index.php?$1","'.$data->baseURL.'","'.$data->fullURL.'").\'\'';
  924. $regex_location[] = '#Location: '.$data->integratedURL.'index\.php\z#Sise';
  925. $replace_location[] = '\'Location: \'.$this->fixUrlNoAmp("index.php","'.$data->baseURL.'","'.$data->fullURL.'").\'\'';
  926. $value = preg_replace($regex_location, $replace_location, $value);
  927. header($value);
  928. return $buffer;
  929. } else if (stripos($value, 'Refresh') === 0) {
  930. $regex_location[] = '#Refresh: (.*?) URL=' . $data->integratedURL . 'index\.php\?(.*?)\z#Sise';
  931. $replace_location[] = '\'Refresh: $1 \'.$this->fixUrlNoAmp("index.php?$2","' . $data->baseURL . '","' . $data->fullURL . '").\'\'';
  932. $regex_location[] = '#Refresh: (.*?) URL=' . $data->integratedURL . 'index\.php\z#Sise';
  933. $replace_location[] = '\'Refresh: $1 \'.$this->fixUrlNoAmp("index.php","' . $data->baseURL . '","' . $data->fullURL . '").\'\'';
  934. $value = preg_replace($regex_location, $replace_location, $value);
  935. header($value);
  936. return $buffer;
  937. }
  938. }
  939. if ( $this->callbackbypass ) return $buffer;
  940. global $context;
  941. if ( isset($context['get_data']) ) {
  942. if ( $context['get_data'] && strpos( $context['get_data'] , 'jFusion_Route' ) ) {
  943. $buffer = str_replace ($context['get_data'],'?action=admin',$buffer);
  944. }
  945. }
  946. //fix for form actions
  947. $data->buffer = $buffer;
  948. ini_set('pcre.backtrack_limit',strlen($data->buffer)*2);
  949. $this->parseBuffer($data);
  950. if ( !strlen($data->header) || !strlen($data->body) ) {
  951. return $buffer;
  952. } else {
  953. $this->parseHeader($data);
  954. $this->parseBody($data);
  955. return '<html><head>'.$data->header.'</head><body>'.$data->body.'</body></html>';
  956. }
  957. }
  958. function getCalender( ) {
  959. $out = array();
  960. $db = JFusionFactory::getDatabase($this->getJname());
  961. $params = JFusionFactory::getParams($this->getJname());
  962. $calender_itemid = $params->get('calender_itemid',0);
  963. $show_calender = $params->get('show_calender',0);
  964. $show_calender_holiday = $params->get('show_calender_holiday',0);
  965. $show_birthday = $params->get('show_birthday',0);
  966. $show_joined = $params->get('show_joined',0);
  967. $baseURL = JFusionFunction::getPluginURL($calender_itemid);
  968. if ($show_calender) {
  969. $query = 'SELECT startDate, endDate, title, subject, c.ID_MEMBER as userid, body '.
  970. 'FROM #__calendar as c INNER JOIN #__topics as t ON c.ID_TOPIC = t.ID_TOPIC INNER JOIN #__messages as m ON t.ID_FIRST_MSG = m.ID_MSG';
  971. $db->setQuery($query);
  972. $result = $db->loadObjectList();
  973. if (is_array($result)) {
  974. foreach($result as $key => $event) {
  975. $start = strtotime($event->startDate);
  976. $end = strtotime($event->endDate)+(3600*24);
  977. $e = new vevent(); // initiate a new EVENT
  978. $e->setProperty( 'categories', 'CALENDER_'.$this->getJname() );
  979. $e->setProperty( 'dtstart', date("Y",$start), date("m",$start), date("d",$start), 00, 00, 00 );
  980. $e->setProperty( 'dtend', date("Y",$end), date("m",$end), date("d",$end), 00, 00, 00 );
  981. $e->setProperty( 'description' , $event->body );
  982. $e->setProperty( 'summary' , $event->title );
  983. $e->setProperty( 'status' , 'CONFIRMED' );
  984. $e->setProperty( 'transp' , 'TRANSPARENT' );
  985. $out[] = $e;
  986. }
  987. }
  988. }
  989. if ($show_calender_holiday) {
  990. $query = 'SELECT eventDate, title '.
  991. 'FROM #__calendar_holidays ';
  992. $db->setQuery($query);
  993. $result = $db->loadObjectList();
  994. if (is_array($result)) {
  995. foreach($result as $key => $event) {
  996. $yearly = false;
  997. if ( strpos($event->eventDate, '0004' ) !== FALSE ) {
  998. $yearly = true;
  999. $event->eventDate = str_replace('0004','1990',$event->eventDate);
  1000. }
  1001. $start = strtotime($event->eventDate);
  1002. $end = $start+(3600*24);
  1003. if ($yearly) {
  1004. $end = $end-1;
  1005. }
  1006. $e = new vevent(); // initiate a new EVENT
  1007. $e->setProperty( 'categories', 'CALENDER_HOLLIDAY_'.$this->getJname() );
  1008. $e->setProperty( 'dtstart', date("Y",$start), date("m",$start), date("d",$start), 00, 00, 00 );
  1009. $e->setProperty( 'dtend', date("Y",$end), date("m",$end), date("d",$end), 00, 00, 00 );
  1010. $e->setProperty( 'summary' , $event->title );
  1011. $e->setProperty( 'status' , 'CONFIRMED' );
  1012. $e->setProperty( 'transp' , 'TRANSPARENT' );
  1013. if ($yearly ) {
  1014. $e->setProperty( 'rrule' , array( 'FREQ' => 'YEARLY' ));
  1015. }
  1016. $out[] = $e;
  1017. }
  1018. }
  1019. }
  1020. if ($show_birthday|| $show_joined) {
  1021. $query = 'SELECT ID_MEMBER , birthdate, memberName, is_activated, dateRegistered '.
  1022. 'FROM #__members '.
  1023. 'WHERE is_activated=1 AND birthdate!='.$db->Quote('0001-01-01');
  1024. $db->setQuery($query);
  1025. $result = $db->loadObjectList();
  1026. if (is_array($result)) {
  1027. foreach($result as $key => $event) {
  1028. if ($show_birthday) {
  1029. $start = strtotime($event->birthdate);
  1030. $end = $start+(3600*24)-1;
  1031. $e = new vevent(); // initiate a new EVENT
  1032. $e->setProperty( 'categories', 'CALENDER_BBIRTHDAY_'.$this->getJname() );
  1033. $e->setProperty( 'dtstart', date("Y",$start), date("m",$start), date("d",$start), 00, 00, 00 );
  1034. $e->setProperty( 'dtend', date("Y",$end), date("m",$end), date("d",$end), 00, 00, 00 );
  1035. $e->setProperty( 'summary' , 'Birthday: '. $event->memberName );
  1036. $url = $this->fixUrl($this->getProfileURL($event->ID_MEMBER),$baseURL,'');
  1037. $e->setProperty( 'description' , 'Profile: <a href="'.$url.'">'.$event->memberName.'</a>' ); // describe the event
  1038. $e->setProperty( 'status' , 'CONFIRMED' );
  1039. $e->setProperty( 'transp' , 'TRANSPARENT' );
  1040. $e->setProperty( 'rrule' , array( 'FREQ' => 'YEARLY' ));
  1041. $out[] = $e;
  1042. }
  1043. if ($show_joined) {
  1044. $start = $event->dateRegistered;
  1045. $end = $event->dateRegistered+(3600*24);
  1046. $e = new vevent(); // initiate a new EVENT
  1047. $e->setProperty( 'categories', 'CALENDER_BBIRTHDAY_'.$this->getJname() );
  1048. $e->setProperty( 'dtstart', date("Y",$start), date("m",$start), date("d",$start), 00, 00, 00 );
  1049. $e->setProperty( 'dtend', date("Y",$end), date("m",$end), date("d",$end), 00, 00, 00 );
  1050. $e->setProperty( 'summary' , 'Joined: '. $event->memberName );
  1051. $url = $this->fixUrl($this->getProfileURL($event->ID_MEMBER),$baseURL,'');
  1052. $e->setProperty( 'description' , 'Profile: <a href="'.$url.'">'.$event->memberName.'</a>' ); // describe the event
  1053. $e->setProperty( 'status' , 'CONFIRMED' );
  1054. $e->setProperty( 'transp' , 'TRANSPARENT' );
  1055. $out[] = $e;
  1056. }
  1057. }
  1058. }
  1059. }
  1060. return $out;
  1061. }
  1062. }