From a3c23f2430714e13149be56e420cfca3a6e6daea Mon Sep 17 00:00:00 2001 From: Volkmar Kantor Date: Sat, 22 Aug 2015 10:08:55 +0200 Subject: [PATCH 01/18] refactoring of getImageSizes based on http://codex.wordpress.org/Function_Reference/get_intermediate_image_sizes --- functions/settings.php | 103 ++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 59 deletions(-) diff --git a/functions/settings.php b/functions/settings.php index b10e6b5..5d52bae 100644 --- a/functions/settings.php +++ b/functions/settings.php @@ -4,7 +4,7 @@ class CropThumbnailsSettings { private $optionsKey = 'crop-post-thumbs'; private $cssPrefix = 'cpt_settings_'; private $standardSizes = array('thumbnail','medium','large'); - + function __construct() { add_action('admin_menu', array($this,'addOptionsPage')); if(is_admin()) { @@ -12,26 +12,26 @@ function __construct() { add_action('admin_head', array($this,'optionsPageStyle')); } } - + function optionsPageStyle() { if(!empty($_REQUEST['page']) && $_REQUEST['page']=='page-cpt') { wp_enqueue_style('crop-thumbnails-options-style',plugins_url('css/options.css',dirname(__FILE__))); } } - + function addSettingsLinkToPluginPage($links, $file) { - if ($file === 'crop-thumbnails/crop-thumbnails.php'){ - $settings_link = ''.__('Settings',CROP_THUMBS_LANG).''; - array_unshift( $links, $settings_link ); - } - return $links; + if ($file === 'crop-thumbnails/crop-thumbnails.php'){ + $settings_link = ''.__('Settings',CROP_THUMBS_LANG).''; + array_unshift( $links, $settings_link ); + } + return $links; } - + function addOptionsPage() { add_options_page(__('Crop Post Thumbnail Page',CROP_THUMBS_LANG), 'Crop-Thumbnails', 'manage_options', 'page-cpt', array($this,'optionsPage')); add_action('admin_init', array($this,'settingsInitialisation')); } - + function optionsPage() { ?>

@@ -39,12 +39,12 @@ function optionsPage() { ?>
uniqeSettingsId); ?> - +
-
+
- +

(and let him know you love this plugin)
by donating via Paypal. Thanks a lot!',CROP_THUMBS_LANG); ?>

