/plugins/content/jfusion.php
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
- <?php
- /**
- * @package JFusion
- * @subpackage Plugin_Discussbot
- * @author JFusion development team
- * @copyright Copyright (C) 2008 JFusion. All rights reserved.
- * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
- */
- // no direct access
- defined('_JEXEC' ) or die('Restricted access' );
- /**
- * Load the JFusion framework
- */
- jimport('joomla.plugin.plugin');
- require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.factory.php');
- require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.jfusionpublic.php');
- JPlugin::loadLanguage( 'plg_content_jfusion', JPATH_ADMINISTRATOR );
- /**
- * @package JFusion
- */
- class plgContentJfusion extends JPlugin
- {
- var $params = false;
- var $mode = '';
- var $valid = false;
- var $jname = '';
- var $creationMode = '';
- var $template = 'default';
- var $article = '';
- var $replyCount = false;
- var $output = array();
- var $dbtask = '';
- var $ajaxRequest = 0;
- var $validity_reason = '';
- var $thread_status = '';
- var $manual_plug = false;
- var $manual_threadid = 0;
- var $debug_mode = 0;
- var $debug_output = array();
- var $clear_debug_output = true;
- /**
- * Constructor
- *
- * For php4 compatability we must not use the __constructor as a constructor for
- * plugins because func_get_args ( void ) returns a copy of all passed arguments
- * NOT references. This causes problems with cross-referencing necessary for the
- * observer design pattern.
- */
- function plgContentJfusion(&$subject, $params)
- {
- parent::__construct($subject, $params);
- //make sure Joomla's content helper is loaded
- if (!class_exists('ContentHelperRoute')) {
- require_once JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php';
- }
- //retrieve plugin software for discussion bot
- if ($this->params===false) {
- $this->params = new JParameter( $params->params);
- }
- $this->jname =& $this->params->get('jname',false);
- //determine what mode we are to operate in
- if ($this->params->get("auto_create",0)) {
- $this->mode = ($this->params->get("test_mode",1)) ? 'test' : 'auto';
- } else {
- $this->mode = 'manual';
- }
- $this->creationMode =& $this->params->get('create_thread','load');
- $this->debug_mode = JRequest::getInt('debug_discussionbot',0);
- //$this->debug_mode = 1;
- if ($this->debug_mode) {
- $session =& JFactory::getSession();
- $this->debug_output = $session->get('jfusion.discussion.debug',false);
- if ($this->debug_output!==false) {
- $this->clear_debug_output = false;
- }
- $session->clear('jfusion.discussion.debug');
- if (!is_array($this->debug_output)) $this->debug_output = array();
- }
- }
- function onAfterContentSave(&$subject, $isNew) {
- //check to see if a valid $content object was passed on
- if (!is_object($subject)){
- JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('NO_CONTENT_DATA_FOUND'), 1);
- return false;
- }
- $this->article =& $subject;
- //make sure there is a plugin
- if (empty($this->jname)) {
- return false;
- }
- $this->_debug('onAfterContentSave called');
- //validate the article
- $this->thread_status = $this->_get_thread_status();
- $this->valid = $this->_validate(true);
- $this->_debug('Validity: ' . $this->valid . "; " . $this->validity_reason);
- //ignore auto mode if the article has been manually plugged
- $manually_plugged = preg_match('/\{jfusion_discuss (.*)\}/U', $this->article->introtext . $this->article->fulltext);
- $this->_debug('Checking mode...');
- if ($this->mode=='auto' && empty($manually_plugged)) {
- $this->_debug('In auto mode');
- if ($this->valid) {
- $threadinfo =& $this->_get_thread_info();
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- $forumid = $JFusionForum->getDefaultForum($this->params, $this->article);
- if (($this->creationMode=='load') ||
- ($this->creationMode=='new' && ($isNew || (!$isNew && $this->thread_status))) ||
- ($this->creationMode=='reply' && $this->thread_status)) {
- //update/create thread
- $status = $this->_check_thread_exists();
- } else {
- $this->_debug('Article did not meet requirements to update/create thread');
- }
- } elseif ($this->creationMode=='new' && $isNew) {
- $this->_debug('Failed validity test but creationMode is set to new and this is a new article');
- $mainframe = & JFactory::getApplication();
- $publishUp = JFactory::getDate($this->article->publish_up)->toUnix();
- $now = JFactory::getDate('now', $mainframe->getCfg('offset'))->toUnix();
- if ($now < $publish_up || !$this->article->state) {
- $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.');
- //the publish date is set for the future so create an entry in the
- //database so that the thread is created when the publish date arrives
- $placeholder = new stdClass();
- $placeholder->threadid = 0;
- $placeholder->forumid = 0;
- $placeholder->postid = 0;
- JFusionFunction::updateDiscussionBotLookup($this->article->id, $placeholder, $this->jname);
- }
- }
- } elseif ($this->mode=='test' && empty($manually_plugged)) {
- //recheck validity without stipulation
- $this->valid = $this->_validate();
- $this->_debug('In test mode thus not creating the article');
- $threadinfo =& $this->_get_thread_info();
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- $content = "<u>" . $this->article->title . "</u><br />";
- if (!empty($threadinfo)) {
- $content .= JText::_('DISCUSSBOT_TEST_MODE') . "<img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
- if ($threadinfo->published) {
- $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_PUBLISHED') . "<br />";
- } else {
- $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_UNPUBLISHED') . "<br />";
- }
- $content .= JText::_('THREADID') . ": " . $threadinfo->threadid . "<br />";
- $content .= JText::_('FORUMID') . ": " . $threadinfo->forumid . "<br />";
- $content .= JText::_('FIRST_POSTID') . ": " . $threadinfo->postid. "<br />";
- $forumlist =& $this->_get_lists('forum');
- if (!isset($forumlist[$threadinfo->forumid])) {
- $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('FORUM_NOT_EXIST') . "<br />";
- }
- $forumthread = $JFusionForum->getThread($threadinfo->threadid);
- if (empty($forumthread)) {
- $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('THREAD_NOT_EXIST') . "<br />";
- }
- } else {
- $valid = ($this->valid) ? JText::_('YES') : JText::_('NO');
- if (!$this->valid) {
- $content .= JText::_('DISCUSSBOT_TEST_MODE') . "<img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/x.png' style='margin-left:5px;'><br/>";
- $content .= JText::_('VALID') . ": " . $valid . "<br />";
- $content .= JText::_('INVALID_REASON') . ": " . $this->validity_reason . "<br />";
- } else {
- $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
- $content .= JText::_('VALID_REASON') . ": " . $this->validity_reason . "<br />";
- $content .= JText::_('STATUS') . ": " . JText::_('UNINITIALIZED_THREAD_WILL_BE_CREATED') . "<br />";
- $forumid = $JFusionForum->getDefaultForum($this->params, $this->article);
- $content .= JText::_('FORUMID') . ": " . $forumid . "<br />";
- $author = $JFusionForum->getThreadAuthor($this->params, $this->article);
- $content .= JText::_('AUTHORID') . ": " . $author . "<br />";
- }
- }
- JError::raiseNotice('500', $content);
- } else {
- $this->_debug('In manual mode...checking to see if article has been initialized');
- $threadinfo =& $this->_get_thread_info();
- if (!empty($threadinfo) && $threadinfo->published == 1 && $threadinfo->manual == 1) {
- $this->_debug('Article has been initialized...updating thread');
- //update thread
- $status = $this->_check_thread_exists();
- } else {
- $this->_debug('Article has not been initialized');
- }
- }
- $this->_debug('onAfterContentSave complete', true);
- }
- function onPrepareContent(&$subject, $params)
- {
- $mainframe = & JFactory::getApplication();
- //reset some vars
- $this->manual_plug = false;
- $this->manual_threadid = 0;
- if ($this->clear_debug_output) {
- $this->debug_output = array();
- }
- $this->thread_status = '';
- $this->validity_reason = '';
- $this->_debug('onPrepareContent called');
- //check to see if a valid $content object was passed on
- if (!is_object($subject)){
- JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('NO_CONTENT_DATA_FOUND'), 1);
- return false;
- }
- //make sure there is a plugin
- if (empty($this->jname)) {
- return false;
- }
- //prevent any output by the plugins (this could prevent cookies from being passed to the header)
- ob_start();
- //set some variables needed throughout
- $this->template = $this->params->get("template","default");
- if (!defined('DISCUSSION_TEMPLATE_PATH')) {
- //let's first check for customized files in Joomla's template directory
- $app =& JFactory::getApplication();
- $JoomlaTemplateOverride = JPATH_BASE.DS.'templates'. DS .$app->getTemplate() . DS. 'html' . DS . 'plg_content_jfusion' . DS;
- if (file_exists($JoomlaTemplateOverride)) {
- define('DISCUSSION_TEMPLATE_PATH', $JoomlaTemplateOverride);
- define('DISCUSSION_TEMPLATE_URL', JFusionFunction::getJoomlaURL() . 'templates/' . $app->getTemplate() . 'html/plg_content_jfusion/');
- } else {
- define('DISCUSSION_TEMPLATE_PATH',JPATH_BASE.DS.'plugins'.DS.'content'.DS.'discussbot'.DS.'tmpl'.DS.$this->template.DS);
- define('DISCUSSION_TEMPLATE_URL',JFusionFunction::getJoomlaURL().'plugins/content/discussbot/tmpl/'.$this->template.'/');
- }
- }
- $this->article =& $subject;
- //make sure we have an actual article
- if ($this->article->id) {
- $this->dbtask = JRequest::getVar('dbtask', 'render_content', 'post');
- $skip_new_check = ($this->dbtask=='create_thread') ? true : false;
- $this->thread_status = $this->_get_thread_status();
- $this->valid = $this->_validate($skip_new_check);
- $this->_debug('Validity: ' . $this->valid . "; " . $this->validity_reason);
- $this->ajaxRequest = JRequest::getInt('ajax_request',0);
- if ($this->dbtask == 'create_thread') {
- //this article has been manually initiated for discussion
- $this->_create_thread();
- } elseif (($this->dbtask == 'create_post' || $this->dbtask == 'create_threadpost') && $this->params->get("enable_quickreply",false)) {
- //a quick reply has been submitted so let's create the post
- $this->_create_post();
- } elseif ($this->dbtask == 'unpublish_discussion') {
- //an article has been "uninitiated"
- $this->_unpublish_discussion();
- } elseif ($this->dbtask == 'publish_discussion') {
- //an article has been "reinitiated"
- $this->_publish_discussion();
- }
- //save the visibility of the posts if applicable
- $show_discussion = JRequest::getVar('show_discussion','');
- if ($show_discussion!=='') {
- $JSession =& JFactory::getSession();
- $JSession->set('jfusion.discussion.visibility',(int) $show_discussion);
- }
- //check for some specific ajax requests
- if ($this->ajaxRequest) {
- //check to see if this is an ajax call to update the pagination
- if ($this->params->get('enable_pagination',1) && $this->dbtask == 'update_pagination') {
- $this->_update_pagination();
- }
- if ($this->params->get('show_posts',1) && $this->dbtask == 'update_posts') {
- $this->_update_posts();
- }
- if ($this->dbtask=='update_content') {
- $threadinfo =& $this->_get_thread_info();
- if (!empty($threadinfo->published)) {
- //content is now published so display it
- die($this->_render_discussion_content($threadinfo));
- } else {
- //content is now not published so remove it
- die();
- }
- }
- if ($this->dbtask == 'update_buttons') {
- $this->_update_buttons();
- }
- if ($show_discussion!=='') {
- die('jfusion.discussion.visibility set to '.$show_discussion);
- }
- die("Discussion bot ajax request made but it doesn't seem to have been picked up");
- }
- //add scripts to header
- static $scriptsLoaded;
- if (empty($scriptsLoaded)) {
- $this->_load_scripts();
- $scriptsLoaded = 1;
- }
- //generate content
- $this->_prepare_content();
- }
- ob_end_clean();
- return true;
- }
- function _prepare_content()
- {
- JHTML::_( 'behavior.mootools' );
- $this->_debug('Preparing content');
- $content = '';
- //get the jfusion forum object
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- //find any {jfusion_discuss...} to manually plug
- $this->_debug('Finding all manually added plugs');
- preg_match_all('/\{jfusion_discuss (.*)\}/U',$this->article->text,$matches);
- $this->_debug(count($matches[1]) . ' matches found');
- foreach($matches[1] as $id) {
- //only use the first and get rid of the others
- if (empty($this->manual_plug)) {
- $this->manual_plug = true;
- $this->_debug('Plugging for thread id ' . $id);
- //get the existing thread information
- $threadinfo = $JFusionForum->getThread($id);
- if (!empty($threadinfo)) {
- //override thread status
- $this->thread_status = true;
- $content = $this->_render($threadinfo);
- $this->article->text = str_replace("{jfusion_discuss $id}",$content,$this->article->text);
- } else {
- $this->article->text = str_replace("{jfusion_discuss $id}",JText::_("THREADID_NOT_FOUND"),$this->article->text);
- }
- if ($this->mode=='test') {
- $content = "<div class='jfusionclearfix' style='border:1px solid #ECF8FD; background-color:#ECF8FD; margin-top:10px; margin-bottom:10px;'>\n";
- $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
- $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_PUBLISHED') . "<br />";
- $threadinfo = $JFusionForum->getThread($id);
- if (empty($threadinfo)) {
- $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('THREAD_NOT_EXIST') . "<br />";
- } else {
- $content .= JText::_('THREADID') . ": " . $threadinfo->threadid . "<br />";
- $content .= JText::_('FORUMID') . ": " . $threadinfo->forumid . "<br />";
- $content .= JText::_('FIRST_POSTID') . ": " . $threadinfo->postid. "<br />";
- }
- $forumlist =& $this->_get_lists('forum');
- if (!isset($forumlist[$threadinfo->forumid])) {
- $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('FORUM_NOT_EXIST') . "<br />";
- }
- $content .= "</div>\n";
- }
- } else {
- $this->_debug('Removing plug for thread ' . $id);
- $this->article->text = str_replace("{jfusion_discuss $id}",'',$this->article->text);
- }
- }
- //check to see if the fulltext has a manual plug if we are in a blog view
- if (!$this->manual_plug && JRequest::getVar('view')!='article') {
- preg_match('/\{jfusion_discuss (.*)\}/U',$this->article->fulltext,$match);
- if (!empty($match)) {
- $this->_debug("No plugs in text but found plugs in fulltext");
- $this->manual_plug = true;
- $this->manual_threadid = $match[1];
- //create buttons for the manually plugged article
- $content = $this->_render_buttons();
- //append the content
- $this->article->text .= $content;
- }
- }
- //check for auto mode if not already manually plugged
- if (!$this->manual_plug) {
- $this->_debug('Article not manually plugged...checking for other mode');
- $threadinfo =& $this->_get_thread_info();
- //create the thread if this article has been validated
- if ($this->mode=='auto') {
- $this->_debug('In auto mode');
- if ($this->valid) {
- $status = $this->_check_thread_exists();
- }
- $content = $this->_render($threadinfo);
- } elseif ($this->mode=='test') {
- $this->_debug('In test mode');
- //get the existing thread information
- $content = "<div class='jfusionclearfix' style='border:1px solid #ECF8FD; background-color:#ECF8FD; margin-top:10px; margin-bottom:10px;'>\n";
- if (!empty($threadinfo)) {
- $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
- if ($threadinfo->published) {
- $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_PUBLISHED') . "<br />";
- } else {
- $content .= JText::_('STATUS') . ": " . JText::_('INITIALIZED_AND_UNPUBLISHED') . "<br />";
- }
- $content .= JText::_('THREADID') . ": " . $threadinfo->threadid . "<br />";
- $content .= JText::_('FORUMID') . ": " . $threadinfo->forumid . "<br />";
- $content .= JText::_('FIRST_POSTID') . ": " . $threadinfo->postid. "<br />";
- $forumlist =& $this->_get_lists('forum');
- if (!isset($forumlist[$threadinfo->forumid])) {
- $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('FORUM_NOT_EXIST') . "<br />";
- }
- $forumthread = $JFusionForum->getThread($threadinfo->threadid);
- if (empty($forumthread)) {
- $content .= "<span style='color:red; font-weight:bold;'>" . JText::_('WARNING') . "</span>: " . JText::_('THREAD_NOT_EXIST') . "<br />";
- }
- } else {
- $valid = ($this->valid) ? JText::_('YES') : JText::_('NO');
- if (!$this->valid) {
- $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/x.png' style='margin-left:5px;'><br/>";
- $content .= JText::_('VALID') . ": " . $valid . "<br />";
- $content .= JText::_('INVALID_REASON') . ": " . $this->validity_reason . "<br />";
- } else {
- $content .= "<b>" . JText::_('DISCUSSBOT_TEST_MODE') . "</b><img src='".JFusionFunction::getJoomlaURL()."plugins/content/discussbot/images/check.png' style='margin-left:5px;'><br/>";
- $content .= JText::_('VALID_REASON') . ": " . $this->validity_reason . "<br />";
- $content .= JText::_('STATUS') . ": " . JText::_('UNINITIALIZED_THREAD_WILL_BE_CREATED') . "<br />";
- $forumid = $JFusionForum->getDefaultForum($this->params, $this->article);
- $content .= JText::_('FORUMID') . ": " . $forumid . "<br />";
- $author = $JFusionForum->getThreadAuthor($this->params, $this->article);
- $content .= JText::_('AUTHORID') . ": " . $author . "<br />";
- }
- }
- $content .= "</div>\n";
- } elseif (!empty($threadinfo->manual)) {
- $this->_debug('In manual mode but article has been initialized');
- //this article was generated by the initialize button
- $content = $this->_render($threadinfo);
- } else {
- $this->_debug('In manual mode');
- //in manual mode so just create the buttons
- $content = $this->_render_buttons();
- }
- //append the content
- $this->article->text .= $content;
- }
- static $taskFormLoaded;
- if (empty($taskFormLoaded)) {
- $this->_debug('Adding task form');
- //tak on the task form; it only needs to be added once which will be used for create_thread
- $uri = JFactory::getURI();
- $url = $uri->toString(array('path', 'query', 'fragment'));
- $content = "<form style='display:none;' id='JFusionTaskForm' name='JFusionTaskForm' method='post' action='".$url."'>\n";
- $content .= "<input type='hidden' name='articleId' value='' />\n";
- $content .= "<input type='hidden' name='dbtask' value='' />\n";
- $content .= "</form>\n";
- $this->article->text .= $content;
- $taskFormLoaded = 1;
- }
- if ($this->debug_mode) {
- require_once(JPATH_ADMINISTRATOR .DS.'components'.DS.'com_jfusion'.DS.'models'.DS.'model.debug.php');
- ob_start();
- debug::show($this->debug_output, 'Discussion bot debug info',1);
- $this->article->text .= ob_get_contents();
- ob_end_clean();
- }
- }
- function _create_thread()
- {
- $JoomlaUser =& JFactory::getUser();
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- $mainframe = & JFactory::getApplication();
- if ($return = JRequest::getVar('return')) {
- $url = base64_decode($return);
- } else {
- $uri = JFactory::getURI();
- $url = $uri->toString(array('path', 'query', 'fragment'));
- $url = JRoute::_($url, false);
- if ($uri->getVar('view')=='article') {
- //tak on the discussion jump to
- $url .= "#discussion";
- $JSession =& JFactory::getSession();
- $JSession->set('jfusion.discussion.visibility',1);
- }
- }
- //make sure the article submitted matches the one loaded
- $submittedArticleId = JRequest::getInt('articleId', 0, 'post');
- $editAccess = $JoomlaUser->authorize('com_content', 'edit', 'content', 'all');
- if ($editAccess && $this->valid && $submittedArticleId == $this->article->id) {
- $status = $this->_check_thread_exists(1);
- if ($status['error']) {
- if (is_array($status['error'])) {
- foreach($status['error'] as $err) {
- $mainframe->enqueueMessage('error',$this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'). ': ' . $err);
- }
- } else {
- $mainframe->enqueueMessage('error',$this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'). ': ' . $status['error']);
- }
- $mainframe->redirect($url);
- } else {
- $mainframe->redirect($url, JText::sprintf('THREAD_CREATED_SUCCESSFULLY',$this->article->title));
- }
- }
- }
- function _create_post()
- {
- $JoomlaUser =& JFactory::getUser();
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- //define some variables
- $allowGuests =& $this->params->get("quickreply_allow_guests",0);
- $ajaxEnabled = ($this->params->get("enable_ajax",1) && $this->ajaxRequest);
- //process quick replies
- if ($allowGuests || !$JoomlaUser->guest) {
- //make sure something was submitted
- $quickReplyText = JRequest::getVar('quickReply', '', 'POST');
- if (!empty($quickReplyText)) {
- //retrieve the userid from forum software
- if ($allowGuests && $JoomlaUser->guest) {
- $userinfo = new stdClass();
- $userinfo->guest = 1;
- $captcha_verification = $JFusionForum->verifyCaptcha($this->params);
- } else {
- $JFusionUser =& JFusionFactory::getUser($this->jname);
- $userinfo = $JFusionUser->getUser($JoomlaUser);
- $userinfo->guest = 0;
- //we have a user logged in so ignore captcha
- $captcha_verification = true;
- }
- if ($captcha_verification) {
- if ($this->dbtask=='create_threadpost') {
- $status = $this->_check_thread_exists();
- $threadinfo = $status['threadinfo'];
- } elseif ($this->dbtask=="create_post") {
- $threadinfo =& $this->_get_thread_info();
- }
- //create the post
- if (!empty($threadinfo->threadid) && !empty($threadinfo->forumid)) {
- $status = $JFusionForum->createPost($this->params, $threadinfo, $this->article, $userinfo);
- if ($status['error']){
- if ($ajaxEnabled) {
- //output the error
- die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . $status['error']);
- } else {
- JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), $status['error'],1);
- }
- } else {
- if ($ajaxEnabled) {
- //if pagination is set, set $limitstart so that we go to the added post
- if ($this->params->get('enable_pagination',true)) {
- $replyCount = $JFusionForum->getReplyCount($threadinfo);
- $application =& JFactory::getApplication();
- $limit = $application->getUserStateFromRequest( 'global.list.limit', 'limit', 14, 'int' );
- if ($this->params->get("sort_posts",'ASC')=='ASC') {
- $limitstart = floor(($replyCount-1)/$limit) * $limit;
- } else {
- $limitstart = 0;
- }
- JRequest::setVar('limitstart',$limitstart);
- }
- $posts = $JFusionForum->getPosts($this->params, $threadinfo);
- $this->output = array();
- $this->output['posts'] = $this->_prepare_posts_output($posts);
- //take note of the created post
- $this->output['submitted_postid'] = $status['postid'];
- if (isset($status['post_moderated'])) {
- $this->output['post_moderated'] = $status['post_moderated'];
- } else {
- $this->output['post_moderated'] = 0;
- }
- //output only the new post div
- $this->_render_file('default_posts.php','die');
- } else {
- if ($this->params->get('jumpto_new_post',0)) {
- $jumpto = (isset($status['postid'])) ? "post" . $status['postid'] : '';
- } else {
- $jumpto = '';
- }
- $url = $this->_get_article_url($jumpto,'',false);
- if (isset($status['post_moderated'])) {
- $text = ($status['post_moderated']) ? 'SUCCESSFUL_POST_MODERATED' : 'SUCCESSFUL_POST';
- } else {
- $text = 'SUCCESSFUL_POST';
- }
- $mainframe = & JFactory::getApplication();
- $mainframe->redirect($url, JText::_($text));
- }
- }
- } else {
- if ($ajaxEnabled) {
- die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . JText::_('THREADID_NOT_FOUND'));
- } else {
- JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('THREADID_NOT_FOUND'),1);
- }
- }
- } else {
- if ($ajaxEnabled) {
- die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . JText::_('CAPTCHA_INCORRECT'));
- } else {
- JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('CAPTCHA_INCORRECT'),1);
- }
- }
- } else {
- if ($ajaxEnabled) {
- die($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR') . ': ' . JText::_('QUICKEREPLY_EMPTY'));
- } else {
- JFusionFunction::raiseWarning($this->jname . ' ' . JText::_('DISCUSSBOT_ERROR'), JText::_('QUICKEREPLY_EMPTY'),1);
- }
- }
- }
- //if ajax is enabled, then something has gone wrong so die
- if ($ajaxEnabled) die(JText::_('DISCUSSBOT_ERROR'));
- }
- function _unpublish_discussion()
- {
- $JoomlaUser =& JFactory::getUser();
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- //make sure the article submitted matches the one loaded
- $submittedArticleId = JRequest::getInt('articleId', 0, 'post');
- $editAccess = $JoomlaUser->authorize('com_content', 'edit', 'content', 'all');
- if ($editAccess && $this->valid && $submittedArticleId == $this->article->id) {
- $threadinfo =& $this->_get_thread_info();
- if (!empty($threadinfo)) {
- //created by discussion bot thus update the look up table
- JFusionFunction::updateDiscussionBotLookup($this->article->id, $threadinfo, $this->jname, 0, $threadinfo->manual);
- } else {
- //manually plugged thus remove any db plugin tags
- $jdb =& JFactory::getDBO();
- //retrieve the original text
- $query = "SELECT `introtext`, `fulltext` FROM #__content WHERE id = " . $this->article->id;
- $jdb->setQuery($query);
- $texts = $jdb->loadObject();
- //remove any {jfusion_discuss...}
- $fulltext = preg_replace('/\{jfusion_discuss (.*)\}/U','',$texts->fulltext, -1, $fullTextCount);
- $introtext = preg_replace('/\{jfusion_discuss (.*)\}/U','',$texts->introtext, -1, $introTextCount);
- if (!empty($fullTextCount) || !empty($introTextCount)) {
- $query = "UPDATE #__content SET `fulltext` = " . $jdb->Quote($fulltext) . ", `introtext` = " .$jdb->Quote($introtext) . " WHERE id = " . (int) $this->article->id;
- $jdb->setQuery($query);
- $jdb->query();
- }
- }
- if ($this->ajaxRequest) {
- $this->thread_status = $this->_get_thread_status();
- die($this->_render_buttons(true));
- }
- } else {
- die('Access denied!');
- }
- }
- function _publish_discussion()
- {
- $JoomlaUser =& JFactory::getUser();
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- //make sure the article submitted matches the one loaded
- $submittedArticleId = JRequest::getInt('articleId', 0, 'post');
- $editAccess = $JoomlaUser->authorize('com_content', 'edit', 'content', 'all');
- if ($editAccess && $this->valid && $submittedArticleId == $this->article->id) {
- $threadinfo =& $this->_get_thread_info();
- JFusionFunction::updateDiscussionBotLookup($this->article->id, $threadinfo, $this->jname, 1, $threadinfo->manual);
- if ($this->ajaxRequest) {
- $this->thread_status = $this->_get_thread_status();
- die($this->_render_buttons(true));
- }
- } else {
- die('Access denied!');
- }
- }
- function _render(&$threadinfo)
- {
- $this->_debug('Beginning rendering content');
- if (!empty($threadinfo)) {
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- $this->replyCount = $JFusionForum->getReplyCount($threadinfo);
- }
- $view = JRequest::getVar('view');
- //let's only show quick replies and posts on the article view
- if ($view=="article") {
- $content = $this->_render_buttons();
- $JSession =& JFactory::getSession();
- if (!empty($threadinfo->manual) && empty($threadinfo->published)) {
- $this->_debug('Discussion content not displayed as this discussion is unpublished');
- $display = 'none';
- $generate_guts = false;
- } else {
- if ($JSession->get('jfusion.discussion.visibility',0) || empty($threadinfo) && $this->creationMode == 'reply') {
- //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
- $display = 'block';
- } else {
- $display = ($this->params->get('show_toggle_posts_link',1) && $this->params->get('collapse_discussion',1)) ? 'none' : 'block';
- }
- $generate_guts = true;
- }
- $content .= "<div style='float:none; display:{$display};' id='discussion'>\n";
- if ($generate_guts) {
- $content .= $this->_render_discussion_content($threadinfo);
- }
- $content .= "</div>";
- } else {
- $content = $this->_render_buttons();
- }
- return $content;
- }
- function _render_discussion_content(&$threadinfo)
- {
- $this->_debug('Rendering discussion content');
- //setup parameters
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- $allowGuests =& $this->params->get("quickreply_allow_guests",0);
- $JoomlaUser =& JFactory::getUser();
- //make sure the user exists in the software before displaying the quick reply
- $JFusionUser =& JFusionFactory::getUser($this->jname);
- $JFusionUserinfo = $JFusionUser->getUser($JoomlaUser);
- $action_url = $this->_get_article_url('','',false);
- $this->output = array();
- $this->output['reply_count'] = $this->replyCount;
- if (!empty($threadinfo)) {
- //prepare quick reply box if enabled
- if ($this->params->get("enable_quickreply")){
- $threadLocked = $JFusionForum->getThreadLockedStatus($threadinfo->threadid);
- $show_form = ($allowGuests || !$JoomlaUser->guest) ? true : false;
- if ($threadLocked) {
- $this->output['reply_form_error'] = $this->params->get("locked_msg");
- $this->output['show_reply_form'] = false;
- } elseif ($show_form) {
- if (!$JoomlaUser->guest && empty($JFusionUserinfo)) {
- $this->output['reply_form_error'] = $this->jname . ': ' . JText::_('USER_NOT_EXIST')."\n";
- $this->output['show_reply_form'] = false;
- } else {
- $showGuestInputs = ($allowGuests && $JoomlaUser->guest) ? true : false;
- $this->output['reply_form'] = "<form id='jfusionQuickReply{$this->article->id}' name='jfusionQuickReply{$this->article->id}' method=post action='".$action_url."'>\n";
- $this->output['reply_form'] .= "<input type=hidden name='dbtask' value='create_post'>\n";
- $this->output['reply_form'] .= $JFusionForum->createQuickReply($this->params,$showGuestInputs);
- $this->output['reply_form'] .= "</form>";
- $this->output['show_reply_form'] = true;
- }
- } else {
- $this->output['reply_form_error'] = $this->params->get("must_login_msg");
- $this->output['show_reply_form'] = false;
- }
- }
- //add posts to content if enabled
- if ($this->params->get("show_posts")) {
- //get the posts
- $posts = $JFusionForum->getPosts($this->params, $threadinfo);
- if (!empty($posts)){
- $this->output['posts'] = $this->_prepare_posts_output($posts);
- }
- if ($this->params->get("enable_pagination",1)) {
- $this->output['post_pagination'] = "<div id='jfusionPostPagination'>\n";
- if ($this->replyCount) {
- $application = JFactory::getApplication() ;
- $limitstart = JRequest::getInt( 'limitstart', 0 );
- $limit = $application->getUserStateFromRequest( 'global.list.limit', 'limit', 5, 'int' );
- jimport('joomla.html.pagination');
- $pageNav = new JPagination($this->replyCount, $limitstart, $limit );
- $this->output['post_pagination'] .= "<form method='post' name='jfusionPaginationForm' action='$action_url'>\n";
- $this->output['post_pagination'] .= $pageNav->getListFooter();
- $this->output['post_pagination'] .= "</form>\n";
- }
- $this->output['post_pagination'] .= "</div>\n";
- } else {
- $this->output['post_pagination'] = '';
- }
- } else {
- $this->output['posts'] = '';
- $this->output['post_pagination'] = '';
- }
- } elseif ($this->creationMode=='reply') {
- //prepare quick reply box if enabled
- $show_form = ($allowGuests || (!$JoomlaUser->guest && !empty($JFusionUserinfo))) ? true : false;
- if ($show_form) {
- if (!$JoomlaUser->guest && empty($JFusionUserinfo)) {
- $this->output['reply_form_error'] = $this->jname . ': ' . JText::_('USER_NOT_EXIST')."\n";
- $this->output['show_reply_form'] = false;
- } else {
- $showGuestInputs = ($allowGuests && $JoomlaUser->guest) ? true : false;
- $this->output['reply_form'] = "<form id='jfusionQuickReply{$this->article->id}' name='jfusionQuickReply{$this->article->id}' method=post action='".$actionUrl."'>\n";
- $this->output['reply_form'] .= "<input type=hidden name='dbtask' value='create_threadpost'/>\n";
- $this->output['reply_form'] .= $JFusionForum->createQuickReply($this->params,$showGuestInputs);
- $this->output['reply_form'] .= "</form>";
- $this->output['show_reply_form'] = true;
- }
- } else {
- $this->output['reply_form_error'] = $this->params->get("must_login_msg");
- $this->output['show_reply_form'] = false;
- }
- }
- //populate the template
- $content = $this->_render_file('default.php','capture');
- return $content;
- }
- function _render_buttons($innerhtml = false)
- {
- $this->_debug('Rendering buttons');
- //setup some variables
- $threadinfo =& $this->_get_thread_info();
- $JUser =& JFactory::getUser();
- $attribs = new JParameter( $this->article->attribs);
- $itemid =& $this->params->get("itemid");
- $link_text =& $this->params->get("link_text");
- $link_type=& $this->params->get("link_type",'text');
- $link_mode=& $this->params->get("link_mode",'always');
- $blog_link_mode=& $this->params->get("blog_link_mode",'forum');
- $linkHTML = ($link_type=='image') ? "<img style='border:0;' src='$link_text'>" : $link_text;
- $linkTarget =& $this->params->get('link_target','_parent');
- //prevent notices and warnings in default_buttons.php if there are no buttons to display
- $this->output = array();
- $this->output['buttons'] = array();
- if (isset($this->article->params)) {
- //blog view
- $article_params =& $this->article->params;
- $readmore_catch = $this->article->readmore;
- $show_readmore = $article_params->get('show_readmore');
- } elseif (isset($this->article->parameters)) {
- //article view
- $article_params =& $this->article->parameters;
- $readmore_catch = JRequest::getInt('readmore');
- $override = JRequest::getInt('show_readmore',false);
- $show_readmore = ($override!==false) ? $override : $article_params->get('show_readmore');
- }
- //let's overwrite the readmore link with our own
- //needed as in the case of updating the buttons via ajax which calls the article view
- $view = ($override = JRequest::getVar('view_override')) ? $override : JRequest::getVar('view');
- if ($view != 'article' && $this->params->get('overwrite_readmore',1)) {
- //make sure the readmore link is enabled for this article
- if (($show_readmore != 0 && $readmore_catch != 0)) {
- if ($this->article->access <= $JUser->get('aid', 0)) {
- $readmore_link = $this->_get_article_url();
- if ($readmore = $attribs->get('readmore')) {
- $readmore_text = $readmore;
- } else {
- $readmore_text = JText::_('Read more...');
- }
- } else {
- $return_url = base64_encode($this->_get_article_url());
- $readmore_link = JRoute::_('index.php?option=com_user&view=login&return='.$return_url);
- $readmore_text = JText::_('Register to read more...');
- }
- $this->output['buttons']['readmore']['href'] = $readmore_link;
- $this->output['buttons']['readmore']['text'] = $readmore_text;
- $this->output['buttons']['readmore']['target'] = '_self';
- //set it so that Joomla does not show its readmore link
- if (isset($this->article->readmore)) $this->article->readmore = 0;
- $article_params->set('show_readmore', 0);
- }
- }
- //create a link to manually create the thread if it is not already
- $show_button = $this->params->get('enable_initiate_buttons',false);
- if ($show_button) {
- $user =& JFactory::getUser();
- $editAccess = $user->authorize('com_content', 'edit', 'content', 'all');
- if ($editAccess) {
- if ($this->thread_status || $this->manual_plug) {
- //discussion is published
- $dbtask = 'unpublish_discussion';
- $text = 'UNINITIATE_DISCUSSION';
- } elseif (isset($threadinfo->published)) {
- //discussion is unpublished
- $dbtask = 'publish_discussion';
- $text = 'INITIATE_DISCUSSION';
- } else {
- //discussion is uninitiated
- $dbtask = 'create_thread';
- $text = 'INITIATE_DISCUSSION';
- }
- $this->output['buttons']['initiate']['href'] = "javascript: void(0);";
- $vars = "&view_override=$view";
- $vars .= ($this->params->get('overwrite_readmore',1)) ? "&readmore={$readmore_catch}&show_readmore={$show_readmore}" : "";
- $this->output['buttons']['initiate']['js']['onclick'] = "confirmThreadAction(".$this->article->id.",'$dbtask', '$vars', '{$this->_get_article_url()}');";
- $this->output['buttons']['initiate']['text'] = JText::_($text);
- $this->output['buttons']['initiate']['target'] = '_self';
- }
- }
- //create the discuss this link
- if ($this->thread_status || $this->manual_plug) {
- if ($link_mode!="never") {
- $JFusionForum =& JFusionFactory::getForum($this->jname);
- if ($this->replyCount === false) {
- $this->replyCount = $JFusionForum->getReplyCount($threadinfo);
- }
- if ($view=="article") {
- if ($link_mode=="article" || $link_mode=="always") {
- $this->output['buttons']['discuss']['href'] = JFusionFunction::routeURL($JFusionForum->getThreadURL($threadinfo->threadid), $itemid, $this->jname);
- $this->output['buttons']['discuss']['text'] = $linkHTML;
- $this->output['buttons']['discuss']['target'] = $linkTarget;
- if ($this->params->get('enable_comment_in_forum_button',0)) {
- $commentLinkText = $this->params->get('comment_in_forum_link_text', JText::_('ADD_COMMENT'));
- $commentLinkHTML = ($this->params->get('comment_in_forum_link_type')=='image') ? "<img style='border:0;' src='$commentLinkText'>" : $commentLinkText;
- $this->output['buttons']['comment_in_forum']['href'] = JFusionFunction::routeURL($JFusionForum->getReplyURL($threadinfo->forumid, $threadinfo->threadid), $itemid, $this->jname);
- $this->output['buttons']['comment_in_forum']['text'] = $commentLinkHTML;
- $this->output['buttons']['comment_in_forum']['target'] = $linkTarget;
- }
- }
- } elseif ($link_mode=="blog" || $link_mode=="always") {
- if ($blog_link_mode=="joomla") {
- if ($this->article->access <= $JUser->get('aid', 0)) {
- $discuss_link = $this->_get_article_url('discussion');
- } else {
- $return_url = base64_encode($this->_get_article_url('discussion'));
- $discuss_link = JRoute::_('index.php?option=com_user&view=login&return='.$return_url);
- }
- $this->output['buttons']['discuss']['href'] = 'javascript: void(0);';
- $this->output['buttons']['discuss']['js']['onclick'] = "toggleDiscussionVisibility(1,'$discuss_link');";
- $this->output['buttons']['discuss']['target'] = '_self';
- } else …
Large files files are truncated, but you can click here to view the full file