示例#1
0
/**
 * Add an option to gallery images with no links
 */
function new_gallery_shortcode($attr)
{
    global $post, $wp_locale;
    $output = gallery_shortcode($attr);
    if ($attr['link'] == "none") {
        $output = preg_replace(array('/<a[^>]*>/', '/<\\/a>/'), '', $output);
    }
    return $output;
}
示例#2
0
function fotorama_gallery_shortcode($atts)
{
    if (!$atts) {
        $atts = array();
    }
    if (array_key_exists('fotorama', $atts) && $atts['fotorama'] == 'false') {
        return gallery_shortcode($atts);
    }
    $atts['link'] = 'file';
    $atts['itemtag'] = 'dl';
    $atts['icontag'] = 'dt';
    $atts['captiontag'] = 'dd';
    $atts['columns'] = 0;
    if (array_key_exists('orderby', $atts) && $atts['orderby'] == 'rand') {
        $atts['orderby'] = '';
        $atts['shuffle'] = 'true';
    }
    $atts['size'] = 'thumbnail';
    $gallery = gallery_shortcode($atts);
    $width = array_key_exists('width', $atts) ? $atts['width'] : '';
    $height = array_key_exists('height', $atts) ? $atts['height'] : '';
    $atts['size'] = 'large';
    preg_match_all('/(<img[^<>]*>).*\\n*.*<\\/dt/', gallery_shortcode($atts), $images);
    preg_match_all('/href=(\'|")([^"\']+)(\'|").*\\n*.*<\\/dt/', $gallery, $hrefs);
    for ($i = 0, $l = count($images[0]); $i < $l; $i++) {
        $image = $images[1][$i];
        preg_match('/src=(\'|")([^"\']+)(\'|")/', $image, $src);
        if (!$i) {
            preg_match('/width=(\'|")([^"\']+)(\'|")/', $image, $__width);
            $_width = $__width[2];
            preg_match('/height=(\'|")([^"\']+)(\'|")/', $image, $__height);
            $_height = $__height[2];
            if (!$width) {
                $atts['width'] = $_width;
            }
            if (!$height) {
                $height = $_height;
            }
        }
        $quote = $hrefs[1][$i];
        $full = $hrefs[2][$i];
        $gallery = str_replace($quote . $full . $quote, $quote . $src[2] . $quote . ' data-full=' . $quote . $full . $quote, $gallery);
    }
    $atts['auto'] = 'false';
    $atts['max-width'] = '100%';
    $atts['ratio'] = array_key_exists('ratio', $atts) ? $atts['ratio'] : ($_width && $_height ? $_width / $_height : '');
    $data = '';
    foreach ($atts as $key => $value) {
        if ($key != 'fotorama') {
            $data .= "data-{$key}='{$value}'";
        }
    }
    return "<div class='fotorama--wp' {$data}>{$gallery}</div>";
}
/**
 * Output a formatted WordPress image gallery of related attachments on
 * attachment image pages.
 *
 * @since  1.0.0
 * @access public
 * @return string
 */
function carelib_get_attachment_image_gallery()
{
    if (!wp_attachment_is_image()) {
        return false;
    }
    $parent = get_queried_object()->post_parent;
    if (empty($parent)) {
        return false;
    }
    $gallery = gallery_shortcode(array('columns' => 4, 'numberposts' => 8, 'orderby' => 'rand', 'id' => $parent, 'exclude' => get_the_ID()));
    if (empty($gallery)) {
        return false;
    }
    $markup = '<div class="image-gallery"><h3 class="attachment-meta-title">%s</h3>%s</div>';
    $title = esc_attr__('Related Images', 'carelib');
    $output = sprintf($markup, $title, $gallery);
    return apply_filters("{$GLOBALS['carelib_prefix']}_attachment_image_gallery", $output, $markup, $title, $gallery);
}
function bootstrat_carousel_gallery_shortcode($attr)
{
    /* Validate for necessary data */
    if (isset($attr['ids']) and isset($attr['type']) and $attr['type'] == 'carousel') {
        /* Define data by given attributes. */
        $attr['ids'] = $attr['ids'];
        $attr['name'] = isset($attr['name']) ? sanitize_title($attr['name']) : 'bootstrap-carousel';
        /* Any name. String will be sanitize to be used as HTML ID. Recomended when you want to have more than one carousel in the same page. Default: bootstrap-carousel. */
        $attr['width'] = isset($attr['width']) ? $attr['width'] : '';
        /* Carousel container width, in px or % */
        $attr['height'] = isset($attr['height']) ? $attr['height'] : '';
        /* Carousel item height, in px or % */
        $attr['indicators'] = isset($attr['indicators']) ? $attr['indicators'] : 'before-inner';
        /* Accepted values: before-inner, after-inner, after-control, false. Default: before-inner. */
        $attr['control'] = isset($attr['control']) ? $attr['control'] : 'true';
        /* Accepted values: true, false. Default: true. */
        $attr['interval'] = isset($attr['interval']) ? $attr['interval'] : 5000;
        /* The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle. */
        $attr['pause'] = isset($attr['pause']) ? $attr['pause'] : 'hover';
        /* Pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. */
        $attr['titletag'] = isset($attr['titletag']) ? $attr['titletag'] : 'h4';
        /* Define tag for image title. Default: h4. */
        $attr['title'] = isset($attr['title']) ? $attr['title'] : 'true';
        /* Show or hide image title. Set false to hide. Default: true. */
        $attr['text'] = isset($attr['text']) ? $attr['text'] : 'true';
        /* Show or hide image text. Set false to hide. Default: true. */
        $attr['wpautop'] = isset($attr['wpautop']) ? $attr['wpautop'] : 'true';
        /* Auto-format text. Default: true. */
        $attr['containerclass'] = isset($attr['containerclass']) ? $attr['containerclass'] : '';
        /* Extra class for container. */
        $attr['itemclass'] = isset($attr['itemclass']) ? $attr['itemclass'] : '';
        /* Extra class for item. */
        $attr['captionclass'] = isset($attr['captionclass']) ? $attr['captionclass'] : '';
        /* Extra class for caption. */
        /* Obtain HTML. */
        $output = bootstrat_carousel_get_html_from($attr);
        /* If attributes could not be validated, execute default gallery shortcode function */
    } else {
        $output = gallery_shortcode($attr);
    }
    return $output;
}
/**
 * Gallery Shortcode Function
 * @param array $attrs Shortcode Attributes
 * @return none
 */
function twentytwentyproton($attrs)
{
    //fallback to previous gallery shortcode
    if ($attrs["link"] != "twentytwentyproton") {
        return gallery_shortcode($attrs);
    }
    //check if image ids are set
    if (!empty($attrs["ids"])) {
        //explode ids and make sure there are exactly two
        $ids = explode(",", $attrs["ids"]);
        if (count($ids) == 2) {
            //get images info
            $images = array(wp_get_attachment_image_src($ids[0], $attrs["size"]), wp_get_attachment_image_src($ids[1], $attrs["size"]));
            //generate unique id for dom elements
            $uniqid = uniqid();
            //initialize markup and javascript
            $content = "\r\n\t\t\t\t<script type='text/javascript'>\r\n\t\t\t\t\twindow.addEventListener('load',function(){\r\n\t\t\t\t\t\tjQuery('#" . $uniqid . "').show().twentytwentyproton({\r\n\t\t\t\t\t\t\tparticle:'" . plugin_dir_url(__FILE__) . "twentytwenty-proton/img/particle.png',\r\n\t\t\t\t\t\t\tfullscreen:false\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t</script>\r\n\t\t\t\t<div id='" . $uniqid . "' style='display:none; width:" . max($images[0][1], $images[1][1]) . "px;'>\r\n\t\t\t\t\t<img src='" . $images[0][0] . "' width='" . $images[0][1] . "' height='" . $images[0][2] . "' />\r\n\t\t\t\t\t<img src='" . $images[1][0] . "' width='" . $images[1][1] . "' height='" . $images[1][2] . "' />\r\n\t\t\t\t</div>\r\n\t\t\t";
        }
    }
    return $content;
}
示例#6
0
 public function gallery_shortcode($attr)
 {
     $attr = wp_parse_args($attr, array('itemtag' => 'li', 'icontag' => 'div', 'captiontag' => 'div', 'lightbox' => true));
     $open_in_lightbox = $attr['lightbox'] !== 'false';
     if ($open_in_lightbox) {
         $attr['link'] = 'file';
     }
     $html = gallery_shortcode($attr);
     $html = preg_replace('/<br[^>]*>/i', '', $html);
     $open_tag_found = preg_match('/^\\s*(<div[^>]*>)/i', $html, $open_matches);
     $close_tag_found = preg_match('/(<\\/div>)\\s*$/i', $html);
     // replace first opening and last closing tag
     if ($open_tag_found && $close_tag_found) {
         $open_div = $open_matches[1];
         $new_open_div = str_replace('div', 'figure', $open_div) . '<ol>';
         $html = str_replace($open_div, $new_open_div, $html);
         $html = preg_replace('/<\\/div>\\s*$/', '</ol></figure>', $html);
         $lightbox_group_id = rand();
         if ($open_in_lightbox) {
             $html = str_replace('<a', '<a data-g1-lightbox="gallery-' . $lightbox_group_id . '"', $html);
         }
     }
     return $html;
 }
