PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/content/jfusion.php

http://jfusion.googlecode.com/
PHP | 1323 lines | 1029 code | 174 blank | 120 comment | 281 complexity | d19fde951ffcc12caa16b610656a48f3 MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @package JFusion
  4. * @subpackage Plugin_Discussbot
  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. * Load the JFusion framework
  13. */
  14. jimport('joomla.plugin.plugin');
  15. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.factory.php');
  16. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.jfusionpublic.php');
  17. JPlugin::loadLanguage( 'plg_content_jfusion', JPATH_ADMINISTRATOR );
  18. /**
  19. * @package JFusion
  20. */
  21. class plgContentJfusion extends JPlugin
  22. {
  23. var $params = false;
  24. var $mode = '';
  25. var $valid = false;
  26. var $jname = '';
  27. var $creationMode = '';
  28. var $template = 'default';
  29. var $article = '';
  30. var $replyCount = false;
  31. var $output = array();
  32. var $dbtask = '';
  33. var $ajaxRequest = 0;
  34. var $validity_reason = '';
  35. var $thread_status = '';
  36. var $manual_plug = false;
  37. var $manual_threadid = 0;
  38. var $debug_mode = 0;
  39. var $debug_output = array();
  40. var $clear_debug_output = true;
  41. /**
  42. * Constructor
  43. *
  44. * For php4 compatability we must not use the __constructor as a constructor for
  45. * plugins because func_get_args ( void ) returns a copy of all passed arguments
  46. * NOT references. This causes problems with cross-referencing necessary for the
  47. * observer design pattern.
  48. */
  49. function plgContentJfusion(&$subject, $params)
  50. {
  51. parent::__construct($subject, $params);
  52. //make sure Joomla's content helper is loaded
  53. if (!class_exists('ContentHelperRoute')) {
  54. require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
  55. }
  56. //retrieve plugin software for discussion bot
  57. if ($this->params===false) {
  58. $this->params = new JParameter( $params->params);
  59. }
  60. $this->jname =& $this->params->get('jname',false);
  61. //determine what mode we are to operate in
  62. if ($this->params->get("auto_create",0)) {
  63. $this->mode = ($this->params->get("test_mode",1)) ? 'test' : 'auto';
  64. } else {
  65. $this->mode = 'manual';
  66. }
  67. $this->creationMode =& $this->params->get('create_thread','load');
  68. $this->debug_mode = JRequest::getInt('debug_discussionbot',0);
  69. //$this->debug_mode = 1;
  70. if ($this->debug_mode) {
  71. $session =& JFactory::getSession();
  72. $this->debug_output = $session->get('jfusion.discussion.debug',false);
  73. if ($this->debug_output!==false) {
  74. $this->clear_debug_output = false;
  75. }
  76. $session->clear('jfusion.discussion.debug');
  77. if (!is_array($this->debug_output)) $this->debug_output = array();
  78. }
  79. }
  80. function onAfterContentSave(&$subject, $isNew) {
  81. //check to see if a valid $content object was passed on
  82. if (!is_object($subject)){
  83. JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('NO_CONTENT_DATA_FOUND'), 1);
  84. return false;
  85. }
  86. $this->article =& $subject;
  87. //make sure there is a plugin
  88. if (empty($this->jname)) {
  89. return false;
  90. }
  91. $this->_debug('onAfterContentSave called');
  92. //validate the article
  93. $this->thread_status = $this->_get_thread_status();
  94. $this->valid = $this->_validate(true);
  95. $this->_debug('Validity: ' . $this->valid . "; " . $this->validity_reason);
  96. //ignore auto mode if the article has been manually plugged
  97. $manually_plugged = preg_match('/\{jfusion_discuss (.*)\}/U', $this->article->introtext . $this->article->fulltext);
  98. $this->_debug('Checking mode...');
  99. if ($this->mode=='auto' && empty($manually_plugged)) {
  100. $this->_debug('In auto mode');
  101. if ($this->valid) {
  102. $threadinfo =& $this->_get_thread_info();
  103. $JFusionForum =& JFusionFactory::getForum($this->jname);
  104. $forumid = $JFusionForum->getDefaultForum($this->params, $this->article);
  105. if (($this->creationMode=='load') ||
  106. ($this->creationMode=='new' && ($isNew || (!$isNew && $this->thread_status))) ||
  107. ($this->creationMode=='reply' && $this->thread_status)) {
  108. //update/create thread
  109. $status = $this->_check_thread_exists();
  110. } else {
  111. $this->_debug('Article did not meet requirements to update/create thread');
  112. }
  113. } elseif ($this->creationMode=='new' && $isNew) {
  114. $this->_debug('Failed validity test but creationMode is set to new and this is a new article');
  115. $mainframe = & JFactory::getApplication();
  116. $publishUp = JFactory::getDate($this->article->publish_up)->toUnix();
  117. $now = JFactory::getDate('now', $mainframe->getCfg('offset'))->toUnix();
  118. if ($now < $publish_up || !$this->article->state) {
  119. $this->_debug('Article set to be published in the future or is unpublished thus creating an entry in the database so that the thread is created when appropriate.');
  120. //the publish date is set for the future so create an entry in the
  121. //database so that the thread is created when the publish date arrives
  122. $placeholder = new stdClass();
  123. $placeholder->threadid = 0;
  124. $placeholder->forumid = 0;
  125. $placeholder->postid = 0;
  126. JFusionFunction::updateDiscussionBotLookup($this->article->id, $placeholder, $this->jname);
  127. }
  128. }
  129. } elseif ($this->mode=='test' && empty($manually_plugged)) {
  130. //recheck validity without stipulation
  131. $this->valid = $this->_validate();
  132. $this->_debug('In test mode thus not creating the article');
  133. $threadinfo =& $this->_get_thread_info();
  134. $JFusionForum =& JFusionFactory::getForum($this->jname);
  135. $content = "<u>" . $this->article->title . "</u><br />";
  136. if (!empty($threadinfo)) {
  137. $content .= JText::_('DISCUSSBOT_TEST_MODE') . "<img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
  138. if ($threadinfo->published) {
  139. $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_PUBLISHED') . "<br />";
  140. } else {
  141. $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_UNPUBLISHED') . "<br />";
  142. }
  143. $content .= JText::_('THREADID') . ": " . $threadinfo->threadid . "<br />";
  144. $content .= JText::_('FORUMID') . ": " . $threadinfo->forumid . "<br />";
  145. $content .= JText::_('FIRST_POSTID') . ": " . $threadinfo->postid. "<br />";
  146. $forumlist =& $this->_get_lists('forum');
  147. if (!isset($forumlist[$threadinfo->forumid])) {
  148. $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('FORUM_NOT_EXIST') . "<br />";
  149. }
  150. $forumthread = $JFusionForum->getThread($threadinfo->threadid);
  151. if (empty($forumthread)) {
  152. $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('THREAD_NOT_EXIST') . "<br />";
  153. }
  154. } else {
  155. $valid = ($this->valid) ? JText::_('YES') : JText::_('NO');
  156. if (!$this->valid) {
  157. $content .= JText::_('DISCUSSBOT_TEST_MODE') . "<img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/x.png' style='margin-left:5px;'><br/>";
  158. $content .= JText::_('VALID') . ": " . $valid . "<br />";
  159. $content .= JText::_('INVALID_REASON') . ": " . $this->validity_reason . "<br />";
  160. } else {
  161. $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
  162. $content .= JText::_('VALID_REASON') . ": " . $this->validity_reason . "<br />";
  163. $content .= JText::_('STATUS') . ": " . JText::_('UNINITIALIZED_THREAD_WILL_BE_CREATED') . "<br />";
  164. $forumid = $JFusionForum->getDefaultForum($this->params, $this->article);
  165. $content .= JText::_('FORUMID') . ": " . $forumid . "<br />";
  166. $author = $JFusionForum->getThreadAuthor($this->params, $this->article);
  167. $content .= JText::_('AUTHORID') . ": " . $author . "<br />";
  168. }
  169. }
  170. JError::raiseNotice('500', $content);
  171. } else {
  172. $this->_debug('In manual mode...checking to see if article has been initialized');
  173. $threadinfo =& $this->_get_thread_info();
  174. if (!empty($threadinfo) && $threadinfo->published == 1 && $threadinfo->manual == 1) {
  175. $this->_debug('Article has been initialized...updating thread');
  176. //update thread
  177. $status = $this->_check_thread_exists();
  178. } else {
  179. $this->_debug('Article has not been initialized');
  180. }
  181. }
  182. $this->_debug('onAfterContentSave complete', true);
  183. }
  184. function onPrepareContent(&$subject, $params)
  185. {
  186. $mainframe = & JFactory::getApplication();
  187. //reset some vars
  188. $this->manual_plug = false;
  189. $this->manual_threadid = 0;
  190. if ($this->clear_debug_output) {
  191. $this->debug_output = array();
  192. }
  193. $this->thread_status = '';
  194. $this->validity_reason = '';
  195. $this->_debug('onPrepareContent called');
  196. //check to see if a valid $content object was passed on
  197. if (!is_object($subject)){
  198. JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('NO_CONTENT_DATA_FOUND'), 1);
  199. return false;
  200. }
  201. //make sure there is a plugin
  202. if (empty($this->jname)) {
  203. return false;
  204. }
  205. //prevent any output by the plugins (this could prevent cookies from being passed to the header)
  206. ob_start();
  207. //set some variables needed throughout
  208. $this->template = $this->params->get("template","default");
  209. if (!defined('DISCUSSION_TEMPLATE_PATH')) {
  210. //let's first check for customized files in Joomla's template directory
  211. $app =& JFactory::getApplication();
  212. $JoomlaTemplateOverride = JPATH_BASE.DS.'templates'. DS .$app->getTemplate() . DS. 'html' . DS . 'plg_content_jfusion' . DS;
  213. if (file_exists($JoomlaTemplateOverride)) {
  214. define('DISCUSSION_TEMPLATE_PATH', $JoomlaTemplateOverride);
  215. define('DISCUSSION_TEMPLATE_URL', JFusionFunction::getJoomlaURL() . 'templates/' . $app->getTemplate() . 'html/plg_content_jfusion/');
  216. } else {
  217. define('DISCUSSION_TEMPLATE_PATH',JPATH_BASE.DS.'plugins'.DS.'content'.DS.'discussbot'.DS.'tmpl'.DS.$this->template.DS);
  218. define('DISCUSSION_TEMPLATE_URL',JFusionFunction::getJoomlaURL().'plugins/content/discussbot/tmpl/'.$this->template.'/');
  219. }
  220. }
  221. $this->article =& $subject;
  222. //make sure we have an actual article
  223. if ($this->article->id) {
  224. $this->dbtask = JRequest::getVar('dbtask', 'render_content', 'post');
  225. $skip_new_check = ($this->dbtask=='create_thread') ? true : false;
  226. $this->thread_status = $this->_get_thread_status();
  227. $this->valid = $this->_validate($skip_new_check);
  228. $this->_debug('Validity: ' . $this->valid . "; " . $this->validity_reason);
  229. $this->ajaxRequest = JRequest::getInt('ajax_request',0);
  230. if ($this->dbtask == 'create_thread') {
  231. //this article has been manually initiated for discussion
  232. $this->_create_thread();
  233. } elseif (($this->dbtask == 'create_post' || $this->dbtask == 'create_threadpost') && $this->params->get("enable_quickreply",false)) {
  234. //a quick reply has been submitted so let's create the post
  235. $this->_create_post();
  236. } elseif ($this->dbtask == 'unpublish_discussion') {
  237. //an article has been "uninitiated"
  238. $this->_unpublish_discussion();
  239. } elseif ($this->dbtask == 'publish_discussion') {
  240. //an article has been "reinitiated"
  241. $this->_publish_discussion();
  242. }
  243. //save the visibility of the posts if applicable
  244. $show_discussion = JRequest::getVar('show_discussion','');
  245. if ($show_discussion!=='') {
  246. $JSession =& JFactory::getSession();
  247. $JSession->set('jfusion.discussion.visibility',(int) $show_discussion);
  248. }
  249. //check for some specific ajax requests
  250. if ($this->ajaxRequest) {
  251. //check to see if this is an ajax call to update the pagination
  252. if ($this->params->get('enable_pagination',1) && $this->dbtask == 'update_pagination') {
  253. $this->_update_pagination();
  254. }
  255. if ($this->params->get('show_posts',1) && $this->dbtask == 'update_posts') {
  256. $this->_update_posts();
  257. }
  258. if ($this->dbtask=='update_content') {
  259. $threadinfo =& $this->_get_thread_info();
  260. if (!empty($threadinfo->published)) {
  261. //content is now published so display it
  262. die($this->_render_discussion_content($threadinfo));
  263. } else {
  264. //content is now not published so remove it
  265. die();
  266. }
  267. }
  268. if ($this->dbtask == 'update_buttons') {
  269. $this->_update_buttons();
  270. }
  271. if ($show_discussion!=='') {
  272. die('jfusion.discussion.visibility set to '.$show_discussion);
  273. }
  274. die("Discussion bot ajax request made but it doesn't seem to have been picked up");
  275. }
  276. //add scripts to header
  277. static $scriptsLoaded;
  278. if (empty($scriptsLoaded)) {
  279. $this->_load_scripts();
  280. $scriptsLoaded = 1;
  281. }
  282. //generate content
  283. $this->_prepare_content();
  284. }
  285. ob_end_clean();
  286. return true;
  287. }
  288. function _prepare_content()
  289. {
  290. JHTML::_( 'behavior.mootools' );
  291. $this->_debug('Preparing content');
  292. $content = '';
  293. //get the jfusion forum object
  294. $JFusionForum =& JFusionFactory::getForum($this->jname);
  295. //find any {jfusion_discuss...} to manually plug
  296. $this->_debug('Finding all manually added plugs');
  297. preg_match_all('/\{jfusion_discuss (.*)\}/U',$this->article->text,$matches);
  298. $this->_debug(count($matches[1]) . ' matches found');
  299. foreach($matches[1] as $id) {
  300. //only use the first and get rid of the others
  301. if (empty($this->manual_plug)) {
  302. $this->manual_plug = true;
  303. $this->_debug('Plugging for thread id ' . $id);
  304. //get the existing thread information
  305. $threadinfo = $JFusionForum->getThread($id);
  306. if (!empty($threadinfo)) {
  307. //override thread status
  308. $this->thread_status = true;
  309. $content = $this->_render($threadinfo);
  310. $this->article->text = str_replace("{jfusion_discuss $id}",$content,$this->article->text);
  311. } else {
  312. $this->article->text = str_replace("{jfusion_discuss $id}",JText::_("THREADID_NOT_FOUND"),$this->article->text);
  313. }
  314. if ($this->mode=='test') {
  315. $content = "<div class='jfusionclearfix' style='border:1px solid #ECF8FD; background-color:#ECF8FD; margin-top:10px; margin-bottom:10px;'>\n";
  316. $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
  317. $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_PUBLISHED') . "<br />";
  318. $threadinfo = $JFusionForum->getThread($id);
  319. if (empty($threadinfo)) {
  320. $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('THREAD_NOT_EXIST') . "<br />";
  321. } else {
  322. $content .= JText::_('THREADID') . ": " . $threadinfo->threadid . "<br />";
  323. $content .= JText::_('FORUMID') . ": " . $threadinfo->forumid . "<br />";
  324. $content .= JText::_('FIRST_POSTID') . ": " . $threadinfo->postid. "<br />";
  325. }
  326. $forumlist =& $this->_get_lists('forum');
  327. if (!isset($forumlist[$threadinfo->forumid])) {
  328. $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('FORUM_NOT_EXIST') . "<br />";
  329. }
  330. $content .= "</div>\n";
  331. }
  332. } else {
  333. $this->_debug('Removing plug for thread ' . $id);
  334. $this->article->text = str_replace("{jfusion_discuss $id}",'',$this->article->text);
  335. }
  336. }
  337. //check to see if the fulltext has a manual plug if we are in a blog view
  338. if (!$this->manual_plug && JRequest::getVar('view')!='article') {
  339. preg_match('/\{jfusion_discuss (.*)\}/U',$this->article->fulltext,$match);
  340. if (!empty($match)) {
  341. $this->_debug("No plugs in text but found plugs in fulltext");
  342. $this->manual_plug = true;
  343. $this->manual_threadid = $match[1];
  344. //create buttons for the manually plugged article
  345. $content = $this->_render_buttons();
  346. //append the content
  347. $this->article->text .= $content;
  348. }
  349. }
  350. //check for auto mode if not already manually plugged
  351. if (!$this->manual_plug) {
  352. $this->_debug('Article not manually plugged...checking for other mode');
  353. $threadinfo =& $this->_get_thread_info();
  354. //create the thread if this article has been validated
  355. if ($this->mode=='auto') {
  356. $this->_debug('In auto mode');
  357. if ($this->valid) {
  358. $status = $this->_check_thread_exists();
  359. }
  360. $content = $this->_render($threadinfo);
  361. } elseif ($this->mode=='test') {
  362. $this->_debug('In test mode');
  363. //get the existing thread information
  364. $content = "<div class='jfusionclearfix' style='border:1px solid #ECF8FD; background-color:#ECF8FD; margin-top:10px; margin-bottom:10px;'>\n";
  365. if (!empty($threadinfo)) {
  366. $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
  367. if ($threadinfo->published) {
  368. $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_PUBLISHED') . "<br />";
  369. } else {
  370. $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_UNPUBLISHED') . "<br />";
  371. }
  372. $content .= JText::_('THREADID') . ": " . $threadinfo->threadid . "<br />";
  373. $content .= JText::_('FORUMID') . ": " . $threadinfo->forumid . "<br />";
  374. $content .= JText::_('FIRST_POSTID') . ": " . $threadinfo->postid. "<br />";
  375. $forumlist =& $this->_get_lists('forum');
  376. if (!isset($forumlist[$threadinfo->forumid])) {
  377. $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('FORUM_NOT_EXIST') . "<br />";
  378. }
  379. $forumthread = $JFusionForum->getThread($threadinfo->threadid);
  380. if (empty($forumthread)) {
  381. $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('THREAD_NOT_EXIST') . "<br />";
  382. }
  383. } else {
  384. $valid = ($this->valid) ? JText::_('YES') : JText::_('NO');
  385. if (!$this->valid) {
  386. $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/x.png' style='margin-left:5px;'><br/>";
  387. $content .= JText::_('VALID') . ": " . $valid . "<br />";
  388. $content .= JText::_('INVALID_REASON') . ": " . $this->validity_reason . "<br />";
  389. } else {
  390. $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
  391. $content .= JText::_('VALID_REASON') . ": " . $this->validity_reason . "<br />";
  392. $content .= JText::_('STATUS') . ": " . JText::_('UNINITIALIZED_THREAD_WILL_BE_CREATED') . "<br />";
  393. $forumid = $JFusionForum->getDefaultForum($this->params, $this->article);
  394. $content .= JText::_('FORUMID') . ": " . $forumid . "<br />";
  395. $author = $JFusionForum->getThreadAuthor($this->params, $this->article);
  396. $content .= JText::_('AUTHORID') . ": " . $author . "<br />";
  397. }
  398. }
  399. $content .= "</div>\n";
  400. } elseif (!empty($threadinfo->manual)) {
  401. $this->_debug('In manual mode but article has been initialized');
  402. //this article was generated by the initialize button
  403. $content = $this->_render($threadinfo);
  404. } else {
  405. $this->_debug('In manual mode');
  406. //in manual mode so just create the buttons
  407. $content = $this->_render_buttons();
  408. }
  409. //append the content
  410. $this->article->text .= $content;
  411. }
  412. static $taskFormLoaded;
  413. if (empty($taskFormLoaded)) {
  414. $this->_debug('Adding task form');
  415. //tak on the task form; it only needs to be added once which will be used for create_thread
  416. $uri = JFactory::getURI();
  417. $url = $uri->toString(array('path', 'query', 'fragment'));
  418. $content = "<form style='display:none;' id='JFusionTaskForm' name='JFusionTaskForm' method='post' action='".$url."'>\n";
  419. $content .= "<input type='hidden' name='articleId' value='' />\n";
  420. $content .= "<input type='hidden' name='dbtask' value='' />\n";
  421. $content .= "</form>\n";
  422. $this->article->text .= $content;
  423. $taskFormLoaded = 1;
  424. }
  425. if ($this->debug_mode) {
  426. require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.debug.php');
  427. ob_start();
  428. debug::show($this->debug_output, 'Discussion bot debug info',1);
  429. $this->article->text .= ob_get_contents();
  430. ob_end_clean();
  431. }
  432. }
  433. function _create_thread()
  434. {
  435. $JoomlaUser =& JFactory::getUser();
  436. $JFusionForum =& JFusionFactory::getForum($this->jname);
  437. $mainframe = & JFactory::getApplication();
  438. if ($return = JRequest::getVar('return')) {
  439. $url = base64_decode($return);
  440. } else {
  441. $uri = JFactory::getURI();
  442. $url = $uri->toString(array('path', 'query', 'fragment'));
  443. $url = JRoute::_($url, false);
  444. if ($uri->getVar('view')=='article') {
  445. //tak on the discussion jump to
  446. $url .= "#discussion";
  447. $JSession =& JFactory::getSession();
  448. $JSession->set('jfusion.discussion.visibility',1);
  449. }
  450. }
  451. //make sure the article submitted matches the one loaded
  452. $submittedArticleId = JRequest::getInt('articleId', 0, 'post');
  453. $editAccess = $JoomlaUser->authorize('com_content', 'edit', 'content', 'all');
  454. if ($editAccess && $this->valid && $submittedArticleId == $this->article->id) {
  455. $status = $this->_check_thread_exists(1);
  456. if ($status['error']) {
  457. if (is_array($status['error'])) {
  458. foreach($status['error'] as $err) {
  459. $mainframe->enqueueMessage('error',$this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'). ': ' . $err);
  460. }
  461. } else {
  462. $mainframe->enqueueMessage('error',$this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'). ': ' . $status['error']);
  463. }
  464. $mainframe->redirect($url);
  465. } else {
  466. $mainframe->redirect($url, JText::sprintf('THREAD_CREATED_SUCCESSFULLY',$this->article->title));
  467. }
  468. }
  469. }
  470. function _create_post()
  471. {
  472. $JoomlaUser =& JFactory::getUser();
  473. $JFusionForum =& JFusionFactory::getForum($this->jname);
  474. //define some variables
  475. $allowGuests =& $this->params->get("quickreply_allow_guests",0);
  476. $ajaxEnabled = ($this->params->get("enable_ajax",1) && $this->ajaxRequest);
  477. //process quick replies
  478. if ($allowGuests || !$JoomlaUser->guest) {
  479. //make sure something was submitted
  480. $quickReplyText = JRequest::getVar('quickReply', '', 'POST');
  481. if (!empty($quickReplyText)) {
  482. //retrieve the userid from forum software
  483. if ($allowGuests && $JoomlaUser->guest) {
  484. $userinfo = new stdClass();
  485. $userinfo->guest = 1;
  486. $captcha_verification = $JFusionForum->verifyCaptcha($this->params);
  487. } else {
  488. $JFusionUser =& JFusionFactory::getUser($this->jname);
  489. $userinfo = $JFusionUser->getUser($JoomlaUser);
  490. $userinfo->guest = 0;
  491. //we have a user logged in so ignore captcha
  492. $captcha_verification = true;
  493. }
  494. if ($captcha_verification) {
  495. if ($this->dbtask=='create_threadpost') {
  496. $status = $this->_check_thread_exists();
  497. $threadinfo = $status['threadinfo'];
  498. } elseif ($this->dbtask=="create_post") {
  499. $threadinfo =& $this->_get_thread_info();
  500. }
  501. //create the post
  502. if (!empty($threadinfo->threadid) && !empty($threadinfo->forumid)) {
  503. $status = $JFusionForum->createPost($this->params, $threadinfo, $this->article, $userinfo);
  504. if ($status['error']){
  505. if ($ajaxEnabled) {
  506. //output the error
  507. die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . $status['error']);
  508. } else {
  509. JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), $status['error'],1);
  510. }
  511. } else {
  512. if ($ajaxEnabled) {
  513. //if pagination is set, set $limitstart so that we go to the added post
  514. if ($this->params->get('enable_pagination',true)) {
  515. $replyCount = $JFusionForum->getReplyCount($threadinfo);
  516. $application =& JFactory::getApplication();
  517. $limit = $application->getUserStateFromRequest( 'global.list.limit', 'limit', 14, 'int' );
  518. if ($this->params->get("sort_posts",'ASC')=='ASC') {
  519. $limitstart = floor(($replyCount-1)/$limit) * $limit;
  520. } else {
  521. $limitstart = 0;
  522. }
  523. JRequest::setVar('limitstart',$limitstart);
  524. }
  525. $posts = $JFusionForum->getPosts($this->params, $threadinfo);
  526. $this->output = array();
  527. $this->output['posts'] = $this->_prepare_posts_output($posts);
  528. //take note of the created post
  529. $this->output['submitted_postid'] = $status['postid'];
  530. if (isset($status['post_moderated'])) {
  531. $this->output['post_moderated'] = $status['post_moderated'];
  532. } else {
  533. $this->output['post_moderated'] = 0;
  534. }
  535. //output only the new post div
  536. $this->_render_file('default_posts.php','die');
  537. } else {
  538. if ($this->params->get('jumpto_new_post',0)) {
  539. $jumpto = (isset($status['postid'])) ? "post" . $status['postid'] : '';
  540. } else {
  541. $jumpto = '';
  542. }
  543. $url = $this->_get_article_url($jumpto,'',false);
  544. if (isset($status['post_moderated'])) {
  545. $text = ($status['post_moderated']) ? 'SUCCESSFUL_POST_MODERATED' : 'SUCCESSFUL_POST';
  546. } else {
  547. $text = 'SUCCESSFUL_POST';
  548. }
  549. $mainframe = & JFactory::getApplication();
  550. $mainframe->redirect($url, JText::_($text));
  551. }
  552. }
  553. } else {
  554. if ($ajaxEnabled) {
  555. die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . JText::_('THREADID_NOT_FOUND'));
  556. } else {
  557. JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('THREADID_NOT_FOUND'),1);
  558. }
  559. }
  560. } else {
  561. if ($ajaxEnabled) {
  562. die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . JText::_('CAPTCHA_INCORRECT'));
  563. } else {
  564. JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('CAPTCHA_INCORRECT'),1);
  565. }
  566. }
  567. } else {
  568. if ($ajaxEnabled) {
  569. die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . JText::_('QUICKEREPLY_EMPTY'));
  570. } else {
  571. JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('QUICKEREPLY_EMPTY'),1);
  572. }
  573. }
  574. }
  575. //if ajax is enabled, then something has gone wrong so die
  576. if ($ajaxEnabled) die(JText::_('DISCUSSBOT_ERROR'));
  577. }
  578. function _unpublish_discussion()
  579. {
  580. $JoomlaUser =& JFactory::getUser();
  581. $JFusionForum =& JFusionFactory::getForum($this->jname);
  582. //make sure the article submitted matches the one loaded
  583. $submittedArticleId = JRequest::getInt('articleId', 0, 'post');
  584. $editAccess = $JoomlaUser->authorize('com_content', 'edit', 'content', 'all');
  585. if ($editAccess && $this->valid && $submittedArticleId == $this->article->id) {
  586. $threadinfo =& $this->_get_thread_info();
  587. if (!empty($threadinfo)) {
  588. //created by discussion bot thus update the look up table
  589. JFusionFunction::updateDiscussionBotLookup($this->article->id, $threadinfo, $this->jname, 0, $threadinfo->manual);
  590. } else {
  591. //manually plugged thus remove any db plugin tags
  592. $jdb =& JFactory::getDBO();
  593. //retrieve the original text
  594. $query = "SELECT `introtext`, `fulltext` FROM #__content WHERE id = " . $this->article->id;
  595. $jdb->setQuery($query);
  596. $texts = $jdb->loadObject();
  597. //remove any {jfusion_discuss...}
  598. $fulltext = preg_replace('/\{jfusion_discuss (.*)\}/U','',$texts->fulltext, -1, $fullTextCount);
  599. $introtext = preg_replace('/\{jfusion_discuss (.*)\}/U','',$texts->introtext, -1, $introTextCount);
  600. if (!empty($fullTextCount) || !empty($introTextCount)) {
  601. $query = "UPDATE #__content SET `fulltext` = " . $jdb->Quote($fulltext) . ", `introtext` = " .$jdb->Quote($introtext) . " WHERE id = " . (int) $this->article->id;
  602. $jdb->setQuery($query);
  603. $jdb->query();
  604. }
  605. }
  606. if ($this->ajaxRequest) {
  607. $this->thread_status = $this->_get_thread_status();
  608. die($this->_render_buttons(true));
  609. }
  610. } else {
  611. die('Access denied!');
  612. }
  613. }
  614. function _publish_discussion()
  615. {
  616. $JoomlaUser =& JFactory::getUser();
  617. $JFusionForum =& JFusionFactory::getForum($this->jname);
  618. //make sure the article submitted matches the one loaded
  619. $submittedArticleId = JRequest::getInt('articleId', 0, 'post');
  620. $editAccess = $JoomlaUser->authorize('com_content', 'edit', 'content', 'all');
  621. if ($editAccess && $this->valid && $submittedArticleId == $this->article->id) {
  622. $threadinfo =& $this->_get_thread_info();
  623. JFusionFunction::updateDiscussionBotLookup($this->article->id, $threadinfo, $this->jname, 1, $threadinfo->manual);
  624. if ($this->ajaxRequest) {
  625. $this->thread_status = $this->_get_thread_status();
  626. die($this->_render_buttons(true));
  627. }
  628. } else {
  629. die('Access denied!');
  630. }
  631. }
  632. function _render(&$threadinfo)
  633. {
  634. $this->_debug('Beginning rendering content');
  635. if (!empty($threadinfo)) {
  636. $JFusionForum =& JFusionFactory::getForum($this->jname);
  637. $this->replyCount = $JFusionForum->getReplyCount($threadinfo);
  638. }
  639. $view = JRequest::getVar('view');
  640. //let's only show quick replies and posts on the article view
  641. if ($view=="article") {
  642. $content = $this->_render_buttons();
  643. $JSession =& JFactory::getSession();
  644. if (!empty($threadinfo->manual) && empty($threadinfo->published)) {
  645. $this->_debug('Discussion content not displayed as this discussion is unpublished');
  646. $display = 'none';
  647. $generate_guts = false;
  648. } else {
  649. if ($JSession->get('jfusion.discussion.visibility',0) || empty($threadinfo) && $this->creationMode == 'reply') {
  650. //show the discussion area if no replies have been made and creationMode is set to on first reply OR if user has set it to show
  651. $display = 'block';
  652. } else {
  653. $display = ($this->params->get('show_toggle_posts_link',1) && $this->params->get('collapse_discussion',1)) ? 'none' : 'block';
  654. }
  655. $generate_guts = true;
  656. }
  657. $content .= "<div style='float:none; display:{$display};' id='discussion'>\n";
  658. if ($generate_guts) {
  659. $content .= $this->_render_discussion_content($threadinfo);
  660. }
  661. $content .= "</div>";
  662. } else {
  663. $content = $this->_render_buttons();
  664. }
  665. return $content;
  666. }
  667. function _render_discussion_content(&$threadinfo)
  668. {
  669. $this->_debug('Rendering discussion content');
  670. //setup parameters
  671. $JFusionForum =& JFusionFactory::getForum($this->jname);
  672. $allowGuests =& $this->params->get("quickreply_allow_guests",0);
  673. $JoomlaUser =& JFactory::getUser();
  674. //make sure the user exists in the software before displaying the quick reply
  675. $JFusionUser =& JFusionFactory::getUser($this->jname);
  676. $JFusionUserinfo = $JFusionUser->getUser($JoomlaUser);
  677. $action_url = $this->_get_article_url('','',false);
  678. $this->output = array();
  679. $this->output['reply_count'] = $this->replyCount;
  680. if (!empty($threadinfo)) {
  681. //prepare quick reply box if enabled
  682. if ($this->params->get("enable_quickreply")){
  683. $threadLocked = $JFusionForum->getThreadLockedStatus($threadinfo->threadid);
  684. $show_form = ($allowGuests || !$JoomlaUser->guest) ? true : false;
  685. if ($threadLocked) {
  686. $this->output['reply_form_error'] = $this->params->get("locked_msg");
  687. $this->output['show_reply_form'] = false;
  688. } elseif ($show_form) {
  689. if (!$JoomlaUser->guest && empty($JFusionUserinfo)) {
  690. $this->output['reply_form_error'] = $this->jname . ': ' . JText::_('USER_NOT_EXIST')."\n";
  691. $this->output['show_reply_form'] = false;
  692. } else {
  693. $showGuestInputs = ($allowGuests && $JoomlaUser->guest) ? true : false;
  694. $this->output['reply_form'] = "<form id='jfusionQuickReply{$this->article->id}' name='jfusionQuickReply{$this->article->id}' method=post action='".$action_url."'>\n";
  695. $this->output['reply_form'] .= "<input type=hidden name='dbtask' value='create_post'>\n";
  696. $this->output['reply_form'] .= $JFusionForum->createQuickReply($this->params,$showGuestInputs);
  697. $this->output['reply_form'] .= "</form>";
  698. $this->output['show_reply_form'] = true;
  699. }
  700. } else {
  701. $this->output['reply_form_error'] = $this->params->get("must_login_msg");
  702. $this->output['show_reply_form'] = false;
  703. }
  704. }
  705. //add posts to content if enabled
  706. if ($this->params->get("show_posts")) {
  707. //get the posts
  708. $posts = $JFusionForum->getPosts($this->params, $threadinfo);
  709. if (!empty($posts)){
  710. $this->output['posts'] = $this->_prepare_posts_output($posts);
  711. }
  712. if ($this->params->get("enable_pagination",1)) {
  713. $this->output['post_pagination'] = "<div id='jfusionPostPagination'>\n";
  714. if ($this->replyCount) {
  715. $application = JFactory::getApplication() ;
  716. $limitstart = JRequest::getInt( 'limitstart', 0 );
  717. $limit = $application->getUserStateFromRequest( 'global.list.limit', 'limit', 5, 'int' );
  718. jimport('joomla.html.pagination');
  719. $pageNav = new JPagination($this->replyCount, $limitstart, $limit );
  720. $this->output['post_pagination'] .= "<form method='post' name='jfusionPaginationForm' action='$action_url'>\n";
  721. $this->output['post_pagination'] .= $pageNav->getListFooter();
  722. $this->output['post_pagination'] .= "</form>\n";
  723. }
  724. $this->output['post_pagination'] .= "</div>\n";
  725. } else {
  726. $this->output['post_pagination'] = '';
  727. }
  728. } else {
  729. $this->output['posts'] = '';
  730. $this->output['post_pagination'] = '';
  731. }
  732. } elseif ($this->creationMode=='reply') {
  733. //prepare quick reply box if enabled
  734. $show_form = ($allowGuests || (!$JoomlaUser->guest && !empty($JFusionUserinfo))) ? true : false;
  735. if ($show_form) {
  736. if (!$JoomlaUser->guest && empty($JFusionUserinfo)) {
  737. $this->output['reply_form_error'] = $this->jname . ': ' . JText::_('USER_NOT_EXIST')."\n";
  738. $this->output['show_reply_form'] = false;
  739. } else {
  740. $showGuestInputs = ($allowGuests && $JoomlaUser->guest) ? true : false;
  741. $this->output['reply_form'] = "<form id='jfusionQuickReply{$this->article->id}' name='jfusionQuickReply{$this->article->id}' method=post action='".$actionUrl."'>\n";
  742. $this->output['reply_form'] .= "<input type=hidden name='dbtask' value='create_threadpost'/>\n";
  743. $this->output['reply_form'] .= $JFusionForum->createQuickReply($this->params,$showGuestInputs);
  744. $this->output['reply_form'] .= "</form>";
  745. $this->output['show_reply_form'] = true;
  746. }
  747. } else {
  748. $this->output['reply_form_error'] = $this->params->get("must_login_msg");
  749. $this->output['show_reply_form'] = false;
  750. }
  751. }
  752. //populate the template
  753. $content = $this->_render_file('default.php','capture');
  754. return $content;
  755. }
  756. function _render_buttons($innerhtml = false)
  757. {
  758. $this->_debug('Rendering buttons');
  759. //setup some variables
  760. $threadinfo =& $this->_get_thread_info();
  761. $JUser =& JFactory::getUser();
  762. $attribs = new JParameter( $this->article->attribs);
  763. $itemid =& $this->params->get("itemid");
  764. $link_text =& $this->params->get("link_text");
  765. $link_type=& $this->params->get("link_type",'text');
  766. $link_mode=& $this->params->get("link_mode",'always');
  767. $blog_link_mode=& $this->params->get("blog_link_mode",'forum');
  768. $linkHTML = ($link_type=='image') ? "<img style='border:0;' src='$link_text'>" : $link_text;
  769. $linkTarget =& $this->params->get('link_target','_parent');
  770. //prevent notices and warnings in default_buttons.php if there are no buttons to display
  771. $this->output = array();
  772. $this->output['buttons'] = array();
  773. if (isset($this->article->params)) {
  774. //blog view
  775. $article_params =& $this->article->params;
  776. $readmore_catch = $this->article->readmore;
  777. $show_readmore = $article_params->get('show_readmore');
  778. } elseif (isset($this->article->parameters)) {
  779. //article view
  780. $article_params =& $this->article->parameters;
  781. $readmore_catch = JRequest::getInt('readmore');
  782. $override = JRequest::getInt('show_readmore',false);
  783. $show_readmore = ($override!==false) ? $override : $article_params->get('show_readmore');
  784. }
  785. //let's overwrite the readmore link with our own
  786. //needed as in the case of updating the buttons via ajax which calls the article view
  787. $view = ($override = JRequest::getVar('view_override')) ? $override : JRequest::getVar('view');
  788. if ($view != 'article' && $this->params->get('overwrite_readmore',1)) {
  789. //make sure the readmore link is enabled for this article
  790. if (($show_readmore != 0 && $readmore_catch != 0)) {
  791. if ($this->article->access <= $JUser->get('aid', 0)) {
  792. $readmore_link = $this->_get_article_url();
  793. if ($readmore = $attribs->get('readmore')) {
  794. $readmore_text = $readmore;
  795. } else {
  796. $readmore_text = JText::_('Read more...');
  797. }
  798. } else {
  799. $return_url = base64_encode($this->_get_article_url());
  800. $readmore_link = JRoute::_('index.php?option=com_user&view=login&return='.$return_url);
  801. $readmore_text = JText::_('Register to read more...');
  802. }
  803. $this->output['buttons']['readmore']['href'] = $readmore_link;
  804. $this->output['buttons']['readmore']['text'] = $readmore_text;
  805. $this->output['buttons']['readmore']['target'] = '_self';
  806. //set it so that Joomla does not show its readmore link
  807. if (isset($this->article->readmore)) $this->article->readmore = 0;
  808. $article_params->set('show_readmore', 0);
  809. }
  810. }
  811. //create a link to manually create the thread if it is not already
  812. $show_button = $this->params->get('enable_initiate_buttons',false);
  813. if ($show_button) {
  814. $user =& JFactory::getUser();
  815. $editAccess = $user->authorize('com_content', 'edit', 'content', 'all');
  816. if ($editAccess) {
  817. if ($this->thread_status || $this->manual_plug) {
  818. //discussion is published
  819. $dbtask = 'unpublish_discussion';
  820. $text = 'UNINITIATE_DISCUSSION';
  821. } elseif (isset($threadinfo->published)) {
  822. //discussion is unpublished
  823. $dbtask = 'publish_discussion';
  824. $text = 'INITIATE_DISCUSSION';
  825. } else {
  826. //discussion is uninitiated
  827. $dbtask = 'create_thread';
  828. $text = 'INITIATE_DISCUSSION';
  829. }
  830. $this->output['buttons']['initiate']['href'] = "javascript: void(0);";
  831. $vars = "&view_override=$view";
  832. $vars .= ($this->params->get('overwrite_readmore',1)) ? "&readmore={$readmore_catch}&show_readmore={$show_readmore}" : "";
  833. $this->output['buttons']['initiate']['js']['onclick'] = "confirmThreadAction(".$this->article->id.",'$dbtask', '$vars', '{$this->_get_article_url()}');";
  834. $this->output['buttons']['initiate']['text'] = JText::_($text);
  835. $this->output['buttons']['initiate']['target'] = '_self';
  836. }
  837. }
  838. //create the discuss this link
  839. if ($this->thread_status || $this->manual_plug) {
  840. if ($link_mode!="never") {
  841. $JFusionForum =& JFusionFactory::getForum($this->jname);
  842. if ($this->replyCount === false) {
  843. $this->replyCount = $JFusionForum->getReplyCount($threadinfo);
  844. }
  845. if ($view=="article") {
  846. if ($link_mode=="article" || $link_mode=="always") {
  847. $this->output['buttons']['discuss']['href'] = JFusionFunction::routeURL($JFusionForum->getThreadURL($threadinfo->threadid), $itemid, $this->jname);
  848. $this->output['buttons']['discuss']['text'] = $linkHTML;
  849. $this->output['buttons']['discuss']['target'] = $linkTarget;
  850. if ($this->params->get('enable_comment_in_forum_button',0)) {
  851. $commentLinkText = $this->params->get('comment_in_forum_link_text', JText::_('ADD_COMMENT'));
  852. $commentLinkHTML = ($this->params->get('comment_in_forum_link_type')=='image') ? "<img style='border:0;' src='$commentLinkText'>" : $commentLinkText;
  853. $this->output['buttons']['comment_in_forum']['href'] = JFusionFunction::routeURL($JFusionForum->getReplyURL($threadinfo->forumid, $threadinfo->threadid), $itemid, $this->jname);
  854. $this->output['buttons']['comment_in_forum']['text'] = $commentLinkHTML;
  855. $this->output['buttons']['comment_in_forum']['target'] = $linkTarget;
  856. }
  857. }
  858. } elseif ($link_mode=="blog" || $link_mode=="always") {
  859. if ($blog_link_mode=="joomla") {
  860. if ($this->article->access <= $JUser->get('aid', 0)) {
  861. $discuss_link = $this->_get_article_url('discussion');
  862. } else {
  863. $return_url = base64_encode($this->_get_article_url('discussion'));
  864. $discuss_link = JRoute::_('index.php?option=com_user&view=login&return='.$return_url);
  865. }
  866. $this->output['buttons']['discuss']['href'] = 'javascript: void(0);';
  867. $this->output['buttons']['discuss']['js']['onclick'] = "toggleDiscussionVisibility(1,'$discuss_link');";
  868. $this->output['buttons']['discuss']['target'] = '_self';
  869. } else

Large files files are truncated, but you can click here to view the full file