Exemple #1
0
        function render_field($field)
        {
            // enqueue
            acf_enqueue_uploader();
            // vars
            $posts = array();
            $atts = array('id' => $field['id'], 'class' => "acf-gallery {$field['class']}", 'data-preview_size' => $field['preview_size'], 'data-library' => $field['library'], 'data-min' => $field['min'], 'data-max' => $field['max'], 'data-mime_types' => $field['mime_types']);
            // set gallery height
            $height = acf_get_user_setting('gallery_height', 400);
            $height = max($height, 200);
            // minimum height is 200
            $atts['style'] = "height:{$height}px";
            // load posts
            if (!empty($field['value'])) {
                $posts = acf_get_posts(array('post_type' => 'attachment', 'post__in' => $field['value']));
            }
            ?>
<div <?php 
            acf_esc_attr_e($atts);
            ?>
>
	
	<div class="acf-hidden">
		<input type="hidden" <?php 
            acf_esc_attr_e(array('name' => $field['name'], 'value' => '', 'data-name' => 'ids'));
            ?>
 />
	</div>
	
	<div class="acf-gallery-main">
		
		<div class="acf-gallery-attachments">
			
			<?php 
            if (!empty($posts)) {
                ?>
			
				<?php 
                foreach ($posts as $post) {
                    // vars
                    $type = acf_maybe_get(explode('/', $post->post_mime_type), 0);
                    $thumb_id = $post->ID;
                    $thumb_url = '';
                    $thumb_class = 'acf-gallery-attachment acf-soh';
                    $filename = wp_basename($post->guid);
                    // thumb
                    if ($type === 'image' || $type === 'audio' || $type === 'video') {
                        // change $thumb_id
                        if ($type === 'audio' || $type === 'video') {
                            $thumb_id = get_post_thumbnail_id($post->ID);
                        }
                        // get attachment
                        if ($thumb_id) {
                            $thumb_url = wp_get_attachment_image_src($thumb_id, $field['preview_size']);
                            $thumb_url = acf_maybe_get($thumb_url, 0);
                        }
                    }
                    // fallback
                    if (!$thumb_url) {
                        $thumb_url = wp_mime_type_icon($post->ID);
                        $thumb_class .= ' is-mime-icon';
                    }
                    ?>
					<div class="<?php 
                    echo $thumb_class;
                    ?>
" data-id="<?php 
                    echo $post->ID;
                    ?>
">
						<input type="hidden" name="<?php 
                    echo $field['name'];
                    ?>
[]" value="<?php 
                    echo $post->ID;
                    ?>
" />
						<div class="margin" title="<?php 
                    echo $filename;
                    ?>
">
							<div class="thumbnail">
								<img src="<?php 
                    echo $thumb_url;
                    ?>
"/>
							</div>
							<?php 
                    if ($type !== 'image') {
                        ?>
							<div class="filename"><?php 
                        echo acf_get_truncated($filename, 18);
                        ?>
</div>
							<?php 
                    }
                    ?>
						</div>
						<div class="actions acf-soh-target">
							<a class="acf-icon dark remove-attachment" data-id="<?php 
                    echo $post->ID;
                    ?>
" href="#">
								<i class="acf-sprite-delete"></i>
							</a>
						</div>
					</div>
					
				<?php 
                }
                ?>
				
			<?php 
            }
            ?>
			
			
		</div>
		
		<div class="acf-gallery-toolbar">
			
			<ul class="acf-hl">
				<li>
					<a href="#" class="acf-button blue add-attachment"><?php 
            _e('Add to gallery', 'acf');
            ?>
</a>
				</li>
				<li class="acf-fr">
					<select class="bulk-actions">
						<option value=""><?php 
            _e('Bulk actions', 'acf');
            ?>
</option>
						<option value="date"><?php 
            _e('Sort by date uploaded', 'acf');
            ?>
</option>
						<option value="modified"><?php 
            _e('Sort by date modified', 'acf');
            ?>
</option>
						<option value="title"><?php 
            _e('Sort by title', 'acf');
            ?>
</option>
						<option value="reverse"><?php 
            _e('Reverse current order', 'acf');
            ?>
</option>
					</select>
				</li>
			</ul>
			
		</div>
		
	</div>
	
	<div class="acf-gallery-side">
	<div class="acf-gallery-side-inner">
			
		<div class="acf-gallery-side-data"></div>
						
		<div class="acf-gallery-toolbar">
			
			<ul class="acf-hl">
				<li>
					<a href="#" class="acf-button close-sidebar"><?php 
            _e('Close', 'acf');
            ?>
</a>
				</li>
				<li class="acf-fr">
					<a class="acf-button blue update-attachment"><?php 
            _e('Update', 'acf');
            ?>
</a>
				</li>
			</ul>
			
		</div>
		
	</div>	
	</div>
	
</div>
		<?php 
        }
