Dotclear

source: themes/freshy2/_public.php @ 2170

Revision 2170, 6.3 KB checked in by bruno, 14 years ago (diff)

Added dotclear 2.2 compatibility.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of Freshy2, a theme for Dotclear.
4# Original WP Theme from Julien de Luca
5# (http://www.jide.fr/francais/)
6#
7# Copyright (c) 2008-2009
8# Bruno Hondelatte dsls@morefnu.org
9# Pierre Van Glabeke contact@brol.info
10#
11# Licensed under the GPL version 2.0 license.
12# A copy of this license is available in LICENSE file or at
13# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
14# -- END LICENSE BLOCK ------------------------------------
15$core->tpl->addValue('Freshy2StyleSheet',array('tplFreshy2Theme','FreshyStyleSheet'));
16$core->tpl->addValue('Freshy2LayoutClass',array('tplFreshy2Theme','FreshyLayoutClass'));
17$core->tpl->addBlock('Freshy2IfHasSidebar',array('tplFreshy2Theme','FreshyIfHasSidebar'));
18$core->tpl->addBlock('Freshy2IfHasSidebarContent',array('tplFreshy2Theme','FreshyIfHasSidebarContent'));
19$core->addBehavior('publicHeadContent',array('tplFreshy2Theme','publicHeadContent'));
20l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/public');
21
22class tplFreshy2Theme
23{
24     public static $settings;
25     
26     public static function initSettings() {
27          global $core;
28          if (!version_compare(DC_VERSION,'2.1.6','<='))
29               self::$settings =& $core->blog->settings->freshy2;
30          else
31               self::$settings =& $core->blog->settings;
32     }
33
34     public static function FreshyStyleSheet($attr) {
35          return "style.css";
36     }
37
38     public static function FreshyLayoutClass($attr) {
39          $p = '<?php '."\n";
40          $p .= 'if (tplFreshy2Theme::$settings->freshy2_sidebar_right != "none")'."\n";
41          $p .= '  echo "sidebar_right ";'."\n";
42          $p .= 'if (tplFreshy2Theme::$settings->freshy2_sidebar_left != "none")'."\n";
43          $p .= '  echo "sidebar_left";'."\n";
44          $p .= '?>'."\n";
45          return $p;
46     }
47
48     public static function FreshyIfHasSidebar($attr,$content) {
49          if (isset($attr['pos'])) 
50               $pos=trim(strtolower($attr['pos']));
51          else
52               $pos="right";
53          if ($pos == 'both') {
54               return '<?php if ((tplFreshy2Theme::$settings->freshy2_sidebar_left != "none") '.
55                    '&& (tplFreshy2Theme::$settings->freshy2_sidebar_right != "none")): ?>'."\n".
56                    $content."\n".
57                    '<?php endif; ?>'."\n";
58          } else {
59               $setting = "freshy2_sidebar_".$pos;
60               return '<?php if (tplFreshy2Theme::$settings->'.$setting.' != "none"): ?>'."\n".
61                    $content."\n".
62                    '<?php endif; ?>'."\n";
63          }
64     }
65     public static function FreshyIfHasSidebarContent($attr,$content) {
66          if (isset($attr['pos'])) 
67               $pos=trim(strtolower($attr['pos']));
68          else
69               $pos="right";
70          $setting = "freshy2_sidebar_".$pos;
71          if (isset($attr['value'])) 
72               $value=trim(strtolower($attr['value']));
73          else
74               $value="nav";
75          return '<?php if (tplFreshy2Theme::$settings->'.$setting.' == "'.$value.'"): ?>'."\n".
76               $content."\n".
77               '<?php endif; ?>'."\n";
78     }
79
80     public static function publicHeadContent($core)
81     {
82          $cust = self::$settings->freshy2_custom;
83          $topimg = self::$settings->freshy2_top_image;
84          $theme_url= self::$settings->themes_url."/".self::$settings->theme;
85
86          $css_content='';
87          if (empty($cust) === false && $cust !== 'default') {
88               $css_content .= '@import url('.
89               $theme_url.'/'.$cust.");\n";
90          }
91          if ($topimg !== null && $topimg !== 'default') {
92               $css_content .= "#header_image {\n".
93                    "background-image:url(".$theme_url.'/images/headers/'.$topimg.");\n".
94                    "}\n";
95          }
96          if ($css_content != "") {
97               echo '<style type="text/css" media="screen">'."\n".
98                    $css_content.
99                    "</style>\n";
100          }
101     }
102}
103$core->tpl->addValue('gravatar', array('gravatar', 'tplGravatar'));
104
105class gravatar {
106
107  const
108    URLBASE = 'http://www.gravatar.com/avatar.php?gravatar_id=%s&amp;default=%s&amp;size=%d',
109    HTMLTAG = '<img src="%s" class="%s" alt="%s" />',
110    DEFAULT_SIZE = '40',
111    DEFAULT_CLASS = 'gravatar_img',
112    DEFAULT_ALT = 'Gravatar de %s';
113
114  public static function tplGravatar($attr)
115  {
116    $md5mail = '\'.md5(strtolower($_ctx->comments->getEmail(false))).\'';
117    $size    = array_key_exists('size',   $attr) ? $attr['size']   : self::DEFAULT_SIZE;
118    $class   = array_key_exists('class',  $attr) ? $attr['class']  : self::DEFAULT_CLASS;
119    $alttxt  = array_key_exists('alt',    $attr) ? $attr['alt']    : self::DEFAULT_ALT;
120    $altimg  = array_key_exists('altimg', $attr) ? $attr['altimg'] : '';
121    $gurl    = sprintf(self::URLBASE,
122                       $md5mail, urlencode($altimg), $size);
123    $gtag    = sprintf(self::HTMLTAG,
124                       $gurl, $class, preg_match("/%s/i", $alttxt) ?
125                                      sprintf($alttxt, '\'.$_ctx->comments->comment_author.\'') : $alttxt);
126    return '<?php echo \'' . $gtag . '\'; ?>';
127  }
128
129}
130
131$core->tpl->addValue('MetaSeparator',array('tplMyMoreTpl','MetaSeparator'));
132$core->tpl->addValue('CatSeparator',array('tplMyMoreTpl','CatSeparator'));
133
134/**
135MetaSeparator
136 
137Cette fonction affiche un séparateur (qui peut être spécifié en paramètre) entre
138les tags d'un billet ou les sous-catégories de la page catégories. Cela permet par
139exemple d'utiliser une virgule comme séparateur de tags et de ne pas avoir une virgule
140superflue qui traîne après le dernier item.
141 
142Paramètre du tag (ou de la sous-catégorie) :
143  - separator : indique le texte à utiliser comme séparateur (valeur par défaut : ', ')
144 
145Exemples d'utilisation :
146 
147Le bloc de code pour les tags :
148  <tpl:EntryMetaData><a href="{{tpl:MetaURL}}">{{tpl:MetaID}}</a>{{tpl:MetaSeparator}}</tpl:EntryMetaData>
149affiche une liste de tous les tags du billet en les séparant simplement par une virgule.
150 
151Le bloc de code pour les sous-catégories (fichier category.html) :
152  <tpl:CategoryFirstChildren>
153     <tpl:CategoriesHeader><p>{{tpl:lang Subcategories}}<span class="item"></tpl:CategoriesHeader><a href="{{tpl:CategoryURL}}">{{tpl:CategoryTitle encode_html="1"}}</a>{{tpl:CatSeparator}}
154     <tpl:CategoriesFooter></span></p></tpl:CategoriesFooter>
155  </tpl:CategoryFirstChildren>
156affiche une liste de toutes les sous-catégories de la catégorie en les séparant simplement par une virgule.
157*/
158
159class tplMyMoreTpl
160{
161  public static function MetaSeparator($attr)
162  {
163     $ret = isset($attr['separator']) ? $attr['separator'] : ', ';
164     $ret = html::escapeHTML($ret);
165     return '<?php if (! $_ctx->meta->isEnd()) { ' . "echo '".addslashes($ret)."'; } ?>";
166  }
167  public static function CatSeparator($attr)
168  {
169     $ret = isset($attr['separator']) ? $attr['separator'] : ', ';
170     $ret = html::escapeHTML($ret);
171     return '<?php if (! $_ctx->categories->isEnd()) { ' . "echo '".addslashes($ret)."'; } ?>";
172  }
173
174}
175
176tplFreshy2Theme::initSettings();
177?>
Note: See TracBrowser for help on using the repository browser.

Sites map