Changeset 2752289
- Timestamp:
- 07/05/2022 10:52:46 PM (4 years ago)
- Location:
- fws-resize-on-demand/trunk
- Files:
-
- 5 edited
-
fws-resize-on-demand.php (modified) (2 diffs)
-
src/Dashboard.php (modified) (8 diffs)
-
src/Hooks.php (modified) (9 diffs)
-
src/templates/settings.php (modified) (3 diffs)
-
src/templates/utils.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fws-resize-on-demand/trunk/fws-resize-on-demand.php
r2696272 r2752289 5 5 * Plugin URI: https://wordpress.org/plugins/fws-resize-on-demand 6 6 * Description: On-demand image resizer for WordPress. 7 * Version: 0.3. 37 * Version: 0.3.4 8 8 * Author: Miroslav Curcic 9 9 * Author URI: https://profiles.wordpress.org/tekod 10 * Text Domain: fws-rod 11 * Domain Path: /languages 12 * Requires at least: 4.8 10 13 */ 11 14 … … 16 19 define('FWS_ROD_PLUGINBASENAME', plugin_basename(__FILE__)); 17 20 define('FWS_ROD_DIR', __DIR__); 18 define('FWS_ROD_VERSION', '0.3. 3');21 define('FWS_ROD_VERSION', '0.3.4'); 19 22 20 23 -
fws-resize-on-demand/trunk/src/Dashboard.php
r2636601 r2752289 106 106 // wrapper and <h1> 107 107 echo '<div class="fws_rod">'; 108 echo '<h1> Resize on demand</h1>';108 echo '<h1>' . __('Resize on demand', 'fws-rod') . '</h1>'; 109 109 echo '<hr>'; 110 110 … … 130 130 //$URL= admin_url( 'options-general.php?page='.self::$AdminPageSlug.'&tab='.esc_attr($Slug)); 131 131 $Class= $CurrentTab === $Slug ? 'nav-tab nav-tab-active' : 'nav-tab'; 132 $Tabs .= '<a href="javascript:FwsRodTab(\''.$Slug.'\')" id="fws_rod_tab_'.$Slug.'" class="'.$Class.'">'.esc_html ($Label).'</a>';132 $Tabs .= '<a href="javascript:FwsRodTab(\''.$Slug.'\')" id="fws_rod_tab_'.$Slug.'" class="'.$Class.'">'.esc_html__($Label, 'fws-rod').'</a>'; 133 133 } 134 134 … … 167 167 168 168 // prepare confirmation message 169 set_transient(self::$AdminMsgTransient.'_msg', 'updated- Settings saved.');169 set_transient(self::$AdminMsgTransient.'_msg', 'updated-' . __('Settings saved.')); 170 170 } 171 171 … … 208 208 209 209 // prepare confirmation message 210 set_transient(self::$AdminMsgTransient.'_msg', "updated-Removed $TotalCount thumbnails.");210 set_transient(self::$AdminMsgTransient.'_msg', 'updated-' . sprintf(__('Removed %n thumbnails.', 'fws-rod'), $TotalCount)); 211 211 } 212 212 … … 235 235 236 236 // prepare confirmation message 237 set_transient(self::$AdminMsgTransient.'_msg', 'updated- Settings saved.');237 set_transient(self::$AdminMsgTransient.'_msg', 'updated-' . __('Settings saved.')); 238 238 } 239 239 … … 265 265 266 266 // check each size 267 $ExistingSizes = array_keys($Meta['sizes']); 267 268 foreach ($Meta['sizes'] as $Key => $SizePack) { 268 269 … … 287 288 if ($NeedUpdateMeta) { 288 289 wp_update_attachment_metadata($Attachment['post_id'], $Meta); 290 $Removed = implode(',', array_diff($ExistingSizes, array_keys($Meta['sizes']))); 291 $Left = implode(',', array_keys($Meta['sizes'])); 292 Services::Log("Deleted thumbnails of post #$Attachment[post_id]: [$Removed], Left: [$Left]"); 289 293 } 290 294 … … 303 307 304 308 if (!wp_verify_nonce($_POST[Config::$OptionName.'_nonce'], $Action)) { 305 set_transient(self::$AdminMsgTransient.'_msg', 'error- Session expired, please try again.');309 set_transient(self::$AdminMsgTransient.'_msg', 'error-' . __('Session expired, please try again.', 'fws-rod')); 306 310 return false; 307 311 } 308 312 if (!isset($_POST['_wp_http_referer'])) { 309 set_transient(self::$AdminMsgTransient.'_msg', 'error- Missing target.');313 set_transient(self::$AdminMsgTransient.'_msg', 'error-' . __('Missing target.', 'fws-rod')); 310 314 return false; 311 315 } -
fws-resize-on-demand/trunk/src/Hooks.php
r2638271 r2752289 6 6 */ 7 7 class Hooks { 8 9 10 // current image meta-data 11 protected static $ImageMetaData; 8 12 9 13 … … 49 53 50 54 // skip if thumbnail already exists 51 $ImageData = wp_get_attachment_metadata($Id);52 if (is_array( $ImageData) && isset($ImageData['sizes'][$Size])) {55 self::$ImageMetaData = wp_get_attachment_metadata($Id); 56 if (is_array(self::$ImageMetaData) && isset(self::$ImageMetaData['sizes'][$Size])) { 53 57 Services::Log('Thumb already exist. Skip.'); 54 58 return false; … … 56 60 57 61 // skip if $Id does not refer to a valid attachment 58 if ( $ImageData === false) {62 if (self::$ImageMetaData === false) { 59 63 Services::Log('Attachment data not found. Skip.'); 60 64 return false; … … 62 66 63 67 // resize now 64 return self::Resize($I mageData, $Id, $Size);68 return self::Resize($Id, $Size); 65 69 } 66 70 … … 80 84 * Resize image. 81 85 * 82 * @param array $ImageData83 86 * @param int $Id 84 87 * @param string $Size 85 88 * @return array|false 86 89 */ 87 protected static function Resize($I mageData, $Id, $Size) {90 protected static function Resize($Id, $Size) { 88 91 89 92 $RegisteredSizes= self::GetRegisteredSizes(); … … 91 94 92 95 // log event 93 Services::Log("Resize ' $ImageData[file]' to '$Size' size ($SizeData[width]x$SizeData[height])", true);96 Services::Log("Resize '".self::$ImageMetaData['file']."' to '$Size' size ($SizeData[width]x$SizeData[height])", true); 94 97 95 98 // first search for higher-resolution sizes to properly create "srcset" 96 99 $HighResolutionPattern = '/^' . preg_quote($Size, '/') . '@[1-9]+(\\.[0-9]+)?x$/'; 97 100 foreach ($RegisteredSizes as $SubName => $SubData) { 98 if (!isset( $ImageData['sizes'][$SubName]) && preg_match($HighResolutionPattern, $SubName)) {101 if (!isset(self::$ImageMetaData['sizes'][$SubName]) && preg_match($HighResolutionPattern, $SubName)) { 99 102 Services::Log("Resize to higher-resolution size '$SubName'."); 100 self::ResizeSingleImage($I mageData, $Id, $SubName, $SubData); // resize and ignore result103 self::ResizeSingleImage($Id, $SubName, $SubData); // resize and ignore result 101 104 } 102 105 } 103 106 104 107 // now resize image to requested image-size 105 return self::ResizeSingleImage($I mageData, $Id, $Size, $SizeData);108 return self::ResizeSingleImage($Id, $Size, $SizeData); 106 109 } 107 110 … … 110 113 * Perform actual image resizing. 111 114 * 112 * @param array $ImageData113 115 * @param int $Id 114 116 * @param string $SizeName … … 116 118 * @return array|false 117 119 */ 118 protected static function ResizeSingleImage($I mageData, $Id, $SizeName, $SizeData) {120 protected static function ResizeSingleImage($Id, $SizeName, $SizeData) { 119 121 120 122 // make the new thumb … … 131 133 132 134 // save image meta, or WP can't see that the thumb exists now 133 $ImageData['sizes'][$SizeName]= $Resized;134 wp_update_attachment_metadata($Id, $ImageData);135 self::$ImageMetaData['sizes'][$SizeName]= $Resized; 136 wp_update_attachment_metadata($Id, self::$ImageMetaData); 135 137 136 138 // log event 137 139 Services::Log("Successfully created '$Resized[file]'."); 140 Services::Log('ImageMetaData: '.json_encode(self::$ImageMetaData['sizes'])); 138 141 139 142 // return the array for displaying the resized image -
fws-resize-on-demand/trunk/src/templates/settings.php
r2636601 r2752289 64 64 } 65 65 </style> 66 <h3> Apply on-demand resizing on these image sizes:</h3>66 <h3><?=esc_html__('Apply on-demand resizing on these image sizes:', 'fws-rod')?></h3> 67 67 <form id="RodSettingsForm" action="admin-post.php" method="post"> 68 68 <table> 69 69 <tr> 70 70 <td colspan="2"> 71 <a href="javascript:FwsRodCheckAll();"> Check all</a>71 <a href="javascript:FwsRodCheckAll();"><?=esc_html__('Check all', 'fws-rod')?></a> 72 72 </td> 73 73 </tr> … … 82 82 $Checked= ' checked'; 83 83 $Disabled= ' disabled'; 84 $Notice= 'This size has been enabled programmatically.';84 $Notice= esc_html__('This size has been enabled programmatically.', 'fws-rod'); 85 85 } 86 86 if (in_array($Key, $ForceDisableSizes)) { 87 87 $Checked= ''; 88 88 $Disabled= ' disabled'; 89 $Notice= 'This size has been disabled programmatically.';89 $Notice= esc_html__('This size has been disabled programmatically.', 'fws-rod'); 90 90 } 91 91 ?> … … 110 110 </table> 111 111 <div style="padding:1em 0 0 1em; color:gray"> 112 Total: <?php echo count($Sizes); ?> registered sizes112 <?=esc_html(sprintf(__('Total: %d registered sizes', 'fws-rod'), count($Sizes)))?> 113 113 </div> 114 114 <?php submit_button(); ?> -
fws-resize-on-demand/trunk/src/templates/utils.php
r2636601 r2752289 22 22 <div> 23 23 <form action="admin-post.php" method="post" class="utils-form"> 24 Delete all thumbnails at sizes that we handle so they can be re-created on demand.25 <?php submit_button( 'Delete', 'primary large', 'submit'); ?>24 <?=esc_html__('Delete all thumbnails at sizes that we handle so they can be re-created on demand.', 'fws-rod')?> 25 <?php submit_button(__('Delete'), 'primary large', 'submit'); ?> 26 26 <input type="hidden" name="action" value="<?php echo esc_attr($ActionDel); ?>"> 27 27 <?php wp_nonce_field($ActionDel, $OptionName.'_nonce', false); ?> … … 30 30 31 31 <form action="admin-post.php" method="post" class="utils-form"> 32 Enable debug logging to trace sources of image resizing.32 <?=esc_html__('Enable debug logging to trace sources of image resizing.', 'fws-rod')?> 33 33 <div style="padding:2em 0 0 0"> 34 34 <input type="checkbox" name="fws_ROD_Logging" id="fws_ROD_Logging" value="1"<?php checked($IsLoggingEnabled); ?>> 35 <label for="fws_ROD_Logging"> Enable debug logging</label>35 <label for="fws_ROD_Logging"><?=esc_html__('Enable debug logging', 'fws-rod')?></label> 36 36 </div> 37 <?php submit_button( 'Save choice', 'primary large', 'submit'); ?>37 <?php submit_button(__('Save Changes'), 'primary large', 'submit'); ?> 38 38 <input type="hidden" name="action" value="<?php echo esc_attr($ActionLog); ?>"> 39 39 <?php wp_nonce_field($ActionLog, $OptionName.'_nonce', false); ?> 40 40 <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr($RedirectURL); ?>"> 41 41 <div style="padding: 1em 0 2em 0"> 42 Log file is located at:<br><?php echo esc_html($LogFilePath); ?> 42 <?=esc_html__('Log file is located at:', 'fws-rod')?> 43 <br> 44 <?=esc_html($LogFilePath)?> 43 45 </div> 44 46 </form>
Note: See TracChangeset
for help on using the changeset viewer.