media_upload_nextgen_form

The NextGEN Gallery media upload nextgen form function.

Description

media_upload_nextgen_form( $errors ); 

Parameters (1)

0. $errors
The errors.

Usage

  1. if ( !function_exists( 'media_upload_nextgen_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/admin/media-upload.php'; 
  3.  
  4. // The errors. 
  5. $errors = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = media_upload_nextgen_form($errors); 
  9.  

Defined (1)

The function is defined in the following location(s).

/products/photocrati_nextgen/modules/ngglegacy/admin/media-upload.php  
  1. function media_upload_nextgen_form($errors) { 
  2.  
  3. global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $ngg, $nggdb; 
  4.  
  5. media_upload_header(); 
  6.  
  7. $post_id = intval($_REQUEST['post_id']); 
  8. $galleryID = 0; 
  9. $total = 1; 
  10. $picarray = array(); 
  11. $chromeless = !empty($_GET['chromeless']) ? $_GET['chromeless'] : null; 
  12. $chromeless_url = $chromeless ? ('&chromeless=' . $chromeless) : null; 
  13.  
  14. $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=nextgen&post_id=$post_id" . $chromeless_url, 'admin'); 
  15.  
  16. // Get number of images in gallery  
  17. if ( isset($_REQUEST['select_gal']) ) { 
  18. $galleryID = (int) $_REQUEST['select_gal']; 
  19. $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = '$galleryID'"); 
  20.  
  21. // Build navigation 
  22. $_GET['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 0; 
  23. if ( $_GET['paged'] < 1 ) 
  24. $_GET['paged'] = 1; 
  25. $start = ( $_GET['paged'] - 1 ) * 10; 
  26. if ( $start < 1 ) 
  27. $start = 0; 
  28.  
  29. // Get the images 
  30. if ( $galleryID != 0 ) 
  31. $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, 10 ");  
  32.  
  33. // WP-Core code for Post-thumbnail 
  34. $calling_post_id = 0; 
  35. if ( isset( $_GET['post_id'] ) ) 
  36. $calling_post_id = $_GET['post_id']; 
  37.  
  38. ?> 
  39.  
  40. <script type="text/javascript"> 
  41. <!-- 
  42. function NGGSetAsThumbnail(id, nonce) { 
  43. var $link = jQuery('a#ngg-post-thumbnail-' + id); 
  44.  
  45. $link.text( setPostThumbnailL10n.saving ); 
  46. jQuery.post(ajaxurl, { 
  47. action:"ngg_set_post_thumbnail", post_id: post_id, thumbnail_id: id, cookie: encodeURIComponent(document.cookie) 
  48. }, function(str) { 
  49. var win = window.dialogArguments || opener || parent || top; 
  50. $link.text( setPostThumbnailL10n.setThumbnail ); 
  51. if ( str == '0' ) { 
  52. alert( setPostThumbnailL10n.error ); 
  53. } else if (str == '-1') { 
  54. // image removed 
  55. } else { 
  56. jQuery('a.ngg-post-thumbnail').each(function() { jQuery(this).show(); }); 
  57. jQuery('a.ngg-post-thumbnail-standin').each(function() { jQuery(this).hide(); }); 
  58. $link.hide(); 
  59.  
  60. var $dummy = $link.next(); 
  61. $dummy.attr('id', 'wp-post-thumbnail-' + str); 
  62. $dummy.show(); 
  63.  
  64. WPSetAsThumbnail(str, nonce); 
  65. ); 
  66. //--> 
  67. </script> 
  68.  
  69. <form id="filter" action="" method="get"> 
  70. <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> 
  71. <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> 
  72. <?php 
  73. if ($chromeless) 
  74. ?> 
  75. <input type="hidden" name="chromeless" value="<?php echo esc_attr( $chromeless ); ?>" /> 
  76. <?php  
  77. ?> 
  78. <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> 
  79.  
  80. <div class="tablenav"> 
  81. <?php 
  82. $page_links = paginate_links( array( 
  83. 'base' => add_query_arg( 'paged', '%#%' ),  
  84. 'format' => '',  
  85. 'total' => ceil($total / 10),  
  86. 'current' => $_GET['paged'] 
  87. )); 
  88.  
  89. if ( $page_links ) 
  90. echo "<div class='tablenav-pages'>$page_links</div>"; 
  91. ?> 
  92.  
  93. <div class="alignleft actions"> 
  94. <select id="select_gal" name="select_gal" style="width:120px;"> 
  95. <option value="0" <?php selected('0', $galleryID); ?> ><?php esc_attr( _e('No gallery', "nggallery") ); ?></option> 
  96. <?php 
  97. // Show gallery selection 
  98. $gallerylist = $nggdb->find_all_galleries(); 
  99. if(is_array($gallerylist)) { 
  100. foreach($gallerylist as $gallery) { 
  101. $selected = ($gallery->gid == $galleryID )? ' selected="selected"' : ""; 
  102. echo '<option value="'.$gallery->gid.'"'.$selected.' >'.$gallery->title.'</option>'."\n"; 
  103. ?> 
  104. </select> 
  105. <input type="submit" id="show-gallery" value="<?php esc_attr( _e('Select »', 'nggallery') ); ?>" class="button-secondary" /> 
  106. </div> 
  107. <br style="clear:both;" /> 
  108. </div> 
  109. </form> 
  110. <br style="clear:both;"/> 
  111. <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form" id="library-form"> 
  112.  
  113. <?php wp_nonce_field('ngg-media-form'); ?> 
  114.  
  115. <script type="text/javascript"> 
  116. <!-- 
  117. jQuery(function($) { 
  118. var preloaded = $(".media-item.preloaded"); 
  119. if ( preloaded.length > 0 ) { 
  120. preloaded.each(function() {prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')}, '');}); 
  121. updateMediaForm(); 
  122. }); 
  123. --> 
  124. </script> 
  125.  
  126. <div id="media-items"> 
  127. <?php 
  128. if( is_array($picarray) ) { 
  129. foreach ($picarray as $picid) { 
  130. //TODO:Reduce SQL Queries 
  131. $picture = nggdb::find_image($picid); 
  132. ?> 
  133. <div id='media-item-<?php echo $picid ?>' class='media-item preloaded'> 
  134. <div class='filename'></div> 
  135. <a class='toggle describe-toggle-on' href='#'><?php esc_attr( _e('Show', "nggallery") ); ?></a> 
  136. <a class='toggle describe-toggle-off' href='#'><?php esc_attr( _e('Hide', "nggallery") );?></a> 
  137. <div class='filename new'><?php echo ( empty($picture->alttext) ) ? wp_html_excerpt( esc_html( $picture->filename ), 60) : stripslashes( wp_html_excerpt( esc_html( $picture->alttext ), 60) ); ?></div> 
  138. <table class='slidetoggle describe startclosed'><tbody> 
  139. <tr> 
  140. <td rowspan='4'><img class='thumbnail' alt='<?php echo esc_attr( $picture->alttext ); ?>' src='<?php echo esc_attr( $picture->thumbURL ); ?>'/></td> 
  141. <td><?php esc_html( _e('Image ID:', "nggallery") ); ?><?php echo $picid ?></td> 
  142. </tr> 
  143. <tr><td><?php echo esc_html( $picture->filename ); ?></td></tr> 
  144. <tr><td><?php echo esc_html( stripslashes($picture->alttext) ); ?></td></tr> 
  145. <tr><td> </td></tr> 
  146. <tr> 
  147. <td class="label"><label for="image[<?php echo $picid ?>][alttext]"><?php esc_attr_e('Alt/Title text', "nggallery") ;?></label></td> 
  148. <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> 
  149. </tr>  
  150. <tr> 
  151. <td class="label"><label for="image[<?php echo $picid ?>][description]"><?php esc_attr_e("Description", "nggallery") ; ?></label></td> 
  152. <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> 
  153. </tr> 
  154. <tr class="align"> 
  155. <td class="label"><label for="image[<?php echo $picid ?>][align]"><?php esc_attr_e("Alignment"); ?></label></td> 
  156. <td class="field"> 
  157. <input name="image[<?php echo $picid ?>][align]" id="image-align-none-<?php echo $picid ?>" checked="checked" value="none" type="radio" /> 
  158. <label for="image-align-none-<?php echo $picid ?>" class="align image-align-none-label"><?php esc_attr_e("None") ;?></label> 
  159. <input name="image[<?php echo $picid ?>][align]" id="image-align-left-<?php echo $picid ?>" value="left" type="radio" /> 
  160. <label for="image-align-left-<?php echo $picid ?>" class="align image-align-left-label"><?php esc_attr_e("Left") ;?></label> 
  161. <input name="image[<?php echo $picid ?>][align]" id="image-align-center-<?php echo $picid ?>" value="center" type="radio" /> 
  162. <label for="image-align-center-<?php echo $picid ?>" class="align image-align-center-label"><?php esc_attr_e("Center") ;?></label> 
  163. <input name="image[<?php echo $picid ?>][align]" id="image-align-right-<?php echo $picid ?>" value="right" type="radio" /> 
  164. <label for="image-align-right-<?php echo $picid ?>" class="align image-align-right-label"><?php esc_attr_e("Right") ;?></label> 
  165. </td> 
  166. </tr> 
  167. <tr class="image-size"> 
  168. <th class="label"><label for="image[<?php echo $picid ?>][size]"><span class="alignleft"><?php esc_attr_e('Size', 'nggallery') ; ?></span></label> 
  169. </th> 
  170. <td class="field"> 
  171. <input name="image[<?php echo $picid ?>][size]" id="image-size-thumb-<?php echo $picid ?>" type="radio" checked="checked" value="thumbnail" /> 
  172. <label for="image-size-thumb-<?php echo $picid ?>"><?php esc_attr_e('Thumbnail', 'nggallery') ; ?></label> 
  173. <input name="image[<?php echo $picid ?>][size]" id="image-size-full-<?php echo $picid ?>" type="radio" value="full" /> 
  174. <label for="image-size-full-<?php echo $picid ?>"><?php esc_attr_e("Full size") ; ?></label> 
  175. <input name="image[<?php echo $picid ?>][size]" id="image-size-singlepic-<?php echo $picid ?>" type="radio" value="singlepic" /> 
  176. <label for="image-size-singlepic-<?php echo $picid ?>"><?php esc_attr_e("Singlepic", "nggallery") ; ?></label> 
  177. </td> 
  178. </tr> 
  179. <tr class="submit"> 
  180. <td> 
  181. <input type="hidden" name="image[<?php echo $picid ?>][thumb]" value="<?php echo esc_attr( $picture->thumbURL ); ?>" /> 
  182. <input type="hidden" name="image[<?php echo $picid ?>][url]" value="<?php echo esc_attr( $picture->imageURL ); ?>" /> 
  183. </td> 
  184. <td class="savesend"> 
  185. <?php 
  186. if ( $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) ) 
  187. $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); 
  188. echo "<a class='ngg-post-thumbnail' id='ngg-post-thumbnail-" . $picid . "' href='#' onclick='NGGSetAsThumbnail(\"$picid\", \"$ajax_nonce\");return false;'>" . esc_html__( 'Use as featured image' ) . "</a>"; 
  189. echo "<a class='ngg-post-thumbnail-standin' href='#' style='display:none;'></a>"; 
  190. ?> 
  191. <button type="submit" id="ngg-mlitp-<?php echo esc_attr($picid); ?>" class="button ngg-mlitp" value="1" name="send[<?php echo $picid ?>]"><?php esc_html_e( 'Insert into Post' ); ?></button> 
  192. </td> 
  193. </tr> 
  194. </tbody></table> 
  195. </div> 
  196. <?php  
  197. ?> 
  198. </div> 
  199. <p class="ml-submit"> 
  200. <input type="submit" class="button savebutton" name="save" value="<?php esc_attr( _e('Save all changes', 'nggallery') ); ?>" /> 
  201. </p> 
  202. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 
  203. <input type="hidden" name="select_gal" id="select_gal" value="<?php echo (int) $galleryID; ?>" /> 
  204. </form> 
  205.  
  206. <script type="text/javascript"> 
  207. jQuery(function($) { 
  208. // reset the media library modal tab 
  209. var mlmodal = top.wp.media.editor.get(); 
  210. mlmodal.on('close', function() { 
  211. mlmodal.setState('insert'); 
  212. }); 
  213. }); 
  214. </script> 
  215.  
  216. <?php