PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/ngglegacy/admin/media-upload.php

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