Example #1
0
 public static function getCommentsCount($object_id, $object_group = 'com_content', $filter = '')
 {
     $acl = JCommentsFactory::getACL();
     $options = array();
     $options['object_id'] = (int) $object_id;
     $options['object_group'] = trim($object_group);
     $options['published'] = $acl->canPublish() || $acl->canPublishForObject($object_id, $object_group) ? null : 1;
     $options['filter'] = $filter;
     return JCommentsModel::getCommentsCount($options);
 }
Example #2
0
 public static function deleteComments($object_id, $object_group = 'com_content')
 {
     $object_group = trim($object_group);
     $oids = is_array($object_id) ? implode(',', $object_id) : $object_id;
     $db = JFactory::getDbo();
     $query = "SELECT id FROM #__jcomments " . "\n WHERE object_group = " . $db->Quote($object_group) . "\n AND object_id IN (" . $oids . ")";
     $db->setQuery($query);
     $cids = $db->loadColumn();
     JCommentsModel::deleteCommentsByIds($cids);
     $query = "DELETE FROM #__jcomments_objects " . " WHERE object_group = " . $db->Quote($object_group) . " AND object_id = " . $db->Quote($object_id);
     $db->setQuery($query);
     $db->execute();
     return true;
 }
 if ($separate_comments) {
     // Comments integration trigger when separate_comments in plugin is set to yes/1
     if (isset($match->team1_result)) {
         $joomleage_comments_object_group = 'com_joomleague_matchreport';
     } else {
         $joomleage_comments_object_group = 'com_joomleague_nextmatch';
     }
 } else {
     // Comments integration trigger when separate_comments in plugin is set to no/0
     $joomleage_comments_object_group = 'com_joomleague';
 }
 $options = array();
 $options['object_id'] = (int) $match->id;
 $options['object_group'] = $joomleage_comments_object_group;
 $options['published'] = 1;
 $count = JCommentsModel::getCommentsCount($options);
 if ($count == 1) {
     $imgTitle = $count . ' ' . JText::_('COM_JOOMLEAGUE_TEAMPLAN_COMMENTS_COUNT_SINGULAR');
     if ($this->config['show_comments_count'] == 1) {
         $href_text = JHTML::image(JURI::root() . 'media/com_joomleague/jl_images/discuss_active.gif', $imgTitle, array(' title' => $imgTitle, ' border' => 0, ' style' => 'vertical-align: middle'));
     } elseif ($this->config['show_comments_count'] == 2) {
         $href_text = '<span title="' . $imgTitle . '">(' . $count . ')</span>';
     }
     //Link
     if (isset($match->team1_result)) {
         $link = JoomleagueHelperRoute::getMatchReportRoute($this->project->slug, $match->id) . '#comments';
     } else {
         $link = JoomleagueHelperRoute::getNextMatchRoute($this->project->slug, $match->id) . '#comments';
     }
     $viewComment = JHTML::link($link, $href_text);
     echo $viewComment;
Example #4
0
 public static function remove()
 {
     JCommentsSecurity::checkToken();
     $cid = JCommentsInput::getVar('cid', array());
     if (is_array($cid)) {
         $db = JCommentsFactory::getDBO();
         $config = JCommentsFactory::getConfig();
         if ($config->getInt('delete_mode') == 0) {
             JCommentsModel::deleteCommentsByIds($cid);
         } else {
             $comment = new JCommentsTableComment($db);
             foreach ($cid as $id) {
                 $comment->reset();
                 if ($comment->load($id)) {
                     $comment->markAsDeleted();
                 }
             }
         }
         $cache = JCommentsFactory::getCache('com_jcomments');
         $cache->clean();
     }
     JCommentsRedirect(JCOMMENTS_INDEX . '?option=com_jcomments&task=comments');
 }
Example #5
0
	function onPrepareContent(&$article, &$params, $limitstart = 0)
	{
		require_once (JCOMMENTS_HELPERS . '/content.php');

		// check whether plugin has been unpublished
		if (!JPluginHelper::isEnabled('content', 'jcomments')) {
			JCommentsContentPluginHelper::clear($article, true);
			return '';
		}

		$app = JFactory::getApplication('site');
		$option = JRequest::getCmd('option');
		$view = JRequest::getCmd('view');

		if (!isset($article->id) || ($option != 'com_content' && $option != 'com_alphacontent' && $option != 'com_multicategories')) {
			return '';
		}

		if (!isset($params) || $params == null) {
			jimport('joomla.html.parameter');
			$params = new JParameter('');
		} else if (isset($params->_raw) && strpos($params->_raw, 'moduleclass_sfx') !== false) {
			return '';
		}

		if ($view == 'frontpage' || $view == 'featured') {
			if ($this->params->get('show_frontpage', 1) == 0) {
				return '';
			}
		}

		require_once (JCOMMENTS_BASE . '/jcomments.config.php');
		require_once (JCOMMENTS_BASE . '/jcomments.class.php');

		JCommentsContentPluginHelper::processForeignTags($article);

		$config = JCommentsFactory::getConfig();

		$categoryEnabled = JCommentsContentPluginHelper::checkCategory($article->catid);
		$commentsEnabled = JCommentsContentPluginHelper::isEnabled($article) || $categoryEnabled;
		$commentsDisabled = JCommentsContentPluginHelper::isDisabled($article) || !$commentsEnabled;
		$commentsLocked = JCommentsContentPluginHelper::isLocked($article);

		if ($article->state == -1 && $this->params->get('enable_for_archived', 0) == 0) {
			$commentsLocked = true;
		}

		$config->set('comments_on', intval($commentsEnabled));
		$config->set('comments_off', intval($commentsDisabled));
		$config->set('comments_locked', intval($commentsLocked));

		if ($view != 'article') {
			$user = JFactory::getUser();

			if (JCOMMENTS_JVERSION == '1.5') {
				$checkAccess = $article->access <= $user->get('aid', 0);
			} else {
				$authorised = JAccess::getAuthorisedViewLevels($user->get('id'));
				$checkAccess = in_array($article->access, $authorised);
			}

			if ($checkAccess) {
				require_once(JPATH_ROOT . '/components/com_content/helpers/route.php');
				if (JCOMMENTS_JVERSION == '1.5') {
					$readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));
				} else {
					$readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid));
				}
				$readmore_register = 0;
			} else {
				if (JCOMMENTS_JVERSION == '1.5') {
					$readmore_link = JRoute::_('index.php?option=com_user&task=register');
				} else {
					$returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug));

					$menu = JFactory::getApplication()->getMenu();
					$active = $menu->getActive();
					$itemId = $active->id;
					$link1 = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId);
					$link = new JURI($link1);
					$link->setVar('return', base64_encode($returnURL));
					$readmore_link = $link;
				}
				$readmore_register = 1;
			}

			// load template for comments & readmore links
			$tmpl = JCommentsFactory::getTemplate($article->id, 'com_content', false);
			$tmpl->load('tpl_links');

			$tmpl->addVar('tpl_links', 'comments_link_style', ($readmore_register ? -1 : 1));
			$tmpl->addVar('tpl_links', 'content-item', $article);
			$tmpl->addVar('tpl_links', 'show_hits', intval($this->params->get('show_hits', 0) && $params->get('show_hits', 0)));

			$readmoreDisabled = false;

			if (($params->get('show_readmore') == 0) || (@$article->readmore == 0)) {
				$readmoreDisabled = true;
			} else if (@$article->readmore > 0) {
				$readmoreDisabled = false;
			}

			if ($this->params->get('readmore_link', 1) == 0) {
				$readmoreDisabled = true;
			}

			$tmpl->addVar('tpl_links', 'readmore_link_hidden', intval($readmoreDisabled));

			// don't fill any readmore variable if it disabled
			if (!$readmoreDisabled) {
				if ($readmore_register == 1) {
					$readmore_text = JText::_('LINK_REGISTER_TO_READ_MORE');
				} else if (isset($params) && $readmore = $params->get('readmore')) {
					$readmore_text = $readmore;
				} else {
					$readmore_text = JText::_('LINK_READ_MORE');
				}
				$tmpl->addVar('tpl_links', 'link-readmore', $readmore_link);
				$tmpl->addVar('tpl_links', 'link-readmore-text', $readmore_text);
				$tmpl->addVar('tpl_links', 'link-readmore-title', $article->title);
				$tmpl->addVar('tpl_links', 'link-readmore-class', $this->params->get('readmore_css_class', 'readmore-link'));
			}

			$commentsDisabled = false;

			if ($config->getInt('comments_off', 0) == 1) {
				$commentsDisabled = true;
			} else if ($config->getInt('comments_on', 0) == 1) {
				$commentsDisabled = false;
			}

			$tmpl->addVar('tpl_links', 'comments_link_hidden', intval($commentsDisabled));

			$count = 0;

			// do not query comments count if comments disabled and link hidden
			if (!$commentsDisabled) {
				require_once (JCOMMENTS_MODELS . '/jcomments.php');

				$anchor = "";

				if ($this->params->get('comments_count', 1) != 0) {

					$acl = JCommentsFactory::getACL();

					$options = array();
					$options['object_id'] = (int) $article->id;
					$options['object_group'] = 'com_content';
					$options['published'] = $acl->canPublish() || $acl->canPublishForObject($article->id, 'com_content') ? null : 1;

					$count = JCommentsModel::getCommentsCount($options);

					$tmpl->addVar('tpl_links', 'comments-count', $count);
					$anchor = $count == 0 ? '#addcomment' : '#comments';

					if ($count == 0) {
						$link_text = JText::_('LINK_ADD_COMMENT');
					} else {
						if (JCOMMENTS_JVERSION == '1.5') {
							require_once (JCOMMENTS_LIBRARIES.'/joomlatune/language.tools.php');
							$lang = JFactory::getLanguage();
							$suffix = JoomlaTuneLanguageTools::getPluralSuffix($lang->getTag(), $count);
							$string = 'LINK_READ_COMMENTS';
							$key = $string . '_' . $suffix;
							if (!$lang->hasKey($key)) {
								$key = $string;
							}
							$link_text = JText::sprintf($key, $count);

						} else {
							$link_text = JText::plural('LINK_READ_COMMENTS', $count);
						}
					}
				} else {
					$link_text = JText::_('LINK_ADD_COMMENT');
				}

				$tmpl->addVar('tpl_links', 'link-comment', $readmore_link . $anchor);
				$tmpl->addVar('tpl_links', 'link-comment-text', $link_text);
				$tmpl->addVar('tpl_links', 'link-comments-class', $this->params->get('comments_css_class', 'comments-link'));
			}

			JCommentsContentPluginHelper::clear($article, true);

			// hide comments link if comments enabled but link disabled in plugin params
			if ((($this->params->get('comments_count', 1) == 0)
					|| ($count == 0 && $this->params->get('add_comments', 1) == 0)
					|| ($count == 0 && $readmore_register == 1))
					&& !$commentsDisabled) {
				$tmpl->addVar('tpl_links', 'comments_link_hidden', 1);
			}

			//links_position
			if ($this->params->get('links_position', 1) == 1) {
				$article->text .= $tmpl->renderTemplate('tpl_links');
			} else {
				$article->text = $tmpl->renderTemplate('tpl_links') . $article->text;
			}

			$tmpl->freeTemplate('tpl_links');

			if ($this->params->get('readmore_link', 1) == 1) {
				$article->readmore = 0;
				$article->readmore_link = '';
				$article->readmore_register = false;
			}
		} else {
			if ($this->params->get('show_comments_event') == 'onPrepareContent') {
				$isEnabled = ($config->getInt('comments_on', 0) == 1) && ($config->getInt('comments_off', 0) == 0);
				if ($isEnabled && $view == 'article') {
					require_once (JCOMMENTS_BASE . '/jcomments.php');

					$comments = JComments::show($article->id, 'com_content', $article->title);

					if (strpos($article->text, '{jcomments}') !== false) {
						$article->text = str_replace('{jcomments}', $comments, $article->text);
					} else {
						$article->text .= $comments;
					}
				}
			}
			JCommentsContentPluginHelper::clear($article, true);
		}
		return '';
	}
