Dotclear

source: plugins/widgets/_public.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 3.6 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14include dirname(__FILE__).'/_default_widgets.php';
15require_once dirname(__FILE__).'/_widgets_functions.php';
16
17$core->tpl->addValue('Widgets',array('publicWidgets','tplWidgets'));
18$core->tpl->addBlock('Widget',array('publicWidgets','tplWidget'));
19
20class publicWidgets
21{
22     public static function tplWidgets($attr)
23     {
[936]24          $type = isset($attr['type']) ? $attr['type'] : '';
25
[0]26          # widgets to disable
27          $disable = isset($attr['disable']) ? trim($attr['disable']) : '';
[2566]28
[936]29          if ($type == '') {
30               $res = "publicWidgets::widgetsHandler('nav','".addslashes($disable)."');"."\n".
31                    "   publicWidgets::widgetsHandler('extra','".addslashes($disable)."');"."\n".
32                    "   publicWidgets::widgetsHandler('custom','".addslashes($disable)."');"."\n";
33          } else {
34               if (!in_array($type, array('nav','extra','custom'))) {
35                    $type = 'nav';
36               }
37               $res = "publicWidgets::widgetsHandler('".addslashes($type)."','".addslashes($disable)."');";
38          }
39          return '<?php '.$res.' ?>';
[0]40     }
[2566]41
[0]42     public static function widgetsHandler($type,$disable='')
43     {
44          $wtype = 'widgets_'.$type;
[671]45          $GLOBALS['core']->blog->settings->addNameSpace('widgets');
[0]46          $widgets = $GLOBALS['core']->blog->settings->widgets->{$wtype};
[2566]47
[0]48          if (!$widgets) { // If widgets value is empty, get defaults
49               $widgets = self::defaultWidgets($type);
50          } else { // Otherwise, load widgets
51               $widgets = dcWidgets::load($widgets);
52          }
[2566]53
[0]54          if ($widgets->isEmpty()) { // Widgets are empty, don't show anything
55               return;
56          }
[2566]57
[0]58          $disable = preg_split('/\s*,\s*/',$disable,-1,PREG_SPLIT_NO_EMPTY);
59          $disable = array_flip($disable);
[2566]60
[0]61          foreach ($widgets->elements() as $k => $w)
62          {
63               if (isset($disable[$w->id()])) {
64                    continue;
65               }
66               echo $w->call($k);
67          }
68     }
[2566]69
[0]70     private static function defaultWidgets($type)
71     {
72          $widgets = new dcWidgets();
73          $w = new dcWidgets();
[2566]74
[0]75          if (isset($GLOBALS['__default_widgets'][$type])) {
76               $w = $GLOBALS['__default_widgets'][$type];
77          }
[2566]78
[0]79          return $w;
80     }
[2566]81
[0]82     public static function tplWidget($attr,$content)
83     {
84          if (!isset($attr['id']) || !($GLOBALS['__widgets']->{$attr['id']} instanceof dcWidget)) {
85               return;
86          }
[2566]87
[0]88          # We change tpl:lang syntax, we need it
89          $content = preg_replace('/\{\{tpl:lang\s+(.*?)\}\}/msu','{tpl:lang $1}',$content);
[2566]90
[0]91          # We remove every {{tpl:
92          $content = preg_replace('/\{\{tpl:.*?\}\}/msu','',$content);
[2566]93
[0]94          return
95          "<?php publicWidgets::widgetHandler('".addslashes($attr['id'])."','".str_replace("'","\\'",$content)."'); ?>";
96     }
[2566]97
[0]98     public static function widgetHandler($id,$xml)
99     {
100          $widgets =& $GLOBALS['__widgets'];
[2566]101
[0]102          if (!($widgets->{$id} instanceof dcWidget)) {
103               return;
104          }
[2566]105
[0]106          $xml = '<?xml version="1.0" encoding="utf-8" ?><widget>'.$xml.'</widget>';
107          $xml = @simplexml_load_string($xml);
108          if (!($xml instanceof SimpleXMLElement)) {
109               echo "Invalid widget XML fragment";
110               return;
111          }
[2566]112
[0]113          $w = clone $widgets->{$id};
[2566]114
[0]115          foreach ($xml->setting as $e)
116          {
117               if (empty($e['name'])) {
118                    continue;
119               }
[2566]120
[0]121               $setting = (string) $e['name'];
122               if (count($e->children())>0) {
123                    $text = preg_replace('#^<setting[^>]*>(.*)</setting>$#msu','\1', (string)$e->asXML());
124               } else {
125                    $text=$e;
126               }
127               $w->{$setting} = preg_replace_callback('/\{tpl:lang (.*?)\}/msu',array('self','widgetL10nHandler'),$text);
128          }
[2566]129
[0]130          echo $w->call(0);
131     }
[2566]132
[0]133     private static function widgetL10nHandler($m)
134     {
135          return __($m[1]);
136     }
137}
Note: See TracBrowser for help on using the repository browser.

Sites map