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