示例#7
0
/**
 * Output a formatted WordPress image gallery of related attachments on
 * attachment image pages.
 *
 * @since  1.0.0
 * @access public
 * @return void
 */
function alpha_attachment_image_gallery()
{
    if (!wp_attachment_is_image()) {
        return;
    }
    $parent = get_queried_object()->post_parent;
    if (empty($parent)) {
        return;
    }
    $gallery = gallery_shortcode(array('columns' => 4, 'numberposts' => 8, 'orderby' => 'rand', 'id' => $parent, 'exclude' => get_the_ID()));
    if (empty($gallery)) {
        return;
    }
    $markup = '<div class="image-gallery"><h3 class="attachment-meta-title">%s</h3>%s</div>';
    $title = esc_attr__('Related Images', 'alpha');
    echo apply_filters('alpha_attachment_image_gallery', sprintf($markup, $title, $gallery), $markup, $title, $gallery);
}
示例#8
0
 function widget($args, $instance)
 {
     if (!is_singular()) {
         return;
     }
     //only run on single post/page/custom post_type pages
     $post = get_post();
     if (is_null($post)) {
         return;
     }
     //we have a post to work with
     $gargs = array('columns' => 1, 'link' => 'file', 'orderby' => 'rand', 'size' => $instance['size']);
     if ($instance['hide_featured'] && ($featured_image = get_post_thumbnail_id($post->ID))) {
         $gargs['exclude'] = $featured_image;
     }
     $gallery = gallery_shortcode($gargs);
     if (empty($gallery)) {
         return;
     }
     //no gallery so do not display an empty widget
     $args = $this->override_args($args, $instance);
     extract($args);
     echo $before_widget;
     echo $gallery;
     echo $after_widget;
     self::limit_images($post->ID, $instance['posts_per_page'], $instance['lightbox']);
 }
示例#9
0
		<div class="media-info image-info">

			<h3 class="attachment-meta-title"><?php 
    _e('Image Info', 'saga');
    ?>
