Dotclear

Changeset 2772:df84ff8c6261


Ignore:
Timestamp:
11/10/14 12:00:56 (11 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add tpl:IfWidgets template block -> return true if at least one widget will be displayed

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inc/public/default-templates/currywurst/_footer.html

    r2670 r2772  
    22 
    33<div class="footer" id="footer" role="contentinfo"> 
    4      <div class="widgets footer__widgets" id="blogcustom"> 
    5         <h2 class="blogcustom__title">{{tpl:lang Blog info}}</h2> 
    6           {{tpl:Widgets type="custom"}} 
    7      </div> <!-- End #custom widgets --> 
     4     <tpl:IfWidgets type="custom"> 
     5          <div class="widgets footer__widgets" id="blogcustom"> 
     6             <h2 class="blogcustom__title">{{tpl:lang Blog info}}</h2> 
     7               {{tpl:Widgets type="custom"}} 
     8          </div> <!-- End #custom widgets --> 
     9     </tpl:IfWidgets> 
    810 
    911     {{tpl:SysBehavior behavior="publicInsideFooter"}} 
  • inc/public/default-templates/currywurst/_sidebar.html

    r2670 r2772  
    11<div class="sidebar" id="sidebar" role="complementary"> 
    2      <div class="widgets blognav__widgets" id="blognav"> 
    3         <h2 class="blognav__title">{{tpl:lang Blog menu}}</h2> 
    4           {{tpl:Widgets type="nav"}} 
    5      </div> <!-- End #blognav --> 
    6      <div class="widgets blogextra__widgets" id="blogextra"> 
    7         <h2 class="blogextra__title">{{tpl:lang Extra menu}}</h2> 
    8           {{tpl:Widgets type="extra"}} 
    9      </div> <!-- End #blogextra --> 
     2     <tpl:IfWidgets type="nav"> 
     3          <div class="widgets blognav__widgets" id="blognav"> 
     4             <h2 class="blognav__title">{{tpl:lang Blog menu}}</h2> 
     5               {{tpl:Widgets type="nav"}} 
     6          </div> <!-- End #blognav --> 
     7     </tpl:IfWidgets> 
     8     <tpl:IfWidgets type="extra"> 
     9          <div class="widgets blogextra__widgets" id="blogextra"> 
     10             <h2 class="blogextra__title">{{tpl:lang Extra menu}}</h2> 
     11               {{tpl:Widgets type="extra"}} 
     12          </div> <!-- End #blogextra --> 
     13     </tpl:IfWidgets> 
    1014</div> 
  • plugins/widgets/_public.php

    r2566 r2772  
    1717$core->tpl->addValue('Widgets',array('publicWidgets','tplWidgets')); 
    1818$core->tpl->addBlock('Widget',array('publicWidgets','tplWidget')); 
     19$core->tpl->addBlock('IfWidgets',array('publicWidgets','tplIfWidgets')); 
    1920 
    2021class publicWidgets 
     
    6667               echo $w->call($k); 
    6768          } 
     69     } 
     70 
     71     public static function tplIfWidgets($attr,$content) 
     72     { 
     73          $type = isset($attr['type']) ? $attr['type'] : ''; 
     74 
     75          # widgets to disable 
     76          $disable = isset($attr['disable']) ? trim($attr['disable']) : ''; 
     77 
     78          if ($type == '') { 
     79               $res = "publicWidgets::ifWidgetsHandler('nav','".addslashes($disable)."') &&"."\n". 
     80                    "   publicWidgets::ifWidgetsHandler('extra','".addslashes($disable)."') &&"."\n". 
     81                    "   publicWidgets::ifWidgetsHandler('custom','".addslashes($disable)."')"."\n"; 
     82          } else { 
     83               if (!in_array($type, array('nav','extra','custom'))) { 
     84                    $type = 'nav'; 
     85               } 
     86               $res = "publicWidgets::ifWidgetsHandler('".addslashes($type)."','".addslashes($disable)."')"; 
     87          } 
     88          return '<?php if('.$res.') : ?>'.$content.'<?php endif; ?>'; 
     89     } 
     90 
     91     public static function ifWidgetsHandler($type,$disable='') 
     92     { 
     93          $wtype = 'widgets_'.$type; 
     94          $GLOBALS['core']->blog->settings->addNameSpace('widgets'); 
     95          $widgets = $GLOBALS['core']->blog->settings->widgets->{$wtype}; 
     96 
     97          if (!$widgets) { // If widgets value is empty, get defaults 
     98               $widgets = self::defaultWidgets($type); 
     99          } else { // Otherwise, load widgets 
     100               $widgets = dcWidgets::load($widgets); 
     101          } 
     102 
     103          return (!$widgets->isEmpty()); 
    68104     } 
    69105 
Note: See TracChangeset for help on using the changeset viewer.

Sites map