Plugin Directory

Changeset 3252345


Ignore:
Timestamp:
03/07/2025 08:44:33 PM (13 months ago)
Author:
creativform
Message:

2.2.1

  • Fixed PHP errors from the previous version
  • Improved UTF-8 encoding
  • Optimized transliteration scripts
  • Added support for the special HTML attributes
Location:
serbian-transliteration
Files:
138 added
6 edited

Legend:

Unmodified
Added
Removed
  • serbian-transliteration/trunk/CHANGELOG.txt

    r3244095 r3252345  
     1= 2.2.1 =
     2* Fixed PHP errors from the previous version
     3* Improved UTF-8 encoding
     4* Optimized transliteration scripts
     5* Added support for the special HTML attributes
     6
    17= 2.2.0 =
    28* NEW: Phantom Mode - ultra fast DOM-based transliteration (experimental)
  • serbian-transliteration/trunk/classes/controller.php

    r3244095 r3252345  
    239239            return $placeholder;
    240240        }, $content);
     241       
     242        // Extract <head> contents and replace them with placeholders
     243        $head_placeholders = [];
     244        $content = preg_replace_callback('/<head\b[^>]*>(.*?)<\/head>/is', function($matches) use (&$head_placeholders) {
     245            $placeholder = '@=[3-' . count($head_placeholders) . ']=@';
     246            $head_placeholders[$placeholder] = $matches[0];
     247            return $placeholder;
     248        }, $content);
    241249
    242250        // Handle percentage format specifiers by replacing them with placeholders
    243251        $formatSpecifiers = [];
    244252        $content = preg_replace_callback('/(\b\d+(?:\.\d+)?&#37;)/', function($matches) use (&$formatSpecifiers) {
    245             $placeholder = '@=[3-' . count($formatSpecifiers) . ']=@';
     253            $placeholder = '@=[4-' . count($formatSpecifiers) . ']=@';
    246254            $formatSpecifiers[$placeholder] = $matches[0];
    247255            return $placeholder;
     
    288296            $content = strtr($content, $style_placeholders);
    289297            unset($style_placeholders);
     298        }
     299       
     300        // Restore <head> contents back to their original form
     301        if ($head_placeholders) {
     302            $content = strtr($content, $head_placeholders);
     303            unset($head_placeholders);
    290304        }
    291305
     
    405419        }, $content);
    406420       
     421        // Extract <head> contents and replace them with placeholders
     422        $head_placeholders = [];
     423        $content = preg_replace_callback('/<head\b[^>]*>(.*?)<\/head>/is', function($matches) use (&$head_placeholders) {
     424            $placeholder = '@=[5-' . count($head_placeholders) . ']=@';
     425            $head_placeholders[$placeholder] = $matches[0];
     426            return $placeholder;
     427        }, $content);
     428       
    407429        // Extract special shortcode contents and replace them with placeholders
    408430        $special_shortcodes = [];
    409431        $content = preg_replace_callback('/\{\{([\w+_-]+)\s?([^\}]*)\}\}(.*?)\{\{\/\1\}\}/is', function($matches) use (&$special_shortcodes) {
    410             $placeholder = '@=[5-' . count($special_shortcodes) . ']=@';
     432            $placeholder = '@=[6-' . count($special_shortcodes) . ']=@';
    411433            $special_shortcodes[$placeholder] = $matches[0];
    412434            return $placeholder;
     
    414436
    415437        $content = preg_replace_callback('/\{([\w+_-]+)\s?([^\}]*)\}(.*?)\{\/\1\}/is', function($matches) use (&$special_shortcodes) {
    416             $placeholder = '@=[6-' . count($special_shortcodes) . ']=@';
     438            $placeholder = '@=[7-' . count($special_shortcodes) . ']=@';
    417439            $special_shortcodes[$placeholder] = $matches[0];
    418440            return $placeholder;
     
    427449        );
    428450        $content = preg_replace_callback($regex, function($matches) use (&$formatSpecifiers) {
    429             $placeholder = '@=[7-' . count($formatSpecifiers) . ']=@';
     451            $placeholder = '@=[8-' . count($formatSpecifiers) . ']=@';
    430452            $formatSpecifiers[$placeholder] = $matches[0];
    431453            return $placeholder;
     
    496518            $content = strtr($content, $style_placeholders);
    497519            unset($style_placeholders);
     520        }
     521       
     522        // Restore <head> contents back to their original form
     523        if ($head_placeholders) {
     524            $content = strtr($content, $head_placeholders);
     525            unset($head_placeholders);
    498526        }
    499527
     
    620648        }
    621649
    622         $dom = new DOMDocument();
     650        $dom = new DOMDocument('1.0', 'UTF-8');
    623651
    624652        libxml_use_internal_errors(true);
    625         $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
     653        $html = '<?xml encoding="UTF-8">' . $html; // UTF-8 deklaracija OBAVEZNA!
     654        $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    626655        libxml_clear_errors();
    627656
     
    639668            'img',
    640669            'svg',
    641             'image'
    642         ]);
     670            'image',
     671            'head',
     672            'meta'
     673        ], 'dom');
    643674
    644675        // Atributi na koje se primenjuje transliteracija
    645         $attributesToTransliterate = apply_filters('transliteration_html_attributes', [
    646             'title',
    647             'data-title',
    648             'alt',
    649             'placeholder',
    650             'data-placeholder',
    651             'aria-label',
    652             'data-label',
    653             'data-description'
    654         ], 'inherit');
     676        $attributesToTransliterate = $this->private__html_atributes('dom', true);
    655677
    656678        // Transliteracija teksta unutar tagova, osim onih koji su na listi za izbegavanje
    657679        foreach ($xpath->query('//text()') as $textNode) {
    658680            if (!in_array($textNode->parentNode->nodeName, $skipTags)) {
    659                 $textNode->nodeValue = mb_convert_encoding(
    660                     $this->transliterate_no_html($textNode->nodeValue),
    661                     'HTML-ENTITIES',
    662                     'UTF-8'
    663                 );
     681                $textNode->nodeValue = $this->transliterate_no_html($textNode->nodeValue);
    664682            }
    665683        }
    666684
    667685        // Transliteracija određenih atributa
    668        
    669686        foreach ($xpath->query('//*[@' . implode(' or @', $attributesToTransliterate) . ']') as $node) {
    670687            foreach ($attributesToTransliterate as $attr) {
    671688                if ($node->hasAttribute($attr)) {
    672                     $node->setAttribute($attr, mb_convert_encoding(
    673                         $this->transliterate_no_html($node->getAttribute($attr)),
    674                         'HTML-ENTITIES',
    675                         'UTF-8'
    676                     ));
     689                    $node->setAttribute($attr, $this->transliterate($node->getAttribute($attr)));
    677690                }
    678691            }
     
    680693
    681694        // Vraćamo HTML sa pravilnim enkodingom
    682         return mb_convert_encoding($dom->saveHTML(), 'UTF-8', 'HTML-ENTITIES');
    683     }
     695        return $dom->saveHTML();
     696    }
     697
    684698
    685699   
     
    687701     * PRIVATE: Allowed HTML attributes for transliteration
    688702     */
    689     private function private__html_atributes($type = 'inherit') {
    690         return self::cached_static('private__html_atributes', function() use ($type) {
     703    private function private__html_atributes($type = 'inherit', $return_array = false) {
     704        return self::cached_static('private__html_atributes', function() use ($type, $return_array) {
    691705            $html_attributes_match = [
    692706                'title',
     
    697711                'aria-label',
    698712                'data-label',
    699                 'data-description'
     713                'data-description',
     714                'data-text',
     715                'data-content',
     716                'data-tooltip',
     717                'data-success_message',
     718                'data-qm-component',
     719                'data-qm-subject'
    700720            ];
    701721           
     
    704724            $html_attributes_match =  is_array($html_attributes_match) ? array_map('trim', $html_attributes_match) : [];
    705725           
     726            if($return_array) {
     727                return $html_attributes_match;
     728            }
     729           
    706730            return join('|', $html_attributes_match);
    707         }, $type);
     731        }, [$type, $return_array]);
    708732    }
    709733
  • serbian-transliteration/trunk/classes/wordpress.php

    r3224920 r3252345  
    55    public function __construct() {
    66        $this->add_filter('sanitize_user', 'allow_cyrillic_usernames', 10, 3);
    7         $this->add_filter('body_class', 'add_body_class', 10, 1);
     7        $this->add_filter('body_class', 'add_body_class', 10, 2);
     8       
    89        $this->transliterate_rss_atom();
    910        $this->transliterate_widgets();
     
    4344    }
    4445   
    45     public function add_body_class($classes){
     46    public function add_body_class($classes, $css_class){
    4647        if(get_rstr_option('enable-body-class', 'no') == 'no') {
    47             return;
     48            return $classes;
    4849        }
     50       
    4951        $script = Transliteration_Utilities::get_current_script();
     52       
    5053        //body class based on the current script - cyr, lat
    5154        $classes[] = 'rstr-' . $script;
    5255        $classes[] = 'transliteration-' . $script;
    5356        $classes[] = $script;
     57       
    5458        return $classes;
    5559    }
     
    6165       
    6266        $priority = PHP_INT_MAX - 100;
     67       
    6368        $actions = [
    6469            'rss_head', 'rss_footer',
     
    6772            'atom_head', 'atom_footer',
    6873        ];
     74       
    6975        foreach ($actions as $action) {
    7076            $this->add_action($action, 'rss_output_buffer_' . (strpos($action??'', '_head') ? 'start' : 'end'), $priority);
    71         }       
     77        }
    7278    }
    7379   
  • serbian-transliteration/trunk/constants.php

    r3239677 r3252345  
    3030 * @verson    1.0.0
    3131*/
    32 
    33 // This is need for plugin debugging.
    34 if (defined('WP_DEBUG')) {
    35     if (WP_DEBUG === true || WP_DEBUG === 1) {
    36         if (!defined('RSTR_DEBUG')) define('RSTR_DEBUG', true);
    37     }
    38 }
    3932
    4033// Plugin basename
  • serbian-transliteration/trunk/readme.txt

    r3244095 r3252345  
    55Tested up to: 6.7
    66Requires PHP: 7.0
    7 Stable tag: 2.2.0
     7Stable tag: 2.2.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    108108
    109109== Changelog ==
     110
     111= 2.2.1 =
     112* Fixed PHP errors from the previous version
     113* Improved UTF-8 encoding
     114* Optimized transliteration scripts
     115* Added support for the special HTML attributes
    110116
    111117= 2.2.0 =
     
    216222
    217223== Upgrade Notice ==
     224
     225= 2.2.1 =
     226* Fixed PHP errors from the previous version
     227* Improved UTF-8 encoding
     228* Optimized transliteration scripts
     229* Added support for the special HTML attributes
    218230
    219231= 2.2.0 =
  • serbian-transliteration/trunk/serbian-transliteration.php

    r3244095 r3252345  
    66 * Description:       All in one Cyrillic to Latin transliteration plugin for WordPress that actually works.
    77 * Donate link:       https://www.buymeacoffee.com/ivijanstefan
    8  * Version:           2.2.0
     8 * Version:           2.2.1
    99 * Requires at least: 5.4
    1010 * Tested up to:      6.7
     
    100100include_once __DIR__ . '/constants.php';
    101101
    102 // Developers need good debug
    103 if( (defined('RSTR_DEV_MODE') && RSTR_DEV_MODE) || (defined('RSTR_DEBUG') && RSTR_DEBUG) ) {
    104     error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
    105     add_action('doing_it_wrong_run', '__return_false');
    106     ini_set('display_errors', true);
    107     ini_set('log_errors', true);
    108 }
    109 
    110102// Set database tables
    111103global $wpdb, $rstr_is_admin;
Note: See TracChangeset for help on using the changeset viewer.