PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/site/tmp/install_4a925da139185/admin/plugins/smf/forum.php

https://bitbucket.org/manchas/jrobotz
PHP | 656 lines | 450 code | 89 blank | 117 comment | 68 complexity | 75e68d1b1fd2e3395fd38ce8a1d32f39 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, 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 Forum Class for SMF 1.1.x
  12. * For detailed descriptions on these functions please check the model.abstractforum.php
  13. * @package JFusion_SMF
  14. */
  15. class JFusionForum_smf extends JFusionForum
  16. {
  17. function getJname()
  18. {
  19. return 'smf';
  20. }
  21. function getThreadURL($threadid)
  22. {
  23. return 'index.php?topic=' . $threadid;
  24. }
  25. function getPostURL($threadid, $postid)
  26. {
  27. return 'index.php?topic=' . $threadid . '.msg'.$postid.'#msg' . $postid;
  28. }
  29. function getProfileURL($uid)
  30. {
  31. return 'index.php?action=profile&u='.$uid;
  32. }
  33. function getPrivateMessageURL()
  34. {
  35. return 'index.php?action=pm';
  36. }
  37. function getViewNewMessagesURL()
  38. {
  39. return 'index.php?action=unread';
  40. }
  41. function getActivityQuery($usedforums, $result_order, $result_limit)
  42. {
  43. $where = (!empty($usedforums)) ? ' WHERE a.ID_BOARD IN (' . $usedforums .')' : '';
  44. $end = $result_order." LIMIT 0,".$result_limit;
  45. $query = array(
  46. //LAT with first post info
  47. LAT.'0' => "SELECT a.ID_TOPIC AS threadid, a.ID_LAST_MSG AS postid, b.posterName AS username, b.ID_MEMBER AS userid, b.subject AS subject, b.posterTime AS dateline FROM `#__topics` as a INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG INNER JOIN `#__messages` AS c ON a.ID_LAST_MSG = c.ID_MSG $where ORDER BY c.posterTime $end",
  48. //LAT with latest post info
  49. LAT.'1' => "SELECT a.ID_TOPIC AS threadid, a.ID_LAST_MSG AS postid, c.posterName AS username, c.ID_MEMBER AS userid, b.subject AS subject, c.posterTime AS dateline FROM `#__topics` as a INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG INNER JOIN `#__messages` AS c ON a.ID_LAST_MSG = c.ID_MSG $where ORDER BY c.posterTime $end",
  50. LCT => "SELECT a.ID_TOPIC AS threadid, b.ID_MSG AS postid, b.posterName AS username, b.ID_MEMBER AS userid, b.subject AS subject, b.body, b.posterTime AS dateline FROM `#__topics` as a INNER JOIN `#__messages` as b ON a.ID_FIRST_MSG = b.ID_MSG $where ORDER BY b.posterTime $end",
  51. LCP => "SELECT ID_TOPIC AS threadid, ID_MSG AS postid, posterName AS username, ID_MEMBER AS userid, subject AS subject, body, posterTime AS dateline FROM `#__messages` " . str_replace('a.ID_BOARD','ID_BOARD',$where) . " ORDER BY posterTime $end"
  52. );
  53. return $query;
  54. }
  55. function getForumList()
  56. {
  57. // initialise some objects
  58. $db = JFusionFactory::getDatabase($this->getJname());
  59. $query = 'SELECT ID_BOARD as id, name FROM #__boards';
  60. $db->setQuery($query );
  61. //getting the results
  62. return $db->loadObjectList();
  63. }
  64. function getPrivateMessageCounts($userid)
  65. {
  66. if ($userid) {
  67. // initialise some objects
  68. $db = JFusionFactory::getDatabase($this->getJname());
  69. // read unread count
  70. $db->setQuery('SELECT unreadMessages FROM #__members WHERE ID_MEMBER = '.$userid);
  71. $unreadCount = $db->loadResult();
  72. // read total pm count
  73. $db->setQuery('SELECT instantMessages FROM #__members WHERE ID_MEMBER = '.$userid);
  74. $totalCount = $db->loadResult();
  75. return array('unread' => $unreadCount, 'total' => $totalCount);
  76. }
  77. return array('unread' => 0, 'total' => 0);
  78. }
  79. function getAvatar($puser_id)
  80. {
  81. if ($puser_id) {
  82. // Get SMF Params and get an instance of the database
  83. $params = JFusionFactory::getParams($this->getJname());
  84. $db = JFusionFactory::getDatabase($this->getJname());
  85. // Load member params from database "mainly to get the avatar"
  86. $db->setQuery('SELECT * FROM #__members WHERE ID_MEMBER='.$puser_id);
  87. $db->query();
  88. $result = $db->loadObject();
  89. if (!empty($result)) {
  90. $url = '';
  91. // SMF has a wierd way of holding attachments. Get instance of the attachments table
  92. $db->setQuery('SELECT * FROM #__attachments WHERE ID_MEMBER='.$puser_id);
  93. $db->query();
  94. $attachment = $db->loadObject();
  95. // See if the user has a specific attachment ment for an avatar
  96. if(!empty($attachment) && $attachment->ID_THUMB == 0 && $attachment->ID_MSG == 0 && empty($result->avatar)) {
  97. $url = $params->get('source_url').'index.php?action=dlattach;attach='.$attachment->ID_ATTACH.';type=avatar';
  98. // If user didnt, check to see if the avatar specified in the first query is a url. If so use it.
  99. } else if(preg_match("/http(s?):\/\//",$result->avatar)){
  100. $url = $result->avatar;
  101. } else if($result->avatar) {
  102. // If the avatar specified in the first query is not a url but is a file name. Make it one
  103. $db->setQuery('SELECT * FROM #__settings WHERE variable = "avatar_url"');
  104. $avatarurl = $db->loadObject();
  105. // Check for trailing slash. If there is one DONT ADD ONE!
  106. if(substr($avatarurl->value, -1) == DS){
  107. $url = $avatarurl->value.$result->avatar;
  108. // I like redundancy. Recheck to see if there isnt a trailing slash. If there isnt one, add one.
  109. } else if(substr($avatarurl->value, -1) !== DS){
  110. $url = $avatarurl->value."/".$result->avatar;
  111. }
  112. }
  113. return $url;
  114. }
  115. }
  116. }
  117. function checkThreadExists(&$dbparams, &$contentitem, &$existingthread, $forumid)
  118. {
  119. $status = array();
  120. $status['debug'] = array();
  121. $status['error'] = array();
  122. //set the timezone to UTC
  123. date_default_timezone_set('UTC');
  124. if(!empty($existingthread))
  125. {
  126. //check to make sure the thread still exists in the software
  127. $jdb = & JFusionFactory::getDatabase($this->getJname());
  128. $query = "SELECT COUNT(*) FROM #__messages WHERE ID_BOARD = {$existingthread->forumid} AND ID_TOPIC = {$existingthread->threadid} AND ID_MSG = {$existingthread->postid}";
  129. $jdb->setQuery($query);
  130. if($jdb->loadResult()==0)
  131. {
  132. //the thread no longer exists in the software!! recreate it
  133. $this->createThread($dbparams, $contentitem, $forumid, $status);
  134. if (empty($status['error'])) {
  135. $status['action'] = 'created';
  136. }
  137. return $status;
  138. }
  139. elseif(strtotime($contentitem->modified) > $existingthread->modified)
  140. {
  141. //update the post if the content has been updated
  142. $this->updateThread($dbparams, $existingthread, $contentitem, $status);
  143. if (empty($status['error'])) {
  144. $status['action'] = 'updated';
  145. }
  146. return $status;
  147. }
  148. }
  149. else
  150. {
  151. //thread does not exist; create it
  152. $this->createThread($dbparams, $contentitem, $forumid, $status);
  153. if (empty($status['error'])) {
  154. $status['action'] = 'created';
  155. }
  156. return $status;
  157. }
  158. }
  159. /**
  160. * Creates new thread and posts first post
  161. * @param object with discussion bot parameters
  162. * @param object $contentitem object containing content information
  163. * @param int Id of forum to create thread
  164. * @param array $status contains errors and status of actions
  165. */
  166. function createThread(&$dbparams, &$contentitem, $forumid, &$status)
  167. {
  168. //setup some variables
  169. $userid = $dbparams->get("default_userid");
  170. $firstPost = $dbparams->get("first_post");
  171. $jdb =& JFusionFactory::getDatabase($this->getJname());
  172. $subject = trim(strip_tags($contentitem->title));
  173. //set what should be posted as the first post
  174. if($firstPost=="articleLink") {
  175. //create link
  176. $forumText = $dbparams->get("first_post_link_text");
  177. if($dbparams->get("first_post_link_type") == 'image') {
  178. $forumText = "<img src='$forumText'>";
  179. }
  180. $text = $this->prepareText(JFusionFunction::createJoomlaArticleURL($contentitem,$forumText));
  181. } elseif($firstPost=="articleIntro") {
  182. //prepare the text for posting
  183. $text = $this->prepareText($contentitem->introtext)."</br></br>";
  184. //create link
  185. $forumText = $dbparams->get("first_post_link_text");
  186. if($dbparams->get("first_post_link_type") == 'image') {
  187. $forumText = "<img src='$forumText'>";
  188. }
  189. $text .= $this->prepareText(JFusionFunction::createJoomlaArticleURL($contentitem,$forumText));
  190. } else {
  191. //prepare the text for posting
  192. $text = $this->prepareText($contentitem->introtext . $contentitem->fulltext);
  193. }
  194. //the user information
  195. $query = "SELECT memberName, emailAddress FROM #__members WHERE ID_MEMBER = '$userid'";
  196. $jdb->setQuery($query);
  197. $smfUser = $jdb->loadObject();
  198. $timestamp = $dbparams->get('use_content_created_date',false) ? strtotime($contentitem->created) : time();
  199. $topic_row = new stdClass();
  200. $topic_row->isSticky = 0;
  201. $topic_row->ID_BOARD = $forumid;
  202. $topic_row->ID_FIRST_MSG = $topic_row->ID_LAST_MSG = 0;
  203. $topic_row->ID_MEMBER_STARTED = $topic_row->ID_MEMBER_UPDATED = $userid;
  204. $topic_row->ID_POLL = 0;
  205. $topic_row->numReplies = 0;
  206. $topic_row->numViews = 0;
  207. $topic_row->locked = 0;
  208. if(!$jdb->insertObject('#__topics', $topic_row, 'ID_TOPIC' )){
  209. $status['error'] = $jdb->stderr();
  210. return;
  211. }
  212. $topicid = $jdb->insertid();
  213. $post_row = new stdClass();
  214. $post_row->ID_BOARD = $forumid;
  215. $post_row->ID_TOPIC = $topicid;
  216. $post_row->posterTime = $timestamp;
  217. $post_row->ID_MEMBER = $userid;
  218. $post_row->ID_MSG_MODIFIED = $userid;
  219. $post_row->subject = $subject;
  220. $post_row->posterName = $smfUser->memberName;
  221. $post_row->posterEmail = $smfUser->emailAddress;
  222. $post_row->posterIP = $_SERVER["REMOTE_ADDR"];
  223. $post_row->smileysEnabled = 1;
  224. $post_row->modifiedTime = 0;
  225. $post_row->modifiedName = '';
  226. $post_row->body = $text;
  227. $post_row->icon = 'xx';
  228. if(!$jdb->insertObject('#__messages', $post_row, 'ID_MSG')) {
  229. $status['error'] = $jdb->stderr();
  230. return;
  231. }
  232. $postid = $jdb->insertid();
  233. $topic_row = new stdClass();
  234. $topic_row->ID_FIRST_MSG = $postid;
  235. $topic_row->ID_LAST_MSG = $postid;
  236. $topic_row->ID_TOPIC = $topicid;
  237. if(!$jdb->updateObject('#__topics', $topic_row, 'ID_TOPIC' )) {
  238. $status['error'] = $jdb->stderr();
  239. return;
  240. }
  241. $forum_stats = new stdClass();
  242. $forum_stats->ID_BOARD = $forumid;
  243. $query = "SELECT m.posterTime FROM #__messages AS m INNER JOIN #__boards AS b ON b.ID_LAST_MSG = m.ID_MSG WHERE b.ID_BOARD = $forumid";
  244. $jdb->setQuery($query);
  245. $lastPostTime = (int) $jdb->loadResult();
  246. if($dbparams->get('use_content_created_date',false)) {
  247. //only update the last post for the board if it really is newer
  248. $updateLastPost = ($timestamp > $lastPostTime) ? true : false;
  249. } else {
  250. $updateLastPost = true;
  251. }
  252. if($updateLastPost) {
  253. $forum_stats->ID_LAST_MSG = $postid;
  254. $forum_stats->ID_MSG_UPDATED = $postid;
  255. }
  256. $query = "SELECT numTopics, numPosts FROM #__boards WHERE ID_BOARD = $forumid";
  257. $jdb->setQuery($query);
  258. $num = $jdb->loadObject();
  259. $forum_stats->numPosts = $num->numPosts +1;
  260. $forum_stats->numTopics = $num->numTopics +1;
  261. if(!$jdb->updateObject('#__boards', $forum_stats, 'ID_BOARD' )) {
  262. $status['error'] = $jdb->stderr();
  263. return;
  264. }
  265. if(!empty($topicid) && !empty($postid)) {
  266. //save the threadid to the lookup table
  267. JFusionFunction::updateForumLookup($contentitem->id, $forumid, $topicid, $postid, $this->getJname());
  268. }
  269. }
  270. /**
  271. * Updates information in a specific thread/post
  272. * @param object with discussion bot parameters
  273. * @param object with existing thread info
  274. * @param object $contentitem object containing content information
  275. * @param array $status contains errors and status of actions
  276. */
  277. function updateThread(&$dbparams, &$existingthread, &$contentitem, &$status)
  278. {
  279. $threadid =& $existingthread->threadid;
  280. $forumid =& $existingthread->forumid;
  281. $postid =& $existingthread->postid;
  282. //setup some variables
  283. $firstPost = $dbparams->get("first_post");
  284. $jdb =& JFusionFactory::getDatabase($this->getJname());
  285. $subject = trim(strip_tags($contentitem->title));
  286. //set what should be posted as the first post
  287. if($firstPost=="articleLink") {
  288. //create link
  289. $forumText = $dbparams->get("first_post_link_text");
  290. if($dbparams->get("first_post_link_type") == 'image') {
  291. $forumText = "<img src='$forumText'>";
  292. }
  293. $text = $this->prepareText(JFusionFunction::createJoomlaArticleURL($contentitem,$forumText));
  294. } elseif($firstPost=="articleIntro") {
  295. //prepare the text for posting
  296. $text = $this->prepareText($contentitem->introtext)."</br></br>";
  297. //create link
  298. $forumText = $dbparams->get("first_post_link_text");
  299. if($dbparams->get("first_post_link_type") == 'image') {
  300. $forumText = "<img src='$forumText'>";
  301. }
  302. $text .= $this->prepareText(JFusionFunction::createJoomlaArticleURL($contentitem,$forumText));
  303. } else {
  304. //prepare the text for posting
  305. $text = $this->prepareText($contentitem->introtext . $contentitem->fulltext);
  306. }
  307. $timestamp = time();
  308. $userid = $dbparams->get('default_user');
  309. $query = "SELECT memberName FROM #__members WHERE ID_MEMBER = '$userid'";
  310. $jdb->setQuery($query);
  311. $smfUser = $jdb->loadObject();
  312. $post_row = new stdClass();
  313. $post_row->subject = $subject;
  314. $post_row->body = $text;
  315. $post_row->modifiedTime = $timestamp;
  316. $post_row->modifiedName = $smfUser->memberName;
  317. $post_row->ID_MSG_MODIFIED = $userid;
  318. $post_row->ID_MSG = $postid;
  319. if(!$jdb->updateObject('#__messages', $post_row, 'ID_MSG')) {
  320. $status['error'] = $jdb->stderr();
  321. } else {
  322. //update the lookup table
  323. JFusionFunction::updateForumLookup($contentitem->id, $forumid, $threadid, $postid, $this->getJname());
  324. }
  325. }
  326. /**
  327. * Returns HTML of a quick reply
  328. * @param $dbparams object with discussion bot parameters
  329. * @param boolean $showGuestInputs toggles whether to show guest inputs or not
  330. * @return string of html
  331. */
  332. function createQuickReply(&$dbparams,$showGuestInputs)
  333. {
  334. $html = '';
  335. if($showGuestInputs) {
  336. $html .= "<table><tr><td>".JText::_('USERNAME') .":</td><td><input name='guest_username' value='' class='inputbox'/></td></tr>";
  337. $html .= "<tr><td>".JText::_('EMAIL') ."</td><td><input name='guest_email' value='' class='inputbox'/></td></tr>";
  338. $question = $dbparams->get('captcha_question');
  339. if(!empty($question)) {
  340. $html .= "<tr><td>$question:</td><td><input name='captcha_answer' value='' class='inputbox'/></td></tr>";
  341. }
  342. $html .= "</table><br>";
  343. }
  344. $html .= "<textarea name='quickReply' class='inputbox'></textarea><br>";
  345. $html .= "<div style='width:100%; text-align:right;'><input type='submit' value='Submit'/></div>";
  346. return $html;
  347. }
  348. /**
  349. * Creates a post from the quick reply
  350. * @param object with discussion bot parameters
  351. * @param $ids stdClass with thread id ($ids->threadid) and first post id ($ids->postid)
  352. * @param $contentitem object of content item
  353. * @param $userinfo object info of the forum user
  354. * @return array with status
  355. */
  356. function createPost(&$dbparams, &$ids, &$contentitem, &$userinfo)
  357. {
  358. $status = array();
  359. $status["error"] = false;
  360. if($userinfo->guest) {
  361. $captcha_answer = JRequest::getVar('captcha_answer', '', 'POST');
  362. if($captcha_answer != $dbparams->get('captcha_answer')) {
  363. $status["error"][] = JText::_('CAPTCHA_INCORRECT');
  364. return $status;
  365. } else {
  366. $userinfo->username = JRequest::getVar('guest_username', '', 'POST');
  367. $userinfo->email = JRequest::getVar('guest_email', '', 'POST');
  368. $userinfo->userid = 0;
  369. $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
  370. if(empty($userinfo->username) || empty($userinfo->email) || !eregi($pattern, $userinfo->email)) {
  371. $status['error'][] = JTEXT::_('GUEST_FIELDS_MISSING');
  372. return $status;
  373. } else {
  374. //check to see if user exists to prevent user hijacking
  375. $JFusionUser = JFusionFactory::getUser($this->getJname());
  376. define('OVERRIDE_IDENTIFIER',3);
  377. $existinguser = $JFusionUser->getUser($userinfo->username);
  378. if(!empty($existinguser)) {
  379. $status["error"][] = JText::_('USERNAME_IN_USE');
  380. return $status;
  381. }
  382. //check for email
  383. $existinguser = $JFusionUser->getUser($userinfo->email);
  384. if(!empty($existinguser)) {
  385. $status["error"][] = JText::_('EMAIL_IN_USE');
  386. return $status;
  387. }
  388. }
  389. }
  390. }
  391. //setup some variables
  392. $userid = $userinfo->userid;
  393. $jdb =& JFusionFactory::getDatabase($this->getJname());
  394. $text = JRequest::getVar('quickReply', false, 'POST');
  395. if(!empty($text)) {
  396. $text = $this->prepareText($text);
  397. //get some topic information
  398. $where = "WHERE t.ID_TOPIC = {$ids->threadid} AND m.ID_MSG = t.ID_FIRST_MSG";
  399. $query = "SELECT t.ID_FIRST_MSG , t.numReplies, m.subject FROM `#__messages` as m INNER JOIN `#__topics` as t ON t.ID_TOPIC = m.ID_TOPIC $where";
  400. $jdb->setQuery($query);
  401. $topic = $jdb->loadObject();
  402. //the user information
  403. if($userinfo->guest) {
  404. $smfUser = new stdClass();
  405. $smfUser->memberName = $userinfo->username;
  406. $smfUser->emailAddress = $userinfo->email;
  407. } else {
  408. $query = "SELECT memberName,emailAddress FROM #__members WHERE ID_MEMBER = '$userid'";
  409. $jdb->setQuery($query);
  410. $smfUser = $jdb->loadObject();
  411. }
  412. $timestamp = time();
  413. $post_row = new stdClass();
  414. $post_row->ID_BOARD = $ids->forumid;
  415. $post_row->ID_TOPIC = $ids->threadid;
  416. $post_row->posterTime = $timestamp;
  417. $post_row->ID_MEMBER = $userid;
  418. $post_row->ID_MSG_MODIFIED = $userid;
  419. $post_row->subject = 'Re: '.$topic->subject;
  420. $post_row->posterName = $smfUser->memberName;
  421. $post_row->posterEmail = $smfUser->emailAddress;
  422. $post_row->posterIP = $_SERVER["REMOTE_ADDR"];
  423. $post_row->smileysEnabled = 1;
  424. $post_row->modifiedTime = 0;
  425. $post_row->modifiedName = '';
  426. $post_row->body = $text;
  427. $post_row->icon = 'xx';
  428. if(!$jdb->insertObject('#__messages', $post_row, 'ID_MSG')) {
  429. $status['error'] = $jdb->stderr();
  430. return $status;
  431. }
  432. $postid = $jdb->insertid();
  433. $topic_row = new stdClass();
  434. $topic_row->ID_LAST_MSG = $postid;
  435. $topic_row->ID_MEMBER_UPDATED = (int) $userid;
  436. $topic_row->numReplies = $topic->numReplies + 1;
  437. $topic_row->ID_TOPIC = $ids->threadid;
  438. if(!$jdb->updateObject('#__topics', $topic_row, 'ID_TOPIC' )) {
  439. $status['error'] = $jdb->stderr();
  440. return $status;
  441. }
  442. $forum_stats = new stdClass();
  443. $forum_stats->ID_LAST_MSG = $postid;
  444. $forum_stats->ID_MSG_UPDATED = $postid;
  445. $query = "SELECT numPosts FROM #__boards WHERE ID_BOARD = {$ids->forumid}";
  446. $jdb->setQuery($query);
  447. $num = $jdb->loadObject();
  448. $forum_stats->numPosts = $num->numPosts + 1;
  449. $forum_stats->ID_BOARD = $ids->forumid;
  450. if(!$jdb->updateObject('#__boards', $forum_stats, 'ID_BOARD' )) {
  451. $status['error'] = $jdb->stderr();
  452. return $status;
  453. }
  454. }
  455. return $status;
  456. }
  457. /**
  458. * Retrieves the posts to be displayed in the content item if enabled
  459. * @param object with discussion bot parameters
  460. * @param int Id of thread
  461. * @param int Id of first post which is useful if you do not want the first post to be included in results
  462. * @return array or object Returns retrieved posts
  463. */
  464. function getPosts(&$dbparams, &$existingthread)
  465. {
  466. $threadid =& $existingthread->threadid;
  467. $postid =& $existingthread->postid;
  468. //set the query
  469. $limit_posts = $dbparams->get("limit_posts");
  470. $limit = empty($limit_posts) || trim($limit_posts)==0 ? "" : "LIMIT 0,$limit_posts";
  471. $sort = $dbparams->get("sort_posts");
  472. $where = "WHERE ID_TOPIC = {$threadid} AND ID_MSG != {$postid}";
  473. $query = "SELECT ID_TOPIC , ID_MSG, posterName, ID_MEMBER, CASE WHEN ID_MEMBER = 0 THEN 1 ELSE 0 END AS guest, subject, posterTime, body FROM `#__messages` $where ORDER BY posterTime $sort $limit";
  474. $jdb = & JFusionFactory::getDatabase($this->getJname());
  475. $jdb->setQuery($query);
  476. $posts = $jdb->loadObjectList();
  477. return $posts;
  478. }
  479. function getReplyCount(&$existingthread)
  480. {
  481. $db =& JFusionFactory::getDatabase($this->getJname());
  482. $query = "SELECT numReplies FROM #__topics WHERE ID_TOPIC = {$existingthread->threadid}";
  483. $db->setQuery($query);
  484. $result = $db->loadResult();
  485. return $result;
  486. }
  487. /**
  488. * Returns an object of columns used in createPostTable()
  489. * Saves from having to repeat the same code over and over for each plugin
  490. * For example:
  491. * $columns->userid = "userid";
  492. * $columns->username = "username";
  493. * $columns->username_clean = "username_clean"; //if applicable for filtered usernames
  494. * $columns->dateline = "dateline";
  495. * $columns->posttext = "pagetext";
  496. * $columns->posttitle = "title";
  497. * $columns->postid = "postid";
  498. * $columns->threadid = "threadid";
  499. * @return object with column names
  500. */
  501. function getDiscussionColumns()
  502. {
  503. $columns = new stdClass();
  504. $columns->userid = "ID_MEMBER";
  505. $columns->username = "posterName";
  506. $columns->dateline = "posterTime";
  507. $columns->posttext = "body";
  508. $columns->posttitle = "subject";
  509. $columns->postid = "ID_MSG";
  510. $columns->threadid = "ID_TOPIC";
  511. $columns->guest = "guest";
  512. return $columns;
  513. }
  514. /**
  515. * Prepares text before saving to db or presentint to joomla article
  516. * @param string Text to be modified
  517. * @param $prepareForJoomla boolean to indicate if the text is to be saved to software's db or presented in joomla article
  518. * @return string Modified text
  519. */
  520. function prepareText($text, $prepareForJoomla = false)
  521. {
  522. static $bbcode;
  523. if($prepareForJoomla===false) {
  524. //first thing is to remove all joomla plugins
  525. preg_match_all('/\{(.*)\}/U',$text,$matches);
  526. //find each thread by the id
  527. foreach($matches[1] AS $plugin) {
  528. //replace plugin with nothing
  529. $text = str_replace('{'.$plugin.'}',"",$text);
  530. }
  531. if(!is_array($bbcode)) {
  532. $bbcode = array();
  533. //pattens to run in begening
  534. $bbcode[0][] = "#<a[^>]*href=['|\"](ftp://)(.*?)['|\"][^>]*>(.*?)</a>#si";
  535. $bbcode[1][] = "[ftp=$1$2]$3[/ftp]";
  536. //pattens to run in end
  537. $bbcode[2][] = '#<table[^>]*>(.*?)<\/table>#si';
  538. $bbcode[3][] = '[table]$1[/table]';
  539. $bbcode[2][] = '#<tr[^>]*>(.*?)<\/tr>#si';
  540. $bbcode[3][] = '[tr]$1[/tr]';
  541. $bbcode[2][] = '#<td[^>]*>(.*?)<\/td>#si';
  542. $bbcode[3][] = '[td]$1[/td]';
  543. $bbcode[2][] = '#<strong[^>]*>(.*?)<\/strong>#si';
  544. $bbcode[3][] = '[b]$1[/b]';
  545. $bbcode[2][] = '#<(strike|s)>(.*?)<\/\\1>#sim';
  546. $bbcode[3][] = '[s]$2[/s]';
  547. }
  548. $text = JFusionFunction::parseCode($text,'bbcode',false,$bbcode);
  549. } else {
  550. //remove phpbb's bbcode uids
  551. $text = preg_replace("#\[(.*?):(.*?)]#si","[$1]",$text);
  552. //decode html entities
  553. $text = html_entity_decode($text);
  554. //parse bbcode to html
  555. $text = JFusionFunction::parseCode($text,'html');
  556. }
  557. return $text;
  558. }
  559. function getThread($threadid)
  560. {
  561. $db =& JFusionFactory::getDatabase($this->getJname());
  562. $query = "SELECT ID_TOPIC AS threadid, ID_BOARD AS forumid, ID_FIRST_MSG AS postid FROM #__topics WHERE ID_TOPIC = $threadid";
  563. $db->setQuery($query);
  564. $results = $db->loadObject();
  565. return $results;
  566. }
  567. }