Example #6
0
 function remove()
 {
     $id = JCommentsInput::getVar('cid', array());
     if (is_array($id) && count($id) > 0) {
         JCommentsModel::deleteCommentsByIds($id);
         JCommentsCache::cleanCache('com_jcomments');
     }
     JCommentsRedirect(JCOMMENTS_INDEX . '?option=com_jcomments&task=comments');
 }
Example #7
0
 function deleteComments($object_id, $object_group = 'com_content')
 {
     $object_group = trim($object_group);
     $oids = is_array($object_id) ? $object_id : array($object_id);
     $oids = implode(',', $oids);
     $db =& JCommentsFactory::getDBO();
     $query = "SELECT id FROM #__jcomments " . "\n WHERE object_group = '" . $db->getEscaped($object_group) . "'" . "\n AND object_id IN (" . $oids . ")";
     $db->setQuery($query);
     $cids = $db->loadResultArray();
     JCommentsModel::deleteCommentsByIds($cids);
     return true;
 }
Example #8
0
 function onAfterRoute()
 {
     $legacyFile = JPATH_ROOT . '/components/com_jcomments/jcomments.legacy.php';
     if (!is_file($legacyFile)) {
         return;
     }
     include_once $legacyFile;
     $mainframe = JFactory::getApplication('site');
     $mainframe->getRouter();
     $document = JFactory::getDocument();
     if ($document->getType() == 'html') {
         if ($mainframe->isAdmin()) {
             $document->addStyleSheet(JURI::base() . 'components/com_jcomments/assets/icon.css?v=2');
             $option = JAdministratorHelper::findOption();
             $task = JRequest::getCmd('task');
             $type = JRequest::getCmd('type', '', 'post');
             // remove comments if content item deleted from trash
             if ($option == 'com_trash' && $task == 'delete' && $type == 'content') {
                 $cid = JRequest::getVar('cid', array(0), 'post', 'array');
                 JArrayHelper::toInteger($cid, array(0));
                 include_once JPATH_ROOT . '/components/com_jcomments/jcomments.php';
                 JCommentsModel::deleteComments($cid, 'com_content');
             }
         } else {
             $option = JRequest::getCmd('option');
             if ($option == 'com_content' || $option == 'com_alphacontent' || $option == 'com_multicategories') {
                 include_once JCOMMENTS_BASE . '/jcomments.class.php';
                 include_once JCOMMENTS_BASE . '/jcomments.config.php';
                 include_once JCOMMENTS_HELPERS . '/system.php';
                 // include JComments CSS
                 if ($this->params->get('disable_template_css', 0) == 0) {
                     $document->addStyleSheet(JCommentsSystemPluginHelper::getCSS());
                     $language = JFactory::getLanguage();
                     if ($language->isRTL()) {
                         $rtlCSS = JCommentsSystemPluginHelper::getCSS(true);
                         if ($rtlCSS != '') {
                             $document->addStyleSheet($rtlCSS);
                         }
                     }
                 }
                 if (!defined('JCOMMENTS_CSS')) {
                     define('JCOMMENTS_CSS', 1);
                 }
                 // include JComments JavaScript library
                 $document->addScript(JCommentsSystemPluginHelper::getCoreJS());
                 if (!defined('JOOMLATUNE_AJAX_JS')) {
                     $document->addScript(JCommentsSystemPluginHelper::getAjaxJS());
                     define('JOOMLATUNE_AJAX_JS', 1);
                 }
                 if (!defined('JCOMMENTS_JS')) {
                     define('JCOMMENTS_JS', 1);
                 }
             }
         }
     }
 }
