Changeset 34

Show
Ignore:
Timestamp:
03/10/08 03:43:54 (10 months ago)
Author:
enobrev
Message:

Store Log entries as GMT +00:00 (#1) and allow users to set their timezone (#2). Allow Site Admins to set server timezone as default for users/visitors without a timezone. Also added 34.sql/34.sql which has the updates the database to sync with this revision - adds timezone column to users table, inserts site.tz setting and updates all current log entries to GMT +00:00 (if current log entries are at -5 or EST. should be modified according to server's actual TZ)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • conf.php

    r17 r34  
    2727); 
    2828 
     29$timezones = array( 
     30        'USA Hawaii' => '-10:00', 
     31        'USA Alaska' => '-09:00', 
     32        'USA Pacific' => '-08:00', 
     33        'USA Mountain' => '-07:00', 
     34        'USA Central' => '-06:00', 
     35        'USA Eastern' => '-05:00', 
     36        'American Samoa' => '-11:00', 
     37        'Samoa' => '-11:00', 
     38        'Christmas Is.' => '-10:00', 
     39        'Cook Is.' => '-10:00', 
     40        'French Polynesia' => '-10:00', 
     41        'USA Hawaii' => '-10:00', 
     42        'USA Alaska' => '-09:00', 
     43        'Canada Pacific' => '-08:00', 
     44        'USA Pacific' => '-08:00', 
     45        'Canada Mountain' => '-07:00', 
     46        'Mexico West' => '-07:00', 
     47        'USA Mountain' => '-07:00', 
     48        'Belize' => '-06:00', 
     49        'Canada Central' => '-06:00', 
     50        'Costa Rica' => '-06:00', 
     51        'El Salvador' => '-06:00', 
     52        'Guatemala' => '-06:00', 
     53        'Honduras' => '-06:00', 
     54        'Mexico Central' => '-06:00', 
     55        'Nicaragua' => '-06:00', 
     56        'USA Central' => '-06:00', 
     57        'Bahamas' => '-05:00', 
     58        'Canada Eastern' => '-05:00', 
     59        'Cayman Islands' => '-05:00', 
     60        'Colombia' => '-05:00', 
     61        'Cuba' => '-05:00', 
     62        'Ecuador' => '-05:00', 
     63        'Haiti' => '-05:00', 
     64        'Jamaica' => '-05:00', 
     65        'Mexico East' => '-05:00', 
     66        'Panama, Republic Of' => '-05:00', 
     67        'Peru' => '-05:00', 
     68        'Turks and Caicos' => '-05:00', 
     69        'USA Eastern' => '-05:00', 
     70        'Antigua and Barbuda' => '-04:00', 
     71        'Aruba' => '-04:00', 
     72        'Barbados' => '-04:00', 
     73        'Bermuda' => '-04:00', 
     74        'Bolivia' => '-04:00', 
     75        'Brazil West' => '-04:00', 
     76        'British Virgin Islands' => '-04:00', 
     77        'Chile' => '-04:00', 
     78        'Dominica' => '-04:00', 
     79        'Dominican Republic' => '-04:00', 
     80        'Falkland Islands' => '-04:00', 
     81        'Grenada' => '-04:00', 
     82        'Guadalupe' => '-04:00', 
     83        'Netherlands Antilles' => '-04:00', 
     84        'Paraguay' => '-04:00', 
     85        'Puerto Rico' => '-04:00', 
     86        'Saba' => '-04:00', 
     87        'St Lucia' => '-04:00', 
     88        'St Marten' => '-04:00', 
     89        'St Thomas' => '-04:00', 
     90        'St Vincent' => '-04:00', 
     91        'Trinidad and Tobago' => '-04:00', 
     92        'Venezuela' => '-04:00', 
     93        'Canada Newfoundland' => '-03:30', 
     94        'Argentina' => '-03:00', 
     95        'Brazil East' => '-03:00', 
     96        'French Antilles (Martinique)' => '-03:00', 
     97        'French Guinea' => '-03:00', 
     98        'Greenland' => '-03:00', 
     99        'Guyana' => '-03:00', 
     100        'St Pierre & Miquelon' => '-03:00', 
     101        'Suriname' => '-03:00', 
     102        'Uruguay' => '-03:00', 
     103        'Antarctica' => '-02:00', 
     104        'Cape Verde' => '-01:00', 
     105        'Ascension' => '+00:00', 
     106        'Burkina Faso' => '+00:00', 
     107        'Faeroe Islands' => '+00:00', 
     108        'Gambia' => '+00:00', 
     109        'Ghana' => '+00:00', 
     110        'Guinea-Bissau' => '+00:00', 
     111        'Guinea' => '+00:00', 
     112        'Iceland' => '+00:00', 
     113        'Ireland' => '+00:00', 
     114        'Liberia' => '+00:00', 
     115        'Mali Republic' => '+00:00', 
     116        'Mauritania' => '+00:00', 
     117        'Morocco' => '+00:00', 
     118        'Sao Tome' => '+00:00', 
     119        'Senegal' => '+00:00', 
     120        'Sierra Leone' => '+00:00', 
     121        'Togo' => '+00:00', 
     122        'United Kingdom' => '+00:00', 
     123        'Albania' => '+01:00', 
     124        'Algeria' => '+01:00', 
     125        'Andorra' => '+01:00', 
     126        'Angola' => '+01:00', 
     127        'Austria' => '+01:00', 
     128        'Belgium' => '+01:00', 
     129        'Benin' => '+01:00', 
     130        'Bosnia Herzegovina' => '+01:00', 
     131        'Cameroon' => '+01:00', 
     132        'Central African Rep' => '+01:00', 
     133        'Chad Rep' => '+01:00', 
     134        'Congo' => '+01:00', 
     135        'Croatia' => '+01:00', 
     136        'Czech Republic' => '+01:00', 
     137        'Denmark' => '+01:00', 
     138        'Equatorial Guinea' => '+01:00', 
     139        'France' => '+01:00', 
     140        'Gabon Republic' => '+01:00', 
     141        'Germany' => '+01:00', 
     142        'Gibraltar' => '+01:00', 
     143        'Hungary' => '+01:00', 
     144        'Italy' => '+01:00', 
     145        'Liechtenstein' => '+01:00', 
     146        'Luxembourg' => '+01:00', 
     147        'Macedonia' => '+01:00', 
     148        'Malta' => '+01:00', 
     149        'Monaco' => '+01:00', 
     150        'Namibia' => '+01:00', 
     151        'Netherlands' => '+01:00', 
     152        'Nigeria' => '+01:00', 
     153        'Niger Republic' => '+01:00', 
     154        'Norway' => '+01:00', 
     155        'Poland' => '+01:00', 
     156        'Portugal' => '+01:00', 
     157        'San Marino' => '+01:00', 
     158        'Slovakia' => '+01:00', 
     159        'Slovenia' => '+01:00', 
     160        'Spain' => '+01:00', 
     161        'Sweden' => '+01:00', 
     162        'Switzerland' => '+01:00', 
     163        'Tunisia' => '+01:00', 
     164        'Vatican City' => '+01:00', 
     165        'Yugoslavia' => '+01:00', 
     166        'Belarus' => '+02:00', 
     167        'Botswana' => '+02:00', 
     168        'Bulgaria' => '+02:00', 
     169        'Burundi' => '+02:00', 
     170        'Cyprus' => '+02:00', 
     171        'Egypt' => '+02:00', 
     172        'Estonia' => '+02:00', 
     173        'Finland' => '+02:00', 
     174        'Greece' => '+02:00', 
     175        'Israel' => '+02:00', 
     176        'Jordan' => '+02:00', 
     177        'Latvia' => '+02:00', 
     178        'Lebanon' => '+02:00', 
     179        'Lesotho' => '+02:00', 
     180        'Libya' => '+02:00', 
     181        'Lithuania' => '+02:00', 
     182        'Malawi' => '+02:00', 
     183        'Moldova' => '+02:00', 
     184        'Mozambique' => '+02:00', 
     185        'Romania' => '+02:00', 
     186        'Russia West' => '+02:00', 
     187        'Rwanda' => '+02:00', 
     188        'South Africa' => '+02:00', 
     189        'Sudan' => '+02:00', 
     190        'Swaziland' => '+02:00', 
     191        'Syria' => '+02:00', 
     192        'Turkey' => '+02:00', 
     193        'Ukraine' => '+02:00', 
     194        'Zaire' => '+02:00', 
     195        'Zambia' => '+02:00', 
     196        'Zimbabwe' => '+02:00', 
     197        'Azerbaijan' => '+03:00', 
     198        'Bahrain' => '+03:00', 
     199        'Djibouti' => '+03:00', 
     200        'Eritrea' => '+03:00', 
     201        'Ethiopia' => '+03:00', 
     202        'Iraq' => '+03:00', 
     203        'Kenya' => '+03:00', 
     204        'Kuwait' => '+03:00', 
     205        'Madagascar' => '+03:00', 
     206        'Mayotte' => '+03:00', 
     207        'Qatar' => '+03:00', 
     208        'Saudi Arabia' => '+03:00', 
     209        'Somalia' => '+03:00', 
     210        'Tanzania' => '+03:00', 
     211        'Uganda' => '+03:00', 
     212        'Yemen' => '+03:00', 
     213        'Iran' => '+03:30', 
     214        'Armenia' => '+04:00', 
     215        'Georgia' => '+04:00', 
     216        'Mauritius' => '+04:00', 
     217        'Oman' => '+04:00', 
     218        'Reunion Island' => '+04:00', 
     219        'Russia Central 1' => '+04:00', 
     220        'Seychelles Islands' => '+04:00', 
     221        'United Arab Emirates' => '+04:00', 
     222        'Afghanistan ' => '+04:30', 
     223        'Kyrgyzstan' => '+05:00', 
     224        'Maldives' => '+05:00', 
     225        'Pakistan' => '+05:00', 
     226        'Turkmenistan' => '+05:00', 
     227        'Uzbekistan' => '+05:00', 
     228        'India' => '+05:30', 
     229        'Nepal' => '+05:30', 
     230        'Sri Lanka' => '+05:30', 
     231        'Bangladesh' => '+06:00', 
     232        'Bhutan' => '+06:00', 
     233        'Kazakhstan' => '+06:00', 
     234        'Tajikistan' => '+06:00', 
     235        'Myanmar' => '+06:30', 
     236        'Cambodia' => '+07:00', 
     237        'Indonesia West' => '+07:00', 
     238        'Laos' => '+07:00', 
     239        'Russia Central 2' => '+07:00', 
     240        'Thailand' => '+07:00', 
     241        'Vietnam' => '+07:00', 
     242        'Australia West' => '+08:00', 
     243        'Brunei' => '+08:00', 
     244        'China' => '+08:00', 
     245        'Hong Kong' => '+08:00', 
     246        'Indonesia Central' => '+08:00', 
     247        'Malaysia' => '+08:00', 
     248        'Mongolia' => '+08:00', 
     249        'Philippines' => '+08:00', 
     250        'Singapore' => '+08:00', 
     251        'Taiwan' => '+08:00', 
     252        'Indonesia East' => '+09:00', 
     253        'Japan' => '+09:00', 
     254        'Korea, North' => '+09:00', 
     255        'Korea, South' => '+09:00', 
     256        'Palau' => '+09:00', 
     257        'Australia North' => '+09:30', 
     258        'Australia South' => '+10:00', 
     259        'Australia East' => '+10:00', 
     260        'Guam' => '+10:00', 
     261        'Papua New Guinea' => '+10:00', 
     262        'New Caledonia' => '+11:00', 
     263        'Russia East' => '+11:00', 
     264        'Solomon Islands' => '+11:00', 
     265        'Vanuatu' => '+11:00', 
     266        'Norfolk Island' => '+11:30', 
     267        'Fiji Islands' => '+12:00', 
     268        'Kiribati' => '+12:00', 
     269        'Marshall Islands' => '+12:00', 
     270        'Nauru' => '+12:00', 
     271        'New Zealand' => '+12:00', 
     272        'Tuvalu' => '+12:00', 
     273        'Wallis And Futuna Islands' => '+12:00', 
     274        'Tonga Islands' => '+13:00' 
     275 ); 
    29276?> 
  • index.php

    r31 r34  
    5656if ( $_POST['text'] ) { 
    5757        $profile = get_profile(); 
    58         mysql_query("INSERT INTO log (user_id,created_at,text) VALUES(" . $profile['id'] . ",NOW(),'" . ereg_replace( "'", "\\'", $_POST['text'] ) . "');"); 
     58        mysql_query("INSERT INTO log (user_id,created_at,text) VALUES(" . $profile['id'] . ", CONVERT_TZ(NOW(), '" . $timezones[$conf['site.tz']] . "', '+00:00'),'" . ereg_replace( "'", "\\'", $_POST['text'] ) . "');"); 
    5959         
    6060        if ( is_ajax() ) { 
  • install.sql

    r24 r34  
    77 
    88LOCK TABLES `conf` WRITE; 
    9 INSERT INTO `conf` VALUES ('site.title','bitlog'),('site.desc','a simple bitlog'),('site.admin','test'),('site.url',''),('site.theme','simple'),('site.charset','UTF-8'),('site.lang','en-US'),('posts.num','15'),('feed.theme','rss2'),('site.register','single'),('urls.theme','bitlog'); 
     9INSERT INTO `conf` VALUES ('site.title','bitlog'),('site.desc','a simple bitlog'),('site.admin','test'),('site.url',''),('site.theme','simple'),('site.charset','UTF-8'),('site.tz','USA Eastern'),('site.lang','en-US'),('posts.num','15'),('feed.theme','rss2'),('site.register','single'),('urls.theme','bitlog'); 
    1010UNLOCK TABLES; 
    1111 
     
    3131  `is_admin` tinyint(4) NOT NULL, 
    3232  `fullname` varchar(75) collate utf8_unicode_ci NOT NULL, 
     33  `timezone` varchar(50) collate utf8_unicode_ci NOT NULL, 
    3334  `icon` varchar(255) collate utf8_unicode_ci NOT NULL, 
    3435  PRIMARY KEY  (`id`) 
     
    3637 
    3738LOCK TABLES `users` WRITE; 
    38 INSERT INTO `users` VALUES (1,'test','5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8','Somewhere',1,'Test User',''); 
     39INSERT INTO `users` VALUES (1,'test','5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8','Somewhere',1,'Test User','USA Eastern',''); 
    3940UNLOCK TABLES; 
  • lib/auth.php

    r33 r34  
    44        global $_REQUEST; 
    55 
    6     if ( !session_id() ) { 
    7        session_start(); 
    8    
     6       if ( !session_id() ) { 
     7          session_start(); 
     8       
    99         
    1010        if ( !empty( $user ) && !empty( $pass ) ) { 
     
    3030 
    3131function logout() { 
    32     if ( !session_id() ) { 
    33        session_start(); 
    34    
     32       if ( !session_id() ) { 
     33          session_start(); 
     34       
    3535        session_unset(); 
    3636        session_destroy(); 
     
    4444 
    4545function loggedin() { 
    46     if ( !session_id() ) { 
    47        session_start(); 
    48    
     46       if ( !session_id() ) { 
     47          session_start(); 
     48       
    4949        return !empty( $_SESSION['bit_user'] ); 
    5050} 
     
    7373} 
    7474 
     75function get_profile_timezone() { 
     76        global $conf, $timezones; 
     77 
     78        $profile = get_profile(); 
     79 
     80        if (array_key_exists('timezone', $profile) 
     81        &&  array_key_exists($profile['timezone'], $timezones)) { 
     82                return $timezones[$profile['timezone']]; 
     83        } 
     84         
     85        return $timezones[$conf['site.tz']]; 
     86} 
     87 
    7588function is_admin() { 
    7689        $tmp_profile = get_profile(); 
  • lib/pages.php

    r17 r34  
    6060// Settings Page 
    6161function page_settings() { 
    62         global $theme_path, $conf, $title
     62        global $theme_path, $conf, $title, $timezones
    6363         
    6464        if ( !loggedin() ) { 
     
    7070                         
    7171                        // Update the profile information 
    72                         mysql_query(sprintf("UPDATE users SET location='%s', fullname='%s', icon='%s' WHERE id=%s;", 
    73                                 $_POST['location'], $_POST['fullname'], $_POST['icon'], $profile['id'] )); 
     72                        mysql_query(sprintf("UPDATE users SET location='%s', fullname='%s', timezone='%s', icon='%s' WHERE id=%s;", 
     73                                $_POST['location'], $_POST['fullname'], $_POST['timezone'], $_POST['icon'], $profile['id'] )); 
    7474                         
    7575                        // Update the password (when necessary) 
  • lib/posts.php

    r30 r34  
    77        $num = $conf['posts.num'] + 1; 
    88         
    9         load_posts( "SELECT * FROM users, log WHERE users.name='$author' AND users.id = log.user_id" . 
     9        load_posts( "SELECT *, CONVERT_TZ(created_at, '+00:00', '" . get_profile_timezone() . "') AS created_at FROM users, log WHERE users.name='$author' AND users.id = log.user_id" . 
    1010                " ORDER BY created_at DESC LIMIT $offset,$num;" ); 
    1111         
     
    2525        $num = $conf['posts.num'] + 1; 
    2626         
    27         load_posts( "SELECT * FROM users, log WHERE log.user_id=users.id" . 
     27        load_posts( "SELECT *, CONVERT_TZ(created_at, '+00:00', '" . get_profile_timezone() . "') AS created_at FROM users, log WHERE log.user_id=users.id" . 
    2828                ( $year > 0 ?  " AND YEAR(created_at) = $year" : "" ) . 
    2929                ( $month > 0 ?  " AND MONTH(created_at) = $month" : "" ) . 
     
    4444        } 
    4545         
    46         load_posts( "SELECT * FROM users, log WHERE log.id = $id AND users.id = log.user_id LIMIT 1;" ); 
     46        load_posts( "SELECT *, CONVERT_TZ(created_at, '+00:00', '" . get_profile_timezone() . "') AS created_at FROM users, log WHERE log.id = $id AND users.id = log.user_id LIMIT 1;" ); 
    4747} 
    4848 
  • themes/simple/settings.php

    r17 r34  
    77        <label for="name">Full Name:</label><input type="text" name="fullname" class="text" value="<?=$profile['fullname']?>"/><br/> 
    88        <label for="name">Location:</label><input type="text" name="location" class="text" value="<?=$profile['location']?>"/><br/> 
     9        <label for="timezone">Time Zone:</label> 
     10        <select name="timezone"> 
     11                <?php foreach ($timezones as $country => $gmt) { 
     12                        $selected = ''; 
     13                        if ($country == $profile['timezone']) { 
     14                                $selected = 'selected="selected"'; 
     15                        } 
     16                 ?> 
     17                        <option value="<?= $country ?>" <?= $selected ?>>(<?= $gmt ?>) <?= $country ?></option> 
     18                <?php } ?> 
     19        </select><br/> 
    920        <label for="name">Icon (URL):</label><input type="text" name="icon" class="text" value="<?=$profile['icon']?>"/><br/> 
    1021        <label>&nbsp;</label><small>(Should be square, 48x48 pixels is best.)</small><br/><br/> 
     
    2435<?php foreach ( $conf as $name => $value ) { 
    2536        if ( strrpos($name,"db.") === false ) { 
     37                if ( $name == 'site.tz' ) { 
    2638        ?> 
    27         <label><?=$name?></label><input type="text" class="text" name="<?=$name?>" value="<?=$value?>"/><br/> 
    28 <?php } } ?> 
     39                <label><?=$name?></label> 
     40                <select name="<?= $name ?>"> 
     41                        <?php foreach ($timezones as $country => $gmt) { 
     42                                $selected = ''; 
     43                                if ($country == $value) { 
     44                                        $selected = 'selected="selected"'; 
     45                                } 
     46                         ?> 
     47                                <option value="<?= $country ?>" <?= $selected ?>>(<?= $gmt ?>) <?= $country ?></option> 
     48                        <?php } ?> 
     49                </select><br/> 
     50        <?php 
     51                } else { 
     52        ?> 
     53                <label><?=$name?></label><input type="text" class="text" name="<?=$name?>" value="<?=$value?>"/><br/> 
     54<?php } } } ?> 
    2955<input type="submit" class="submit" value="Save"/> 
    3056<input type="hidden" name="form" value="settings"/>