-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathninja-galleries.php
400 lines (360 loc) · 12.8 KB
/
ninja-galleries.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
/*
Plugin Name: Ninja Galleries
Plugin URI: http://wpninjas.net/plugins/ninja-galleries/
Description: Ninja Galleries lets you easily create image galleries by tagging your images and then assigning those tags to a gallery page.
Version: 1.0.24
Author: Kevin Stover
Author URI: http://www.wpninjas.net
*/
require_once("wpnj-media-tags/media_tags.php");
function wpnj_gallery_post_display($content){
global $post;
$this_type = get_post_type($post->ID);
if($this_type == "wpnj_gallery"){
$wpnj_img_size = "thumbnail";
$test = wpnj_mediatags_load_master();
if($test){
foreach($test as $val){
$wpnj_gal_field = "wpnj_gallery_" . $val->slug;
$meta = get_post_meta($post->ID, $wpnj_gal_field, true);
if($meta){
if($wpnj_selected_tags == ""){
$wpnj_selected_tags = $val->slug;
}else{
$wpnj_selected_tags .= ',' . $val->slug;
}
}
}
$media_items = wpnj_get_attachments_by_media_tags('media_tags=' . $wpnj_selected_tags);
if($media_items){
$content .= '<hr />';
foreach($media_items as $media_item){
//print_r($media_item);
$page_uri = get_page_uri($post->ID);
$image_src = wp_get_attachment_image_src($media_item->ID, $wpnj_img_size);
$full_src = wp_get_attachment_image_src($media_item->ID, "full");
$content .= '<dl class="gallery-item"><dt class="gallery-icon"><a title="'.$media_item->post_excerpt.'" rel="lightbox[ '.$page_uri.' ]" href="'.$full_src[0].'"><img src="'.$image_src[0].'"></a></dt></dl>';
//$content .= '<img src="'.$image_src[0].'">';
}
}
}
}
return $content;
}
add_filter("the_content", "wpnj_gallery_post_display");
function wpnj_gallery_build_tax(){
register_taxonomy(
'wpnj_gallery_cat',
'wpnj_gallery',
array(
'hierarchical' => true,
'label' => 'Gallery Category',
'query_var' => true,
'rewrite' => true ) );
}
add_action('init', 'wpnj_gallery_build_tax');
function wpnj_gallery_display_list($args){
if($args['cat']){
$cats_array = explode("," , $args['cat']);
foreach($cats_array as $cat_title){
$full_term = get_term_by('name', $cat_title, 'wpnj_gallery_cat');
//if($slugs == ""){
//$slugs = $full_term->slug;
//}else{
//$slugs .= ','.$full_term->slug;
//}
$test = get_terms('wpnj_gallery_cat', 'slug='.$full_term->slug);
//print_r($test);
//echo $test[0]->slug;
echo '<h2>'.$test[0]->name.'</h2>';
$items = array(
'post_type' => 'wpnj_gallery',
'posts_per_page' => 10,
'taxonomy' => 'wpnj_gallery_cat',
'term' => $test[0]->slug
);
$loop = new WP_Query($items);
echo '<div class="whole-gallery">';
while ( $loop->have_posts() ){
$loop->the_post();
echo '<dl class="gallery-item"><dt class="gallery-icon"><a href="';
the_permalink();
echo '">';
if(function_exists('the_post_thumbnail')){
the_post_thumbnail('thumbnail');
}
echo '</a></dt><dd>';
the_title();
echo '</dd></dl>';
}
echo '</div>';
}
}elseif($args['gallery']){
$items = array(
'post_type' => 'wpnj_gallery',
'name' => $args['gallery']
);
$loop = new WP_Query($items);
echo '<div class="whole-gallery">';
while ( $loop->have_posts() ){
$loop->the_post();
echo '<dl class="gallery-item"><dt class="gallery-icon"><a href="';
the_permalink();
echo '">';
if(function_exists('the_post_thumbnail')){
the_post_thumbnail('thumbnail');
}
echo '</a></dt><dd>';
the_title();
echo '</dd></dl>';
}
echo '</div>';
}else{
$test = get_terms('wpnj_gallery_cat');
foreach($test as $val){
echo '<h2>'.$val->name.'</h2>';
$items = array(
'post_type' => 'wpnj_gallery',
'posts_per_page' => 10,
'taxonomy' => 'wpnj_gallery_cat',
'term' => $val->slug
);
$loop = new WP_Query($items);
echo '<div class="whole-gallery">';
while ( $loop->have_posts() ){
$loop->the_post();
echo '<dl class="gallery-item"><dt class="gallery-icon"><a href="';
the_permalink();
echo '">';
if(function_exists('the_post_thumbnail')){
the_post_thumbnail('thumbnail');
}
echo '</a></dt><dd>';
the_title();
echo '</dd></dl>';
}
echo '</div>';
}
}
//Reset Query
wp_reset_query();
}
add_shortcode('wpnj_gal_list', 'wpnj_gallery_display_list');
//Custom Post Type Stuff:
add_action('init', 'wpnj_gallery_custom_post_type');
function wpnj_gallery_custom_post_type()
{
$labels = array(
'name' => _x('Galleries', 'post type general name'),
'singular_name' => _x('Gallery', 'post type singular name'),
'add_new' => _x('Add New', 'wpnj_gallery'),
'add_new_item' => __('Add New Gallery'),
'edit_item' => __('Edit Gallery'),
'new_item' => __('New Gallery'),
'view_item' => __('View Gallery'),
'search_items' => __('Search Galleries'),
'not_found' => __('No Galleries found'),
'not_found_in_trash' => __('No Galleries found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'_builtin' => false, // It's a custom post type, not built in!
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'rewrite' => array("slug" => "gallery"), // Permalinks format
'menu_icon' => get_stylesheet_directory_uri() . '/images/icon-gallery.png',
'supports' => array('title','editor','thumbnail'),
'taxonomies' => array('') // this is IMPORTANT
);
register_post_type('wpnj_gallery',$args);
}
//add filter to insure the text Book, or book, is displayed when user updates a book
add_filter('post_updated_messages', 'wpnj_gallery_updated_messages');
function wpnj_gallery_updated_messages( $messages ) {
$messages['wpnj_gallery'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __('Gallery updated. <a href="%s">View Gallery</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Gallery updated.'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Gallery restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Gallery published. <a href="%s">View Gallery</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Book saved.'),
8 => sprintf( __('Gallery submitted. <a target="_blank" href="%s">Preview Gallery</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Gallery scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Gallery</a>'),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Gallery draft updated. <a target="_blank" href="%s">Preview Gallery</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
//display contextual help for Books
add_action( 'contextual_help', 'add_help_text', 10, 3 );
function add_help_text($contextual_help, $screen_id, $screen) {
//$contextual_help .= var_dump($screen); // use this to help determine $screen->id
if ('wpnj_gallery' == $screen->id ) {
$contextual_help =
'<p>' . __('Things to remember when adding or editing a Gallery:') . '</p>' .
'<ul>' .
'<li>' . __('Specify the correct genre such as Mystery, or Historic.') . '</li>' .
'<li>' . __('Specify the correct writer of the book. Remember that the Author module refers to you, the author of this book review.') . '</li>' .
'</ul>' .
'<p>' . __('If you want to schedule the book review to be published in the future:') . '</p>' .
'<ul>' .
'<li>' . __('Under the Publish module, click on the Edit link next to Publish.') . '</li>' .
'<li>' . __('Change the date to the date to actual publish this article, then click on Ok.') . '</li>' .
'</ul>' .
'<p><strong>' . __('For more information:') . '</strong></p>' .
'<p>' . __('<a href="http://codex.wordpress.org/Posts_Edit_SubPanel" target="_blank">Edit Posts Documentation</a>') . '</p>' .
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ;
} elseif ( 'edit-book' == $screen->id ) {
$contextual_help =
'<p>' . __('This is the help screen displaying the table of books blah blah blah.') . '</p>' ;
}
return $contextual_help;
}
add_filter("manage_edit-wpnj_gallery_columns", "wpnj_gallery_edit_columns");
add_action("manage_posts_custom_column", "wpnj_gallery_custom_columns");
function wpnj_gallery_edit_columns($columns){
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"thumbnail" => "Thumbnail",
"title" => "Gallery",
"description" => "Description",
"tags" => "Tags",
);
return $columns;
}
function wpnj_gallery_custom_columns($column){
global $post;
switch ($column)
{
case "thumbnail":
$custom = get_post_custom();
if(function_exists('the_post_thumbnail')){
echo the_post_thumbnail(array('100px', '100px'));
}
break;
case "description":
$custom = get_post_custom();
echo $post->post_content;
break;
case "tags":
$custom = get_post_custom();
echo get_the_tag_list( '', ', ' );
break;
}
}
add_action('admin_menu', 'mytheme_add_box2');
// Add meta box
function mytheme_add_box2() {
global $wpnj_master_tags, $meta_box2;
$wpnj_test = wpnj_mediatags_load_master();
//print_r($test);
$prefix = "wpnj_gallery_";
$wpnj_master_tags = array();
if($wpnj_test){
foreach($wpnj_test as $wpnj_var){
$new_item = array(
'name' => $wpnj_var->name,
'desc' => $wpnj_var->desc,
'id' => $prefix . $wpnj_var->slug,
'type' => 'checkbox',
'std' => ''
);
$wpnj_master_tags[] = $new_item;
}
}
$meta_box2 = array(
'id' => 'gal',
'title' => 'Add Images Tagged With:',
'page' => 'wpnj_gallery',
'context' => 'normal',
'priority' => 'high',
'fields' => $wpnj_master_tags
);
add_meta_box($meta_box2['id'], $meta_box2['title'], 'mytheme_show_box2', $meta_box2['page'], $meta_box2['context'], $meta_box2['priority']);
}
// Callback function to show fields in meta box
function mytheme_show_box2() {
global $post, $wpnj_master_tags, $meta_box2;
// Use nonce for verification
echo '<input type="hidden" name="mytheme_meta_box2_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box2['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
echo '<tr>',
'<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
'<td>';
switch ($field['type']) {
case 'text':
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
'<br />', $field['desc'];
break;
case 'textarea':
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
'<br />', $field['desc'];
break;
case 'select':
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
foreach ($field['options'] as $option) {
echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
}
echo '</select>';
break;
case 'radio':
foreach ($field['options'] as $option) {
echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' />', $option['name'];
}
break;
case 'checkbox':
echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
break;
}
echo '<td>',
'</tr>';
}
echo '</table>';
}
add_action('save_post', 'mytheme_save_data2');
// Save data from meta box
function mytheme_save_data2($post_id) {
global $meta_box2;
// verify nonce
if (!wp_verify_nonce($_POST['mytheme_meta_box2_nonce'], basename(__FILE__))) {
return $post_id;
}
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($meta_box2['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}
//----End Gallery Custom Post Type
include_once ( dirname(__FILE__) . "/wpnj-media-tags/media_tags.php");