Example #9
0
 public static function addComment($values = array())
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $user = JCommentsFactory::getUser();
     $acl = JCommentsFactory::getACL();
     $config = JCommentsFactory::getConfig();
     $response = JCommentsFactory::getAjaxResponse();
     if ($acl->canComment()) {
         $values = self::prepareValues($_POST);
         $object_group = isset($values['object_group']) ? JCommentsSecurity::clearObjectGroup($values['object_group']) : '';
         $object_id = isset($values['object_id']) ? intval($values['object_id']) : '';
         if ($object_group == '' || $object_id == '') {
             // TODO: add appropriate error message
             return $response;
         }
         $commentsPerObject = $config->getInt('max_comments_per_object');
         if ($commentsPerObject > 0) {
             $commentsCount = JComments::getCommentsCount($object_id, $object_group);
             if ($commentsCount >= $commentsPerObject) {
                 $message = $config->get('message_locked');
                 if (empty($message)) {
                     $message = $config->get('ERROR_CANT_COMMENT');
                 }
                 $message = self::escapeMessage($message);
                 $response->addAlert($message);
                 return $response;
             }
         }
         $userIP = $acl->getUserIP();
         if (!$user->id) {
             $noErrors = false;
             if (isset($values['userid']) && intval($values['userid']) > 0) {
                 // TODO: we need more correct way to detect login timeout
                 self::showErrorMessage(JText::_('ERROR_SESSION_EXPIRED'));
             } else {
                 if ($config->getInt('author_name', 2) == 2 && empty($values['name'])) {
                     self::showErrorMessage(JText::_('ERROR_EMPTY_NAME'), 'name');
                 } else {
                     if (JCommentsSecurity::checkIsRegisteredUsername($values['name']) == 1) {
                         self::showErrorMessage(JText::_('ERROR_NAME_EXISTS'), 'name');
                     } else {
                         if (JCommentsSecurity::checkIsForbiddenUsername($values['name']) == 1) {
                             self::showErrorMessage(JText::_('ERROR_FORBIDDEN_NAME'), 'name');
                         } else {
                             if (preg_match('/[\\"\'\\[\\]\\=\\<\\>\\(\\)\\;]+/', $values['name'])) {
                                 self::showErrorMessage(JText::_('ERROR_INVALID_NAME'), 'name');
                             } else {
                                 if ($config->get('username_maxlength') != 0 && JCommentsText::strlen($values['name']) > $config->get('username_maxlength')) {
                                     self::showErrorMessage(JText::_('ERROR_TOO_LONG_USERNAME'), 'name');
                                 } else {
                                     if ($config->getInt('author_email') == 2 && empty($values['email'])) {
                                         self::showErrorMessage(JText::_('ERROR_EMPTY_EMAIL'), 'email');
                                     } else {
                                         if (!empty($values['email']) && !preg_match(_JC_REGEXP_EMAIL2, $values['email'])) {
                                             self::showErrorMessage(JText::_('ERROR_INCORRECT_EMAIL'), 'email');
                                         } else {
                                             if ($config->getInt('author_email') != 0 && JCommentsSecurity::checkIsRegisteredEmail($values['email']) == 1) {
                                                 self::showErrorMessage(JText::_('ERROR_EMAIL_EXISTS'), 'email');
                                             } else {
                                                 if ($config->getInt('author_homepage') == 2 && empty($values['homepage'])) {
                                                     self::showErrorMessage(JText::_('ERROR_EMPTY_HOMEPAGE'), 'homepage');
                                                 } else {
                                                     $noErrors = true;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!$noErrors) {
                 return $response;
             }
         }
         if ($acl->check('floodprotection') == 1 && JCommentsSecurity::checkFlood($userIP)) {
             self::showErrorMessage(JText::_('ERROR_TOO_QUICK'));
         } else {
             if (empty($values['homepage']) && $config->get('author_homepage') == 3) {
                 self::showErrorMessage(JText::_('ERROR_EMPTY_HOMEPAGE'), 'homepage');
             } else {
                 if (empty($values['title']) && $config->get('comment_title') == 3) {
                     self::showErrorMessage(JText::_('ERROR_EMPTY_TITLE'), 'title');
                 } else {
                     if (empty($values['comment'])) {
                         self::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment');
                     } else {
                         if ($config->getInt('comment_maxlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) > $config->get('comment_maxlength')) {
                             self::showErrorMessage(JText::_('ERROR_YOUR_COMMENT_IS_TOO_LONG'), 'comment');
                         } else {
                             if ($config->getInt('comment_minlength', 0) != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) < $config->get('comment_minlength')) {
                                 self::showErrorMessage(JText::_('ERROR_YOUR_COMMENT_IS_TOO_SHORT'), 'comment');
                             } else {
                                 if ($acl->check('enable_captcha') == 1) {
                                     $captchaEngine = $config->get('captcha_engine', 'kcaptcha');
                                     if ($captchaEngine == 'kcaptcha') {
                                         require_once JCOMMENTS_BASE . DS . 'jcomments.captcha.php';
                                         if (!JCommentsCaptcha::check($values['captcha_refid'])) {
                                             self::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha');
                                             JCommentsCaptcha::destroy();
                                             $response->addScript("jcomments.clear('captcha');");
                                             return $response;
                                         }
                                     } else {
                                         $result = JCommentsEvent::trigger('onJCommentsCaptchaVerify', array($values['captcha_refid'], &$response));
                                         // if all plugins returns false
                                         if (!in_array(true, $result, true)) {
                                             self::showErrorMessage(JText::_('ERROR_CAPTCHA'));
                                             return $response;
                                         }
                                     }
                                 }
                                 $db = JCommentsFactory::getDBO();
                                 // small fix (by default $my has empty 'name' and 'email' field)
                                 if ($user->id) {
                                     $currentUser = JCommentsFactory::getUser($user->id);
                                     $user->name = $currentUser->name;
                                     $user->username = $currentUser->username;
                                     $user->email = $currentUser->email;
                                     unset($currentUser);
                                 }
                                 if (empty($values['name'])) {
                                     $values['name'] = 'Guest';
                                     // JText::_('Guest');
                                 }
                                 $comment = new JCommentsTableComment($db);
                                 $comment->id = 0;
                                 $comment->name = $user->id ? $user->name : preg_replace("/[\\'\"\\>\\<\\(\\)\\[\\]]?+/i", '', $values['name']);
                                 $comment->username = $user->id ? $user->username : $comment->name;
                                 $comment->email = $user->id ? $user->email : (isset($values['email']) ? $values['email'] : '');
                                 if ($config->getInt('author_homepage') != 0 && !empty($values['homepage'])) {
                                     $comment->homepage = JCommentsText::url($values['homepage']);
                                 }
                                 $comment->comment = $values['comment'];
                                 // filter forbidden bbcodes
                                 $bbcode = JCommentsFactory::getBBCode();
                                 $comment->comment = $bbcode->filter($comment->comment);
                                 if ($comment->comment != '') {
                                     if ($config->getInt('enable_custom_bbcode')) {
                                         // filter forbidden custom bbcodes
                                         $commentLength = strlen($comment->comment);
                                         $customBBCode = JCommentsFactory::getCustomBBCode();
                                         $comment->comment = $customBBCode->filter($comment->comment);
                                         if (strlen($comment->comment) == 0 && $commentLength > 0) {
                                             self::showErrorMessage(JText::_('ERROR_YOU_HAVE_NO_RIGHTS_TO_USE_THIS_TAG'), 'comment');
                                             return $response;
                                         }
                                     }
                                 }
                                 if ($comment->comment == '') {
                                     self::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment');
                                     return $response;
                                 }
                                 $commentWithoutQuotes = $bbcode->removeQuotes($comment->comment);
                                 if ($commentWithoutQuotes == '') {
                                     self::showErrorMessage(JText::_('ERROR_NOTHING_EXCEPT_QUOTES'), 'comment');
                                     return $response;
                                 } else {
                                     if ($config->getInt('comment_minlength', 0) != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($commentWithoutQuotes) < $config->get('comment_minlength')) {
                                         self::showErrorMessage(JText::_('ERROR_YOUR_COMMENT_IS_TOO_SHORT'), 'comment');
                                         return $response;
                                     }
                                 }
                                 $values['subscribe'] = isset($values['subscribe']) ? (int) $values['subscribe'] : 0;
                                 if ($values['subscribe'] == 1 && $comment->email == '') {
                                     self::showErrorMessage(JText::_('ERROR_SUBSCRIPTION_EMAIL'), 'email');
                                     return $response;
                                 }
                                 $comment->object_id = (int) $object_id;
                                 $comment->object_group = $object_group;
                                 $comment->title = isset($values['title']) ? $values['title'] : '';
                                 $comment->parent = isset($values['parent']) ? intval($values['parent']) : 0;
                                 $comment->lang = JCommentsMultilingual::getLanguage();
                                 $comment->ip = $userIP;
                                 $comment->userid = $user->id ? $user->id : 0;
                                 $comment->published = $acl->check('autopublish');
                                 $comment->date = JCommentsFactory::getDate();
                                 $query = "SELECT COUNT(*) " . "\nFROM #__jcomments " . "\nWHERE comment = '" . $db->getEscaped($comment->comment) . "'" . "\n  AND ip = '" . $db->getEscaped($comment->ip) . "'" . "\n  AND name = '" . $db->getEscaped($comment->name) . "'" . "\n  AND userid = '" . $comment->userid . "'" . "\n  AND object_id = " . $comment->object_id . "\n  AND parent = " . $comment->parent . "\n  AND object_group = '" . $db->getEscaped($comment->object_group) . "'" . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "");
                                 $db->setQuery($query);
                                 $found = $db->loadResult();
                                 // if duplicates is not found
                                 if ($found == 0) {
                                     $result = JCommentsEvent::trigger('onJCommentsCommentBeforeAdd', array(&$comment));
                                     if (in_array(false, $result, true)) {
                                         return $response;
                                     }
                                     // save comments subscription
                                     if ($values['subscribe']) {
                                         require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
                                         $manager = JCommentsSubscriptionManager::getInstance();
                                         $manager->subscribe($comment->object_id, $comment->object_group, $comment->userid, $comment->email, $comment->name, $comment->lang);
                                     }
                                     $merged = false;
                                     $merge_time = $config->getInt('merge_time', 0);
                                     // merge comments from same author
                                     if ($user->id && $merge_time > 0) {
                                         // load previous comment for same object and group
                                         $prevComment = JCommentsModel::getLastComment($comment->object_id, $comment->object_group, $comment->parent);
                                         if ($prevComment != null) {
                                             // if previous comment from same author and it currently not edited
                                             // by any user - we'll update comment, else - insert new record to database
                                             if ($prevComment->userid == $comment->userid && $prevComment->parent == $comment->parent && !$acl->isLocked($prevComment)) {
                                                 $newText = $prevComment->comment . '<br /><br />' . $comment->comment;
                                                 $timeDiff = strtotime($comment->date) - strtotime($prevComment->date);
                                                 if ($timeDiff < $merge_time) {
                                                     $maxlength = $config->getInt('comment_maxlength');
                                                     $needcheck = $acl->check('enable_comment_length_check');
                                                     // validate new comment text length and if it longer than specified -
                                                     // disable union current comment with previous
                                                     if ($needcheck == 0 || $needcheck == 1 && $maxlength != 0 && JCommentsText::strlen($newText) <= $maxlength) {
                                                         $comment->id = $prevComment->id;
                                                         $comment->comment = $newText;
                                                         $merged = true;
                                                     }
                                                 }
                                             }
                                             unset($prevComment);
                                         }
                                     }
                                     // save new comment to database
                                     if (!$comment->store()) {
                                         $response->addScript("jcomments.clear('comment');");
                                         if ($acl->check('enable_captcha') == 1 && $config->get('captcha_engine', 'kcaptcha') == 'kcaptcha') {
                                             JCommentsCaptcha::destroy();
                                             $response->addScript("jcomments.clear('captcha');");
                                         }
                                         return $response;
                                     }
                                     // store/update information about commented object
                                     JCommentsObjectHelper::storeObjectInfo($comment->object_id, $comment->object_group, $comment->lang);
                                     JCommentsEvent::trigger('onJCommentsCommentAfterAdd', array(&$comment));
                                     // send notification to administrators
                                     if ($config->getInt('enable_notification') == 1) {
                                         if ($config->check('notification_type', 1) == true) {
                                             JComments::sendNotification($comment, true);
                                         }
                                     }
                                     // if comment published we need update comments list
                                     if ($comment->published) {
                                         // send notification to comment subscribers
                                         JComments::sendToSubscribers($comment, true);
                                         if ($merged) {
                                             $commentText = $comment->comment;
                                             $html = JCommentsText::jsEscape(JComments::getCommentItem($comment));
                                             $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');");
                                             $comment->comment = $commentText;
                                         } else {
                                             $count = JComments::getCommentsCount($comment->object_id, $comment->object_group);
                                             if ($config->get('template_view') == 'tree') {
                                                 if ($count > 1) {
                                                     $html = JComments::getCommentListItem($comment);
                                                     $html = JCommentsText::jsEscape($html);
                                                     $mode = $config->getInt('tree_order') == 1 || $config->getInt('tree_order') == 2 && $comment->parent > 0 ? 'b' : 'a';
                                                     $response->addScript("jcomments.updateTree('{$html}','{$comment->parent}','{$mode}');");
                                                 } else {
                                                     $html = JComments::getCommentsTree($comment->object_id, $comment->object_group);
                                                     $html = JCommentsText::jsEscape($html);
                                                     $response->addScript("jcomments.updateTree('{$html}',null);");
                                                 }
                                             } else {
                                                 // if pagination disabled and comments count > 1...
                                                 if ($config->getInt('comments_per_page') == 0 && $count > 1) {
                                                     // update only added comment
                                                     $html = JComments::getCommentListItem($comment);
                                                     $html = JCommentsText::jsEscape($html);
                                                     if ($config->get('comments_order') == 'DESC') {
                                                         $response->addScript("jcomments.updateList('{$html}','p');");
                                                     } else {
                                                         $response->addScript("jcomments.updateList('{$html}','a');");
                                                     }
                                                 } else {
                                                     // update comments list
                                                     $html = JComments::getCommentsList($comment->object_id, $comment->object_group, JComments::getCommentPage($comment->object_id, $comment->object_group, $comment->id));
                                                     $html = JCommentsText::jsEscape($html);
                                                     $response->addScript("jcomments.updateList('{$html}','r');");
                                                 }
                                                 // scroll to first comment
                                                 if ($config->get('comments_order') == 'DESC') {
                                                     $response->addScript("jcomments.scrollToList();");
                                                 }
                                             }
                                         }
                                         self::showInfoMessage(JText::_('THANK_YOU_FOR_YOUR_SUBMISSION'));
                                     } else {
                                         self::showInfoMessage(JText::_('THANK_YOU_YOUR_COMMENT_WILL_BE_PUBLISHED_ONCE_REVIEWED'));
                                     }
                                     // clear comments textarea & update comment length counter if needed
                                     $response->addScript("jcomments.clear('comment');");
                                     if ($acl->check('enable_captcha') == 1 && $config->get('captcha_engine', 'kcaptcha') == 'kcaptcha') {
                                         require_once JCOMMENTS_BASE . DS . 'jcomments.captcha.php';
                                         JCommentsCaptcha::destroy();
                                         $response->addScript("jcomments.clear('captcha');");
                                     }
                                 } else {
                                     self::showErrorMessage(JText::_('ERROR_DUPLICATE_COMMENT'), 'comment');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $message = $config->get('ERROR_CANT_COMMENT');
         if ($acl->getUserBlocked()) {
             $bannedMessage = $config->get('message_banned');
             if (!empty($bannedMessage)) {
                 $message = self::escapeMessage($bannedMessage);
             }
         }
         $response->addAlert($message);
     }
     return $response;
 }
Example #10
0
 public static function showUserComments()
 {
     $config = JCommentsFactory::getConfig();
     if ($config->get('enable_rss') == '1') {
         $app = JCommentsFactory::getApplication('site');
         $acl = JCommentsFactory::getACL();
         $userid = (int) JCommentsInput::getVar('userid', 0);
         $limit = (int) JCommentsInput::getVar('limit', $config->getInt('feed_limit', 100));
         $user = JCommentsFactory::getUser($userid);
         if (!isset($user->id)) {
             self::showNotFound();
             return;
         }
         if (JCOMMENTS_JVERSION == '1.0') {
             $offset = $app->getCfg('offset') + date('O') / 100;
         } else {
             $offset = $app->getCfg('offset');
         }
         $lm = $limit != $config->getInt('feed_limit') ? '&amp;limit=' . $limit : '';
         if (JCommentsMultilingual::isEnabled()) {
             $language = JCommentsMultilingual::getLanguage();
             $lp = '&amp;lang=' . $language;
         } else {
             $language = null;
             $lp = '';
         }
         if (JCOMMENTS_JVERSION == '1.0') {
             $syndicationURL = $app->getCfg('live_site') . '/index2.php?option=com_jcomments&amp;task=rss_user&amp;userid=' . $userid . $lm . $lp . '&amp;no_html=1';
         } else {
             $liveSite = str_replace(JURI::root(true), '', $app->getCfg('live_site'));
             $syndicationURL = $liveSite . JRoute::_('index.php?option=com_jcomments&amp;task=rss_user&amp;userid=' . $userid . $lm . $lp . '&amp;tmpl=raw');
         }
         $user->userid = $user->id;
         $username = JComments::getCommentAuthorName($user);
         $rss = new JoomlaTuneFeed();
         $rss->setOffset($offset);
         $rss->encoding = JCOMMENTS_ENCODING;
         $rss->title = JText::sprintf('USER_FEED_TITLE', $username);
         $rss->link = $app->getCfg('live_site');
         $rss->syndicationURL = $syndicationURL;
         $rss->description = JText::sprintf('USER_FEED_DESCRIPTION', $username);
         $options = array();
         $options['lang'] = $language;
         $options['userid'] = $userid;
         $options['published'] = 1;
         $options['filter'] = 'c.deleted = 0';
         $options['orderBy'] = 'c.date DESC';
         $options['votes'] = false;
         $options['limit'] = $limit;
         $options['limitStart'] = 0;
         $options['objectinfo'] = true;
         $options['access'] = $acl->getUserAccess();
         $rows = JCommentsModel::getCommentsList($options);
         $word_maxlength = $config->getInt('word_maxlength');
         $lang = JCommentsMultilingual::isEnabled() ? JCommentsMultilingual::getLanguage() : null;
         foreach ($rows as $row) {
             $comment = JCommentsText::cleanText($row->comment);
             if ($comment != '') {
                 // getting object's information (title and link)
                 $object_title = empty($row->object_title) ? JCommentsObjectHelper::getTitle($row->object_id, $row->object_group, $lang) : $row->object_title;
                 $object_link = empty($row->object_link) ? JCommentsObjectHelper::getLink($row->object_id, $row->object_group, $lang) : $row->object_link;
                 $object_link = JCommentsFactory::getAbsLink(str_replace('amp;', '', $object_link));
                 // apply censor filter
                 $object_title = JCommentsText::censor($object_title);
                 $comment = JCommentsText::censor($comment);
                 // fix long words problem
                 if ($word_maxlength > 0) {
                     $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' ');
                     if ($object_title != '') {
                         $object_title = JCommentsText::fixLongWords($object_title, $word_maxlength, ' ');
                     }
                 }
                 $author = JComments::getCommentAuthorName($row);
                 $item = new JoomlaTuneFeedItem();
                 $item->title = $object_title;
                 $item->link = $object_link . '#comment-' . $row->id;
                 $item->description = JText::sprintf('USER_FEED_ITEM_DESCRIPTION', $author, $comment);
                 $item->source = $object_link;
                 if (JCOMMENTS_JVERSION == '1.0') {
                     $date = strtotime((string) $row->date) - $offset * 3600;
                     $item->pubDate = date('Y-m-d H:i:s', $date);
                 } else {
                     $item->pubDate = $row->date;
                 }
                 $item->author = $author;
                 $rss->addItem($item);
             }
         }
         $rss->display();
         unset($rows, $rss);
         exit;
     }
 }
Example #11
0
 function delete(&$pks)
 {
     $db = $this->getDbo();
     JArrayHelper::toInteger($pks);
     for ($i = 0; $i < count($pks); $i++) {
         $query = 'SELECT filename FROM #__igallery_img WHERE id = ' . (int) $pks[$i];
         $db->setQuery($query);
         $photo = $db->loadObject();
         $query = 'SELECT filename FROM #__igallery_img WHERE filename = ' . $db->Quote($photo->filename);
         $db->setQuery($query);
         $db->query();
         $numRows = $db->getNumRows();
         $deleteOrig = $numRows > 1 ? false : true;
         igFileHelper::deleteImage($photo->filename, $deleteOrig);
         $query = 'DELETE FROM #__igallery_img WHERE id = ' . (int) $pks[$i];
         $db->setQuery($query);
         if (!$db->query()) {
             $this->setError($db->getErrorMsg());
             return false;
         }
         $commentsPath = JPATH_SITE . '/components/com_jcomments/jcomments.php';
         if (file_exists($commentsPath)) {
             require_once $commentsPath;
             JCommentsModel::deleteComments((int) $pks[$i], 'com_igallery');
         }
         $alPath = JPATH_SITE . '/components/com_alratings/classes/alratings.php';
         if (file_exists($alPath)) {
             require_once $alPath;
             ALRatings::deleteRating('com_igallery', (int) $pks[$i]);
         }
     }
     $row = $this->getTable('igallery_img');
     $row->reorder('gallery_id = ' . JRequest::getInt('catid', 0));
     return true;
 }
Example #12
0
 /**
  * @deprecated As of version 2.2.0.0
  * @see  JCommentsModel::deleteComments
  */
 function deleteComments($object_id, $object_group = 'com_content')
 {
     JCommentsModel::deleteComments($object_id, $object_group);
     return true;
 }
Example #13
0
 function onContentAfterDelete($context, $data)
 {
     if ($context == 'com_content.article') {
         require_once JPATH_ROOT . '/components/com_jcomments/models/jcomments.php';
         JCommentsModel::deleteComments((int) $table->id, 'com_content');
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->delete();
         $query->from($db->quoteName('#__jcomments_subscriptions'));
         $query->where($db->quoteName('object_id') . ' = ' . (int) $data->id);
         $query->where($db->quoteName('object_group') . ' = ' . $db->Quote('com_content'));
         $db->setQuery($query);
         $db->execute();
     }
 }
Example #14
0
 function onPrepareContent(&$article, &$params, $limitstart = 0)
 {
     require_once JCOMMENTS_HELPERS . DS . 'content.php';
     // check whether plugin has been unpublished
     if (!JPluginHelper::isEnabled('content', 'jcomments')) {
         JCommentsContentPluginHelper::clear($article, true);
         return;
     }
     $application =& JFactory::getApplication('site');
     $option = JRequest::getCmd('option');
     $view = JRequest::getCmd('view');
     if (!isset($article->id) || $option != 'com_content' && $option != 'com_alphacontent' && $option != 'com_customproperties') {
         return;
     }
     if (!isset($params) || $params == null) {
         $params = new JParameter('');
     } else {
         if (strpos($params->_raw, 'moduleclass_sfx') !== false) {
             return '';
         }
     }
     if ($view == 'frontpage') {
         if ($this->params->get('show_frontpage', 1) == 0) {
             return;
         }
     }
     require_once JCOMMENTS_BASE . DS . 'jcomments.config.php';
     require_once JCOMMENTS_BASE . DS . 'jcomments.class.php';
     JCommentsContentPluginHelper::processForeignTags($article);
     $config =& JCommentsFactory::getConfig();
     $categoryEnabled = JCommentsContentPluginHelper::checkCategory($article->catid);
     $commentsEnabled = JCommentsContentPluginHelper::isEnabled($article) || $categoryEnabled;
     $commentsDisabled = JCommentsContentPluginHelper::isDisabled($article) || !$commentsEnabled;
     $commentsLocked = JCommentsContentPluginHelper::isLocked($article);
     if ($article->state == -1 && $config->getInt('enable_for_archived') == 0) {
         $commentsLocked = true;
     }
     $config->set('comments_on', intval($commentsEnabled));
     $config->set('comments_off', intval($commentsDisabled));
     $config->set('comments_locked', intval($commentsLocked));
     if ($view != 'article') {
         $user =& JFactory::getUser();
         if ($article->access <= $user->get('aid', 0)) {
             $readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));
             $readmore_register = 0;
         } else {
             $readmore_link = JRoute::_('index.php?option=com_user&task=register');
             $readmore_register = 1;
         }
         // load template for comments & readmore links
         $tmpl =& JCommentsFactory::getTemplate($article->id, 'com_content', false);
         $tmpl->load('tpl_links');
         $tmpl->addVar('tpl_links', 'comments_link_style', $readmore_register ? -1 : 1);
         $tmpl->addVar('tpl_links', 'content-item', $article);
         $tmpl->addVar('tpl_links', 'show_hits', intval($this->params->get('show_hits', 0) && $params->get('show_hits', 0)));
         $tmpl->addVar('tpl_links', 'link-comment', $readmore_link);
         $tmpl->addVar('tpl_links', 'link-comments-class', $this->params->get('comments_css_class', 'comments-link'));
         $readmoreDisabled = false;
         if ($params->get('show_readmore') == 0 || @$article->readmore == 0) {
             $readmoreDisabled = true;
         } else {
             if (@$article->readmore > 0) {
                 $readmoreDisabled = false;
             }
         }
         if ($this->params->get('readmore_link', 1) == 0) {
             $readmoreDisabled = true;
         }
         $tmpl->addVar('tpl_links', 'readmore_link_hidden', intval($readmoreDisabled));
         // don't fill any readmore variable if it disabled
         if (!$readmoreDisabled) {
             if ($readmore_register == 1) {
                 $readmore_text = JText::_('Register to read more...');
             } else {
                 if (isset($params) && ($readmore = $params->get('readmore'))) {
                     $readmore_text = $readmore;
                 } else {
                     $readmore_text = JText::_('Read more...');
                 }
             }
             $tmpl->addVar('tpl_links', 'link-readmore', $readmore_link);
             $tmpl->addVar('tpl_links', 'link-readmore-text', $readmore_text);
             $tmpl->addVar('tpl_links', 'link-readmore-title', $article->title);
             $tmpl->addVar('tpl_links', 'link-readmore-class', $this->params->get('readmore_css_class', 'readmore-link'));
         }
         $commentsDisabled = false;
         if ($config->getInt('comments_off', 0) == 1) {
             $commentsDisabled = true;
         } else {
             if ($config->getInt('comments_on', 0) == 1) {
                 $commentsDisabled = false;
             }
         }
         $tmpl->addVar('tpl_links', 'comments_link_hidden', intval($commentsDisabled));
         $count = 0;
         // do not query comments count if comments disabled and link hidden
         if (!$commentsDisabled && $this->params->get('comments_count', 1) != 0) {
             require_once JCOMMENTS_BASE . DS . 'model' . DS . 'jcomments.php';
             $count = JCommentsModel::getCommentsCount($article->id, 'com_content');
             $tmpl->addVar('tpl_links', 'comments-count', $count);
             if ($config->getInt('use_plural_forms', 0)) {
                 require_once JCOMMENTS_LIBRARIES . DS . 'joomlatune' . DS . 'language.tools.php';
                 $tmpl->addVar('tpl_links', 'use-plural-forms', $config->getInt('use_plural_forms', 0));
             }
         }
         JCommentsContentPluginHelper::clear($article, true);
         // hide comments link if comments enabled but link disabled in plugin params
         if (($this->params->get('comments_count', 1) == 0 || $count == 0 && $this->params->get('add_comments', 1) == 0 || $count == 0 && $readmore_register == 1) && !$commentsDisabled) {
             $tmpl->addVar('tpl_links', 'comments_link_hidden', 1);
         }
         //links_position
         if ($this->params->get('links_position', 1) == 1) {
             $article->text .= $tmpl->renderTemplate('tpl_links');
         } else {
             $article->text = $tmpl->renderTemplate('tpl_links') . $article->text;
         }
         $tmpl->freeTemplate('tpl_links');
         if ($this->params->get('readmore_link', 1) == 1) {
             $article->readmore = 0;
             if (isset($params)) {
                 $params->set('show_readmore', 0);
             }
             $article->readmore_link = '';
             $article->readmore_register = false;
         }
     } else {
         if ($this->params->get('show_comments_event') == 'onPrepareContent') {
             $isEnabled = $config->getInt('comments_on', 0) == 1 && $config->getInt('comments_off', 0) == 0;
             if ($isEnabled && $view == 'article') {
                 require_once JCOMMENTS_BASE . DS . 'jcomments.php';
                 $article->text .= JComments::show($article->id, 'com_content', $article->title);
             }
         } else {
             $user = JFactory::getUser();
             if ($user->usertype == 'Super Administrator') {
                 $application =& JFactory::getApplication('site');
                 $template = $application->getTemplate();
                 $articleTemplate = DS . 'templates' . DS . $template . DS . 'html' . DS . 'com_content' . DS . 'article' . DS . 'default.php';
                 if (is_file(JPATH_SITE . $articleTemplate)) {
                     $tmpl = implode('', file(JPATH_SITE . $articleTemplate));
                     if (strpos($tmpl, 'afterDisplayContent') === false) {
                         JError::raiseWarning(500, JText::sprintf('The article template (%s) doesn\'t have afterDisplayContent event!', $articleTemplate));
                     }
                 }
             }
         }
         JCommentsContentPluginHelper::clear($article, true);
     }
     return;
 }
Example #15
0
 function deleteComment($id)
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $acl =& JCommentsFactory::getACL();
     $db =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $response =& JCommentsFactory::getAjaxResponse();
     $comment = new JCommentsDB($db);
     if ($comment->load((int) $id)) {
         if ($acl->isLocked($comment)) {
             $response->addAlert(JText::_('ERROR_BEING_EDITTED'));
         } else {
             if ($acl->canDelete($comment)) {
                 $object_id = $comment->object_id;
                 $object_group = $comment->object_group;
                 if ($config->getInt('enable_mambots') == 1) {
                     $allowed = true;
                     require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
                     JCommentsPluginHelper::importPlugin('jcomments');
                     JCommentsPluginHelper::trigger('onBeforeCommentDeleted', array(&$comment, &$response, &$allowed));
                     if ($allowed === false) {
                         return $response;
                     }
                     $comment->delete();
                     JCommentsPluginHelper::trigger('onAfterCommentDeleted', array(&$comment, &$response));
                 } else {
                     $comment->delete();
                 }
                 $count = JCommentsModel::getCommentsCount($object_id, $object_group);
                 if ($count > 0) {
                     $response->addScript("jcomments.updateComment('{$id}','');");
                 } else {
                     if ($config->get('template_view') == 'tree') {
                         $response->addScript("jcomments.updateTree('',null);");
                     } else {
                         $response->addScript("jcomments.updateList('','r');");
                     }
                 }
             } else {
                 $response->addAlert(JText::_('ERROR_CANT_DELETE'));
             }
         }
     }
     unset($comment);
     return $response;
 }
Example #16
0
 public static function showUserComments()
 {
     $config = JCommentsFactory::getConfig();
     if ($config->get('enable_rss') == '1') {
         $app = JFactory::getApplication('site');
         $acl = JCommentsFactory::getACL();
         $userid = $app->input->getInt('userid', 0);
         $limit = $app->input->getInt('limit', $config->getInt('feed_limit', 100));
         $user = JFactory::getUser($userid);
         if (!isset($user->id)) {
             self::showNotFound();
             return;
         }
         $lm = $limit != $config->getInt('feed_limit') ? '&amp;limit=' . $limit : '';
         if (JCommentsMultilingual::isEnabled()) {
             $language = JCommentsMultilingual::getLanguage();
             $lp = '&amp;lang=' . $language;
         } else {
             $language = null;
             $lp = '';
         }
         $liveSite = trim(str_replace(JURI::root(true), '', str_replace('/administrator', '', JURI::root())), '/');
         $syndicationURL = $liveSite . JRoute::_('index.php?option=com_jcomments&amp;task=rss_user&amp;userid=' . $userid . $lm . $lp . '&amp;tmpl=raw');
         $user->userid = $user->id;
         $username = JComments::getCommentAuthorName($user);
         $rss = new JoomlaTuneFeed();
         $rss->title = JText::sprintf('USER_FEED_TITLE', $username);
         $rss->link = str_replace('/administrator', '', JURI::root());
         $rss->syndicationURL = $syndicationURL;
         $rss->description = JText::sprintf('USER_FEED_DESCRIPTION', $username);
         $options = array();
         $options['lang'] = $language;
         $options['userid'] = $userid;
         $options['published'] = 1;
         $options['filter'] = 'c.deleted = 0';
         $options['orderBy'] = 'c.date DESC';
         $options['votes'] = false;
         $options['limit'] = $limit;
         $options['limitStart'] = 0;
         $options['objectinfo'] = true;
         $options['access'] = $acl->getUserAccess();
         $rows = JCommentsModel::getCommentsList($options);
         $word_maxlength = $config->getInt('word_maxlength');
         foreach ($rows as $row) {
             $comment = JCommentsText::cleanText($row->comment);
             if ($comment != '') {
                 // getting object's information (title and link)
                 $object_title = $row->object_title;
                 $object_link = JCommentsFactory::getAbsLink(str_replace('amp;', '', $row->object_link));
                 // apply censor filter
                 $object_title = JCommentsText::censor($object_title);
                 $comment = JCommentsText::censor($comment);
                 // fix long words problem
                 if ($word_maxlength > 0) {
                     $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' ');
                     if ($object_title != '') {
                         $object_title = JCommentsText::fixLongWords($object_title, $word_maxlength, ' ');
                     }
                 }
                 $author = JComments::getCommentAuthorName($row);
                 $item = new JoomlaTuneFeedItem();
                 $item->title = $object_title;
                 $item->link = $object_link . '#comment-' . $row->id;
                 $item->description = JText::sprintf('USER_FEED_ITEM_DESCRIPTION', $author, $comment);
                 $item->source = $object_link;
                 $item->pubDate = $row->date;
                 $item->author = $author;
                 $rss->addItem($item);
             }
         }
         $rss->display();
         unset($rows, $rss);
         exit;
     }
 }
Example #17
0
function plgContentJCommentsLinksJ10($published, &$row, &$params, $page = 0)
{
    global $task, $option, $my;
    // disable comments link in 3rd party components (except Events and AlphaContent)
    if ($option != 'com_content' && $option != 'com_frontpage' && $option != 'com_alphacontent' && $option != 'com_events') {
        return;
    }
    require_once JCOMMENTS_HELPERS . '/content.php';
    require_once JCOMMENTS_LIBRARIES . '/joomlatune/language.tools.php';
    if (!isset($params) || $params == null) {
        $params = new mosParameters('');
    }
    $pvars = array_keys(get_object_vars($params->_params));
    if (!$published || $params->get('popup') || in_array('moduleclass_sfx', $pvars)) {
        JCommentsContentPluginHelper::processForeignTags($row, true);
        JCommentsContentPluginHelper::clear($row, true);
        return;
    }
    /*
    if ($option == 'com_frontpage') {
    	$pluginParams = JCommentsPluginHelper::getParams('jcomments', 'content');
    	if ((int) $pluginParams->get('show_frontpage', 1) == 0) {
    		return;
    	}
    }
    */
    require_once JCOMMENTS_BASE . '/jcomments.config.php';
    require_once JCOMMENTS_BASE . '/jcomments.class.php';
    if ($task != 'view') {
        // replace other comment systems tags to JComments equivalents like {jcomments on}
        JCommentsContentPluginHelper::processForeignTags($row, false);
        // show link to comments only
        if ($row->access <= $my->gid) {
            $readmore_link = JCommentsObjectHelper::getLink($row->id, 'com_content');
            $readmore_register = 0;
        } else {
            $readmore_link = sefRelToAbs('index.php?option=com_registration&amp;task=register');
            $readmore_register = 1;
        }
        $tmpl = JCommentsFactory::getTemplate($row->id, 'com_content', false);
        $tmpl->load('tpl_links');
        $tmpl->addVar('tpl_links', 'comments_link_style', $readmore_register ? -1 : 1);
        $tmpl->addVar('tpl_links', 'link-readmore', $readmore_link);
        $tmpl->addVar('tpl_links', 'content-item', $row);
        if ($params->get('readmore') == 0 || @$row->readmore == 0) {
            $tmpl->addVar('tpl_links', 'readmore_link_hidden', 1);
        } else {
            if (@$row->readmore > 0) {
                $tmpl->addVar('tpl_links', 'readmore_link_hidden', 0);
            }
        }
        $config = JCommentsFactory::getConfig();
        $commentsDisabled = false;
        if (!JCommentsContentPluginHelper::checkCategory($row->catid)) {
            $commentsDisabled = true;
        }
        if ($config->getInt('comments_off', 0) == 1) {
            $commentsDisabled = true;
        } else {
            if ($config->getInt('comments_on', 0) == 1) {
                $commentsDisabled = false;
            }
        }
        $tmpl->addVar('tpl_links', 'comments_link_hidden', intval($commentsDisabled));
        $count = 0;
        // do not query comments count if comments disabled and link hidden
        if (!$commentsDisabled) {
            require_once JCOMMENTS_MODELS . '/jcomments.php';
            require_once JCOMMENTS_LIBRARIES . '/joomlatune/language.tools.php';
            $acl = JCommentsFactory::getACL();
            $options = array();
            $options['object_id'] = (int) $row->id;
            $options['object_group'] = 'com_content';
            $options['published'] = $acl->canPublish() || $acl->canPublishForObject($row->id, 'com_content') ? null : 1;
            $count = JCommentsModel::getCommentsCount($options);
            $anchor = $count == 0 ? '#addcomments' : '#comments';
            $link_text = $count == 0 ? JText::_('LINK_ADD_COMMENT') : JText::plural('LINK_READ_COMMENTS', $count);
            $tmpl->addVar('tpl_links', 'link-comment', $readmore_link . $anchor);
            $tmpl->addVar('tpl_links', 'link-comment-text', $link_text);
            $tmpl->addVar('tpl_links', 'link-comments-class', 'comments-link');
            $tmpl->addVar('tpl_links', 'comments-count', $count);
        }
        if ($readmore_register == 1 && $count == 0) {
            $tmpl->addVar('tpl_links', 'comments_link_hidden', 1);
        }
        if ($readmore_register == 1) {
            $readmore_text = JText::_('LINK_REGISTER_TO_READ_MORE');
        } else {
            $readmore_text = JText::_('LINK_READ_MORE');
        }
        $tmpl->addVar('tpl_links', 'link-readmore-text', $readmore_text);
        $tmpl->addVar('tpl_links', 'link-readmore-title', $row->title);
        $tmpl->addVar('tpl_links', 'link-readmore-class', 'readmore-link');
        JCommentsContentPluginHelper::clear($row, true);
        $row->text .= $tmpl->renderTemplate('tpl_links');
        $GLOBALS['jcomments_params_readmore'] = $params->get('readmore');
        $GLOBALS['jcomments_row_readmore'] = $row->readmore;
        $params->set('readmore', 0);
        $row->readmore = 0;
    } else {
        JCommentsContentPluginHelper::processForeignTags($row, true);
        JCommentsContentPluginHelper::clear($row, true);
    }
    return;
}
 function delete(&$pks)
 {
     $db = $this->getDbo();
     $id = is_array($pks) ? (int) $pks[0] : (int) $pks;
     $query = 'SELECT * FROM #__igallery WHERE id = ' . (int) $id;
     $db->setQuery($query);
     $category = $db->loadObject();
     if (strlen($category->menu_image_filename) > 2) {
         $query = 'SELECT menu_image_filename FROM #__igallery WHERE menu_image_filename = ' . $this->_db->Quote($category->menu_image_filename);
         $db->setQuery($query);
         $db->query();
         $numRows = $db->getNumRows();
         $deleteOrig = $numRows > 1 ? false : true;
         igFileHelper::deleteImage($category->menu_image_filename, $deleteOrig);
     }
     $query = 'SELECT id, filename FROM #__igallery_img WHERE gallery_id = ' . (int) $id;
     $db->setQuery($query);
     $photoList = $db->loadObjectList();
     for ($i = 0; $i < count($photoList); $i++) {
         $photo = $photoList[$i];
         $query = 'SELECT filename FROM #__igallery_img WHERE filename = ' . $db->Quote($photo->filename);
         $db->setQuery($query);
         $db->query();
         $numRows = $db->getNumRows();
         $deleteOrig = $numRows > 1 ? false : true;
         igFileHelper::deleteImage($photo->filename, $deleteOrig);
         $query = 'DELETE FROM #__igallery_img WHERE id = ' . (int) $photo->id;
         $db->setQuery($query);
         if (!$db->query()) {
             $this->setError($db->getErrorMsg());
             return false;
         }
         $commentsPath = JPATH_SITE . '/components/com_jcomments/jcomments.php';
         if (file_exists($commentsPath)) {
             require_once $commentsPath;
             JCommentsModel::deleteComments((int) $photo->id, 'com_igallery');
         }
         $alPath = JPATH_SITE . '/components/com_alratings/classes/alratings.php';
         if (file_exists($alPath)) {
             require_once $alPath;
             ALRatings::deleteRating('com_igallery', (int) $photo->id);
         }
     }
     $query = 'DELETE FROM #__igallery WHERE id = ' . (int) $id;
     $db->setQuery($query);
     if (!$db->query()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     $query = 'UPDATE #__igallery SET parent = 0 WHERE parent = ' . (int) $id;
     $db->setQuery($query);
     if (!$db->query()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     $row = $this->getTable('igallery');
     $row->reorder('parent = ' . (int) $category->parent);
     return true;
 }