Dotclear

source: plugins/carnaval/_public.php @ 556

Revision 556, 3.6 KB checked in by Osku, 15 years ago (diff)

Carnaval 1.2RC - finally blowup friendly

Line 
1<?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
2/***************************************************************\
3 *  This is 'Carnaval', a plugin for Dotclear 2                *
4 *                                                             *
5 *  Copyright (c) 2007-2008                                    *
6 *  Osku and contributors.                                     *
7 *                                                             *
8 *  This is an open source software, distributed under the GNU *
9 *  General Public License (version 2) terms and  conditions.  *
10 *                                                             *
11 *  You should have received a copy of the GNU General Public  *
12 *  License along with 'Carnaval' (see COPYING.txt);           *
13 *  if not, write to the Free Software Foundation, Inc.,       *
14 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    *
15\***************************************************************/
16
17# On surchage les fonctions template
18
19if ($core->blog->settings->carnaval_active){
20$core->tpl->addValue('CommentIfMe',array('tplCarnaval','CommentIfMe'));
21$core->tpl->addValue('PingIfOdd',array('tplCarnaval','PingIfOdd'));
22$core->addBehavior('publicHeadContent',array('tplCarnaval','publicHeadContent'));
23}
24
25class tplCarnaval
26{
27     public static function CommentIfMe($attr)
28     {
29          $ret = isset($attr['return']) ? $attr['return'] : 'me';
30          $ret = html::escapeHTML($ret);
31         
32          return
33          '<?php if ($_ctx->comments->isMe()) { '.
34          "echo '".addslashes($ret)."'; } ".
35          "echo tplCarnaval::getCommentClass(); ?>";
36     }
37     
38     public static function PingIfOdd($attr)
39     {
40          $ret = isset($attr['return']) ? $attr['return'] : 'odd';
41          $ret = html::escapeHTML($ret);
42         
43          return
44          '<?php if (($_ctx->pings->index()+1)%2) { '.
45          "echo '".addslashes($ret)."'; } ".
46          "echo tplCarnaval::getPingClass(); ?>";
47     }
48     
49     public static function getCommentClass()
50     {
51          global $_ctx;
52         
53          $classe_perso = dcCarnaval::getCommentClass($_ctx->comments->getEmail(false));
54          return html::escapeHTML($classe_perso);
55     }
56     
57     public static function getPingClass()
58     {
59          global $_ctx;
60         
61          $classe_perso = dcCarnaval::getPingClass($_ctx->pings->getAuthorURL());
62          return html::escapeHTML($classe_perso);
63     }
64     
65     
66     public static function publicHeadContent(&$core)
67     {
68          if ($core->blog->settings->theme != 'default') {
69               return;
70          }
71          echo '<style type="text/css">'."\n".self::carnavalStyleHelper()."\n</style>\n";
72     }
73     
74     public static function carnavalStyleHelper()
75     {
76          $cval = dcCarnaval::getClasses();
77          $css = array();
78          while ($cval->fetch())
79               {
80                    $res = '';
81                    $cl_class = $cval->comment_class;
82                    $cl_txt = $cval->comment_text_color;
83                    $cl_backg = $cval->comment_background_color;
84                    self::prop($css,'#comments dd.'.$cl_class,'color',$cl_txt);
85                    self::prop($css,'#comments dd.'.$cl_class,'background-color',$cl_backg);
86                    self::backgroundImg($css,'#comments dt.'.$cl_class, $cl_backg,$cl_class.'-comment-t.png');
87                    self::backgroundImg($css,'#comments dd.'.$cl_class,$cl_backg,$cl_class.'-comment-b.png');
88                    foreach ($css as $selector => $values)
89                    {
90                         $res .= $selector." {\n";
91                         foreach ($values as $k => $v) {
92                              $res .= $k.':'.$v.";\n";
93                         }
94                         $res .= "}\n";
95                    }
96               }
97               return $res;
98     }
99
100     protected static function prop(&$css,$selector,$prop,$value)
101     {
102          if ($value) {
103               $css[$selector][$prop] = $value;
104          }
105     }
106     
107     protected static function backgroundImg(&$css,$selector,$value,$image)
108     {
109          $file = carnavalConfig::imagesPath().'/'.$image;
110          if ($value && file_exists($file)){
111               $css[$selector]['background-image'] = 'url('.carnavalConfig::imagesURL().'/'.$image.')';
112          }
113     }
114}
115?>
Note: See TracBrowser for help on using the repository browser.

Sites map