public static function get_clean_structure($default_prop, $value, $closure_defaults = array(), $default_key = '')
 {
     $get_property_value = self::_get_property_value_func();
     $structure = $get_property_value($value, array('if_array' => function ($value) use($default_prop, $default_key) {
         return SmartUtil::set_array_prop_def($default_prop, $value, $default_key);
     }, 'if_closure' => function ($value) use($closure_defaults, $default_prop, $default_key) {
         return SmartUtil::set_closure_prop_def($default_prop, $value, $closure_defaults, $default_key);
     }, 'if_other' => function ($value) use($default_prop, $default_key) {
         $default_prop[$default_key] = $value;
         return $default_prop;
     }));
     return $structure;
 }
Beispiel #2
0
 public static function print_dropdown($items, $options = array(), $return = false)
 {
     $get_property_value = self::_get_property_value_func();
     $items_html = '';
     $main_attrs = array();
     $default_options = array('type' => 'ul', 'attr' => array(), 'class' => '', 'id' => '', 'multilevel' => false);
     $new_options = parent::set_array_prop_def($default_options, $options, 'class');
     foreach ($items as $item) {
         $item_html = '';
         $item_prop = array('content' => '', 'submenu' => array(), 'class' => array(), 'attr' => array());
         $new_item_prop = $get_property_value($item, array('if_array' => function ($item) use($item_prop) {
             return SmartUtil::set_array_prop_def($item_prop, $item, 'content');
         }, 'if_closure' => function ($item) use($item_prop) {
             return SmartUtil::set_closure_prop_def($item_prop, $item);
         }, 'if_other' => function ($item) use($item_prop) {
             $item_prop['content'] = $item;
             return $item_prop;
         }));
         $classes = array();
         if ($new_item_prop['class']) {
             $classes[] = is_array($new_item_prop['class']) ? implode(' ', $new_item_prop['class']) : $new_item_prop['class'];
         }
         $attrs = array();
         if ($new_item_prop['attr']) {
             foreach ($new_item_prop['attr'] as $key => $value) {
                 $attrs[] = $key . '="' . $value . '"';
             }
         }
         $content = $new_item_prop['content'];
         if ($new_item_prop['submenu']) {
             $content .= self::print_dropdown($new_item_prop['submenu'], null, true);
             $classes[] = 'dropdown-submenu';
         } else {
             if ($content === '-') {
                 $classes[] = 'divider';
             } else {
                 if (preg_match("/##(.*)?##/", $content, $header_matches)) {
                     $classes[] = 'dropdown-header';
                     $content = trim($header_matches[1]);
                 }
             }
         }
         $attrs[] = $classes ? ' class="' . trim(implode(' ', $classes)) . '"' : '';
         $item_html = '<li' . ($attrs ? ' ' . implode(' ', $attrs) : '') . '>' . $content . '</li>';
         $items_html .= $item_html;
     }
     $classes = array('dropdown-menu');
     if ($new_options['multilevel']) {
         $classes[] = 'multi-level';
     }
     $main_attrs[] = 'role="menu"';
     if ($new_options['class']) {
         $classes[] = $new_options['class'];
     }
     if ($new_options['attr']) {
         foreach ($new_options['attr'] as $key => $value) {
             $main_attrs[] = $key . '="' . $value . '"';
         }
     }
     if ($new_options['id']) {
         $main_attrs[] = 'id="' . $new_options['id'] . '"';
     }
     $main_attrs[] = 'class="' . implode(' ', $classes) . '"';
     $result = '<ul ' . implode(' ', $main_attrs) . '>';
     $result .= $items_html;
     $result .= '</ul>';
     if ($return) {
         return $result;
     } else {
         echo $result;
     }
 }
 public static function print_dropdown($items, $multi_level = false, $return = false)
 {
     $get_property_value = self::_get_property_value_func();
     $items_html = '';
     foreach ($items as $item) {
         $item_html = '';
         $item_prop = array('content' => '', 'submenu' => array(), 'class' => '');
         $new_item_prop = $get_property_value($item, array('if_array' => function ($item) use($item_prop) {
             return SmartUtil::set_array_prop_def($item_prop, $item, 'content');
         }, 'if_closure' => function ($item) use($item_prop) {
             return SmartUtil::set_closure_prop_def($item_prop, $item);
         }, 'if_other' => function ($item) use($item_prop) {
             $item_prop['content'] = $item;
             return $item_prop;
         }));
         $classes = array();
         if ($new_item_prop['class']) {
             $classes[] = $new_item_prop['class'];
         }
         $content = $new_item_prop['content'];
         if ($new_item_prop['submenu']) {
             $content .= self::print_dropdown($new_item_prop['submenu'], false, true);
             $classes[] = 'dropdown-submenu';
         } else {
             if ($content === '-') {
                 $classes[] = 'divider';
             }
         }
         $class = $classes ? ' class="' . trim(implode(' ', $classes)) . '"' : '';
         $item_html = '<li' . $class . '>' . $content . '</li>';
         $items_html .= $item_html;
     }
     $result = '<ul class="dropdown-menu' . ($multi_level ? ' multi-level' : '') . '" role="menu">';
     $result .= $items_html;
     $result .= '</ul>';
     if ($return) {
         return $result;
     } else {
         echo $result;
     }
 }