Changeset 2885046
- Timestamp:
- 03/22/2023 03:16:40 PM (3 years ago)
- Location:
- kama-thumbnail
- Files:
-
- 2 added
- 10 edited
- 1 copied
-
tags/3.5.1 (copied) (copied from kama-thumbnail/trunk)
-
tags/3.5.1/classes/Helpers.php (modified) (1 diff)
-
tags/3.5.1/classes/Options.php (modified) (2 diffs)
-
tags/3.5.1/classes/Options_Page.php (modified) (7 diffs)
-
tags/3.5.1/classes/Options_Page_Fields.php (added)
-
tags/3.5.1/kama_thumbnail.php (modified) (1 diff)
-
tags/3.5.1/readme.txt (modified) (1 diff)
-
trunk/classes/Helpers.php (modified) (1 diff)
-
trunk/classes/Options.php (modified) (2 diffs)
-
trunk/classes/Options_Page.php (modified) (7 diffs)
-
trunk/classes/Options_Page_Fields.php (added)
-
trunk/kama_thumbnail.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kama-thumbnail/tags/3.5.1/classes/Helpers.php
r2836004 r2885046 14 14 */ 15 15 public static function parse_main_dom( string $host ): string { 16 17 $host = rtrim( $host, '/' ); 16 18 17 19 // URL passed OR port is specified (dom.site.ru:8080 > dom.site.ru) (59.120.54.215:8080 > 59.120.54.215) -
kama-thumbnail/tags/3.5.1/classes/Options.php
r2836004 r2885046 285 285 public function sanitize_options( array $opts ): array { 286 286 287 $defopt = (object) $this->get_default_options();288 289 287 foreach( $opts as $key => & $val ){ 290 288 291 if( $key === 'allow_hosts'){289 if( 'allow_hosts' === $key ){ 292 290 $ah = wp_parse_list( $val ); 293 291 … … 300 298 $val = array_unique( $ah ); 301 299 } 302 elseif( $key === 'meta_key' && ! $val ){ 303 304 $val = $defopt->meta_key; 305 } 306 elseif( $key === 'cache_dir' && $val ){ 307 $res = kthumb_cache()->check_cache_dir_path( $val ); 308 if( is_wp_error( $res ) ){ 309 $val = ''; 300 elseif( 'meta_key' === $key ){ 301 $val = sanitize_text_field( $val ?: self::$default_options['meta_key'] ); 302 } 303 elseif( 'cache_dir' === $key ){ 304 if( $val ){ 305 $res = kthumb_cache()->check_cache_dir_path( $val ); 306 if( is_wp_error( $res ) ){ 307 $val = ''; 308 } 310 309 } 311 310 } 312 elseif( $key === 'stop_creation_sec' ){ 313 314 $maxallowed = ini_get( 'max_execution_time' ) * 0.95; // -5% 315 $val = (float) $val; 316 $val = ( $val > $maxallowed || ! $val ) ? $maxallowed : $val; 311 elseif( 'stop_creation_sec' === $key ){ 312 $val = (float) ( $val ?: self::$default_options['stop_creation_sec'] ); 313 314 // NOTE: `max_execution_time` may be set to 0 - no limit. No restrict in this case. 315 $allowed_sec = ini_get( 'max_execution_time' ) * 0.95; // -5% 316 if( $allowed_sec && $val > $allowed_sec ){ 317 $val = $allowed_sec; 318 } 317 319 } 318 320 else { -
kama-thumbnail/tags/3.5.1/classes/Options_Page.php
r2836004 r2885046 18 18 } 19 19 20 self::$opt_page_key = is_multisite() ? 'kama_thumb' : 'media';20 self::$opt_page_key = 'kama_thumb'; 21 21 22 22 add_action( 'wp_ajax_ktclearcache', [ $this, 'cache_clear_ajax_handler' ] ); … … 24 24 if( ! defined( 'DOING_AJAX' ) ){ 25 25 26 add_action( ( is_multisite() ? 'network_admin_menu' : 'admin_menu' ), [ $this, ' _register_settings' ] );26 add_action( ( is_multisite() ? 'network_admin_menu' : 'admin_menu' ), [ $this, 'add_options_page' ] ); 27 27 28 28 // ссылка на настойки со страницы плагинов 29 add_filter( 'plugin_action_links', [ $this, ' _setting_page_link' ], 10, 2 );29 add_filter( 'plugin_action_links', [ $this, 'add_setting_page_in_plugin_links' ], 10, 2 ); 30 30 31 31 // обновления опций 32 32 if( is_multisite() ){ 33 add_action( 'network_admin_edit_ ' . 'kt_opt_up', [ $this, '_network_options_update_handler' ] );33 add_action( 'network_admin_edit_kt_opt_up', [ $this, '_network_options_update_handler' ] ); 34 34 } 35 35 } 36 } 37 38 public static function get_options_page_url(){ 39 40 return is_multisite() 41 ? network_admin_url( 'settings.php?page='. self::$opt_page_key ) 42 : admin_url( 'options-general.php?page=' . self::$opt_page_key ); 36 43 } 37 44 … … 66 73 } 67 74 68 public function _network_options_page_html(): void {69 ?>70 <form method="POST" action="edit.php?action=kt_opt_up" style="max-width:900px;">71 <?php72 // NOTE: settings_fields() is not suitable for a multisite...73 wp_nonce_field( self::$opt_page_key );74 do_settings_sections( self::$opt_page_key );75 submit_button();76 ?>77 </form>78 <?php79 }80 81 75 public function _network_options_update_handler(): void { 82 76 … … 87 81 kthumb_opt()->update_options( $new_opts ); 88 82 89 $settings_url = network_admin_url( 'settings.php?page='. self::$opt_page_key ); 90 wp_redirect( add_query_arg( 'updated', 'true', $settings_url ) ); 83 wp_redirect( add_query_arg( 'updated', 'true', self::get_options_page_url() ) ); 91 84 exit(); 92 85 } 93 86 94 public function _register_settings(): void { 95 96 if( ! is_multisite() ){ 87 public function add_options_page(): void { 88 89 if( is_multisite() ){ 90 $parent_slug = 'settings.php'; // a separate page for multisite 91 $capability = 'manage_network_options'; 92 } 93 else { 94 $parent_slug = 'options-general.php'; 95 $capability = 'manage_options'; 96 97 97 register_setting( self::$opt_page_key, kthumb_opt()->opt_name, [ kthumb_opt(), 'sanitize_options' ] ); 98 98 } 99 99 100 // for the multisite, a separate page is created in the network settings 101 if( is_multisite() ){ 102 103 $hook = add_submenu_page( 104 'settings.php', 105 'Kama Thumbnail', 106 'Kama Thumbnail', 107 'manage_network_options', 108 self::$opt_page_key, 109 [ $this, '_network_options_page_html' ] 110 ); 111 } 112 113 $section = 'kama_thumbnail_section'; 100 $hook = add_submenu_page( 101 $parent_slug, // `null` to hide page 102 __( 'Kama Thumbnail Settings', 'kama-thumbnail' ), 103 'Kama Thumbnail', 104 $capability, 105 self::$opt_page_key, 106 [ $this, '_options_page_html' ] 107 ); 108 109 if( ! $hook ){ 110 return; 111 } 112 113 add_action( "admin_print_scripts-$hook", static function(){ 114 self::styles(); 115 } ); 116 117 $section_name = 'kama_thumbnail_section'; 114 118 115 119 add_settings_section( 116 $section ,117 __( 'Kama Thumbnail Settings', 'kama-thumbnail' ),118 '',120 $section_name, 121 null, // title 122 null, // callback 119 123 self::$opt_page_key 120 124 ); … … 122 126 add_settings_field( 123 127 'kt_options_field', 124 $this->buttons_html(),125 [ $this, ' _options_field_html' ],128 self::buttons_html(), 129 [ $this, 'options_fields_html' ], 126 130 self::$opt_page_key, 127 $section // section 128 ); 129 130 } 131 132 private function buttons_html(){ 131 $section_name // section 132 ); 133 134 // Link to settings page from `options-media.php` page 135 136 add_settings_section( 137 $section_name, 138 'Kama Thumbnail', 139 static function(){ 140 echo sprintf( 'Moved to <a href="%s">settings page</a>.', self::get_options_page_url() ); 141 }, 142 'media' 143 ); 144 145 } 146 147 public function _options_page_html(): void { 148 149 $action_url = is_multisite() ? 'edit.php?action=kt_opt_up' : 'options.php'; 150 ?> 151 <div class="wrap"> 152 <h1><?= get_admin_page_title() ?></h1> 153 154 <form method="POST" action="<?= $action_url ?>" style="max-width: 1100px;"> 155 <?php 156 // NOTE: settings_fields() is not suitable for a multisite... 157 if( is_multisite() ){ 158 wp_nonce_field( self::$opt_page_key ); 159 } 160 else { 161 settings_fields( self::$opt_page_key ); 162 } 163 164 do_settings_sections( self::$opt_page_key ); 165 submit_button(); 166 ?> 167 </form> 168 </div> 169 <?php 170 } 171 172 private static function buttons_html(){ 133 173 ob_start(); 134 174 ?> … … 178 218 } 179 219 180 public function _options_field_html(): void { 181 182 $opt = new Options(); 183 $opt_name = $opt->opt_name; 184 185 $def_opt = (object) $opt->get_default_options(); 220 /** @private */ 221 public function add_setting_page_in_plugin_links( $actions, $plugin_file ){ 222 223 if( false === strpos( $plugin_file, basename( KTHUMB_DIR ) ) ){ 224 return $actions; 225 } 226 227 $settings_link = sprintf( '<a href="%s">%s</a>', self::get_options_page_url(), __( 'Settings', 'kama-thumbnail' ) ); 228 array_unshift( $actions, $settings_link ); 229 230 return $actions; 231 } 232 233 public function options_fields_html(): void { 234 235 $options = new Options(); 236 $fields = new Options_Page_Fields( $options ); 186 237 187 238 $elems = [ 188 '_delete_img_cache' => $this->clear_img_cache_field_html(), 189 190 'cache_dir' => 191 '<input type="text" name="'. $opt_name .'[cache_dir]" value="'. esc_attr( $opt->cache_dir ) .'" style="width:80%;" placeholder="'. esc_attr( kthumb_opt()->cache_dir ) .'">'. 192 '<p class="description">'. __('Full path to the cache folder with 755 rights or above.','kama-thumbnail') .'</p>', 193 194 'cache_dir_url' => 195 '<input type="text" name="'. $opt_name .'[cache_dir_url]" value="'. esc_attr( $opt->cache_dir_url ) .'" style="width:80%;" placeholder="'. esc_attr( kthumb_opt()->cache_dir_url ) .'"> 196 <p class="description">'. __('URL of cache folder.','kama-thumbnail') .' '. __('Must contain substring: cache or thumb.','kama-thumbnail') .'</p>', 197 198 'no_photo_url' => 199 '<input type="text" name="'. $opt_name .'[no_photo_url]" value="'. esc_attr( $opt->no_photo_url ) .'" style="width:80%;" placeholder="'. esc_attr( kthumb_opt()->no_photo_url ) .'"> 200 <p class="description">'. __('URL of stub image.','kama-thumbnail') .' '. __('Or WP attachment ID.','kama-thumbnail') .'</p>', 201 202 'meta_key' => 203 '<input type="text" name="'. $opt_name .'[meta_key]" value="'. esc_attr( $opt->meta_key ) .'" class="regular-text"> 204 <p class="description">'. __('Custom field key, where the thumb URL will be. Default:','kama-thumbnail') .' <code>'. esc_html( $def_opt->meta_key ) .'</code></p>', 205 206 'allow_hosts' => 207 '<textarea name="'. $opt_name .'[allow_hosts]" style="width:350px;height:45px;">'. esc_textarea( implode( "\n", $opt->allow_hosts ) ) .'</textarea> 208 <p class="description"><code>allow</code> '. __('Hosts from which thumbs can be created. One per line: <i>sub.mysite.com</i>. Specify <code>any</code>, to use any hosts.','kama-thumbnail') .'</p>', 209 210 'quality' => 211 '<code>quality</code> <input type="number" name="'. $opt_name .'[quality]" value="'. esc_attr( $opt->quality ) .'" style="width:60px;"> 212 <p class="description" style="display:inline-block;">'. __('Quality of creating thumbs from 0 to 100. Default:','kama-thumbnail') .' <code>'. $def_opt->quality .'</code></p>', 213 214 'no_stub' => ' 215 <label> 216 <input type="hidden" name="'. $opt_name .'[no_stub]" value="0"> 217 <input type="checkbox" name="'. $opt_name .'[no_stub]" value="1" '. checked( 1, @ $opt->no_stub, 0 ) .'> 218 <code>no_stub</code> '. __('Don\'t show nophoto image.','kama-thumbnail') .' 219 </label>', 220 221 'rise_small' => ' 222 <label> 223 <input type="hidden" name="'. $opt_name .'[rise_small]" value="0"> 224 <input type="checkbox" name="'. $opt_name .'[rise_small]" value="1" '. checked( 1, @ $opt->rise_small, 0 ) .'> 225 <code>rise_small=true</code> — '. __('Increase the thumbnail you create (width/height) if it is smaller than the specified size.','kama-thumbnail') .' 226 </label>', 227 228 'use_in_content' => ' 229 <input type="text" name="'. $opt_name .'[use_in_content]" value="'.( isset( $opt->use_in_content ) ? esc_attr( $opt->use_in_content ) : 'mini' ).'"> 230 <p class="description">'. 231 __( 'Find specified here class of IMG tag in content and make thumb from found image by it`s sizes.', 'kama-thumbnail' ) . 232 ' ' . 233 __( 'Leave this field empty to disable this function.', 'kama-thumbnail' ) . 234 '<br>' . 235 __( 'You can specify several classes, separated by comma or space: mini, size-large.', 'kama-thumbnail' ) . 236 '<br>' . 237 sprintf( __( 'Default: %s', 'kama-thumbnail' ), '<code>mini</code>' ) . 238 '</p>', 239 240 'auto_clear' => ' 241 <label> 242 <input type="hidden" name="'. $opt_name .'[auto_clear]" value="0"> 243 <input type="checkbox" name="'. $opt_name .'[auto_clear]" value="1" '. checked( 1, @ $opt->auto_clear, 0 ) .'> 244 '. sprintf( 245 __('Clear all cache automaticaly every %s days.','kama-thumbnail'), 246 '<input type="number" name="'. $opt_name .'[auto_clear_days]" value="'. @ $opt->auto_clear_days .'" style="width:50px;">' 247 ) .' 248 </label>', 249 250 'stop_creation_sec' => ' 251 <input type="number" step="0.5" name="'. $opt_name .'[stop_creation_sec]" value="'.( isset($opt->stop_creation_sec) ? esc_attr($opt->stop_creation_sec) : 20 ).'" style="width:4rem;"> '. __('seconds','kama-thumbnail') .' 252 <p class="description" style="display:inline-block;">'. sprintf( __('The maximum number of seconds since PHP started, after which thumbnails creation will be stopped. Must be less then %s (current PHP `max_execution_time`).','kama-thumbnail'), ini_get('max_execution_time') ) .'</p>', 253 239 '_delete_img_cache' => $fields->delete_img_cache(), 240 'cache_dir' => $fields->cache_dir(), 241 'cache_dir_url' => $fields->cache_dir_url(), 242 'no_photo_url' => $fields->no_photo_url(), 243 'meta_key' => $fields->meta_key(), 244 'allow_hosts' => $fields->allow_hosts(), 245 'quality' => $fields->quality(), 246 'no_stub' => $fields->no_stub(), 247 'rise_small' => $fields->rise_small(), 248 'use_in_content' => $fields->use_in_content(), 249 'auto_clear' => $fields->auto_clear(), 250 'stop_creation_sec' => $fields->stop_creation_sec(), 254 251 ]; 255 252 256 $elems = apply_filters( 'kama_thumb__options_field_elems', $elems, $opt_name, $opt, $def_opt ); 257 258 $elems['debug'] = ' 259 <label> 260 <input type="hidden" name="'. $opt_name .'[debug]" value="0"> 261 <input type="checkbox" name="'. $opt_name .'[debug]" value="1" '. checked( 1, @ $opt->debug, 0 ) .'> 262 '. __('Debug mode. Recreates thumbs all time (disables the cache).','kama-thumbnail') .' 263 </label>'; 264 265 ?> 266 <style> 267 .ktumb-line{ padding-bottom:1.5em; } 268 </style> 269 <?php 253 $elems = apply_filters( 'kama_thumb__options_field_elems', $elems, $options ); 254 255 $elems['debug'] = $fields->debug(); // at bottom 256 270 257 foreach( $elems as $elem ){ 271 258 ?> … … 273 260 <?php 274 261 } 275 276 } 277 278 private function clear_img_cache_field_html(){ 279 ob_start(); 262 } 263 264 protected static function styles(): void { 280 265 ?> 281 <div> 282 <button type="button" class="button" onclick="window.ktclearcache( 'rm_img_cache', this.nextElementSibling.value )"><?= __( 'Clear IMG cache', 'kama-thumbnail' ) ?></button> 283 <input type="text" value="" style="width:71%;" placeholder="<?= __( 'Image/Thumb URL or attachment ID', 'kama-thumbnail' ) ?>"> 284 </div> 285 <p class="description"> 286 <?= __( 'Clears all chached files of single IMG. The URL format can be any of:', 'kama-thumbnail' ) ?> 287 <code>http://dom/path.jpg</code> 288 <code>https://dom/path.jpg</code> 289 <code>//dom/path.jpg</code> 290 <code>/path.jpg</code> 291 </p> 266 <style> 267 .ktumb-line{ padding-bottom: 1.5em; } 268 </style> 292 269 <?php 293 return ob_get_clean(); 294 } 295 296 public function _setting_page_link( $actions, $plugin_file ){ 297 298 if( false === strpos( $plugin_file, basename( KTHUMB_DIR ) ) ){ 299 return $actions; 300 } 301 302 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-media.php' ), __( 'Settings', 'kama-thumbnail' ) ); 303 array_unshift( $actions, $settings_link ); 304 305 return $actions; 306 } 307 270 } 308 271 } 309 272 -
kama-thumbnail/tags/3.5.1/kama_thumbnail.php
r2836004 r2885046 15 15 * Requires at least: 4.7 16 16 * 17 * Version: 3.5. 017 * Version: 3.5.1 18 18 */ 19 19 -
kama-thumbnail/tags/3.5.1/readme.txt
r2836004 r2885046 311 311 312 312 == Changelog == 313 314 = 3.5.1 = 315 - CHG: Options Page Moved from Media page to separate page. 316 - CHG: Minor improvements. 317 - IMP: Note if `ini_get( 'max_execution_time' ) === 0`. 313 318 314 319 = 3.5.0 = -
kama-thumbnail/trunk/classes/Helpers.php
r2836004 r2885046 14 14 */ 15 15 public static function parse_main_dom( string $host ): string { 16 17 $host = rtrim( $host, '/' ); 16 18 17 19 // URL passed OR port is specified (dom.site.ru:8080 > dom.site.ru) (59.120.54.215:8080 > 59.120.54.215) -
kama-thumbnail/trunk/classes/Options.php
r2836004 r2885046 285 285 public function sanitize_options( array $opts ): array { 286 286 287 $defopt = (object) $this->get_default_options();288 289 287 foreach( $opts as $key => & $val ){ 290 288 291 if( $key === 'allow_hosts'){289 if( 'allow_hosts' === $key ){ 292 290 $ah = wp_parse_list( $val ); 293 291 … … 300 298 $val = array_unique( $ah ); 301 299 } 302 elseif( $key === 'meta_key' && ! $val ){ 303 304 $val = $defopt->meta_key; 305 } 306 elseif( $key === 'cache_dir' && $val ){ 307 $res = kthumb_cache()->check_cache_dir_path( $val ); 308 if( is_wp_error( $res ) ){ 309 $val = ''; 300 elseif( 'meta_key' === $key ){ 301 $val = sanitize_text_field( $val ?: self::$default_options['meta_key'] ); 302 } 303 elseif( 'cache_dir' === $key ){ 304 if( $val ){ 305 $res = kthumb_cache()->check_cache_dir_path( $val ); 306 if( is_wp_error( $res ) ){ 307 $val = ''; 308 } 310 309 } 311 310 } 312 elseif( $key === 'stop_creation_sec' ){ 313 314 $maxallowed = ini_get( 'max_execution_time' ) * 0.95; // -5% 315 $val = (float) $val; 316 $val = ( $val > $maxallowed || ! $val ) ? $maxallowed : $val; 311 elseif( 'stop_creation_sec' === $key ){ 312 $val = (float) ( $val ?: self::$default_options['stop_creation_sec'] ); 313 314 // NOTE: `max_execution_time` may be set to 0 - no limit. No restrict in this case. 315 $allowed_sec = ini_get( 'max_execution_time' ) * 0.95; // -5% 316 if( $allowed_sec && $val > $allowed_sec ){ 317 $val = $allowed_sec; 318 } 317 319 } 318 320 else { -
kama-thumbnail/trunk/classes/Options_Page.php
r2836004 r2885046 18 18 } 19 19 20 self::$opt_page_key = is_multisite() ? 'kama_thumb' : 'media';20 self::$opt_page_key = 'kama_thumb'; 21 21 22 22 add_action( 'wp_ajax_ktclearcache', [ $this, 'cache_clear_ajax_handler' ] ); … … 24 24 if( ! defined( 'DOING_AJAX' ) ){ 25 25 26 add_action( ( is_multisite() ? 'network_admin_menu' : 'admin_menu' ), [ $this, ' _register_settings' ] );26 add_action( ( is_multisite() ? 'network_admin_menu' : 'admin_menu' ), [ $this, 'add_options_page' ] ); 27 27 28 28 // ссылка на настойки со страницы плагинов 29 add_filter( 'plugin_action_links', [ $this, ' _setting_page_link' ], 10, 2 );29 add_filter( 'plugin_action_links', [ $this, 'add_setting_page_in_plugin_links' ], 10, 2 ); 30 30 31 31 // обновления опций 32 32 if( is_multisite() ){ 33 add_action( 'network_admin_edit_ ' . 'kt_opt_up', [ $this, '_network_options_update_handler' ] );33 add_action( 'network_admin_edit_kt_opt_up', [ $this, '_network_options_update_handler' ] ); 34 34 } 35 35 } 36 } 37 38 public static function get_options_page_url(){ 39 40 return is_multisite() 41 ? network_admin_url( 'settings.php?page='. self::$opt_page_key ) 42 : admin_url( 'options-general.php?page=' . self::$opt_page_key ); 36 43 } 37 44 … … 66 73 } 67 74 68 public function _network_options_page_html(): void {69 ?>70 <form method="POST" action="edit.php?action=kt_opt_up" style="max-width:900px;">71 <?php72 // NOTE: settings_fields() is not suitable for a multisite...73 wp_nonce_field( self::$opt_page_key );74 do_settings_sections( self::$opt_page_key );75 submit_button();76 ?>77 </form>78 <?php79 }80 81 75 public function _network_options_update_handler(): void { 82 76 … … 87 81 kthumb_opt()->update_options( $new_opts ); 88 82 89 $settings_url = network_admin_url( 'settings.php?page='. self::$opt_page_key ); 90 wp_redirect( add_query_arg( 'updated', 'true', $settings_url ) ); 83 wp_redirect( add_query_arg( 'updated', 'true', self::get_options_page_url() ) ); 91 84 exit(); 92 85 } 93 86 94 public function _register_settings(): void { 95 96 if( ! is_multisite() ){ 87 public function add_options_page(): void { 88 89 if( is_multisite() ){ 90 $parent_slug = 'settings.php'; // a separate page for multisite 91 $capability = 'manage_network_options'; 92 } 93 else { 94 $parent_slug = 'options-general.php'; 95 $capability = 'manage_options'; 96 97 97 register_setting( self::$opt_page_key, kthumb_opt()->opt_name, [ kthumb_opt(), 'sanitize_options' ] ); 98 98 } 99 99 100 // for the multisite, a separate page is created in the network settings 101 if( is_multisite() ){ 102 103 $hook = add_submenu_page( 104 'settings.php', 105 'Kama Thumbnail', 106 'Kama Thumbnail', 107 'manage_network_options', 108 self::$opt_page_key, 109 [ $this, '_network_options_page_html' ] 110 ); 111 } 112 113 $section = 'kama_thumbnail_section'; 100 $hook = add_submenu_page( 101 $parent_slug, // `null` to hide page 102 __( 'Kama Thumbnail Settings', 'kama-thumbnail' ), 103 'Kama Thumbnail', 104 $capability, 105 self::$opt_page_key, 106 [ $this, '_options_page_html' ] 107 ); 108 109 if( ! $hook ){ 110 return; 111 } 112 113 add_action( "admin_print_scripts-$hook", static function(){ 114 self::styles(); 115 } ); 116 117 $section_name = 'kama_thumbnail_section'; 114 118 115 119 add_settings_section( 116 $section ,117 __( 'Kama Thumbnail Settings', 'kama-thumbnail' ),118 '',120 $section_name, 121 null, // title 122 null, // callback 119 123 self::$opt_page_key 120 124 ); … … 122 126 add_settings_field( 123 127 'kt_options_field', 124 $this->buttons_html(),125 [ $this, ' _options_field_html' ],128 self::buttons_html(), 129 [ $this, 'options_fields_html' ], 126 130 self::$opt_page_key, 127 $section // section 128 ); 129 130 } 131 132 private function buttons_html(){ 131 $section_name // section 132 ); 133 134 // Link to settings page from `options-media.php` page 135 136 add_settings_section( 137 $section_name, 138 'Kama Thumbnail', 139 static function(){ 140 echo sprintf( 'Moved to <a href="%s">settings page</a>.', self::get_options_page_url() ); 141 }, 142 'media' 143 ); 144 145 } 146 147 public function _options_page_html(): void { 148 149 $action_url = is_multisite() ? 'edit.php?action=kt_opt_up' : 'options.php'; 150 ?> 151 <div class="wrap"> 152 <h1><?= get_admin_page_title() ?></h1> 153 154 <form method="POST" action="<?= $action_url ?>" style="max-width: 1100px;"> 155 <?php 156 // NOTE: settings_fields() is not suitable for a multisite... 157 if( is_multisite() ){ 158 wp_nonce_field( self::$opt_page_key ); 159 } 160 else { 161 settings_fields( self::$opt_page_key ); 162 } 163 164 do_settings_sections( self::$opt_page_key ); 165 submit_button(); 166 ?> 167 </form> 168 </div> 169 <?php 170 } 171 172 private static function buttons_html(){ 133 173 ob_start(); 134 174 ?> … … 178 218 } 179 219 180 public function _options_field_html(): void { 181 182 $opt = new Options(); 183 $opt_name = $opt->opt_name; 184 185 $def_opt = (object) $opt->get_default_options(); 220 /** @private */ 221 public function add_setting_page_in_plugin_links( $actions, $plugin_file ){ 222 223 if( false === strpos( $plugin_file, basename( KTHUMB_DIR ) ) ){ 224 return $actions; 225 } 226 227 $settings_link = sprintf( '<a href="%s">%s</a>', self::get_options_page_url(), __( 'Settings', 'kama-thumbnail' ) ); 228 array_unshift( $actions, $settings_link ); 229 230 return $actions; 231 } 232 233 public function options_fields_html(): void { 234 235 $options = new Options(); 236 $fields = new Options_Page_Fields( $options ); 186 237 187 238 $elems = [ 188 '_delete_img_cache' => $this->clear_img_cache_field_html(), 189 190 'cache_dir' => 191 '<input type="text" name="'. $opt_name .'[cache_dir]" value="'. esc_attr( $opt->cache_dir ) .'" style="width:80%;" placeholder="'. esc_attr( kthumb_opt()->cache_dir ) .'">'. 192 '<p class="description">'. __('Full path to the cache folder with 755 rights or above.','kama-thumbnail') .'</p>', 193 194 'cache_dir_url' => 195 '<input type="text" name="'. $opt_name .'[cache_dir_url]" value="'. esc_attr( $opt->cache_dir_url ) .'" style="width:80%;" placeholder="'. esc_attr( kthumb_opt()->cache_dir_url ) .'"> 196 <p class="description">'. __('URL of cache folder.','kama-thumbnail') .' '. __('Must contain substring: cache or thumb.','kama-thumbnail') .'</p>', 197 198 'no_photo_url' => 199 '<input type="text" name="'. $opt_name .'[no_photo_url]" value="'. esc_attr( $opt->no_photo_url ) .'" style="width:80%;" placeholder="'. esc_attr( kthumb_opt()->no_photo_url ) .'"> 200 <p class="description">'. __('URL of stub image.','kama-thumbnail') .' '. __('Or WP attachment ID.','kama-thumbnail') .'</p>', 201 202 'meta_key' => 203 '<input type="text" name="'. $opt_name .'[meta_key]" value="'. esc_attr( $opt->meta_key ) .'" class="regular-text"> 204 <p class="description">'. __('Custom field key, where the thumb URL will be. Default:','kama-thumbnail') .' <code>'. esc_html( $def_opt->meta_key ) .'</code></p>', 205 206 'allow_hosts' => 207 '<textarea name="'. $opt_name .'[allow_hosts]" style="width:350px;height:45px;">'. esc_textarea( implode( "\n", $opt->allow_hosts ) ) .'</textarea> 208 <p class="description"><code>allow</code> '. __('Hosts from which thumbs can be created. One per line: <i>sub.mysite.com</i>. Specify <code>any</code>, to use any hosts.','kama-thumbnail') .'</p>', 209 210 'quality' => 211 '<code>quality</code> <input type="number" name="'. $opt_name .'[quality]" value="'. esc_attr( $opt->quality ) .'" style="width:60px;"> 212 <p class="description" style="display:inline-block;">'. __('Quality of creating thumbs from 0 to 100. Default:','kama-thumbnail') .' <code>'. $def_opt->quality .'</code></p>', 213 214 'no_stub' => ' 215 <label> 216 <input type="hidden" name="'. $opt_name .'[no_stub]" value="0"> 217 <input type="checkbox" name="'. $opt_name .'[no_stub]" value="1" '. checked( 1, @ $opt->no_stub, 0 ) .'> 218 <code>no_stub</code> '. __('Don\'t show nophoto image.','kama-thumbnail') .' 219 </label>', 220 221 'rise_small' => ' 222 <label> 223 <input type="hidden" name="'. $opt_name .'[rise_small]" value="0"> 224 <input type="checkbox" name="'. $opt_name .'[rise_small]" value="1" '. checked( 1, @ $opt->rise_small, 0 ) .'> 225 <code>rise_small=true</code> — '. __('Increase the thumbnail you create (width/height) if it is smaller than the specified size.','kama-thumbnail') .' 226 </label>', 227 228 'use_in_content' => ' 229 <input type="text" name="'. $opt_name .'[use_in_content]" value="'.( isset( $opt->use_in_content ) ? esc_attr( $opt->use_in_content ) : 'mini' ).'"> 230 <p class="description">'. 231 __( 'Find specified here class of IMG tag in content and make thumb from found image by it`s sizes.', 'kama-thumbnail' ) . 232 ' ' . 233 __( 'Leave this field empty to disable this function.', 'kama-thumbnail' ) . 234 '<br>' . 235 __( 'You can specify several classes, separated by comma or space: mini, size-large.', 'kama-thumbnail' ) . 236 '<br>' . 237 sprintf( __( 'Default: %s', 'kama-thumbnail' ), '<code>mini</code>' ) . 238 '</p>', 239 240 'auto_clear' => ' 241 <label> 242 <input type="hidden" name="'. $opt_name .'[auto_clear]" value="0"> 243 <input type="checkbox" name="'. $opt_name .'[auto_clear]" value="1" '. checked( 1, @ $opt->auto_clear, 0 ) .'> 244 '. sprintf( 245 __('Clear all cache automaticaly every %s days.','kama-thumbnail'), 246 '<input type="number" name="'. $opt_name .'[auto_clear_days]" value="'. @ $opt->auto_clear_days .'" style="width:50px;">' 247 ) .' 248 </label>', 249 250 'stop_creation_sec' => ' 251 <input type="number" step="0.5" name="'. $opt_name .'[stop_creation_sec]" value="'.( isset($opt->stop_creation_sec) ? esc_attr($opt->stop_creation_sec) : 20 ).'" style="width:4rem;"> '. __('seconds','kama-thumbnail') .' 252 <p class="description" style="display:inline-block;">'. sprintf( __('The maximum number of seconds since PHP started, after which thumbnails creation will be stopped. Must be less then %s (current PHP `max_execution_time`).','kama-thumbnail'), ini_get('max_execution_time') ) .'</p>', 253 239 '_delete_img_cache' => $fields->delete_img_cache(), 240 'cache_dir' => $fields->cache_dir(), 241 'cache_dir_url' => $fields->cache_dir_url(), 242 'no_photo_url' => $fields->no_photo_url(), 243 'meta_key' => $fields->meta_key(), 244 'allow_hosts' => $fields->allow_hosts(), 245 'quality' => $fields->quality(), 246 'no_stub' => $fields->no_stub(), 247 'rise_small' => $fields->rise_small(), 248 'use_in_content' => $fields->use_in_content(), 249 'auto_clear' => $fields->auto_clear(), 250 'stop_creation_sec' => $fields->stop_creation_sec(), 254 251 ]; 255 252 256 $elems = apply_filters( 'kama_thumb__options_field_elems', $elems, $opt_name, $opt, $def_opt ); 257 258 $elems['debug'] = ' 259 <label> 260 <input type="hidden" name="'. $opt_name .'[debug]" value="0"> 261 <input type="checkbox" name="'. $opt_name .'[debug]" value="1" '. checked( 1, @ $opt->debug, 0 ) .'> 262 '. __('Debug mode. Recreates thumbs all time (disables the cache).','kama-thumbnail') .' 263 </label>'; 264 265 ?> 266 <style> 267 .ktumb-line{ padding-bottom:1.5em; } 268 </style> 269 <?php 253 $elems = apply_filters( 'kama_thumb__options_field_elems', $elems, $options ); 254 255 $elems['debug'] = $fields->debug(); // at bottom 256 270 257 foreach( $elems as $elem ){ 271 258 ?> … … 273 260 <?php 274 261 } 275 276 } 277 278 private function clear_img_cache_field_html(){ 279 ob_start(); 262 } 263 264 protected static function styles(): void { 280 265 ?> 281 <div> 282 <button type="button" class="button" onclick="window.ktclearcache( 'rm_img_cache', this.nextElementSibling.value )"><?= __( 'Clear IMG cache', 'kama-thumbnail' ) ?></button> 283 <input type="text" value="" style="width:71%;" placeholder="<?= __( 'Image/Thumb URL or attachment ID', 'kama-thumbnail' ) ?>"> 284 </div> 285 <p class="description"> 286 <?= __( 'Clears all chached files of single IMG. The URL format can be any of:', 'kama-thumbnail' ) ?> 287 <code>http://dom/path.jpg</code> 288 <code>https://dom/path.jpg</code> 289 <code>//dom/path.jpg</code> 290 <code>/path.jpg</code> 291 </p> 266 <style> 267 .ktumb-line{ padding-bottom: 1.5em; } 268 </style> 292 269 <?php 293 return ob_get_clean(); 294 } 295 296 public function _setting_page_link( $actions, $plugin_file ){ 297 298 if( false === strpos( $plugin_file, basename( KTHUMB_DIR ) ) ){ 299 return $actions; 300 } 301 302 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-media.php' ), __( 'Settings', 'kama-thumbnail' ) ); 303 array_unshift( $actions, $settings_link ); 304 305 return $actions; 306 } 307 270 } 308 271 } 309 272 -
kama-thumbnail/trunk/kama_thumbnail.php
r2836004 r2885046 15 15 * Requires at least: 4.7 16 16 * 17 * Version: 3.5. 017 * Version: 3.5.1 18 18 */ 19 19 -
kama-thumbnail/trunk/readme.txt
r2836004 r2885046 311 311 312 312 == Changelog == 313 314 = 3.5.1 = 315 - CHG: Options Page Moved from Media page to separate page. 316 - CHG: Minor improvements. 317 - IMP: Note if `ini_get( 'max_execution_time' ) === 0`. 313 318 314 319 = 3.5.0 =
Note: See TracChangeset
for help on using the changeset viewer.