diff --git a/inc/front/shortcodes.php b/inc/front/shortcodes.php index 5ae8331..3fac834 100644 --- a/inc/front/shortcodes.php +++ b/inc/front/shortcodes.php @@ -5,121 +5,134 @@ add_shortcode('gallery', 'roots_gallery_shortcode'); // cleanup gallery_shortcode() -function roots_gallery_shortcode($attr) { - $post = get_post(); +function roots_gallery_shortcode($attr) +{ + $post = get_post(); + + static $instance = 0; + $instance++; + + if (!empty($attr['ids'])) { + if (empty($attr['orderby'])) { + $attr['orderby'] = 'post__in'; + } + $attr['include'] = $attr['ids']; + } - static $instance = 0; - $instance++; + // Jetpack tiled gallery compatibility + if ($attr['type'] != '') { + if (class_exists('Jetpack_Tiled_Gallery')) { + $gallery = new Jetpack_Tiled_Gallery; + add_filter('post_gallery', array($gallery, 'gallery_shortcode'), 1001, 2); - if (!empty($attr['ids'])) { - if (empty($attr['orderby'])) { - $attr['orderby'] = 'post__in'; + return gallery_shortcode($attr); + } } - $attr['include'] = $attr['ids']; - } - $output = apply_filters('post_gallery', '', $attr); + $output = apply_filters('post_gallery', '', $attr); - if ($output != '') { - return $output; - } + if ($output != '') { + return $output; + } - if (isset($attr['orderby'])) { - $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); - if (!$attr['orderby']) { - unset($attr['orderby']); + if (isset($attr['orderby'])) { + $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); + if (!$attr['orderby']) { + unset($attr['orderby']); + } } - } - - extract(shortcode_atts(array( - 'order' => 'ASC', - 'orderby' => 'menu_order ID', - 'id' => $post->ID, - 'icontag' => 'li', - 'excerpttag' => 'p', - 'captiontag' => 'div', - 'titletag' => 'h5', - 'columns' => 3, - 'size' => 'thumbnail', - 'include' => '', - 'exclude' => '' - ), $attr)); - - $id = intval($id); - - if ($order === 'RAND') { - $orderby = 'none'; - } - - if (!empty($include)) { - $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); - - $attachments = array(); - foreach ($_attachments as $key => $val) { - $attachments[$val->ID] = $_attachments[$key]; + + extract(shortcode_atts(array( + 'order' => 'ASC', + 'orderby' => 'menu_order ID', + 'id' => $post->ID, + 'icontag' => 'li', + 'excerpttag' => 'p', + 'captiontag' => 'div', + 'titletag' => 'h5', + 'columns' => 3, + 'size' => 'thumbnail', + 'include' => '', + 'exclude' => '' + ), $attr)); + + $id = intval($id); + + if ($order === 'RAND') { + $orderby = 'none'; } - } elseif (!empty($exclude)) { - $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); - } else { - $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); - } - - if (empty($attachments)) { - return ''; - } - - if (is_feed()) { - $output = "\n"; - foreach ($attachments as $att_id => $attachment) - $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; - return $output; - } - - $captiontag = tag_escape($captiontag); - $columns = intval($columns); - $itemwidth = $columns > 0 ? floor(100/$columns) : 100; - $float = is_rtl() ? 'right' : 'left'; - - $selector = "gallery-{$instance}"; - - $gallery_style = $gallery_div = ''; - if (apply_filters('use_default_gallery_style', true)) { - $gallery_style = ""; - } - $size_class = sanitize_html_class($size); - $gallery_div = "\n"; + if (is_feed()) { + $output = "\n"; + foreach ($attachments as $att_id => $attachment) + $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; - return $output; + return $output; + } + + $captiontag = tag_escape($captiontag); + $columns = intval($columns); + $itemwidth = $columns > 0 ? floor(100 / $columns) : 100; + $float = is_rtl() ? 'right' : 'left'; + + $selector = "gallery-{$instance}"; + + $gallery_style = $gallery_div = ''; + if (apply_filters('use_default_gallery_style', true)) { + $gallery_style = ""; + } + $size_class = sanitize_html_class($size); + $gallery_div = "\n"; + + return $output; } /* The following shortcodes are from Alien Ship theme by mindctrl https://github.com/mindctrl/alienship @@ -127,36 +140,38 @@ function roots_gallery_shortcode($attr) { /* =Alerts - Types are 'info', 'error', 'success', and unspecified(which displays a default color). Specify a heading text. See example. * Example: [alert type="success" heading="Congrats!"]You won the lottery![/alert] ----------------------------------------------- */ -if ( ! function_exists( 'stormbringer_alert' ) ): -function stormbringer_alert($atts, $content = null) { - extract(shortcode_atts(array('type' => 'alert', 'heading' => ''), $atts)); - if ($type != "alert") { - return '
×'. do_shortcode($heading) .'

' . do_shortcode($content) . '

'; - } else { - return '
×'. do_shortcode($heading) .'' . do_shortcode($content) . '
'; - } -} -add_shortcode('alert', 'stormbringer_alert'); -endif; +if (!function_exists('stormbringer_alert')): + function stormbringer_alert($atts, $content = null) + { + extract(shortcode_atts(array('type' => 'alert', 'heading' => ''), $atts)); + if ($type != "alert") { + return '
×' . do_shortcode($heading) . '

' . do_shortcode($content) . '

