| 1 | <?php
 | 
|---|
| 2 | function widget_block($options)
 | 
|---|
| 3 | {
 | 
|---|
| 4 |         $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
 | 
|---|
| 5 |         $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_block_widget.html' : trim( $options[1] );
 | 
|---|
| 6 |     $selected = array_slice($options,2); // get allowed cats
 | 
|---|
| 7 | 
 | 
|---|
| 8 |         $output = '';
 | 
|---|
| 9 |         foreach($selected as $select){
 | 
|---|
| 10 |                 $ex = explode('::',$select);
 | 
|---|
| 11 |                 $sidebar_id = $ex[0];
 | 
|---|
| 12 |                 $widget_id = $ex[1] ;
 | 
|---|
| 13 |         
 | 
|---|
| 14 |                 ob_start();
 | 
|---|
| 15 |                         render_widget($sidebar_id,$widget_id);
 | 
|---|
| 16 |                         $output .= ob_get_contents();
 | 
|---|
| 17 |                 ob_end_clean(); 
 | 
|---|
| 18 |         }
 | 
|---|
| 19 | //      if (count($selected) > 1)
 | 
|---|
| 20 |                 $block['widget'] = "<ul>\n" . $output . "\n</ul>\n";
 | 
|---|
| 21 | //      else
 | 
|---|
| 22 | //              $block['widget'] = $output;                                                             
 | 
|---|
| 23 |         return $block ; 
 | 
|---|
| 24 | }
 | 
|---|
| 25 | 
 | 
|---|
| 26 | function render_widget($index = 1, $widget_id) {
 | 
|---|
| 27 |         global $wp_registered_sidebars, $wp_registered_widgets;
 | 
|---|
| 28 | 
 | 
|---|
| 29 |         if ( is_int($index) ) {
 | 
|---|
| 30 |                 $index = "sidebar-$index";
 | 
|---|
| 31 |         } else {
 | 
|---|
| 32 |                 $index = sanitize_title($index);
 | 
|---|
| 33 |                 foreach ( (array) $wp_registered_sidebars as $key => $value ) {
 | 
|---|
| 34 |                         if ( sanitize_title($value['name']) == $index ) {
 | 
|---|
| 35 |                                 $index = $key;
 | 
|---|
| 36 |                                 break;
 | 
|---|
| 37 |                         }
 | 
|---|
| 38 |                 }
 | 
|---|
| 39 |         }
 | 
|---|
| 40 | 
 | 
|---|
| 41 |         $sidebars_widgets = wp_get_sidebars_widgets();
 | 
|---|
| 42 |         $registered_sidebars = $wp_registered_sidebars[$index];
 | 
|---|
| 43 |         $key_exists = array_key_exists($index, $sidebars_widgets);
 | 
|---|
| 44 |         $is_array = is_array($sidebars_widgets[$index]);
 | 
|---|
| 45 |         
 | 
|---|
| 46 | 
 | 
|---|
| 47 |         
 | 
|---|
| 48 |         if ( empty($registered_sidebars) || !$key_exists || !$is_array || empty($sidebars_widgets[$index]) )
 | 
|---|
| 49 |                 return false;
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         $sidebar = $wp_registered_sidebars[$index];
 | 
|---|
| 52 | 
 | 
|---|
| 53 |         $did_one = false;
 | 
|---|
| 54 |         foreach ( (array) $sidebars_widgets[$index] as $id ) {
 | 
|---|
| 55 |                 if ($id != $widget_id) continue;
 | 
|---|
| 56 |                 $params = array_merge(
 | 
|---|
| 57 |                         array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
 | 
|---|
| 58 |                         (array) $wp_registered_widgets[$id]['params']
 | 
|---|
| 59 |                 );
 | 
|---|
| 60 | 
 | 
|---|
| 61 |                 // Substitute HTML id and class attributes into before_widget
 | 
|---|
| 62 |                 $classname_ = '';
 | 
|---|
| 63 |                 foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
 | 
|---|
| 64 |                         if ( is_string($cn) )
 | 
|---|
| 65 |                                 $classname_ .= '_' . $cn;
 | 
|---|
| 66 |                         elseif ( is_object($cn) )
 | 
|---|
| 67 |                                 $classname_ .= '_' . get_class($cn);
 | 
|---|
| 68 |                 }
 | 
|---|
| 69 |                 $classname_ = ltrim($classname_, '_');
 | 
|---|
| 70 |                 $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
 | 
|---|
| 71 | 
 | 
|---|
| 72 |                 $params = apply_filters( 'dynamic_sidebar_params', $params );
 | 
|---|
| 73 | 
 | 
|---|
| 74 |                 $callback = $wp_registered_widgets[$id]['callback'];
 | 
|---|
| 75 | 
 | 
|---|
| 76 |                 if ( is_callable($callback) ) {
 | 
|---|
| 77 |                         call_user_func_array($callback, $params);
 | 
|---|
| 78 |                         $did_one = true;
 | 
|---|
| 79 |                 }
 | 
|---|
| 80 |         }
 | 
|---|
| 81 | 
 | 
|---|
| 82 |         return $did_one;
 | 
|---|
| 83 | }
 | 
|---|
| 84 | ?> | 
|---|