__widgets as $pos => $w) { $serialized[] = ($w->serialize($pos)); } return base64_encode(serialize($serialized)); } public function create($id, $name, $callback, $append_callback = null, $desc = '') { $this->__widgets[$id] = new dcWidget($id, $name, $callback, $desc); $this->__widgets[$id]->append_callback = $append_callback; } public function append($widget) { if ($widget instanceof dcWidget) { if (is_callable($widget->append_callback)) { call_user_func($widget->append_callback, $widget); } $this->__widgets[] = $widget; } } public function isEmpty() { return count($this->__widgets) == 0; } public function elements($sorted = false) { if ($sorted) { uasort($this->__widgets, array('self', 'sort')); } return $this->__widgets; } public function __get($id) { if (!isset($this->__widgets[$id])) { return; } return $this->__widgets[$id]; } public function __wakeup() { foreach ($this->__widgets as $i => $w) { if (!($w instanceof dcWidget)) { unset($this->__widgets[$i]); } } } public static function loadArray($A, $widgets) { if (!($widgets instanceof self)) { return false; } uasort($A, array('self', 'arraySort')); $result = new self; foreach ($A as $v) { if ($widgets->{$v['id']} != null) { $w = clone $widgets->{$v['id']}; # Settings unset($v['id']); unset($v['order']); foreach ($v as $sid => $s) { $w->{$sid} = $s; } $result->append($w); } } return $result; } private static function arraySort($a, $b) { if ($a['order'] == $b['order']) { return 0; } return $a['order'] > $b['order'] ? 1 : -1; } private static function sort($a, $b) { $c = dcUtils::removeDiacritics(mb_strtolower($a->name())); $d = dcUtils::removeDiacritics(mb_strtolower($b->name())); if ($c == $d) { return 0; } return ($c < $d) ? -1 : 1; } } class dcWidget { private $id; private $name; private $desc; private $public_callback = null; public $append_callback = null; private $settings = array(); public function serialize($order) { $values = array(); foreach ($this->settings as $k => $v) { $values[$k] = $v['value']; } $values['id'] = $this->id; $values['order'] = $order; return $values; } public function __construct($id, $name, $callback, $desc = '') { $this->public_callback = $callback; $this->id = $id; $this->name = $name; $this->desc = $desc; } public function id() { return $this->id; } public function name() { return $this->name; } public function desc() { return $this->desc; } public function getCallback() { return $this->public_callback; } public function call($i = 0) { if (is_callable($this->public_callback)) { return call_user_func($this->public_callback, $this, $i); } return '
Callback not found for widget ' . $this->id . '
'; } /* Widget rendering tool --------------------------------------------------- */ public function renderDiv($content_only, $class, $attr, $content) { if ($content_only) { return $content; } $ret = ' ' . "\n"; return $ret; } public function renderTitle($title) { global $core; if (!$title) { return ''; } $wtscheme = $core->themes->moduleInfo($core->blog->settings->system->theme, 'widgettitleformat'); if (empty($wtscheme)) { $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme, 'tplset'); if (empty($tplset) || $tplset == DC_DEFAULT_TPLSET) { // Use H2 for mustek based themes $wtscheme = '' . form::field(array($iname, $wfid), 20, 255, html::escapeHTML($s['value']), 'maximal') . '
'; break; case 'textarea': $res .= '' . form::textarea(array($iname, $wfid), 30, 8, html::escapeHTML($s['value']), 'maximal') . '
'; break; case 'check': $res .= '' . form::hidden(array($iname), '0') . '
'; break; case 'radio': $res .= '' . ($s['title'] ? '
' : '');
if (!empty($s['options'])) {
foreach ($s['options'] as $k => $v) {
$res .= $k > 0 ? '
' : '';
$res .=
'';
}
}
$res .= '
' . form::combo(array($iname, $wfid), $s['options'], $s['value']) . '
'; break; } return $res; } }