Esempio n. 1
0
 public static function show()
 {
     require_once JCOMMENTS_BASE . '/jcomments.php';
     $app = JCommentsFactory::getApplication('administrator');
     $context = 'com_jcomments.comments.';
     $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', ''));
     $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', 'c.date');
     $filter_order_Dir = $app->getUserStateFromRequest($context . 'filter_order_Dir', 'filter_order_Dir', 'desc');
     $search = trim($app->getUserStateFromRequest($context . 'search', 'search', ''));
     if ($filter_order == '') {
         $filter_order = 'c.date';
     }
     if ($filter_order_Dir == '') {
         $filter_order_Dir = 'desc';
     }
     if (JCOMMENTS_JVERSION == '1.0') {
         $search = strtolower($search);
     } else {
         $search = JString::strtolower($search);
     }
     $lists['order'] = $filter_order;
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['search'] = $search;
     $db = JCommentsFactory::getDBO();
     // load object_groups (components)
     $query = "SELECT DISTINCT(object_group) AS name, object_group AS value " . " FROM #__jcomments_objects " . " WHERE object_group <> ''" . " ORDER BY object_group";
     $db->setQuery($query);
     $objectGroups = $db->loadObjectList('name');
     $cnt = count($objectGroups);
     if ($cnt == 0 || $cnt > 0 && !in_array($object_group, array_keys($objectGroups))) {
         $app->setUserState($context . "fog", '');
         $app->setUserState($context . "foid", '');
         $object_group = '';
     }
     $where = array();
     if ($object_group != '') {
         $where[] = 'c.object_group = ' . $db->Quote($object_group);
     } else {
         $object_id = 0;
         $app->setUserState($context . "foid", '');
     }
     if ($object_id != 0) {
         $where[] = 'c.object_id = ' . intval($object_id);
     }
     if ($flang != '-1') {
         $where[] = 'c.lang = ' . $db->Quote($flang);
     }
     if (trim($fauthor) != '') {
         $where[] = 'c.name = ' . $db->Quote($fauthor);
     }
     if ($fstate != '' && $fstate != '-1') {
         if ($fstate == '2') {
             $where[] = 'EXISTS (SELECT * FROM #__jcomments_reports AS r WHERE r.commentid = c.id)';
         } else {
             $where[] = 'c.published = ' . intval($fstate);
         }
     }
     if ($search != '') {
         $where[] = '(' . 'LOWER(c.comment) like "%' . $db->getEscaped($search, true) . '%" OR ' . 'LOWER(c.title) like "%' . $db->getEscaped($search, true) . '%" OR ' . 'LOWER(c.name) like "%' . $db->getEscaped($search, true) . '%" OR ' . 'LOWER(c.username) like "%' . $db->getEscaped($search, true) . '%" OR ' . 'LOWER(c.email) like "%' . $db->getEscaped($search, true) . '%"' . ')';
     }
     // TODO: add filter to show deleted comments
     $where[] = 'c.deleted = 0';
     $query = "SELECT COUNT(*)" . "\nFROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "");
     $db->setQuery($query);
     $total = $db->loadResult();
     $lists['pageNav'] = JCommentsAdmin::getPagination($total, $limitstart, $limit);
     $query = "SELECT c.*, u.name AS editor, js.id as subscription, (select count(*) from #__jcomments_reports where commentid = c.id) as reports" . ", jo.title AS object_title, jo.link AS object_link" . "\nFROM #__jcomments AS c" . "\n LEFT JOIN #__jcomments_objects AS jo ON jo.object_id = c.object_id AND jo.object_group = c.object_group AND jo.lang = c.lang" . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" . "\n LEFT JOIN #__jcomments_subscriptions AS js ON js.object_id = c.object_id AND js.object_group = c.object_group AND ((c.userid > 0 AND js.userid = c.userid) OR (js.email <> '' AND c.email <> '' AND js.email = c.email)) AND js.lang = c.lang" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nORDER BY " . $filter_order . ' ' . $filter_order_Dir;
     $db->setQuery($query, $lists['pageNav']->limitstart, $lists['pageNav']->limit);
     $lists['rows'] = $db->loadObjectList();
     // Filter by object_group (component)
     $cnt = count($objectGroups);
     if (JCOMMENTS_JVERSION == '1.0') {
         $a = array();
         if (is_array($objectGroups)) {
             foreach ($objectGroups as $o) {
                 $a[] = $o;
             }
         }
         $objectGroups = $a;
     }
     if ($cnt > 1 || $cnt == 1 && $total == 0) {
         array_unshift($objectGroups, JCommentsHTML::makeOption('', JText::_('A_FILTER_COMPONENT'), 'name', 'value'));
         $lists['fog'] = JCommentsHTML::selectList($objectGroups, 'fog', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'name', 'value', $object_group);
     } else {
         if ($cnt == 1) {
             /*
              			if ($object_group == '') {
             	$aGroups = array_keys($objectGroups);
             	$object_group = array_pop($aGroups);
             }
             */
         }
     }
     unset($objectGroups);
     // 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');
     $stateOptions[] = JCommentsHTML::makeOption('2', JText::_('A_FILTER_STATE_REPORTED'), 'text', 'value');
     $lists['fstate'] = JCommentsHTML::selectList($stateOptions, 'fstate', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'text', 'value', $fstate);
     unset($stateOptions);
     // Filter by language
     $query = "SELECT DISTINCT(lang) AS text, lang AS value " . " FROM #__jcomments_objects " . "\nORDER 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 author
     $lists['fauthor'] = '';
     // Do not use user filter if we have more than 5000 comments
     if ($total <= 5000) {
         $db->setQuery("SELECT COUNT(DISTINCT(name)) FROM #__jcomments;");
         $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 " . "\nFROM #__jcomments" . "\nWHERE name <> ''" . "\nORDER 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_JComments::show($lists);
 }
Esempio n. 2
0
 function show()
 {
     global $mainframe;
     require_once JCOMMENTS_BASE . DS . 'jcomments.php';
     $option = JCommentsInput::getVar('option');
     $object_group = trim($mainframe->getUserStateFromRequest("fog{$option}", 'fog', ''));
     $object_id = intval($mainframe->getUserStateFromRequest("foid{$option}", 'foid', 0));
     $flang = trim($mainframe->getUserStateFromRequest("flang{$option}", 'flang', ''));
     $fauthor = trim($mainframe->getUserStateFromRequest("fauthor{$option}", 'fauthor', ''));
     $fstate = trim($mainframe->getUserStateFromRequest("fstate{$option}", 'fstate', ''));
     $limit = intval($mainframe->getUserStateFromRequest("view{$option}limit", 'limit', $mainframe->getCfg('list_limit')));
     $limitstart = intval($mainframe->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0));
     $filter_order = $mainframe->getUserStateFromRequest($option . '.comments.filter_order', 'filter_order', 'c.date');
     $filter_order_Dir = $mainframe->getUserStateFromRequest($option . '.comments.filter_order_Dir', 'filter_order_Dir', 'desc');
     $search = trim($mainframe->getUserStateFromRequest($option . '.comments.search', 'search', ''));
     if ($filter_order == "") {
         $filter_order = 'c.date';
     }
     if ($filter_order_Dir == "") {
         $filter_order_Dir = 'desc';
     }
     if (JCOMMENTS_JVERSION == '1.5') {
         $search = JString::strtolower($search);
     } else {
         $search = strtolower($search);
     }
     $lists['order'] = $filter_order;
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['search'] = $search;
     $db =& JCommentsFactory::getDBO();
     // load object_groups (components)
     $query = "SELECT DISTINCT(object_group) AS name, object_group AS value " . "\nFROM #__jcomments " . "\nORDER BY object_group";
     $db->setQuery($query);
     $objectGroups = $db->loadObjectList('name');
     $cnt = count($objectGroups);
     if ($cnt == 0 || $cnt > 0 && !in_array($object_group, array_keys($objectGroups))) {
         $mainframe->setUserState("fog{$option}", '');
         $mainframe->setUserState("foid{$option}", '');
         $object_group = '';
     }
     $where = array();
     if ($object_group != '') {
         $where[] = 'c.object_group = "' . $object_group . '"';
     } else {
         $object_id = 0;
         $mainframe->setUserState("foid{$option}", '');
     }
     if ($object_id != 0) {
         $where[] = 'c.object_id = ' . $object_id;
     }
     if ($flang != '') {
         $where[] = 'c.lang = "' . $flang . '"';
     }
     if (trim($fauthor) != '') {
         $where[] = 'c.name = "' . $fauthor . '"';
     }
     if (trim($fstate) != '' && trim($fstate) != '-1') {
         $where[] = 'c.published = "' . intval($fstate) . '"';
     }
     if ($search != '') {
         $where[] = '(' . 'LOWER(c.comment) like "%' . $search . '%" OR ' . 'LOWER(c.title) like "%' . $search . '%" OR ' . 'LOWER(c.name) like "%' . $search . '%" OR ' . 'LOWER(c.username) like "%' . $search . '%" OR ' . 'LOWER(c.email) like "%' . $search . '%"' . ')';
     }
     $query = "SELECT COUNT(*)" . "\nFROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "");
     $db->setQuery($query);
     $total = $db->loadResult();
     if (JCOMMENTS_JVERSION == '1.0') {
         require_once $mainframe->getCfg('absolute_path') . DS . 'administrator' . DS . 'includes' . DS . 'pageNavigation.php';
         $lists['pageNav'] = new mosPageNav($total, $limitstart, $limit);
     } else {
         jimport('joomla.html.pagination');
         $lists['pageNav'] = new JPagination($total, $limitstart, $limit);
     }
     $query = "SELECT c.*, u.name AS editor, js.id as subscription" . "\nFROM #__jcomments AS c" . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" . "\n LEFT JOIN #__jcomments_subscriptions AS js ON js.object_id = c.object_id AND js.object_group = c.object_group AND ((c.userid > 0 AND js.userid = c.userid) OR (js.email <> '' AND c.email <> '' AND js.email = c.email)) AND js.lang = c.lang" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nORDER BY " . $filter_order . ' ' . $filter_order_Dir;
     $db->setQuery($query, $lists['pageNav']->limitstart, $lists['pageNav']->limit);
     $lists['rows'] = $db->loadObjectList();
     // Filter by object_group (component)
     $cnt = count($objectGroups);
     if (JCOMMENTS_JVERSION == '1.0') {
         $a = array();
         if (is_array($objectGroups)) {
             foreach ($objectGroups as $o) {
                 $a[] = $o;
             }
         }
         $objectGroups = $a;
     }
     if ($cnt > 1 || $cnt == 1 && ($total = 0)) {
         array_unshift($objectGroups, JCommentsHTML::makeOption('', JText::_('A_FILTER_ALL_COMPONENTS'), 'name', 'value'));
         $lists['fog'] = JCommentsHTML::selectList($objectGroups, 'fog', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'name', 'value', $object_group);
     } else {
         if ($cnt == 1) {
             if ($object_group == '') {
                 $aGroups = array_keys($objectGroups);
                 $object_group = array_pop($aGroups);
             }
         }
     }
     unset($objectGroups);
     // TODO: found more simple way to get commented objects titles
     /*
     $lists['foid'] = '';
     
     if ($object_group != '') {
     	$query = "SELECT DISTINCT(object_id) AS value "
     		. "\nFROM #__jcomments "
     		. "\nWHERE object_group = '" . $object_group . "'"
     		. (($flang != '') ? "AND lang = '" . $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, $flang);
     		if ($rows[$i]->name == '') {
     			$rows[$i]->name = 'Untitled' . $rows[$i]->value;
     		}
     	}
     
     	if (count($rows) > 0) {
     		usort($rows, create_function('$a, $b', 'return strcasecmp( $a->name, $b->name);'));
     		array_unshift($rows, JCommentsHTML::makeOption('', '', 'name', 'value'));
     		$lists['foid'] = JCommentsHTML::selectList($rows, 'foid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'name', $object_id);
     		unset($rows);
     	}
     }
     */
     // Filter by published state
     $stateOptions = array();
     $stateOptions[] = JCommentsHTML::makeOption('', JText::_('Select state'), 'text', 'value');
     $stateOptions[] = JCommentsHTML::makeOption('-1', JText::_('All'), 'text', 'value');
     $stateOptions[] = JCommentsHTML::makeOption('1', JText::_('Published'), 'text', 'value');
     $stateOptions[] = JCommentsHTML::makeOption('0', JText::_('Unpublished'), 'text', 'value');
     $lists['fstate'] = JCommentsHTML::selectList($stateOptions, 'fstate', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'text', 'value', $fstate);
     unset($stateOptions);
     // Filter by language
     $query = "SELECT DISTINCT(lang) AS text, lang AS value " . "\nFROM #__jcomments" . "\nORDER BY lang";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if (count($rows) > 1) {
         array_unshift($rows, JCommentsHTML::makeOption('', '', 'text', 'value'));
         $lists['flang'] = JCommentsHTML::selectList($rows, 'flang', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'text', 'value', $flang);
     }
     unset($rows);
     // Filter by author
     $lists['fauthor'] = '';
     $db->setQuery("SELECT COUNT(DISTINCT(name)) FROM #__jcomments;");
     $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 " . "\nFROM #__jcomments" . "\nWHERE name <> ''" . "\nORDER BY name";
         $db->setQuery($query);
         $rows = $db->loadObjectList();
         if (count($rows) > 1) {
             array_unshift($rows, JCommentsHTML::makeOption('', JText::_('A_FILTER_ALL_AUTHORS'), 'author', 'value'));
             $lists['fauthor'] = JCommentsHTML::selectList($rows, 'fauthor', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'author', 'value', $fauthor);
         }
         unset($rows);
     }
     HTML_JComments::show($lists);
 }