Dotclear

source: themes/freshy2/_public.php @ 1851

Revision 1851, 6.1 KB checked in by bruno, 14 years ago (diff)

Added pos="both" attribute for <tpl:Freshy2IfHasSidebar>, cf.  http://forum.dotclear.net/viewtopic.php?id=40786

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 function FreshyStyleSheet($attr) {
25          return "style.css";
26     }
27
28     public static function FreshyLayoutClass($attr) {
29          $p = '<?php '."\n";
30          $p .= 'if ($core->blog->settings->freshy2_sidebar_right != "none")'."\n";
31          $p .= '  echo "sidebar_right ";'."\n";
32          $p .= 'if ($core->blog->settings->freshy2_sidebar_left != "none")'."\n";
33          $p .= '  echo "sidebar_left";'."\n";
34          $p .= '?>'."\n";
35          return $p;
36     }
37
38     public static function FreshyIfHasSidebar($attr,$content) {
39          if (isset($attr['pos'])) 
40               $pos=trim(strtolower($attr['pos']));
41          else
42               $pos="right";
43          if ($pos == 'both') {
44               return '<?php if (($core->blog->settings->freshy2_sidebar_left != "none") '.
45                    '&& ($core->blog->settings->freshy2_sidebar_right != "none")): ?>'."\n".
46                    $content."\n".
47                    '<?php endif; ?>'."\n";
48          } else {
49               $setting = "freshy2_sidebar_".$pos;
50               return '<?php if ($core->blog->settings->'.$setting.' != "none"): ?>'."\n".
51                    $content."\n".
52                    '<?php endif; ?>'."\n";
53          }
54     }
55     public static function FreshyIfHasSidebarContent($attr,$content) {
56          if (isset($attr['pos'])) 
57               $pos=trim(strtolower($attr['pos']));
58          else
59               $pos="right";
60          $setting = "freshy2_sidebar_".$pos;
61          if (isset($attr['value'])) 
62               $value=trim(strtolower($attr['value']));
63          else
64               $value="nav";
65          return '<?php if ($core->blog->settings->'.$setting.' == "'.$value.'"): ?>'."\n".
66               $content."\n".
67               '<?php endif; ?>'."\n";
68     }
69
70     public static function publicHeadContent($core)
71     {
72          $cust = $core->blog->settings->freshy2_custom;
73          $topimg = $core->blog->settings->freshy2_top_image;
74          $theme_url=$core->blog->settings->themes_url."/".$core->blog->settings->theme;
75
76          $css_content='';
77          if (empty($cust) === false && $cust !== 'default') {
78               $css_content .= '@import url('.
79               $theme_url.'/'.$cust.");\n";
80          }
81          if ($topimg !== null && $topimg !== 'default') {
82               $css_content .= "#header_image {\n".
83                    "background-image:url(".$theme_url.'/images/headers/'.$topimg.");\n".
84                    "}\n";
85          }
86          if ($css_content != "") {
87               echo '<style type="text/css" media="screen">'."\n".
88                    $css_content.
89                    "</style>\n";
90          }
91     }
92}
93$core->tpl->addValue('gravatar', array('gravatar', 'tplGravatar'));
94
95class gravatar {
96
97  const
98    URLBASE = 'http://www.gravatar.com/avatar.php?gravatar_id=%s&amp;default=%s&amp;size=%d',
99    HTMLTAG = '<img src="%s" class="%s" alt="%s" />',
100    DEFAULT_SIZE = '40',
101    DEFAULT_CLASS = 'gravatar_img',
102    DEFAULT_ALT = 'Gravatar de %s';
103
104  public static function tplGravatar($attr)
105  {
106    $md5mail = '\'.md5(strtolower($_ctx->comments->getEmail(false))).\'';
107    $size    = array_key_exists('size',   $attr) ? $attr['size']   : self::DEFAULT_SIZE;
108    $class   = array_key_exists('class',  $attr) ? $attr['class']  : self::DEFAULT_CLASS;
109    $alttxt  = array_key_exists('alt',    $attr) ? $attr['alt']    : self::DEFAULT_ALT;
110    $altimg  = array_key_exists('altimg', $attr) ? $attr['altimg'] : '';
111    $gurl    = sprintf(self::URLBASE,
112                       $md5mail, urlencode($altimg), $size);
113    $gtag    = sprintf(self::HTMLTAG,
114                       $gurl, $class, preg_match("/%s/i", $alttxt) ?
115                                      sprintf($alttxt, '\'.$_ctx->comments->comment_author.\'') : $alttxt);
116    return '<?php echo \'' . $gtag . '\'; ?>';
117  }
118
119}
120
121$core->tpl->addValue('MetaSeparator',array('tplMyMoreTpl','MetaSeparator'));
122$core->tpl->addValue('CatSeparator',array('tplMyMoreTpl','CatSeparator'));
123
124/**
125MetaSeparator
126 
127Cette fonction affiche un séparateur (qui peut être spécifié en paramètre) entre
128les tags d'un billet ou les sous-catégories de la page catégories. Cela permet par
129exemple d'utiliser une virgule comme séparateur de tags et de ne pas avoir une virgule
130superflue qui traîne après le dernier item.
131 
132Paramètre du tag (ou de la sous-catégorie) :
133  - separator : indique le texte à utiliser comme séparateur (valeur par défaut : ', ')
134 
135Exemples d'utilisation :
136 
137Le bloc de code pour les tags :
138  <tpl:EntryMetaData><a href="{{tpl:MetaURL}}">{{tpl:MetaID}}</a>{{tpl:MetaSeparator}}</tpl:EntryMetaData>
139affiche une liste de tous les tags du billet en les séparant simplement par une virgule.
140 
141Le bloc de code pour les sous-catégories (fichier category.html) :
142  <tpl:CategoryFirstChildren>
143     <tpl:CategoriesHeader><p>{{tpl:lang Subcategories}}<span class="item"></tpl:CategoriesHeader><a href="{{tpl:CategoryURL}}">{{tpl:CategoryTitle encode_html="1"}}</a>{{tpl:CatSeparator}}
144     <tpl:CategoriesFooter></span></p></tpl:CategoriesFooter>
145  </tpl:CategoryFirstChildren>
146affiche une liste de toutes les sous-catégories de la catégorie en les séparant simplement par une virgule.
147*/
148
149class tplMyMoreTpl
150{
151  public static function MetaSeparator($attr)
152  {
153     $ret = isset($attr['separator']) ? $attr['separator'] : ', ';
154     $ret = html::escapeHTML($ret);
155     return '<?php if (! $_ctx->meta->isEnd()) { ' . "echo '".addslashes($ret)."'; } ?>";
156  }
157  public static function CatSeparator($attr)
158  {
159     $ret = isset($attr['separator']) ? $attr['separator'] : ', ';
160     $ret = html::escapeHTML($ret);
161     return '<?php if (! $_ctx->categories->isEnd()) { ' . "echo '".addslashes($ret)."'; } ?>";
162  }
163
164}
165?>
Note: See TracBrowser for help on using the repository browser.

Sites map