</h3>

			<?php 
    hybrid_media_meta();
    ?>

		</div><!-- .media-info -->

		<?php 
    $gallery = gallery_shortcode(array('columns' => 4, 'numberposts' => 8, 'orderby' => 'rand', 'id' => get_queried_object()->post_parent, 'exclude' => get_the_ID()));
    ?>

		<?php 
    if (!empty($gallery)) {
        // Check if the gallery is not empty.
        ?>

			<div class="image-gallery">
				<h3 class="attachment-meta-title"><?php 
        _e('Gallery', 'saga');
        ?>
</h3>
				<?php 
        echo $gallery;
        ?>
function gdlr_gallery_shortcode($atts)
{
    if (!empty($atts['masterslider']) && $atts['masterslider'] == "true") {
        return gallery_shortcode($atts);
    }
    extract(shortcode_atts(array('columns' => '3', 'ids' => '', 'link' => 'post', 'type' => 'grid', 'caption' => 'yes', 'caption_position' => 'left', 'thumbnail_size' => 'thumbnail', 'size' => ''), $atts));
    $settings = array();
    $settings['show-caption'] = $caption;
    if (!empty($size)) {
        $settings['thumbnail-size'] = $size;
    } else {
        $settings['thumbnail-size'] = $thumbnail_size;
    }
    $settings['gallery-columns'] = $columns;
    $slides = array();
    $ids = explode(',', $ids);
    foreach ($ids as $slide_id) {
        $data = array();
        if ($link == 'file') {
            $data['slide-link'] = 'current';
        } else {
            if ($link == 'post') {
                $data['new-tab'] = 'disable';
                $data['slide-link'] = 'url';
                $data['url'] = get_permalink($slide_id);
            }
        }
        if ($type == 'slider' && $caption == 'yes') {
            $attachment = gdlr_get_attachment_info($slide_id);
            $data['title'] = $attachment['title'];
            $data['caption'] = $attachment['caption'];
            $data['caption-position'] = $caption_position;
        }
        $slides[$slide_id] = $data;
    }
    if (function_exists('gdlr_get_slider_item') && $type == 'slider') {
        $settings['slider-type'] = 'flexslider';
        return gdlr_get_flex_slider($slides, array('size' => $thumbnail_size));
    } else {
        if (function_exists('gdlr_get_gallery_thumbnail') && $type == 'thumbnail') {
            $settings['slider'] = $slides;
            return '<div class="gdlr-shortcode-wrapper">' . gdlr_get_gallery_thumbnail($settings) . '</div>';
        } else {
            if (function_exists('gdlr_get_gallery')) {
                $settings['slider'] = $slides;
                return '<div class="gdlr-shortcode-wrapper">' . gdlr_get_gallery($settings) . '</div>';
            }
        }
    }
    return '';
}
示例#11
0
/**
 * Add scripts to head
 */
function photo_galleria_scripts_head()
{
    global $post, $wp_query;
    // Retreive our plugin options
    $photo_galleria = get_option('photo_galleria');
    $design = $photo_galleria['design'];
    if ($design == 'classic' || $design == '') {
        $design = PHOTO_GALLERIA_PLUGIN_URL . '/themes/classic/galleria.classic.js';
    } elseif ($design == 'dots') {
        $design = PHOTO_GALLERIA_PLUGIN_URL . '/themes/dots/galleria.dots.js';
    }
    //elseif ($design == 'fullscreen') {
    //$design = '/themes/fullscreen/galleria.fullscreen.js';}
    $autoplay = $photo_galleria['autoplay'];
    if ($autoplay == 1) {
        $autoplay = '5000';
    }
    if ($autoplay == 0) {
        $autoplay = 'false';
    }
    $height = $photo_galleria['height'];
    if ($height == "") {
        $height = 500;
    }
    $width = $photo_galleria['width'];
    if ($width == "") {
        $width = 500;
    }
    $transition = $photo_galleria['transition'];
    // show only on homepage and archive pages
    if (!is_admin() && is_home() || !is_admin() && is_archive()) {
        echo "\n<script type=\"text/javascript\">\n\t\t\t    \n  // Load theme\n  Galleria.loadTheme('" . $design . "');\n\t";
        // run galleria and add some options
        echo "jQuery('";
        $posts = get_posts('numberposts=-1');
        $stack = array();
        foreach ($posts as $post) {
            $pid = $post->ID;
            if (stripos($post->post_content, '[gallery') !== false) {
                $element = "#galleria-" . $pid;
                array_push($stack, $element);
            }
        }
        //print_r($stack);
        $lastitem = end($stack);
        foreach ($stack as $ele) {
            if ($ele != $lastitem) {
                echo $ele . ", ";
            } else {
                echo $ele;
            }
        }
        echo "').galleria({\n  \t\tautoplay: " . $autoplay . ",\n      height: " . $height . ",\n\t\t\twidth: " . $width . ",\n      transition: '" . $transition . "',\n      data_config: function(img) {\n          // will extract and return image captions from the source:\n          return  {\n              title: jQuery(img).parent().next('strong').html(),\n              description: jQuery(img).parent().next('strong').next().html()\n          };\n      }\n  });\n  </script>\n";
    }
    // Show only on single posts and pages
    if (!is_admin() && is_single() || !is_admin() && is_page() && !is_page_template('page-blog.php')) {
        echo "\n<script type=\"text/javascript\">\n\t\t\t    \n  // Load theme\n  Galleria.loadTheme('" . $design . "');\n\t";
        // run galleria and add some options
        echo "jQuery('";
        if (gallery_shortcode($post->ID)) {
            $pid = $post->ID;
        }
        echo "#galleria-" . $pid . "').galleria({\n  \t\tautoplay: " . $autoplay . ",\n      height: " . $height . ",\n\t  clicknext: 'false',\n      width: " . $width . ",\n      transition: '" . $transition . "',\n      data_config: function(img) {\n          // will extract and return image captions from the source:\n          return  {\n              title: jQuery(img).parent().next('strong').html(),\n              description: jQuery(img).parent().next('strong').next().html()\n          };\n      }\n  });\n  </script>\n";
    }
}
示例#12
0
function exclude_thumbnail_from_gallery($null, $attr)
{
    if (!($thumbnail_ID = get_post_thumbnail_id())) {
        return $null;
    }
    // no point carrying on if no thumbnail ID
    // temporarily remove the filter, otherwise endless loop!
    remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
    // pop in our excluded thumbnail
    if (!isset($attr['exclude']) || empty($attr['exclude'])) {
        $attr['exclude'] = array($thumbnail_ID);
    } elseif (is_array($attr['exclude'])) {
        $attr['exclude'][] = $thumbnail_ID;
    }
    // now manually invoke the shortcode handler
    $gallery = gallery_shortcode($attr);
    // add the filter back
    add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
    // return output to the calling instance of gallery_shortcode()
    return $gallery;
}
示例#13
0
 function lsx_portfolio_gallery()
 {
     $media = get_attached_media('image');
     $media_array = array();
     $post_thumbnail_id = get_post_thumbnail_id(get_the_ID());
     if (!empty($media)) {
         foreach ($media as $media_item) {
             if ($post_thumbnail_id != $media_item->ID) {
                 $media_array[] = $media_item->ID;
             }
         }
         if (!empty($media_array)) {
             echo gallery_shortcode(array('size' => 'full', 'ids' => implode(',', $media_array)));
         }
     }
 }
示例#14
0
        ?>

						</article><!-- #post-<?php 
        the_ID();
        ?>
 -->

					<?php 
        // Action hook for placing content after post content
        do_action('satu_entry_after');
        ?>

					<div class="attachment-gallery">

						<?php 
        $gallery = gallery_shortcode(array('columns' => 4, 'numberposts' => 8, 'id' => $post->post_parent, 'exclude' => get_the_ID()));
        ?>

						<?php 
        if (!empty($gallery)) {
            ?>
							<div class="image-gallery">
								<?php 
            echo $gallery;
            ?>
							</div>
						<?php 
        }
        ?>

					</div><!-- .attachment-gallery -->
示例#15
0
    public static function bb_gallery_shortcode($attr, $content = '')
    {
        if (is_feed() || is_array($attr) && !empty($attr['mode']) && $attr['mode'] === 'wordpress') {
            # invoke the standard WordPress gallery shortcode function
            unset($attr['mode']);
            return gallery_shortcode($attr);
        }
        if (is_array($attr) && !empty($attr['mode']) && $attr['mode'] === 'get_first') {
            # in this mode only the first image is returned for use as a representative image for a gallery
            unset($attr['mode']);
            $get_first = TRUE;
            ob_start();
            #TODO: set underlying SQL LIMIT to 1
        }
        foreach (['thumbnail', 'medium', 'medium_large', 'large', 'full'] as $size) {
            $label = "{$size}_width";
            $width = intval(get_option("{$size}_size_w"));
            if (!$width && $size === 'medium_large') {
                $width = 768;
            }
            $width = intval(1.125 * $width);
            if ($size === 'thumbnail') {
                ${$label} = $width;
            } else {
                ${$label} = $prev_width + 1;
            }
            $prev_width = $width;
        }
        ob_start();
        require_once dirname(__FILE__) . '/bbg_xiv-gallery_templates_wp_rest.php';
        $templates = ob_get_clean();
        $post = get_post();
        static $instance = 10000;
        # not 0 to create a different space from the WordPress "gallery" shortcode
        $instance++;
        static $bbg_xiv_data = ['version' => '1.0'];
        $bbg_xiv_data['ajaxurl'] = admin_url('admin-ajax.php');
        $bbg_xiv_data['bbg_xiv_flex_min_width'] = get_option('bbg_xiv_flex_min_width', 128);
        $bbg_xiv_data['bbg_xiv_flex_min_width_for_caption'] = get_option('bbg_xiv_flex_min_width_for_caption', 96);
        $bbg_xiv_data['bbg_xiv_max_search_results'] = get_option('bbg_xiv_max_search_results', 250);
        $bbg_xiv_data['bbg_xiv_flex_min_width_for_dense_view'] = get_option('bbg_xiv_flex_min_width_for_dense_view', 1280);
        $bbg_xiv_data['bbg_xiv_flex_number_of_dense_view_columns'] = get_option('bbg_xiv_flex_number_of_dense_view_columns', 10);
        $bbg_xiv_data['bbg_xiv_carousel_interval'] = get_option('bbg_xiv_carousel_interval', 2500);
        $bbg_xiv_data['bbg_xiv_disable_flexbox'] = get_option('bbg_xiv_disable_flexbox', FALSE);
        $bbg_xiv_data['bbg_xiv_default_view'] = get_option('bbg_xiv_default_view', 'Gallery');
        $bbg_xiv_data['bbg_xiv_wp_rest_api'] = self::$wp_rest_api_available && self::$use_wp_rest_api_if_available;
        # translations for JavaScript side
        $bbg_xiv_lang['Nothing Found'] = __('Nothing Found', 'bb_gallery');
        $bbg_xiv_lang['Search Results for'] = __('Search Results for', 'bb_gallery');
        $bbg_xiv_lang['Page'] = __('Page', 'bb_gallery');
        $bbg_xiv_lang['of'] = __('of', 'bb_gallery');
        $bbg_xiv_lang['Images'] = __('Images', 'bb_gallery');
        $bbg_xiv_lang['to'] = __('to', 'bb_gallery');
        $bbg_xiv_lang['galleryOfGalleriesTitle'] = __('Each image below represents a gallery. Please click on an image to load its gallery.', 'bb_gallery');
        $default_flags = [];
        switch (get_option('bbg_xiv_use_tiles', 'Cover')) {
            case 'Cover':
                $default_flags[] = 'tiles';
                break;
            case 'Contain':
                $default_flags[] = 'tiles';
                $default_flags[] = 'contain';
                break;
            case 'Fill':
                $default_flags[] = 'tiles';
                $default_flags[] = 'fill';
                break;
        }
        if (get_option('bbg_xiv_use_embedded_carousel', TRUE)) {
            $default_flags[] = 'embedded-carousel';
        }
        if (is_array($attr)) {
            if (!empty($attr['mode']) && $attr['mode'] === "galleries") {
                # this is a proprietary mode to display altgallery entries as a gallery of representative images
                $gallery_icons_mode = TRUE;
            }
            if (!empty($attr['view'])) {
                # this sets the initial view of a gallery - gallery, carousel or tabs
                $default_view = $attr['view'];
            }
            if (!empty($attr['flags'])) {
                # flag to set embedded carousel mode
                $flags = $attr['flags'];
            }
        }
        # merge the default flags and the flags from the shortcode
        if (empty($flags)) {
            $flags = $default_flags;
        } else {
            $flags = explode(',', $flags);
            $flags = array_merge($default_flags, $flags);
            $flags = array_unique($flags);
        }
        # handle cancel flags
        foreach (['embedded-carousel', 'tiles', 'contain', 'fill'] as $flag) {
            if (($i = array_search('no-' . $flag, $flags)) !== FALSE) {
                unset($flags[$i]);
                if (($j = array_search($flag, $flags)) !== FALSE) {
                    unset($flags[$j]);
                }
            }
        }
        $flags = implode(',', $flags);
        $galleries = [];
        if ($content) {
            # Unfortunately (and also I think incorrectly) the 'the_content' filter wptexturize() from formatting.php will process the parameters of shortcodes
            # prettifying the quote marks. So, we need to undo this mutilation and restore the original content.
            # Opinion: WordPress seems to love regex but regex is simply inadequate for parsing HTML!
            $content = preg_replace('/&#8216;|&#8217;|&#8220;|&#8221;|&#8242;|&#8243;/', '"', $content);
            if (preg_match_all('#\\[altgallery\\s+title="([^"]+)"\\s+([^\\]]+)\\]#m', $content, $matches, PREG_SET_ORDER)) {
                foreach ($matches as $match) {
                    $gallery = $galleries[] = (object) ['title' => $match[1], 'specifiers' => $match[2]];
                    if (!empty($gallery_icons_mode)) {
                        $gallery->specifiers = preg_replace_callback(['/(^|\\s+)(image)="(\\d+)"/', '/(^|\\s+)(caption)="([^"]*)"/'], function ($matches) use($gallery) {
                            $gallery->{$matches}[2] = $matches[3];
                            return '';
                        }, $gallery->specifiers);
                        if (empty($gallery->image)) {
                            # no image specified so use the first image of the gallery
                            $gallery_attr = ['mode' => 'get_first'];
                            preg_replace_callback('/(\\w+)=("|\')(.*?)\\2/', function ($matches) use(&$gallery_attr) {
                                $gallery_attr[$matches[1]] = $matches[3];
                            }, $gallery->specifiers);
                            $attachment = self::bb_gallery_shortcode($gallery_attr);
                            $gallery->image = self::$wp_rest_api_available && self::$use_wp_rest_api_if_available ? $attachment['id'] : $attachment->ID;
                        }
                        if (empty($gallery->caption)) {
                            $gallery->caption = $gallery->title;
                        }
                    }
                }
            }
            if (!empty($gallery_icons_mode)) {
                // construct a 'ids' parameter with ids of gallery icons
                $attr['ids'] = implode(',', array_map(function ($gallery) {
                    return $gallery->image;
                }, $galleries));
            }
        }
        if (!empty($attr['ids'])) {
            // 'ids' is explicitly ordered, unless you specify otherwise.
            if (empty($attr['orderby'])) {
                $attr['orderby'] = 'post__in';
            }
            $attr['include'] = $attr['ids'];
        }
        /**
         * Filter the default gallery shortcode output.
         *
         * If the filtered output isn't empty, it will be used instead of generating
         * the default gallery template.
         *
         * @since 2.5.0
         * @since 4.2.0 The `$instance` parameter was added.
         *
         * @see gallery_shortcode()
         *
         * @param string $output   The gallery output. Default empty.
         * @param array  $attr     Attributes of the gallery shortcode.
         * @param int    $instance Unique numeric ID of this gallery shortcode instance.
         */
        $output = apply_filters('post_gallery', '', $attr, $instance);
        if ($output != '') {
            return $output;
        }
        $atts = shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order', 'id' => $post ? $post->ID : 0, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'link' => '', 'bb_tags' => ''), $attr, 'gallery');
        $id = intval($atts['id']);
        $selector = "gallery-{$instance}";
        if (self::$wp_rest_api_available && self::$use_wp_rest_api_if_available) {
            # map gallery shortcode parameters to WP REST API parameters
            $orderby_map = ['menu_order' => 'menu_order', 'title' => 'title', 'post_date' => 'date', 'rand' => 'rand', 'ID' => 'id', 'post__in' => 'include'];
            $order_map = ['ASC' => 'asc', 'DESC' => 'desc'];
            # Initialize the Backbone.js collection using data from the WP REST API for the WP REST API model
            $attributes = ['author' => [], 'author_exclude' => [], 'menu_order' => '', 'offset' => '', 'order' => $order_map[$atts['order']], 'orderby' => $orderby_map[$atts['orderby']], 'page' => 1, 'include' => [], 'exclude' => [], 'per_page' => 10, 'slug' => '', 'parent' => '', 'parent_exclude' => '', 'status' => 'publish', 'search' => ''];
            if (!empty($atts['bb_tags'])) {
                // Translate the terms of the proprietary 'bb_tags' attribute to ids
                $bb_tags = array_map('trim', explode(',', $atts['bb_tags']));
                $attributes['bb-tags'] = get_terms(['taxonomy' => 'bb_tags', 'slug' => $bb_tags, 'name' => $bb_tags, 'fields' => 'ids']);
            } else {
                if (!empty($atts['include'])) {
                    $attributes['include'] = explode(',', $atts['include']);
                    $attributes['per_page'] = count($attributes['include']);
                } elseif (!empty($atts['exclude'])) {
                    $attributes['parent'] = [$id];
                    $attributes['exclude'] = explode(',', $atts['exclude']);
                    $attributes['per_page'] = 1024;
                } else {
                    $attributes['parent'] = [$id];
                    $attributes['per_page'] = 1024;
                }
            }
            if (!empty($get_first)) {
                $attributes['per_page'] = 1;
            }
            $request = new WP_REST_Request('GET', '/wp/v2/media');
            $request->set_query_params($attributes);
            # TODO: $request may need to set some of the params below
            #$request->set_body_params( wp_unslash( $_POST ) );
            #$request->set_file_params( $_FILES );
            #$request->set_headers( $this->get_headers( wp_unslash( $_SERVER ) ) );
            #$request->set_body( $this->get_raw_data() );
            #$request->set_url_params( $args );
            #$request->set_attributes( $handler );
            #$request->set_default_params( $defaults );
            self::add_additional_rest_fields();
            $controller = new WP_REST_Attachments_Controller("attachment");
            $attachments = $controller->get_items($request)->data;
            if (!empty($get_first)) {
                ob_end_clean();
                return reset($attachments);
            }
            if (!empty($gallery_icons_mode)) {
                # replace title and caption for image with title and caption for gallery and also remember the gallery index
                foreach ($galleries as $i => $gallery) {
                    if (empty($attachments[$i])) {
                        # this is an error probably caused by a duplicate image id
                        continue;
                    }
                    $attachment =& $attachments[$i];
                    if ((int) $gallery->image === (int) $attachment['id']) {
                        # if this is not true then there probably is a duplicate image id
                        $attachment['gallery_index'] = $i;
                        $attachment['title']['rendered'] = $gallery->title;
                        $attachment['caption'] = $gallery->caption;
                        $attachment['description'] = '';
                    }
                }
            }
            $bbg_xiv_data["{$selector}-data"] = json_encode($attachments);
        } else {
            // initialize the Backbone.js collection using data for my proprietary model
            // Handle the proprietary 'bb_tags' attribute - this specifies a gallery by a taxonomy expression
            if (!empty($atts['bb_tags'])) {
                $bb_tags = explode(',', $atts['bb_tags']);
                $tax_query = array();
                // search by both slug and name
                $tax_query['relation'] = 'OR';
                $tax_query[] = array('taxonomy' => 'bb_tags', 'field' => 'slug', 'terms' => $bb_tags);
                $tax_query[] = array('taxonomy' => 'bb_tags', 'field' => 'name', 'terms' => $bb_tags);
                $_attachments = get_posts(array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'tax_query' => $tax_query, 'posts_per_page' => empty($get_first) ? -1 : 1, 'offset' => 0));
                $attachments = array();
                foreach ($_attachments as $key => $val) {
                    $attachments[$val->ID] = $_attachments[$key];
                }
            } elseif (!empty($atts['include'])) {
                $_attachments = get_posts(array('include' => empty($get_first) ? $atts['include'] : (string) explode(',', $atts['include'])[0], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby']));
                $attachments = array();
                foreach ($_attachments as $key => $val) {
                    $attachments[$val->ID] = $_attachments[$key];
                }
            } elseif (!empty($atts['exclude'])) {
                $attachments = get_children(array('post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'numberposts' => empty($get_first) ? -1 : 1));
            } else {
                $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'numberposts' => empty($get_first) ? -1 : 1));
            }
            if (!empty($get_first)) {
                ob_end_clean();
                return reset($attachments);
            }
            #if ( empty( $attachments ) ) {
            #  return '';
            #}
            self::bbg_xiv_do_attachments($attachments);
            if (!empty($gallery_icons_mode)) {
                # replace title and caption for image with title and caption for gallery and also remember the gallery index
                foreach ($galleries as $i => $gallery) {
                    $attachment = $attachments[$gallery->image];
                    $attachment->gallery_index = $i;
                    $attachment->post_title = $gallery->title;
                    $attachment->post_excerpt = $gallery->caption;
                    $attachment->post_content = '';
                }
            }
            $bbg_xiv_data["{$selector}-data"] = json_encode(array_values($attachments));
        }
        wp_localize_script('bbg_xiv-gallery', 'bbg_xiv', $bbg_xiv_data);
        wp_localize_script('bbg_xiv-gallery', 'bbg_xiv_lang', $bbg_xiv_lang);
        $float = is_rtl() ? 'right' : 'left';
        $size_class = sanitize_html_class($atts['size']);
        # The "Table View" is primarily intended for developers and should be disabled for production environmemts.
        $table_nav_item = '';
        if (get_option('bbg_xiv_table')) {
            $table_nav_item = <<<EOD
                        <li><a href="#">Table</a></li>
EOD;
        }
        $translations = ['GALLERY MENU' => __('GALLERY MENU', 'bb_gallery'), 'IMAGES:' => __('IMAGES:', 'bb_gallery'), 'GALLERIES:' => __('GALLERIES:', 'bb_gallery'), 'View' => __('View', 'bb_gallery'), 'Gallery' => __('Gallery', 'bb_gallery'), 'Carousel' => __('Carousel', 'bb_gallery'), 'Justified' => __('Justified', 'bb_gallery'), 'Tabs' => __('Tabs', 'bb_gallery'), 'Dense' => __('Dense', 'bb_gallery'), 'VIEWS' => __('VIEWS', 'bb_gallery'), 'GALLERIES' => __('GALLERIES', 'bb_gallery'), 'Home' => __('Home', 'bb_gallery'), 'Titles' => __('Titles', 'bb_gallery'), 'Search Images on Site' => __('Search Images on Site', 'bb_gallery'), 'Options' => __('Options', 'bb_gallery'), 'Help' => __('Help', 'bb_gallery'), 'get help' => __('get help', 'bb_gallery'), 'configure bandwidth, carousel interval, ...' => __('configure bandwidth, carousel interval, ...', 'bb_gallery'), 'return to home gallery' => __('return to home gallery', 'bb_gallery'), 'show/hide image titles' => __('show/hide image titles', 'bb_gallery'), 'Carousel Time Interval in ms' => __('Carousel Time Interval in ms', 'bb_gallery'), 'Minimum Width for Gallery Images in px' => __('Minimum Width for Gallery Images in px', 'bb_gallery'), 'Maximum Number of Images Returned by Search' => __('Maximum Number of Images Returned by Search', 'bb_gallery'), 'Number of Columns in the Dense View' => __('Number of Columns in the Dense View', 'bb_gallery'), 'Bandwidth' => __('Bandwidth', 'bb_gallery'), 'Auto' => __('Auto', 'bb_gallery'), 'High' => __('High', 'bb_gallery'), 'Medium' => __('Medium', 'bb_gallery'), 'Low' => __('Low', 'bb_gallery'), 'Interface' => __('Interface', 'bb_gallery'), 'Mouse' => __('Mouse', 'bb_gallery'), 'Touch' => __('Touch', 'bb_gallery'), 'Save' => __('Save', 'bb_gallery'), 'Cancel' => __('Cancel', 'bb_gallery'), 'Help' => __('Help', 'bb_gallery')];
        if (!$galleries) {
            for ($i = 1; $i <= self::$gallery_menu_items_count; $i++) {
                $option = get_option("bbg_xiv_gallery_menu_{$i}", '');
                if (preg_match('/^"([^"]+)":(.+)$/', $option, $matches) === 1) {
                    $galleries[] = (object) ['title' => $matches[1], 'specifiers' => $matches[2]];
                }
            }
        }
        ob_start();
        wp_nonce_field(self::$nonce_action);
        $nonce_field = ob_get_clean();
        $output = $templates;
        $output .= <<<EOD
<div class="bbg_xiv-bootstrap bbg_xiv-gallery">
    <nav role="navigation" class="navbar navbar-inverse bbg_xiv-gallery_navbar">
        <div class="navbar-header">
            <button type="button" data-target="#{$selector}-navbarCollapse" data-toggle="collapse" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="#" class="navbar-brand bbg_xiv-images_brand">{$translations['GALLERY MENU']}</a>
        </div>
        <div id="{$selector}-navbarCollapse" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li class="dropdown bbg_xiv-select_view">
                    <a data-toggle="dropdown" class="dropdown-toggle bbg_xiv-selected_view" href="#"><span>{$translations['View']}</span> <b class="caret"></b></a>
                    <ul role="menu" class="dropdown-menu bbg_xiv-view_menu">
                        <li class="dropdown-header">{$translations['VIEWS']}</li>
                        <li class="bbg_xiv-view bbg_xiv-view_gallery active"><a data-view="Gallery" href="#">{$translations['Gallery']}</a></li>
                        <li class="bbg_xiv-view bbg_xiv-view_carousel bbg_xiv-hide_for_gallery_icons"><a data-view="Carousel" href="#">{$translations['Carousel']}</a></li>
                        <li class="bbg_xiv-view bbg_xiv-view_justified bbg_xiv-hide_for_gallery_icons"><a data-view="Justified" href="#">{$translations['Justified']}</a></li>
                        <li class="bbg_xiv-view bbg_xiv-view_tabs"><a data-view="Tabs" href="#">{$translations['Tabs']}</a></li>
                        <li class="bbg_xiv-view bbg_xiv-hide_for_gallery_icons bbg_xiv-large_viewport_only"><a data-view="Dense" href="#">{$translations['Dense']}</a></li>
                        <!-- TODO: Add entry for new views here. -->
                        {$table_nav_item}
EOD;
        if ($galleries) {
            # output menu items for dynamically loaded galleries
            $output .= <<<EOD
                        <li class="divider"></li>
                        <li class="dropdown-header">{$translations['GALLERIES']}</li>
                        <li class="bbg_xiv-alt_gallery bbg_xiv-alt_gallery_home active"><a data-view="gallery_home" data-specifiers='' href="#">{$translations['Home']}</a></li>
EOD;
            foreach ($galleries as $i => $gallery) {
                $output .= <<<EOD
                        <li class="bbg_xiv-alt_gallery"><a data-view="gallery_{$i}" data-specifiers='{$gallery->specifiers}' href="#">{$gallery->title}</a></li>
EOD;
            }
        }
        $output .= <<<EOD
                    </ul>
                </li>
            </ul>
            <form role="search" class="navbar-form navbar-left bbg_xiv-search_form">
                <div class="form-group">
                    <input type="text" placeholder="{$translations['Search Images on Site']}" class="form-control">
                </div>
                <button type="submit" class="btn btn-default bbg_xiv-search" title="start search"><span class="glyphicon glyphicon-search"></span></button>
                {$nonce_field}
            </form>
            <button type="button" class="btn btn-info bbg_xiv-help" title="{$translations['get help']}">
                <span class="glyphicon glyphicon-question-sign"></span>
                <span class="bbg_xiv-navbar_button_text">{$translations['Help']}</span>
            </button>
            <button type="button" class="btn btn-info bbg_xiv-configure" title="{$translations['configure bandwidth, carousel interval, ...']}">
                <span class="glyphicon glyphicon-cog"></span>
                <span class="bbg_xiv-navbar_button_text">{$translations['Options']}</span>
            </button>
            <button type="button" class="btn btn-info bbg_xiv-home" title="{$translations['return to home gallery']}">
                <span class="glyphicon glyphicon-home"></span>
                <span class="bbg_xiv-navbar_button_text">{$translations['Home']}</span>
            </button>
            <button type="button" class="btn btn-info bbg_xiv-titles" title="{$translations['show/hide image titles']}">
                <span class="glyphicon glyphicon-subtitles"></span>
                <span class="bbg_xiv-navbar_button_text">{$translations['Titles']}</span>
            </button>
        </div>
    </nav>
EOD;
        # Optionally show titles of dynamically loadable galleries as tab items
        if ($galleries && empty($gallery_icons_mode) && get_option('bbg_xiv_use_gallery_tabs', TRUE)) {
            $output .= <<<EOD
    <!-- Gallery Tabs -->
    <div class="bbg_xiv-container bbg_xiv-gallery_tabs_container">
      <nav role="navigation" class="navbar navbar-default">
        <div class="navbar-header">
          <button type="button" data-target="#gallery_tabbar_collapse" data-toggle="collapse" class="navbar-toggle">
            <span class="sr-only">Toggle galleries</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a href="#" class="navbar-brand bbg_xiv-tabs_brand">{$translations['GALLERIES:']}</a>
        </div>
        <div id="gallery_tabbar_collapse" class="collapse navbar-collapse bbg_xiv-closed">
          <ul class="nav nav-tabs">
            <li class="bbg_xiv-tabs_title"><a href="#">{$translations['GALLERIES:']}</a></li>
        <li class="active"><a data-view="gallery_home" data-specifiers='' href="#">{$translations['Home']}</a></li>
EOD;
            foreach ($galleries as $i => $gallery) {
                $output .= <<<EOD
            <li><a data-view="gallery_{$i}" data-specifiers='{$gallery->specifiers}' href="#">{$gallery->title}</a></li>
EOD;
            }
            $output .= <<<EOD
          </ul>
        </div>
        <span class="glyphicon glyphicon-collapse-down"></span>
      </nav>
    </div>
EOD;
        }
        $class_gallery_icons_mode = empty($gallery_icons_mode) ? '' : ' bbg_xiv-gallery_icons_mode';
        $class_default_view = empty($default_view) ? '' : ' bbg_xiv-default_view_' . $default_view;
        $flags = empty($flags) ? '' : $flags;
        $output .= <<<EOD
    <!-- Search or Gallery Headings -->
    <div id="{$selector}-heading" class="bbg_xiv-search_header">
        <span class="bbg_xiv-search_heading_first"></span><br>
        <button class="btn btn-primary btn-sm bbg_xiv-search_scroll_left" disabled><span class="glyphicon glyphicon-chevron-left"></span></button>
        <span class="bbg_xiv-search_heading_second"></span>
        <button class="btn btn-primary btn-sm bbg_xiv-search_scroll_right"><span class="glyphicon glyphicon-chevron-right"></span></button>
    </div>
    <div id="{$selector}-alt_gallery_heading" class="bbg_xiv-alt_gallery_header">
        <span class="bbg_xiv-alt_gallery_heading"></span>
    </div>
    <div id="{$selector}" class="gallery galleryid-{$id} gallery-size-{$size_class} bbg_xiv-gallery_envelope{$class_gallery_icons_mode}{$class_default_view}" data-flags="{$flags}">
        <div class="ui-loader"><span class="ui-icon-loading"></span></div>
   </div>
    <div class="bbg_xiv-configure_outer">
    </div>
    <div class="bbg_xiv-configure_inner">
      <button class="bbg_xiv-configure_close"><span class="glyphicon glyphicon-remove"></span></button>
      <h1>BB Gallery Options</h1>
      <form class="form-horizontal">
        <div class="form-group">
          <label for="bbg_xiv-carousel_delay" class="control-label col-sm-9 col-md-offset-2 col-md-6">{$translations['Carousel Time Interval in ms']}</label>
          <div class="col-sm-3 col-md-2">
            <input type="number" class="form-control" id="bbg_xiv-carousel_delay" min="1000" step="100">
          </div>
        </div>
        <div class="form-group">
          <label for="bbg_xiv-min_image_width" class="control-label col-sm-9 col-md-offset-2 col-md-6">{$translations['Minimum Width for Gallery Images in px']}</label>
          <div class="col-sm-3 col-md-2">
            <input type="number" class="form-control" id="bbg_xiv-min_image_width" min="32" max="1024">
          </div>
        </div>
        <div class="form-group">
          <label for="bbg_xiv-max_search_results" class="control-label col-sm-9 col-md-offset-2 col-md-6">{$translations['Maximum Number of Images Returned by Search']}</label>
          <div class="col-sm-3 col-md-2">
            <input type="number" class="form-control" id="bbg_xiv-max_search_results" min="1" max="{$bbg_xiv_data['bbg_xiv_max_search_results']}">
          </div>
        </div>
        <div class="form-group bbg_xiv-mouse_only_option">
          <label for="bbg_xiv-columns_in_dense_view" class="control-label col-sm-9 col-md-offset-2 col-md-6">{$translations['Number of Columns in the Dense View']}</label>
          <div class="col-sm-3 col-md-2">
            <input type="number" class="form-control" id="bbg_xiv-columns_in_dense_view" min="2" max="32">
          </div>
        </div>
        <div class="form-group">
          <label for="bbg_xiv-bandwidth" class="control-label col-sm-3 col-md-offset-2 col-md-2">{$translations['Bandwidth']}</label>
          <div class="col-sm-9 col-md-6">
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-bandwidth" value="auto" id="bbg_xiv-bandwidth_auto" checked>
                <span class="bbg_xiv-radio_text">{$translations['Auto']}</span>
            </span>
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-bandwidth" value="normal" id="bbg_xiv-bandwidth_normal">
                <span class="bbg_xiv-radio_text">{$translations['High']}</span>
            </span>
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-bandwidth" value="low" id="bbg_xiv-bandwidth_low">
                <span class="bbg_xiv-radio_text">{$translations['Medium']}</span>
            </span>
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-bandwidth" value="very low" id="bbg_xiv-bandwidth_very_low">
                <span class="bbg_xiv-radio_text">{$translations['Low']}</span>
            </span>
          </div>
        </div>
        <div class="form-group">
          <label for="bbg_xiv-interface" class="control-label col-sm-3 col-md-offset-2 col-md-2">{$translations['Interface']}</label>
          <div class="col-sm-9 col-md-6">
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-interface" value="auto" id="bbg_xiv-interface_auto" checked>
                <span class="bbg_xiv-radio_text">{$translations['Auto']}</span>
            </span>
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-interface" value="mouse" id="bbg_xiv-interface_mouse">
                <span class="bbg_xiv-radio_text">{$translations['Mouse']}</span>
            </span>
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-interface" value="touch" id="bbg_xiv-interface_touch">
                <span class="bbg_xiv-radio_text">{$translations['Touch']}</span>
            </span>
            <span class="bbg_xiv-radio_input">
                <input type="radio" class="form-control" name="bbg_xiv-interface" value="null" id="bbg_xiv-interface_null" disabled>
                <span class="bbg_xiv-radio_text"></span>
            </span>
          </div>
        </div>
        <br>
        <div class="form-group">
          <div class="col-sm-offset-4 col-sm-8">
            <button type="button" class="btn btn-primary bbg_xiv-options_btn bbg_xiv-save_options">{$translations['Save']}</button>
            <button type="button" class="btn btn-default bbg_xiv-options_btn bbg_xiv-cancel_options">{$translations['Cancel']}</button>
            <button type="button" class="btn btn-info bbg_xiv-options_btn bbg_xiv-help_options">{$translations['Help']}</button>
          </div>
        </div>
      </form>
    </div>
</div>
EOD;
        return $output;
    }
示例#16
0
function modified_gallery_shortcode($attr)
{
    if (is_page_template('gallery.php')) {
        // EDIT this slug
        $attr['size'] = "full";
        $attr['link'] = "file";
        $attr['itemtag'] = "li";
        $attr['icontag'] = "span";
        $attr['captiontag'] = "p";
        $output = gallery_shortcode($attr);
        $output = strip_tags($output, '<style><img><ul><li>');
        $output = str_replace(array(" class='gallery-item'"), array(""), $output);
        $output = '<ul class="slides">' . $output . '</ul>';
    } else {
        $output = gallery_shortcode($attr);
    }
    return $output;
}
 /**
  * Wraps the gallery shortcode and removes breaks from the output.
  */
 public function gallery_shortcode($attr)
 {
     $content = \gallery_shortcode($attr);
     return preg_replace('/<br style=([^>]+)>/mi', '', $content);
 }
示例#18
0
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'];
    }


    // Jetpack tiled gallery compatibility
    if ($attr['type'] != '' && class_exists('Jetpack_Tiled_Gallery')) {
        $gallery = new Jetpack_Tiled_Gallery;
        add_filter('post_gallery', array($gallery, 'gallery_shortcode'), 1001, 2);

        return gallery_shortcode($attr);
    }

    $output = apply_filters('post_gallery', '', $attr);

    if ($output != '') {
        return $output;
    }

    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];
        }
    } 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 = "<ul id='$selector' class='thumbnails gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
    $output = apply_filters('gallery_style', $gallery_style . "\n\t\t" . $gallery_div);

    $i = 0;
    foreach ($attachments as $id => $attachment) {
        $class = '';
        $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);

        /*    $class="span2";
            if($size=="thumbnail")$class=GALLERY_THUMBNAIL_CLASSES;
            if($size=="medium")$class=GALLERY_MEDIUM_CLASSES;
            if($size=="large")$class=GALLERY_LARGE_CLASSES;*/
        $class .= ($i % $columns == 1 ? 'endofline' : '');
        $output .= "<{$icontag} class=\"" . $class . "\"><div class=\"thumbnail\">";

        $output .= $link;
        //if ($captiontag && trim($attachment->post_title)) {
        if ($attachment->post_excerpt) {
            $output .= "<{$captiontag} class=\"caption\">";
            //$output .= "<{$titletag}>" . wptexturize($attachment->post_title) . "</{$titletag}>";
            if (trim($attachment->post_excerpt))
                $output .= "<{$excerpttag}>" . wptexturize($attachment->post_excerpt) . "</{$excerpttag}>";
            $output .= "</{$captiontag}>";
        }

        $output .= "</div></{$icontag}>";
        if ($columns > 0 && ++$i % $columns == 0) {
            $output .= '';
        }
    }

    $output .= "</ul>\n";

    return $output;
}
示例#19
0
/**
 * Post gallery preview
 *
 * Show X rows of thumbnails from post content with gallery shortcode(s).
 * The shortcode column attribute from the first gallery will be used.
 *
 * @since 0.9
 * @param object $post Post to make gallery preview for
 * @param array $options Options for preview display
 * @return string Gallery shortcode output
 */
