Dotclear

Changeset 2072


Ignore:
Timestamp:
02/12/10 22:45:31 (13 years ago)
Author:
Moe
Message:

CountDown? 1.2-alpha2 :

  • added dynamic display (closes #255)
  • added public and admin declaration of the widget
  • added PHP 5.3 support
  • switched to GPL v2
Location:
plugins/countdown
Files:
32 added
2 deleted
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • plugins/countdown/_define.php

    r693 r2072  
    22# ***** BEGIN LICENSE BLOCK ***** 
    33# 
    4 # This file is part of CountDown. 
    5 # Copyright 2007 Moe (http://gniark.net/) 
     4# This file is part of CountDown, a plugin for Dotclear 2 
     5# Copyright 2007,2010 Moe (http://gniark.net/) 
    66# 
    7 # CountDown is free software; you can redistribute it and/or modify 
    8 # it under the terms of the GNU General Public License as published by 
    9 # the Free Software Foundation; either version 3 of the License, or 
    10 # (at your option) any later version. 
     7# CountDown is free software; you can redistribute it and/or 
     8# modify it under the terms of the GNU General Public License v2.0 
     9# as published by the Free Software Foundation. 
    1110# 
    1211# CountDown is distributed in the hope that it will be useful, 
    1312# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    1514# GNU General Public License for more details. 
    1615# 
    17 # You should have received a copy of the GNU General Public License 
    18 # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     16# You should have received a copy of the GNU General Public 
     17# License along with this program. If not, see 
     18# <http://www.gnu.org/licenses/>. 
    1919# 
    2020# ***** END LICENSE BLOCK ***** 
     
    2424$this->registerModule( 
    2525     /* Name */                         "CountDown", 
    26      /* Description*/         "Countdown widget", 
     26     /* Description*/         "CountDown widget", 
    2727     /* Author */                  "Moe (http://gniark.net/)", 
    28      /* Version */                 '1.1', 
     28     /* Version */                 '1.2-alpha2', 
    2929     /* Permissions */        'admin' 
    3030); 
  • plugins/countdown/_widget.php

    r693 r2072  
    22# ***** BEGIN LICENSE BLOCK ***** 
    33# 
    4 # This file is part of CountDown. 
    5 # Copyright 2007 Moe (http://gniark.net/) 
    6 # 
    7 # CountDown is free software; you can redistribute it and/or modify 
    8 # it under the terms of the GNU General Public License as published by 
    9 # the Free Software Foundation; either version 3 of the License, or 
    10 # (at your option) any later version. 
     4# This file is part of CountDown, a plugin for Dotclear 2 
     5# Copyright 2007,2010 Moe (http://gniark.net/) 
     6# 
     7# CountDown is free software; you can redistribute it and/or 
     8# modify it under the terms of the GNU General Public License v2.0 
     9# as published by the Free Software Foundation. 
    1110# 
    1211# CountDown is distributed in the hope that it will be useful, 
    1312# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    1514# GNU General Public License for more details. 
    1615# 
    17 # You should have received a copy of the GNU General Public License 
    18 # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     16# You should have received a copy of the GNU General Public 
     17# License along with this program. If not, see 
     18# <http://www.gnu.org/licenses/>. 
    1919# 
    2020# ***** END LICENSE BLOCK ***** 
     
    2222if (!defined('DC_RC_PATH')) {return;} 
    2323 
    24 class publicCountDown 
     24$core->addBehavior('initWidgets', 
     25     array('CountDownBehaviors','initWidgets')); 
     26  
     27class CountDownBehaviors 
    2528{ 
    26      public static function Show(&$w) 
     29     public static function initWidgets($w) 
    2730     { 
    2831          # set timezone 
    2932          global $core; 
     33          $tz = $core->blog->settings->blog_timezone; 
     34 
     35          $w->create('CountDown',__('CountDown'), 
     36               array('CountDownBehaviors','Show')); 
     37 
     38          $w->CountDown->setting('title',__('Title:'),__('CountDown'),'text'); 
     39 
     40          $w->CountDown->setting('text_before', 
     41               __('Text displayed if the date is in the future:'),__('In'),'text'); 
     42 
     43          $w->CountDown->setting('text_after', 
     44               __('Text displayed if the date is in the past:'),__('For'),'text'); 
     45 
     46          # create arrays for year, month, day, hour, minute and second 
     47          $array_year = $array_month = $array_day = $array_hour = array(); 
     48          $array_minute = $array_number_of_times = array(); 
     49          for ($i = 1902;$i <= 2037;$i++) 
     50          { 
     51               $array_year[$i] = $i; 
     52          } 
     53          for ($i = 1;$i <= 12;$i++) 
     54          { 
     55               $i = str_repeat('0',(2-strlen($i))).$i; 
     56               $array_month[ucfirst(__(strftime('%B', mktime(0, 0, 0, $i, 1, 1970)))).' ('.$i.')'] = $i; 
     57          } 
     58          for ($i = 1;$i <= 31;$i++) 
     59          { 
     60               $i = str_repeat('0',(2-strlen($i))).$i; 
     61               $array_day[$i] = $i; 
     62          } 
     63          for ($i = 0;$i <= 23;$i++) 
     64          { 
     65               $i = str_repeat('0',(2-strlen($i))).$i; 
     66               $array_hour[$i] = $i; 
     67          } 
     68          for ($i = 0;$i <= 60;$i++) 
     69          { 
     70               $i = str_repeat('0',(2-strlen($i))).$i; 
     71               $array_minute[$i] = $i; 
     72          } 
     73          for ($i = 1;$i <= 5;$i++) 
     74          { 
     75               $array_number_of_times[$i] = $i; 
     76          } 
     77          $array_number_of_times['6 ('.__('all').')'] = 6; 
     78          # /create arrays 
     79 
     80          $w->CountDown->setting('year',ucfirst(__('year')).':', 
     81               dt::str('%Y',null,$tz),'combo',$array_year); 
     82          $w->CountDown->setting('month',ucfirst(__('month')).':', 
     83               dt::str('%m',null,$tz),'combo',$array_month); 
     84          $w->CountDown->setting('day',ucfirst(__('day')).':', 
     85               dt::str('%d',null,$tz),'combo',$array_day); 
     86          $w->CountDown->setting('hour',ucfirst(__('hour')).':', 
     87               dt::str('%H',null,$tz),'combo',$array_hour); 
     88          $w->CountDown->setting('minute',ucfirst(__('minute')).':', 
     89               dt::str('%M',null,$tz),'combo',$array_minute); 
     90          $w->CountDown->setting('second',ucfirst(__('second')).':', 
     91               dt::str('%S',null,$tz),'combo',$array_minute); 
     92 
     93          $w->CountDown->setting('number_of_times', 
     94               __('Number of values to be displayed:'),'6','combo', 
     95               $array_number_of_times); 
     96 
     97          $w->CountDown->setting('zeros', 
     98               __('Show zeros before hours, minutes and seconds'),false,'check'); 
     99           
     100          $w->CountDown->setting('dynamic', 
     101               __('Enable dynamic display'),false,'check'); 
     102           
     103          $jquery_countdown_ref = 'http://keith-wood.name/countdownRef.html'; 
     104           
     105          $w->CountDown->setting('dynamic_format', 
     106               sprintf(__('Dynamic display format (see <a href="%1$s" %2$s>jQuery Countdown reference</a>):'), 
     107               $jquery_countdown_ref, 
     108               'onclick="return window.confirm(\''. 
     109               __('Are you sure you want to leave this page?').'\')"'), 
     110               __('yowdHMS'),'text'); 
     111           
     112          $w->CountDown->setting('dynamic_layout_before', 
     113               sprintf(__('Dynamic display layout if the date is in the future (see <a href="%1$s" %2$s>jQuery Countdown reference</a>):'), 
     114               $jquery_countdown_ref, 
     115               'onclick="return window.confirm(\''. 
     116               __('Are you sure you want to leave this page?').'\')"'), 
     117               __('In {y<}{yn} {yl}, {y>}{o<}{on} {ol}, {o>}{d<}{dn} {dl}, {d>}{hn} {hl}, {mn} {ml} and {sn} {sl}'), 
     118               'textarea'); 
     119           
     120          $w->CountDown->setting('dynamic_layout_after', 
     121               sprintf(__('Dynamic display layout if the date is in the past (see <a href="%1$s" %2$s>jQuery Countdown reference</a>):'), 
     122               $jquery_countdown_ref, 
     123               'onclick="return window.confirm(\''. 
     124               __('Are you sure you want to leave this page?').'\')"'), 
     125               __('For {y<}{yn} {yl}, {y>}{o<}{on} {ol}, {o>}{d<}{dn} {dl}, {d>}{hn} {hl}, {mn} {ml} and {sn} {sl}'), 
     126               'textarea'); 
     127           
     128          $w->CountDown->setting('homeonly', 
     129               __('Home page only'),false,'check'); 
     130     } 
     131      
     132     # escape quotes but not XHTML tags 
     133     # inspired by html::escapeJS() 
     134     public static function escapeQuotes($str) 
     135     { 
     136          $str = str_replace("'","\'",$str); 
     137          $str = str_replace('"','\"',$str); 
     138          return $str; 
     139     } 
     140      
     141     public static function Show($w) 
     142     { 
     143          # set timezone 
     144          global $core; 
    30145 
    31146          if ($w->homeonly && $core->url->type != 'default') { 
     
    36151          $local_time = dt::addTimeZone($core->blog->settings->blog_timezone); 
    37152 
    38           $ts = mktime($w->hour,$w->minute,$w->second,$w->month,$w->day,$w->year); 
     153          $ts = mktime($w->hour,$w->minute,$w->second,$w->month,$w->day, 
     154               $w->year); 
    39155          # get difference 
    40156          (int)$diff = ($local_time - $ts); 
    41157          $after = ($diff > 0) ? true : false; 
    42158          $diff = abs($diff); 
    43  
     159           
    44160          $times = array(); 
    45  
     161           
    46162          $intervals = array 
    47163          ( 
    48                (3600*24*365.24) => array('one'=>__('year'),'more'=>__('years'),'zeros'=>false), 
    49                (3600*24*30.4) => array('one'=>__('month'),'more'=>__('months'),'zeros'=>false), 
    50                (3600*24) => array('one'=>__('day'),'more'=>__('days'),'zeros'=>false), 
    51                (3600) => array('one'=>__('hour'),'more'=>__('hours'),'zeros'=>true), 
    52                (60) => array('one'=>__('minute'),'more'=>__('minutes'),'zeros'=>true), 
    53                (1) => array('one'=>__('second'),'more'=>__('seconds'),'zeros'=>true), 
     164               (3600*24*365.24) => array('one'=>__('year'),'more'=>__('years'), 
     165                    'zeros'=>false), 
     166               (3600*24*30.4) => array('one'=>__('month'),'more'=>__('months'), 
     167                    'zeros'=>false), 
     168               (3600*24) => array('one'=>__('day'),'more'=>__('days'), 
     169                    'zeros'=>false), 
     170               (3600) => array('one'=>__('hour'),'more'=>__('hours'), 
     171                    'zeros'=>true), 
     172               (60) => array('one'=>__('minute'),'more'=>__('minutes'), 
     173                    'zeros'=>true), 
     174               (1) => array('one'=>__('second'),'more'=>__('seconds'), 
     175                    'zeros'=>true), 
    54176          ); 
    55  
     177           
    56178          foreach ($intervals as $k => $v) 
    57179          { 
     
    59181               { 
    60182                    $time = floor($diff/$k); 
    61                     $times[] = (($w->zeros AND $v['zeros']) ? sprintf('%02d',$time) : $time).' '.(($time <= 1) ? $v['one'] : $v['more']); 
     183                    $times[] = (($w->zeros AND $v['zeros']) 
     184                         ? sprintf('%02d',$time) : $time).' '.(($time <= 1) ? $v['one'] 
     185                         : $v['more']); 
    62186                    $diff = $diff%$k; 
    63187               } 
    64188          } 
    65  
     189           
    66190          # output 
    67           $header = (strlen($w->title) > 0) ? '<h2>'.html::escapeHTML($w->title).'</h2>' : null; 
     191          $header = (strlen($w->title) > 0) 
     192               ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''; 
    68193          $text = ($after) ? $w->text_after : $w->text_before; 
    69194          if (strlen($text) > 0) {$text .= ' ';} 
    70  
     195           
    71196          # get times and make a string 
    72197          $times = array_slice($times,0,$w->number_of_times); 
     
    77202          } 
    78203          else {$str = implode('',$times);} 
    79  
    80           return '<div class="countdown">'.$header.'<p class="text">'.$text.$str.'</p></div>'; 
     204           
     205          if (!$w->dynamic) 
     206          { 
     207               return '<div class="countdown">'.$header. 
     208                    '<p class="text">'.$text.'<span>'.$str.'</span></p>'. 
     209               '</div>'; 
     210          } 
     211          else 
     212          { 
     213               # dynamic display with Countdown for jQuery 
     214               if (!is_numeric($GLOBALS['_ctx']->countdown)) 
     215               { 
     216                    $GLOBALS['_ctx']->countdown = 0; 
     217               } 
     218               $id = $GLOBALS['_ctx']->countdown; 
     219               $GLOBALS['_ctx']->countdown += 1; 
     220                
     221               $script = ''; 
     222                
     223               if (!defined('COUNTDOWN_SCRIPT')) 
     224               { 
     225                    $script = 
     226                         '<script type="text/javascript" src="'. 
     227                         $core->blog->getQmarkURL(). 
     228                         'pf=countdown/js/jquery.countdown.min.js"></script>'."\n"; 
     229           
     230                    $l10n_file = 
     231                         'jquery.countdown-'.$core->blog->settings->lang.'.js'; 
     232                    if (file_exists(dirname(__FILE__).'/js/'.$l10n_file)) 
     233                    { 
     234                         $script .=  
     235                         '<script type="text/javascript" src="'.$core->blog->getQmarkURL(). 
     236                              'pf=countdown/js/'.$l10n_file.'"></script>'."\n"; 
     237                    } 
     238                     
     239                    define('COUNTDOWN_SCRIPT',(bool)true); 
     240               } 
     241                
     242               if ($after) 
     243               { 
     244                    $to = 'since'; 
     245                    $layout = $w->dynamic_layout_after; 
     246               } 
     247               else 
     248               { 
     249                    $to = 'until'; 
     250                    $layout = $w->dynamic_layout_before; 
     251               } 
     252                
     253               return $script.'<div class="countdown">'.$header. 
     254                    '<p class="text" id="countdown-'.$id.'">'.$text.$str.'</p>'. 
     255                    '<script type="text/javascript">'."\n". 
     256                    '//<![CDATA['."\n". 
     257                         '$().ready(function() {'. 
     258                         "$('#countdown-".$id."').countdown({". 
     259                              # In Javascript, 0 = January, 11 = December 
     260                              $to.": new Date(".(int)$w->year.",".(int)$w->month."-1,". 
     261                              (int)$w->day.",".(int)$w->hour.",".(int)$w->minute.",". 
     262                              (int)$w->second."), 
     263                              description: '".html::escapeJS($text)."', 
     264                              format: '".$w->dynamic_format."', 
     265                              layout: '".$layout."', 
     266                              expiryText: '".html::escapeJS($w->text_after)."', 
     267                         });". 
     268                         '});'."\n". 
     269                    '//]]>'. 
     270                    '</script>'."\n". 
     271               '</div>'; 
     272          } 
    81273     } 
    82274} 
  • plugins/countdown/locales/fr/main.po

    r1638 r2072  
    1 # French translation of CountDown, a plugin for dotclear 
    2 # This file is generated by LangOmatic, a plugin for Dotclear 
     1# Language: français 
     2# Module: countdown - 1.2-alpha2 
     3# Date: 2010-02-12 18:31:01 
     4# Translated with dcTranslater - 1.2 
     5 
    36msgid "" 
    4 msgstr "" 
    5 "Content-Type: text/plain; charset=UTF-8\n" 
    6 "Project-Id-Version: \n" 
    7 "POT-Creation-Date: \n" 
    8 "PO-Revision-Date: \n" 
    9 "Last-Translator: Kozlika <kozlika@free.fr>\n" 
    10 "Language-Team: \n" 
    11 "MIME-Version: 1.0\n" 
    12 "Content-Transfer-Encoding: 8bit\n" 
     7msgstr "Content-Type: text/plain; charset=UTF-8\n" 
    138 
    14 #: _admin.php:12 
    15 #: _admin.php:14 
     9#: _admin.php:38 
    1610msgid "CountDown" 
    1711msgstr "Chronomètre" 
    1812 
    19 #: _admin.php:16 
     13#: _admin.php:41 
    2014msgid "Text displayed if the date is in the future:" 
    2115msgstr "Texte affiché si la date est dans le futur&nbsp;:" 
    2216 
    23 #: _admin.php:16 
     17#: _admin.php:41 
    2418msgid "In" 
    2519msgstr "Dans" 
    2620 
    27 #: _admin.php:18 
     21#: _admin.php:44 
    2822msgid "Text displayed if the date is in the past:" 
    2923msgstr "Texte affiché si la date est passée&nbsp;:" 
    3024 
    31 #: _admin.php:18 
     25#: _admin.php:44 
    3226msgid "For" 
    3327msgstr "Depuis" 
    3428 
    35 #: _admin.php:50 
     29#: _admin.php:77 
    3630msgid "all" 
    3731msgstr "tous" 
    3832 
    39 #: _admin.php:53 
    40 #: _public.php:30 
     33#: _public.php:58 
    4134msgid "year" 
    4235msgstr "année" 
    4336 
    44 #: _admin.php:54 
    45 #: _public.php:36 
     37#: _public.php:60 
    4638msgid "month" 
    4739msgstr "mois" 
    4840 
    49 #: _admin.php:55 
    50 #: _public.php:42 
     41#: _public.php:62 
    5142msgid "day" 
    5243msgstr "jour" 
    5344 
    54 #: _admin.php:56 
    55 #: _public.php:48 
     45#: _public.php:64 
    5646msgid "hour" 
    5747msgstr "heure" 
    5848 
    59 #: _admin.php:57 
    60 #: _public.php:54 
     49#: _public.php:66 
    6150msgid "minute" 
    6251msgstr "minute" 
    6352 
    64 #: _admin.php:58 
    65 #: _public.php:60 
     53#: _public.php:68 
    6654msgid "second" 
    6755msgstr "seconde" 
    6856 
    69 #: _admin.php:60 
     57#: _admin.php:94 
    7058msgid "Number of values to be displayed:" 
    7159msgstr "Nombre de valeurs à afficher&nbsp;:" 
    7260 
    73 #: _admin.php:62 
     61#: _admin.php:98 
    7462msgid "Show zeros before hours, minutes and seconds" 
    7563msgstr "Afficher des zéros devant les heures, les minutes et les secondes" 
    7664 
    77 #: _public.php:30 
     65#: _admin.php:101 
     66msgid "Enable dynamic display" 
     67msgstr "Activer l'affichage dynamique" 
     68 
     69#: _admin.php:106 
     70msgid "Dynamic display format (see <a href="%1$s" %2$s>jQuery Countdown reference</a>):" 
     71msgstr "Format de l'affichage dynamique (voir <a href=\"%1$s\" %2$s>jQuery Countdown reference</a>)&nbsp;:" 
     72 
     73#: _admin.php:113 
     74msgid "Dynamic display layout if the date is in the future (see <a href="%1$s" %2$s>jQuery Countdown reference</a>):" 
     75msgstr "Mise en page de l'affichage dynamique si la date est dans le futur (voir <a href=\"%1$s\" %2$s>jQuery Countdown reference</a>)&nbsp;:" 
     76 
     77#: _admin.php:117 
     78msgid "In {y<}{yn} {yl}, {y>}{o<}{on} {ol}, {o>}{d<}{dn} {dl}, {d>}{hn} {hl}, {mn} {ml} and {sn} {sl}" 
     79msgstr "Dans {y<}{yn} {yl}, {y>}{o<}{on} {ol}, {o>}{d<}{dn} {dl}, {d>}{hn} {hl}, {mn} {ml} et {sn} {sl}" 
     80 
     81#: _admin.php:121 
     82msgid "Dynamic display layout if the date is in the past (see <a href="%1$s" %2$s>jQuery Countdown reference</a>):" 
     83msgstr "Mise en page de l'affichage dynamique si la date est passée (voir <a href=\"%1$s\" %2$s>jQuery Countdown reference</a>)&nbsp;:" 
     84 
     85#: _admin.php:125 
     86msgid "For {y<}{yn} {yl}, {y>}{o<}{on} {ol}, {o>}{d<}{dn} {dl}, {d>}{hn} {hl}, {mn} {ml} and {sn} {sl}" 
     87msgstr "Depuis {y<}{yn} {yl}, {y>}{o<}{on} {ol}, {o>}{d<}{dn} {dl}, {d>}{hn} {hl}, {mn} {ml} et {sn} {sl}" 
     88 
     89#: _public.php:58 
    7890msgid "years" 
    7991msgstr "années" 
    8092 
    81 #: _public.php:36 
     93#: _public.php:60 
    8294msgid "months" 
    8395msgstr "mois" 
    8496 
    85 #: _public.php:42 
     97#: _public.php:62 
    8698msgid "days" 
    8799msgstr "jours" 
    88100 
    89 #: _public.php:48 
     101#: _public.php:64 
    90102msgid "hours" 
    91103msgstr "heures" 
    92104 
    93 #: _public.php:54 
     105#: _public.php:66 
    94106msgid "minutes" 
    95107msgstr "minutes" 
    96108 
    97 #: _public.php:60 
     109#: _public.php:68 
    98110msgid "seconds" 
    99111msgstr "secondes" 
    100112 
    101 #: _public.php:74 
     113#: _public.php:95 
    102114msgid "and" 
    103115msgstr "et" 
Note: See TracChangeset for help on using the changeset viewer.

Sites map