Exemple #2
0
        function render_field($field)
        {
            // enqueue
            acf_enqueue_uploader();
            // vars
            $atts = array('id' => $field['id'], 'class' => "acf-gallery {$field['class']}", 'data-library' => $field['library'], 'data-min' => $field['min'], 'data-max' => $field['max'], 'data-mime_types' => $field['mime_types'], 'data-insert' => $field['insert'], 'data-columns' => 4);
            // set gallery height
            $height = acf_get_user_setting('gallery_height', 400);
            $height = max($height, 200);
            // minimum height is 200
            $atts['style'] = "height:{$height}px";
            // get posts
            $value = $this->get_attachments($field['value']);
            ?>
<div <?php 
            acf_esc_attr_e($atts);
            ?>
>
	
	<div class="acf-hidden">
		<?php 
            acf_hidden_input(array('name' => $field['name'], 'value' => ''));
            ?>
	</div>
	
	<div class="acf-gallery-main">
		
		<div class="acf-gallery-attachments">
			
			<?php 
            if ($value) {
                ?>
			
				<?php 
                foreach ($value as $i => $v) {
                    // bail early if no value
                    if (!$v) {
                        continue;
                    }
                    // vars
                    $a = array('ID' => $v->ID, 'title' => $v->post_title, 'filename' => wp_basename($v->guid), 'type' => acf_maybe_get(explode('/', $v->post_mime_type), 0), 'class' => 'acf-gallery-attachment acf-soh');
                    // thumbnail
                    $thumbnail = acf_get_post_thumbnail($a['ID'], 'medium');
                    // remove filename if is image
                    if ($a['type'] == 'image') {
                        $a['filename'] = '';
                    }
                    // class
                    $a['class'] .= ' -' . $a['type'];
                    if ($thumbnail['type'] == 'icon') {
                        $a['class'] .= ' -icon';
                    }
                    ?>
					<div class="<?php 
                    echo $a['class'];
                    ?>
" data-id="<?php 
                    echo $a['ID'];
                    ?>
">
						<?php 
                    acf_hidden_input(array('name' => $field['name'] . '[]', 'value' => $a['ID']));
                    ?>
						<div class="margin">
							<div class="thumbnail">
								<img src="<?php 
                    echo $thumbnail['url'];
                    ?>
" alt="" title="<?php 
                    echo $a['title'];
                    ?>
"/>
							</div>
							<?php 
                    if ($a['filename']) {
                        ?>
							<div class="filename"><?php 
                        echo acf_get_truncated($a['filename'], 30);
                        ?>
</div>	
							<?php 
                    }
                    ?>
						</div>
						<div class="actions acf-soh-target">
							<a class="acf-icon -cancel dark acf-gallery-remove" href="#" data-id="<?php 
                    echo $a['ID'];
                    ?>
" title="<?php 
                    _e('Remove', 'acf');
                    ?>
"></a>
						</div>
					</div>
				<?php 
                }
                ?>
				
			<?php 
            }
            ?>
			
		</div>
		
		<div class="acf-gallery-toolbar">
			
			<ul class="acf-hl">
				<li>
					<a href="#" class="acf-button button button-primary acf-gallery-add"><?php 
            _e('Add to gallery', 'acf');
            ?>
</a>
				</li>
				<li class="acf-fr">
					<select class="acf-gallery-sort">
						<option value=""><?php 
            _e('Bulk actions', 'acf');
            ?>
</option>
						<option value="date"><?php 
            _e('Sort by date uploaded', 'acf');
            ?>
</option>
						<option value="modified"><?php 
            _e('Sort by date modified', 'acf');
            ?>
</option>
						<option value="title"><?php 
            _e('Sort by title', 'acf');
            ?>
</option>
						<option value="reverse"><?php 
            _e('Reverse current order', 'acf');
            ?>
</option>
					</select>
				</li>
			</ul>
			
		</div>
		
	</div>
	
	<div class="acf-gallery-side">
	<div class="acf-gallery-side-inner">
			
		<div class="acf-gallery-side-data"></div>
						
		<div class="acf-gallery-toolbar">
			
			<ul class="acf-hl">
				<li>
					<a href="#" class="acf-button button acf-gallery-close"><?php 
            _e('Close', 'acf');
            ?>
</a>
				</li>
				<li class="acf-fr">
					<a class="acf-button button button-primary acf-gallery-update"><?php 
            _e('Update', 'acf');
            ?>
</a>
				</li>
			</ul>
			
		</div>
		
	</div>	
	</div>
	
</div>
		<?php 
        }