'; + } else { + return '
×' . do_shortcode($heading) . '' . do_shortcode($content) . '
'; + } + } + add_shortcode('alert', 'stormbringer_alert'); +endif; /* =Badges ----------------------------------------------- * [badge] shortcode. Options for type are default, success, warning, error, info, and inverse. If a type of not specified, default is used. * Example: [badge type="important"]1[/badge] */ -if ( ! function_exists( 'stormbringer_badge' ) ): -function stormbringer_badge($atts, $content = null) { - extract(shortcode_atts(array('type' => 'badge'), $atts)); - if ($type != "badge") { - return '' . do_shortcode($content) . ''; - } else { - return '' . do_shortcode($content) . ''; - } -} -add_shortcode('badge', 'stormbringer_badge'); -endif; +if (!function_exists('stormbringer_badge')): + function stormbringer_badge($atts, $content = null) + { + extract(shortcode_atts(array('type' => 'badge'), $atts)); + if ($type != "badge") { + return '' . do_shortcode($content) . ''; + } else { + return '' . do_shortcode($content) . ''; + } + } + add_shortcode('badge', 'stormbringer_badge'); +endif; /* =Buttons @@ -164,106 +179,113 @@ function stormbringer_badge($atts, $content = null) { /* [button] shortcode. Options for type= are "primary", "info", "success", "warning", "danger", and "inverse". * Options for size are mini, small, medium and large. If none is specified it defaults to medium size. * Example: [button type="info" size="large" link="http://yourlink.com"]Button Text[/button] */ -if ( ! function_exists( 'stormbringer_button' ) ): -function stormbringer_button($atts, $content = null) { - extract(shortcode_atts(array('link' => '#', 'type' => '', 'size' => 'md'), $atts)); - - if (empty($type)) { - $type = "btn"; - } else { - $type = "btn btn-" . $type; - } - - if ($size == "md") { - $size = ""; - } else { - $size = "btn-" . $size; - } - - return '' . do_shortcode($content) . ''; -} -add_shortcode('button', 'stormbringer_button'); -endif; +if (!function_exists('stormbringer_button')): + function stormbringer_button($atts, $content = null) + { + extract(shortcode_atts(array('link' => '#', 'type' => '', 'size' => 'md'), $atts)); + + if (empty($type)) { + $type = "btn"; + } else { + $type = "btn btn-" . $type; + } + + if ($size == "md") { + $size = ""; + } else { + $size = "btn-" . $size; + } + + return '' . do_shortcode($content) . ''; + } + add_shortcode('button', 'stormbringer_button'); +endif; /* =Labels ----------------------------------------------- * [label] shortcode. Options for type= are "default", important", "info", "success", "warning", and "inverse". If a type of not specified, default is used. * Example: [label type="important"]Label text[/label] */ -if ( ! function_exists( 'stormbringer_label' ) ): -function stormbringer_label($atts, $content = null) { - extract(shortcode_atts(array('type' => 'label'), $atts)); - if ($type != "label") { - return '' . do_shortcode($content) . ''; - } else { - return '' . do_shortcode($content) . ''; - } -} -add_shortcode('label', 'stormbringer_label'); -endif; +if (!function_exists('stormbringer_label')): + function stormbringer_label($atts, $content = null) + { + extract(shortcode_atts(array('type' => 'label'), $atts)); + if ($type != "label") { + return '' . do_shortcode($content) . ''; + } else { + return '' . do_shortcode($content) . ''; + } + } + add_shortcode('label', 'stormbringer_label'); +endif; /* =Panels ----------------------------------------------- * [panel] shortcode. Columns defaults to 6. You can specify columns in the shortcode. * Example: [panel columns="4"]Your panel text here.[/panel] */ -if ( ! function_exists( 'stormbringer_panel' ) ): -function stormbringer_panel( $atts, $content = null ) { - extract(shortcode_atts(array('columns' => '6'), $atts)); - $gridsize = '12'; - $span = '"span'; - if ($columns != "12") { - $span .= ''.$columns.'"'; - $spanfollow = $gridsize - $columns; - return '

' . do_shortcode($content) . '

 
'; } - else { - $span .= ''.$columns.'"'; - return '

' . do_shortcode($content) . '

'; - } -} -add_shortcode('panel', 'stormbringer_panel'); -endif; +if (!function_exists('stormbringer_panel')): + function stormbringer_panel($atts, $content = null) + { + extract(shortcode_atts(array('columns' => '6'), $atts)); + $gridsize = '12'; + $span = '"span'; + if ($columns != "12") { + $span .= '' . $columns . '"'; + $spanfollow = $gridsize - $columns; + + return '

' . do_shortcode($content) . '

 
'; + } else { + $span .= '' . $columns . '"'; + + return '

' . do_shortcode($content) . '

'; + } + } + add_shortcode('panel', 'stormbringer_panel'); +endif; /* =Wells ----------------------------------------------- * [well] shortcode. * Example: [well]Your text here.[/well] */ -if ( ! function_exists( 'stormbringer_well' ) ): -function stormbringer_well($atts, $content = null) { - return '
' . do_shortcode($content) .'
'; -} -add_shortcode('well', 'stormbringer_well'); +if (!function_exists('stormbringer_well')): + function stormbringer_well($atts, $content = null) + { + return '
' . do_shortcode($content) . '
'; + } + + add_shortcode('well', 'stormbringer_well'); endif; // Block Messages -function stormbringer_blockquotes( $atts, $content = null ) { - extract( shortcode_atts( array( - 'float' => '', /* left, right */ - 'cite' => '', /* text for cite */ - ), $atts ) ); - - $output = ''; - - if($cite){ - $output .= '' . $cite . ''; - } - - $output .= ''; - - return $output; +function stormbringer_blockquotes($atts, $content = null) +{ + extract(shortcode_atts(array( + 'float' => '', /* left, right */ + 'cite' => '', /* text for cite */ + ), $atts)); + + $output = ''; + + if ($cite) { + $output .= '' . $cite . ''; + } + + $output .= ''; + + return $output; } add_shortcode('blockquote', 'stormbringer_blockquotes'); - +