Changeset 2566:9bf417837888 for plugins/widgets
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- Location:
- plugins/widgets
- Files:
-
- 8 edited
-
_admin.php (modified) (1 diff)
-
_default_widgets.php (modified) (1 diff)
-
_define.php (modified) (1 diff)
-
_install.php (modified) (1 diff)
-
_public.php (modified) (10 diffs)
-
class.widgets.php (modified) (23 diffs)
-
dragdrop.js (modified) (6 diffs)
-
style.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
plugins/widgets/_admin.php
r2230 r2566 27 27 preg_match('/plugin.php\?p=widgets(&.*)?$/',$_SERVER['REQUEST_URI']), 28 28 $core->auth->check('admin',$core->blog->id)); 29 ?> -
plugins/widgets/_default_widgets.php
r2412 r2566 123 123 # --BEHAVIOR-- initDefaultWidgets 124 124 $core->callBehavior('initDefaultWidgets',$__widgets,$__default_widgets); 125 ?> -
plugins/widgets/_define.php
r2257 r2566 23 23 ) 24 24 ); 25 ?> -
plugins/widgets/_install.php
r1179 r2566 38 38 $core->setVersion('widgets',$version); 39 39 return true; 40 ?> -
plugins/widgets/_public.php
r1179 r2566 26 26 # widgets to disable 27 27 $disable = isset($attr['disable']) ? trim($attr['disable']) : ''; 28 28 29 29 if ($type == '') { 30 30 $res = "publicWidgets::widgetsHandler('nav','".addslashes($disable)."');"."\n". … … 39 39 return '<?php '.$res.' ?>'; 40 40 } 41 41 42 42 public static function widgetsHandler($type,$disable='') 43 43 { … … 45 45 $GLOBALS['core']->blog->settings->addNameSpace('widgets'); 46 46 $widgets = $GLOBALS['core']->blog->settings->widgets->{$wtype}; 47 47 48 48 if (!$widgets) { // If widgets value is empty, get defaults 49 49 $widgets = self::defaultWidgets($type); … … 51 51 $widgets = dcWidgets::load($widgets); 52 52 } 53 53 54 54 if ($widgets->isEmpty()) { // Widgets are empty, don't show anything 55 55 return; 56 56 } 57 57 58 58 $disable = preg_split('/\s*,\s*/',$disable,-1,PREG_SPLIT_NO_EMPTY); 59 59 $disable = array_flip($disable); 60 60 61 61 foreach ($widgets->elements() as $k => $w) 62 62 { … … 67 67 } 68 68 } 69 69 70 70 private static function defaultWidgets($type) 71 71 { 72 72 $widgets = new dcWidgets(); 73 73 $w = new dcWidgets(); 74 74 75 75 if (isset($GLOBALS['__default_widgets'][$type])) { 76 76 $w = $GLOBALS['__default_widgets'][$type]; 77 77 } 78 78 79 79 return $w; 80 80 } 81 81 82 82 public static function tplWidget($attr,$content) 83 83 { … … 85 85 return; 86 86 } 87 87 88 88 # We change tpl:lang syntax, we need it 89 89 $content = preg_replace('/\{\{tpl:lang\s+(.*?)\}\}/msu','{tpl:lang $1}',$content); 90 90 91 91 # We remove every {{tpl: 92 92 $content = preg_replace('/\{\{tpl:.*?\}\}/msu','',$content); 93 93 94 94 return 95 95 "<?php publicWidgets::widgetHandler('".addslashes($attr['id'])."','".str_replace("'","\\'",$content)."'); ?>"; 96 96 } 97 97 98 98 public static function widgetHandler($id,$xml) 99 99 { 100 100 $widgets =& $GLOBALS['__widgets']; 101 101 102 102 if (!($widgets->{$id} instanceof dcWidget)) { 103 103 return; 104 104 } 105 105 106 106 $xml = '<?xml version="1.0" encoding="utf-8" ?><widget>'.$xml.'</widget>'; 107 107 $xml = @simplexml_load_string($xml); … … 110 110 return; 111 111 } 112 112 113 113 $w = clone $widgets->{$id}; 114 114 115 115 foreach ($xml->setting as $e) 116 116 { … … 118 118 continue; 119 119 } 120 120 121 121 $setting = (string) $e['name']; 122 122 if (count($e->children())>0) { … … 127 127 $w->{$setting} = preg_replace_callback('/\{tpl:lang (.*?)\}/msu',array('self','widgetL10nHandler'),$text); 128 128 } 129 129 130 130 echo $w->call(0); 131 131 } 132 132 133 133 private static function widgetL10nHandler($m) 134 134 { … … 136 136 } 137 137 } 138 ?> -
plugins/widgets/class.widgets.php
r2442 r2566 15 15 { 16 16 private $__widgets = array(); 17 17 18 18 public static function load($s) 19 19 { 20 20 $o = @unserialize(base64_decode($s)); 21 21 22 22 if ($o instanceof self) { 23 23 return $o; … … 26 26 } 27 27 } 28 28 29 29 public function store() 30 30 { … … 35 35 return base64_encode(serialize($serialized)); 36 36 } 37 37 38 38 public function create($id,$name,$callback,$append_callback=null,$desc='') 39 39 { … … 41 41 $this->__widgets[$id]->append_callback = $append_callback; 42 42 } 43 43 44 44 public function append($widget) 45 45 { … … 51 51 } 52 52 } 53 53 54 54 public function isEmpty() 55 55 { 56 56 return count($this->__widgets) == 0; 57 57 } 58 58 59 59 public function elements($sorted=false) 60 60 { … … 64 64 return $this->__widgets; 65 65 } 66 66 67 67 public function __get($id) 68 68 { … … 72 72 return $this->__widgets[$id]; 73 73 } 74 74 75 75 public function __wakeup() 76 76 { … … 82 82 } 83 83 } 84 84 85 85 public static function loadArray($A,$widgets) 86 86 { … … 88 88 return false; 89 89 } 90 90 91 91 uasort($A,array('self','arraySort')); 92 92 93 93 $result = new self; 94 94 foreach ($A as $v) … … 97 97 { 98 98 $w = clone $widgets->{$v['id']}; 99 99 100 100 # Settings 101 101 unset($v['id']); … … 104 104 $w->{$sid} = $s; 105 105 } 106 106 107 107 $result->append($w); 108 108 } 109 109 } 110 110 111 111 return $result; 112 112 } 113 113 114 114 private static function arraySort($a, $b) 115 115 { … … 119 119 return $a['order'] > $b['order'] ? 1 : -1; 120 120 } 121 121 122 122 private static function sort($a,$b) 123 123 { 124 $c = $a->name(); 125 $d = $b->name(); 126 if ($c == $d) { 127 return 0; 128 } 129 return ($c < $d) ? -1 : 1; 124 $c = $a->name(); 125 $d = $b->name(); 126 if ($c == $d) { 127 return 0; 128 } 129 return ($c < $d) ? -1 : 1; 130 130 } 131 131 } … … 139 139 public $append_callback = null; 140 140 private $settings = array(); 141 141 142 142 public function serialize($order) { 143 143 $values = array(); … … 148 148 return $values; 149 149 } 150 150 151 151 public function __construct($id,$name,$callback,$desc='') 152 152 { … … 156 156 $this->desc = $desc; 157 157 } 158 158 159 159 public function id() 160 160 { 161 161 return $this->id; 162 162 } 163 163 164 164 public function name() 165 165 { … … 171 171 return $this->desc; 172 172 } 173 173 174 174 public function getCallback() 175 175 { 176 176 return $this->public_callback; 177 177 } 178 178 179 179 public function call($i=0) 180 180 { … … 184 184 return '<p>Callback not found for widget '.$this->id.'</p>'; 185 185 } 186 186 187 187 /* Widget settings 188 188 --------------------------------------------------- */ … … 194 194 return null; 195 195 } 196 196 197 197 public function __set($n,$v) 198 198 { … … 201 201 } 202 202 } 203 203 204 204 public function setting($name,$title,$value,$type='text') 205 205 { … … 210 210 } 211 211 } 212 212 213 213 $this->settings[$name] = array( 214 214 'title' => $title, … … 216 216 'value' => $value 217 217 ); 218 218 219 219 if (isset($options)) { 220 220 $this->settings[$name]['options'] = $options; 221 221 } 222 222 } 223 223 224 224 public function settings() 225 225 { 226 226 return $this->settings; 227 227 } 228 228 229 229 public function formSettings($pr='',&$i=0) 230 230 { … … 235 235 $i++; 236 236 } 237 237 238 238 return $res; 239 239 } 240 240 241 241 public function formSetting($id,$s,$pr='',&$i=0) 242 242 { … … 288 288 } 289 289 } 290 ?> -
plugins/widgets/dragdrop.js
r2401 r2566 13 13 14 14 $(function() { 15 15 16 16 // clean 17 17 $('.remove-if-drag').remove(); 18 18 $('.hidden-if-drag').hide(); 19 19 $('.widgets, .sortable-delete').addClass('if-drag'); 20 20 21 21 // move 22 22 $( ".connected, .sortable-delete" ).sortable({ … … 34 34 }, 35 35 update: function(event, ui) { 36 36 37 37 ul = $(this); 38 38 widget = ui.item; 39 39 field = ul.parents('.widgets'); 40 40 41 41 // met a zéro le décalage 42 42 ui.item.css('left', 'auto'); 43 43 44 44 // signale les zones vides 45 45 if( ul.find('li:not(.empty-widgets)').length == 0 ) { … … 50 50 field.find('ul.sortable-delete').show(); 51 51 } 52 52 53 53 // remove 54 54 if( widget.parents('ul').is('.sortable-delete') ) { … … 57 57 }); 58 58 } 59 59 60 60 // réordonne 61 61 reorder(ul); 62 62 63 63 // expand 64 64 if(widget.find('img.expand').length == 0) { … … 66 66 dotclear.viewPostContent(widget, 'close'); 67 67 } 68 68 69 69 } 70 70 }); 71 71 72 72 // add 73 73 $( "#widgets-ref > li" ).draggable({ … … 81 81 } 82 82 }); 83 83 84 84 $("li.ui-draggable, ul.ui-sortable li") 85 85 .not('ul.sortable-delete li, li.empty-widgets') -
plugins/widgets/style.css
r2442 r2566 120 120 width: 49%; 121 121 background: #eee; 122 padding: 1.5em 1% 0; 122 padding: 1.5em 1% 0; 123 123 margin: 0 1% 0 0; 124 124 }
Note: See TracChangeset
for help on using the changeset viewer.
