get('authors_module_category'); if ($cid > 0) { $categories = modK2ToolsHelper::getCategoryChildren($cid); $categories[] = $cid; JArrayHelper::toInteger($categories); $where = " catid IN(".implode(',', $categories).") AND "; } $user = JFactory::getUser(); $aid = (int)$user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); if (K2_JVERSION != '15') { $languageCheck = ''; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $languageCheck = "AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').")"; } $query = "SELECT DISTINCT created_by FROM #__k2_items WHERE {$where} published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0 AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND created_by_alias='' {$languageCheck} AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") {$languageCheck})"; } else { $query = "SELECT DISTINCT created_by FROM #__k2_items WHERE {$where} published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0 AND access<={$aid} AND created_by_alias='' AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid} )"; } $db->setQuery($query); $rows = $db->loadObjectList(); $authors = array(); if (count($rows)) { foreach ($rows as $row) { $author = JFactory::getUser($row->created_by); $author->link = JRoute::_(K2HelperRoute::getUserRoute($author->id)); $query = "SELECT id, gender, description, image, url, `group`, plugins FROM #__k2_users WHERE userID=".(int)$author->id; $db->setQuery($query); $author->profile = $db->loadObject(); if ($params->get('authorAvatar')) { $author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth')); } if (K2_JVERSION != '15') { $languageCheck = ''; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $languageCheck = "AND i.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") AND c.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').")"; } $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid WHERE i.created_by = ".(int)$author->id." AND i.published = 1 AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." ) AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." ) AND i.trash = 0 AND created_by_alias='' AND c.published = 1 AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND c.trash = 0 {$languageCheck} ORDER BY created DESC"; } else { $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid WHERE i.created_by = ".(int)$author->id." AND i.published = 1 AND i.access <= {$aid} AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." ) AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." ) AND i.trash = 0 AND created_by_alias='' AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0 ORDER BY created DESC"; } $db->setQuery($query, 0, 1); $author->latest = $db->loadObject(); $author->latest->id = (int)$author->latest->id; $author->latest->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($author->latest->id.':'.urlencode($author->latest->alias), $author->latest->catid.':'.urlencode($author->latest->categoryalias)))); $query = "SELECT COUNT(*) FROM #__k2_comments WHERE published=1 AND itemID={$author->latest->id}"; $db->setQuery($query); $author->latest->numOfComments = $db->loadResult(); if ($params->get('authorItemsCounter')) { if (K2_JVERSION != '15') { $languageCheck = ''; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $languageCheck = "AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').")"; } $query = "SELECT COUNT(*) FROM #__k2_items WHERE {$where} published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0 AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") AND created_by_alias='' AND created_by={$row->created_by} {$languageCheck} AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") {$languageCheck} )"; } else { $query = "SELECT COUNT(*) FROM #__k2_items WHERE {$where} published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0 AND access<={$aid} AND created_by_alias='' AND created_by={$row->created_by} AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid} )"; } $db->setQuery($query); $numofitems = $db->loadResult(); $author->items = $numofitems; } $authors[] = $author; } } return $authors; } public static function getArchive(&$params) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $aid = (int)$user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $query = "SELECT DISTINCT MONTH(created) as m, YEAR(created) as y FROM #__k2_items WHERE published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0"; if (K2_JVERSION != '15') { $query .= " AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") "; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") "; } } else { $query .= " AND access<={$aid} "; } $catid = $params->get('archiveCategory', 0); if ($catid > 0) $query .= " AND catid=".(int)$catid; $query .= " ORDER BY created DESC"; $db->setQuery($query, 0, 12); $rows = $db->loadObjectList(); $months = array( JText::_('K2_JANUARY'), JText::_('K2_FEBRUARY'), JText::_('K2_MARCH'), JText::_('K2_APRIL'), JText::_('K2_MAY'), JText::_('K2_JUNE'), JText::_('K2_JULY'), JText::_('K2_AUGUST'), JText::_('K2_SEPTEMBER'), JText::_('K2_OCTOBER'), JText::_('K2_NOVEMBER'), JText::_('K2_DECEMBER'), ); if (count($rows)) { foreach ($rows as $row) { if ($params->get('archiveItemsCounter')) { $row->numOfItems = modK2ToolsHelper::countArchiveItems($row->m, $row->y, $catid); } else { $row->numOfItems = ''; } $row->name = $months[($row->m) - 1]; if ($params->get('archiveCategory', 0) > 0) { $row->link = JRoute::_(K2HelperRoute::getDateRoute($row->y, $row->m, null, $params->get('archiveCategory'))); } else { $row->link = JRoute::_(K2HelperRoute::getDateRoute($row->y, $row->m)); } $archives[] = $row; } return $archives; } } public static function tagCloud(&$params) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $aid = (int)$user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $query = "SELECT i.id FROM #__k2_items as i"; $query .= " LEFT JOIN #__k2_categories c ON c.id = i.catid"; $query .= " WHERE i.published=1 "; $query .= " AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." ) "; $query .= " AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )"; $query .= " AND i.trash=0 "; if (K2_JVERSION != '15') { $query .= " AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") "; } else { $query .= " AND i.access <= {$aid} "; } $query .= " AND c.published=1 "; $query .= " AND c.trash=0 "; if (K2_JVERSION != '15') { $query .= " AND c.access IN(".implode(',', $user->getAuthorisedViewLevels()).") "; } else { $query .= " AND c.access <= {$aid} "; } $cloudCategory = $params->get('cloud_category'); if (is_array($cloudCategory)) { $cloudCategory = array_filter($cloudCategory); } if ($cloudCategory) { if (!is_array($cloudCategory)) { $cloudCategory = (array)$cloudCategory; } foreach ($cloudCategory as $cloudCategoryID) { $categories[] = $cloudCategoryID; if ($params->get('cloud_category_recursive')) { $children = modK2ToolsHelper::getCategoryChildren($cloudCategoryID); $categories = @array_merge($categories, $children); } } $categories = @array_unique($categories); JArrayHelper::toInteger($categories); if (count($categories) == 1) { $query .= " AND i.catid={$categories[0]}"; } else { $query .= " AND i.catid IN(".implode(',', $categories).")"; } } if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") AND i.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") "; } } $db->setQuery($query); $IDs = K2_JVERSION == '30' ? $db->loadColumn() : $db->loadResultArray(); if (!is_array($IDs) || !count($IDs)) { return array(); } $query = "SELECT tag.name, tag.id FROM #__k2_tags as tag LEFT JOIN #__k2_tags_xref AS xref ON xref.tagID = tag.id WHERE xref.itemID IN (".implode(',', $IDs).") AND tag.published = 1"; $db->setQuery($query); $rows = $db->loadObjectList(); $cloud = array(); if (count($rows)) { foreach ($rows as $tag) { if (@array_key_exists($tag->name, $cloud)) { $cloud[$tag->name]++; } else { $cloud[$tag->name] = 1; } } $max_size = $params->get('max_size'); $min_size = $params->get('min_size'); $max_qty = max(array_values($cloud)); $min_qty = min(array_values($cloud)); $spread = $max_qty - $min_qty; if (0 == $spread) { $spread = 1; } $step = ($max_size - $min_size) / ($spread); $counter = 0; arsort($cloud, SORT_NUMERIC); $cloud = @array_slice($cloud, 0, $params->get('cloud_limit'), true); uksort($cloud, "strnatcasecmp"); foreach ($cloud as $key => $value) { $size = $min_size + (($value - $min_qty) * $step); $size = ceil($size); $tmp = new stdClass; $tmp->tag = $key; $tmp->count = $value; $tmp->size = $size; $tmp->link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($key))); $tags[$counter] = $tmp; $counter++; } return $tags; } } public static function getSearchCategoryFilter(&$params) { $result = ''; $cid = $params->get('category_id', NULL); if ($params->get('catfilter')) { if (!is_null($cid)) { if (is_array($cid)) { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $result = @implode(',', $categories); } else { JArrayHelper::toInteger($cid); $result = implode(',', $cid); } } else { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $result = @implode(',', $categories); } else { $result = (int)$cid; } } } } return $result; } public static function hasChildren($id) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $aid = (int)$user->get('aid'); $id = (int)$id; $db = JFactory::getDBO(); $query = "SELECT * FROM #__k2_categories WHERE parent={$id} AND published=1 AND trash=0 "; if (K2_JVERSION != '15') { $query .= " AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") "; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") "; } } else { $query .= " AND access <= {$aid}"; } $db->setQuery($query); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { echo $db->stderr(); return false; } if (count($rows)) { return true; } else { return false; } } public static function treerecurse(&$params, $id = 0, $level = 0, $begin = false) { static $output; if ($begin) { $output = ''; } $mainframe = JFactory::getApplication(); $root_id = (int)$params->get('root_id'); $end_level = $params->get('end_level', NULL); $id = (int)$id; $catid = JRequest::getInt('id'); $option = JRequest::getCmd('option'); $view = JRequest::getCmd('view'); $user = JFactory::getUser(); $aid = (int)$user->get('aid'); $db = JFactory::getDBO(); switch ($params->get('categoriesListOrdering')) { case 'alpha' : $orderby = 'name'; break; case 'ralpha' : $orderby = 'name DESC'; break; case 'order' : $orderby = 'ordering'; break; case 'reversedefault' : $orderby = 'id DESC'; break; default : $orderby = 'id ASC'; break; } if (($root_id != 0) && ($level == 0)) { $query = "SELECT * FROM #__k2_categories WHERE parent={$root_id} AND published=1 AND trash=0 "; } else { $query = "SELECT * FROM #__k2_categories WHERE parent={$id} AND published=1 AND trash=0 "; } if (K2_JVERSION != '15') { $query .= " AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") "; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") "; } } else { $query .= " AND access <= {$aid}"; } $query .= " ORDER BY {$orderby}"; $db->setQuery($query); $rows = $db->loadObjectList(); if ($db->getErrorNum()) { echo $db->stderr(); return false; } if ($level < intval($end_level) || is_null($end_level)) { $output .= '