function ctfw_post_gallery_preview($post, $options = array())
{
    $preview = '';
    // Option defaults
    $options = wp_parse_args($options, array('rows' => 2, 'columns' => ''));
    $options = apply_filters('ctfw_post_gallery_preview_options', $options);
    // Get data from galleries used in post
    $galleries_data = ctfw_post_galleries_data($post);
    // Found at least one gallery with image?
    if (!empty($galleries_data['image_count'])) {
        // Get columns attribute from first gallery shortcode
        $first_gallery_columns = !empty($galleries_data['galleries'][0]['columns']) ? $galleries_data['galleries'][0]['columns'] : '';
        // Show limited number of rows
        $rows = $options['rows'];
        $columns = !empty($options['columns']) ? $options['columns'] : $first_gallery_columns;
        // inherit from first shortcode or use default
        $limit = $rows * $columns;
        // based on columns
        $ids = array_slice($galleries_data['image_ids'], 0, $limit);
        // truncate
        $ids = implode(',', $ids);
        // form as list
        // Build gallery HTML
        $preview = gallery_shortcode(array('columns' => $columns, 'ids' => $ids));
    }
    // Return filterable
    return apply_filters('ctfw_post_gallery_preview', $preview, $post, $options);
}
示例#20
0
<?php

$args = array('post_parent' => $post->ID, 'post_type' => 'attachment', 'order' => 'ASC');
$attachments = get_children($args);
if (!$attachments) {
    return;
}
$attr = array('include' => array_slice(array_keys($attachments), 0, 2));
echo gallery_shortcode($attr);
$all_data = array();
foreach ($attachments as $attachment_id => $attachment) {
    $data = array();
    list($data['href'], $width, $height) = wp_get_attachment_image_src($attachment_id, 'full');
    list($data['thumbnail'], $width, $height) = wp_get_attachment_image_src($attachment_id);
    $all_data[] = $data;
}
?>

