Dotclear

source: plugins/bloganniv/_public.php @ 3159

Revision 3159, 4.5 KB checked in by brol, 10 years ago (diff)

version 1.3.2 : modif locales, modif apparence widget

  • Property svn:executable set to *
Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3# This file is part of DotClear bloganniv plugin.
4# Copyright (c) 2007 Trautmann Francis and contributors. All rights
5# reserved.
6#
7# DotClear 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 2 of the License, or
10# (at your option) any later version.
11#
12# DotClear is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with DotClear; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20#
21# ***** END LICENSE BLOCK *****
22
23if (!defined('DC_RC_PATH')) { return; }
24
25l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/admin');
26
27require dirname(__FILE__).'/_widgets.php';
28
29$core->tpl->addValue('blogAnniv',array('tplBlogAnniv','blogAnniv'));
30
31class tplBlogAnniv
32{
33
34     public static function blogAnniv($attr)
35     {
36          $output = '';
37         
38          if (isset($attr['text']))
39          {
40               $author = isset($attr['author']) ? ' <cite>'.$attr['author'].'</cite>' : '';
41               
42               $output = '<blockquote>'.$attr['text'].$author.'</blockquote>';
43          }
44         
45          return $output;
46     }
47     
48     public static function BlogAnnivWidget($w)
49     {
50          global $core;
51         
52          // Si nous sommes pas en page accueil et que c'est coché page accueil uniquement on fait rien
53
54          if (($w->homeonly == 1 && $core->url->type != 'default') ||
55               ($w->homeonly == 2 && $core->url->type == 'default')) {
56               return;
57          }
58         
59          $title = $w->title ? html::escapeHTML($w->title) : __('Subscribe');
60          $ftdatecrea = $w->ftdatecrea;
61          //Si la date est vide nous recherchons la date en base
62          if (strlen(rtrim($ftdatecrea))==0){
63               ///////////////////////////////////////////////
64               //ACCES BDD
65               //je récupère la date du blog
66               require_once dirname(__FILE__).'/class.dc.dateBlog.php';
67         
68               $lc = new dateBlog($GLOBALS['core']->blog);
69               try {
70                    $Posts = $lc->getdateBlog();
71               } 
72               catch (Exception $e) {
73                    return false;
74               }
75               foreach($Posts->rows() as $k => $v)
76               {
77                    $ftdatecrea = html::clean($v['blog_creadt']);
78                    $ftdatecrea = substr($ftdatecrea,0,10);
79                    $ftdatecrea = str_replace("-","/",$ftdatecrea);
80                    list($annee, $mois, $jour) = explode('/', $ftdatecrea);
81                    // On remet la date en forme française
82                    $ftdatecrea=$jour."/".$mois."/".$annee;
83                    #printf($ftdatecrea);
84                    #printf(html::clean($v['blog_id']));
85               }
86               //FIN ACCES BDD
87               ///////////////////////////////////////////////
88          } else {
89               list($jour, $mois, $annee) = explode('/', $ftdatecrea);
90          }
91          $nbrejours=0;
92          $nbreannee=0;
93          // Test si la date est valide
94          if(@checkdate($mois,$jour,$annee)){
95               // Ok nous pouvons calculer la date anniversaire et le nombre de jours restant avant
96               
97               //Extraction des données
98               list($jour2, $mois2, $annee2) = explode('-', date('d-m-Y'));
99
100               //Calcul des timestamp
101               $timestamp1 = mktime(0,0,0,$mois,$jour,$annee2); // La date anniversaire cette année
102               $timestamp2 = mktime(0,0,0,$mois2,$jour2,$annee2); 
103               //Affichage du nombre de jour
104
105      //je regarde si la date anniv n'est pas passé
106      if (($timestamp2 - $timestamp1)> 0)
107      {
108      $timestamp1 = mktime(0,0,0,$mois,$jour,$annee2 + 1);
109      $nbrejours = round(abs(mktime(0,0,0,$mois2,$jour2,$annee2) - $timestamp1)/86400);
110      $nbreannee = abs($annee2 - $annee);
111      }
112      else {
113      $nbrejours = abs($timestamp2 - $timestamp1)/86400;
114      $nbreannee = abs($annee2 - $annee - 1);
115      }
116               // abs($timestamp2 - $timestamp1)/(86400*7); //Affichage du nombre de semaine : 3.85
117          } else {
118               $ftdatecrea= '$ftdatecrea date invalide';
119          }
120          $dispyearborn = $dispyear = "";
121          // Si je dois afficher la date de naissance
122          if ($w->dispyearborn) {
123               $dispyearborn = __('Born:').
124      ' <span class="annivne">'.$ftdatecrea.'</span><br />';
125          }
126          // Si je dois afficher le l'age en année
127          if ($w->dispyear) {
128               $dispyear = __('Age:').
129      ' <span class="annivan">'.$nbreannee.'</span> '.
130      __('year(s)').
131      '<br />';
132          }
133          return
134          $res = ($w->content_only ? '' : '<div class="bloganniv'.($w->class ? ' '.html::escapeHTML($w->class) : '').'">').
135          '<h2>'.$title.'</h2>'.'<p>'.
136          $dispyearborn.
137          $dispyear.
138          __('Birthday in').
139    ' <span class="annivjrs">'.$nbrejours.'</span> '.
140    __('day(s)').'</p>'.
141    ($w->content_only ? '' : '</div>');
142     }
143}
144?>
Note: See TracBrowser for help on using the repository browser.

Sites map