public function add_gallery_meta_boxes() { global $post; global $maxgalleria; $new_gallery = $maxgalleria->new_gallery; $image_gallery = $maxgalleria->image_gallery; $video_gallery = $maxgalleria->video_gallery; if (isset($post)) { $options = new MaxGalleryOptions($post->ID); if ($options->is_new_gallery()) { $this->add_normal_meta_box('meta-new', __('New Gallery', 'maxgalleria'), array($new_gallery, 'show_meta_box_new')); } if ($options->is_image_gallery()) { $this->add_side_meta_box('meta-shortcodes', __('Shortcodes', 'maxgalleria'), array($image_gallery, 'show_meta_box_shortcodes')); // Only show if a template has been chosen if ($options->get_template() != '') { do_action(MAXGALLERIA_ACTION_BEFORE_TEMPLATE_META_BOXES); $this->add_normal_meta_box('meta-image-gallery', __('Gallery', 'maxgalleria'), array($image_gallery, 'show_meta_box_gallery')); do_action(MAXGALLERIA_ACTION_AFTER_TEMPLATE_META_BOXES); } } if ($options->is_video_gallery()) { $this->add_side_meta_box('meta-shortcodes', __('Shortcodes', 'maxgalleria'), array($video_gallery, 'show_meta_box_shortcodes')); // Only show if a template has been chosen if ($options->get_template() != '') { do_action(MAXGALLERIA_ACTION_BEFORE_TEMPLATE_META_BOXES); $this->add_normal_meta_box('meta-video-gallery', __('Gallery', 'maxgalleria'), array($video_gallery, 'show_meta_box_gallery')); do_action(MAXGALLERIA_ACTION_AFTER_TEMPLATE_META_BOXES); } } } }
public function maxgallery_shortcode($atts) { extract(shortcode_atts(array('id' => '', 'name' => ''), $atts)); $gallery_id = sanitize_text_field("{$id}"); $gallery_name = sanitize_text_field("{$name}"); $output = ''; $gallery = null; if ($gallery_id != '' && $gallery_name != '') { // If both given, the id wins $gallery = get_post($gallery_id); } if ($gallery_id != '' && $gallery_name == '') { // Get the gallery by id $gallery = get_post($gallery_id); } if ($gallery_id == '' && $gallery_name != '') { // Get the gallery by name $query = new WP_Query(array('name' => $gallery_name, 'post_type' => MAXGALLERIA_POST_TYPE)); $gallery = $query->get_queried_object(); } if (isset($gallery) && $gallery->post_status == 'publish') { $args = array('post_parent' => $gallery->ID, 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'asc', 'numberposts' => -1); $attachments = get_posts($args); if (count($attachments) > 0) { $options = new MaxGalleryOptions($gallery->ID); global $maxgalleria; $templates = $maxgalleria->get_template_addons(); foreach ($templates as $template) { if ($template['key'] == $options->get_template()) { $output = call_user_func($template['output'], $gallery, $attachments); } } } } return $output; }
?> </optgroup> <optgroup label="<?php _e('Video Galleries', 'maxgalleria'); ?> "> <?php foreach ($galleries as $gallery) { ?> <?php $maxgallery = new MaxGalleryOptions($gallery->ID); if ($maxgallery->is_video_gallery()) { $args = array('post_parent' => $gallery->ID, 'post_type' => 'attachment', 'numberposts' => -1); $attachments = get_posts($args); $template_key = $maxgallery->get_template(); $template_name = $maxgalleria->get_template_name($template_key); $number = ''; if (count($attachments) == 0) { $number = __('0 videos', 'maxgalleria'); } if (count($attachments) == 1) { $number = __('1 video', 'maxgalleria'); } if (count($attachments) > 1) { $number = sprintf(__('%d videos', 'maxgalleria'), count($attachments)); } echo '<option value="' . $gallery->ID . '">' . $gallery->post_title . ' (' . $number . ', ' . $template_name . ')</option>'; } ?> <?php
public function create_gallery_columns($column) { // The Title and Date columns are standard, so we don't have to explicitly provide output for them global $post; $maxgallery = new MaxGalleryOptions($post->ID); // Get all the attachments (the -1 gets all of them) $args = array('post_parent' => $post->ID, 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'asc', 'numberposts' => -1); $attachments = get_posts($args); // Rounded borders $style = 'border-radius: 2px; -moz-border-radius: 2px; -webkit-border-radius: 2px;'; switch ($column) { case 'type': if ($maxgallery->is_image_gallery()) { echo '<img src="' . MAXGALLERIA_PLUGIN_URL . '/images/image-32.png" alt="' . __('Image', 'maxgalleria') . '" title="' . __('Image', 'maxgalleria') . '" style="' . $style . '" />'; } if ($maxgallery->is_video_gallery()) { echo '<img src="' . MAXGALLERIA_PLUGIN_URL . '/images/video-32.png" alt="' . __('Video', 'maxgalleria') . '" title="' . __('Video', 'maxgalleria') . '" style="' . $style . '" />'; } break; case 'thumbnail': if (has_post_thumbnail($post->ID)) { echo get_the_post_thumbnail($post->ID, array(32, 32), array('style' => $style)); } else { // Show the first thumb foreach ($attachments as $attachment) { $no_media_icon = 0; echo wp_get_attachment_image($attachment->ID, array(32, 32), $no_media_icon, array('style' => $style)); break; } } break; case 'template': $template_key = $maxgallery->get_template(); echo $this->get_template_name($template_key); break; case 'number': if ($maxgallery->is_image_gallery()) { if (count($attachments) == 0) { _e('0 images', 'maxgalleria'); } if (count($attachments) == 1) { _e('1 image', 'maxgalleria'); } if (count($attachments) > 1) { printf(__('%d images', 'maxgalleria'), count($attachments)); } } if ($maxgallery->is_video_gallery()) { if (count($attachments) == 0) { _e('0 videos', 'maxgalleria'); } if (count($attachments) == 1) { _e('1 video', 'maxgalleria'); } if (count($attachments) > 1) { printf(__('%d videos', 'maxgalleria'), count($attachments)); } } break; case 'shortcode': echo '[maxgallery id="' . $post->ID . '"]'; if ($post->post_status == 'publish') { echo '<br />'; echo '[maxgallery name="' . $post->post_name . '"]'; } break; } }
?> <?php foreach ($templates as $key => $template) { ?> <div class="meta-template"> <img src="<?php echo $template['image']; ?> " alt="<?php echo $template['name']; ?> " title="<?php echo $template['name']; ?> " <?php echo $options->get_template() == $key ? 'class="selected"' : ''; ?> /> <input type="radio" name="<?php echo $options->template_key; ?> " id="<?php echo $options->template_key; ?> _<?php echo $key; ?> " value="<?php echo $key; ?> " <?php