Advertisement
englishextra

swamper.class.php

Jun 24th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.69 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * $shimansky.biz
  5.  *
  6.  * Static web site core scripts
  7.  * @category PHP
  8.  * @access public
  9.  * @copyright (c) 2012 Shimansky.biz
  10.  * @author Serguei Shimansky <serguei@shimansky.biz>
  11.  * @license http://opensource.org/licenses/bsd-license.php
  12.  * @package shimansky.biz
  13.  * @link https://bitbucket.org/englishextra/shimansky.biz
  14.  * @link https://github.com/englishextra/shimansky.biz.git
  15.  */
  16.  
  17. /**
  18.  * General purpose PHP class to work with strings and files
  19.  *
  20.  * PHP version 5.4+
  21.  *
  22.  * Copyright (c) 2012 Shimansky.biz
  23.  * All rights reserved.
  24.  *
  25.  * Redistribution and use in source and binary forms, with or without
  26.  * modification, are permitted provided that the following conditions are met:
  27.  * 1. Redistributions of source code must retain the above copyright
  28.  *    notice, this list of conditions and the following disclaimer.
  29.  * 2. Redistributions in binary form must reproduce the above copyright
  30.  *    notice, this list of conditions and the following disclaimer in the
  31.  *    documentation and/or other materials provided with the distribution.
  32.  * 3. All advertising materials mentioning features or use of this software
  33.  *    must display the following acknowledgement:
  34.  *    This product includes software developed by the organization.
  35.  * 4. Neither the name of the organizatio> nor the
  36.  *    names of its contributors may be used to endorse or promote products
  37.  *    derived from this software without specific prior written permission.
  38.  *
  39.  * THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER ''AS IS'' AND ANY
  40.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  41.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  42.  * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY
  43.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  44.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  45.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  46.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49.  *
  50.  * Methods:
  51.  *
  52.  * 1. is_utf8
  53.  * 2. safe_str
  54.  * 3. get_post
  55.  * 4. ensure_amp
  56.  * 5. ensure_lt_gt
  57.  * 6. ord_space
  58.  * 7. ord_underscore
  59.  * 8. ord_hypher
  60.  * 9. ord_newline
  61.  * 10. remove_tags
  62.  * 11. remove_ents
  63.  * 12. remove_comments
  64.  * 13. has_http
  65.  * 14. is_ip
  66.  * 15. write_file
  67.  * 16. clear_data
  68.  * 17. remove_dir_content
  69.  * 18. remove_bbcoded
  70.  * 19. text_symbs_to_num_ents
  71.  * 20. acc_text_to_num_ents
  72.  * 21. safe_html
  73.  * 22. random_anchor
  74.  *
  75.  * PHP version 5.4+
  76.  *
  77.  * @category PHP
  78.  * @access public
  79.  * @copyright (c) 2012 Shimansky.biz
  80.  * @author Serguei Shimansky <serguei@shimansky.biz>
  81.  * @license http://opensource.org/licenses/bsd-license.php
  82.  * @package shimansky.biz
  83.  * @version 0.1
  84.  * @https://github.com/englishextra/shimansky.biz
  85.  */
  86. class Swamper {
  87.  
  88.     /**
  89.      *  There is a difference between the two: If you write an empty __construct() function, you overwrite any inherited __construct() from a parent class.
  90.      *  So if you don't need it and you do not want to overwrite the parent constructor explicitly, don't write it at all.
  91.      */
  92.     function __construct() {
  93.  
  94.     }
  95.  
  96.     public function is_utf8($s) {
  97.  
  98.         // From http://w3.org/International/questions/qa-forms-utf-8.html
  99.         return preg_match('%^(?:
  100.         [\x09\x0A\x0D\x20-\x7E] # ASCII
  101.         | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  102.         | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  103.         | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  104.         | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  105.         | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  106.         | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  107.         | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  108.         )*$%xs', $s);
  109.     }
  110.  
  111.     public function safe_str($s) {
  112.  
  113.         return str_replace(array("\n", "\r", "\t", "\v", "\0", "\x0B"), '', preg_replace("/[^\x20-\xFF]/", "", trim(@strval($s))));
  114.     }
  115.  
  116.     public function get_post($s, $v = '') {
  117.  
  118.         if (isset($_GET[$s]) || isset($_POST[$s])) {
  119.  
  120.             $v = isset($_GET[$s]) ? $_GET[$s] : (isset($_POST[$s]) ? urldecode($_POST[$s]) : '');
  121.             if (is_array($v)) {
  122.  
  123.                 foreach ($v as &$v1) {
  124.  
  125.                     $v1 = strtr($v1, array_flip(get_html_translation_table(HTML_ENTITIES)));
  126.                     $v1 = trim($v1);
  127.                     $v1 = $this->safe_str($v1);
  128.                 }
  129.                 unset($v1);
  130.             } else {
  131.  
  132.                 $v = strtr($v, array_flip(get_html_translation_table(HTML_ENTITIES)));
  133.                 $v = trim($v);
  134.                 $v = $this->safe_str($v);
  135.             }
  136.         }
  137.         return $v;
  138.     }
  139.  
  140.     public function ensure_amp($s) {
  141.  
  142.         $s = str_replace('&', '&amp;', $s);
  143.         $s = str_replace(array('&amp;amp;', '&amp;#'), array('&amp;', '&#'), $s);
  144.         $s = preg_replace("/(\&amp\;)([a-z0-9]+)(\;)/", "&\\2;", $s);
  145.         $s = preg_replace("/(\&\#)([a-z0-9]+)(\;)/", "&#\\2;", $s);
  146.         return $s;
  147.     }
  148.  
  149.     public function ensure_lt_gt($s) {
  150.  
  151.         $s = str_replace('<', '&lt;', $s);
  152.         $s = str_replace('>', '&gt;', $s);
  153.         $s = str_replace(array('&amp;lt;', '&amp;gt;'), array('&lt;', '&gt;'), $s);
  154.         return $s;
  155.     }
  156.  
  157.     public function ord_space($s) {
  158.  
  159.         return trim(preg_replace("/[\ ]+/", " ", $s));
  160.     }
  161.  
  162.     public function ord_underscore($s) {
  163.  
  164.         return trim(preg_replace("/[\_]+/", "_", $s));
  165.     }
  166.  
  167.     public function ord_hypher($s) {
  168.  
  169.         return trim(preg_replace("/[\-]+/", "-", $s));
  170.     }
  171.  
  172.     public function ord_newline($s) {
  173.  
  174.         return preg_replace("/[\r]+/s", "\r", $s);
  175.         return preg_replace("/[\n]+/s", "\n", $s);
  176.     }
  177.  
  178.     public function remove_tags($s) {
  179.  
  180.         $s = stripslashes($s);
  181.         $s = preg_replace("'<script[^>]*?>.*?</script>'si", ' ', $s);
  182.         $s = preg_replace("'<style[^>]*?>.*?</style>'si", ' ', $s);
  183.         $s = preg_replace("'<[\/\!]*?[^<>]*?>'si", ' ', $s);
  184.         $s = $this->ord_space($s);
  185.         return $s;
  186.     }
  187.  
  188.     public function remove_ents($s) {
  189.  
  190.         $s = preg_replace("'(\&)([A-Za-z0-9\#]+)(\;)'si", ' ', $s);
  191.         return $s;
  192.     }
  193.  
  194.     public function remove_comments($s) {
  195.  
  196.         $s = preg_replace("'<!--.*?-->'si", ' ', $s);
  197.         $s = preg_replace("'\/\*.*?\*\/'si", ' ', $s);
  198.         return $s;
  199.     }
  200.  
  201.     public function has_http($s, $r = false) {
  202.  
  203.         if (preg_match("/^(http|https|ftp)\:\/\//", $s) &&
  204.                 !preg_match("/^\//", $s)) {
  205.  
  206.             return $r = true;
  207.         }
  208.     }
  209.  
  210.     public function is_ip($ip) {
  211.  
  212.         //first of all the format of the ip address is matched
  213.         if (preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $ip)) {
  214.  
  215.             //now all the intger values are separated
  216.             $parts = explode(".", $ip);
  217.             //now we need to check each part can range from 0-255
  218.             foreach ($parts as $ip_parts) {
  219.  
  220.                 if (intval($ip_parts) > 255 || intval($ip_parts) < 0) {
  221.  
  222.                     return false; //if number is not within range of 0-255
  223.                 }
  224.             }
  225.             return true;
  226.         } else {
  227.  
  228.             return false; //if format of ip address doesn't matches
  229.         }
  230.     }
  231.  
  232.     public function write_file($data, $p, $type) {
  233.  
  234.         if (!$fo = fopen($data, $type)) {
  235.  
  236.             die('Cannot open file: ' . $data);
  237.         }
  238.         if (!is_writable($data)) {
  239.  
  240.             die('Cannot write file: ' . $data);
  241.         }
  242.         flock($fo, LOCK_EX);
  243.         fputs($fo, $p);
  244.         fflush($fo);
  245.         flock($fo, LOCK_UN);
  246.         fclose($fo);
  247.     }
  248.  
  249.     public function clear_data($data) {
  250.  
  251.         $p = '';
  252.         if (file_exists($data)) {
  253.  
  254.             if (!$fo = fopen($data, "w+")) {
  255.  
  256.                 die('Cannot open file: ' . $data);
  257.             }
  258.             flock($fo, LOCK_EX);
  259.             fputs($fo, $p);
  260.             fflush($fo);
  261.             flock($fo, LOCK_UN);
  262.             fclose($fo);
  263.         }
  264.     }
  265.  
  266.     public function remove_dir_content($dirname = '.') {
  267.  
  268.         if (is_dir($dirname)) {
  269.  
  270.             echo '<strong>' . $dirname . '</strong> is a directory.<br />';
  271.             if ($handle = @opendir($dirname)) {
  272.  
  273.                 while (false !== ($file = readdir($handle))) {
  274.  
  275.                     if ($file != "." && $file != "..") {
  276.  
  277.                         echo '<strong>' . $file . '</strong> deleted<br />';
  278.  
  279.                         $fullpath = $dirname . '/' . $file;
  280.  
  281.                         if (is_dir($fullpath)) {
  282.  
  283.                             $this->remove_dir_content($fullpath);
  284.                             @rmdir($fullpath);
  285.                         } else {
  286.  
  287.                             @unlink($fullpath);
  288.                         }
  289.                     }
  290.                 }
  291.                 closedir($handle);
  292.             }
  293.         }
  294.     }
  295.  
  296.     public function remove_bbcoded($s) {
  297.  
  298.         $a = array(
  299.             '(\[img\])(.*?)(\[\/img\])' => ' ',
  300.             '(\[img\=left\])(.*?)(\[\/img\])' => ' ',
  301.             '(\[img\=right\])(.*?)(\[\/img\])' => ' ',
  302.             '(\[color\=[a-zA-Z0-9\#]+\])(.*?)(\[\/color\])' => ' ',
  303.             '(\[)(.*?)(\])' => ' '
  304.         );
  305.         foreach ($a as $k => $v) {
  306.  
  307.             $s = preg_replace("/${k}/", $v, $s);
  308.             $s = $this->ord_space($s);
  309.         }
  310.         return $s;
  311.     }
  312.  
  313.     public function text_symbs_to_dec_ents($s) {
  314.  
  315.         /*
  316.         $a[] = null;
  317.  
  318.         dont include these:
  319.  
  320.         $a[] = array(' ', '&#160;');
  321.  
  322.         $a[] = array('&', '&#38;');
  323.         $a[] = array('#', '&#35;');
  324.         $a[] = array(';', '&#59;');
  325.  
  326.         $a[] = array('0', '&#48;');
  327.         $a[] = array('1', '&#49;');
  328.         $a[] = array('2', '&#50;');
  329.         $a[] = array('3', '&#51;');
  330.         $a[] = array('4', '&#52;');
  331.         $a[] = array('5', '&#53;');
  332.         $a[] = array('6', '&#54;');
  333.         $a[] = array('7', '&#55;');
  334.         $a[] = array('8', '&#56;');
  335.         $a[] = array('9', '&#57;');
  336.         */
  337.  
  338.         $a = null;
  339.  
  340.         $a = array(
  341.  
  342.         '¡' => '&#161;', '¢' => '&#162;', '£' => '&#163;', '¤' => '&#164;', '¥' => '&#165;', '¦' => '&#166;', '§' => '&#167;', '¨' => '&#168;', '©' => '&#169;', 'ª' => '&#170;', '«' => '&#171;', '¬' => '&#172;', '­' => '&#173;', '®' => '&#174;', '¯' => '&#175;', '°' => '&#176;', '±' => '&#177;', '²' => '&#178;', '³' => '&#179;', '´' => '&#180;', 'µ' => '&#181;', '¶' => '&#182;', '·' => '&#183;', '¸' => '&#184;', '¹' => '&#185;', 'º' => '&#186;', '»' => '&#187;', '¼' => '&#188;', '½' => '&#189;', '¾' => '&#190;', '¿' => '&#191;', 'À' => '&#192;', 'Á' => '&#193;', 'Â' => '&#194;', 'Ã' => '&#195;', 'Ä' => '&#196;', 'Å' => '&#197;', 'Æ' => '&#198;', 'Ç' => '&#199;', 'È' => '&#200;', 'É' => '&#201;', 'Ê' => '&#202;', 'Ë' => '&#203;', 'Ì' => '&#204;', 'Í' => '&#205;', 'Î' => '&#206;', 'Ï' => '&#207;', 'Ð' => '&#208;', 'Ñ' => '&#209;', 'Ò' => '&#210;', 'Ó' => '&#211;', 'Ô' => '&#212;', 'Õ' => '&#213;', 'Ö' => '&#214;', '×' => '&#215;', 'Ø' => '&#216;', 'Ù' => '&#217;', 'Ú' => '&#218;', 'Û' => '&#219;', 'Ü' => '&#220;', 'Ý' => '&#221;', 'Þ' => '&#222;', 'ß' => '&#223;', 'à' => '&#224;', 'á' => '&#225;', 'â' => '&#226;', 'ã' => '&#227;', 'ä' => '&#228;', 'å' => '&#229;', 'æ' => '&#230;', 'ç' => '&#231;', 'è' => '&#232;', 'é' => '&#233;', 'ê' => '&#234;', 'ë' => '&#235;', 'ì' => '&#236;', 'í' => '&#237;', 'î' => '&#238;', 'ï' => '&#239;', 'ð' => '&#240;', 'ñ' => '&#241;', 'ò' => '&#242;', 'ó' => '&#243;', 'ô' => '&#244;', 'õ' => '&#245;', 'ö' => '&#246;', '÷' => '&#247;', 'ø' => '&#248;', 'ù' => '&#249;', 'ú' => '&#250;', 'û' => '&#251;', 'ü' => '&#252;', 'ý' => '&#253;', 'þ' => '&#254;', 'ÿ' => '&#255;', 'Œ' => '&#338;', 'œ' => '&#339;', 'Š' => '&#352;', 'š' => '&#353;', 'Ÿ' => '&#376;', 'ƒ' => '&#402;', 'ˆ' => '&#710;', '˜' => '&#732;', 'Α' => '&#913;', 'Β' => '&#914;', 'Γ' => '&#915;', 'Δ' => '&#916;', 'Ε' => '&#917;', 'Ζ' => '&#918;', 'Η' => '&#919;', 'Θ' => '&#920;', 'Ι' => '&#921;', 'Κ' => '&#922;', 'Λ' => '&#923;', 'Μ' => '&#924;', 'Ν' => '&#925;', 'Ξ' => '&#926;', 'Ο' => '&#927;', 'Π' => '&#928;', 'Ρ' => '&#929;', 'Σ' => '&#931;', 'Τ' => '&#932;', 'Υ' => '&#933;', 'Φ' => '&#934;', 'Χ' => '&#935;', 'Ψ' => '&#936;', 'Ω' => '&#937;', 'α' => '&#945;', 'β' => '&#946;', 'γ' => '&#947;', 'δ' => '&#948;', 'ε' => '&#949;', 'ζ' => '&#950;', 'η' => '&#951;', 'θ' => '&#952;', 'ι' => '&#953;', 'κ' => '&#954;', 'λ' => '&#955;', 'μ' => '&#956;', 'ν' => '&#957;', 'ξ' => '&#958;', 'ο' => '&#959;', 'π' => '&#960;', 'ρ' => '&#961;', 'ς' => '&#962;', 'σ' => '&#963;', 'τ' => '&#964;', 'υ' => '&#965;', 'φ' => '&#966;', 'χ' => '&#967;', 'ψ' => '&#968;', 'ω' => '&#969;', 'ϑ' => '&#977;', 'ϒ' => '&#978;', 'ϖ' => '&#982;', ' ' => '&#8194;', ' ' => '&#8195;', ' ' => '&#8201;', '‌' => '&#8204;', '‍' => '&#8205;', '‎' => '&#8206;', '‏' => '&#8207;', '–' => '&#8211;', '—' => '&#8212;', '‘' => '&#8216;', '’' => '&#8217;', '‚' => '&#8218;', '“' => '&#8220;', '”' => '&#8221;', '„' => '&#8222;', '†' => '&#8224;', '‡' => '&#8225;', '•' => '&#8226;', '…' => '&#8230;', '‰' => '&#8240;', '′' => '&#8242;', '″' => '&#8243;', '‹' => '&#8249;', '›' => '&#8250;', '‾' => '&#8254;', '⁄' => '&#8260;', '€' => '&#8364;', 'ℑ' => '&#8465;', '℘' => '&#8472;', 'ℜ' => '&#8476;', '™' => '&#8482;', 'ℵ' => '&#8501;', '←' => '&#8592;', '↑' => '&#8593;', '→' => '&#8594;', '↓' => '&#8595;', '↔' => '&#8596;', '↵' => '&#8629;', '⇐' => '&#8656;', '⇑' => '&#8657;', '⇒' => '&#8658;', '⇓' => '&#8659;', '⇔' => '&#8660;', '∀' => '&#8704;', '∂' => '&#8706;', '∃' => '&#8707;', '∅' => '&#8709;', '∇' => '&#8711;', '∈' => '&#8712;', '∉' => '&#8713;', '∋' => '&#8715;', '∏' => '&#8719;', '∑' => '&#8721;', '−' => '&#8722;', '∗' => '&#8727;', '√' => '&#8730;', '∝' => '&#8733;', '∞' => '&#8734;', '∠' => '&#8736;', '∧' => '&#8743;', '∨' => '&#8744;', '∩' => '&#8745;', '∪' => '&#8746;', '∫' => '&#8747;', '∴' => '&#8756;', '∼' => '&#8764;', '≅' => '&#8773;', '≈' => '&#8776;', '≠' => '&#8800;', '≡' => '&#8801;', '≤' => '&#8804;', '≥' => '&#8805;', '⊂' => '&#8834;', '⊃' => '&#8835;', '⊄' => '&#8836;', '⊆' => '&#8838;', '⊇' => '&#8839;', '⊕' => '&#8853;', '⊗' => '&#8855;', '⊥' => '&#8869;', '⋅' => '&#8901;', '⌈' => '&#8968;', '⌉' => '&#8969;', '⌊' => '&#8970;', '⌋' => '&#8971;', '◊' => '&#9674;', '♠' => '&#9824;', '♣' => '&#9827;', '♥' => '&#9829;', '♦' => '&#9830;', '⟨' => '&#9001;', '⟩' => '&#9002;',
  343.         /* '!' => '&#33;', */
  344.         /* '"' => '&#34;', */
  345.         /* '$' => '&#36;', */
  346.         /* '%' => '&#37;', */
  347.         /* '(' => '&#40;', */
  348.         /* ')' => '&#41;', */
  349.         /* '*' => '&#42;', */
  350.         /* '+' => '&#43;', */
  351.         /* ',' => '&#44;', */
  352.         /* '-' => '&#45;', */
  353.         /* '.' => '&#46;', */
  354.         /* '/' => '&#47;', */
  355.         /* ':' => '&#58;', */
  356.         /* '<' => '&#60;', */
  357.         /* '=' => '&#61;', */
  358.         /* '>' => '&#62;', */
  359.         /* '?' => '&#63;', */
  360.         '@' => '&#64;',
  361.         /* '[' => '&#91;', */
  362.         /* '\'' => '&#39;', */
  363.         /* '\\' => '&#92;', */
  364.         /* ']' => '&#93;', */
  365.         '^' => '&#94;',
  366.         /* '_' => '&#95;', */
  367.         '`' => '&#96;',
  368.         /* '{' => '&#123;', */
  369.         /* '|' => '&#124;', */
  370.         /* '}' => '&#125;', */
  371.         /* '~' => '&#126;', */
  372.         '✁' => '&#9985;', '✂' => '&#9986;', '✃' => '&#9987;', '✄' => '&#9988;', '✆' => '&#9990;', '✇' => '&#9991;', '✈' => '&#9992;', '✉' => '&#9993;', '✌' => '&#9996;', '✍' => '&#9997;', '✎' => '&#9998;', '✏' => '&#9999;', '✐' => '&#10000;', '✑' => '&#10001;', '✒' => '&#10002;', '✓' => '&#10003;', '✔' => '&#10004;', '✕' => '&#10005;', '✖' => '&#10006;', '✗' => '&#10007;', '✘' => '&#10008;', '✙' => '&#10009;', '✚' => '&#10010;', '✛' => '&#10011;', '✜' => '&#10012;', '✝' => '&#10013;', '✞' => '&#10014;', '✟' => '&#10015;', '✠' => '&#10016;', '✡' => '&#10017;', '✢' => '&#10018;', '✣' => '&#10019;', '✤' => '&#10020;', '✥' => '&#10021;', '✦' => '&#10022;', '✧' => '&#10023;', '✩' => '&#10025;', '✪' => '&#10026;', '✫' => '&#10027;', '✬' => '&#10028;', '✭' => '&#10029;', '✮' => '&#10030;', '✯' => '&#10031;', '✰' => '&#10032;', '✱' => '&#10033;', '✲' => '&#10034;', '✳' => '&#10035;', '✴' => '&#10036;', '✵' => '&#10037;', '✶' => '&#10038;', '✷' => '&#10039;', '✸' => '&#10040;', '✹' => '&#10041;', '✺' => '&#10042;', '✻' => '&#10043;', '✼' => '&#10044;', '✽' => '&#10045;', '✾' => '&#10046;', '✿' => '&#10047;', '❀' => '&#10048;', '❁' => '&#10049;', '❂' => '&#10050;', '❃' => '&#10051;', '❄' => '&#10052;', '❅' => '&#10053;', '❆' => '&#10054;', '❇' => '&#10055;', '❈' => '&#10056;', '❉' => '&#10057;', '❊' => '&#10058;', '❋' => '&#10059;', '❍' => '&#10061;', '❏' => '&#10063;', '❐' => '&#10064;', '❑' => '&#10065;', '❒' => '&#10066;', '❖' => '&#10070;', '❘' => '&#10072;', '❙' => '&#10073;', '❚' => '&#10074;', '❛' => '&#10075;', '❜' => '&#10076;', '❝' => '&#10077;', '❞' => '&#10078;', '❡' => '&#10081;', '❢' => '&#10082;', '❣' => '&#10083;', '❤' => '&#10084;', '❥' => '&#10085;', '❦' => '&#10086;', '❧' => '&#10087;', '❶' => '&#10102;', '❷' => '&#10103;', '❸' => '&#10104;', '❹' => '&#10105;', '❺' => '&#10106;', '❻' => '&#10107;', '❼' => '&#10108;', '❽' => '&#10109;', '❾' => '&#10110;', '❿' => '&#10111;', '➀' => '&#10112;', '➁' => '&#10113;', '➂' => '&#10114;', '➃' => '&#10115;', '➄' => '&#10116;', '➅' => '&#10117;', '➆' => '&#10118;', '➇' => '&#10119;', '➈' => '&#10120;', '➉' => '&#10121;', '➊' => '&#10122;', '➋' => '&#10123;', '➌' => '&#10124;', '➍' => '&#10125;', '➎' => '&#10126;', '➏' => '&#10127;', '➐' => '&#10128;', '➑' => '&#10129;', '➒' => '&#10130;', '➓' => '&#10131;', '➔' => '&#10132;', '➘' => '&#10136;', '➙' => '&#10137;', '➚' => '&#10138;', '➛' => '&#10139;', '➜' => '&#10140;', '➝' => '&#10141;', '➞' => '&#10142;', '➟' => '&#10143;', '➠' => '&#10144;', '➡' => '&#10145;', '➢' => '&#10146;', '➣' => '&#10147;', '➤' => '&#10148;', '➥' => '&#10149;', '➦' => '&#10150;', '➧' => '&#10151;', '➨' => '&#10152;', '➩' => '&#10153;', '➪' => '&#10154;', '➫' => '&#10155;', '➬' => '&#10156;', '➭' => '&#10157;', '➮' => '&#10158;', '➯' => '&#10159;', '➱' => '&#10161;', '➲' => '&#10162;', '➳' => '&#10163;', '➴' => '&#10164;', '➵' => '&#10165;', '➶' => '&#10166;', '➷' => '&#10167;', '➸' => '&#10168;', '➹' => '&#10169;', '➺' => '&#10170;', '➻' => '&#10171;', '➼' => '&#10172;', '➽' => '&#10173;', '➾' => '&#10174;');
  373.  
  374.         foreach($a as $k => $v) {
  375.  
  376.             $s = str_replace($k, $v, $s);
  377.         }
  378.  
  379.         return $s;
  380.     }
  381.  
  382.     public function acc_text_to_dec_ents($s) {
  383.  
  384.         $a = null;
  385.  
  386.         $a = array('Á' => '&#193;', 'Â' => '&#194;', 'Æ' => '&#198;', 'À' => '&#192;', 'Å' => '&#197;', 'Ã' => '&#195;', 'Ä' => '&#196;', 'Ç' => '&#199;', 'É' => '&#201;', 'Ê' => '&#202;', 'È' => '&#200;', 'Ð' => '&#208;', 'Ë' => '&#203;', 'ƒ' => '&#402;', 'Í' => '&#205;', 'Î' => '&#206;', 'Ì' => '&#204;', 'Ï' => '&#207;', 'Ñ' => '&#209;', 'Ó' => '&#211;', 'Ô' => '&#212;', 'Œ' => '&#338;', 'Ò' => '&#210;', 'Ø' => '&#216;', 'Õ' => '&#213;', 'Ö' => '&#214;', 'Š' => '&#352;', 'ß' => '&#223;', 'Þ' => '&#222;', 'Ú' => '&#218;', 'Û' => '&#219;', 'Ù' => '&#217;', 'ü' => '&#252;', 'Ý' => '&#221;', 'Ÿ' => '&#376;', 'á' => '&#225;', 'â' => '&#226;', 'æ' => '&#230;', 'à' => '&#224;', 'å' => '&#229;', 'ã' => '&#227;', 'ä' => '&#228;', 'ç' => '&#231;', 'é' => '&#233;', 'ê' => '&#234;', 'è' => '&#232;', 'ð' => '&#240;', 'ë' => '&#235;', 'ƒ' => '&#402;', 'í' => '&#237;', 'î' => '&#238;', 'ì' => '&#236;', 'ï' => '&#239;', 'ñ' => '&#241;', 'ó' => '&#243;', 'ô' => '&#244;', 'œ' => '&#339;', 'ò' => '&#242;', 'ø' => '&#248;', 'õ' => '&#245;', 'ö' => '&#246;', 'š' => '&#353;', 'ß' => '&#223;', 'þ' => '&#254;', 'ú' => '&#250;', 'û' => '&#251;', 'ù' => '&#249;', 'Ü' => '&#220;', 'ý' => '&#253;', 'ÿ' => '&#255;');
  387.  
  388.         foreach($a as $k => $v) {
  389.  
  390.             $s = str_replace($k, $v, $s);
  391.         }
  392.  
  393.         return $s;
  394.     }
  395.  
  396.     public function safe_html($s, $length = '') {
  397.  
  398.         $s = $this->safe_str($s);
  399.         $s = $this->remove_comments($s);
  400.         $s = $this->remove_tags($s);
  401.         $s = $this->ensure_lt_gt($s);
  402.         $s = $this->text_symbs_to_dec_ents($s);
  403.         $s = $this->acc_text_to_dec_ents($s);
  404.         if (!empty($length) && (mb_strlen($s, mb_detect_encoding($s)) > $length)) {
  405.  
  406.             $s = mb_substr($s, 0, ($length - 5), mb_detect_encoding($s)) . ' [...]';
  407.         }
  408.         $s = $this->ord_space($s);
  409.         $s = $this->ord_newline($s);
  410.         $s = $this->ensure_amp($s);
  411.         return $s;
  412.     }
  413.  
  414.     public function random_anchor() {
  415.  
  416.         $r = range(0, 9);
  417.         shuffle($r);
  418.         $ds = '';
  419.         foreach ($r as $d) {
  420.  
  421.             $ds .= $d;
  422.         }
  423.         return $ds;
  424.     }
  425.  
  426. }
  427.  
  428. /* if (!isset($Swamper) || empty($Swamper)) {
  429.  
  430.     $Swamper = new Swamper();
  431. } */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement