PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/flash-album-gallery/admin/media-upload.php

https://github.com/santi93/Andes
PHP | 234 lines | 179 code | 40 blank | 15 comment | 18 complexity | 2fc4a9dd1fd7beabee0f5fb3b93eb71c MD5 | raw file
  1. <?php
  2. /**
  3. * @title Add action/filter for the upload tab
  4. */
  5. function flag_wp_upload_tabs ($tabs) {
  6. $newtab = array('flag' => __('FlAG Gallery','flag'));
  7. return array_merge($tabs,$newtab);
  8. }
  9. add_filter('media_upload_tabs', 'flag_wp_upload_tabs');
  10. function media_upload_flag() {
  11. // Generate TinyMCE HTML output
  12. if ( isset($_POST['send']) ) {
  13. $keys = array_keys($_POST['send']);
  14. $send_id = (int) array_shift($keys);
  15. $image = $_POST['image'][$send_id];
  16. $alttext = stripslashes( htmlspecialchars ($image['alttext'], ENT_QUOTES));
  17. $description = stripslashes (htmlspecialchars($image['description'], ENT_QUOTES));
  18. // here is no new line allowed
  19. $clean_description = preg_replace("/\n|\r\n|\r$/", " ", $description);
  20. $img = flagdb::find_image($send_id);
  21. $class="flag-singlepic flag-{$image['align']}";
  22. // Build output
  23. if ($image['size'] == "thumbnail")
  24. $html = "<img src='{$image['thumb']}' alt='$alttext' class='$class' align='{$image['align']}' />";
  25. // Wrap the link to the fullsize image around
  26. $html = "<a href='{$image['url']}' title='$clean_description'>$html</a>";
  27. if ($image['size'] == "full")
  28. $html = "<img src='{$image['url']}' alt='$alttext' class='$class' align='{$image['align']}' />";
  29. media_upload_flag_save_image();
  30. // Return it to TinyMCE
  31. return media_send_to_editor($html);
  32. }
  33. // Save button
  34. if ( isset($_POST['save']) ) {
  35. media_upload_flag_save_image();
  36. }
  37. return wp_iframe( 'media_upload_flag_form', $errors );
  38. }
  39. add_action('media_upload_flag', 'media_upload_flag');
  40. function media_upload_flag_save_image() {
  41. global $wpdb;
  42. check_admin_referer('flag-media-form');
  43. if ( !empty($_POST['image']) ) foreach ( $_POST['image'] as $image_id => $image ) {
  44. // Function save desription
  45. $alttext = esc_attr($image['alttext']);
  46. $description = esc_attr($image['description']);
  47. $wpdb->query("UPDATE $wpdb->flagpictures SET alttext= '$alttext', description = '$description' WHERE pid = '$image_id'");
  48. }
  49. }
  50. function media_upload_flag_form($errors) {
  51. global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types, $flag;
  52. media_upload_header();
  53. $post_id = intval($_REQUEST['post_id']);
  54. $galleryID = 0;
  55. $total = 1;
  56. $picarray = false;
  57. $form_action_url = site_url( "wp-admin/media-upload.php?type={$GLOBALS['type']}&tab=flag&post_id=$post_id", 'admin');
  58. // Get number of images in gallery
  59. if ($_REQUEST['select_gal']){
  60. $galleryID = (int) $_REQUEST['select_gal'];
  61. $total = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->flagpictures WHERE galleryid = '$galleryID'");
  62. }
  63. // Build navigation
  64. $_GET['paged'] = intval($_GET['paged']);
  65. if ( $_GET['paged'] < 1 )
  66. $_GET['paged'] = 1;
  67. $start = ( $_GET['paged'] - 1 ) * 10;
  68. if ( $start < 1 )
  69. $start = 0;
  70. // Get the images
  71. if ( $galleryID != 0 )
  72. $picarray = $wpdb->get_col("SELECT pid FROM $wpdb->flagpictures WHERE galleryid = '$galleryID' AND exclude != 1 ORDER BY {$flag->options['galSort']} {$flag->options['galSortDir']} LIMIT $start, 10 ");
  73. ?>
  74. <form id="filter" action="" method="get">
  75. <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
  76. <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
  77. <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
  78. <div class="tablenav">
  79. <?php
  80. $page_links = paginate_links( array(
  81. 'base' => add_query_arg( 'paged', '%#%' ),
  82. 'format' => '',
  83. 'total' => ceil($total / 10),
  84. 'current' => $_GET['paged']
  85. ));
  86. if ( $page_links )
  87. echo "<div class='tablenav-pages'>$page_links</div>";
  88. ?>
  89. <div class="alignleft actions">
  90. <select id="select_gal" name="select_gal" style="width:200px;">;
  91. <option value="0" <?php selected('0', $galleryID); ?> ><?php esc_attr( _e('No gallery',"flag") ); ?></option>
  92. <?php
  93. // Show gallery selection
  94. $gallerylist = $wpdb->get_results("SELECT * FROM $wpdb->flaggallery ORDER BY gid ASC");
  95. if(is_array($gallerylist)) {
  96. foreach($gallerylist as $gallery) {
  97. $selected = ($gallery->gid == $galleryID )? ' selected="selected"' : "";
  98. echo '<option value="'.$gallery->gid.'"'.$selected.' >'.$gallery->title.'</option>'."\n";
  99. }
  100. }
  101. ?>
  102. </select>
  103. <input type="submit" id="show-gallery" value="<?php esc_attr( _e('Select &#187;','flag') ); ?>" class="button-secondary" />
  104. </div>
  105. <br style="clear:both;" />
  106. </div>
  107. </form>
  108. <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form" id="library-form">
  109. <?php wp_nonce_field('flag-media-form'); ?>
  110. <script type="text/javascript">
  111. <!--
  112. jQuery(function($){
  113. var preloaded = $(".media-item.preloaded");
  114. if ( preloaded.length > 0 ) {
  115. preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  116. updateMediaForm();
  117. }
  118. });
  119. -->
  120. </script>
  121. <div id="media-items">
  122. <?php
  123. if(is_array($picarray)) {
  124. foreach ($picarray as $picid) {
  125. //TODO:Reduce SQL Queries
  126. $picture = flagdb::find_image($picid);
  127. ?>
  128. <div id='media-item-<?php echo $picid; ?>' class='media-item preloaded'>
  129. <div class='filename'></div>
  130. <a class='toggle describe-toggle-on' href='#'><?php esc_attr( _e('Show', "flag") ); ?></a>
  131. <a class='toggle describe-toggle-off' href='#'><?php esc_attr( _e('Hide', "flag") ); ?></a>
  132. <div class='filename new'><?php echo ( empty($picture->alttext) ) ? wp_html_excerpt($picture->filename,60): stripslashes( wp_html_excerpt($picture->alttext,60) ); ?></div>
  133. <table class='slidetoggle describe startclosed'><tbody>
  134. <tr>
  135. <td rowspan='4'><img class='thumbnail' alt='<?php echo esc_attr( $picture->alttext ); ?>' src='<?php echo esc_attr( $picture->thumbURL ); ?>'/></td>
  136. <td><?php esc_attr( _e('Image ID:', "flag") ); ?><?php echo $picid; ?></td>
  137. </tr>
  138. <tr><td><?php echo esc_attr( $picture->filename ); ?></td></tr>
  139. <tr><td><?php echo esc_attr( stripslashes($picture->alttext) ); ?></td></tr>
  140. <tr><td>&nbsp;</td></tr>
  141. <tr>
  142. <td class="label"><label for="image[<?php echo $picid; ?>][alttext]"><?php esc_attr( _e('Alt/Title text', "flag") ); ?></label></td>
  143. <td class="field"><input id="image[<?php echo $picid; ?>][alttext]" name="image[<?php echo $picid; ?>][alttext]" value="<?php echo esc_attr( stripslashes($picture->alttext) ); ?>" type="text"/></td>
  144. </tr>
  145. <tr>
  146. <td class="label"><label for="image[<?php echo $picid; ?>][description]"><?php esc_attr( _e("Description","flag") ); ?></label></td>
  147. <td class="field"><textarea name="image[<?php echo $picid; ?>][description]" id="image[<?php echo $picid; ?>][description]"><?php echo esc_attr( stripslashes($picture->description) ); ?></textarea></td>
  148. </tr>
  149. <tr class="align">
  150. <td class="label"><label for="image[<?php echo $picid; ?>][align]"><?php esc_attr( _e("Alignment") ); ?></label></td>
  151. <td class="field">
  152. <input name="image[<?php echo $picid; ?>][align]" id="image-align-none-<?php echo $picid; ?>" checked="checked" value="none" type="radio" />
  153. <label for="image-align-none-<?php echo $picid; ?>" class="align image-align-none-label"><?php esc_attr( _e("None") ); ?></label>
  154. <input name="image[<?php echo $picid; ?>][align]" id="image-align-left-<?php echo $picid; ?>" value="left" type="radio" />
  155. <label for="image-align-left-<?php echo $picid; ?>" class="align image-align-left-label"><?php esc_attr( _e("Left") ); ?></label>
  156. <input name="image[<?php echo $picid; ?>][align]" id="image-align-center-<?php echo $picid; ?>" value="center" type="radio" />
  157. <label for="image-align-center-<?php echo $picid; ?>" class="align image-align-center-label"><?php esc_attr( _e("Center") ); ?></label>
  158. <input name="image[<?php echo $picid; ?>][align]" id="image-align-right-<?php echo $picid; ?>" value="right" type="radio" />
  159. <label for="image-align-right-<?php echo $picid; ?>" class="align image-align-right-label"><?php esc_attr( _e("Right") ); ?></label>
  160. </td>
  161. </tr>
  162. <tr class="image-size">
  163. <th class="label"><label for="image[<?php echo $picid; ?>][size]"><span class="alignleft"><?php esc_attr( _e("Size") ); ?></span></label>
  164. </th>
  165. <td class="field">
  166. <input name="image[<?php echo $picid; ?>][size]" id="image-size-thumb-<?php echo $picid; ?>" type="radio" checked="checked" value="thumbnail" />
  167. <label for="image-size-thumb-<?php echo $picid; ?>"><?php esc_attr( _e("Thumbnail") ); ?></label>
  168. <input name="image[<?php echo $picid; ?>][size]" id="image-size-full-<?php echo $picid; ?>" type="radio" value="full" />
  169. <label for="image-size-full-<?php echo $picid; ?>"><?php esc_attr( _e("Full size") ); ?></label>
  170. </td>
  171. </tr>
  172. <tr class="submit">
  173. <td>
  174. <input type="hidden" name="image[<?php echo $picid; ?>][thumb]" value="<?php echo $picture->thumbURL; ?>" />
  175. <input type="hidden" name="image[<?php echo $picid; ?>][url]" value="<?php echo $picture->imageURL; ?>" />
  176. </td>
  177. <td class="savesend"><button type="submit" class="button" value="1" name="send[<?php echo $picid; ?>]"><?php echo esc_attr( __('Insert into Post') ); ?></button></td>
  178. </tr>
  179. </tbody></table>
  180. </div>
  181. <?php
  182. }
  183. }
  184. ?>
  185. </div>
  186. <p class="ml-submit">
  187. <input type="submit" class="button savebutton" name="save" value="<?php esc_attr( _e('Save all changes','flag') ); ?>" />
  188. </p>
  189. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  190. <input type="hidden" name="select_gal" id="select_gal" value="<?php echo (int) $galleryID; ?>" />
  191. </form>
  192. <?php
  193. }
  194. ?>