Plugin Directory

Changeset 2972681


Ignore:
Timestamp:
09/28/2023 02:16:18 PM (2 years ago)
Author:
burlingtonbytes
Message:

Release v2.0.7 - Adds support for figure markup

Location:
wp-smartcrop
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-smartcrop/tags/2.0.7/readme.txt

    r2744222 r2972681  
    111111== Changelog ==
    112112
     113= 2.0.7 =
     114* Add support for figure markup
     115
    113116= 2.0.6 =
    114117* Test against WordPress 5.6.0
  • wp-smartcrop/tags/2.0.7/wp-smartcrop.php

    r2744222 r2972681  
    44 * Plugin URI: https://www.wpsmartcrop.com/
    55 * Description: Style your images exactly how you want them to appear, for any screen size, and never get a cut-off face.
    6  * Version: 2.0.6
     6 * Version: 2.0.7
    77 * Author: Bytes.co
    88 * Author URI: https://bytes.co
     
    1313if( !class_exists('WP_Smart_Crop') ) {
    1414    class WP_Smart_Crop {
    15         public  $version = '2.0.6';
     15        public  $version = '2.0.7';
    1616        private $plugin_dir_path;
    1717        private $plugin_dir_url;
     
    432432        function the_content( $content ) {
    433433            $tags = $this->extract_tags( $content, 'img', true, true );
     434            $figure_tags = $this->extract_tags( $content, 'figure', false, true ); // wordpress can attach size details to a figure wrapper now
     435            $tags = array_merge( $tags, $figure_tags );
     436
    434437            $unique_tags = array();
    435438            $ids = array();
    436439            foreach( $tags as $tag ) {
    437                 list( $id, $size ) = $this->get_id_and_size_from_tag( $tag );
     440                $id = null;
     441                $size = null;
     442                if ( $tag['tag_name'] == 'img' ) {
     443                    list( $id, $size ) = $this->get_id_and_size_from_tag( $tag );
     444                } elseif ( $tag['tag_name'] == 'figure' ) { // specially process our figure tags to get size data
     445                    $img_tag = $this->extract_tags( $tag['full_tag'] ?? '', 'img', true, true );
     446                    // we're processing only the first img
     447                    if ( $img_tag && count($img_tag) ) {
     448                        $img_tag = $img_tag[0];
     449                        $tag['img_tag'] = $img_tag;
     450                    } else {
     451                        continue;
     452                    }
     453                    $img_tag['attributes']['class'] .= $tag['attributes']['class'];
     454                    list( $id, $size ) = $this->get_id_and_size_from_tag( $img_tag );
     455                }
     456                //var_dump( $size );
    438457                if( $id && $size ) {
    439458                    $ids[] = $id;
     
    725744            $id   = $tag['id'];
    726745            $size = $tag['size'];
    727             $atts = $tag['attributes'];
     746            $atts = $tag['img_tag']['attributes'] ?: $tag['attributes'];
    728747            $focus_attr = $this->get_smartcrop_focus_attr( $id, $size );
    729748            if( $focus_attr ) {
     
    736755                $atts['data-smartcrop-focus'] = $focus_attr;
    737756            }
    738             $new_tag = '<img';
     757            $value = '';
     758            $old_img_tag = $tag['full_tag'];
     759            // special processing for figure tags
     760            if ( $tag['tag_name'] == 'figure' ) {
     761                $old_img_tag = $tag['img_tag']['full_tag'] ?? null;
     762            }
     763            $new_img_tag = '<img';
    739764            foreach( $atts as $name => $val ) {
    740                 $new_tag .= ' ' . $name . '="' . $val . '"';
    741             }
    742             $new_tag .= ' />';
     765                $new_img_tag .= ' ' . $name . '="' . $val . '"';
     766            }
     767            $new_img_tag .= ' />';
     768            $new_tag = str_replace( $old_img_tag, $new_img_tag, $tag['full_tag'] );
    743769            return $new_tag;
    744770        }
  • wp-smartcrop/trunk/readme.txt

    r2744222 r2972681  
    111111== Changelog ==
    112112
     113= 2.0.7 =
     114* Add support for figure markup
     115
    113116= 2.0.6 =
    114117* Test against WordPress 5.6.0
  • wp-smartcrop/trunk/wp-smartcrop.php

    r2744222 r2972681  
    44 * Plugin URI: https://www.wpsmartcrop.com/
    55 * Description: Style your images exactly how you want them to appear, for any screen size, and never get a cut-off face.
    6  * Version: 2.0.6
     6 * Version: 2.0.7
    77 * Author: Bytes.co
    88 * Author URI: https://bytes.co
     
    1313if( !class_exists('WP_Smart_Crop') ) {
    1414    class WP_Smart_Crop {
    15         public  $version = '2.0.6';
     15        public  $version = '2.0.7';
    1616        private $plugin_dir_path;
    1717        private $plugin_dir_url;
     
    432432        function the_content( $content ) {
    433433            $tags = $this->extract_tags( $content, 'img', true, true );
     434            $figure_tags = $this->extract_tags( $content, 'figure', false, true ); // wordpress can attach size details to a figure wrapper now
     435            $tags = array_merge( $tags, $figure_tags );
     436
    434437            $unique_tags = array();
    435438            $ids = array();
    436439            foreach( $tags as $tag ) {
    437                 list( $id, $size ) = $this->get_id_and_size_from_tag( $tag );
     440                $id = null;
     441                $size = null;
     442                if ( $tag['tag_name'] == 'img' ) {
     443                    list( $id, $size ) = $this->get_id_and_size_from_tag( $tag );
     444                } elseif ( $tag['tag_name'] == 'figure' ) { // specially process our figure tags to get size data
     445                    $img_tag = $this->extract_tags( $tag['full_tag'] ?? '', 'img', true, true );
     446                    // we're processing only the first img
     447                    if ( $img_tag && count($img_tag) ) {
     448                        $img_tag = $img_tag[0];
     449                        $tag['img_tag'] = $img_tag;
     450                    } else {
     451                        continue;
     452                    }
     453                    $img_tag['attributes']['class'] .= $tag['attributes']['class'];
     454                    list( $id, $size ) = $this->get_id_and_size_from_tag( $img_tag );
     455                }
     456                //var_dump( $size );
    438457                if( $id && $size ) {
    439458                    $ids[] = $id;
     
    725744            $id   = $tag['id'];
    726745            $size = $tag['size'];
    727             $atts = $tag['attributes'];
     746            $atts = $tag['img_tag']['attributes'] ?: $tag['attributes'];
    728747            $focus_attr = $this->get_smartcrop_focus_attr( $id, $size );
    729748            if( $focus_attr ) {
     
    736755                $atts['data-smartcrop-focus'] = $focus_attr;
    737756            }
    738             $new_tag = '<img';
     757            $value = '';
     758            $old_img_tag = $tag['full_tag'];
     759            // special processing for figure tags
     760            if ( $tag['tag_name'] == 'figure' ) {
     761                $old_img_tag = $tag['img_tag']['full_tag'] ?? null;
     762            }
     763            $new_img_tag = '<img';
    739764            foreach( $atts as $name => $val ) {
    740                 $new_tag .= ' ' . $name . '="' . $val . '"';
    741             }
    742             $new_tag .= ' />';
     765                $new_img_tag .= ' ' . $name . '="' . $val . '"';
     766            }
     767            $new_img_tag .= ' />';
     768            $new_tag = str_replace( $old_img_tag, $new_img_tag, $tag['full_tag'] );
    743769            return $new_tag;
    744770        }
Note: See TracChangeset for help on using the changeset viewer.