public function store($updateNulls = false) { $config = JCommentsFactory::getConfig(); if ($this->parent > 0) { $parent = new JCommentsTableComment($this->_db); if ($parent->load($this->parent)) { if (empty($this->title) && $config->getInt('comment_title') == 1) { if (!empty($parent->title)) { if (strpos($parent->title, JText::_('COMMENT_TITLE_RE')) === false) { $this->title = JText::_('COMMENT_TITLE_RE') . ' ' . $parent->title; } else { $this->title = $parent->title; } } } $this->thread_id = $parent->thread_id ? $parent->thread_id : $parent->id; $this->level = $parent->level + 1; $this->path = $parent->path . ',' . $parent->id; } } else { if (empty($this->title) && $config->getInt('comment_title') == 1) { $title = JCommentsObjectHelper::getTitle($this->object_id, $this->object_group, $this->lang); if (!empty($title)) { $this->title = JText::_('COMMENT_TITLE_RE') . ' ' . $title; } } $this->path = '0'; } if (isset($this->datetime)) { unset($this->datetime); } if (isset($this->author)) { unset($this->author); } return parent::store($updateNulls); }
function canPublishForObject($object_id, $object_group) { return $this->userID && $this->canPublishForMyObject && $this->userID == JCommentsObjectHelper::getOwner($object_id, $object_group) ? 1 : 0; }
function show($lists) { global $mainframe; $filter = ''; $filterClear = ''; if (isset($lists['fog'])) { $filter .= ' ' . $lists['fog']; $filterClear .= "document.getElementById('fog').value='';"; } if (isset($lists['flang'])) { $filter .= ' ' . $lists['flang']; $filterClear .= "document.getElementById('flang').value='';"; } if (isset($lists['foid'])) { $filter .= ' ' . $lists['foid']; $filterClear .= "document.getElementById('foid').value='';"; } if (isset($lists['fauthor']) && $lists['fauthor'] != '') { $filter .= ' ' . $lists['fauthor']; $filterClear .= "document.getElementById('fauthor').value='';"; } if (isset($lists['fstate'])) { $filter .= ' ' . $lists['fstate']; $filterClear .= "document.getElementById('fstate').value='';\n"; } if (JCOMMENTS_JVERSION == '1.5') { ?> <script type="text/javascript"> <!-- function tableOrdering( order, dir, task ) { var form = document.adminForm; form.filter_order.value = order; form.filter_order_Dir.value = dir; document.adminForm.submit( task ); } //--> </script> <?php } ?> <form action="<?php echo JCOMMENTS_INDEX; ?> " method="post" name="adminForm"> <table class="adminheading" width="100%"> <tr> <?php if (JCOMMENTS_JVERSION == '1.0') { ?> <th style="background-image: none; padding: 0;"><img src="./components/com_jcomments/assets/subscriptions48x48.png" width="48" height="48" align="middle" /> <?php echo JText::_('A_SUBSCRIPTIONS'); ?> </th> <?php } ?> <td nowrap="nowrap" align="left" width="50%"> <label for="search"><?php echo JText::_('A_FILTER'); ?> :</label> <input type="text" name="search" id="search" value="<?php echo $lists['search']; ?> " class="text_area" onchange="document.adminForm.submit();" /> <button onclick="this.form.submit();"><?php echo JText::_('Go'); ?> </button> <button onclick="document.getElementById('search').value='';<?php echo $filterClear; ?> this.form.submit();"><?php echo JText::_('Reset'); ?> </button> </td> <td nowrap="nowrap" align="right" width="50%"> <?php if (trim($filter) != '') { echo $filter; } ?> </td> </tr> </table> <table class="adminlist" cellspacing="1"> <thead> <tr> <th width="5" class="title"><label for="toggle">#</label></th> <th width="5"><input type="checkbox" id="toggle" name="toggle" value="" onclick="checkAll(<?php echo count($lists['rows']); ?> );" /></th> <?php if (JCOMMENTS_JVERSION == '1.5') { ?> <th width="20%" align="left" nowrap="nowrap"><?php echo JHTML::_('grid.sort', 'Name', 'js.name', $lists['order_Dir'], $lists['order']); ?> </th> <th width="20%" align="left"><?php echo JHTML::_('grid.sort', 'E-mail', 'js.email', $lists['order_Dir'], $lists['order']); ?> </th> <th width="40%" align="left"><?php echo JText::_('A_COMMENT_OBJECT_TITLE'); ?> </th> <th width="10%" align="left"><?php echo JHTML::_('grid.sort', 'A_COMPONENT', 'js.object_group', $lists['order_Dir'], $lists['order']); ?> </th> <th width="10%" nowrap="nowrap"><?php echo JHTML::_('grid.sort', 'State', 'js.published', $lists['order_Dir'], $lists['order']); ?> </th> <?php } else { ?> <th width="20%" align="left" nowrap="nowrap"><?php echo JText::_('Name'); ?> </th> <th width="20%" align="left"><?php echo JText::_('E-mail'); ?> </th> <th width="40%" align="left"><?php echo JText::_('A_COMMENT_OBJECT_TITLE'); ?> </th> <th width="10%" align="left"><?php echo JText::_('A_COMPONENT'); ?> </th> <th width="10%" nowrap="nowrap"><?php echo JText::_('State'); ?> </th> <?php } ?> </tr> </thead> <tbody> <?php for ($i = 0, $k = 0, $n = count($lists['rows']); $i < $n; $i++) { $row =& $lists['rows'][$i]; $task = $row->published ? 'subscription.unpublish' : 'subscription.publish'; $img = $row->published ? 'tick.png' : 'publish_x.png'; $row->title = JCommentsObjectHelper::getTitle($row->object_id, $row->object_group, $row->lang); $row->link = $mainframe->getCfg('live_site') . '/' . JCOMMENTS_INDEX . '?option=com_jcomments&task=go2object&object_id=' . $row->object_id . '&object_group=' . $row->object_group . '&no_html=1'; $link = JCOMMENTS_INDEX . '?option=com_jcomments&task=subscription.edit&hidemainmenu=1&cid=' . $row->id; $link_title = JCOMMENTS_JVERSION == '1.5' ? JText::_('Edit') : _E_EDIT; $statusTitle = $row->published ? JText::_('A_DISABLE') : JText::_('A_ENABLE'); ?> <tr class="<?php echo "row{$k}"; ?> "> <td><label for="cb<?php echo $i; ?> "><?php echo $i + 1 + $lists['pageNav']->limitstart; ?> </label></td> <td width="20"><input type="checkbox" id="cb<?php echo $i; ?> " name="cid[]" value="<?php echo $row->id; ?> " onclick="isChecked(this.checked);" /></td> <td align="left"><a href="<?php echo $link; ?> " title="<?php echo $link_title; ?> "><?php echo $row->name; ?> </a></td> <td align="left"><?php echo $row->email; ?> </td> <td align="left"><a href="<?php echo $row->link; ?> " title="<?php echo htmlspecialchars($row->title); ?> " target="_blank"><?php echo $row->title; ?> </a></td> <td align="left">[<?php echo $row->object_group; ?> ]</td> <td align="center"><a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i; ?> ','<?php echo $task; ?> ')" title="<?php echo $statusTitle; ?> "><img src="images/<?php echo $img; ?> " border="0" alt="<?php echo $statusTitle; ?> " /></a></td> </tr> <?php $k = 1 - $k; } ?> </tbody> <tfoot> <tr> <td colspan="15"><?php echo $lists['pageNav']->getListFooter(); ?> </td> </tr> </tfoot> </table> <input type="hidden" name="option" value="com_jcomments" /> <input type="hidden" name="task" value="subscriptions" /> <input type="hidden" name="boxchecked" value="0" /> <input type="hidden" name="hidemainmenu" value="0" /> <input type="hidden" name="filter_order" value="<?php echo $lists['order']; ?> " /> <input type="hidden" name="filter_order_Dir" value="" /> </form> <?php }
public static function showObjectComments() { $config = JCommentsFactory::getConfig(); if ($config->get('enable_rss') == '1') { $app = JFactory::getApplication('site'); $object_id = $app->input->getInt('object_id', 0); $object_group = JCommentsSecurity::clearObjectGroup($app->input->get('object_group', 'com_content')); $limit = $app->input->getInt('limit', $config->getInt('feed_limit', 100)); // if no group or id specified - return 404 if ($object_id == 0 || $object_group == '') { self::showNotFound(); return; } $lm = $limit != $config->getInt('feed_limit') ? '&limit=' . $limit : ''; if (JCommentsMultilingual::isEnabled()) { $language = JCommentsMultilingual::getLanguage(); $lp = '&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&task=rss&object_id=' . $object_id . '&object_group=' . $object_group . $lm . $lp . '&format=raw'); $object_title = JCommentsObjectHelper::getTitle($object_id, $object_group, $language); $object_link = JCommentsObjectHelper::getLink($object_id, $object_group, $language); $object_link = str_replace('amp;', '', JCommentsFactory::getAbsLink($object_link)); $rss = new JoomlaTuneFeed(); $rss->title = $object_title; $rss->link = $object_link; $rss->syndicationURL = $syndicationURL; $rss->description = JText::sprintf('OBJECT_FEED_DESCRIPTION', $rss->title); $options = array(); $options['object_id'] = $object_id; $options['object_group'] = $object_group; $options['lang'] = $language; $options['published'] = 1; $options['filter'] = 'c.deleted = 0'; $options['orderBy'] = 'c.date DESC'; $options['limit'] = $limit; $options['limitStart'] = 0; $options['objectinfo'] = true; $rows = JCommentsModel::getCommentsList($options); $word_maxlength = $config->getInt('word_maxlength'); foreach ($rows as $row) { $comment = JCommentsText::cleanText($row->comment); $title = $row->title; $author = JComments::getCommentAuthorName($row); if ($comment != '') { // apply censor filter $title = JCommentsText::censor($title); $comment = JCommentsText::censor($comment); // fix long words problem if ($word_maxlength > 0) { $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' '); if ($title != '') { $title = JCommentsText::fixLongWords($title, $word_maxlength, ' '); } } $item = new JoomlaTuneFeedItem(); $item->title = $title != '' ? $title : JText::sprintf('OBJECT_FEED_ITEM_TITLE', $author); $item->link = $object_link . '#comment-' . $row->id; $item->description = $comment; $item->source = $object_link; $item->pubDate = $row->date; $item->author = $author; $rss->addItem($item); } } $rss->display(); unset($rows, $rss); exit; } }
public static function show() { $app = JCommentsFactory::getApplication('administrator'); $context = 'com_jcomments.subscriptions.'; $object_group = trim($app->getUserStateFromRequest($context . 'fog', 'fog', '')); $object_id = intval($app->getUserStateFromRequest($context . 'foid', 'foid', 0)); $flang = trim($app->getUserStateFromRequest($context . 'flang', 'flang', '-1')); $fauthor = trim($app->getUserStateFromRequest($context . 'fauthor', 'fauthor', '')); $fstate = trim($app->getUserStateFromRequest($context . 'fstate', 'fstate', '-1')); $limit = intval($app->getUserStateFromRequest($context . 'limit', 'limit', $app->getCfg('list_limit'))); $limitstart = intval($app->getUserStateFromRequest($context . 'limitstart', 'limitstart', 0)); $filter_order = $app->getUserStateFromRequest($context . 'filter_order', 'filter_order', 'js.name'); $filter_order_Dir = $app->getUserStateFromRequest($context . 'filter_order_Dir', 'filter_order_Dir', 'asc'); $search = trim($app->getUserStateFromRequest($context . 'search', 'search', '')); if (JCOMMENTS_JVERSION == '1.0') { $search = strtolower($search); } else { $search = JString::strtolower($search); } if ($filter_order == '') { $filter_order = 'js.name'; } if ($filter_order_Dir == '') { $filter_order_Dir = 'asc'; } $lists['order'] = $filter_order; $lists['order_Dir'] = $filter_order_Dir; $lists['search'] = $search; $db = JCommentsFactory::getDBO(); $where = array(); if ($object_group != '') { $where[] = 'js.object_group = "' . $db->getEscaped($object_group, true) . '"'; } if ($object_id != 0) { $where[] = 'js.object_id = ' . intval($object_id); } if ($flang != '-1') { $where[] = 'js.lang = "' . $db->getEscaped($flang, true) . '"'; } if ($fauthor != '') { $where[] = 'js.name = "' . $db->getEscaped($fauthor, true) . '"'; } if ($fstate != '' && $fstate != '-1') { $where[] = 'js.published = ' . intval($fstate); } if ($search != '') { $where[] = '(js.name like "%' . $db->getEscaped($search, true) . '%" OR js.email like "%' . $db->getEscaped($search, true) . '%")'; } $query = "SELECT COUNT(*)" . " FROM #__jcomments_subscriptions AS js" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : ""); $db->setQuery($query); $total = $db->loadResult(); $lists['pageNav'] = JCommentsAdmin::getPagination($total, $limitstart, $limit); $query = "SELECT js.*, u.name AS editor" . " FROM #__jcomments_subscriptions AS js" . " LEFT JOIN #__users AS u ON u.id = js.userid" . (count($where) ? " WHERE " . implode(' AND ', $where) : "") . " ORDER BY " . $filter_order . ' ' . $filter_order_Dir; $db->setQuery($query, $lists['pageNav']->limitstart, $lists['pageNav']->limit); $lists['rows'] = $db->loadObjectList(); // Filter by object_group (component) $query = "SELECT DISTINCT(object_group) AS name, object_group AS value " . " FROM #__jcomments_subscriptions" . " ORDER BY name"; $db->setQuery($query); $rows = $db->loadObjectList(); $cnt = count($rows); if ($cnt > 1 || $cnt == 1 && $total == 0) { array_unshift($rows, JCommentsHTML::makeOption('', JText::_('A_FILTER_COMPONENT'), 'name', 'value')); $lists['fog'] = JCommentsHTML::selectList($rows, 'fog', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'name', 'value', $object_group); } else { if ($cnt == 1) { if ($object_group == '') { $object_group = $rows[0]->name; } } } unset($rows); if ($object_group != '') { $query = "SELECT DISTINCT object_id AS value, lang " . " FROM #__jcomments_subscriptions " . " WHERE object_group = " . $db->Quote($object_group) . ($flang != '-1' ? " AND lang = " . $db->Quote($flang) : ""); $db->setQuery($query); $rows = $db->loadObjectList(); for ($i = 0, $n = count($rows); $i < $n; $i++) { $rows[$i]->name = JCommentsObjectHelper::getTitle($rows[$i]->value, $object_group, $rows[$i]->lang); if ($rows[$i]->name == '') { $rows[$i]->name = 'Untitled' . $rows[$i]->value; } } // Don't show filter if we have more than 100 objects if (count($rows) > 1 && count($rows) < 100) { usort($rows, create_function('$a, $b', 'return strcasecmp( $a->name, $b->name);')); array_unshift($rows, JCommentsHTML::makeOption('', JText::_('A_FILTER_OBJECT'), 'value', 'name')); $lists['foid'] = JCommentsHTML::selectList($rows, 'foid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'name', $object_id); unset($rows); } } // Filter by language $query = "SELECT DISTINCT(lang) AS text, lang AS value " . " FROM #__jcomments_subscriptions" . " ORDER BY lang"; $db->setQuery($query); $rows = $db->loadObjectList(); if (count($rows) > 1) { array_unshift($rows, JCommentsHTML::makeOption('-1', JText::_('A_FILTER_LANGUAGE'), 'text', 'value')); $lists['flang'] = JCommentsHTML::selectList($rows, 'flang', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'text', 'value', $flang); } unset($rows); // Filter by published state $stateOptions = array(); $stateOptions[] = JCommentsHTML::makeOption('-1', JText::_('A_FILTER_STATE'), 'text', 'value'); $stateOptions[] = JCommentsHTML::makeOption('', JText::_('A_FILTER_STATE_ALL'), 'text', 'value'); $stateOptions[] = JCommentsHTML::makeOption('1', JText::_('A_FILTER_STATE_PUBLISHED'), 'text', 'value'); $stateOptions[] = JCommentsHTML::makeOption('0', JText::_('A_FILTER_STATE_UNPUBLISHED'), 'text', 'value'); $lists['fstate'] = JCommentsHTML::selectList($stateOptions, 'fstate', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'text', 'value', $fstate); unset($stateOptions); // Filter by author $lists['fauthor'] = ''; $db->setQuery("SELECT COUNT(DISTINCT(name)) FROM #__jcomments_subscriptions;"); $usersCount = $db->loadResult(); // Don't show filter if we have more than 100 comments' authors if ($usersCount > 0 && $usersCount < 100) { $query = "SELECT DISTINCT(name) AS author, name AS value " . " FROM #__jcomments_subscriptions" . " ORDER BY name"; $db->setQuery($query); $rows = $db->loadObjectList(); if (count($rows) > 1) { array_unshift($rows, JCommentsHTML::makeOption('', JText::_('A_FILTER_AUTHOR'), 'author', 'value')); $lists['fauthor'] = JCommentsHTML::selectList($rows, 'fauthor', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'author', 'value', $fauthor); } unset($rows); } HTML_JCommentsAdminSubscriptionManager::show($lists); }
function addComment($values = array()) { global $my, $mainframe; if (JCommentsSecurity::badRequest() == 1) { JCommentsSecurity::notAuth(); } $acl =& JCommentsFactory::getACL(); $config =& JCommentsFactory::getConfig(); $response =& JCommentsFactory::getAjaxResponse(); if ($acl->canComment()) { $values = JCommentsAJAX::prepareValues($_POST); $userIP = $acl->getUserIP(); if (!$my->id) { $noErrors = false; if (empty($values['name'])) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_NAME'), 'name'); } else { if (JCommentsSecurity::checkIsRegisteredUsername($values['name']) == 1) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_NAME_EXISTS'), 'name'); } else { if (JCommentsSecurity::checkIsForbiddenUsername($values['name']) == 1) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_FORBIDDEN_NAME'), 'name'); } else { if (preg_match('/[\\"\'\\[\\]\\=\\<\\>\\(\\)\\;]+/', $values['name'])) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_INVALID_NAME'), 'name'); } else { if ($config->get('username_maxlength') != 0 && JCommentsText::strlen($values['name']) > $config->get('username_maxlength')) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_TOO_LONG_USERNAME'), 'name'); } else { if ($config->get('author_email') == 2 && empty($values['email'])) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_EMAIL'), 'email'); } else { if (!empty($values['email']) && !preg_match(_JC_REGEXP_EMAIL2, $values['email'])) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_INCORRECT_EMAIL'), 'email'); } else { if ($config->get('author_email') != 0 && JCommentsSecurity::checkIsRegisteredEmail($values['email']) == 1) { // TODO: change this error message with more appropriate JCommentsAJAX::showErrorMessage(JText::_('ERROR_NAME_EXISTS'), 'email'); } else { if (empty($values['homepage']) && $config->get('author_homepage') == 2) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_HOMEPAGE'), 'homepage'); } else { $noErrors = true; } } } } } } } } } if (!$noErrors) { return $response; } } if ($acl->check('floodprotection') == 1 && JCommentsSecurity::checkFlood($userIP)) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_TOO_QUICK')); } else { if (empty($values['homepage']) && $config->get('author_homepage') == 3) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_HOMEPAGE'), 'homepage'); } else { if (empty($values['title']) && $config->get('comment_title') == 3) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_TITLE'), 'title'); } else { if (empty($values['comment'])) { JCommentsAJAX::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')) { JCommentsAJAX::showErrorMessage(JText::_('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')) { JCommentsAJAX::showErrorMessage(JText::_('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'])) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha'); JCommentsCaptcha::destroy(); $response->addScript("jcomments.clear('captcha');"); return $response; } } else { if ($config->getInt('enable_mambots') == 1) { require_once JCOMMENTS_HELPERS . DS . 'plugin.php'; JCommentsPluginHelper::importPlugin('jcomments'); $result = JCommentsPluginHelper::trigger('onJCommentsCaptchaVerify', array($values['captcha-refid'], &$response)); // if all plugins returns false if (!in_array(true, $result, true)) { JCommentsAJAX::showErrorMessage(JText::_('ERROR_CAPTCHA')); return $response; } } } } $db =& JCommentsFactory::getDBO(); // small fix (by default $my has empty 'name' and 'email' field) if ($my->id) { $currentUser = JCommentsFactory::getUser($my->id); $my->name = $currentUser->name; $my->username = $currentUser->username; $my->email = $currentUser->email; unset($currentUser); } $comment = new JCommentsDB($db); $comment->id = 0; $comment->name = $my->id ? $my->name : preg_replace("/[\\'\"\\>\\<\\(\\)\\[\\]]?+/i", '', $values['name']); $comment->username = $my->id ? $my->username : $comment->name; $comment->email = $my->id ? $my->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']; //$comment->comment = JCommentsText::nl2br(stripslashes($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) { JCommentsAJAX::showErrorMessage(JText::_('You have no rights to use this tag'), 'comment'); return $response; } } } if ($comment->comment == '') { JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment'); return $response; } $commentWithoutQuotes = $bbcode->removeQuotes($comment->comment); if ($commentWithoutQuotes == '') { JCommentsAJAX::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')) { JCommentsAJAX::showErrorMessage(JText::_('Your comment is too short'), 'comment'); return $response; } } unset($commentWithoutQuotes); $values['subscribe'] = isset($values['subscribe']) ? (int) $values['subscribe'] : 0; if ($values['subscribe'] == 1 && $comment->email == '') { JCommentsAJAX::showErrorMessage(JText::_('ERROR_SUBSCRIPTION_EMAIL'), 'email'); return $response; } $object_group = trim(strip_tags($values['object_group'])); $object_group = preg_replace('#[^0-9A-Za-z\\-\\_\\,\\.]#is', '', $object_group); $comment->object_id = (int) $values['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 = $my->id ? $my->id : 0; $comment->published = $acl->check('autopublish'); if (JCOMMENTS_JVERSION == '1.5') { $dateNow =& JFactory::getDate(); $comment->date = $dateNow->toMySQL(); } else { $comment->date = date('Y-m-d H:i:s', time() + $mainframe->getCfg('offset') * 60 * 60); } $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) { // trigger onBeforeCommentAdded event $allowed = true; if ($config->getInt('enable_mambots') == 1) { require_once JCOMMENTS_HELPERS . DS . 'plugin.php'; JCommentsPluginHelper::importPlugin('jcomments'); JCommentsPluginHelper::trigger('onBeforeCommentAdded', array(&$comment, &$response, &$allowed)); } if ($allowed === false) { 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 ($my->id && $merge_time > 0) { // load previous comment for same object and group $prevComment = JComments::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->datetime); 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); } } if ($comment->parent > 0) { $parent = new JCommentsDB($db); if ($parent->load($comment->parent)) { if ($config->getInt('comment_title') == 1 && $comment->title == '') { if (!empty($parent->title)) { $comment->title = JText::_('Re') . ' ' . $parent->title; } } $comment->level = $parent->level + 1; $comment->path = $parent->path . ',' . $parent->id; } } else { if ($config->getInt('comment_title') == 1 && $comment->title == '') { $object_title = JCommentsObjectHelper::getTitle($comment->object_id, $comment->object_group, $comment->lang); $comment->title = JText::_('Re') . ' ' . $object_title; } $comment->path = '0'; } // save new comment to database if (!$comment->store()) { $response->addScript("jcomments.clear('comment');"); if ($acl->check('enable_captcha') == 1) { JCommentsCaptcha::destroy(); $response->addScript("jcomments.clear('captcha');"); } $errorMessage = $db->getErrorMsg(); if ($errorMessage != '') { if ($my->usertype == 'Super Administrator') { JCommentsAJAX::showErrorMessage($db->getErrorMsg()); } } return $response; } // datetime field is used in prepareComment function $comment->datetime = $comment->date; if (is_string($comment->datetime)) { $comment->datetime = strtotime($comment->datetime); } if ($config->getInt('enable_mambots') == 1) { require_once JCOMMENTS_HELPERS . DS . 'plugin.php'; JCommentsPluginHelper::importPlugin('jcomments'); JCommentsPluginHelper::trigger('onAfterCommentAdded', array(&$comment, &$response, &$allowed)); } // 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); $comment->usertype = $my->id != 0 ? str_replace(' ', '-', strtolower($my->usertype)) : 'guest'; if ($merged) { $commentText = $comment->comment; JComments::prepareComment($comment); $tmpl =& JCommentsFactory::getTemplate(); $tmpl->load('tpl_comment'); $tmpl->addVar('tpl_comment', 'get_comment_body', 1); $tmpl->addObject('tpl_comment', 'comment', $comment); $html = $tmpl->renderTemplate('tpl_comment'); $html = JCommentsText::jsEscape($html); $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');"); $comment->comment = $commentText; } else { $count = JCommentsModel::getCommentsCount($comment->object_id, $comment->object_group); if ($config->get('template_view') == 'tree') { if ($count > 1) { $html = JComments::getCommentListItem($comment); $html = JCommentsText::jsEscape($html); $response->addScript("jcomments.updateTree('{$html}','{$comment->parent}');"); } 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();"); } } } JCommentsAJAX::showInfoMessage(JText::_('Thank you for your submission!')); } else { JCommentsAJAX::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');"); unset($comment); if ($acl->check('enable_captcha') == 1) { $captchaEngine = $config->get('captcha_engine', 'kcaptcha'); if ($captchaEngine == 'kcaptcha') { require_once JCOMMENTS_BASE . DS . 'jcomments.captcha.php'; JCommentsCaptcha::destroy(); $response->addScript("jcomments.clear('captcha');"); } } } else { JCommentsAJAX::showErrorMessage(JText::_('ERROR_DUPLICATE_COMMENT'), 'comment'); } } } } } } } } else { $response->addAlert(JText::_('ERROR_CANT_COMMENT')); } return $response; }
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') ? '&limit=' . $limit : ''; if (JCommentsMultilingual::isEnabled()) { $language = JCommentsMultilingual::getLanguage(); $lp = '&lang=' . $language; } else { $language = null; $lp = ''; } if (JCOMMENTS_JVERSION == '1.0') { $syndicationURL = $app->getCfg('live_site') . '/index2.php?option=com_jcomments&task=rss_user&userid=' . $userid . $lm . $lp . '&no_html=1'; } else { $liveSite = str_replace(JURI::root(true), '', $app->getCfg('live_site')); $syndicationURL = $liveSite . JRoute::_('index.php?option=com_jcomments&task=rss_user&userid=' . $userid . $lm . $lp . '&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; } }
public function store($updateNulls = false) { $config = JCommentsFactory::getConfig(); $app = JFactory::getApplication(); if ($app->isAdmin()) { $language = JFactory::getLanguage(); $language->load('com_jcomments', JPATH_SITE); if ($this->id == 0 && !empty($this->source)) { $this->comment = $this->clearComment($this->comment); $this->homepage = strip_tags($this->homepage); $this->title = strip_tags($this->title); if (!$this->userid) { $this->name = $this->clearComment($this->name); $this->username = $this->clearComment($this->username); } } } if ($this->parent > 0) { $parent = new JCommentsTableComment($this->_db); if ($parent->load($this->parent)) { if (empty($this->title) && $config->getInt('comment_title') == 1) { if (!empty($parent->title)) { if (strpos($parent->title, JText::_('COMMENT_TITLE_RE')) === false) { $this->title = JText::_('COMMENT_TITLE_RE') . ' ' . $parent->title; } else { $this->title = $parent->title; } } } $this->thread_id = $parent->thread_id ? $parent->thread_id : $parent->id; $this->level = $parent->level + 1; $this->path = $parent->path . ',' . $parent->id; } } else { if (empty($this->title) && $config->getInt('comment_title') == 1) { $title = JCommentsObjectHelper::getTitle($this->object_id, $this->object_group, $this->lang); if (!empty($title)) { $this->title = JText::_('COMMENT_TITLE_RE') . ' ' . $title; } } $this->path = '0'; } if (isset($this->datetime)) { unset($this->datetime); } if (isset($this->author)) { unset($this->author); } return parent::store($updateNulls); }
function redirectToObject() { global $mainframe; $object_id = (int) JCommentsInput::getVar('object_id', 0); $object_group = trim(strip_tags(JCommentsInput::getVar('object_group', 'com_content'))); if ($object_id != 0 && $object_group != '') { $link = JCommentsObjectHelper::getLink($object_id, $object_group); $link = str_replace('amp;', '', $link); if ($link == '') { $link = $mainframe->getCfg('live_site'); } } else { $link = $mainframe->getCfg('live_site'); } JCommentsRedirect($link); }
public static function refreshObjectsAjax() { $app = JFactory::getApplication(); $hash = $app->input->post->get('hash', ''); $step = $app->input->post->getInt('step'); $lang = $app->input->post->get('lang', ''); $count = 50; if ($hash === md5($app->getCfg('secret'))) { $db = JFactory::getDBO(); if ($step == 0) { if ($app->getCfg('caching') != 0) { // clean cache for all object groups $db->setQuery('SELECT DISTINCT object_group FROM #__jcomments_objects'); $rows = $db->loadColumn(); foreach ($rows as $row) { $cache = JFactory::getCache('com_jcomments_objects_' . strtolower($row)); $cache->clean(); } } $db->setQuery('TRUNCATE TABLE #__jcomments_objects'); $db->execute(); } $where = array(); $where[] = 'IFNULL(c.lang, "") <> ""'; // count objects without information $query = "SELECT COUNT(DISTINCT c.object_id, c.object_group, c.lang)" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : ""); $db->setQuery($query); $total = (int) $db->loadResult(); $count = 0; if ($total > 0) { $where[] = 'NOT EXISTS (SELECT o.id FROM #__jcomments_objects AS o WHERE o.object_id = c.object_id AND o.object_group = c.object_group AND o.lang = c.lang)'; // get list of first objects without information $query = "SELECT DISTINCT c.object_id, c.object_group, c.lang" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . " ORDER BY c.object_group, c.lang"; $db->setQuery($query, 0, $count); $rows = $db->loadObjectList(); $i = 0; $multilanguage = JCommentsMultilingual::isEnabled(); $nextLanguage = $lang; if (count($rows)) { foreach ($rows as $row) { if ($nextLanguage != $row->lang && $multilanguage) { $nextLanguage = $row->lang; break; } // retrieve and store object information JCommentsObjectHelper::storeObjectInfo($row->object_id, $row->object_group, $row->lang, false, true); $i++; } } if ($i > 0) { $db->setQuery("SELECT COUNT(*) FROM #__jcomments_objects"); $count = (int) $db->loadResult(); } $percent = ceil($count / $total * 100); $percent = min($percent, 100); } else { $percent = 100; } $step++; $lang_codes = JLanguageHelper::getLanguages('lang_code'); $language_sef = isset($lang_codes[$nextLanguage]) ? $lang_codes[$nextLanguage]->sef : $nextLanguage; $data = array('count' => $count, 'total' => $total, 'percent' => $percent, 'step' => $step, 'hash' => $hash, 'object_group' => null, 'lang' => $nextLanguage, 'lang_sef' => $language_sef); echo json_encode($data); } $app->close(); }
function onContentAfterSave($context, $article, $isNew) { // Check we are handling the frontend edit form. if ($context == 'com_content.form' && !$isNew) { require_once JPATH_ROOT . '/components/com_jcomments/helpers/content.php'; if (JCommentsContentPluginHelper::checkCategory($article->catid)) { require_once JPATH_ROOT . '/components/com_jcomments/helpers/object.php'; JCommentsObjectHelper::storeObjectInfo($article->id, 'com_content'); } } }
/** * Prepares data for notification * * @param array $data An associative array of notification data * @param string $type Type of notification * * @return mixed */ private static function prepareData($data, $type) { require_once JPATH_ROOT . '/components/com_jcomments/jcomments.php'; $object = JCommentsObjectHelper::getObjectInfo($data['comment']->object_id, $data['comment']->object_group, $data['comment']->lang); $data['notification-type'] = $type; $data['object_title'] = $object->title; $data['object_link'] = JCommentsFactory::getAbsLink($object->link); $data['comment']->author = JComments::getCommentAuthorName($data['comment']); $data['comment']->title = JCommentsText::censor($data['comment']->title); $data['comment']->comment = JCommentsText::censor($data['comment']->comment); $data['comment']->comment = JCommentsFactory::getBBCode()->replace($data['comment']->comment); if (JCommentsFactory::getConfig()->getInt('enable_custom_bbcode')) { $data['comment']->comment = JCommentsFactory::getCustomBBCode()->replace($data['comment']->comment, true); } $data['comment']->comment = trim(preg_replace('/(\\s){2,}/i', '\\1', $data['comment']->comment)); return $data; }
/** * Returns array of titles for given objects * * @static * @access public * @param array $object_id * @param string $object_group * @return array */ function getTitles($object_ids, $object_group = 'com_content', $language = null) { static $cache = null; $count = count($object_ids); $titles = array(); if ($count) { if (!is_array($cache)) { $cache = array(); } $cache_key = md5($object_group . '_' . md5(serialize($object_ids)) . '_getTitles'); if (isset($cache[$cache_key])) { return $cache[$cache_key]; } ob_start(); include_once JCOMMENTS_BASE . DS . 'plugins' . DS . $object_group . '.plugin.php'; ob_end_clean(); $class = 'jc_' . $object_group; if (class_exists($class)) { if (is_callable(array($class, 'getTitles'))) { $titles = call_user_func(array($class, 'getTitles'), $object_ids, $language); } else { if (is_callable(array($class, 'getObjectTitle'))) { foreach ($object_ids as $object_id) { $titles[$object_id] = JCommentsObjectHelper::_getObjectVar($object_id, $object_group, $language, 'getObjectTitle'); } } } $cache[$cache_key] = $titles; } } return $titles; }
/** * Comments Search method * * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * @param string Target search string * @param string matching option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if restricted to areas, null if search all */ function plgSearchJComments($text, $phrase = '', $ordering = '', $areas = null) { $text = trim($text); if ($text == '') { return array(); } if (is_array($areas)) { if (!array_intersect($areas, array_keys(plgSearchJCommentsAreas()))) { return array(); } } if (file_exists(JCOMMENTS_BASE . DS . 'jcomments.php')) { require_once JCOMMENTS_BASE . DS . 'jcomments.php'; require_once JCOMMENTS_BASE . DS . 'jcomments.class.php'; require_once JCOMMENTS_HELPERS . DS . 'plugin.php'; require_once JCOMMENTS_HELPERS . DS . 'content.php'; require_once JCOMMENTS_HELPERS . DS . 'object.php'; $db =& JCommentsFactory::getDBO(); $pluginParams = JCommentsPluginHelper::getParams('jcomments', 'search'); $limit = $pluginParams->def('search_limit', 50); switch ($phrase) { case 'exact': $where = "LOWER(comment) LIKE '%{$text}%' OR LOWER(title) LIKE '%{$text}%'"; break; case 'all': case 'any': default: $words = explode(' ', $text); $wheres = array(); foreach ($words as $word) { $wheres2 = array(); $wheres2[] = "LOWER(name) LIKE '%{$word}%'"; $wheres2[] = "LOWER(comment) LIKE '%{$word}%'"; $wheres2[] = "LOWER(title) LIKE '%{$word}%'"; $wheres[] = implode(' OR ', $wheres2); } $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')'; break; } switch ($ordering) { case 'oldest': $order = 'date ASC'; break; case 'newest': default: $order = 'date DESC'; break; } $query = "SELECT " . "\n comment AS text" . "\n, date AS created" . "\n, '2' AS browsernav" . "\n, '" . JText::_('Comments') . "' AS section" . "\n, '' AS href" . "\n, id" . "\n, object_id" . "\n, object_group" . "\nFROM #__jcomments " . "\nWHERE published='1'" . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . "\n AND ({$where}) " . "\nORDER BY object_id, {$order}"; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $result = array(); $cnt = count($rows); if ($cnt > 0) { $last_object_id = -1; $object_link = ''; $acl =& JCommentsFactory::getACL(); $lang = JCommentsMultilingual::isEnabled() ? JCommentsMultilingual::getLanguage() : null; for ($i = 0; $i < $cnt; $i++) { if ($rows[$i]->object_id != $last_object_id) { $last_object_id = $rows[$i]->object_id; $object_link = JCommentsObjectHelper::getLink($rows[$i]->object_id, $rows[$i]->object_group); $object_title = JCommentsObjectHelper::getTitle($rows[$i]->object_id, $rows[$i]->object_group, $lang); } $rows[$i]->href = $object_link . '#comment-' . $rows[$i]->id; $comment = JCommentsText::cleanText($rows[$i]->text); if ($acl->check('enable_autocensor')) { $comment = JCommentsText::censor($comment); } if ($comment != '') { $rows[$i]->title = $object_title; $rows[$i]->text = $comment; $result[] = $rows[$i]; } } } unset($rows); return $result; } return array(); }
/** * Returns a reference to the global {@link JoomlaTuneTemplateRender} object, only creating it if it does not already exist. * * @param int $object_id * @param string $object_group * @param bool $needThisUrl * * @return JoomlaTuneTemplateRender */ public static function getTemplate($object_id = 0, $object_group = 'com_content', $needThisUrl = true) { global $Itemid; ob_start(); $app = JFactory::getApplication(); $language = JFactory::getLanguage(); $config = JCommentsFactory::getConfig(); $templateName = $config->get('template'); if (empty($templateName)) { $templateName = 'default'; $config->set('template', $templateName); } include_once JCOMMENTS_LIBRARIES . '/joomlatune/template.php'; $templateDefaultDirectory = JCOMMENTS_SITE . '/tpl/' . $templateName; $templateDirectory = $templateDefaultDirectory; $templateUrl = JURI::root() . 'components/com_jcomments/tpl/' . $templateName; $templateOverride = JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_jcomments/' . $templateName; if (is_dir($templateOverride)) { $templateDirectory = $templateOverride; $templateUrl = JURI::root() . 'templates/' . $app->getTemplate() . '/html/com_jcomments/' . $templateName; } $tmpl = JoomlaTuneTemplateRender::getInstance(); $tmpl->setRoot($templateDirectory); $tmpl->setDefaultRoot($templateDefaultDirectory); $tmpl->setBaseURI($templateUrl); $tmpl->addGlobalVar('siteurl', JURI::root()); $tmpl->addGlobalVar('charset', 'utf-8'); $tmpl->addGlobalVar('ajaxurl', JCommentsFactory::getLink('ajax', $object_id, $object_group)); $tmpl->addGlobalVar('smilesurl', JCommentsFactory::getLink('smilies', $object_id, $object_group)); if ($config->getInt('enable_rss') == 1) { $tmpl->addGlobalVar('rssurl', JCommentsFactory::getLink('rss', $object_id, $object_group)); } $tmpl->addGlobalVar('template', $templateName); $tmpl->addGlobalVar('template_url', $templateUrl); $tmpl->addGlobalVar('itemid', $Itemid ? $Itemid : 1); $tmpl->addGlobalVar('direction', $language->isRTL() ? 'rtl' : 'ltr'); $lang = $language->getTag(); $domain = $lang == 'ru-RU' || $lang == 'uk-UA' || $lang == 'be-BY' ? 'ru' : 'com'; $tmpl->addGlobalVar('comment-object_id', $object_id); $tmpl->addGlobalVar('comment-object_group', $object_group); if ($needThisUrl == true) { $tmpl->addGlobalVar('thisurl', JCommentsObjectHelper::getLink($object_id, $object_group, $lang)); } ob_end_clean(); return $tmpl; }
function onContentAfterSave($context, &$article, $isNew) { // Check we are handling the frontend edit form. if ($context == 'com_content.form') { require_once(JCOMMENTS_HELPERS . '/content.php'); if (JCommentsContentPluginHelper::checkCategory($article->catid)) { require_once(JCOMMENTS_HELPERS . '/object.php'); JCommentsObjectHelper::storeObjectInfo($article->id, 'com_content'); } } }
function feedLastCommentsGlobal() { global $mainframe; $object_group = trim(strip_tags(JCommentsInput::getVar('object_group', ''))); $object_group = preg_replace('#[^0-9A-Za-z\\-\\_\\,\\.]#is', '', $object_group); $limit = (int) JCommentsInput::getVar('limit', 100); $config =& JCommentsFactory::getConfig(); if ($config->get('enable_rss') == '1') { $iso = explode('=', _ISO); $charset = strtolower((string) $iso[1]); if (JCOMMENTS_JVERSION == '1.5') { $offset = $mainframe->getCfg('offset'); } else { $offset = $mainframe->getCfg('offset') + date('O') / 100; } $object_group = preg_replace('#[\'\\"]#ism', '', $object_group); $og = $object_group ? '&object_group=' . $object_group : ''; $lm = $limit != 100 ? '&limit=' . $limit : ''; if (JCOMMENTS_JVERSION == '1.5') { $syndicationURL = JoomlaTuneRoute::_('index.php?option=com_jcomments&task=rss_full' . $og . $lm . '&tmpl=component'); } else { $syndicationURL = $mainframe->getCfg('live_site') . '/index2.php?option=com_jcomments&task=rss_full' . $og . $lm . '&no_html=1'; } $rss = new JoomlaTuneFeed(); $rss->setOffset($offset); $rss->encoding = $charset; $rss->title = JText::_('Comments'); $rss->link = $mainframe->getCfg('live_site'); $rss->syndicationURL = $syndicationURL; $rss->description = JText::_('COMMENTS_FOR') . ' ' . $mainframe->getCfg('sitename'); if ($object_group != '') { $groups = explode(',', $object_group); } else { $groups = array(); } $db =& JCommentsFactory::getDBO(); $query = "SELECT id, title, object_id, object_group, userid, name, username, date, UNIX_TIMESTAMP(date) as date_ts, comment" . "\nFROM #__jcomments " . "\nWHERE published = '1'" . (count($groups) > 0 ? "\n AND (object_group = '" . implode("' OR object_group='", $groups) . "')" : '') . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . "\nORDER BY date DESC"; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $word_maxlength = $config->getInt('word_maxlength'); $lang = JCommentsMultilingual::isEnabled() ? JCommentsMultilingual::getLanguage() : null; foreach ($rows as $row) { $comment = JCommentsText::cleanText($row->comment); $author = JComments::getCommentAuthorName($row); if ($comment != '') { $object_title = JCommentsObjectHelper::getTitle($row->object_id, $row->object_group, $lang); $object_link = JCommentsObjectHelper::getLink($row->object_id, $row->object_group); $object_link = str_replace('amp;', '', $object_link); $object_link = JCommentsFactory::getAbsLink($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 ($comment != '') { $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' '); } } $item = new JoomlaTuneFeedItem(); $item->title = $object_title; $item->link = $object_link . '#comment-' . $row->id; $item->description = $author . ' ' . JText::_('Wrote') . ' "' . $comment . '"'; $item->source = $object_link; if (JCOMMENTS_JVERSION == '1.5') { $item->pubDate = $row->date; } else { $date = strtotime((string) $row->date) - $offset * 3600; $item->pubDate = date('Y-m-d H:i:s', $date); } $item->author = $author; $rss->addItem($item); } } $rss->display(); unset($rows, $rss); exit; } }
/** * Returns a reference to the global {@link JoomlaTuneTemplateRender} object, * only creating it if it doesn't already exist. * * @param int $object_id * @param string $object_group * @param bool $needThisUrl * @return JoomlaTuneTemplateRender */ public static function getTemplate($object_id = 0, $object_group = 'com_content', $needThisUrl = true) { global $Itemid; ob_start(); $app = JCommentsFactory::getApplication(); $config = JCommentsFactory::getConfig(); $templateName = $config->get('template'); if (empty($templateName)) { $templateName = 'default'; $config->set('template', $templateName); } include_once JCOMMENTS_LIBRARIES . '/joomlatune/template.php'; $templateDefaultDirectory = JCOMMENTS_BASE . '/tpl/' . $templateName; $templateDirectory = $templateDefaultDirectory; $templateUrl = $app->getCfg('live_site') . '/components/com_jcomments/tpl/' . $templateName; if (JCOMMENTS_JVERSION != '1.0') { $templateOverride = JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/com_jcomments/' . $templateName; if (is_dir($templateOverride)) { $templateDirectory = $templateOverride; $templateUrl = JURI::root() . 'templates/' . $app->getTemplate() . '/html/com_jcomments/' . $templateName; } } $tmpl = JoomlaTuneTemplateRender::getInstance(); $tmpl->setRoot($templateDirectory); $tmpl->setDefaultRoot($templateDefaultDirectory); $tmpl->setBaseURI($templateUrl); $tmpl->addGlobalVar('siteurl', $app->getCfg('live_site')); $tmpl->addGlobalVar('charset', strtolower(preg_replace('/charset=/', '', _ISO))); $tmpl->addGlobalVar('ajaxurl', JCommentsFactory::getLink('ajax', $object_id, $object_group)); $tmpl->addGlobalVar('smilesurl', JCommentsFactory::getLink('smiles', $object_id, $object_group)); if ($config->getInt('enable_rss') == 1) { $tmpl->addGlobalVar('rssurl', JCommentsFactory::getLink('rss', $object_id, $object_group)); } $tmpl->addGlobalVar('template', $templateName); $tmpl->addGlobalVar('template_url', $templateUrl); $tmpl->addGlobalVar('itemid', $Itemid ? $Itemid : 1); if (JCOMMENTS_JVERSION == '1.0') { $tmpl->addGlobalVar('direction', 'ltr'); } else { $language = JFactory::getLanguage(); $tmpl->addGlobalVar('direction', $language->isRTL() ? 'rtl' : 'ltr'); } $lang = $app->getCfg('lang'); if ($lang == 'russian' || $lang == 'ukrainian' || $lang == 'belorussian' || $lang == 'ru-RU' || $lang == 'uk-UA' || $lang == 'be-BY') { $tmpl->addGlobalVar('support', base64_decode('PGEgaHJlZj0iaHR0cDovL3d3dy5qb29tbGF0dW5lLnJ1IiB0aXRsZT0iSkNvbW1lbnRzIiB0YXJnZXQ9Il9ibGFuayI+SkNvbW1lbnRzPC9hPg==')); } else { $tmpl->addGlobalVar('support', base64_decode('PGEgaHJlZj0iaHR0cDovL3d3dy5qb29tbGF0dW5lLmNvbSIgdGl0bGU9IkpDb21tZW50cyIgdGFyZ2V0PSJfYmxhbmsiPkpDb21tZW50czwvYT4=')); } $tmpl->addGlobalVar('comment-object_id', $object_id); $tmpl->addGlobalVar('comment-object_group', $object_group); if ($needThisUrl == true) { $tmpl->addGlobalVar('thisurl', JCommentsObjectHelper::getLink($object_id, $object_group)); } ob_end_clean(); return $tmpl; }
public static function RefreshObjects($hash, $step = 0, $object_group = '', $lang = '') { if (JCommentsSecurity::badRequest() == 1) { JCommentsSecurity::notAuth(); } $response = JCommentsFactory::getAjaxResponse(); $app = JCommentsFactory::getApplication(); $count = 50; if ($hash === md5($app->getCfg('secret'))) { $db = JCommentsFactory::getDBO(); if ($step == 0) { $db->setQuery('DELETE FROM #__jcomments_objects WHERE 1=1'); $db->query(); } $where = array(); $where[] = 'IFNULL(c.lang, "") <> ""'; if (!empty($object_group)) { $where[] = 'c.object_group = ' . $db->Quote($object_group); } // count objects without information $query = "SELECT COUNT(DISTINCT c.object_id, c.object_group, c.lang)" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : ""); $db->setQuery($query); $objectsCount = (int) $db->loadResult(); $where[] = 'NOT EXISTS (SELECT o.id FROM #__jcomments_objects AS o WHERE o.object_id = c.object_id AND o.object_group = c.object_group AND o.lang = c.lang)'; // get list of first objects without information $query = "SELECT DISTINCT c.object_id, c.object_group, c.lang" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . " ORDER BY c.object_group, c.lang"; $db->setQuery($query, 0, $count); $rows = $db->loadObjectList(); $i = 0; $multilanguage = JCommentsMultilingual::isEnabled(); $nextLanguage = $lang; if (count($rows)) { foreach ($rows as $row) { if ($nextLanguage != $row->lang && $multilanguage) { $nextLanguage = $row->lang; break; } // retrieve and store object information JCommentsObjectHelper::storeObjectInfo($row->object_id, $row->object_group, $row->lang, false, true); $i++; } } $objectsRefreshed = 0; if ($i > 0) { $db->setQuery("SELECT COUNT(*) FROM #__jcomments_objects"); $objectsRefreshed = (int) $db->loadResult(); $response->addScript("JCommentsRefreshObjectsProgress({$objectsRefreshed}, {$objectsCount});"); } if ($objectsCount > $objectsRefreshed && ($i > 0 || $lang != $nextLanguage)) { // we need continue refresh $step++; $response->addScript("JCommentsRefreshObjectsAJAX('{$hash}', '{$step}', '', '{$nextLanguage}');"); } else { $response->addScript("JCommentsRefreshObjectsProgress({$objectsCount}, {$objectsCount});"); if ($app->getCfg('caching')) { // clean cache for all object groups $db->setQuery('SELECT DISTINCT object_group FROM #__jcomments_objects'); $rows = $db->loadResultArray(); foreach ($rows as $row) { $cache = JCommentsFactory::getCache('com_jcomments_objects_' . strtolower($row)); $cache->clean(); } } } } return $response; }
public static function executeCmd() { $app = JFactory::getApplication('site'); $cmd = strtolower($app->input->get('cmd', '')); $hash = $app->input->get('hash', ''); $id = $app->input->getInt('id', 0); $message = ''; $link = str_replace('/administrator', '', JURI::root()) . 'index.php'; $checkHash = JCommentsFactory::getCmdHash($cmd, $id); if ($hash == $checkHash) { $config = JCommentsFactory::getConfig(); if ($config->getInt('enable_quick_moderation') == 1) { JTable::addIncludePath(JCOMMENTS_TABLES); $comment = JTable::getInstance('Comment', 'JCommentsTable'); if ($comment->load($id)) { $link = JCommentsObjectHelper::getLink($comment->object_id, $comment->object_group, $comment->lang); $link = str_replace('&', '&', $link); switch ($cmd) { case 'publish': $comment->published = 1; $comment->store(); // send notification to comment subscribers JComments::sendToSubscribers($comment, true); $link .= '#comment-' . $comment->id; break; case 'unpublish': $comment->published = 0; $comment->store(); $acl = JCommentsFactory::getACL(); if ($acl->canPublish()) { $link .= '#comment-' . $comment->id; } else { $link .= '#comments'; } break; case 'delete': if ($config->getInt('delete_mode') == 0) { $comment->delete(); $link .= '#comments'; } else { $comment->markAsDeleted(); $link .= '#comment-' . $comment->id; } break; case 'ban': if ($config->getInt('enable_blacklist') == 1) { $acl = JCommentsFactory::getACL(); // we will not ban own IP ;) if ($comment->ip != $acl->getUserIP()) { $options = array(); $options['ip'] = $comment->ip; // check if this IP already banned if (JCommentsSecurity::checkBlacklist($options)) { $blacklist = JTable::getInstance('Blacklist', 'JCommentsTable'); $blacklist->ip = $comment->ip; $blacklist->store(); $message = JText::_('SUCCESSFULLY_BANNED'); } else { $message = JText::_('ERROR_IP_ALREADY_BANNED'); } } else { $message = JText::_('ERROR_YOU_CAN_NOT_BAN_YOUR_IP'); } } break; } JCommentsNotificationHelper::send(); } else { $message = JText::_('ERROR_NOT_FOUND'); } } else { $message = JText::_('ERROR_QUICK_MODERATION_DISABLED'); } } else { $message = JText::_('ERROR_QUICK_MODERATION_INCORRECT_HASH'); } $app->redirect($link, $message); }
public static function redirectToObject() { $app = JCommentsFactory::getApplication('site'); $object_id = (int) JCommentsInput::getVar('object_id', 0); $object_group = trim(strip_tags(JCommentsInput::getVar('object_group', 'com_content'))); $lang = trim(strip_tags(JCommentsInput::getVar('lang'))); if ($object_id != 0 && $object_group != '') { $link = JCommentsObjectHelper::getLink($object_id, $object_group, $lang); $link = str_replace('amp;', '', $link); if ($link == '') { $link = $app->getCfg('live_site'); } } else { $link = $app->getCfg('live_site'); } JCommentsRedirect($link); }
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&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 edit() { global $my, $mainframe; $id = JCommentsInput::getVar('cid', 0); if (is_array($id)) { $id = $id[0]; } $db =& JCommentsFactory::getDBO(); $row = new JCommentsDB($db); if ($row->load($id)) { $row->checkout($my->id); $row->comment = JCommentsText::br2nl($row->comment); $row->comment = htmlspecialchars($row->comment); $row->comment = JCommentsText::nl2br($row->comment); $row->comment = strip_tags(str_replace('<br />', "\n", $row->comment)); $row->object_title = JCommentsObjectHelper::getTitle($row->object_id, $row->object_group, $row->lang); $row->link = $mainframe->getCfg('live_site') . '/' . JCOMMENTS_INDEX . '?option=com_jcomments&task=go2object&object_id=' . $row->object_id . '&object_group=' . $row->object_group . '&no_html=1'; HTML_JComments::edit($row); } else { JCommentsRedirect(JCOMMENTS_INDEX . '?option=com_jcomments&task=comments'); } }