public static function getArchive($params) { $model = K2Model::getInstance('Items'); $model->setState('site', true); $filter = $params->get('archiveCategory'); $model->setState('category.filter', $filter); $model->setState('sorting', 'created.reverse'); $rows = $model->getArchive(); $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')); $archives = array(); $root = isset($filter->categories[0]) ? $filter->categories[0] : 0; foreach ($rows as $row) { $row->numOfItems = ''; if ($params->get('archiveItemsCounter')) { $row->numOfItems = self::countArchiveItems($row->month, $row->year, $root); } $row->name = $months[$row->month - 1]; $row->link = JRoute::_(K2HelperRoute::getDateRoute($row->year, $row->month, null, $root)); // Legacy $row->y = $row->year; $archives[] = $row; } return $archives; }
function getDateLink($day, $month, $year) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $aid = $user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $languageCheck = ''; if (K2_JVERSION != '15') { $accessCheck = " access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") "; if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $languageCheck = " AND language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") "; } } else { $accessCheck = " access <= {$aid}"; } $query = "SELECT COUNT(*) FROM #__k2_items WHERE YEAR(created)={$year} AND MONTH(created)={$month} AND DAY(created)={$day} AND 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 {$accessCheck} {$languageCheck} AND EXISTS(SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND {$accessCheck} {$languageCheck})"; $catid = $this->category; if ($catid > 0) { $query .= " AND catid={$catid}"; } $db->setQuery($query); $result = $db->loadResult(); if ($db->getErrorNum()) { echo $db->stderr(); return false; } if ($result > 0) { if ($catid > 0) { return JRoute::_(K2HelperRoute::getDateRoute($year, $month, $day, $catid)); } else { return JRoute::_(K2HelperRoute::getDateRoute($year, $month, $day)); } } else { return false; } }