1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @title Add action/filter for the upload tab |
---|
5 | * @author Alex Rabe |
---|
6 | * @copyright 2008-2009 |
---|
7 | */ |
---|
8 | |
---|
9 | // BB developer: the NextGen is the most used tab, so we'd like |
---|
10 | // it to be a first one and a selected one |
---|
11 | add_filter('media_upload_default_tab', 'ngg_wp_default_tab'); |
---|
12 | function ngg_wp_default_tab() { |
---|
13 | return "nextgen"; |
---|
14 | } |
---|
15 | |
---|
16 | function ngg_wp_upload_tabs ($tabs) { |
---|
17 | |
---|
18 | $newtab = array('nextgen' => __('NextGEN Gallery','nggallery')); |
---|
19 | |
---|
20 | return array_merge($tabs,$newtab); |
---|
21 | } |
---|
22 | |
---|
23 | add_filter('media_upload_tabs', 'ngg_wp_upload_tabs'); |
---|
24 | |
---|
25 | function media_upload_nextgen() { |
---|
26 | |
---|
27 | // Not in use |
---|
28 | $errors = false; |
---|
29 | |
---|
30 | // Generate TinyMCE HTML output |
---|
31 | if ( isset($_POST['send']) ) { |
---|
32 | $keys = array_keys($_POST['send']); |
---|
33 | $send_id = (int) array_shift($keys); |
---|
34 | $image = $_POST['image'][$send_id]; |
---|
35 | $alttext = stripslashes( htmlspecialchars ($image['alttext'], ENT_QUOTES)); |
---|
36 | $description = stripslashes (htmlspecialchars($image['description'], ENT_QUOTES)); |
---|
37 | |
---|
38 | // here is no new line allowed |
---|
39 | $clean_description = preg_replace("/\n|\r\n|\r$/", " ", $description); |
---|
40 | $img = nggdb::find_image($send_id); |
---|
41 | $thumbcode = $img->get_thumbcode(); |
---|
42 | $class="ngg-singlepic ngg-{$image['align']}"; |
---|
43 | |
---|
44 | // Build output |
---|
45 | if ($image['size'] == "thumbnail") |
---|
46 | $html = "<img src='{$image['thumb']}' alt='$alttext' class='$class' />"; |
---|
47 | // Wrap the link to the fullsize image around |
---|
48 | $html = "<a $thumbcode href='{$image['url']}' title='$clean_description'>$html</a>"; |
---|
49 | |
---|
50 | if ($image['size'] == "full") |
---|
51 | $html = "<img src='{$image['url']}' alt='$alttext' class='$class' />"; |
---|
52 | |
---|
53 | if ($image['size'] == "singlepic") |
---|
54 | $html = "[singlepic id=$send_id w=320 h=240 float={$image['align']}]"; |
---|
55 | |
---|
56 | media_upload_nextgen_save_image(); |
---|
57 | |
---|
58 | // Return it to TinyMCE |
---|
59 | return media_send_to_editor($html); |
---|
60 | } |
---|
61 | |
---|
62 | // Save button |
---|
63 | if ( isset($_POST['save']) ) { |
---|
64 | media_upload_nextgen_save_image(); |
---|
65 | } |
---|
66 | |
---|
67 | return wp_iframe( 'media_upload_nextgen_form', $errors ); |
---|
68 | } |
---|
69 | |
---|
70 | add_action('media_upload_nextgen', 'media_upload_nextgen'); |
---|
71 | |
---|
72 | function media_upload_nextgen_save_image() { |
---|
73 | |
---|
74 | global $wpdb; |
---|
75 | |
---|
76 | check_admin_referer('ngg-media-form'); |
---|
77 | |
---|
78 | if ( !empty($_POST['image']) ) foreach ( $_POST['image'] as $image_id => $image ) { |
---|
79 | |
---|
80 | // Function save desription |
---|
81 | $alttext = esc_attr($image['alttext']); |
---|
82 | $description = esc_attr($image['description']); |
---|
83 | |
---|
84 | $wpdb->query("UPDATE $wpdb->nggpictures SET alttext= '$alttext', description = '$description' WHERE pid = '$image_id'"); |
---|
85 | |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | function media_upload_nextgen_form($errors) { |
---|
90 | |
---|
91 | global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $ngg; |
---|
92 | |
---|
93 | // BB developer: Max number of images per page |
---|
94 | $ngg_max_images_per_page = 100; |
---|
95 | |
---|
96 | media_upload_header(); |
---|
97 | |
---|
98 | $post_id = intval($_REQUEST['post_id']); |
---|
99 | $galleryID = 0; |
---|
100 | $total = 1; |
---|
101 | $picarray = array(); |
---|
102 | |
---|
103 | $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=nextgen&post_id=$post_id", 'admin'); |
---|
104 | |
---|
105 | // Get number of images in gallery |
---|
106 | if ( isset($_REQUEST['select_gal']) ){ |
---|
107 | $galleryID = (int) $_REQUEST['select_gal']; |
---|
108 | $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = '$galleryID'"); |
---|
109 | } |
---|
110 | |
---|
111 | // Build navigation |
---|
112 | //$_GET['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 0; |
---|
113 | //BB Dev |
---|
114 | $GET['paged'] = intval($_GET['paged']); //BB Dev |
---|
115 | if ( $_GET['paged'] < 1 ) |
---|
116 | $_GET['paged'] = 1; |
---|
117 | $start = ( $_GET['paged'] - 1 ) * $ngg_max_images_per_page; //BB Dev |
---|
118 | if ( $start < 1 ) |
---|
119 | $start = 0; |
---|
120 | |
---|
121 | // Get the images |
---|
122 | if ( $galleryID != 0 ) |
---|
123 | $picarray = $wpdb->get_col("SELECT pid FROM $wpdb->nggpictures WHERE galleryid = '$galleryID' AND exclude != 1 ORDER BY {$ngg->options['galSort']} {$ngg->options['galSortDir']} LIMIT $start, $ngg_max_images_per_page "); //BB Dev |
---|
124 | |
---|
125 | // WP-Core code for Post-thumbnail |
---|
126 | $calling_post_id = 0; |
---|
127 | if ( isset( $_GET['post_id'] ) ) |
---|
128 | $calling_post_id = $_GET['post_id']; |
---|
129 | |
---|
130 | ?> |
---|
131 | |
---|
132 | <script type="text/javascript"> |
---|
133 | <!-- |
---|
134 | function NGGSetAsThumbnail(id){ |
---|
135 | var $link = jQuery('a#ngg-post-thumbnail-' + id); |
---|
136 | |
---|
137 | $link.text( setPostThumbnailL10n.saving ); |
---|
138 | jQuery.post(ajaxurl, { |
---|
139 | action:"ngg_set_post_thumbnail", post_id: post_id, thumbnail_id: id, cookie: encodeURIComponent(document.cookie) |
---|
140 | }, function(str){ |
---|
141 | var win = window.dialogArguments || opener || parent || top; |
---|
142 | $link.text( setPostThumbnailL10n.setThumbnail ); |
---|
143 | if ( str == '0' ) { |
---|
144 | alert( setPostThumbnailL10n.error ); |
---|
145 | } else { |
---|
146 | jQuery('a.ngg-post-thumbnail').show(); |
---|
147 | $link.text( setPostThumbnailL10n.done ); |
---|
148 | $link.fadeOut( 2000 ); |
---|
149 | // set some id as meta input filed |
---|
150 | win.WPSetThumbnailID('ngg-' + id); |
---|
151 | // replace the meta box with the image |
---|
152 | win.WPSetThumbnailHTML(str); |
---|
153 | } |
---|
154 | } |
---|
155 | ); |
---|
156 | } |
---|
157 | //--> |
---|
158 | </script> |
---|
159 | |
---|
160 | <form id="filter" action="" method="get"> |
---|
161 | <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> |
---|
162 | <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> |
---|
163 | <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
164 | |
---|
165 | <div class="tablenav"> |
---|
166 | <?php |
---|
167 | $page_links = paginate_links( array( |
---|
168 | 'base' => add_query_arg( 'paged', '%#%' ), |
---|
169 | 'format' => '', |
---|
170 | 'total' => ceil($total / 10), |
---|
171 | 'current' => $_GET['paged'] |
---|
172 | )); |
---|
173 | |
---|
174 | if ( $page_links ) |
---|
175 | echo "<div class='tablenav-pages'>$page_links</div>"; |
---|
176 | ?> |
---|
177 | |
---|
178 | <div class="alignleft actions"> |
---|
179 | <select id="select_gal" name="select_gal" style="width:300px;" onchange="this.form.submit();">; <!--BB Dev: --> |
---|
180 | <option value="0" <?php selected('0', $galleryID); ?> ><?php esc_attr( _e('No gallery',"nggallery") ); ?></option> |
---|
181 | <?php |
---|
182 | // Show gallery selection |
---|
183 | $gallerylist = $wpdb->get_results("SELECT * FROM $wpdb->nggallery ORDER BY gid ASC"); |
---|
184 | if(is_array($gallerylist)) { |
---|
185 | foreach($gallerylist as $gallery) { |
---|
186 | $selected = ($gallery->gid == $galleryID )? ' selected="selected"' : ""; |
---|
187 | echo '<option value="'.$gallery->gid.'"'.$selected.' >'.$gallery->title.'</option>'."\n"; |
---|
188 | } |
---|
189 | } |
---|
190 | ?> |
---|
191 | </select> |
---|
192 | <!-- BB Dev: <input type="submit" id="show-gallery" value="<?php esc_attr( _e('Select »','nggallery') ); ?>" class="button-secondary" />--> |
---|
193 | </div> |
---|
194 | <br style="clear:both;" /> |
---|
195 | </div> |
---|
196 | </form> |
---|
197 | |
---|
198 | <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form" id="library-form"> |
---|
199 | |
---|
200 | <?php wp_nonce_field('ngg-media-form'); ?> |
---|
201 | |
---|
202 | <script type="text/javascript"> |
---|
203 | <!-- |
---|
204 | jQuery(function($){ |
---|
205 | var preloaded = $(".media-item.preloaded"); |
---|
206 | if ( preloaded.length > 0 ) { |
---|
207 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
---|
208 | updateMediaForm(); |
---|
209 | } |
---|
210 | }); |
---|
211 | --> |
---|
212 | </script> |
---|
213 | |
---|
214 | <div id="media-items"> |
---|
215 | <?php |
---|
216 | if( is_array($picarray) ) { |
---|
217 | foreach ($picarray as $picid) { |
---|
218 | //TODO:Reduce SQL Queries |
---|
219 | $picture = nggdb::find_image($picid); |
---|
220 | ?> |
---|
221 | <div id='media-item-<?php echo $picid ?>' class='media-item preloaded'> |
---|
222 | <div class='filename'></div> |
---|
223 | <!-- BB Dev --> <button style="float:right;margin-right:10px;margin-top:8px;" type="submit" class="button" value="1" name="send[<?php echo $picid ?>]"><?php echo attribute_escape( __('Insert into Post') ); ?></button> |
---|
224 | <a class='toggle describe-toggle-on' href='#'><?php esc_attr( _e('Show', "nggallery") ); ?></a> |
---|
225 | <a class='toggle describe-toggle-off' href='#'><?php esc_attr( _e('Hide', "nggallery") );?></a> |
---|
226 | <div class='filename new'><?php echo ( empty($picture->alttext) ) ? wp_html_excerpt($picture->filename,60): stripslashes( wp_html_excerpt($picture->alttext,60) ); ?></div> |
---|
227 | <table class='slidetoggle describe startclosed'><tbody> |
---|
228 | <tr> |
---|
229 | <td rowspan='4'><img class='thumbnail' alt='<?php echo esc_attr( $picture->alttext ); ?>' src='<?php echo esc_attr( $picture->thumbURL ); ?>'/></td> |
---|
230 | <td><?php esc_attr( _e('Image ID:', "nggallery") ); ?><?php echo $picid ?></td> |
---|
231 | </tr> |
---|
232 | <tr><td><?php echo esc_attr( $picture->filename ); ?></td></tr> |
---|
233 | <tr><td><?php echo esc_attr( stripslashes($picture->alttext) ); ?></td></tr> |
---|
234 | <tr><td> </td></tr> |
---|
235 | <tr> |
---|
236 | <td class="label"><label for="image[<?php echo $picid ?>][alttext]"><?php esc_attr_e('Alt/Title text', "nggallery") ;?></label></td> |
---|
237 | <td class="field"><input id="image[<?php echo $picid ?>][alttext]" name="image[<?php echo $picid ?>][alttext]" value="<?php esc_attr_e( stripslashes($picture->alttext) ); ?>" type="text"/></td> |
---|
238 | </tr> |
---|
239 | <tr> |
---|
240 | <td class="label"><label for="image[<?php echo $picid ?>][description]"><?php esc_attr_e("Description","nggallery") ; ?></label></td> |
---|
241 | <td class="field"><textarea name="image[<?php echo $picid ?>][description]" id="image[<?php echo $picid ?>][description]"><?php esc_attr_e( stripslashes($picture->description) ); ?></textarea></td> |
---|
242 | </tr> |
---|
243 | <tr class="align"> |
---|
244 | <td class="label"><label for="image[<?php echo $picid ?>][align]"><?php esc_attr_e("Alignment"); ?></label></td> |
---|
245 | <td class="field"> |
---|
246 | <input name="image[<?php echo $picid ?>][align]" id="image-align-none-<?php echo $picid ?>" checked="checked" value="none" type="radio" /> |
---|
247 | <label for="image-align-none-<?php echo $picid ?>" class="align image-align-none-label"><?php esc_attr_e("None") ;?></label> |
---|
248 | <input name="image[<?php echo $picid ?>][align]" id="image-align-left-<?php echo $picid ?>" value="left" type="radio" /> |
---|
249 | <label for="image-align-left-<?php echo $picid ?>" class="align image-align-left-label"><?php esc_attr_e("Left") ;?></label> |
---|
250 | <input name="image[<?php echo $picid ?>][align]" id="image-align-center-<?php echo $picid ?>" value="center" type="radio" /> |
---|
251 | <label for="image-align-center-<?php echo $picid ?>" class="align image-align-center-label"><?php esc_attr_e("Center") ;?></label> |
---|
252 | <input name="image[<?php echo $picid ?>][align]" id="image-align-right-<?php echo $picid ?>" value="right" type="radio" /> |
---|
253 | <label for="image-align-right-<?php echo $picid ?>" class="align image-align-right-label"><?php esc_attr_e("Right") ;?></label> |
---|
254 | </td> |
---|
255 | </tr> |
---|
256 | <tr class="image-size"> |
---|
257 | <th class="label"><label for="image[<?php echo $picid ?>][size]"><span class="alignleft"><?php esc_attr_e("Size") ; ?></span></label> |
---|
258 | </th> |
---|
259 | <td class="field"> |
---|
260 | <input name="image[<?php echo $picid ?>][size]" id="image-size-thumb-<?php echo $picid ?>" type="radio" value="thumbnail" /> <!--BB Dev: 'checked' removed !--> |
---|
261 | <label for="image-size-thumb-<?php echo $picid ?>"><?php esc_attr_e("Thumbnail") ; ?></label> |
---|
262 | <input name="image[<?php echo $picid ?>][size]" id="image-size-full-<?php echo $picid ?>" type="radio" checked="checked" value="full" /> <!--BB Dev: 'checked' added !--> |
---|
263 | <label for="image-size-full-<?php echo $picid ?>"><?php esc_attr_e("Full size") ; ?></label> |
---|
264 | <input name="image[<?php echo $picid ?>][size]" id="image-size-singlepic-<?php echo $picid ?>" type="radio" value="singlepic" /> |
---|
265 | <label for="image-size-singlepic-<?php echo $picid ?>"><?php esc_attr_e("Singlepic", "nggallery") ; ?></label> |
---|
266 | </td> |
---|
267 | </tr> |
---|
268 | <tr class="submit"> |
---|
269 | <td> |
---|
270 | <input type="hidden" name="image[<?php echo $picid ?>][thumb]" value="<?php echo $picture->thumbURL ?>" /> |
---|
271 | <input type="hidden" name="image[<?php echo $picid ?>][url]" value="<?php echo $picture->imageURL ?>" /> |
---|
272 | </td> |
---|
273 | <td class="savesend"> |
---|
274 | <?php |
---|
275 | if ( $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) ) |
---|
276 | echo "<a class='ngg-post-thumbnail' id='ngg-post-thumbnail-" . $picid . "' href='#' onclick='NGGSetAsThumbnail(\"$picid\");return false;'>" . esc_html__( 'Use as thumbnail' ) . "</a>"; |
---|
277 | ?> |
---|
278 | <button type="submit" class="button" value="1" name="send[<?php echo $picid ?>]"><?php esc_html_e( 'Insert into Post' ); ?></button> |
---|
279 | </td> |
---|
280 | </tr> |
---|
281 | </tbody></table> |
---|
282 | </div> |
---|
283 | <?php |
---|
284 | } |
---|
285 | } |
---|
286 | ?> |
---|
287 | </div> |
---|
288 | <p class="ml-submit"> |
---|
289 | <input type="submit" class="button savebutton" name="save" value="<?php esc_attr( _e('Save all changes','nggallery') ); ?>" /> |
---|
290 | </p> |
---|
291 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
---|
292 | <input type="hidden" name="select_gal" id="select_gal" value="<?php echo (int) $galleryID; ?>" /> |
---|
293 | </form> |
---|
294 | |
---|
295 | <?php |
---|
296 | } |
---|
297 | ?> |
---|