true, "colorbutton" => true, "editbutton" => true, "togglebutton" => true, "deletebutton" => true, "fullscreenbutton" => true, "custombutton" => true, "collapsed" => false, "sortable" => true, "refreshbutton" => false ); private $_structure = array( "class" => "", "color" => "", "id" => "", "attr" => array(), "options" => array(), "header" => array(), "footer" => "", "footers" => array(), "body" => array() ); public function __construct($options = array(), $contents = array()) { $this->_init_structure($options, $contents); } private function _init_structure($user_options, $user_contents) { $this->_structure = Util::array_to_object($this->_structure); $user_contents_map = array("header" => array(), "body" => "", "color" => ""); $new_user_contents = Util::set_array_prop_def($user_contents_map, $user_contents); $this->_structure->options = Util::set_array_prop_def($this->_options_map, $user_options); $body_structure = array( "editbox" => "", "content" => "", "class" => "", "toolbar" => null, "footer" => null ); $this->_structure->body = Util::set_array_prop_def($body_structure, $new_user_contents["body"], "content"); $header_structure = array( "icon" => null, "class" => "", "title" => "", "toolbar" => array() ); $this->_structure->header = Util::set_array_prop_def($header_structure, $new_user_contents["header"], "title"); $this->_structure->color = $new_user_contents["color"]; $this->_structure->id = Util::create_id(true); } public function __set($name, $value) { if (isset($this->_structure->{$name})) { $this->_structure->{$name} = $value; return; } parent::err('Undefined structure property: '.$name); } public function __call($name, $args) { return parent::_call($this, $this->_structure, $name, $args); } public function __get($name) { if (isset($this->_structure->{$name})) { return $this->_structure->{$name}; } parent::err('Undefined structure property: '.$name); return null; } public function print_html($return = false) { $structure = $this->_structure; $attr = Util::get_property_value( $structure->attr, array( "if_closure" => function($attr) { return Util::run_callback($attr, array($this)); }, //if user passes a closure, pass those optional parameters that they can use "if_other" => function($attr) { return $attr; }, //just directly return the string for this type of structure item "if_array" => function($attr) { $props = array_map(function($attr, $attr_value) { //build attribute values from passed array return $attr.' = "'.$attr_value.'"'; }, array_keys($attr), $attr); return implode(' ', $props); } ) ); $options_map = $this->_options_map; $options = Util::get_property_value( $structure->options, array( "if_closure" => function($options) { return Util::run_callback($options, array($this)); }, "if_other" => function($options) { return $options; }, "if_array" => function($options) use ($options_map) { $props = array_map(function($option, $value) use ($options_map) { if (is_bool($value)) { $str_val = var_export($value, true); if (isset($options_map[$option])) { if ($value !== $options_map[$option]) { return 'data-widget-'.$option.'="'.$str_val.'"'; } else return ''; } else return 'data-widget-'.$option.'="'.$str_val.'"'; } return 'data-widget-'.$option.'="'.$value.'"'; }, array_keys($options), $options); return implode(' ', $props); } ) ); $body = Util::get_property_value( $structure->body, array( "if_closure" => function($body) { return Util::run_callback($body, array($this)); }, "if_other" => function($body) { if ($body === false || is_null($body)) return null; return '
'; }, "if_array" => function($body) { $editbox = ''; if (isset($body["editbox"])) { $editbox = ''; } $content = ''; if (isset($body['content'])) { if (Util::is_closure($body['content'])) { $content = Util::run_callback($body['content'], array($this)); } else { $content = $body['content']; } } $class = 'widget-body'; if (isset($body["class"])) { if (is_array($body["class"])) { $class .= ' '.implode(' ', $body["class"]); } else { $class .= ' '.$body["class"]; } } $toolbar = ''; if (isset($body["toolbar"])) { $toolbar = ''; } $footer = ''; if (isset($body['footer'])) { $footer = ''; } $result = $editbox; $result .= 'SmartUI::Widget->header[content] not defined