Make WordPress Core

Changeset 1632


Ignore:
Timestamp:
09/09/2004 11:07:46 PM (20 years ago)
Author:
rboren
Message:

Allow the calendar start of week to be provisioned. get_calendar() patch from rq. Bug 32.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options-general.php

    r1599 r1632  
    4848  <form name="form1" method="post" action="options.php">
    4949    <input type="hidden" name="action" value="update" />
    50     <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="'blogname','blogdescription','siteurl','admin_email','users_can_register','new_users_can_blog','gmt_offset','date_format','time_format','home'" />
     50    <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="'blogname','blogdescription','siteurl','admin_email','users_can_register','new_users_can_blog','gmt_offset','date_format','time_format','home','start_of_week'" />
    5151    <table width="100%" cellspacing="2" cellpadding="5" class="editform">
    5252      <tr valign="top">
     
    111111<?php _e('Output:') ?> <strong><?php echo gmdate(get_settings('time_format'), current_time('timestamp')); ?></strong></td>
    112112        </tr>
     113      <tr>
     114        <th scope="row"><?php _e('Weeks in the calendar should start on:') ?></th>
     115        <td><select name="start_of_week" id="start_of_week">
     116    <?php
     117for ($day_index = 0; $day_index <= 6; $day_index++) :
     118    if ($day_index == get_settings('start_of_week')) $selected = " selected='selected'";
     119    else $selected = '';
     120echo "\n\t<option value='$day_index' $selected>$weekday[$day_index]</option>";
     121endfor;
     122?>
     123</select></td>
     124            </tr>
     125
    113126</table>
    114127
  • trunk/wp-includes/template-functions-general.php

    r1629 r1632  
    330330}
    331331
     332// Used in get_calendar
     333function calendar_week_mod($num) {
     334    $base = 7;
     335    return ($num - $base*floor($num/$base));
     336}
     337
    332338function get_calendar($daylength = 1) {
    333339    global $wpdb, $m, $monthnum, $year, $timedifference, $month, $month_abbrev, $weekday, $weekday_initial, $weekday_abbrev, $posts;
     
    344350    }
    345351
     352    // week_begins = 0 stands for sunday
     353    $week_begins = intval(get_settings('start_of_week'));
    346354    $add_hours = intval(get_settings('gmt_offset'));
    347355    $add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
     
    396404    }
    397405
    398     foreach ($weekday as $wd) {
     406    $myweek = array();
     407   
     408    for ($wdcount=0; $wdcount<=6; $wdcount++) {
     409        $myweek[]=$weekday[($wdcount+$week_begins)%7];
     410    }
     411   
     412    foreach ($myweek as $wd) {
    399413        echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">" . $day_abbrev[$wd] . '</th>';
    400414    }
     
    478492
    479493    // See how much we should pad in the beginning
    480     $pad = intval(date('w', $unixmonth));
     494    $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    481495    if (0 != $pad) echo "\n\t\t".'<td colspan="'.$pad.'" class="pad">&nbsp;</td>';
    482496
     
    499513        echo '</td>';
    500514
    501         if (6 == date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear)))
     515    if (6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins))
    502516            $newrow = true;
    503517    }
    504518
    505     $pad = 7 - date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear));
     519    $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    506520    if ($pad != 0 && $pad != 7)
    507521        echo "\n\t\t".'<td class="pad" colspan="'.$pad.'">&nbsp;</td>';
Note: See TracChangeset for help on using the changeset viewer.