/** * Display year view * * @param string $topic current topic * @param int $year year to display * @param boolean $main true: display view on its own page * @return string list of months (+ number of stories) for given year * */ function DIR_displayYear($topic, $year, $main = false) { global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR; $retval = ''; if ($main) { $retval .= '<div><h1 style="display:inline">' . $year . '</h1> ' . DIR_topicList($topic, $year) . '</div>' . LB; } else { $retval .= '<h2>' . $year . '</h2>' . LB; } $currentyear = date('Y', time()); $currentmonth = date('m', time()); $start = sprintf('%04d-01-01 00:00:00', $year); $end = sprintf('%04d-12-31 23:59:59', $year); $monthsql = array(); $monthsql['mysql'] = "SELECT DISTINCT MONTH(date) AS month,COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())"; $monthsql['mssql'] = "SELECT MONTH(date) AS month,COUNT(sid) AS count FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())"; $monthsql['pgsql'] = "SELECT EXTRACT(Month from date) AS month,COUNT(sid) AS count FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())"; if ($topic != 'all') { $monthsql['mysql'] .= " AND (tid = '{$topic}')"; $monthsql['mssql'] .= " AND (tid = '{$topic}')"; $monthsql['pgsql'] .= " AND (tid = '{$topic}')"; } $monthsql['mysql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND'); $monthsql['mssql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND'); $monthsql['pgsql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND'); $msql = array(); $msql['mysql'] = $monthsql['mysql'] . " GROUP BY MONTH(date) ORDER BY date ASC"; $msql['mssql'] = $monthsql['mssql'] . " GROUP BY MONTH(date) ORDER BY month(date) ASC"; $msql['pgsql'] = $monthsql['pgsql'] . " GROUP BY month,date ORDER BY DATE ASC"; $mresult = DB_query($msql); $nummonths = DB_numRows($mresult); if ($nummonths > 0) { $retval .= '<ul>' . LB; $lastm = 1; for ($j = 0; $j < $nummonths; $j++) { $M = DB_fetchArray($mresult); for (; $lastm < $M['month']; $lastm++) { $retval .= '<li>' . DIR_monthLink($topic, $year, $lastm, 0) . '</li>'; } $lastm = $M['month'] + 1; $retval .= '<li>' . DIR_monthLink($topic, $year, $M['month'], $M['count']) . '</li>'; } if ($year == $currentyear) { $fillm = $currentmonth; } else { $fillm = 12; } if ($lastm <= $fillm) { for (; $lastm <= $fillm; $lastm++) { $retval .= '<li>' . DIR_monthLink($topic, $year, $lastm, 0) . '</li>'; } } $retval .= '</ul>' . LB; } else { $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>'; } $retval .= LB; return $retval; }
/** * Display year view * * @param Template $template reference of the template * @param string $dir_topic current topic * @param int $year year to display * @return string list of months (+ number of stories) for given year */ function DIR_displayYear($template, $dir_topic, $year) { global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR; $retval = ''; $currentTime = time(); $currentYear = date('Y', $currentTime); $currentMonth = date('m', $currentTime); $start = sprintf('%04d-01-01 00:00:00', $year); $end = sprintf('%04d-12-31 23:59:59', $year); $monthsql = array(); $monthsql['mysql'] = "SELECT DISTINCT MONTH(s.date) AS month, COUNT(DISTINCT s.sid) AS count\n FROM {$_TABLES['stories']} s, {$_TABLES['topic_assignments']} ta\n WHERE (s.date >= '{$start}') AND (s.date <= '{$end}') AND (s.draft_flag = 0) AND (s.date <= NOW())\n AND ta.type = 'article' AND ta.id = s.sid "; $monthsql['pgsql'] = "SELECT EXTRACT(Month from date) AS month,COUNT(DISTINCT sid) AS count\n FROM {$_TABLES['stories']} , {$_TABLES['topic_assignments']} ta\n WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())\n AND ta.type = 'article' AND ta.id = sid "; if ($dir_topic !== 'all') { // Retrieve list of inherited topics $tid_list = TOPIC_getChildList($dir_topic); $monthsql['mysql'] .= " AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$dir_topic}')))"; $monthsql['pgsql'] .= " AND (ta.tid IN({$tid_list}) AND (ta.inherit = 1 OR (ta.inherit = 0 AND ta.tid = '{$dir_topic}')))"; } else { $monthsql['mysql'] .= COM_getTopicSQL('AND', 0, 'ta'); $monthsql['pgsql'] .= COM_getTopicSQL('AND', 0, 'ta'); } $monthsql['mysql'] .= COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " GROUP BY month, date ORDER BY date ASC"; $monthsql['pgsql'] .= COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND') . " GROUP BY month, date ORDER BY DATE ASC"; $mresult = DB_query($monthsql); $nummonths = DB_numRows($mresult); if ($nummonths > 0) { $items = array(); $lastm = 1; for ($j = 0; $j < $nummonths; $j++) { $M = DB_fetchArray($mresult); for (; $lastm < $M['month']; $lastm++) { $items[] = DIR_monthLink($dir_topic, $year, $lastm, 0); } $lastm = $M['month'] + 1; $items[] = DIR_monthLink($dir_topic, $year, $M['month'], $M['count']); } if ($year == $currentYear) { $fillm = $currentMonth; } else { $fillm = 12; } if ($lastm <= $fillm) { for (; $lastm <= $fillm; $lastm++) { $items[] = DIR_monthLink($dir_topic, $year, $lastm, 0); } } $retval .= COM_makeList($items); } else { if (TEMPLATE_EXISTS) { $retval .= $template->parse('message', 'no-articles') . LB; } else { $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>' . LB; } } $retval .= LB; return $retval; }
/** * Display year view * * @param ref &$template reference of the template * @param string $dir_topic current topic * @param int $year year to display * @return string list of months (+ number of stories) for given year * */ function DIR_displayYear(&$template, $topic, $year, $main = false) { global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR; $retval = ''; $currentyear = date('Y', time()); $currentmonth = date('m', time()); $start = sprintf('%04d-01-01 00:00:00', $year); $end = sprintf('%04d-12-31 23:59:59', $year); $monthsql = array(); $monthsql['mysql'] = "SELECT DISTINCT MONTH(date) AS month,COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= '{$start}') AND (date <= '{$end}') AND (draft_flag = 0) AND (date <= NOW())"; if ($topic != 'all') { $monthsql['mysql'] .= " AND (tid = '" . DB_escapeString($topic) . "')"; } $monthsql['mysql'] .= COM_getTopicSql('AND') . COM_getPermSql('AND') . COM_getLangSQL('sid', 'AND'); $msql = array(); $msql['mysql'] = $monthsql['mysql'] . " GROUP BY MONTH(date) ORDER BY date ASC"; $mresult = DB_query($msql); $nummonths = DB_numRows($mresult); if ($nummonths > 0) { $items = array(); $lastm = 1; for ($j = 0; $j < $nummonths; $j++) { $M = DB_fetchArray($mresult); for (; $lastm < $M['month']; $lastm++) { $items[] = DIR_monthLink($topic, $year, $lastm, 0); } $lastm = $M['month'] + 1; $items[] = DIR_monthLink($topic, $year, $M['month'], $M['count']); } if ($year == $currentyear) { $fillm = $currentmonth; } else { $fillm = 12; } if ($lastm <= $fillm) { for (; $lastm <= $fillm; $lastm++) { $items[] = DIR_monthLink($topic, $year, $lastm, 0); } } $retval .= COM_makeList($items); } else { $retval .= $template->parse('message', 'no-articles') . LB; } $retval .= LB; return $retval; }