Changeset 1652

Show
Ignore:
Timestamp:
05/25/2007 09:27:40 PM (20 months ago)
Author:
robertb
Message:

benutze jetzt ganz SQL-like DATE_SUB() und INTERVAL

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/CommentCloser.jplug.php

    r1651 r1652  
    2323                $lifeTime = defined('COMMENT_CLOSER_LIFETIME') ? 
    2424                                COMMENT_CLOSER_LIFETIME : ''; 
     25                $timeUnit = defined('COMMENT_CLOSER_TIMEUNIT') ? 
     26                                COMMENT_CLOSER_TIMEUNIT : ''; 
    2527                $self = htmlspecialchars($_SERVER['REQUEST_URI']); 
    2628 
    2729                if (array_key_exists('commclose_do', $_POST)) { 
    28                         $lifeTime = $_POST['commclose_lifetime'] * 
    29                                         $_POST['commclose_unit']; 
     30                        $lifeTime = $_POST['commclose_lifetime']; 
     31                        $timeUnit = $_POST['commclose_unit']; 
     32 
    3033                        // keine negative Zeiten 
    3134                        if ($lifeTime < 0) 
    3235                                $lifeTime = 0; 
     36 
     37                        # XXX MySQL bug: WEEK wird bei mir nicht 
     38                        # erkannt, deshalb manuelles Umrechnen: 
     39                        if ($timeUnit == 'WEEK') { 
     40                                $lifeTime *= 7; 
     41                                $timeUnit = 'DAY'; 
     42                        } 
    3343 
    3444                        $mask = umask(0); 
     
    3949                                @fwrite($f, 'define(\'COMMENT_CLOSER_'. 
    4050                                        "LIFETIME', $lifeTime);\n"); 
     51                                @fwrite($f, 'define(\'COMMENT_CLOSER_'. 
     52                                        "TIMEUNIT', $timeUnit);\n"); 
    4153                                @fwrite($f, '?>'); 
    4254                                @fclose($f); 
     
    5163        <input type="text" name="commclose_lifetime" size="5" value="$lifeTime" /> 
    5264        <select name="commclose_unit" size="1"> 
    53                 <option value="1">Sekunden</option> 
    54                 <option value="60">Minuten</option> 
    55                 <option value="3600">Stunden</option> 
    56                 <option value="86400">Tagen</option> 
    57                 <option value="604800">Wochen</option> 
    58                 <option value="2592000">Monaten</option> 
    59                 <option value="31536000">Jahren</option> 
     65                <option value="SECOND">Sekunden</option> 
     66                <option value="MINUTE">Minuten</option> 
     67                <option value="HOUR">Stunden</option> 
     68                <option value="DAY">Tagen</option> 
     69                <option value="WEEK">Wochen</option> 
     70                <option value="MONTH">Monaten</option> 
     71                <option value="YEAR">Jahren</option> 
    6072        </select> 
    6173automatisch 
     
    6880        // Pruefen auf zu schliessende Beitraege 
    6981        function hook_onUpdate($data) { 
    70                 if (! defined('COMMENT_CLOSER_LIFETIME') || 
    71                         COMMENT_CLOSER_LIFETIME == 0) 
     82                if (!defined('COMMENT_CLOSER_LIFETIME') || 
     83                        COMMENT_CLOSER_LIFETIME == 0 || 
     84                        !defined('COMMENT_CLOSER_TIMEUNIT')) 
    7285                { 
    7386                        return $data; 
    7487                } 
    7588 
    76                 # TODO 
    7789                $q = new Query('UPDATE kolumne_content SET comments=0 ' . 
    78                         'WHERE UNIX_TIMESTAMP(date) < ' . 
    79                                 'UNIX_TIMESTAMP(NOW()) - ' . 
     90                        'WHERE date < DATE_SUB(NOW(), INTERVAL ' . 
    8091                                COMMENT_CLOSER_LIFETIME . 
    81                         ' AND comments=1'); 
     92                                COMMENT_CLOSER_TIMEUNIT . 
     93                        ') AND comments=1'); 
     94                # TODO error handling 
    8295 
    8396                return $data;