| 1 |
<?php |
| 2 |
|
| 3 |
require_once( 'bwtrace.inc' ); |
| 4 |
/* Shortcodes for each of the more useful "often included key-information" fields |
| 5 |
in Bobbing Wide's Wonder of WordPress websites |
| 6 |
*/ |
| 7 |
|
| 8 |
|
| 9 |
/** |
| 10 |
* Safely invoke SlideShow Gallery Pro |
| 11 |
*/ |
| 12 |
function bw_gp_slideshow( $atts, $hmm=NULL, $tag=NULL ) { |
| 13 |
bw_trace( $atts, __FUNCTION__, __LINE__, __FILE__, "atts" ); |
| 14 |
bw_trace( $tag, __FUNCTION__, __LINE__, __FILE__, "tag" ); |
| 15 |
$continue = true; |
| 16 |
|
| 17 |
if ( $continue && ( 'the_content' != current_filter() ) ) { |
| 18 |
$content = '[' . $tag . ']'; |
| 19 |
$continue = FALSE; |
| 20 |
// $content .= ' !?#'; |
| 21 |
} |
| 22 |
|
| 23 |
if ( $continue && !class_exists( "Gallery" ) ) { |
| 24 |
$content = '[' . $tag . '] <b>Slideshow Gallery Pro not activated</b>'; |
| 25 |
$continue = FALSE; |
| 26 |
} |
| 27 |
|
| 28 |
if ( $continue ) { |
| 29 |
$Gallery = new Gallery(); |
| 30 |
$content = $Gallery->embed( $atts ); |
| 31 |
} |
| 32 |
|
| 33 |
bw_trace( $content, __FUNCTION__, __LINE__, __FILE__, "content" ); |
| 34 |
|
| 35 |
return $content; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
/** |
| 40 |
* This is a prototype function used to investigate what's necessary to make shortcode expansion "safe" |
| 41 |
|
| 42 |
An advanced shortcode processor needs to know the context in which |
| 43 |
the shortcode is being expanded. There are times when we don't want to show the |
| 44 |
HTML since this may include information that would cause CSS to |
| 45 |
do some unexpected styling - so that needs to be stripped |
| 46 |
but there are other times when we do want this to happen |
| 47 |
This function is an experimental / exploratory function |
| 48 |
to find out what needs to be done, when, where and how. |
| 49 |
*/ |
| 50 |
function bw_clever( $atts, $hmm=NULL, $tag=NULL ) { |
| 51 |
/* The current_filter function lets us know why the shortcode is being expanded |
| 52 |
but we also need to know the purpose. |
| 53 |
|
| 54 |
e.g. the_title is used in a multitude of places |
| 55 |
when displayed on a post, page or widget we may want the text nicely formatted |
| 56 |
but in a page list we want plain text - with no shortcode expansion OR expanded but not styled |
| 57 |
How do we decide the best approach to this problem? |
| 58 |
|
| 59 |
*/ |
| 60 |
$cf = current_filter(); |
| 61 |
bw_trace( $cf, __FUNCTION__, __LINE__, __FILE__, "current_filter" ); |
| 62 |
|
| 63 |
$admin = is_admin(); |
| 64 |
// as you can see it's incomplete |
| 65 |
return( $tag ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* These are dummy functions to demonstrate my appalling understanding of php's OO implementation |
| 70 |
*/ |
| 71 |
function bw_nobbut() { |
| 72 |
return ""; |
| 73 |
} |
| 74 |
|
| 75 |
function bw_wtf() { |
| 76 |
bw_trace( "wtf", __FUNCTION__, __LINE__, __FILE__, "wtf" ); |
| 77 |
return( "what the f*ck"); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Expand a shortcode if the function is defined for the event |
| 82 |
* |
| 83 |
* If the function is not defined then simply return the tag inside []'s |
| 84 |
* Note: We use the HTML symbol for [ ([) to prevent the shortcode being expanded multiple times |
| 85 |
|
| 86 |
*/ |
| 87 |
function bw_shortcode_event( $atts, $hmm=NULL, $tag=NULL ) { |
| 88 |
global $bw_sc_ev, $bw_sc_ev_pp; |
| 89 |
// bw_backtrace(); |
| 90 |
|
| 91 |
$result = '[' . $tag . ']'; |
| 92 |
$cf = current_filter(); |
| 93 |
if ( empty( $cf ) ) { $cf = 'wp_footer'; } |
| 94 |
|
| 95 |
bw_trace( $cf, __FUNCTION__, __LINE__, __FILE__, "current_filter" ); |
| 96 |
bw_trace( $tag, __FUNCTION__, __LINE__, __FILE__, "tag" ); |
| 97 |
if ( isset( $bw_sc_ev[ $tag ][ $cf ] )) { |
| 98 |
$shortcodefunc = $bw_sc_ev[ $tag ][ $cf ]; |
| 99 |
if ( function_exists( $shortcodefunc ) ) |
| 100 |
$result = $shortcodefunc( $atts, $hmm, $tag ); |
| 101 |
else { |
| 102 |
$result .= "<b>missing function to expand shortcode: $shortcodefunc</b>"; |
| 103 |
} |
| 104 |
} |
| 105 |
bw_trace( $result, __FUNCTION__, __LINE__, __FILE__, "result" ); |
| 106 |
if ( isset( $bw_sc_ev_pp[ $tag ][ $cf ] )) { |
| 107 |
$ppfunc = $bw_sc_ev_pp[ $tag ][ $cf ]; |
| 108 |
if ( function_exists( $ppfunc ) ) { |
| 109 |
$result = $ppfunc( $result, $cf ); |
| 110 |
} |
| 111 |
else { |
| 112 |
$result .= "<b>missing post processing function: $ppfunc</b>"; |
| 113 |
} |
| 114 |
|
| 115 |
bw_trace( $result, __FUNCTION__, __LINE__, __FILE__, "result" ); |
| 116 |
} |
| 117 |
|
| 118 |
return $result; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* bw_strip_tags() is equivalent to esc_attr( strip_tags() ) |
| 123 |
* but it also gets passed the current_filter - future use |
| 124 |
*/ |
| 125 |
function bw_strip_tags( $string, $current_filter=NULL ) { |
| 126 |
$rstring = $string; |
| 127 |
$rstring = strip_tags( $rstring ); |
| 128 |
$rstring = esc_attr( $rstring ); |
| 129 |
return $rstring; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* bw_admin_strip_tags() strips tags if the content is being displayed on an admin page |
| 134 |
* but it also gets passed the current_filter - future use |
| 135 |
*/ |
| 136 |
function bw_admin_strip_tags( $string, $current_filter=NULL ) { |
| 137 |
|
| 138 |
bw_trace( $string, __FUNCTION__, __LINE__, __FILE__, "string" ); |
| 139 |
$rstring = $string; |
| 140 |
if ( is_admin() ) { |
| 141 |
$rstring = bw_strip_tags( $rstring, $current_filter ); |
| 142 |
} |
| 143 |
return $rstring; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
/** |
| 149 |
* Add a shortcode function for a specific set of events |
| 150 |
* |
| 151 |
* This is a wrapper API for add_shortcode() that will affect how shortcodes are expanded during do_shortcode() processing. |
| 152 |
* Instead of calling the shortcode expansion function directly we always invoke bw_shortcode_event() |
| 153 |
* bw_shortcode_event() checks to see if the shortcode should be expanded in the context. |
| 154 |
* The $postprocess parameter is a function name for performing post processing of the $result in certain contexts |
| 155 |
* Possible functions are: |
| 156 |
* bw_strip_tags |
| 157 |
* bw_admin_strip_tags |
| 158 |
* etcetara tbc |
| 159 |
*/ |
| 160 |
function bw_add_shortcode_event( $shortcode, $function=NULL, $eventlist='the_content,widget_text,the_title', $postprocess=NULL ) { |
| 161 |
global $bw_sc_ev, $bw_sc_ev_pp; |
| 162 |
//bw_trace( $shortcode, __FUNCTION__, __LINE__, __FILE__, "shortcode" ); |
| 163 |
|
| 164 |
|
| 165 |
if ( $function == NULL ) { |
| 166 |
$function = $shortcode; |
| 167 |
} |
| 168 |
$events = explode( ",", $eventlist ); |
| 169 |
foreach ( $events as $event ) { |
| 170 |
$bw_sc_ev[ $shortcode][ $event ] = $function; |
| 171 |
if ( $postprocess != NULL ) { |
| 172 |
$bw_sc_ev_pp[ $shortcode][ $event ] = $postprocess; |
| 173 |
} |
| 174 |
} |
| 175 |
// bw_trace( $bw_sc_ev, __FUNCTION__, __LINE__, __FILE__, "bw_sc_ev" ); |
| 176 |
|
| 177 |
add_shortcode( $shortcode, "bw_shortcode_event" ); |
| 178 |
} |
| 179 |
|
| 180 |
/** |
| 181 |
* Add a shortcode that safely expands in admin page titles |
| 182 |
* but is properly expanded in content and widget text |
| 183 |
* Note: settings_page_bw_email_signature is included to allow the shortcodes to be shown on the "oik email signature" page |
| 184 |
* bp_screens is included to support BuddyPress |
| 185 |
* get_the_excerpt is to support Artisteer 3.1 beta 1 |
| 186 |
*/ |
| 187 |
function bw_add_shortcode( $shortcode, $function=NULL ) { |
| 188 |
bw_add_shortcode_event( $shortcode, $function, 'the_content,widget_text,wp_footer,get_the_excerpt,settings_page_bw_email_signature,bp_screens' ); |
| 189 |
bw_add_shortcode_event( $shortcode, $function, 'the_title', 'bw_admin_strip_tags' ); |
| 190 |
} |
| 191 |
|
| 192 |
bw_add_shortcode_event( "bw_wtf"); |
| 193 |
bw_add_shortcode_event( "bw_wtf", NULL, "the_title", "bw_strip_tags" ); |
| 194 |
|
| 195 |
bw_add_shortcode_event( 'bw_ngslideshow', 'NextGEN_shortcodes::show_slideshow', 'the_content,widget_text' ); |
| 196 |
|
| 197 |
bw_add_shortcode_event( 'bw_directions', 'bw_directions', 'the_content,widget_text' ); |
| 198 |
|
| 199 |
bw_add_shortcode( 'bw', 'bw' ); |
| 200 |
//bw_add_shortcode_event( "bw", "bw" ); |
| 201 |
//bw_add_shortcode_event( "bw", "bw", 'the_title', 'bw_admin_strip_tags' ); |
| 202 |
|
| 203 |
bw_add_shortcode_event( 'oik', 'bw_oik' ); |
| 204 |
bw_add_shortcode_event( "oik", "bw_oik", 'the_title', 'bw_admin_strip_tags' ); |
| 205 |
|
| 206 |
|
| 207 |
bw_add_shortcode( 'bw_address', 'bw_address'); |
| 208 |
bw_add_shortcode( 'bw_mailto', 'bw_mailto' ); |
| 209 |
bw_add_shortcode( 'bw_email', 'bw_email' ); |
| 210 |
bw_add_shortcode( 'bw_geo', 'bw_geo' ); |
| 211 |
bw_add_shortcode( 'bw_telephone', 'bw_telephone' ); |
| 212 |
bw_add_shortcode( 'bw_fax', 'bw_fax' ); |
| 213 |
bw_add_shortcode( 'bw_mobile', 'bw_mobile' ); |
| 214 |
bw_add_shortcode( 'bw_wpadmin', 'bw_wpadmin' ); |
| 215 |
bw_add_shortcode( 'bw_show_googlemap', 'bw_show_googlemap'); |
| 216 |
bw_add_shortcode( 'bw_contact', 'bw_contact' ); |
| 217 |
|
| 218 |
bw_add_shortcode( 'bw_twitter', 'bw_twitter' ); |
| 219 |
bw_add_shortcode( 'bw_facebook', 'bw_facebook' ); |
| 220 |
bw_add_shortcode( 'bw_linkedin', 'bw_linkedin' ); |
| 221 |
bw_add_shortcode( 'bw_youtube', 'bw_youtube' ); |
| 222 |
bw_add_shortcode( 'bw_flickr', 'bw_flickr' ); |
| 223 |
bw_add_shortcode( 'bw_picasa', 'bw_picasa' ); |
| 224 |
bw_add_shortcode( 'bw_skype', 'bw_skype' ); |
| 225 |
|
| 226 |
bw_add_shortcode( 'bw_googleplus', 'bw_google_plus' ); |
| 227 |
bw_add_shortcode( 'bw_google_plus', 'bw_google_plus' ); |
| 228 |
bw_add_shortcode( 'bw_google-plus', 'bw_google_plus' ); |
| 229 |
bw_add_shortcode( 'bw_google', 'bw_google_plus' ); |
| 230 |
|
| 231 |
|
| 232 |
bw_add_shortcode( 'bw_company', 'bw_company' ); |
| 233 |
bw_add_shortcode( 'bw_business', 'bw_business' ); |
| 234 |
bw_add_shortcode( 'bw_formal', 'bw_formal' ); |
| 235 |
bw_add_shortcode( 'bw_slogan', 'bw_slogan' ); |
| 236 |
bw_add_shortcode( 'bw_alt_slogan', 'bw_alt_slogan' ); |
| 237 |
bw_add_shortcode( 'bw_admin', 'bw_admin' ); |
| 238 |
bw_add_shortcode( 'bw_domain', 'bw_domain' ); |
| 239 |
|
| 240 |
|
| 241 |
bw_add_shortcode( 'clear', 'bw_clear' ); |
| 242 |
bw_add_shortcode( 'bw_tel', 'bw_tel' ); |
| 243 |
bw_add_shortcode( 'bw_mob', 'bw_mob' ); |
| 244 |
|
| 245 |
|
| 246 |
bw_add_shortcode( 'ngslideshow', 'NextGEN_shortcodes::show_slideshow' ); |
| 247 |
|
| 248 |
//add_shortcode( 'gpslideshow', 'bw_gp_slideshow' ); |
| 249 |
|
| 250 |
bw_add_shortcode( 'gpslides', 'bw_gp_slideshow' ); |
| 251 |
//add_shortcode( 'clever', 'bw_clever' ); |
| 252 |
bw_add_shortcode( 'bw_follow_me', 'bw_follow_me' ); |
| 253 |
|
| 254 |
|
| 255 |
//bw_add_shortcode( 'bw_logo', 'bw_logo' ); |
| 256 |
bw_add_shortcode_event( 'bw_logo', 'bw_logo', 'the_content,widget_text,settings_page_bw_email_signature' ); |
| 257 |
bw_add_shortcode_event( 'bw_qrcode', 'bw_qrcode', 'the_content,widget_text,settings_page_bw_email_signature'); |
| 258 |
|
| 259 |
// Include [div]/[sdiv], [ediv] and [sediv] |
| 260 |
bw_add_shortcode( 'div', 'bw_sdiv' ); |
| 261 |
bw_add_shortcode( 'sdiv', 'bw_sdiv' ); |
| 262 |
bw_add_shortcode( 'ediv', 'bw_ediv' ); |
| 263 |
bw_add_shortcode( 'sediv', 'bw_sediv' ); |
| 264 |
|
| 265 |
bw_add_shortcode( 'bw_emergency', 'bw_emergency' ); |
| 266 |
bw_add_shortcode( 'bw_abbr', 'bw_abbr' ); |
| 267 |
bw_add_shortcode( 'bw_acronym', 'bw_acronym' ); |
| 268 |
|
| 269 |
// bw_backtrace(); |