/**
  * Get the adverstised stop date (does not include timestamp_max)
  *
  * Note: there is a priority order in the params to determine the stop date.
  *  -dstop
  *  -week + m
  *  -m
  *  -dstart + x days
  */
 function get_advertised_stop_date()
 {
     if ($this->getting_adv_stop_date) {
         // We would be entering an infinite loop, stop now:
         // We cannot determine a stop date, save an empty string (to differentiate from NULL)
         $this->advertised_stop_date = '';
         // Reset anti infinite loop:
         $this->getting_adv_stop_date = false;
         return $this->advertised_stop_date;
     }
     // Anti infinite loop:
     $this->getting_adv_stop_date = true;
     if (is_null($this->advertised_stop_date)) {
         // We haven't determined the stop date yet:
         if (!empty($this->filters['ymdhms_max'])) {
             // We have requested an end date (8 digits)
             $m = $this->filters['ymdhms_max'];
             $this->advertised_stop_date = mktime(0, 0, 0, substr($m, 4, 2), substr($m, 6, 2), substr($m, 0, 4));
         } elseif (!is_null($this->filters['week']) && !empty($this->filters['ymdhms'])) {
             // we want to restrict on a specific week
             $this->advertised_stop_date = get_start_date_for_week(substr($this->filters['ymdhms'], 0, 4), $this->filters['week'], locale_startofweek());
             $this->advertised_stop_date += 518400;
             // + 6 days
         } elseif (!empty($this->filters['ymdhms'])) {
             // We want to restrict on an interval:
             if (strlen($this->filters['ymdhms']) >= 8) {
                 // We have requested a day interval
                 $m = $this->filters['ymdhms'];
                 $this->advertised_stop_date = mktime(0, 0, 0, substr($m, 4, 2), substr($m, 6, 2), substr($m, 0, 4));
             } elseif (strlen($this->filters['ymdhms']) == 6) {
                 // We want to go to the end of the month:
                 $m = $this->filters['ymdhms'];
                 $this->advertised_stop_date = mktime(0, 0, 0, substr($m, 4, 2) + 1, 0, substr($m, 0, 4));
                 // 0th day of next mont = last day of month
             } elseif (strlen($this->filters['ymdhms']) == 4) {
                 // We want to go to the end of the year:
                 $m = $this->filters['ymdhms'];
                 $this->advertised_stop_date = mktime(0, 0, 0, 12, 31, substr($m, 0, 4));
             }
         } elseif ($this->filters['unit'] == 'days' && ($start_date = $this->get_advertised_start_date()) != '') {
             // We want to restrict on a specific number of days after the start date:
             $this->advertised_stop_date = $start_date + ($this->limit - 1) * 86400;
         } else {
             // We cannot determine a stop date, save an empty string (to differentiate from NULL)
             $this->advertised_stop_date = '';
         }
     }
     // Reset anti infinite loop:
     $this->getting_adv_stop_date = false;
     return $this->advertised_stop_date;
 }
