| @@ 128-262 (lines=135) @@ | ||
| 125 | return $output; |
|
| 126 | } |
|
| 127 | /*-----------------------------------*/ |
|
| 128 | function shortcodely_do_widget($atts) |
|
| 129 | { |
|
| 130 | global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars; |
|
| 131 | ||
| 132 | /* check if the widget is in the shortcode x sidebar if not , just use generic, |
|
| 133 | if it is in, then get the instance data and use that */ |
|
| 134 | ||
| 135 | if (is_admin()) { |
|
| 136 | return ''; |
|
| 137 | } // eg in case someone decides to apply content filters when apost is saved, and not all widget stuff is there. |
|
| 138 | ||
| 139 | extract( |
|
| 140 | shortcode_atts( |
|
| 141 | array( |
|
| 142 | 'sidebar' => 'Widgets for Shortcodely', //default |
|
| 143 | 'id' => '', |
|
| 144 | 'name' => '', |
|
| 145 | 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */ |
|
| 146 | 'class' => 'shortcodely_widget', /* the widget class is picked up automatically. If we want to add an additional class at the wrap level to try to match a theme, use this */ |
|
| 147 | 'wrap' => '', /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */ |
|
| 148 | 'widget_classes' => '', /* option to disassociate from themes widget styling */ |
|
| 149 | ), $atts |
|
| 150 | ) |
|
| 151 | ); |
|
| 152 | ||
| 153 | if (isset($_wp_sidebars_widgets)) { |
|
| 154 | shortcodely_show_widget_debug('which one', $name, $id, $sidebar); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc |
|
| 155 | } else { |
|
| 156 | $output = '<br />No widgets defined at all in any sidebar!'; |
|
| 157 | ||
| 158 | return $output; |
|
| 159 | } |
|
| 160 | ||
| 161 | /* compatibility check - if the name is not entered, then the first parameter is the name */ |
|
| 162 | if (empty($name) and ! empty($atts[0])) { |
|
| 163 | $name = $atts[0]; |
|
| 164 | } |
|
| 165 | ||
| 166 | /* the widget need not be specified, [do_widget widgetname] is adequate */ |
|
| 167 | if (! empty($name)) { // we have a name |
|
| 168 | $widget = $name; |
|
| 169 | ||
| 170 | foreach ($wp_registered_widgets as $i => $w) {/* get the official internal name or id that the widget was registered with */ |
|
| 171 | if (strtolower($widget) == (strtolower($w ['name']))) { |
|
| 172 | $widget_ids[] = $i; |
|
| 173 | } |
|
| 174 | //if ($debug) {echo '<br /> Check: '.$w['name'];} |
|
| 175 | } |
|
| 176 | ||
| 177 | if (! ($sidebarid = shortcodely_get_sidebar_id($sidebar))) { |
|
| 178 | $sidebarid = $sidebar; /* get the official sidebar id for this widget area - will take the first one */ |
|
| 179 | } |
|
| 180 | } else { /* check for id if we do not have a name */ |
|
| 181 | ||
| 182 | if (! empty($id)) { /* if a specific id has been specified */ |
|
| 183 | foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */ |
|
| 184 | if ($id == $w['id']) { |
|
| 185 | $widget_ids[] = $id; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | //echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); |
|
| 189 | } else { |
|
| 190 | $output = '<br />No valid widget name or id given in shortcode parameters'; |
|
| 191 | ||
| 192 | return $output; |
|
| 193 | } |
|
| 194 | // if we have id, get the sidebar for it |
|
| 195 | $sidebarid = shortcodely_get_widgets_sidebar($id); |
|
| 196 | if (! $sidebarid) { |
|
| 197 | $output = '<br />Widget not in any sidebars<br />'; |
|
| 198 | ||
| 199 | return $output; |
|
| 200 | } |
|
| 201 | } |
|
| 202 | ||
| 203 | if (empty($widget)) { |
|
| 204 | $widget = ''; |
|
| 205 | } |
|
| 206 | if (empty($id)) { |
|
| 207 | $id = ''; |
|
| 208 | } |
|
| 209 | ||
| 210 | if (empty($widget_ids)) { |
|
| 211 | $output = '<br />Error: Your Requested widget "' . $widget . ' ' . $id . '" is not in the widget list.<br />'; |
|
| 212 | $output .= shortcodely_show_widget_debug('empty', $name, $id, $sidebar); |
|
| 213 | ||
| 214 | return $output; |
|
| 215 | } |
|
| 216 | ||
| 217 | if (empty($widget)) { |
|
| 218 | $widget = ''; |
|
| 219 | } |
|
| 220 | ||
| 221 | //$content = ''; |
|
| 222 | /* if the widget is in our chosen sidebar, then use the options stored for that */ |
|
| 223 | ||
| 224 | if ((! isset($_wp_sidebars_widgets[$sidebarid])) or (empty($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade |
|
| 225 | shortcodely_upgrade_sidebar(); |
|
| 226 | } |
|
| 227 | ||
| 228 | //if we have a specific sidebar selected, use that |
|
| 229 | if ((isset($_wp_sidebars_widgets[$sidebarid])) and (! empty($_wp_sidebars_widgets[$sidebarid]))) { |
|
| 230 | /* get the intersect of the 2 widget setups so we just get the widget we want */ |
|
| 231 | ||
| 232 | $wid = array_intersect($_wp_sidebars_widgets[$sidebarid], $widget_ids); |
|
| 233 | } else { /* the sidebar is not defined or selected - should not happen */ |
|
| 234 | if (isset($debug)) { // only do this in debug mode |
|
| 235 | if (! isset($_wp_sidebars_widgets[$sidebarid])) { |
|
| 236 | $output = '<p>Error: Sidebar "' . $sidebar . '" with sidebarid "' . $sidebarid . '" is not defined.</p>'; |
|
| 237 | } // shouldnt happen - maybe someone running content filters on save |
|
| 238 | else { |
|
| 239 | $output = '<p>Error: Sidebar "' . $sidebar . '" with sidebarid "' . $sidebarid . '" is empty (no widgets)</p>'; |
|
| 240 | } |
|
| 241 | } |
|
| 242 | } |
|
| 243 | ||
| 244 | $output = ''; |
|
| 245 | if (empty($wid) or (! is_array($wid)) or (count($wid) < 1)) { |
|
| 246 | $output = '<p>Error: Your requested Widget "' . $widget . '" is not in the "' . $sidebar . '" sidebar</p>'; |
|
| 247 | $output .= shortcodely_show_widget_debug('empty', $name, $id, $sidebar); |
|
| 248 | ||
| 249 | unset($sidebar); |
|
| 250 | unset($sidebarid); |
|
| 251 | } else { |
|
| 252 | /* There may only be one but if we have two in our chosen widget then it will do both */ |
|
| 253 | $output = ''; |
|
| 254 | foreach ($wid as $i => $widget_instance) { |
|
| 255 | ob_start(); /* catch the echo output, so we can control where it appears in the text */ |
|
| 256 | shortcodely_shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap, $widget_classes); |
|
| 257 | $output .= ob_get_clean(); |
|
| 258 | } |
|
| 259 | } |
|
| 260 | ||
| 261 | return $output; |
|
| 262 | } |
|
| 263 | /* -------------------------------------------------------------------------*/ |
|
| 264 | function shortcodely_shortcode_sidebar($widget_id, |
|
| 265 | $name = 'widgets_for_shortcode', |
|
| @@ 128-262 (lines=135) @@ | ||
| 125 | return $output; |
|
| 126 | } |
|
| 127 | /*-----------------------------------*/ |
|
| 128 | function shortcodely_do_widget($atts) |
|
| 129 | { |
|
| 130 | global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars; |
|
| 131 | ||
| 132 | /* check if the widget is in the shortcode x sidebar if not , just use generic, |
|
| 133 | if it is in, then get the instance data and use that */ |
|
| 134 | ||
| 135 | if (is_admin()) { |
|
| 136 | return ''; |
|
| 137 | } // eg in case someone decides to apply content filters when apost is saved, and not all widget stuff is there. |
|
| 138 | ||
| 139 | extract( |
|
| 140 | shortcode_atts( |
|
| 141 | array( |
|
| 142 | 'sidebar' => 'Widgets for Shortcodely', //default |
|
| 143 | 'id' => '', |
|
| 144 | 'name' => '', |
|
| 145 | 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */ |
|
| 146 | 'class' => 'shortcodely_widget', /* the widget class is picked up automatically. If we want to add an additional class at the wrap level to try to match a theme, use this */ |
|
| 147 | 'wrap' => '', /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */ |
|
| 148 | 'widget_classes' => '', /* option to disassociate from themes widget styling */ |
|
| 149 | ), $atts |
|
| 150 | ) |
|
| 151 | ); |
|
| 152 | ||
| 153 | if (isset($_wp_sidebars_widgets)) { |
|
| 154 | shortcodely_show_widget_debug('which one', $name, $id, $sidebar); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc |
|
| 155 | } else { |
|
| 156 | $output = '<br />No widgets defined at all in any sidebar!'; |
|
| 157 | ||
| 158 | return $output; |
|
| 159 | } |
|
| 160 | ||
| 161 | /* compatibility check - if the name is not entered, then the first parameter is the name */ |
|
| 162 | if (empty($name) and ! empty($atts[0])) { |
|
| 163 | $name = $atts[0]; |
|
| 164 | } |
|
| 165 | ||
| 166 | /* the widget need not be specified, [do_widget widgetname] is adequate */ |
|
| 167 | if (! empty($name)) { // we have a name |
|
| 168 | $widget = $name; |
|
| 169 | ||
| 170 | foreach ($wp_registered_widgets as $i => $w) {/* get the official internal name or id that the widget was registered with */ |
|
| 171 | if (strtolower($widget) == (strtolower($w ['name']))) { |
|
| 172 | $widget_ids[] = $i; |
|
| 173 | } |
|
| 174 | //if ($debug) {echo '<br /> Check: '.$w['name'];} |
|
| 175 | } |
|
| 176 | ||
| 177 | if (! ($sidebarid = shortcodely_get_sidebar_id($sidebar))) { |
|
| 178 | $sidebarid = $sidebar; /* get the official sidebar id for this widget area - will take the first one */ |
|
| 179 | } |
|
| 180 | } else { /* check for id if we do not have a name */ |
|
| 181 | ||
| 182 | if (! empty($id)) { /* if a specific id has been specified */ |
|
| 183 | foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */ |
|
| 184 | if ($id == $w['id']) { |
|
| 185 | $widget_ids[] = $id; |
|
| 186 | } |
|
| 187 | } |
|
| 188 | //echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); |
|
| 189 | } else { |
|
| 190 | $output = '<br />No valid widget name or id given in shortcode parameters'; |
|
| 191 | ||
| 192 | return $output; |
|
| 193 | } |
|
| 194 | // if we have id, get the sidebar for it |
|
| 195 | $sidebarid = shortcodely_get_widgets_sidebar($id); |
|
| 196 | if (! $sidebarid) { |
|
| 197 | $output = '<br />Widget not in any sidebars<br />'; |
|
| 198 | ||
| 199 | return $output; |
|
| 200 | } |
|
| 201 | } |
|
| 202 | ||
| 203 | if (empty($widget)) { |
|
| 204 | $widget = ''; |
|
| 205 | } |
|
| 206 | if (empty($id)) { |
|
| 207 | $id = ''; |
|
| 208 | } |
|
| 209 | ||
| 210 | if (empty($widget_ids)) { |
|
| 211 | $output = '<br />Error: Your Requested widget "' . $widget . ' ' . $id . '" is not in the widget list.<br />'; |
|
| 212 | $output .= shortcodely_show_widget_debug('empty', $name, $id, $sidebar); |
|
| 213 | ||
| 214 | return $output; |
|
| 215 | } |
|
| 216 | ||
| 217 | if (empty($widget)) { |
|
| 218 | $widget = ''; |
|
| 219 | } |
|
| 220 | ||
| 221 | //$content = ''; |
|
| 222 | /* if the widget is in our chosen sidebar, then use the options stored for that */ |
|
| 223 | ||
| 224 | if ((! isset($_wp_sidebars_widgets[$sidebarid])) or (empty($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade |
|
| 225 | shortcodely_upgrade_sidebar(); |
|
| 226 | } |
|
| 227 | ||
| 228 | //if we have a specific sidebar selected, use that |
|
| 229 | if ((isset($_wp_sidebars_widgets[$sidebarid])) and (! empty($_wp_sidebars_widgets[$sidebarid]))) { |
|
| 230 | /* get the intersect of the 2 widget setups so we just get the widget we want */ |
|
| 231 | ||
| 232 | $wid = array_intersect($_wp_sidebars_widgets[$sidebarid], $widget_ids); |
|
| 233 | } else { /* the sidebar is not defined or selected - should not happen */ |
|
| 234 | if (isset($debug)) { // only do this in debug mode |
|
| 235 | if (! isset($_wp_sidebars_widgets[$sidebarid])) { |
|
| 236 | $output = '<p>Error: Sidebar "' . $sidebar . '" with sidebarid "' . $sidebarid . '" is not defined.</p>'; |
|
| 237 | } // shouldnt happen - maybe someone running content filters on save |
|
| 238 | else { |
|
| 239 | $output = '<p>Error: Sidebar "' . $sidebar . '" with sidebarid "' . $sidebarid . '" is empty (no widgets)</p>'; |
|
| 240 | } |
|
| 241 | } |
|
| 242 | } |
|
| 243 | ||
| 244 | $output = ''; |
|
| 245 | if (empty($wid) or (! is_array($wid)) or (count($wid) < 1)) { |
|
| 246 | $output = '<p>Error: Your requested Widget "' . $widget . '" is not in the "' . $sidebar . '" sidebar</p>'; |
|
| 247 | $output .= shortcodely_show_widget_debug('empty', $name, $id, $sidebar); |
|
| 248 | ||
| 249 | unset($sidebar); |
|
| 250 | unset($sidebarid); |
|
| 251 | } else { |
|
| 252 | /* There may only be one but if we have two in our chosen widget then it will do both */ |
|
| 253 | $output = ''; |
|
| 254 | foreach ($wid as $i => $widget_instance) { |
|
| 255 | ob_start(); /* catch the echo output, so we can control where it appears in the text */ |
|
| 256 | shortcodely_shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap, $widget_classes); |
|
| 257 | $output .= ob_get_clean(); |
|
| 258 | } |
|
| 259 | } |
|
| 260 | ||
| 261 | return $output; |
|
| 262 | } |
|
| 263 | /* -------------------------------------------------------------------------*/ |
|
| 264 | function shortcodely_shortcode_sidebar($widget_id, |
|
| 265 | $name = 'widgets_for_shortcode', |
|