Dotclear


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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