// no direct access defined('_JEXEC') or die; $comments = JPATH_SITE . '/components/com_jcomments/jcomments.php'; if (file_exists($comments)) { require_once $comments; } else { return; } require_once dirname(__FILE__) . '/helper.php'; if ($params->get('useCSS') && !defined('_JCOMMENTS_LATEST_CSS')) { define('_JCOMMENTS_LATEST_CSS', 1); $app = JFactory::getApplication('site'); $style = JFactory::getLanguage()->isRTL() ? 'style_rtl.css' : 'style.css'; $css = 'media/' . $module->module . '/css/' . $style; if (is_file(JPATH_SITE . '/templates/' . $app->getTemplate() . '/html/' . $module->module . '/css/' . $style)) { $css = 'templates/' . $app->getTemplate() . '/html/' . $module->module . '/css/' . $style; } $document = JFactory::getDocument(); $document->addStylesheet($css); } $list = modJCommentsLatestHelper::getList($params); if (!empty($list)) { $grouped = false; $comments_grouping = $params->get('comments_grouping', 'none'); $item_heading = $params->get('item_heading', 4); if ($comments_grouping !== 'none') { $grouped = true; $list = modJCommentsLatestHelper::groupBy($list, $comments_grouping); } require JModuleHelper::getLayoutPath('mod_jcomments_latest', $params->get('layout', 'default')); }
public static function getRelativeDate($value, $countParts = 1) { if (version_compare(JVERSION, '1.6.0', 'ge')) { $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); $now = JFactory::getDate(); $now->setTimeZone($tz); } else { $offset = JFactory::getConfig()->getValue('config.offset'); $now = new JDate(); $now->setOffset($offset); } $date = new JDate($value); $diff = $now->toUnix() - $date->toUnix(); $result = $value; $timeParts = array(31536000 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_YEARS', 2592000 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_MONTHS', 604800 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_WEEKS', 86400 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_DAYS', 3600 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_HOURS', 60 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_MINUTES', 1 => 'MOD_JCOMMENTS_LATEST_RELATIVE_DATE_SECONDS'); if ($diff < 5) { $result = JText::_('MOD_JCOMMENTS_LATEST_RELATIVE_DATE_NOW'); } else { $dayDiff = floor($diff / 86400); $nowDay = date('d', $now->toUnix()); $dateDay = date('d', $date->toUnix()); if ($dayDiff == 1 || $dayDiff == 0 && $nowDay != $dateDay) { $result = JText::_('MOD_JCOMMENTS_LATEST_RELATIVE_DATE_YESTERDAY'); } else { $count = 0; $resultParts = array(); foreach ($timeParts as $key => $value) { if ($diff >= $key) { $time = floor($diff / $key); $resultParts[] = modJCommentsLatestHelper::getPluralText($value, $time); $diff = $diff % $key; $count++; if ($count > $countParts - 1 || $diff == 0) { break; } } } if (count($resultParts)) { $result = JText::sprintf('MOD_JCOMMENTS_LATEST_RELATIVE_DATE_AGO', implode(', ', $resultParts)); } } } return $result; }