-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-gg-core.php
122 lines (101 loc) · 3.48 KB
/
class-gg-core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Gambit Gallery core settings & rendering
*/
class GGCore {
function __construct() {
add_filter( 'gg_settings_attrib_defaults', array( $this, 'attributeDefaults' ), 1 );
add_action( 'gg_settings_create', array( $this, 'createSettings' ), 1 );
add_filter( 'gg_gallery_render', array( $this, 'renderGallery' ), 10, 2 );
}
/**
* Get the attachments, this block of code comes from media.php gallery_shortcode()
* AS OF VERSION 4.1
*
* @access protected
* @param $attr array The attributes of the gallery shortcode
* @see wp-includes/media.php gallery_shortcode()
* @return empty if no attachments are available,
* string if feed results
* array of attachment objects
* @since 0.1-alpha
*/
protected function getAttachments( &$atts ) {
$post = get_post();
if ( ! empty( $attr['ids'] ) ) {
// 'ids' is explicitly ordered, unless you specify otherwise.
if ( empty( $attr['orderby'] ) ) {
$atts['orderby'] = 'post__in';
}
$atts['include'] = $atts['ids'];
}
$atts = shortcode_atts( array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post ? $post->ID : 0,
// 'itemtag' => $html5 ? 'figure' : 'dl',
// 'icontag' => $html5 ? 'div' : 'dt',
// 'captiontag' => $html5 ? 'figcaption' : 'dd',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => ''
), $atts, 'gallery' );
$id = intval( $atts['id'] );
if ( ! empty( $atts['include'] ) ) {
$_attachments = get_posts( array( 'include' => $atts['include'], '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'] ) );
} else {
$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
}
if ( empty( $attachments ) ) {
return '';
}
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment ) {
$output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n";
}
return $output;
}
return $attachments;
}
public function attributeDefaults( $atts ) {
// FIXME These are tests only
return array_merge( $atts, array(
'image_gap' => '10',
) );
}
public function createSettings() {
// FIXME These are tests only
?>
<label class="setting <?php echo GG_SLUG ?>">
<span><?php _e('Image Gap Size', GG_I18NDOMAIN ) ?></span>
<input type="number" min="0" max="1000" step="1" value="10" data-setting="image_gap"/>
px
</label>
<?php
}
public function renderGallery( $output, $atts ) {
/**
* Get the attachments that we will display
*/
$attachments = $this->getAttachments( $atts );
if ( is_string( $attachments ) || empty( $attachments ) ) {
return $attachments;
}
// Instance from media.php
static $instance = 0;
$instance++;
// print_r($attachments);
// FIXME These are tests only
return $output;
}
}
new GGCore();