PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/site/tmp/install_4a925da139185/admin/models/model.abstractforum.php

https://bitbucket.org/manchas/jrobotz
PHP | 464 lines | 232 code | 57 blank | 175 comment | 34 complexity | c355b04166596ee96a9f42adb96348a8 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @package JFusion
  4. * @subpackage Models
  5. * @author JFusion development team
  6. * @copyright Copyright (C) 2008 JFusion. All rights reserved.
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  8. */
  9. // no direct access
  10. defined('_JEXEC' ) or die('Restricted access' );
  11. /**
  12. * Abstract interface for all JFusion forum implementations.
  13. * @package JFusion
  14. */
  15. class JFusionForum
  16. {
  17. /**
  18. * returns the name of this JFusion plugin
  19. * @return string name of current JFusion plugin
  20. */
  21. function getJname()
  22. {
  23. return '';
  24. }
  25. /**
  26. * Returns the URL to a thread of the integrated software
  27. * @param integer $threadid threadid
  28. * @return string URL
  29. */
  30. function getThreadURL($threadid)
  31. {
  32. return '';
  33. }
  34. /**
  35. * Returns the URL to a post of the integrated software
  36. * @param integer $threadid threadid
  37. * @param integer $postid postid
  38. * @return string URL
  39. */
  40. function getPostURL($threadid, $postid)
  41. {
  42. return '';
  43. }
  44. /**
  45. * Returns the URL to a userprofile of the integrated software
  46. * @param integer $uid userid
  47. * @return string URL
  48. */
  49. function getProfileURL($uid)
  50. {
  51. return '';
  52. }
  53. /**
  54. * Retrieves the source path to the user's avatar
  55. * @param $uid software's user id
  56. * @return string with source path to users avatar
  57. */
  58. function getAvatar($uid)
  59. {
  60. return 0;
  61. }
  62. /**
  63. * Returns the URL to the view all private messages URL of the integrated software
  64. * @return string URL
  65. */
  66. function getPrivateMessageURL()
  67. {
  68. return '';
  69. }
  70. /**
  71. * Returns the URL to a view new private messages URL of the integrated software
  72. * @return string URL
  73. */
  74. function getViewNewMessagesURL()
  75. {
  76. return '';
  77. }
  78. /**
  79. * Returns the URL to a get private messages URL of the integrated software
  80. * @return string URL
  81. */
  82. function getPrivateMessageCounts($puser_id)
  83. {
  84. return 0;
  85. }
  86. /**
  87. * Returns the an array with SQL statements used by the activity module
  88. * @return array
  89. */
  90. function getActivityQuery($usedforums, $result_order, $result_limit, $display_limit)
  91. {
  92. return 0;
  93. }
  94. /**
  95. * Returns the a list of forums of the integrated software
  96. * @return array List of forums
  97. */
  98. function getForumList()
  99. {
  100. return 0;
  101. }
  102. /**
  103. * Filter forums from a set of results sent in / useful if the plugin needs to restrict the forums visible to a user
  104. * @param $results set of results from query
  105. * @param $limit int limit results parameter as set in the module's params; used for plugins that cannot limit using a query limiter
  106. */
  107. function filterActivityResults(&$results, $limit=0)
  108. {
  109. }
  110. /************************************************
  111. * Functions For JFusion Discussion Bot Plugin
  112. ***********************************************/
  113. /**
  114. * Checks to see if a thread already exists for the content item and calls the appropriate function
  115. * @param object with discussion bot parameters
  116. * @param object $contentitem object containing content information
  117. * @param int default forum id to create the new thread in if applicable (retrieved from $this->getDefaultForum)
  118. * @return array Returns status of actions with errors if any
  119. */
  120. function checkThreadExists(&$params, &$contentitem, $forumid)
  121. {
  122. $status = array();
  123. $status['debug'] = array();
  124. $status['error'] = array();
  125. return $status;
  126. }
  127. /**
  128. * Retrieves the default forum based on section/category stipulations or default set in the plugins config
  129. * @param object with discussion bot parameters
  130. * @param object $contentitem object containing content information
  131. * @return int Returns id number of the forum
  132. */
  133. function getDefaultForum(&$dbparams, &$contentitem)
  134. {
  135. //content section/category
  136. $sectionid =& $contentitem->sectionid;
  137. $catid =& $contentitem->catid;
  138. //default forum to create post in
  139. $forumid = $dbparams->get("default_forum");
  140. //determine default forum
  141. $sections = $dbparams->get("pair_sections");
  142. $sectionPairs = empty($sections) ? false : explode(";",$sections);
  143. $categories = $dbparams->get("pair_categories");
  144. $categoryPairs = empty($categories) ? false : explode(";",$categories);
  145. if($sectionPairs)
  146. {
  147. foreach($sectionPairs as $pairs)
  148. {
  149. $pair = explode(",",$pairs);
  150. //check to see if this section matches the articles
  151. if($pair[0]==$sectionid) $forumid = $pair[1];
  152. }
  153. }
  154. if($categoryPairs)
  155. {
  156. foreach($categoryPairs as $pairs)
  157. {
  158. $pair = explode(",",$pairs);
  159. //check to see if this category matches the articles
  160. if($pair[0]==$catid) $forumid = $pair[1];
  161. }
  162. }
  163. return $forumid;
  164. }
  165. /**
  166. * Retrieves thread information
  167. * @param int Id of specific thread
  168. * @return object Returns object with thread information
  169. * return the object with these three items
  170. * $result->forumid
  171. * $result->threadid (yes add it even though it is passed in as it will be needed in other functions)
  172. * $result->postid - this is the id of the first post in the thread
  173. */
  174. function getThread($threadid)
  175. {
  176. return '';
  177. }
  178. /**
  179. * Creates new thread and posts first post
  180. * @param object with discussion bot parameters
  181. * @param object $contentitem object containing content information
  182. * @param int Id of forum to create thread
  183. * @param array $status contains errors and status of actions
  184. */
  185. function createThread(&$params, &$contentitem, $forumid, &$status)
  186. {
  187. }
  188. /**
  189. * Updates information in a specific thread/post
  190. * @param object with discussion bot parameters
  191. * @param $existingthread object with existin thread info
  192. * @param object $contentitem object containing content information
  193. * @param array $status contains errors and status of actions
  194. */
  195. function updateThread(&$params, &$existingthread, &$contentitem, &$status)
  196. {
  197. }
  198. /**
  199. * Prepares text before saving to db or presentint to joomla article
  200. * @param string Text to be modified
  201. * @param $prepareForJoomla boolean to indicate if the text is to be saved to software's db or presented in joomla article
  202. * @return string Modified text
  203. */
  204. function prepareText($text, $prepareForJoomla = false)
  205. {
  206. if($prepareForJoomla===false) {
  207. //first thing is to remove all joomla plugins
  208. preg_match_all('/\{(.*)\}/U',$text,$matches);
  209. //find each thread by the id
  210. foreach($matches[1] AS $plugin) {
  211. //replace plugin with nothing
  212. $text = str_replace('{'.$plugin.'}',"",$text);
  213. }
  214. }
  215. return $text;
  216. }
  217. /**
  218. * Returns an object of columns used in createPostTable()
  219. * Saves from having to repeat the same code over and over for each plugin
  220. * For example:
  221. * $columns->userid = "userid";
  222. * $columns->username = "username";
  223. * $columns->username_clean = "username_clean"; //if applicable for filtered usernames
  224. * $columns->dateline = "dateline";
  225. * $columns->posttext = "pagetext";
  226. * $columns->posttitle = "title";
  227. * $columns->postid = "postid";
  228. * $columns->threadid = "threadid";
  229. * $columns->guest = "guest";
  230. * @return object with column names
  231. */
  232. function getDiscussionColumns()
  233. {
  234. return;
  235. }
  236. /**
  237. * Creates a table of posts to be displayed in content item
  238. * @param object with discussion bot parameters
  239. * @param obj of thread information
  240. * @param obj list of posts retrieved from getPosts();
  241. * @param array of css classes
  242. * @param obj with discussion bot parameters
  243. * @return string HTML of table to displayed
  244. */
  245. function createPostTable(&$dbparams, &$existingthread, &$posts, &$css)
  246. {
  247. $columns = $this->getDiscussionColumns();
  248. if(empty($columns)) return;
  249. //get required params
  250. defined('_DATE_FORMAT_LC2') or define('_DATE_FORMAT_LC2','%A, %d %B %Y %H:%M');
  251. $date_format = $dbparams->get('custom_date', _DATE_FORMAT_LC2);
  252. $tz_offset = intval($dbparams->get('tz_offset'));
  253. $showdate = intval($dbparams->get('show_date'));
  254. $showuser = intval($dbparams->get('show_user'));
  255. $showavatar = $dbparams->get("show_avatar");
  256. $avatar_software = $dbparams->get("avatar_software",false);
  257. $userlink = intval($dbparams->get('user_link'));
  258. $link_software = $dbparams->get('userlink_software',false);
  259. $userlink_custom = $dbparams->get('userlink_custom',false);
  260. $body_limit = (int) $dbparams->get("body_limit");
  261. $itemid = $dbparams->get("itemid");
  262. $jname = $this->getJname();
  263. $header = $dbparams->get("post_header");
  264. if($showdate && $showuser) $colspan = 2;
  265. else $colspan = 1;
  266. $table = "<div class='{$css["postHeader"]}'>$header</div>\n";
  267. for ($i=0; $i<count($posts); $i++)
  268. {
  269. $p = &$posts[$i];
  270. $userid = $p->{$columns->userid};
  271. $username = $p->{$columns->username};
  272. $username_clean = (isset($columns->username_clean)) ? $p->{$columns->username_clean} : $p->{$columns->username};
  273. $dateline = $p->{$columns->dateline};
  274. $posttext = $p->{$columns->posttext};
  275. $posttitle = $p->{$columns->posttitle};
  276. $postid = $p->{$columns->postid};
  277. $threadid = $p->{$columns->threadid};
  278. $guest = $p->{$columns->guest};
  279. $table .= "<div class = '{$css["postBody"]}'> \n";
  280. //get Joomla's id
  281. $userlookup = JFusionFunction::lookupUser($this->getJname(),$userid,false,$username_clean);
  282. //avatar
  283. if($showavatar){
  284. if(empty($avatar_software) || $avatar_software=='jfusion') {
  285. $avatarSrc = $this->getAvatar($userid);
  286. } elseif(!empty($userlookup)) {
  287. $avatarSrc = JFusionFunction::getAltAvatar($avatar_software,$userlookup->id);
  288. }
  289. if(empty($avatarSrc)) {
  290. $avatarSrc = JFusionFunction::getJoomlaURL().'components/com_jfusion/images/noavatar.png';
  291. }
  292. $size = @getimagesize($avatar);
  293. $maxheight = $dbparams->get('avatar_height',80);
  294. $maxwidth = $dbparams->get('avatar_width',60);
  295. //size the avatar to fit inside the dimensions if larger
  296. if($size!==false && ($size[0] > $maxwidth || $size[1] > $maxheight)) {
  297. $wscale = $maxwidth/$size[0];
  298. $hscale = $maxheight/$size[1];
  299. $scale = min($hscale, $wscale);
  300. $w = floor($scale*$size[0]);
  301. $h = floor($scale*$size[1]);
  302. }
  303. elseif($size!==false) {
  304. //the avatar is within the limits
  305. $w = $size[0];
  306. $h = $size[1];
  307. } else {
  308. //getimagesize failed
  309. $w = $maxwidth;
  310. $h = $maxheight;
  311. }
  312. $avatar = "<div class='{$css["userAvatar"]}'><img height='$h' width='$w' src='$avatarSrc'></div>";
  313. } else {
  314. $avatar = "";
  315. }
  316. $table .= $avatar;
  317. //post title
  318. $urlstring_pre = JFusionFunction::routeURL($this->getPostURL($threadid,$postid), $itemid);
  319. $title = '<a href="'. $urlstring_pre . '">'. $posttitle .'</a>';
  320. $table .= "<div class = '{$css["postTitle"]}'>{$title}</div>\n";
  321. //user info
  322. if ($showuser)
  323. {
  324. if ($userlink && empty($guest) && !empty($userlookup)) {
  325. if(!empty($link_software) && $link_software != 'jfusion' && $link_software!='custom') {
  326. $user_url = JFusionFunction::getAltProfileURL($link_software,$userlookup->id);
  327. } elseif ($link_software=='custom' && !empty($userlink_custom)) {
  328. $user_url = $userlink_custom.$userlookup->id;
  329. } else {
  330. $user_url = false;
  331. }
  332. if($user_url === false) {
  333. $user_url = JFusionFunction::routeURL($this->getProfileURL($userid), $itemid);
  334. }
  335. $user = '<a href="'. $user_url . '">'.$username.'</a>';
  336. } elseif(!empty($guest)) {
  337. $user = "$username (".JText::_('GUEST').")";
  338. } else {
  339. $user = $username;
  340. }
  341. $table .= "<div class='{$css["postUser"]}'> ".JText::_('BY')." $user</div>";
  342. }
  343. //post date
  344. if($showdate){
  345. jimport('joomla.utilities.date');
  346. $JDate = new JDate($dateline);
  347. $JDate->setOffset($tz_offset);
  348. $date = $JDate->toFormat($date_format);
  349. $table .= "<div class='{$css["postDate"]}'>".$date."</div>";
  350. }
  351. //post body
  352. $text = $this->prepareText($posttext,true);
  353. //apply the post body limit if there is one
  354. if(!empty($body_limit) && strlen($text) > $body_limit) {
  355. $text = substr($text,0,$body_limit) . '...';
  356. }
  357. $table .= "<div class='{$css["postText"]}'>{$text}</div> \n";
  358. $table .= "</div>";
  359. }
  360. return $table;
  361. }
  362. /**
  363. * Retrieves the posts to be displayed in the content item if enabled
  364. * @param object with discussion bot parameters
  365. * @param object with forumid, threadid, and postid (first post in thread)
  366. * @return array or object Returns retrieved posts
  367. */
  368. function getPosts(&$params, &$existingthread)
  369. {
  370. return array();
  371. }
  372. /**
  373. * Returns the total number of posts in a thread
  374. * @param object with forumid, threadid, and postid (first post in thread)
  375. * @return int
  376. */
  377. function getReplyCount(&$existingthread)
  378. {
  379. return 0;
  380. }
  381. /**
  382. * Returns HTML of a quick reply
  383. * @param $dbparams object with discussion bot parameters
  384. * @param boolean $showGuestInputs toggles whether to show guest inputs or not
  385. * @return string of html
  386. */
  387. function createQuickReply(&$dbparams,$showGuestInputs)
  388. {
  389. $html = "<textarea name='quickReply' class='inputbox'></textarea><br>";
  390. $html .= "<div style='width:100%; text-align:right;'><input type='submit' value='Submit'/></div>";
  391. return $html;
  392. }
  393. /**
  394. * Creates a post from the quick reply
  395. * @param object with discussion bot parameters
  396. * @param $ids array with forum id ($ids["forumid"], thread id ($ids["threadid"]) and first post id ($ids["postid"])
  397. * @param $contentitem object of content item
  398. * @param $userinfo object info of the forum user
  399. * @return array with status
  400. */
  401. function createPost(&$params, &$ids, &$contentitem, &$userinfo)
  402. {
  403. $status = array();
  404. $status["error"] = false;
  405. return $status;
  406. }
  407. }