Guenni007 icon

avia-special-characters-plugin

Guenni007 | PRO | 09/11/24 06:21:53 PM UTC (Edited) | 0 ⭐ | 2317 👁️ | Never ⏰ | []
PHP |

5.06 KB

|

None

|

0 👍

/

0 👎

<?php
/*
Plugin Name: Avia Special Character Converter Plugin
Plugin URI: www.kriesi.at
Description: Replaces special characters that break layout or Enfold Advanced Layout Editor
Version: 1.1.3
Author: Guenter for www.kriesi.at
Author URI: www.kriesi.at
Text Domain: avia_special_characters
 
@requires:  PHP 5.3   (anonymous functions)
@requires:  WP 4.7
*/
 
/*
 * Copyright 2018
*/
 
if ( ! defined( 'ABSPATH' ) ) {   exit;  } // Exit if accessed directly
 
 
if( ! class_exists( 'avia_special_characters' ) )
{
 
    class avia_special_characters
    {
        /**
         * Holds the instance of this class
         *
         * @since 1.1
         * @var avia_special_characters
         */
        static private $_instance = null;
 
        /**
         *
         * @since 1.0.0
         * @var array
         */
        protected $translate;
 
        /**
         * Return the instance of this class
         *
         * @since 1.1
         * @return avia_special_characters
         */
        static public function instance()
        {
            if( is_null( avia_special_characters::$_instance ) )
            {
                avia_special_characters::$_instance = new avia_special_characters();
            }
 
            return avia_special_characters::$_instance;
        }
 
        /**
         *
         * @since 1.0.0
         */
        protected function __construct()
        {
            $this->translate = array(
                '#lt#'          => '<',
                '#le#'          => '≤',
                '#gt#'          => '>',
                '#ge#'          => '≥',
                '#amp#'         => '&',
                '#lbrack#'      => '[',
                '#rbrack#'      => ']',
                '#lbrace#'      => '{',
                '#rbrace#'      => '}',
                '#bigSZ#'       => '&#7838;',   // german big Letter of ß
                '#quot#'        => '"',
                '#34#'          => "'",
                '#bdquo#'       => "„",
                '#rdquo#'       => "”",
                '#ctemp#'       => '&#8451;',   // Degree in Celcius
                '#ftemp#'       => '&#8457;',   // Degree in Fahrenheit
                '#copy#'        => '&#169;',    // Copyright
                '#reg#'         => '&#174;',    // Registermark
                '#trade#'       => '&#8482;',   // Trademark
                '#br#'          => '<br/>',     // linebreak
                '#shy#'         => '&#173;',    // Softhyphen
                '#nbsp#'        => '&#160;',    // non breaking spaces
                '#sbsp#'        => '&#8239;',   // small non breaking spaces
                '#nbhyp#'       => '&#8209;',   // non breaking hyphen
                '#ndash#'       => '&#8211;',   // dash with n-letter width
                '#mdash#'       => '&#8212;',   // dash with m-letter width
                '#horbar#'      => '&#8213;',   // horizontal bar
                '#1/2#'         => '&#189;',
                '#1/3#'         => '&#8531;',
                '#2/3#'         => '&#8532;',
                '#1/4#'         => '&#188;',
                '#3/4#'         => '&#190;',
                '#1/5#'         => '&#8533;',
                '#2/5#'         => '&#8534;',
                '#3/5#'         => '&#8535;',
                '#4/5#'         => '&#8536;',
            );
 
            add_filter( 'the_content', array( $this, 'handler_the_content' ), 9999999, 1 );
            add_filter( 'avf_text_to_preview', array( $this, 'handler_the_content' ), 9999999, 1 );
 
            /**
             * Allows to translate special characters also in ALB codeblock element
             * (suggested by Guenni007)
             * 
             * @since 1.1.3
             */
            add_filter( 'avf_template_builder_content', array( $this, 'handler_the_content' ), 9999999, 1 );
 
            /**
             * Allow shortcode attributes to translate special characters (e.g. for attribute content used in js)
             * 
             * @since 1.1.2
             */
            add_filter( 'avf_sc_attr_value', array( $this, 'handler_the_content' ), 9999999, 1 );
 
            /**
             * @since 1.1
             */
            add_filter( 'avf_form_subject', array( $this, 'handler_the_content' ), 9999999, 1 );
            add_filter( 'avf_form_mail_form_field', array( $this, 'handler_the_content' ), 9999999, 1 );
            add_filter( 'avf_contact_form_autoresponder_mail', array( $this, 'handler_avf_autoresponder_mail' ), 9999999, 4 );
        }
 
        /**
         *
         * @since 1.0.0
         */
        public function __destruct()
        {
            unset( $this->translate );
        }
 
        /**
         * Replace the special characters
         *
         * @since 1.0.0
         * @param string $content
         * @return string
         */
        public function handler_the_content( $content )
        {
            /**
             * Add additional special characters to translate
             *
             * @since 1.0.0
             * @param array $this->translate
             * @return array
             */
            $this->translate = apply_filters( 'avia_special_characters_translations', $this->translate );
 
            $search = array_keys( $this->translate );
            $replace = array_values( $this->translate );
 
            $new_content = str_replace( $search, $replace, $content );
 
            return $new_content;
        }
 
        /**
         *
         * @since 1.1.1
         * @param array $mail_array
         * @param array $new_post
         * @param array $form_params
         * @param avia_form $form
         * @return array
         */
        public function handler_avf_autoresponder_mail( array $mail_array, array $new_post, array $form_params, avia_form $form )
        {
            $check = [ 'Subject', 'Message' ];
 
            foreach( $check as $key )
            {
                if( isset( $mail_array[ $key ] ) )
                {
                    $mail_array[ $key ] = $this->handler_the_content( $mail_array[ $key ] );
                }
            }
 
            return $mail_array;
        }
    }
 
    /**
     * Returns the main instance of avia_special_characters to prevent the need to use globals
     *
     * @since 1.1
     * @return avia_special_characters
     */
    function AviaSpecialCharacters()
    {
        return avia_special_characters::instance();
    }
 
    AviaSpecialCharacters();
 
}   //  class exists
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