| 1 |
<?php |
| 2 |
//Shortcode for accordion |
| 3 |
function kad_accordion_shortcode_function($atts, $content ) { |
| 4 |
extract(shortcode_atts(array( |
| 5 |
'id' => rand(1, 99) |
| 6 |
), $atts)); |
| 7 |
$GLOBALS['pane_count'] = 0; |
| 8 |
$GLOBALS['panes'] = ''; |
| 9 |
do_shortcode( $content ); |
| 10 |
if( is_array( $GLOBALS['panes'] ) ){ |
| 11 |
$i = 0; |
| 12 |
foreach( $GLOBALS['panes'] as $tab ){ |
| 13 |
if ($i % 2 == 0) {$eo = "even";} else {$eo = "odd";} |
| 14 |
$tabs[] = '<div class="panel panel-default panel-'.$eo.'"><div class="panel-heading"><a class="accordion-toggle '.$tab['open'].'" data-toggle="collapse" data-parent="#accordionname'.$id.'" href="#collapse'.$id.$tab['link'].'"><h5><i class="icon-minus primary-color"></i><i class="icon-plus"></i>'.$tab['title'].'</h5></a></div><div id="collapse'.$id.$tab['link'].'" class="panel-collapse collapse '.$tab['in'].'"><div class="panel-body postclass">'.$tab['content'].'</div></div></div>'; |
| 15 |
$i++; |
| 16 |
} |
| 17 |
$return = "\n".'<div class="panel-group" id="accordionname'.$id.'">'.implode( "\n", $tabs ).'</div>'."\n"; |
| 18 |
} |
| 19 |
return $return; |
| 20 |
} |
| 21 |
|
| 22 |
function kad_accordion_pane_function($atts, $content ) { |
| 23 |
extract(shortcode_atts(array( |
| 24 |
'title' => 'Pane %d', |
| 25 |
'start' => '' |
| 26 |
), $atts)); |
| 27 |
if ($start != '') {$open = '';} else {$open = 'collapsed';} |
| 28 |
if ($start != '') {$in = 'in';} else {$in = '';} |
| 29 |
|
| 30 |
$x = $GLOBALS['pane_count']; |
| 31 |
$GLOBALS['panes'][$x] = array( 'title' => $title, 'open' => $open, 'in' => $in, 'link' => $GLOBALS['pane_count'], 'content' => do_shortcode( $content ) ); |
| 32 |
|
| 33 |
$GLOBALS['pane_count']++; |
| 34 |
} |
| 35 |
function kad_tab_shortcode_function($atts, $content ) { |
| 36 |
extract(shortcode_atts(array( |
| 37 |
'id' => rand(1, 99) |
| 38 |
), $atts)); |
| 39 |
|
| 40 |
$GLOBALS['tab_count'] = 0; |
| 41 |
$GLOBALS['tabs'] = ''; |
| 42 |
do_shortcode( $content ); |
| 43 |
if( is_array( $GLOBALS['tabs'] ) ){ |
| 44 |
|
| 45 |
foreach( $GLOBALS['tabs'] as $nav ){ |
| 46 |
$tabnav[] = '<li class="'.$nav['active'].'"><a href="#sctab'.$id.$nav['link'].'">'.$nav['title'].'</a></li>'; |
| 47 |
} |
| 48 |
|
| 49 |
foreach( $GLOBALS['tabs'] as $tab ){ |
| 50 |
$tabs[] = '<div class="tab-pane clearfix '.$tab['active'].'" id="sctab'.$id.$tab['link'].'">'.$tab['content'].'</div>'; |
| 51 |
} |
| 52 |
|
| 53 |
$return = "\n".'<ul class="nav nav-tabs sc_tabs">'.implode( "\n", $tabnav ).'</ul> <div class="tab-content postclass">'.implode( "\n", $tabs ).'</div>'."\n"; |
| 54 |
} |
| 55 |
return $return; |
| 56 |
} |
| 57 |
function kad_tab_pane_function($atts, $content ) { |
| 58 |
extract(shortcode_atts(array( |
| 59 |
'title' => 'Tab %d', |
| 60 |
'start' => '' |
| 61 |
), $atts)); |
| 62 |
if ($start != '') {$active = 'active';} else {$active = '';} |
| 63 |
|
| 64 |
$x = $GLOBALS['tab_count']; |
| 65 |
$GLOBALS['tabs'][$x] = array( 'title' => $title, 'active' => $active, 'link' => $GLOBALS['tab_count'], 'content' => do_shortcode( $content ) ); |
| 66 |
|
| 67 |
$GLOBALS['tab_count']++; |
| 68 |
} |
| 69 |
|
| 70 |
//Shortcode for columns |
| 71 |
function kad_column_shortcode_function( $atts, $content ) { |
| 72 |
return '<div class="row">'.do_shortcode($content).'</div>'; |
| 73 |
} |
| 74 |
function kad_hcolumn_shortcode_function( $atts, $content ) { |
| 75 |
return '<div class="row">'.do_shortcode($content).'</div>'; |
| 76 |
} |
| 77 |
function kad_column11_function( $atts, $content ) { |
| 78 |
return '<div class="col-md-11">'.do_shortcode($content).'</div>'; |
| 79 |
} |
| 80 |
function kad_column10_function( $atts, $content ) { |
| 81 |
return '<div class="col-md-10">'.do_shortcode($content).'</div>'; |
| 82 |
} |
| 83 |
function kad_column9_function( $atts, $content ) { |
| 84 |
return '<div class="col-md-9">'.do_shortcode($content).'</div>'; |
| 85 |
} |
| 86 |
function kad_column8_function( $atts, $content ) { |
| 87 |
return '<div class="col-md-8">'.do_shortcode($content).'</div>'; |
| 88 |
} |
| 89 |
function kad_column7_function( $atts, $content ) { |
| 90 |
return '<div class="col-md-7">'.do_shortcode($content).'</div>'; |
| 91 |
} |
| 92 |
function kad_column6_function( $atts, $content ) { |
| 93 |
return '<div class="col-md-6">'.do_shortcode($content).'</div>'; |
| 94 |
} |
| 95 |
function kad_column5_function( $atts, $content ) { |
| 96 |
return '<div class="col-md-5">'.do_shortcode($content).'</div>'; |
| 97 |
} |
| 98 |
function kad_column4_function( $atts, $content ) { |
| 99 |
return '<div class="col-md-4">'.do_shortcode($content).'</div>'; |
| 100 |
} |
| 101 |
function kad_column3_function( $atts, $content ) { |
| 102 |
return '<div class="col-md-3">'.do_shortcode($content).'</div>'; |
| 103 |
} |
| 104 |
function kad_column2_function( $atts, $content ) { |
| 105 |
return '<div class="col-md-2">'.do_shortcode($content).'</div>'; |
| 106 |
} |
| 107 |
function kad_column1_function( $atts, $content ) { |
| 108 |
return '<div class="col-md-1">'.do_shortcode($content).'</div>'; |
| 109 |
} |
| 110 |
//Shortcode for Icons |
| 111 |
function kad_icon_shortcode_function( $atts) { |
| 112 |
extract(shortcode_atts(array( |
| 113 |
'icon' => '', |
| 114 |
'size' => '', |
| 115 |
'color' => '', |
| 116 |
'float'=> '' |
| 117 |
), $atts)); |
| 118 |
if ($float != '') $output = '<i class="'.$icon.'" style="font-size:'.$size.'; color:'.$color.'; float:'.$float.'; padding:10px;"></i>'; |
| 119 |
else $output = '<i class="'.$icon.'" style="font-size:'.$size.'; color:'.$color.';"></i>'; |
| 120 |
return $output; |
| 121 |
} |
| 122 |
// Video Shortcode |
| 123 |
function kad_video_shortcode_function( $atts, $content) { |
| 124 |
extract(shortcode_atts(array( |
| 125 |
'width' => '', |
| 126 |
), $atts)); |
| 127 |
if($width != '') { $output = '<div style="max-width:'.$width.'px;"><div class="videofit">'.$content.'</div></div>';} |
| 128 |
else { $output = '<div class="videofit">'.$content.'</div>'; } |
| 129 |
return $output; |
| 130 |
} |
| 131 |
// Based on Ultimate Shortcodes youtube and vimeo shortcodes |
| 132 |
function kad_youtube_shortcode_function( $atts, $content) { |
| 133 |
// Prepare data |
| 134 |
$return = array(); |
| 135 |
$params = array(); |
| 136 |
$atts = shortcode_atts(array( |
| 137 |
'url' => false, |
| 138 |
'width' => 600, |
| 139 |
'height' => 400, |
| 140 |
'maxwidth' => '', |
| 141 |
'autoplay' => 'false', |
| 142 |
'controls' => 'true', |
| 143 |
'hidecontrols' => 'false', |
| 144 |
'fs' => 'true', |
| 145 |
'modestbranding' => 'false', |
| 146 |
'theme' => 'dark' |
| 147 |
), $atts, 'kad_youtube' ); |
| 148 |
|
| 149 |
if ( !$atts['url'] ) return '<p class="error">YouTube: ' . __( 'please specify correct url', 'kadencetoolkit' ) . '</p>'; |
| 150 |
$id = ( preg_match( '%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $atts['url'], $match ) ) ? $match[1] : false; |
| 151 |
// Check that url is specified |
| 152 |
if ( !$id ) return '<p class="error">YouTube: ' . __( 'please specify correct url', 'kadencetoolkit' ) . '</p>'; |
| 153 |
// Prepare params |
| 154 |
if($atts['hidecontrols'] == 'true') {$atts['controls'] = 'false';} |
| 155 |
foreach ( array('autoplay', 'controls', 'fs', 'modestbranding', 'theme' ) as $param ) $params[$param] = str_replace( array( 'false', 'true', 'alt' ), array( '0', '1', '2' ), $atts[$param] ); |
| 156 |
// Prepare player parameters |
| 157 |
$params = http_build_query( $params ); |
| 158 |
if($atts['maxwidth']) {$maxwidth = 'style="max-width:'.$atts['maxwidth'].'px;"';} else{ $maxwidth = '';} |
| 159 |
// Create player |
| 160 |
$return[] = '<div class="kad-youtube-shortcode videofit" '.$maxwidth.' >'; |
| 161 |
$return[] = '<iframe width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="//www.youtube.com/embed/' . $id . '?' . $params . '" frameborder="0" allowfullscreen="true"></iframe>'; |
| 162 |
$return[] = '</div>'; |
| 163 |
// Return result |
| 164 |
return implode( '', $return ); |
| 165 |
} |
| 166 |
function kad_vimeo_shortcode_function( $atts, $content) { |
| 167 |
$return = array(); |
| 168 |
$atts = shortcode_atts( array( |
| 169 |
'url' => false, |
| 170 |
'width' => 600, |
| 171 |
'height' => 400, |
| 172 |
'maxwidth' => '', |
| 173 |
'autoplay' => 'no' |
| 174 |
), $atts, 'vimeo' ); |
| 175 |
if ( !$atts['url'] ) return '<p class="error">Vimeo: ' . __( 'please specify correct url', 'kadencetoolkit' ) . '</p>'; |
| 176 |
$id = ( preg_match( '~(?:<iframe [^>]*src=")?(?:https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/videos?)?\/([0-9]+)[^\s]*)"?(?:[^>]*></iframe>)?(?:<p>.*</p>)?~ix', $atts['url'], $match ) ) ? $match[1] : false; |
| 177 |
// Check that url is specified |
| 178 |
if ( !$id ) return '<p class="error">Vimeo: ' . __( 'please specify correct url', 'kadencetoolkit' ) . '</p>'; |
| 179 |
|
| 180 |
if($atts['maxwidth']) {$maxwidth = 'style="max-width:'.$atts['maxwidth'].'px;"';} else{ $maxwidth = '';} |
| 181 |
$autoplay = ( $atts['autoplay'] === 'yes' ) ? '&autoplay=1' : ''; |
| 182 |
// Create player |
| 183 |
$return[] = '<div class="kad-vimeo-shortcode videofit '.$maxwidth.'">'; |
| 184 |
$return[] = '<iframe width="' . $atts['width'] . '" height="' . $atts['height'] . |
| 185 |
'" src="//player.vimeo.com/video/' . $id . '?title=0&byline=0&portrait=0&color=ffffff' . |
| 186 |
$autoplay . '" frameborder="0" allowfullscreen="true"></iframe>'; |
| 187 |
$return[] = '</div>'; |
| 188 |
// Return result |
| 189 |
return implode( '', $return ); |
| 190 |
} |
| 191 |
//Button |
| 192 |
function kad_button_shortcode_function( $atts) { |
| 193 |
extract(shortcode_atts(array( |
| 194 |
'id' => rand(1, 99), |
| 195 |
'bcolor' => '', |
| 196 |
'bhovercolor' => '', |
| 197 |
'thovercolor' => '', |
| 198 |
'link' => '', |
| 199 |
'text' => '', |
| 200 |
'target' => '_self', |
| 201 |
'tcolor' => '', |
| 202 |
), $atts)); |
| 203 |
$output = '<a href="'.$link.'" class="kad-btn kad-btn-primary" id="kadbtn'.$id.'" target="'.$target.'" style="background-color:'.$bcolor.'; color:'.$tcolor.'">'.$text.'</a>'; |
| 204 |
$output .= '<style type="text/css" media="screen">#kadbtn'.$id.':hover {background:'.$bhovercolor.' !important; color:'.$thovercolor.' !important;} </style>'; |
| 205 |
return $output; |
| 206 |
} |
| 207 |
function kad_blockquote_shortcode_function( $atts, $content) { |
| 208 |
extract(shortcode_atts(array( |
| 209 |
'align' => 'center', |
| 210 |
), $atts)); |
| 211 |
switch ($align) |
| 212 |
{ |
| 213 |
case "center": |
| 214 |
$output = '<div class="blockquote-full postclass clearfix">' . do_shortcode($content) . '</div>'; |
| 215 |
break; |
| 216 |
|
| 217 |
case "left": |
| 218 |
$output = '<div class="blockquote-left postclass clearfix">' . do_shortcode($content) . '</div>'; |
| 219 |
break; |
| 220 |
|
| 221 |
case "right": |
| 222 |
$output = '<div class="blockquote-right postclass clearfix">' . do_shortcode($content) . '</div>'; |
| 223 |
break; |
| 224 |
} |
| 225 |
return $output; |
| 226 |
} |
| 227 |
function kad_pullquote_shortcode_function( $atts, $content) { |
| 228 |
extract( shortcode_atts( array( |
| 229 |
'align' => 'center' |
| 230 |
), $atts )); |
| 231 |
|
| 232 |
switch ($align) |
| 233 |
{ |
| 234 |
case "center": |
| 235 |
$output = '<div class="pullquote-center">' . do_shortcode($content) . '</div>'; |
| 236 |
break; |
| 237 |
|
| 238 |
case "right": |
| 239 |
$output = '<div class="pullquote-right">' . do_shortcode($content) . '</div>'; |
| 240 |
break; |
| 241 |
|
| 242 |
case "left": |
| 243 |
$output = '<div class="pullquote-left">' . do_shortcode($content) . '</div>'; |
| 244 |
break; |
| 245 |
} |
| 246 |
|
| 247 |
return $output; |
| 248 |
} |
| 249 |
function kad_hrule_function( ) { |
| 250 |
return '<div class="hrule clearfix"></div>'; |
| 251 |
} |
| 252 |
function kad_hrpadding10_function( ) { |
| 253 |
return '<div class="space_20 clearfix"></div>'; |
| 254 |
} |
| 255 |
function kad_hrpadding20_function( ) { |
| 256 |
return '<div class="space_40 clearfix"></div>'; |
| 257 |
} |
| 258 |
function kad_hrpadding40_function( ) { |
| 259 |
return '<div class="space_80 clearfix"></div>'; |
| 260 |
} |
| 261 |
function kad_clearfix_function( ) { |
| 262 |
return '<div class="clearfix"></div>'; |
| 263 |
} |
| 264 |
function kad_columnhelper_function( ) { |
| 265 |
return ''; |
| 266 |
} |
| 267 |
function virtuetoolkit_register_shortcodes(){ |
| 268 |
add_shortcode('accordion', 'kad_accordion_shortcode_function'); |
| 269 |
add_shortcode('pane', 'kad_accordion_pane_function'); |
| 270 |
add_shortcode('tabs', 'kad_tab_shortcode_function'); |
| 271 |
add_shortcode('tab', 'kad_tab_pane_function'); |
| 272 |
add_shortcode('columns', 'kad_column_shortcode_function'); |
| 273 |
add_shortcode('hcolumns', 'kad_hcolumn_shortcode_function'); |
| 274 |
add_shortcode('span11', 'kad_column11_function'); |
| 275 |
add_shortcode('span10', 'kad_column10_function'); |
| 276 |
add_shortcode('span9', 'kad_column9_function'); |
| 277 |
add_shortcode('span8', 'kad_column8_function'); |
| 278 |
add_shortcode('span7', 'kad_column7_function'); |
| 279 |
add_shortcode('span6', 'kad_column6_function'); |
| 280 |
add_shortcode('span5', 'kad_column5_function'); |
| 281 |
add_shortcode('span4', 'kad_column4_function'); |
| 282 |
add_shortcode('span3', 'kad_column3_function'); |
| 283 |
add_shortcode('span2', 'kad_column2_function'); |
| 284 |
add_shortcode('span1', 'kad_column1_function'); |
| 285 |
add_shortcode('columnhelper', 'kad_columnhelper_function'); |
| 286 |
add_shortcode('icon', 'kad_icon_shortcode_function'); |
| 287 |
add_shortcode('pullquote', 'kad_pullquote_shortcode_function'); |
| 288 |
add_shortcode('blockquote', 'kad_blockquote_shortcode_function'); |
| 289 |
add_shortcode('btn', 'kad_button_shortcode_function'); |
| 290 |
add_shortcode('hr', 'kad_hrule_function'); |
| 291 |
add_shortcode('space_20', 'kad_hrpadding10_function'); |
| 292 |
add_shortcode('space_40', 'kad_hrpadding20_function'); |
| 293 |
add_shortcode('space_80', 'kad_hrpadding40_function'); |
| 294 |
add_shortcode('kad_youtube', 'kad_youtube_shortcode_function'); |
| 295 |
add_shortcode('kad_vimeo', 'kad_vimeo_shortcode_function'); |
| 296 |
add_shortcode('clear', 'kad_clearfix_function'); |
| 297 |
} |
| 298 |
add_action( 'init', 'virtuetoolkit_register_shortcodes'); |
| 299 |
|
| 300 |
|
| 301 |
function virtue_register_button( $buttons ) { |
| 302 |
array_push( $buttons, "|", "kadcolumns" ); |
| 303 |
array_push( $buttons, "|", "kaddivider" ); |
| 304 |
array_push( $buttons, "|", "kadaccordion" ); |
| 305 |
array_push( $buttons, "|", "kadquote" ); |
| 306 |
array_push( $buttons, "|", "kadbtn" ); |
| 307 |
array_push( $buttons, "|", "kadicon" ); |
| 308 |
array_push( $buttons, "|", "kadyoutube" ); |
| 309 |
array_push( $buttons, "|", "kadvimeo" ); |
| 310 |
return $buttons; |
| 311 |
} |
| 312 |
function virtue_add_plugin( $plugin_array ) { |
| 313 |
$plugin_array['kadcolumns'] = VIRTUE_TOOLKIT_URL . '/shortcodes/columns/columns_shortgen.js'; |
| 314 |
$plugin_array['kadicon'] = VIRTUE_TOOLKIT_URL . '/shortcodes/icons/icon_shortgen.js'; |
| 315 |
$plugin_array['kadaccordion'] = VIRTUE_TOOLKIT_URL . '/shortcodes/accordion/accordion_shortgen.js'; |
| 316 |
$plugin_array['kadyoutube'] = VIRTUE_TOOLKIT_URL . '/shortcodes/youtube/youtube_shortgen.js'; |
| 317 |
$plugin_array['kadvimeo'] = VIRTUE_TOOLKIT_URL . '/shortcodes/vimeo/vimeo_shortgen.js'; |
| 318 |
$plugin_array['kadquote'] = VIRTUE_TOOLKIT_URL . '/shortcodes/pullquote/quote_shortgen.js'; |
| 319 |
$plugin_array['kadbtn'] = VIRTUE_TOOLKIT_URL . '/shortcodes/btns/btns_shortgen.js'; |
| 320 |
$plugin_array['kaddivider'] = VIRTUE_TOOLKIT_URL . '/shortcodes/divider/divider_shortgen.js'; |
| 321 |
return $plugin_array; |
| 322 |
} |
| 323 |
function virtue_tinymce_shortcode_button() { |
| 324 |
|
| 325 |
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) { |
| 326 |
return; |
| 327 |
} |
| 328 |
|
| 329 |
if ( get_user_option('rich_editing') == 'true' ) { |
| 330 |
add_filter( 'mce_external_plugins', 'virtue_add_plugin' ); |
| 331 |
add_filter( 'mce_buttons_3', 'virtue_register_button' ); |
| 332 |
} |
| 333 |
|
| 334 |
} |
| 335 |
add_action('init', 'virtue_tinymce_shortcode_button'); |
| 336 |
|
| 337 |
// Clean up Shortcodes |
| 338 |
function kadtool_content_clean_shortcodes($content){ |
| 339 |
$array = array ( |
| 340 |
'<p>[' => '[', |
| 341 |
']</p>' => ']', |
| 342 |
']<br />' => ']' |
| 343 |
); |
| 344 |
$content = strtr($content, $array); |
| 345 |
return $content; |
| 346 |
} |
| 347 |
add_filter('the_content', 'kadtool_content_clean_shortcodes'); |
| 348 |
function kadtool_widget_clean_shortcodes($text){ |
| 349 |
$array = array ( |
| 350 |
'<p>[' => '[', |
| 351 |
']</p>' => ']', |
| 352 |
'<p></p>' => '', |
| 353 |
']<br />' => ']', |
| 354 |
'<br />[' => '[' |
| 355 |
); |
| 356 |
$text = strtr($text, $array); |
| 357 |
return $text; |
| 358 |
} |
| 359 |
add_filter('widget_text', 'kadtool_widget_clean_shortcodes'); |
| 360 |
add_filter('widget_text', 'do_shortcode', 50); |
| 361 |
|