Changeset 705217
- Timestamp:
- 04/29/2013 05:20:06 AM (13 years ago)
- Location:
- post-thumbnail-extras
- Files:
-
- 9 added
- 3 edited
- 5 copied
-
assets/banner-772x250.jpg (added)
-
tags/3.0 (copied) (copied from post-thumbnail-extras/trunk)
-
tags/3.0/README.txt (copied) (copied from post-thumbnail-extras/trunk/README.txt)
-
tags/3.0/i18n (added)
-
tags/3.0/i18n/post-thumbnail-extras.pot (added)
-
tags/3.0/js (added)
-
tags/3.0/js/media-shortcode.js (added)
-
tags/3.0/php/options.php (copied) (copied from post-thumbnail-extras/trunk/php/options.php) (6 diffs)
-
tags/3.0/php/shortcode.php (copied) (copied from post-thumbnail-extras/trunk/php/shortcode.php) (2 diffs)
-
tags/3.0/post-thumbnail-extras.php (copied) (copied from post-thumbnail-extras/trunk/post-thumbnail-extras.php) (3 diffs)
-
trunk/i18n (added)
-
trunk/i18n/post-thumbnail-extras.pot (added)
-
trunk/js (added)
-
trunk/js/media-shortcode.js (added)
-
trunk/php/options.php (modified) (6 diffs)
-
trunk/php/shortcode.php (modified) (2 diffs)
-
trunk/post-thumbnail-extras.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
post-thumbnail-extras/tags/3.0/php/options.php
r697354 r705217 8 8 public function admin_init() { 9 9 add_settings_field( 'ptx-post-thumbnails' 10 , '<b>' . __( 'Post Thumbnail Extra Sizes', PTX_DOMAIN) . '</b>'10 , '<b>' . __( 'Post Thumbnail Extra Sizes', PTX_DOMAIN ) . '</b>' 11 11 . ' <a class="ptx-add-thumb" href="#">+</a>' 12 12 , array( $this, 'create_post_thumbnails_html' ) … … 14 14 , 'default' 15 15 ); 16 // Register the settings to be handled by wordpress and the callback function 16 17 register_setting( 'media' 17 18 , 'ptx_post_thumbnails' 18 19 , array( $this, 'sanitize_post_thumbnails' ) ); 20 21 // Add a section for displaying other Post Thumbnails and their metadata 22 // (e.g. width, height, crop) 23 add_settings_section( 'ptx-other-post-thumbnails' 24 , __( 'Post Thumbnail Extras - Display other post thumbnails', PTX_DOMAIN ) 25 , array( $this, 'other_post_thumbnails_html' ) 26 , 'media' 27 ); 19 28 } 20 29 … … 121 130 */ 122 131 public function sanitize_post_thumbnails( $input ) { 132 $too_large = 2000; 123 133 //add_settings_error( 'ptx-post-thumbnails' 124 134 // , 'not-really-helpful' … … 126 136 // , 'updated' 127 137 //); 128 129 138 $new_input = array(); 139 140 if ( ! is_array( $input ) ) 141 return $new_input; 142 130 143 $counter = 0; 131 144 $pattern = "/[^[:alnum:]-]+/"; … … 155 168 $thumbnail['crop'] = ( isset( $thumbnail['crop'] ) && $thumbnail['crop'] ); 156 169 170 if ( $too_large < $thumbnail['width'] || $too_large < $thumbnail['height'] ) { 171 add_settings_error( 'ptx-post-thumbnails' 172 , NULL 173 , sprintf( __( "Consider using 0 for an unlimited size side (%s)", PTX_DOMAIN ), $thumbnail['name'] ) 174 , 'updated'); 175 } 176 177 157 178 $new_input[] = $thumbnail; 158 179 } … … 168 189 return $new_input; 169 190 } 191 192 /** 193 * Display post thumbnail metadata for other post thumbnails defined elsewhere 194 */ 195 public function other_post_thumbnails_html() { 196 $thumbnails = $this->get_other_intermediate_image_sizes(); 197 198 if ( ! isset( $thumbnails ) || 0 == count( $thumbnails ) ) { 199 _e( "No additional image sizes defined", PTX_DOMAIN ); 200 return; 201 } 202 203 $name = __( 'Name', PTX_DOMAIN ); 204 $width = __( 'Width', PTX_DOMAIN ); 205 $height = __( 'Height', PTX_DOMAIN ); 206 $crop = __( 'Crop', PTX_DOMAIN ); 207 $output = <<<EOT 208 <style type="text/css" media="all"> 209 #ptx-other-post-thumbnails { 210 width: 50%%; 211 } 212 .widefat thead th:first-of-type { 213 padding-left: 8px; 214 } 215 .widefat.media .check-column { 216 padding-bottom: 8px; 217 } 218 </style> 219 <table id="ptx-other-post-thumbnails" class="wp-list-table widefat fixed media" cellspacing="0"> 220 <thead> 221 <tr> 222 <th class="manage-column column-name check-column" style=""> 223 $name 224 </th> 225 <th class="manage-column check-column" style=""> 226 $width 227 </th> 228 <th class="manage-column check-column" style=""> 229 $height 230 </th> 231 <th class="manage-column check-column" style=""> 232 $crop 233 </th> 234 </tr> 235 </thead> 236 <tbody> 237 %s 238 </tbody> 239 </table> 240 EOT; 241 $body = ""; 242 $row = "<tr><td>%s</td><td>%d</td><td>%d</td><td>%s</td></tr>"; 243 foreach ( $thumbnails as $name => $thumbnail ) { 244 $body .= sprintf( $row 245 , $name 246 , $thumbnail['width'] 247 , $thumbnail['height'] 248 , ( true == $thumbnail['crop'] ) ? __( 'True' ) : __( 'False' ) 249 ); 250 } 251 252 print( sprintf( $output, $body ) ); 253 } 254 255 /** 256 * Ignore 'large', 'medium', 'thumbnail' and any ptx_thumbs 257 */ 258 public function get_other_intermediate_image_sizes() { 259 global $_wp_additional_image_sizes; 260 $filter = array( 'large', 'medium', 'thumbnail' ); 261 262 $ptx_post_thumbnails = get_option( 'ptx_post_thumbnails' ); 263 if ( isset( $ptx_post_thumbnails ) and is_array( $ptx_post_thumbnails ) ){ 264 foreach ( get_option( 'ptx_post_thumbnails' ) as $thumb ) { 265 $filter[] = $thumb['name']; 266 } 267 } 268 269 foreach ( $_wp_additional_image_sizes as $name => $thumb ) { 270 if ( ! in_array( $name, $filter ) ) { 271 $return[$name] = $thumb; 272 } 273 } 274 return $return; 275 } 170 276 } 171 277 278 $PTX_OPTIONS = new PTXOptions(); -
post-thumbnail-extras/tags/3.0/php/shortcode.php
r696870 r705217 4 4 public function __construct() { 5 5 add_shortcode( 'pt', array( $this, 'parse_shortcode' ) ); 6 //add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 7 add_action( 'add_meta_boxes_post', array( $this, 'enqueue_scripts' ) ); 8 add_filter( 'media_view_strings', array( $this, 'media_strings' ), 10, 2 ); 9 add_filter( 'image_size_names_choose', array( $this, 'image_sizes' ) ); 10 add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_attachment' ), 10, 3 ); 6 11 } 7 12 … … 25 30 return wp_get_attachment_image( $id, $size, false, array( 'class' => $class ) ); 26 31 } 32 33 /** 34 * Enqueue scripts for the Edit Post page 35 */ 36 public function enqueue_scripts() { 37 wp_enqueue_script( 'ptx-shortcode' 38 , PTX_PLUGINURL . 'js/media-shortcode.js' 39 , array('media-views', 'media-editor') 40 , false, true 41 ); 42 } 43 44 /** 45 * The i18n strings for the Edit Post page 46 */ 47 public function media_strings( $strings, $post ) { 48 $strings['PTXInsertShortcode'] = __( 'Insert Shortcode', PTX_DOMAIN ); 49 return $strings; 50 } 51 52 /** 53 * Get the list of image sizes 54 */ 55 public function image_sizes ( $sizes ) { 56 $potential_sizes = get_intermediate_image_sizes(); 57 foreach ( $potential_sizes as $size ) { 58 if ( 'post-thumbnail' != $size && ! in_array( $size, $sizes ) ) { 59 $sizes[$size] = $size; 60 } 61 } 62 return $sizes; 63 } 64 65 /** 66 * In the prepare_attachment_for_js ajax call, it marshalls a list of 67 * attachment metadata used for adding to the media-library sidebar. If we want 68 * the other post thumbnails to show up, we have to add them here. 69 * 70 * _Sidenotes_: 71 * 72 * 1. If the post-thumbnail has not yet been generated, and the user selects 73 * a post-thumbnail and does an "Insert into Post", it will link to the fullsize 74 * image and the browser will resize it inefficiently. 75 * 76 * 2. I tried using the image_downsize filter, but that caused an infinite loop 77 * with the wp_get_attachment_* methods. 78 * 79 * See <wp-includes/media.php> for more information. 80 * 81 * @param $response - the metadata being returned to the client 82 * @param $attachment = wp_get_attachment_metadata for the post 83 * @param $meta - Other metadata 84 */ 85 public function fix_attachment( $response, $attachment, $meta ) { 86 $predefined = array( 'thumbnail', 'medium', 'large', 'full' ); 87 $possible_sizes = apply_filters( 'image_size_names_choose', array() ); 88 foreach ( $predefined as $size ) { 89 if ( isset( $possible_sizes[$size] ) ) { 90 unset( $possible_sizes[$size] ); 91 } 92 } 93 94 95 foreach ( $possible_sizes as $size => $label ) { 96 if ( isset( $response['sizes'][$size] ) ) 97 continue; 98 $img = wp_get_attachment_image_src( $response['id'], $size ); 99 $response['sizes'][$size] = array( 100 'height' => $img[2], 101 'width' => $img[1], 102 'url' => $img[0], 103 'orientation' => ( $img[2] > $img[1] ) ? 'portrait' : 'landscape' 104 ); 105 } 106 return $response; 107 } 27 108 } 28 109 110 $PTX_SHORTCODE = new PTXShortcode(); -
post-thumbnail-extras/tags/3.0/post-thumbnail-extras.php
r697354 r705217 5 5 Author: sewpafly 6 6 Author URI: http://sewpafly.github.io/post-thumbnail-editor/ 7 Version: 2.17 Version: 3.0 8 8 Description: Little things that make using post thumbnails easier 9 9 */ … … 13 13 */ 14 14 define( 'PTX_DOMAIN', 'post-thumbnail-extras' ); 15 define( 'PTX_PLUGINURL', plugins_url(basename( dirname(__FILE__))) . "/"); 15 16 16 17 class PostThumbnailExtras { … … 33 34 */ 34 35 $this->load_requires(); 35 $s = new PTXShortcode();36 $o = new PTXOptions();37 36 } 38 37 -
post-thumbnail-extras/trunk/php/options.php
r697354 r705217 8 8 public function admin_init() { 9 9 add_settings_field( 'ptx-post-thumbnails' 10 , '<b>' . __( 'Post Thumbnail Extra Sizes', PTX_DOMAIN) . '</b>'10 , '<b>' . __( 'Post Thumbnail Extra Sizes', PTX_DOMAIN ) . '</b>' 11 11 . ' <a class="ptx-add-thumb" href="#">+</a>' 12 12 , array( $this, 'create_post_thumbnails_html' ) … … 14 14 , 'default' 15 15 ); 16 // Register the settings to be handled by wordpress and the callback function 16 17 register_setting( 'media' 17 18 , 'ptx_post_thumbnails' 18 19 , array( $this, 'sanitize_post_thumbnails' ) ); 20 21 // Add a section for displaying other Post Thumbnails and their metadata 22 // (e.g. width, height, crop) 23 add_settings_section( 'ptx-other-post-thumbnails' 24 , __( 'Post Thumbnail Extras - Display other post thumbnails', PTX_DOMAIN ) 25 , array( $this, 'other_post_thumbnails_html' ) 26 , 'media' 27 ); 19 28 } 20 29 … … 121 130 */ 122 131 public function sanitize_post_thumbnails( $input ) { 132 $too_large = 2000; 123 133 //add_settings_error( 'ptx-post-thumbnails' 124 134 // , 'not-really-helpful' … … 126 136 // , 'updated' 127 137 //); 128 129 138 $new_input = array(); 139 140 if ( ! is_array( $input ) ) 141 return $new_input; 142 130 143 $counter = 0; 131 144 $pattern = "/[^[:alnum:]-]+/"; … … 155 168 $thumbnail['crop'] = ( isset( $thumbnail['crop'] ) && $thumbnail['crop'] ); 156 169 170 if ( $too_large < $thumbnail['width'] || $too_large < $thumbnail['height'] ) { 171 add_settings_error( 'ptx-post-thumbnails' 172 , NULL 173 , sprintf( __( "Consider using 0 for an unlimited size side (%s)", PTX_DOMAIN ), $thumbnail['name'] ) 174 , 'updated'); 175 } 176 177 157 178 $new_input[] = $thumbnail; 158 179 } … … 168 189 return $new_input; 169 190 } 191 192 /** 193 * Display post thumbnail metadata for other post thumbnails defined elsewhere 194 */ 195 public function other_post_thumbnails_html() { 196 $thumbnails = $this->get_other_intermediate_image_sizes(); 197 198 if ( ! isset( $thumbnails ) || 0 == count( $thumbnails ) ) { 199 _e( "No additional image sizes defined", PTX_DOMAIN ); 200 return; 201 } 202 203 $name = __( 'Name', PTX_DOMAIN ); 204 $width = __( 'Width', PTX_DOMAIN ); 205 $height = __( 'Height', PTX_DOMAIN ); 206 $crop = __( 'Crop', PTX_DOMAIN ); 207 $output = <<<EOT 208 <style type="text/css" media="all"> 209 #ptx-other-post-thumbnails { 210 width: 50%%; 211 } 212 .widefat thead th:first-of-type { 213 padding-left: 8px; 214 } 215 .widefat.media .check-column { 216 padding-bottom: 8px; 217 } 218 </style> 219 <table id="ptx-other-post-thumbnails" class="wp-list-table widefat fixed media" cellspacing="0"> 220 <thead> 221 <tr> 222 <th class="manage-column column-name check-column" style=""> 223 $name 224 </th> 225 <th class="manage-column check-column" style=""> 226 $width 227 </th> 228 <th class="manage-column check-column" style=""> 229 $height 230 </th> 231 <th class="manage-column check-column" style=""> 232 $crop 233 </th> 234 </tr> 235 </thead> 236 <tbody> 237 %s 238 </tbody> 239 </table> 240 EOT; 241 $body = ""; 242 $row = "<tr><td>%s</td><td>%d</td><td>%d</td><td>%s</td></tr>"; 243 foreach ( $thumbnails as $name => $thumbnail ) { 244 $body .= sprintf( $row 245 , $name 246 , $thumbnail['width'] 247 , $thumbnail['height'] 248 , ( true == $thumbnail['crop'] ) ? __( 'True' ) : __( 'False' ) 249 ); 250 } 251 252 print( sprintf( $output, $body ) ); 253 } 254 255 /** 256 * Ignore 'large', 'medium', 'thumbnail' and any ptx_thumbs 257 */ 258 public function get_other_intermediate_image_sizes() { 259 global $_wp_additional_image_sizes; 260 $filter = array( 'large', 'medium', 'thumbnail' ); 261 262 $ptx_post_thumbnails = get_option( 'ptx_post_thumbnails' ); 263 if ( isset( $ptx_post_thumbnails ) and is_array( $ptx_post_thumbnails ) ){ 264 foreach ( get_option( 'ptx_post_thumbnails' ) as $thumb ) { 265 $filter[] = $thumb['name']; 266 } 267 } 268 269 foreach ( $_wp_additional_image_sizes as $name => $thumb ) { 270 if ( ! in_array( $name, $filter ) ) { 271 $return[$name] = $thumb; 272 } 273 } 274 return $return; 275 } 170 276 } 171 277 278 $PTX_OPTIONS = new PTXOptions(); -
post-thumbnail-extras/trunk/php/shortcode.php
r696870 r705217 4 4 public function __construct() { 5 5 add_shortcode( 'pt', array( $this, 'parse_shortcode' ) ); 6 //add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 7 add_action( 'add_meta_boxes_post', array( $this, 'enqueue_scripts' ) ); 8 add_filter( 'media_view_strings', array( $this, 'media_strings' ), 10, 2 ); 9 add_filter( 'image_size_names_choose', array( $this, 'image_sizes' ) ); 10 add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_attachment' ), 10, 3 ); 6 11 } 7 12 … … 25 30 return wp_get_attachment_image( $id, $size, false, array( 'class' => $class ) ); 26 31 } 32 33 /** 34 * Enqueue scripts for the Edit Post page 35 */ 36 public function enqueue_scripts() { 37 wp_enqueue_script( 'ptx-shortcode' 38 , PTX_PLUGINURL . 'js/media-shortcode.js' 39 , array('media-views', 'media-editor') 40 , false, true 41 ); 42 } 43 44 /** 45 * The i18n strings for the Edit Post page 46 */ 47 public function media_strings( $strings, $post ) { 48 $strings['PTXInsertShortcode'] = __( 'Insert Shortcode', PTX_DOMAIN ); 49 return $strings; 50 } 51 52 /** 53 * Get the list of image sizes 54 */ 55 public function image_sizes ( $sizes ) { 56 $potential_sizes = get_intermediate_image_sizes(); 57 foreach ( $potential_sizes as $size ) { 58 if ( 'post-thumbnail' != $size && ! in_array( $size, $sizes ) ) { 59 $sizes[$size] = $size; 60 } 61 } 62 return $sizes; 63 } 64 65 /** 66 * In the prepare_attachment_for_js ajax call, it marshalls a list of 67 * attachment metadata used for adding to the media-library sidebar. If we want 68 * the other post thumbnails to show up, we have to add them here. 69 * 70 * _Sidenotes_: 71 * 72 * 1. If the post-thumbnail has not yet been generated, and the user selects 73 * a post-thumbnail and does an "Insert into Post", it will link to the fullsize 74 * image and the browser will resize it inefficiently. 75 * 76 * 2. I tried using the image_downsize filter, but that caused an infinite loop 77 * with the wp_get_attachment_* methods. 78 * 79 * See <wp-includes/media.php> for more information. 80 * 81 * @param $response - the metadata being returned to the client 82 * @param $attachment = wp_get_attachment_metadata for the post 83 * @param $meta - Other metadata 84 */ 85 public function fix_attachment( $response, $attachment, $meta ) { 86 $predefined = array( 'thumbnail', 'medium', 'large', 'full' ); 87 $possible_sizes = apply_filters( 'image_size_names_choose', array() ); 88 foreach ( $predefined as $size ) { 89 if ( isset( $possible_sizes[$size] ) ) { 90 unset( $possible_sizes[$size] ); 91 } 92 } 93 94 95 foreach ( $possible_sizes as $size => $label ) { 96 if ( isset( $response['sizes'][$size] ) ) 97 continue; 98 $img = wp_get_attachment_image_src( $response['id'], $size ); 99 $response['sizes'][$size] = array( 100 'height' => $img[2], 101 'width' => $img[1], 102 'url' => $img[0], 103 'orientation' => ( $img[2] > $img[1] ) ? 'portrait' : 'landscape' 104 ); 105 } 106 return $response; 107 } 27 108 } 28 109 110 $PTX_SHORTCODE = new PTXShortcode(); -
post-thumbnail-extras/trunk/post-thumbnail-extras.php
r697354 r705217 5 5 Author: sewpafly 6 6 Author URI: http://sewpafly.github.io/post-thumbnail-editor/ 7 Version: 2.17 Version: 3.0 8 8 Description: Little things that make using post thumbnails easier 9 9 */ … … 13 13 */ 14 14 define( 'PTX_DOMAIN', 'post-thumbnail-extras' ); 15 define( 'PTX_PLUGINURL', plugins_url(basename( dirname(__FILE__))) . "/"); 15 16 16 17 class PostThumbnailExtras { … … 33 34 */ 34 35 $this->load_requires(); 35 $s = new PTXShortcode();36 $o = new PTXOptions();37 36 } 38 37
Note: See TracChangeset
for help on using the changeset viewer.