<link rel=stylesheet href="<?php 
echo get_stylesheet_directory_uri();
?>
/fancybox/jquery.fancybox.css">
<link rel=stylesheet href="<?php 
echo get_stylesheet_directory_uri();
?>
/fancybox/helpers/jquery.fancybox-thumbs.css">
<script src="<?php 
echo get_stylesheet_directory_uri();
?>
/fancybox/jquery.fancybox.pack.js"></script>
<script src="<?php 
<div class="<?php 
echo $classes;
?>
">
	<div class="featured-gallery">
		<?php 
echo gallery_shortcode(array('ids' => $gallery_ids));
?>
	</div>
</div>
示例#22
0
/**
 * override gallery_shortcode and change link to 'file'
 **/
function pp_gallery_shortcode($atrr)
{
    $atrr['link'] = 'file';
    return gallery_shortcode($atrr);
}
示例#23
0
function glg_make_sure_link_to_media_file($atts)
{
    $atts['link'] = 'file';
    return gallery_shortcode($atts);
}
 function file_gallery_shortcode($atts)
 {
     if (empty($atts['link'])) {
         $atts['link'] = 'file';
     } else {
         if ($atts['link'] === 'none') {
             $atts['link'] = 'none';
         } else {
             $atts['link'] = 'file';
         }
     }
     return gallery_shortcode($atts);
 }
