/products/photocrati_nextgen/modules/ngglegacy/admin/media-upload.php

  1. <?php 
  2.  
  3. /** 
  4. * @title Add action/filter for the upload tab 
  5. * @author Alex Rabe 
  6. * 
  7. */ 
  8.  
  9. function ngg_wp_upload_tabs ($tabs) { 
  10.  
  11. $newtab = array('nextgen' => __('NextGEN Gallery', 'nggallery')); 
  12.  
  13. return array_merge($tabs, $newtab); 
  14.  
  15. add_filter('media_upload_tabs', 'ngg_wp_upload_tabs'); 
  16.  
  17. function media_upload_nextgen() { 
  18.  
  19. // Not in use 
  20. $errors = false; 
  21.  
  22. // Generate TinyMCE HTML output 
  23. if ( isset($_POST['send']) ) { 
  24. $keys = array_keys($_POST['send']); 
  25. $send_id = (int) array_shift($keys); 
  26. $image = $_POST['image'][$send_id]; 
  27. $alttext = stripslashes( htmlspecialchars ($image['alttext'], ENT_QUOTES)); 
  28. $description = stripslashes (htmlspecialchars($image['description'], ENT_QUOTES)); 
  29.  
  30. // here is no new line allowed 
  31. $clean_description = preg_replace("/\n|\r\n|\r$/", " ", $description); 
  32. $img = nggdb::find_image($send_id); 
  33. $thumbcode = $img->get_thumbcode(); 
  34. $class="ngg-singlepic ngg-{$image['align']}"; 
  35.  
  36. // Create a shell displayed-gallery so we can inspect its settings 
  37. $registry = C_Component_Registry::get_instance(); 
  38. $mapper = $registry->get_utility('I_Displayed_Gallery_Mapper'); 
  39. $factory = $registry->get_utility('I_Component_Factory'); 
  40. $args = array( 
  41. 'display_type' => NGG_BASIC_SINGLEPIC 
  42. ); 
  43. $displayed_gallery = $factory->create('displayed_gallery', $args, $mapper); 
  44. $width = $displayed_gallery->display_settings['width']; 
  45. $height = $displayed_gallery->display_settings['height']; 
  46.  
  47. // Build output 
  48. if ($image['size'] == "thumbnail") 
  49. $html = "<img src='{$image['thumb']}' alt='{$alttext}' class='{$class}' />"; 
  50. else 
  51. $html = ''; 
  52.  
  53. // Wrap the link to the fullsize image around 
  54. $html = "<a {$thumbcode} href='{$image['url']}' title='{$clean_description}'>{$html}</a>"; 
  55.  
  56. if ($image['size'] == "full") 
  57. $html = "<img src='{$image['url']}' alt='{$alttext}' class='{$class}' />"; 
  58.  
  59. if ($image['size'] == "singlepic") 
  60. $html = "[singlepic id={$send_id} w={$width} h={$height} float={$image['align']}]"; 
  61.  
  62. media_upload_nextgen_save_image(); 
  63.  
  64. // Return it to TinyMCE 
  65. return media_send_to_editor($html); 
  66.  
  67. // Save button 
  68. if ( isset($_POST['save']) ) { 
  69. media_upload_nextgen_save_image(); 
  70.  
  71. return wp_iframe( 'media_upload_nextgen_form', $errors ); 
  72.  
  73. add_action('media_upload_nextgen', 'media_upload_nextgen'); 
  74.  
  75. function media_upload_nextgen_save_image() { 
  76.  
  77. global $wpdb; 
  78.  
  79. check_admin_referer('ngg-media-form'); 
  80.  
  81. if ( !empty($_POST['image']) ) foreach ( $_POST['image'] as $image_id => $image ) { 
  82.  
  83. // create a unique slug 
  84. $image_slug = nggdb::get_unique_slug( sanitize_title( $image['alttext'] ), 'image' ); 
  85. $wpdb->query( $wpdb->prepare ("UPDATE $wpdb->nggpictures SET image_slug= '%s', alttext= '%s', description = '%s' WHERE pid = %d", $image_slug, $image['alttext'], $image['description'], $image_id)); 
  86. wp_cache_delete($image_id, 'ngg_image'); 
  87.  
  88. function media_upload_nextgen_form($errors) { 
  89.  
  90. global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $ngg, $nggdb; 
  91.  
  92. media_upload_header(); 
  93.  
  94. $post_id = intval($_REQUEST['post_id']); 
  95. $galleryID = 0; 
  96. $total = 1; 
  97. $picarray = array(); 
  98. $chromeless = !empty($_GET['chromeless']) ? $_GET['chromeless'] : null; 
  99. $chromeless_url = $chromeless ? ('&chromeless=' . $chromeless) : null; 
  100.  
  101. $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=nextgen&post_id=$post_id" . $chromeless_url, 'admin'); 
  102.  
  103. // Get number of images in gallery  
  104. if ( isset($_REQUEST['select_gal']) ) { 
  105. $galleryID = (int) $_REQUEST['select_gal']; 
  106. $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures WHERE galleryid = '$galleryID'"); 
  107.  
  108. // Build navigation 
  109. $_GET['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 0; 
  110. if ( $_GET['paged'] < 1 ) 
  111. $_GET['paged'] = 1; 
  112. $start = ( $_GET['paged'] - 1 ) * 10; 
  113. if ( $start < 1 ) 
  114. $start = 0; 
  115.  
  116. // Get the images 
  117. if ( $galleryID != 0 ) 
  118. $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 ");  
  119.  
  120. // WP-Core code for Post-thumbnail 
  121. $calling_post_id = 0; 
  122. if ( isset( $_GET['post_id'] ) ) 
  123. $calling_post_id = $_GET['post_id']; 
  124.  
  125. ?> 
  126.  
  127. <script type="text/javascript"> 
  128. <!-- 
  129. function NGGSetAsThumbnail(id, nonce) { 
  130. var $link = jQuery('a#ngg-post-thumbnail-' + id); 
  131.  
  132. $link.text( setPostThumbnailL10n.saving ); 
  133. jQuery.post(ajaxurl, { 
  134. action:"ngg_set_post_thumbnail", post_id: post_id, thumbnail_id: id, cookie: encodeURIComponent(document.cookie) 
  135. }, function(str) { 
  136. var win = window.dialogArguments || opener || parent || top; 
  137. $link.text( setPostThumbnailL10n.setThumbnail ); 
  138. if ( str == '0' ) { 
  139. alert( setPostThumbnailL10n.error ); 
  140. } else if (str == '-1') { 
  141. // image removed 
  142. } else { 
  143. jQuery('a.ngg-post-thumbnail').each(function() { jQuery(this).show(); }); 
  144. jQuery('a.ngg-post-thumbnail-standin').each(function() { jQuery(this).hide(); }); 
  145. $link.hide(); 
  146.  
  147. var $dummy = $link.next(); 
  148. $dummy.attr('id', 'wp-post-thumbnail-' + str); 
  149. $dummy.show(); 
  150.  
  151. WPSetAsThumbnail(str, nonce); 
  152. ); 
  153. //--> 
  154. </script> 
  155.  
  156. <form id="filter" action="" method="get"> 
  157. <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> 
  158. <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> 
  159. <?php 
  160. if ($chromeless) 
  161. ?> 
  162. <input type="hidden" name="chromeless" value="<?php echo esc_attr( $chromeless ); ?>" /> 
  163. <?php  
  164. ?> 
  165. <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> 
  166.  
  167. <div class="tablenav"> 
  168. <?php 
  169. $page_links = paginate_links( array( 
  170. 'base' => add_query_arg( 'paged', '%#%' ),  
  171. 'format' => '',  
  172. 'total' => ceil($total / 10),  
  173. 'current' => $_GET['paged'] 
  174. )); 
  175.  
  176. if ( $page_links ) 
  177. echo "<div class='tablenav-pages'>$page_links</div>"; 
  178. ?> 
  179.  
  180. <div class="alignleft actions"> 
  181. <select id="select_gal" name="select_gal" style="width:120px;"> 
  182. <option value="0" <?php selected('0', $galleryID); ?> ><?php esc_attr( _e('No gallery', "nggallery") ); ?></option> 
  183. <?php 
  184. // Show gallery selection 
  185. $gallerylist = $nggdb->find_all_galleries(); 
  186. if(is_array($gallerylist)) { 
  187. foreach($gallerylist as $gallery) { 
  188. $selected = ($gallery->gid == $galleryID )? ' selected="selected"' : ""; 
  189. echo '<option value="'.$gallery->gid.'"'.$selected.' >'.$gallery->title.'</option>'."\n"; 
  190. ?> 
  191. </select> 
  192. <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. <br style="clear:both;"/> 
  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. </script> 
  212.  
  213. <div id="media-items"> 
  214. <?php 
  215. if( is_array($picarray) ) { 
  216. foreach ($picarray as $picid) { 
  217. //TODO:Reduce SQL Queries 
  218. $picture = nggdb::find_image($picid); 
  219. ?> 
  220. <div id='media-item-<?php echo $picid ?>' class='media-item preloaded'> 
  221. <div class='filename'></div> 
  222. <a class='toggle describe-toggle-on' href='#'><?php esc_attr( _e('Show', "nggallery") ); ?></a> 
  223. <a class='toggle describe-toggle-off' href='#'><?php esc_attr( _e('Hide', "nggallery") );?></a> 
  224. <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> 
  225. <table class='slidetoggle describe startclosed'><tbody> 
  226. <tr> 
  227. <td rowspan='4'><img class='thumbnail' alt='<?php echo esc_attr( $picture->alttext ); ?>' src='<?php echo esc_attr( $picture->thumbURL ); ?>'/></td> 
  228. <td><?php esc_html( _e('Image ID:', "nggallery") ); ?><?php echo $picid ?></td> 
  229. </tr> 
  230. <tr><td><?php echo esc_html( $picture->filename ); ?></td></tr> 
  231. <tr><td><?php echo esc_html( stripslashes($picture->alttext) ); ?></td></tr> 
  232. <tr><td> </td></tr> 
  233. <tr> 
  234. <td class="label"><label for="image[<?php echo $picid ?>][alttext]"><?php esc_attr_e('Alt/Title text', "nggallery") ;?></label></td> 
  235. <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> 
  236. </tr>  
  237. <tr> 
  238. <td class="label"><label for="image[<?php echo $picid ?>][description]"><?php esc_attr_e("Description", "nggallery") ; ?></label></td> 
  239. <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> 
  240. </tr> 
  241. <tr class="align"> 
  242. <td class="label"><label for="image[<?php echo $picid ?>][align]"><?php esc_attr_e("Alignment"); ?></label></td> 
  243. <td class="field"> 
  244. <input name="image[<?php echo $picid ?>][align]" id="image-align-none-<?php echo $picid ?>" checked="checked" value="none" type="radio" /> 
  245. <label for="image-align-none-<?php echo $picid ?>" class="align image-align-none-label"><?php esc_attr_e("None") ;?></label> 
  246. <input name="image[<?php echo $picid ?>][align]" id="image-align-left-<?php echo $picid ?>" value="left" type="radio" /> 
  247. <label for="image-align-left-<?php echo $picid ?>" class="align image-align-left-label"><?php esc_attr_e("Left") ;?></label> 
  248. <input name="image[<?php echo $picid ?>][align]" id="image-align-center-<?php echo $picid ?>" value="center" type="radio" /> 
  249. <label for="image-align-center-<?php echo $picid ?>" class="align image-align-center-label"><?php esc_attr_e("Center") ;?></label> 
  250. <input name="image[<?php echo $picid ?>][align]" id="image-align-right-<?php echo $picid ?>" value="right" type="radio" /> 
  251. <label for="image-align-right-<?php echo $picid ?>" class="align image-align-right-label"><?php esc_attr_e("Right") ;?></label> 
  252. </td> 
  253. </tr> 
  254. <tr class="image-size"> 
  255. <th class="label"><label for="image[<?php echo $picid ?>][size]"><span class="alignleft"><?php esc_attr_e('Size', 'nggallery') ; ?></span></label> 
  256. </th> 
  257. <td class="field"> 
  258. <input name="image[<?php echo $picid ?>][size]" id="image-size-thumb-<?php echo $picid ?>" type="radio" checked="checked" value="thumbnail" /> 
  259. <label for="image-size-thumb-<?php echo $picid ?>"><?php esc_attr_e('Thumbnail', 'nggallery') ; ?></label> 
  260. <input name="image[<?php echo $picid ?>][size]" id="image-size-full-<?php echo $picid ?>" type="radio" value="full" /> 
  261. <label for="image-size-full-<?php echo $picid ?>"><?php esc_attr_e("Full size") ; ?></label> 
  262. <input name="image[<?php echo $picid ?>][size]" id="image-size-singlepic-<?php echo $picid ?>" type="radio" value="singlepic" /> 
  263. <label for="image-size-singlepic-<?php echo $picid ?>"><?php esc_attr_e("Singlepic", "nggallery") ; ?></label> 
  264. </td> 
  265. </tr> 
  266. <tr class="submit"> 
  267. <td> 
  268. <input type="hidden" name="image[<?php echo $picid ?>][thumb]" value="<?php echo esc_attr( $picture->thumbURL ); ?>" /> 
  269. <input type="hidden" name="image[<?php echo $picid ?>][url]" value="<?php echo esc_attr( $picture->imageURL ); ?>" /> 
  270. </td> 
  271. <td class="savesend"> 
  272. <?php 
  273. if ( $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) ) 
  274. $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); 
  275. 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>"; 
  276. echo "<a class='ngg-post-thumbnail-standin' href='#' style='display:none;'></a>"; 
  277. ?> 
  278. <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> 
  279. </td> 
  280. </tr> 
  281. </tbody></table> 
  282. </div> 
  283. <?php  
  284. ?> 
  285. </div> 
  286. <p class="ml-submit"> 
  287. <input type="submit" class="button savebutton" name="save" value="<?php esc_attr( _e('Save all changes', 'nggallery') ); ?>" /> 
  288. </p> 
  289. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 
  290. <input type="hidden" name="select_gal" id="select_gal" value="<?php echo (int) $galleryID; ?>" /> 
  291. </form> 
  292.  
  293. <script type="text/javascript"> 
  294. jQuery(function($) { 
  295. // reset the media library modal tab 
  296. var mlmodal = top.wp.media.editor.get(); 
  297. mlmodal.on('close', function() { 
  298. mlmodal.setState('insert'); 
  299. }); 
  300. }); 
  301. </script> 
  302.  
  303. <?php 
  304. ?> 
.