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