Exemple #2
0
    /**
     * Builds a date input field.
     *
     * @param string the name of the input field
     * @param string initial value (ISO datetime (YYYY-MM-DD HH:MM:SS)
     *               or erroneous if the field is in error state)
     * @param string label displayed in front of the field
     * @param array Optional params. Additionally to {@link $_common_params} you can use:
     *              - date_format: Format of the date (string, PHP format, default taken from {@link locale_datefmt()})
     *              - add_date_format_note: If true, date format note gets prepended to the field's note
     * @return mixed true (if output) or the generated HTML if not outputting
     */
    function date_input($field_name, $field_value, $field_label, $field_params = array())
    {
        global $month, $weekday_letter;
        if (empty($field_params['date_format'])) {
            // Use locale date format:
            $date_format = locale_datefmt();
        } else {
            $date_format = $field_params['date_format'];
        }
        // Don't keep that attrib in the list:
        unset($field_params['date_format']);
        // Convert PHP date format to JS library date format (date.js):
        // NOTE: when editing/extending this here, you probably also have to adjust param_check_date()!
        $js_date_format = preg_replace_callback('~(\\\\)?(\\w)~', create_function('$m', '
			if( $m[1] == "\\\\" ) return "\\\\".$m[0]; // leave escaped
			switch( $m[2] )
			{
				case "d": return "dd"; // day, 01-31
				case "j": return "d"; // day, 1-31
				case "l": return "EE"; // weekday (name)
				case "D": return "E"; // weekday (abbr)
				case "e": return ""; // weekday letter, not supported

				case "m": return "MM"; // month, 01-12
				case "n": return "M"; // month, 1-12
				case "F": return "MMM"; // full month name; "name or abbr" in date.js
				case "M": return "NNN"; // month name abbr

				case "y": return "yy"; // year, 00-99
				case "Y": return "yyyy"; // year, XXXX
				default:
					return $m[0];
			}'), $date_format);
        #pre_dump( $js_date_format );
        if (param_has_error($field_name)) {
            // There is an error message for this field:
            // We do not try to format the date, we keep the erroneous date.
            //echo 'error on '.$field_name.' keep erroneous entry intact ';
            $field_params['value'] = trim(substr($field_value, 0, 10));
        } else {
            // Make the date value clean for display:
            // The date value may be compact, in this case we have to decompact it
            if (preg_match('/^[0-9]+$/', $field_value)) {
                // The date is compact, so we decompact it
                $field_value = decompact_date($field_value);
            }
            // Get DATE part of datetime and format it to locale format:
            $field_params['value'] = mysql2date($date_format, $field_value);
        }
        if (!empty($field_params['add_date_format_note'])) {
            // Prepend $date_format to note
            $field_params['note'] = empty($field_params['note']) ? '(' . $date_format . ')' : '(' . $date_format . ') ' . $field_params['note'];
        }
        unset($field_params['add_date_format_note']);
        if (!isset($field_params['size'])) {
            // Get size out of $date_format if not explicitly set
            $field_params['size'] = strlen($js_date_format);
        }
        /*
        dh> do not use maxlength by default. Makes no sense IMHO and fails with dateformats like "j \d\e F, Y"
        if( !isset($field_params['maxlength']) )
        {
        	$field_params['maxlength'] = $field_params['size'];
        }
        */
        // Give it a class, so it can be selected for CSS in IE6
        if (empty($field_params['class'])) {
            $field_params['class'] = 'form_date_input';
        } else {
            $field_params['class'] .= ' form_date_input';
        }
        $this->handle_common_params($field_params, $field_name, $field_label);
        $r = $this->begin_field() . '<script type="text/javascript">
						//<![CDATA[
						var cal_' . $field_name . ' = new CalendarPopup();
						cal_' . $field_name . '.showYearNavigation();
						cal_' . $field_name . '.showNavigationDropdowns();
						// cal_' . $field_name . '.showYearNavigationInput();
						// MonthNames get set through MONTH_NAMES
				   cal_' . $field_name . '.setDayHeaders( ' . "'" . T_($weekday_letter[0]) . "'," . "'" . T_($weekday_letter[1]) . "'," . "'" . T_($weekday_letter[2]) . "'," . "'" . T_($weekday_letter[3]) . "'," . "'" . T_($weekday_letter[4]) . "'," . "'" . T_($weekday_letter[5]) . "'," . "'" . T_($weekday_letter[6]) . "' );\n" . ' cal_' . $field_name . '.setWeekStartDay(' . locale_startofweek() . ');
						cal_' . $field_name . ".setTodayText('" . TS_('Today') . "');\r\n\t\t\t\t\t\t//]]>\r\n\t\t\t\t\t</script>\n" . $this->get_input_element($field_params, false) . '<a href="#" onclick="cal_' . $field_name . ".select(document.getElementById('" . $field_name . "'), 'anchor_" . $field_name . "', '" . $js_date_format . "');" . ' return false;" name="anchor_' . $field_name . '" id="anchor_' . $this->get_valid_id($field_name) . '" title="' . T_('Select date') . '">' . get_icon('calendar', 'imgtag', array('title' => T_('Select date'))) . '</a>';
        $r .= $this->end_field();
        return $this->display_or_return($r);
    }
Exemple #3
0
 /**
  * Get archive page URL
  *
  * Note: there ate two similar functions here.
  *
  * @uses Blog::gen_archive_url()
  *
  * @param string monthly, weekly, daily
  */
 function get_archive_url($date, $glue = '&amp;')
 {
     switch ($this->get_setting('archive_mode')) {
         case 'weekly':
             global $cacheweekly, $DB;
             if (!isset($cacheweekly) || empty($cacheweekly[$date])) {
                 $cacheweekly[$date] = $DB->get_var('SELECT ' . $DB->week($DB->quote($date), locale_startofweek()));
             }
             return $this->gen_archive_url(substr($date, 0, 4), NULL, NULL, $cacheweekly[$date], $glue);
             break;
         case 'daily':
             return $this->gen_archive_url(substr($date, 0, 4), substr($date, 5, 2), substr($date, 8, 2), NULL, $glue);
             break;
         case 'monthly':
         default:
             return $this->gen_archive_url(substr($date, 0, 4), substr($date, 5, 2), NULL, NULL, $glue);
     }
 }
/**
 * Registers headlines for initialization of datepicker inputs
 */
function init_datepicker_js($relative_to = 'rsc_url')
{
    require_js('#jquery#', $relative_to);
    require_js('#jqueryUI#', $relative_to);
    $datefmt = locale_datefmt();
    $datefmt = str_replace(array('d', 'j', 'm', 'Y'), array('dd', 'd', 'mm', 'yy'), $datefmt);
    require_css('jquery/smoothness/jquery-ui.css');
    add_js_headline('jQuery(document).ready( function(){
		var monthNames = ["' . T_('January') . '","' . T_('February') . '", "' . T_('March') . '",
						  "' . T_('April') . '", "' . T_('May') . '", "' . T_('June') . '",
						  "' . T_('July') . '", "' . T_('August') . '", "' . T_('September') . '",
						  "' . T_('October') . '", "' . T_('November') . '", "' . T_('December') . '"];

		var dayNamesMin = ["' . T_('Sun') . '", "' . T_('Mon') . '", "' . T_('Tue') . '",
						  "' . T_('Wed') . '", "' . T_('Thu') . '", "' . T_('Fri') . '", "' . T_('Sat') . '"];

		var docHead = document.getElementsByTagName("head")[0];
		for (i=0;i<dayNamesMin.length;i++)
			dayNamesMin[i] = dayNamesMin[i].substr(0, 2)

		jQuery(".form_date_input").datepicker({
			dateFormat: "' . $datefmt . '",
			monthNames: monthNames,
			dayNamesMin: dayNamesMin,
			firstDay: ' . locale_startofweek() . '
		})
	})');
}
    /**
     * Restricts the datestart param to a specific date range.
     *
     * Start date gets restricted to minutes only (to make the query more
     * cachable).
     *
     * Priorities:
     *  -dstart and/or dstop
     *  -week + m
     *  -m
     * @todo  -dstart + x days
     * @see ItemList2::get_advertised_start_date()
     *
     * @param string YYYYMMDDHHMMSS (everything after YYYY is optional) or ''
     * @param integer week number or ''
     * @param string YYYYMMDDHHMMSS to start at, '' for first available
     * @param string YYYYMMDDHHMMSS to stop at
     * @param mixed Do not show posts before this timestamp, can be 'now'
     * @param mixed Do not show posts after this timestamp, can be 'now'
     */
    function where_datestart($m = '', $w = '', $dstart = '', $dstop = '', $timestamp_min = '', $timestamp_max = 'now')
    {
        global $time_difference, $DB;
        $this->m = $m;
        $this->w = $w;
        $this->dstart = $dstart;
        $this->dstop = $dstop;
        $this->timestamp_min = $timestamp_min;
        $this->timestamp_max = $timestamp_max;
        $start_is_set = false;
        $stop_is_set = false;
        // if a start date is specified in the querystring, crop anything before
        if (!empty($dstart)) {
            // Add trailing 0s: YYYYMMDDHHMMSS
            $dstart0 = $dstart . '00000000000000';
            // TODO: this is NOT correct, should be 0101 for month
            // Start date in MySQL format: seconds get omitted (rounded to lower to minute for caching purposes)
            $dstart_mysql = substr($dstart0, 0, 4) . '-' . substr($dstart0, 4, 2) . '-' . substr($dstart0, 6, 2) . ' ' . substr($dstart0, 8, 2) . ':' . substr($dstart0, 10, 2);
            $this->WHERE_and($this->dbprefix . 'datestart >= ' . $DB->quote($dstart_mysql) . '
													OR ( ' . $this->dbprefix . 'datedeadline IS NULL AND ' . $this->dbprefix . 'datestart >= ' . $DB->quote($dstart_mysql) . ' )');
            $start_is_set = true;
        }
        // if a stop date is specified in the querystring, crop anything before
        if (!empty($dstop)) {
            switch (strlen($dstop)) {
                case '4':
                    // We have only year, add one to year
                    $dstop_mysql = $dstop + 1 . '-01-01 00:00:00';
                    break;
                case '6':
                    // We have year month, add one to month
                    $dstop_mysql = date("Y-m-d H:i:s ", mktime(0, 0, 0, substr($dstop, 4, 2) + 1, 01, substr($dstop, 0, 4)));
                    break;
                case '8':
                    // We have year mounth day, add one to day
                    $dstop_mysql = date("Y-m-d H:i:s ", mktime(0, 0, 0, substr($dstop, 4, 2), substr($dstop, 6, 2) + 1, substr($dstop, 0, 4)));
                    break;
                case '10':
                    // We have year mounth day hour, add one to hour
                    $dstop_mysql = date("Y-m-d H:i:s ", mktime(substr($dstop, 8, 2) + 1, 0, 0, substr($dstop, 4, 2), substr($dstop, 6, 2), substr($dstop, 0, 4)));
                    break;
                case '12':
                    // We have year mounth day hour minute, add one to minute
                    $dstop_mysql = date("Y-m-d H:i:s ", mktime(substr($dstop, 8, 2), substr($dstop, 8, 2) + 1, 0, substr($dstop, 4, 2), substr($dstop, 6, 2), substr($dstop, 0, 4)));
                    break;
                default:
                    // add one to second
                    // Stop date in MySQL format: seconds get omitted (rounded to lower to minute for caching purposes)
                    $dstop_mysql = substr($dstop, 0, 4) . '-' . substr($dstop, 4, 2) . '-' . substr($dstop, 6, 2) . ' ' . substr($dstop, 8, 2) . ':' . substr($dstop, 10, 2);
            }
            $this->WHERE_and($this->dbprefix . 'datestart < ' . $DB->quote($dstop_mysql));
            // NOT <= comparator because we compare to the superior stop date
            $stop_is_set = true;
        }
        if (!$start_is_set || !$stop_is_set) {
            if (!is_null($w) && strlen($m) == 4) {
                // If a week number is specified (with a year)
                // Note: we use PHP to calculate week boundaries in order to handle weeks
                // that overlap 2 years properly, even when start on week is monday (which MYSQL won't handle properly)
                $start_date_for_week = get_start_date_for_week($m, $w, locale_startofweek());
                $this->WHERE_and($this->dbprefix . "datestart >= '" . date('Y-m-d', $start_date_for_week) . "'");
                $this->WHERE_and($this->dbprefix . "datestart < '" . date('Y-m-d', $start_date_for_week + 604800) . "'");
                // + 7 days
                $start_is_set = true;
                $stop_is_set = true;
            } elseif (!empty($m)) {
                // We want to restrict on an interval:
                $this->WHERE_and('EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart)=' . intval(substr($m, 0, 4)));
                if (strlen($m) > 5) {
                    $this->WHERE_and('EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart)=' . intval(substr($m, 4, 2)));
                }
                if (strlen($m) > 7) {
                    $this->WHERE_and('EXTRACT(DAY FROM ' . $this->dbprefix . 'datestart)=' . intval(substr($m, 6, 2)));
                }
                if (strlen($m) > 9) {
                    $this->WHERE_and('EXTRACT(HOUR FROM ' . $this->dbprefix . 'datestart)=' . intval(substr($m, 8, 2)));
                }
                if (strlen($m) > 11) {
                    $this->WHERE_and('EXTRACT(MINUTE FROM ' . $this->dbprefix . 'datestart)=' . intval(substr($m, 10, 2)));
                }
                if (strlen($m) > 13) {
                    $this->WHERE_and('EXTRACT(SECOND FROM ' . $this->dbprefix . 'datestart)=' . intval(substr($m, 12, 2)));
                }
                $start_is_set = true;
                $stop_is_set = true;
            }
        }
        // TODO: start + x days
        // TODO: stop - x days
        // SILENT limits!
        // Timestamp limits:
        if ($timestamp_min == 'now') {
            // echo 'hide past';
            $timestamp_min = time();
        }
        if (!empty($timestamp_min)) {
            // Hide posts before
            // echo 'hide before '.$timestamp_min;
            $date_min = remove_seconds($timestamp_min + $time_difference);
            $this->WHERE_and($this->dbprefix . 'datestart >= ' . $DB->quote($date_min));
        }
        if ($timestamp_max == 'now') {
            // echo 'hide future';
            $timestamp_max = time();
        }
        if (!empty($timestamp_max)) {
            // Hide posts after
            // echo 'after';
            $date_max = remove_seconds($timestamp_max + $time_difference);
            $this->WHERE_and($this->dbprefix . 'datestart <= ' . $DB->quote($date_max));
        }
    }
    /**
     * Display the calendar.
     *
     * @todo If a specific day (mode == month) or month (mode == year) is selected, apply another class (default to some border)
     */
    function display()
    {
        global $DB;
        global $weekday, $weekday_abbrev, $weekday_letter, $month, $month_abbrev;
        global $time_difference;
        if ($this->mode == 'month') {
            $end_of_week = (locale_startofweek() + 7) % 7;
            // fplanque>> note: I am removing the searchframe thing because 1) I don't think it's of any use
            // and 2) it's brutally inefficient! If someone needs this it should be implemented with A SINGLE
            // QUERY which gets the last available post (BTW, I think there is already a function for that somwhere)
            // walter>> As we are just counting items, the ORDER BY db_prefix . date_start doesn't matter. And a side effect
            // of that is make queries standart compatible (compatible with other databases than MySQL)
            $arc_sql = 'SELECT COUNT(DISTINCT ' . $this->dbIDname . ') AS item_count,
													EXTRACT(DAY FROM ' . $this->dbprefix . 'datestart) AS myday
									FROM (' . $this->dbtable . ' INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID)
										INNER JOIN T_categories ON postcat_cat_ID = cat_ID
									WHERE EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) = \'' . $this->year . '\'
										AND EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) = \'' . $this->month . '\'
										' . $this->ItemQuery->get_where(' AND ') . '
									GROUP BY myday ' . $this->ItemQuery->get_group_by(', ');
            // echo $this->ItemQuery->where;
            $arc_result = $DB->get_results($arc_sql, ARRAY_A);
            foreach ($arc_result as $arc_row) {
                if (!isset($daysinmonthwithposts[$arc_row['myday']])) {
                    $daysinmonthwithposts[$arc_row['myday']] = 0;
                }
                // The '+' situation actually only happens when we have a complex GROUP BY above
                // (multiple categories wcombined with "ALL")
                $daysinmonthwithposts[$arc_row['myday']] += $arc_row['item_count'];
            }
            $daysinmonth = intval(date('t', mktime(0, 0, 0, $this->month, 1, $this->year)));
            // echo 'days in month=', $daysinmonth;
            // caution: offset bug inside (??)
            $datestartofmonth = mktime(0, 0, 0, $this->month, 1, $this->year);
            // echo date( locale_datefmt(), $datestartofmonth );
            $calendarblah = get_weekstartend($datestartofmonth, locale_startofweek());
            $calendarfirst = $calendarblah['start'];
            $dateendofmonth = mktime(0, 0, 0, $this->month, $daysinmonth, $this->year);
            // echo 'end of month: '.date( 'Y-m-d H:i:s', $dateendofmonth );
            $calendarblah = get_weekstartend($dateendofmonth, locale_startofweek());
            $calendarlast = $calendarblah['end'];
            // echo date( ' Y-m-d H:i:s', $calendarlast );
            // here the offset bug is corrected
            if (intval(date('d', $calendarfirst)) > 1 && intval(date('m', $calendarfirst)) == intval($this->month)) {
                #pre_dump( 'with offset bug', date('Y-m-d', $calendarfirst) );
                $calendarfirst = $calendarfirst - 604800;
                #pre_dump( 'without offset bug', date('Y-m-d', $calendarfirst) );
            }
        } else {
            // mode is 'year'
            // Find months with posts
            $arc_sql = '
				SELECT COUNT(DISTINCT ' . $this->dbIDname . ') AS item_count, EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) AS mymonth
				  FROM (' . $this->dbtable . ' INNER JOIN T_postcats ON ' . $this->dbIDname . ' = postcat_post_ID)
				 INNER JOIN T_categories ON postcat_cat_ID = cat_ID
				 WHERE EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart) = \'' . $this->year . '\' ' . $this->ItemQuery->get_where(' AND ') . '
				 GROUP BY mymonth ' . $this->ItemQuery->get_group_by(', ');
            $arc_result = $DB->get_results($arc_sql, ARRAY_A);
            if ($DB->num_rows > 0) {
                // OK we have a month with posts! // fp>dh why did you removed that?
                foreach ($arc_result as $arc_row) {
                    $monthswithposts[$arc_row['mymonth']] = $arc_row['item_count'];
                }
            }
        }
        // ** display everything **
        echo $this->tablestart;
        // CAPTION :
        if ($this->displaycaption) {
            // caption:
            echo $this->monthstart;
            if ($this->navigation == 'caption') {
                echo implode('&nbsp;', $this->getNavLinks('prev')) . '&nbsp;';
            }
            if ($this->mode == 'month') {
                // MONTH CAPTION:
                $text = date_i18n($this->monthformat, mktime(0, 0, 0, $this->month, 1, $this->year));
                if ($this->linktomontharchive) {
                    // chosen month with link to archives
                    echo $this->archive_link($text, T_('View monthly archive'), $this->year, $this->month);
                } else {
                    echo $text;
                }
            } else {
                // YEAR CAPTION:
                echo date_i18n('Y', mktime(0, 0, 0, 1, 1, $this->year));
                // display year
            }
            if ($this->navigation == 'caption') {
                echo '&nbsp;' . implode('&nbsp;', $this->getNavLinks('next'));
            }
            echo $this->monthend;
        }
        // HEADER :
        if (!empty($this->headerdisplay) && $this->mode == 'month') {
            // Weekdays:
            echo $this->headerrowstart;
            for ($i = locale_startofweek(), $j = $i + 7; $i < $j; $i = $i + 1) {
                echo str_replace('[abbr]', T_($weekday[$i % 7]), $this->headercellstart);
                switch ($this->headerdisplay) {
                    case 'e':
                        // e => 'F'
                        echo T_($weekday_letter[$i % 7]);
                        break;
                    case 'l':
                        // l (lowercase l) => 'Friday'
                        echo T_($weekday[$i % 7]);
                        break;
                    default:
                        // Backward compatibility: any non emty value will display this
                        // D => 'Fri'
                        echo T_($weekday_abbrev[$i % 7]);
                }
                echo $this->headercellend;
            }
            echo $this->headerrowend;
        }
        // FOOTER :
        if ($this->navigation == 'tfoot') {
            // We want to display navigation in the table footer:
            echo "<tfoot>\n";
            echo "<tr>\n";
            echo '<td colspan="' . (($this->mode == 'month' ? 2 : 1) + (int) $this->today_is_visible) . '" id="prev">';
            echo implode('&nbsp;', $this->getNavLinks('prev'));
            echo "</td>\n";
            if ($this->today_is_visible) {
                if ($this->mode == 'month') {
                    echo '<td class="pad">&nbsp;</td>' . "\n";
                }
            } else {
                echo '<td colspan="' . ($this->mode == 'month' ? '3' : '2') . '" class="center">' . $this->archive_link(T_('Current'), '', date('Y'), $this->mode == 'month' ? date('m') : NULL) . '</td>';
            }
            echo '<td colspan="' . (($this->mode == 'month' ? 2 : 1) + (int) $this->today_is_visible) . '" id="next">';
            echo implode('&nbsp;', $this->getNavLinks('next'));
            echo "</td>\n";
            echo "</tr>\n";
            echo "</tfoot>\n";
        }
        // REAL TABLE DATA :
        echo '<tbody>' . $this->rowstart;
        if ($this->mode == 'year') {
            // DISPLAY MONTHS:
            for ($i = 1; $i < 13; $i = $i + 1) {
                // For each month:
                if (isset($monthswithposts[$i])) {
                    if ($this->month == $i) {
                        echo $this->todaycellstartpost;
                    } else {
                        echo $this->linkpostcellstart;
                    }
                    if ($monthswithposts[$i] > 1 && !empty($this->postcount_year_atitle)) {
                        // display postcount
                        $title = sprintf($this->postcount_year_atitle, $monthswithposts[$i]);
                    } elseif (!empty($this->postcount_year_atitle_one)) {
                        // display postcount for one post
                        $title = sprintf($this->postcount_year_atitle_one, 1);
                    } else {
                        $title = '';
                    }
                    echo $this->archive_link(T_($month_abbrev[zeroise($i, 2)]), $title, $this->year, $i);
                } elseif ($this->month == $i) {
                    // current month
                    echo $this->todaycellstart;
                    echo T_($month_abbrev[zeroise($i, 2)]);
                } else {
                    echo $this->cellstart;
                    echo T_($month_abbrev[zeroise($i, 2)]);
                }
                echo $this->cellend;
                if ($i == 4 || $i == 8) {
                    // new row
                    echo $this->rowend . $this->rowstart;
                }
            }
        } else {
            // DISPLAY DAYS of current month:
            $dow = 0;
            $last_day = -1;
            $dom_displayed = 0;
            // days of month displayed
            for ($i = $calendarfirst; $i <= $calendarlast; $i = $i + 86400) {
                // loop day by day (86400 seconds = 24 hours; but not on days where daylight saving changes!)
                if ($dow == 7) {
                    // We need to start a new row:
                    if ($dom_displayed >= $daysinmonth) {
                        // Last day already displayed!
                        break;
                    }
                    echo $this->rowend;
                    echo $this->rowstart;
                    $dow = 0;
                }
                $dow++;
                // correct daylight saving ("last day"+86400 would lead to "last day at 23:00")
                // fp> TODO: use mkdate()
                while (date('j', $i) == $last_day) {
                    $i += 3600;
                }
                $last_day = date('j', $i);
                if (date('m', $i) != $this->month) {
                    // empty cell
                    echo $this->emptycellstart;
                    echo $this->emptycellcontent;
                    echo $this->emptycellend;
                } else {
                    // This day is in this month
                    $dom_displayed++;
                    $calendartoday = date('Ymd', $i) == date('Ymd', time() + $time_difference);
                    if (isset($daysinmonthwithposts[date('j', $i)])) {
                        if ($calendartoday) {
                            echo $this->todaycellstartpost;
                        } else {
                            echo $this->linkpostcellstart;
                        }
                        if ($daysinmonthwithposts[date('j', $i)] > 1 && !empty($this->postcount_month_atitle)) {
                            // display postcount
                            $title = sprintf($this->postcount_month_atitle, $daysinmonthwithposts[date('j', $i)]);
                        } elseif (!empty($this->postcount_month_atitle_one)) {
                            // display postcount for one post
                            $title = sprintf($this->postcount_month_atitle_one, 1);
                        } else {
                            $title = '';
                        }
                        echo $this->archive_link(date('j', $i), $title, $this->year, $this->month, date('d', $i));
                    } elseif ($calendartoday) {
                        echo $this->todaycellstart;
                        echo date('j', $i);
                    } else {
                        echo $this->cellstart;
                        echo date('j', $i);
                    }
                    echo $this->cellend;
                }
            }
            // loop day by day
        }
        // mode == 'month'
        echo $this->rowend . "</tbody>\n";
        echo $this->tableend;
    }
