function _build_query()
 {
     global $TMPL, $DB, $LOC;
     // Do something awesome
     $allowed_params = array('by', 'weblog', 'author_id', 'category', 'category_group', 'entry_id_from', 'entry_id_to', 'group_id', 'show_expired', 'show_future_entries', 'status', 'start_on', 'stop_before', 'uncategorized_entries', 'username');
     foreach ($TMPL->tagparams as $param => $val) {
         if (!in_array($param, $allowed_params)) {
             unset($TMPL->tagparams[$param]);
         }
     }
     $TMPL->tagparams['dynamic'] = 'off';
     if (!class_exists('Weblog')) {
         require PATH_MOD . 'weblog/mod.weblog.php';
     }
     $W = new Weblog();
     $W->build_sql_query();
     if ($W->sql == '') {
         return $TMPL->no_results();
     }
     $this->query = $DB->query($W->sql);
     if ($this->query->num_rows == 0) {
         return $TMPL->no_results();
     }
     foreach ($this->query->result as $entry) {
         $loc = $LOC->set_localized_time($entry['entry_date']);
         $day = intval(date('d', $loc));
         $month = intval(date('m', $loc));
         $year = intval(date('Y', $loc));
         switch ($this->by) {
             default:
             case 'day':
                 $this->periods[] = mktime(0, 0, 0, $month, $day, $year);
                 break;
             case 'month':
                 $this->periods[] = mktime(0, 0, 0, $month, 1, $year);
                 break;
             case 'year':
                 $this->periods[] = mktime(0, 0, 0, 1, 1, $year);
                 break;
         }
     }
     $this->periods = array_unique($this->periods);
     rsort($this->periods);
     $cnt = count($this->periods) - 1;
     $currIndex = array_search($this->current, $this->periods);
     if ($currIndex === false) {
         $this->periods[] = $this->current;
         $this->periods = array_unique($this->periods);
         rsort($this->periods);
         $currIndex = array_search($this->current, $this->periods);
     }
     $this->oldest = isset($this->periods[$cnt]) && $this->periods[$cnt] != $this->current ? $this->periods[$cnt] : 0;
     $this->older = isset($this->periods[$currIndex + 1]) ? $this->periods[$currIndex + 1] : 0;
     $this->newer = isset($this->periods[$currIndex - 1]) ? $this->periods[$currIndex - 1] : 0;
     $this->newest = isset($this->periods[0]) && $this->periods[0] != $this->current ? $this->periods[0] : 0;
 }