media_upload_nextgen_form

The NextCellent 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 . 'nextcellent-gallery/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).

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