PageRenderTime 26ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/HTTP/wp-content/plugins/nextgen-gallery/admin/media-upload.php

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