Exemple #7
0
    /**
     * Count the number of rows of the SQL result
     *
     * These queries are complex enough for us not to have to rewrite them:
     * dh> ???
     */
    function count_total_rows()
    {
        global $DB;
        switch ($this->archive_mode) {
            case 'monthly':
                // ------------------------------ MONTHLY ARCHIVES ------------------------------------
                $sql_count = 'SELECT COUNT( DISTINCT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart), EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart) ) ' . $this->from . $this->where;
                break;
            case 'daily':
                // ------------------------------- DAILY ARCHIVES -------------------------------------
                $sql_count = 'SELECT COUNT( DISTINCT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart), EXTRACT(MONTH FROM ' . $this->dbprefix . 'datestart),
																	EXTRACT(DAY FROM ' . $this->dbprefix . 'datestart) ) ' . $this->from . $this->where;
                break;
            case 'weekly':
                // ------------------------------- WEEKLY ARCHIVES -------------------------------------
                $sql_count = 'SELECT COUNT( DISTINCT EXTRACT(YEAR FROM ' . $this->dbprefix . 'datestart), ' . $DB->week($this->dbprefix . 'datestart', locale_startofweek()) . ' ) ' . $this->from . $this->where;
                break;
            case 'postbypost':
            default:
                // ----------------------------- POSY BY POST ARCHIVES --------------------------------
                $sql_count = 'SELECT COUNT( DISTINCT ' . $this->dbIDname . ' ) ' . $this->from . $this->where . $this->group_by;
        }
        // echo $sql_count;
        $this->total_rows = $DB->get_var($sql_count);
        //count total rows
        // echo 'total rows='.$this->total_rows;
    }