示例#25
0
 /**
  * Create a custom gallery caption output.
  *
  * @since 1.5.3
  *
  * @param   array $attr Gallery attributes.
  * @return  string
  */
 public function custom_gallery_shortcode($attr)
 {
     // Default value in WordPress.
     $captiontag = current_theme_supports('html5', 'gallery') ? 'figcaption' : 'dd';
     // User value.
     if (isset($attr['captiontag'])) {
         $captiontag = $attr['captiontag'];
     }
     // Let WordPress create the regular gallery.
     $gallery = gallery_shortcode($attr);
     // Change the content of the captions.
     $gallery = preg_replace_callback('~(<' . $captiontag . '.*>)(.*)(</' . $captiontag . '>)~mUus', array($this, 'custom_gallery_regex_callback'), $gallery);
     return $gallery;
 }
示例#26
0
    /**
     * Displays a Galleria slideshow using images attached to the specified post/page.
     * Overrides the default functionality of the [gallery] Shortcode.
     *
     * @param array $attr Attributes of the shortcode.
     * @return string HTML content to display gallery.
     */
    public function galleryShortcode($attr)
    {
        global $post, $content_width;
        // global content width set for this theme? (see theme functions.php)
        if (!isset($content_width)) {
            $content_width = 'auto';
        }
        // make sure each slideshow that is rendered for the current request has a unique ID
        static $instance = 0;
        $instance++;
        // yield to other plugins/themes attempting to override the default gallery shortcode
        $output = apply_filters('post_gallery', '', $attr);
        if ($output != '') {
            return $output;
        }
        // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
        if (isset($attr['orderby'])) {
            $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
            if (!$attr['orderby']) {
                unset($attr['orderby']);
            }
        }
        // 3:2 display ratio of the stage, account for 60px thumbnail strip at the bottom
        $width = 'auto';
        $height = '0.76';
        // a fraction of the width
        // extract the shortcode attributes into the current variable space
        extract(shortcode_atts(array('title' => '', 'el_class' => '', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'large', 'include' => '', 'exclude' => '', 'ids' => '', 'link' => 'file', 'titles' => '', 'width' => $width, 'height' => $height, 'transition' => 'fade', 'transition_speed' => 400, 'autoplay' => false, 'theme' => self::getDefaultTheme()), $attr));
        $lightbox = false;
        if ($link == "lightbox") {
            wp_enqueue_script('prettyphoto');
            wp_enqueue_style('prettyphoto');
            $link = "file";
            $lightbox = true;
        }
        if ($theme == 'native' && function_exists('gallery_shortcode')) {
            $output .= "<div id=\"xt-gallery-" . esc_attr($instance) . "\" class=\"widget xt_gallery native " . ($lightbox ? "prettyPhoto" : "") . "\">\n";
            if (!empty($title)) {
                $output .= '<span class="heading-t3"></span>';
                $output .= '<h3 class="widgettitle">' . $title . '</h3>';
                $output .= '<span class="heading-b3"></span>';
            }
            $output .= gallery_shortcode($attr);
            if ($lightbox) {
                $output .= '
				<script type="text/javascript">
				jQuery(document).ready(function($){
						
					var gallery = "#xt-gallery-' . esc_js($instance) . '.prettyPhoto";
						
					$(gallery).find("a").each(function() {
					
						var image_url = $(this).attr("href");
						console.log(image_url);
						var suffix = "";
						if(image_url.search(/\\?/i) == -1) {
							suffix = "?format=raw&ext=jpg";
						}else{
							suffix = "&format=raw&ext=jpg";
						}
						$(this).attr("href", image_url + suffix);
						$(this).attr("rel", "prettyPhoto[xt-gallery-' . esc_js($instance) . ']");
						
					});
					
					setTimeout(function() {
						
						$(gallery).find("a[rel^=\'prettyPhoto[xt-gallery-' . esc_js($instance) . ']\']").prettyPhoto();
						
					},100);	
				});
				</script>
				';
            }
            $output .= '
			<script type="text/javascript">
			jQuery(document).ready(function($){
			
				var gallery = "#xt-gallery-' . esc_js($instance) . '.native";
				$(gallery).find(".gallery-icon img").each(function() {
					var thumb_url = $(this).attr("src");
					var thumb_alt= $(this).attr("alt");
					var thumb_wrap = $(this).parent();
					var gallery_item = thumb_wrap.closest(".gallery-item");
					thumb_wrap.addClass("gallery-thumb-bg");
					thumb_wrap.css({
						"background-image": "url("+thumb_url+")",
						"height": "' . esc_js($height) . 'px"
					});
					thumb_wrap.attr("title", thumb_alt);
					$(this).hide();
				});	
				
				setTimeout(function() {
					$(gallery).animate({"opacity": 1}, 300);
				},500);	

			});
			</script>
			';
            $output .= "</div>\n";
            return $output;
        }
        // the id of the current post, or a different post if specified in the shortcode
        $id = intval($id);
        // random MySQL ordering doesn't need two attributes
        if ($order == 'RAND') {
            $orderby = 'none';
        }
        // use the given IDs of images
        if (!empty($ids)) {
            $include = $ids;
        }
        // fetch the images
        if (!empty($include)) {
            // include only the given image IDs
            $include = preg_replace('/[^0-9,]+/', '', $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];
            }
            if (!empty($ids)) {
                $sortedAttachments = array();
                $ids = preg_replace('/[^0-9,]+/', '', $ids);
                $idsArray = explode(',', $ids);
                foreach ($idsArray as $aid) {
                    if (array_key_exists($aid, $attachments)) {
                        $sortedAttachments[$aid] = $attachments[$aid];
                    }
                }
                $attachments = $sortedAttachments;
            }
        } elseif (!empty($exclude)) {
            // exclude certain image IDs
            $exclude = preg_replace('/[^0-9,]+/', '', $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 {
            // default: all images attached to this post/page
            $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
        }
        // output nothing if we didn't find any images
        if (empty($attachments)) {
            return '';
        }
        // output the individual images when displaying as a news feed
        if (is_feed()) {
            $output = "\n";
            foreach ($attachments as $attachmentId => $attachment) {
                //$output .= wp_get_attachment_link($attachmentId, $size, true) . "\n";
                list($src, $w, $attachment) = wp_get_attachment_image_src($attachmentId, 'medium');
                $output .= '<img src="' . $src . '" width="' . $w . '" height="' . $h . '">' . "\n";
            }
            return $output;
        }
        /***************/
        // xt-galleria
        /***************/
        if (!empty($titles)) {
            $titles = explode("\r\n", $titles);
        }
        // make an array of images with the proper data for Galleria
        $images = array();
        $i = 0;
        foreach ($attachments as $attachmentId => $attachment) {
            $thumb = wp_get_attachment_image_src($attachmentId, 'thumbnail');
            $big = wp_get_attachment_image_src($attachmentId, 'large');
            $image = array('image' => $big[0], 'big' => $big[0], 'thumb' => $thumb[0], 'title' => !empty($titles[$i]) ? $titles[$i] : $attachment->post_title, 'description' => wptexturize($attachment->post_excerpt));
            $images[] = $image;
            $i++;
        }
        // encode the Galleria options as JSON
        $options = json_encode(array('theme' => $theme, 'dataSource' => $images, 'width' => is_numeric($width) ? (int) $width : (string) $width, 'height' => is_int($height) ? (int) $height : (double) $height, 'autoplay' => !empty($autoplay), 'transition' => $transition, 'initialTransition' => $transition, 'fullscreenTransition' => $transition, 'transitionSpeed' => $transition_speed));
        // unique ID for this slideshow
        $domId = "xt_galleria_slideshow_" . $instance;
        $output .= "<div id=\"xt-gallery-" . $instance . "\" class=\"widget xt_gallery\">\n";
        if (!empty($title)) {
            $output .= '<span class="heading-t3"></span>';
            $output .= '<h3 class="widgettitle">' . $title . '</h3>';
            $output .= '<span class="heading-b3"></span>';
        }
        $output .= "\t<div id=\"" . $domId . "\" class=\"xt-galleria-slideshow\"></div>\n";
        $galleria_js = sprintf("%s/galleria/galleria-%s.min.js", $this->url, $this->galleriaVersion);
        $theme_js = sprintf("%s/galleria/themes/%s/galleria.%s.js", $this->url, $theme, $theme);
        $theme_css = sprintf("%s/galleria/themes/%s/galleria.%s.css", $this->url, $theme, $theme);
        wp_register_script('xt-galleria', $galleria_js, 'jquery', $this->galleriaVersion);
        wp_enqueue_script('xt-galleria');
        wp_enqueue_script('xt-galleria-' . $theme . '-js', $theme_js, 'xt-galleria', $this->version);
        wp_enqueue_style('xt-galleria-' . $theme . '-css', $theme_css, array(), $this->version);
        $output .= '
		<script type="text/javascript">
			jQuery(document).ready(function(){ 
			
				Galleria.run("#' . $domId . '", ' . $options . ');
			
			});
		</script>';
        $output .= "</div>\n";
        return $output;
    }
示例#27
0
function ceo_display_comic_gallery($size = 'full')
{
    global $post;
    $output = '';
    if (ceo_pluginfo('click_comic_next')) {
        if (ceo_pluginfo('navigate_only_chapters')) {
            $next_comic = ceo_get_next_comic_in_chapter_permalink();
        } else {
            $next_comic = ceo_get_next_comic_permalink();
        }
    }
    $hovertext = ceo_the_hovertext();
    $comic_galleries_full = get_post_meta($post->ID, 'comic-gallery-full', true);
    if ($comic_galleries_full) {
        $comic_lightbox = get_post_meta($post->ID, 'comic-open-lightbox', true);
        $comic_galleries_jquery = get_post_meta($post->ID, 'comic-gallery-jquery', true);
        if ($images = get_posts(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC'))) {
            $count = 0;
            if ($comic_galleries_jquery) {
                wp_enqueue_script('multicomic', ceo_pluginfo('plugin_url') . 'js/multicomic.js', null, null, true);
            }
            foreach ($images as $image) {
                if ($comic_galleries_jquery) {
                    $output .= '<div id="comic-' . $count . '" class="comicpane">';
                }
                $thumbnail = wp_get_attachment_image_src($image->ID, 'full');
                $thumbnail = reset($thumbnail);
                //				$thumbnail = apply_filters('jetpack_photon_url', $thumbnail);
                if ($comic_lightbox) {
                    $output .= '<a href="' . $thumbnail . '" title="' . $hovertext . '" rel="lightbox">';
                }
                if (ceo_pluginfo('click_comic_next') && !empty($next_comic) && !$comic_lightbox) {
                    $output .= '<a href="' . $next_comic . '" title="' . $hovertext . '">';
                }
                $output .= '<img src="' . $thumbnail . '" alt="' . $hovertext . '" title="' . $hovertext . '" />';
                if (ceo_pluginfo('click_comic_next') && !empty($next_comic) || $comic_lightbox) {
                    $output .= '</a>';
                }
                if ($comic_galleries_jquery) {
                    $output .= "</div>\r\n";
                }
                $count += 1;
            }
            if ($comic_galleries_jquery) {
                $output .= "<button id=\"show-" . $count . "\" type=\"button\" style=\"display:none;\">" . $count . "</button>\r\n";
            }
            //			if ($comic_lightbox) $output .= '<div class="comic-lightbox-text">'.__('Click comic to view larger version.','comiceasel').'</div>';
        }
    } else {
        $output .= ceo_display_featured_image_comic($size);
        $columns = get_post_meta($post->ID, 'comic-gallery-columns', true);
        if (empty($columns)) {
            $columns = 5;
        }
        $args = array('id' => $post->ID, 'columns' => $columns, 'exclude' => array($post->ID));
        $output .= gallery_shortcode($args);
    }
    return apply_filters('ceo_display_comic_gallery', $output);
}
示例#28
0
if (!empty($title)) {
    echo $args['before_title'] . $title . $args['after_title'];
}
// Get posts
$posts = $this->ctc_get_posts();
// widget's default query according to field values
// Determine columns based on thumb size
$thumb_sizes = array('small' => 3, 'medium' => 2, 'large' => 1);
$columns = $thumb_sizes[$instance['thumb_size']];
// Get ID's into list
$ids_array = array();
foreach ($posts as $post) {
    $ids_array[] = $post->ID;
}
$ids = implode(',', $ids_array);
?>

<?php 
// Show gallery
if (!empty($posts)) {
    ?>

	<?php 
    // Use gallery shortcode
    echo gallery_shortcode(array('columns' => $columns, 'ids' => $ids));
    ?>

	<?php 
    // Link to gallery page
    if ($instance['show_link'] && $instance['post_id'] != 'all') {
        ?>
示例#29
0
/**
 * This function replaces the default gallery shortcode, so it can check if this is a recurring event recurrence and pass on the parent post id as the default post. 
 * @param array $attr
 */
function em_event_gallery_override($attr = array())
{
    global $post;
    if ($post->post_type == EM_POST_TYPE_EVENT && empty($attr['id']) && empty($attr['ids'])) {
        //no id specified, so check if it's recurring and override id with recurrence template post id
        $EM_Event = em_get_event($post->ID, 'post_id');
        if ($EM_Event->is_recurrence()) {
            $attr['id'] = $EM_Event->get_event_recurrence()->post_id;
        }
    }
    return gallery_shortcode($attr);
}
示例#30
0
}
add_shortcode('post-category', 'rieley_categories_shortcode');
function rieley_categories_shortcode($attr)
{
    $attr = shortcode_atts(array('before' => '', 'after' => ''), $attr);
    return $attr['before'] . get_the_category_list() . $attr['after'];
}
/**
 * HTML Wrapper - Support for a custom class attribute in the native gallery shortcode
 */
add_filter('post_gallery', function ($html, $attr, $instance) {
    if (isset($attr['class']) && ($class = $attr['class'])) {
        // Unset attribute to avoid infinite recursive loops
        unset($attr['class']);
        // Our custom HTML wrapper
        $html = sprintf('<div class="%s">%s</div>', esc_attr($class), gallery_shortcode($attr));
    }
    return $html;
}, 10, 3);
// Remove ugly gallery styling.
add_theme_support('html5', array('gallery', 'caption'));
add_filter('post_gallery', 'my_post_gallery', 10, 2);
function my_post_gallery($output, $attr)
{
    global $post;
    if (isset($attr['orderby'])) {
        $attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
        if (!$attr['orderby']) {
            unset($attr['orderby']);
        }
    }