@@ -64,10 +64,10 @@ function optionsPage() { ?>
uniqeSettingsId, $this->optionsKey, array($this,'validateSettings') ); - + $_sectionID = 'choose_sizes_section'; add_settings_section($_sectionID, __('Sizes and Posttypes',CROP_THUMBS_LANG), array($this,'sectionDescriptionChooseSizes'), 'page1'); add_settings_field('sizes', __('Choose the image-sizes you want to hide. Choose a post-type to prevent any use of the plugin for these entries.',CROP_THUMBS_LANG), array($this,'callback_choose_size'), 'page1', $_sectionID); @@ -84,7 +84,7 @@ function settingsInitialisation(){ $_tmpID = 'debug_data'; add_settings_field($_tmpID, __('Enable Data-Debug.',CROP_THUMBS_LANG), array($this,'callback_'.$_tmpID), 'page1', $_sectionID, array( 'label_for' => $this->cssPrefix.$_tmpID )); } - + function sectionDescriptionChooseSizes() {?>

@@ -92,7 +92,7 @@ function sectionDescriptionChooseSizes() {?>

'.print_r($options,true).''; $post_types = $this->getPostTypes(); $image_sizes = $this->getImageSizes(); - + //output echo ' diff --git a/functions/settings.php b/functions/settings.php index 6d85575..282e111 100644 --- a/functions/settings.php +++ b/functions/settings.php @@ -241,13 +241,19 @@ function getPostTypes() { * array[]['height'] = int * array[]['width'] = int * array[]['crop'] = boolean + * array[]['name'] = string --> readable name if provided in "image_size_names_choose", else sizename * */ function getImageSizes() { global $_wp_additional_image_sizes;//array with the available image sizes - $tmp_sizes = get_intermediate_image_sizes(); + $tmp_sizes = array_flip(get_intermediate_image_sizes()); + foreach($tmp_sizes as $key=>$value) { + $tmp_sizes[$key] = $key; + } + $tmp_sizes = apply_filters( 'image_size_names_choose', $tmp_sizes ); + $sizes = array(); - foreach( $tmp_sizes as $_size ) { + foreach( $tmp_sizes as $_size=>$theName ) { if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) { $sizes[ $_size ]['width'] = intval(get_option( $_size . '_size_w' )); @@ -260,6 +266,7 @@ function getImageSizes() { 'crop' => (bool) $_wp_additional_image_sizes[ $_size ]['crop'] ); } + $sizes[ $_size ]['name'] = $theName; } return $sizes; } diff --git a/readme.txt b/readme.txt index 64e01bc..181e5d1 100644 --- a/readme.txt +++ b/readme.txt @@ -15,8 +15,6 @@ License URI: http://www.gnu.org/licenses/gpl-3.0.html The plugin enhance functionality to crop your automatic cropped post-thumbnails individuell and simple. It add links in the backend to enter all images you had attached to a post, page or custom-post. In the Crop-Editor you can choose one or more (if they have the same ratio) imagesizes and cut-off the part of the image you want. -The plugin targets advanced users and theme-developers. - Further Features * It is possible to filter the list of available image-sizes (in dependency to post-types) in the settings (Settings > Crop-Thumbnails). * You could provide your users a custom style for the Editor-Window. @@ -51,7 +49,9 @@ Refresh or Update the editor page. Note that the image in the featured-image box will only be a preview, to show what image is choosed. The theme defines what image-size is used on the front-end. = Is it possible to crop an non-cropped image-size? = -No. You should +No. The purpose of this plugin is to provide control for the wordpress automatic crop. If you want to crop let's say the full-size image you should +* a) upload it in a better format in the first place +* OR b) use the Standard Wordpress-Image editor to crop the image. = Is it possible to adjust the css-style of the crop-thumbnail window? = Yes, for a simple test, copy the css/cpt-window.css file into your template_directory and make some change. @@ -85,6 +85,7 @@ Example-Code: * refactoring some parts of the code to make it more modular * adding a cache breaker to the backend, so in post-view and mediathek the image should be refreshed after the modal-dialog closes * provide a javascript-event ('cropThumbnailModalClosed') after the modal is closed (see F.A.Q. for details) +* provide the human-readable Name of the Crop-Size (if available), using the "image_size_names_choose" filter = 0.9.0 = * add crop-thumbnail-button to the default attachement-screens so i could accessed better From 23bc7e3e46e17c8e35aa93b196e371966bf39345 Mon Sep 17 00:00:00 2001 From: Volkmar Kantor Date: Sat, 19 Sep 2015 17:35:20 +0200 Subject: [PATCH 18/18] add filter for adjusting the size of the modal window --- functions/backendpreparer.php | 32 +++++++++++++++++++++++++++----- lang/cpt_lang-de_DE.mo | Bin 6400 -> 6416 bytes lang/cpt_lang-de_DE.po | 7 ++++--- readme.txt | 16 ++++++++++++---- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/functions/backendpreparer.php b/functions/backendpreparer.php index 4effd8d..7bb6356 100644 --- a/functions/backendpreparer.php +++ b/functions/backendpreparer.php @@ -146,13 +146,35 @@ function addLinksToAdmin() { */ $(document).on('click', '.cropThumbnailBox', function(e) { e.preventDefault(); + + 800, //thats the maximum width the modal can be. On small screens it will be smaller (see offsets), set to FALSE if you want no limit + 'maxWidthOffset' => 50, //window-width minus "width_offset" equals modal-width + 'maxHeightOffset' => 100, //window-width minus "height_offset" equals modal-height + ); + $modal_window_settings = apply_filters('crop_thumbnails_modal_window_settings',$modal_window_settings); + + $jsLimitOutput = ''; + if($modal_window_settings['limitToWidth']!==false) { + $value = abs(intval($modal_window_settings['limitToWidth'])); + + $jsLimitOutput.= 'if(boxViewportWidth>'.$value.') { boxViewportWidth = '.$value.'; }'; + } + /*****************************************************************************/ + ?> //modal-box dimensions (will not adjust on viewport change) - var boxViewportHeight = $(window).height() - 100; - var boxViewportWidth = $(window).width() - 50; - if(boxViewportWidth>800) {//do not want to have width bigger than 800 - maybe later, if i have refined the reponsive design - boxViewportWidth = 800; - } + var boxViewportHeight = $(window).height() - ; + var boxViewportWidth = window.outerWidth - ; + + + + //get the data from the link var data = $(this).data('cropthumbnail'); diff --git a/lang/cpt_lang-de_DE.mo b/lang/cpt_lang-de_DE.mo index 13f8717ac377ae3e1b859b6ff1305dc5e73986b7..42267a832bb5d7b3789402990f04bc84b5ac6377 100644 GIT binary patch delta 510 zcmXZW&nv@m9LMqZl8kK3%=}pGdy&G%zWZgnIItf|xj5jWX$oK9A4){rP@BulJ66pk7u@*g9|lM{yl<5{&7{DJi1|Mcb)v=pakx+48uIE^gvJIj7j6*0_u?&Pyx?hesL<_=17@U_`{n z5L?(p)&D{jSR55$iO=TY66)B(89c%U-eG{>s0Mee^uIOCQ8%qPowQBEq;ZBS;QGJ5 z#{%^$hWLr=XpN-Mvy0b8XtD*ylh diff --git a/lang/cpt_lang-de_DE.po b/lang/cpt_lang-de_DE.po index e5b4cb4..1ed96ee 100644 --- a/lang/cpt_lang-de_DE.po +++ b/lang/cpt_lang-de_DE.po @@ -3,7 +3,7 @@ msgstr "" "Project-Id-Version: Crop-Post-Thumbnails\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2013-10-08 00:31+0100\n" -"PO-Revision-Date: 2013-10-08 00:33+0100\n" +"PO-Revision-Date: 2015-09-19 17:32+0100\n" "Last-Translator: Volkmar Kantor \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -11,7 +11,8 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Poedit-KeywordsList: __;_e;esc_attr_e;esc_html_e;esc_html__\n" "X-Poedit-Basepath: .\n" -"X-Generator: Poedit 1.5.4\n" +"X-Generator: Poedit 1.7.6\n" +"Language: de_DE\n" "X-Poedit-SearchPath-0: ..\n" #: ../crop-thumbnails.php:34 @@ -61,7 +62,7 @@ msgid "" "Warning: the original image is to small to be cropped in good quality with " "this thumbnail-size." msgstr "" -"Warung: das Original-Bild ist zu klein um für diese Thumbnail-Größe es in " +"Warung: das Original-Bild ist zu klein um es für diese Thumbnail-Größe in " "guter Qualität zuzuschneiden." #: ../functions/editor.php:182 diff --git a/readme.txt b/readme.txt index 181e5d1..967819c 100644 --- a/readme.txt +++ b/readme.txt @@ -44,10 +44,6 @@ You can use the built in installer and upgrader, or you can install the plugin m = I have cropped the image but the old one is used on the page. = If you had viewed your image on the site before, your browser has cached the image. Go tell them to reload the fresh image from the server by hitting "F5". -= I have cropped the image but in the featured-image box in the editor the croped version dont show up = -Refresh or Update the editor page. -Note that the image in the featured-image box will only be a preview, to show what image is choosed. The theme defines what image-size is used on the front-end. - = Is it possible to crop an non-cropped image-size? = No. The purpose of this plugin is to provide control for the wordpress automatic crop. If you want to crop let's say the full-size image you should * a) upload it in a better format in the first place @@ -63,6 +59,16 @@ function myCustomStyle($content) { return $content; }` += Can i make the modal-dialog fullscreen? = +Yes, i added a filter with some settings for the modal-dialog, so you can adjust the size: +`add_filter('crop_thumbnails_modal_window_settings','crop_thumbnails_modal_window_settings_override'); +function crop_thumbnails_modal_window_settings_override($param) { + $param['limitToWidth'] = false; //You may set a number, then thats the maximum width the modal can be. On small screens it will be smaller (see offsets). Set to FALSE if you want no limit. + $param['maxWidthOffset'] = 0; //window-width minus "width_offset" equals modal-width + $param['maxHeightOffset'] = 0; //window-width minus "height_offset" equals modal-height + return $param; +}` + = I have show the cropped image in the backend in an custom meta-box. It does not update after the modal-dialog closed. Is there a way to fix this = Yeah, there is a way. After the crop-thumbnails-modal closed it triggeres a javascript event on the body element. You could use jQuery to cache-break your cropped thumbnail (in backend-view). The event called "cropThumbnailModalClosed". The plugin also provides a global function that could be called (only in post-edit-view and mediathek) to do the cache-break. @@ -86,6 +92,8 @@ Example-Code: * adding a cache breaker to the backend, so in post-view and mediathek the image should be refreshed after the modal-dialog closes * provide a javascript-event ('cropThumbnailModalClosed') after the modal is closed (see F.A.Q. for details) * provide the human-readable Name of the Crop-Size (if available), using the "image_size_names_choose" filter +* provide some size settings for the modal-dialog - via filter "crop_thumbnails_modal_window_settings" +* mini language update = 0.9.0 = * add crop-thumbnail-button to the default attachement-screens so i could accessed better