public function print_html($return = false) { $get_property_value = parent::_get_property_value_func(); $that = $this; $structure = $this->_structure; $structure->options = parent::set_array_prop_def($this->_options_map, $structure->options); $tabs = $get_property_value($structure->tab, array('if_closure' => function ($tabs) use($that) { return SmartUI::run_callback($tabs, array($that)); }, 'if_other' => function ($tabs) { SmartUI::err('SmartUI::Tab::tab requires array'); return null; })); if (!is_array($tabs)) { parent::err("SmartUI::Tab::tab requires array"); return null; } $li_list = array(); $tab_content_list = array(); $has_active = false; foreach ($tabs as $tab_id => $tab_prop) { $tab_structure = array('content' => isset($structure->content[$tab_id]) ? $structure->content[$tab_id] : '', 'title' => isset($structure->title[$tab_id]) ? $structure->title[$tab_id] : '', 'icon' => isset($structure->icon[$tab_id]) ? $structure->icon[$tab_id] : '', 'dropdown' => isset($structure->dropdown[$tab_id]) ? $structure->dropdown[$tab_id] : '', 'position' => isset($structure->position[$tab_id]) ? $structure->position[$tab_id] : '', 'active' => isset($structure->active[$tab_id]) && $structure->active[$tab_id] === true, 'fade' => false); $new_tab_prop = parent::get_clean_structure($tab_structure, $tab_prop, array($that, $tabs, $tab_id), 'title'); foreach ($new_tab_prop as $tab_prop_key => $tab_prop_vaue) { $new_tab_prop_value = $get_property_value($tab_prop_vaue, array('if_closure' => function ($prop_value) use($that, $tabs) { return SmartUI::run_callback($prop_value, array($that, $tabs)); })); $new_tab_prop[$tab_prop_key] = $new_tab_prop_value; } $tab_content_classes = array(); $tab_content_classes[] = 'tab-pane'; $li_classes = array(); $a_classes = array(); $a_attr = array(); if (!$structure->active && !$has_active || $new_tab_prop['active'] === true && !$has_active) { $li_classes[] = 'active'; $tab_content_classes[] = 'in active'; $has_active = true; } $title = $new_tab_prop['title']; $dropdown_html = ''; if ($new_tab_prop['dropdown']) { $dropdown = $new_tab_prop['dropdown']; $li_classes[] = 'dropdown'; $href = 'javascript:void(0);'; $dropdown_html = is_array($dropdown) ? parent::print_dropdown($dropdown, false, true) : $dropdown; $a_classes[] = 'dropdown-toggle'; $a_attr[] = 'data-toggle="dropdown"'; $title .= ' <b class="caret"></b>'; } else { $href = '#' . $tab_id; $a_attr[] = 'data-toggle="tab"'; } if ($new_tab_prop['position']) { $li_classes[] = 'pull-' . $new_tab_prop['position']; } $icon = $new_tab_prop['icon'] ? '<i class="fa ' . $new_tab_prop['icon'] . '"></i> ' : ''; $class = $li_classes ? ' class="' . implode(' ', $li_classes) . '"' : ''; $li_html = '<li' . $class . '>'; $li_html .= '<a href="' . $href . '" ' . ($a_classes ? 'class="' . implode(' ', $a_classes) . '"' : '') . ($a_attr ? ' ' . implode(' ', $a_attr) : '') . '>' . $icon . $title . '</a>'; $li_html .= $dropdown_html; $li_html .= '</li>'; $li_list[] = $li_html; if ($new_tab_prop['fade']) { $tab_content_classes[] = 'fade'; } $tab_content_html = '<div class="' . implode(' ', $tab_content_classes) . '" id="' . $tab_id . '">'; $tab_content_html .= $new_tab_prop['content']; $tab_content_html .= '</div>'; $tab_content_list[] = $tab_content_html; } $ul_classes = array(); $ul_attr = array(); $ul_classes[] = 'nav nav-tabs'; $ul_id = $structure->tabs_id ? 'id="' . $structure->tabs_id . '"' : ''; $ul_attr[] = $ul_id; $content_classes = array(); $content_classes[] = 'tab-content'; if ($structure->content_class) { $content_classes[] = is_array($structure->content_class) ? implode(' ', $structure->content_class) : $structure->content_class; } $content_id = $structure->content_id ? 'id="' . $structure->content_id . '"' : ''; if ($structure->options['padding']) { $content_classes[] = 'padding-' . $structure->options['padding']; } $content_html = '<div class="' . implode(' ', $content_classes) . '" ' . $content_id . '>'; $content_html .= implode('', $tab_content_list); $content_html .= '</div>'; $main_content_html = ''; if ($structure->options['widget']) { $ul_classes[] = $structure->options['pull'] ? 'pull-' . $structure->options['pull'] : 'pull-left'; $ul_html = '<ul class="' . implode(' ', $ul_classes) . '" ' . implode(' ', $ul_attr) . '>'; $ul_html .= implode('', $li_list); $ul_html .= '</ul>'; $widget = $structure->options['widget']; if (!$widget instanceof Widget) { $ui = new parent(); $widget = $ui->create_widget(); } $widget->body('content', $content_html); $widget->options('colorbutton', false)->options('editbutton', false); $widget->header('title', $ul_html); $result = $widget->print_html(true); } else { if ($structure->options['bordered']) { $ul_classes[] = 'bordered'; } if ($structure->options['pull']) { $ul_classes[] = 'tabs-pull-' . $structure->options['pull']; } $ul_html = '<ul class="' . implode(' ', $ul_classes) . '" ' . implode(' ', $ul_attr) . '>'; $ul_html .= implode('', $li_list); $ul_html .= '</ul>'; $container_classes = array(); $container_classes[] = 'tabbable'; switch ($structure->options['position']) { case 'right': case 'left': $container_classes[] = 'tabs-' . $structure->options['position']; $main_content_html = $ul_html . $content_html; break; case 'below': $container_classes[] = 'tabs-' . $structure->options['position']; $main_content_html = $content_html . $ul_html; break; default: $main_content_html = $ul_html . $content_html; break; } $result = '<div class="' . implode(' ', $container_classes) . '">'; $result .= $main_content_html; $result .= '</div>'; } if ($return) { return $result; } else { echo $result; } }
public function print_html($return = false) { $get_property_value = parent::_get_property_value_func(); $that = $this; $structure = $this->_structure; $icon = $get_property_value($structure->icon, array('if_closure' => function ($icon) use($that) { return SmartUtil::run_callback($icon, array($that)); }, 'if_array' => function ($icon) { SmartUI::err('SmartUI::Widget::icon requires string.'); return ''; })); $container = $get_property_value($structure->container, array('if_closure' => function ($container) use($that) { return SmartUtil::run_callback($container, array($that)); }, 'if_array' => function ($container) { SmartUI::err('SmartUI::Widget::container requires string.'); return ''; })); $content = $get_property_value($structure->content, array('if_closure' => function ($content) use($that) { return SmartUtil::run_callback($content, array($that)); }, 'if_array' => function ($content) { SmartUI::err('SmartUI::Widget::content requires string.'); return ''; })); $attr = $get_property_value($structure->attr, array('if_closure' => function ($attr) use($that) { $callback_return = SmartUtil::run_callback($attr, $array($that)); if (is_array($callback_return)) { return $callback_return; } else { return array($callback_return); } }, 'if_array' => function ($attr) { $attrs = array(); foreach ($attr as $key => $value) { $attrs[] = $key . '="' . $value . '"'; } return $attrs; }, 'if_other' => function ($attr) { return array($attr); })); $class = $get_property_value($structure->class, array("if_closure" => function ($class) use($that) { return SmartUtil::run_callback($class, array($that)); }, "if_array" => function ($class) { return implode(' ', $class); })); $type = $get_property_value($structure->type, array('if_array' => function ($class) { SmartUI::err('SmartUI::Button:type requires string.'); return SmartUI::BUTTON_TYPE_DEFAULT; })); $classes = array(); // labeled and icon if (trim($icon)) { $icon = '<i class="fa ' . $icon . '"></i>'; if ($structure->options['labeled']) { $classes[] = 'btn-labeled'; $icon = $structure->options['labeled'] ? '<span class="btn-label">' . $icon . '</span>' : $icon; } $content = $icon . ' ' . $content; } // custom class if ($class) { $classes[] = $class; } // size $size_class = ''; if ($structure->size) { $size_class = 'btn-' . $structure->size; $classes[] = $size_class; } // disabled $disabled = $structure->options['disabled'] ? 'disabled' : ''; $classes[] = $disabled; $class_htm = $classes ? ' ' . implode(' ', $classes) : ''; $result = ''; if ($structure->dropdown) { $dd_prop = array('items' => array(), 'multilevel' => false, 'split' => false); $new_dd_prop = parent::get_clean_structure($dd_prop, $structure->dropdown, array($this), 'items'); if (is_array($new_dd_prop['items'])) { $dropdown_html = parent::print_dropdown($new_dd_prop['items'], $new_dd_prop['multilevel'], true); } else { $dropdown_html = $new_dd_prop['items']; } if ($new_dd_prop['split']) { $split_prop = array('type' => $type, 'disabled' => false, 'dropup' => false, 'class' => array(), 'attr' => array()); $new_split_prop = parent::get_clean_structure($split_prop, $new_dd_prop['split'], array($this, $new_dd_prop), 'type'); $split_attrs = array(); if (is_array($new_split_prop['attr'])) { foreach ($new_split_prop['attr'] as $split_attr => $value) { $split_attrs[] = $split_attr . '="' . $value . '"'; } } else { $split_attrs[] = $new_split_prop['attr']; } $split_classes = array(); if (is_array($new_split_prop['class'])) { $split_classes[] = implode(' ', $new_split_prop['class']); } else { $split_classes[] = $new_split_prop['class']; } $split_classes[] = $size_class; $split_class_htm = $split_classes ? ' ' . implode(' ', $split_classes) : ''; $btn_main = '<' . $container . ' class="btn btn-' . $type . $class_htm . '" ' . implode(' ', $attr) . '>'; $btn_main .= $content; $btn_main .= '</' . $container . '>'; $btn_dd = '<' . $container . ' class="btn btn-' . $new_split_prop['type'] . $split_class_htm . ' dropdown-toggle" data-toggle="dropdown" ' . implode(' ', $split_attrs) . '>'; $btn_dd .= '<span class="caret"></span>'; $btn_dd .= '</' . $container . '>'; $btn_dd .= $dropdown_html; $result .= '<div class="btn-group' . ($new_split_prop['dropup'] ? ' dropup' : '') . '">' . $btn_main . $btn_dd . '</div>'; } else { $result .= '<div class="dropdown">'; $result .= '<' . $container . ' class="btn btn-' . $type . $class_htm . ' dropdown-toggle" ' . implode(' ', $attr) . ' data-toggle="dropdown">'; $result .= $content . ' <span class="caret"></span>'; $result .= '</' . $container . '>'; $result .= $dropdown_html; $result .= '</div>'; } } else { $result .= '<' . $container . ' class="btn btn-' . $type . $class_htm . '" ' . implode(' ', $attr) . '>'; $result .= $content; $result .= '</' . $container . '>'; } if ($return) { return $result; } else { echo $result; } }