/** * 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(); }
function plgContentJCommentsLinksJ10($published, &$row, &$params, $page = 0) { global $mainframe, $task, $option, $Itemid, $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 . DS . 'plugin.php'; require_once JCOMMENTS_HELPERS . DS . 'content.php'; require_once JCOMMENTS_LIBRARIES . DS . 'joomlatune' . DS . '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', 'content'); if ((int) $pluginParams->get('show_frontpage', 1) == 0) { return; } } require_once JCOMMENTS_BASE . DS . 'jcomments.config.php'; require_once JCOMMENTS_BASE . DS . '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-comment', $readmore_link); $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_BASE . DS . 'model' . DS . 'jcomments.php'; $count = JCommentsModel::getCommentsCount($row->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)); } } if ($readmore_register == 1 && $count == 0) { $tmpl->addVar('tpl_links', 'comments_link_hidden', 1); } if ($readmore_register == 1) { $readmore_text = JText::_('READMORE_REGISTER'); } else { $readmore_text = JText::_('READMORE'); } $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'); $tmpl->addVar('tpl_links', 'link-comments-class', 'comments-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; }