mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-11-15 04:27:14 +01:00
444 lines
13 KiB
PHP
444 lines
13 KiB
PHP
<?php
|
||
/*
|
||
**** COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
|
||
*
|
||
* Xentral (c) Xentral ERP Sorftware GmbH, Fuggerstrasse 11, D-86150 Augsburg, * Germany 2019
|
||
*
|
||
* This file is licensed under the Embedded Projects General Public License *Version 3.1.
|
||
*
|
||
* You should have received a copy of this license from your vendor and/or *along with this file; If not, please visit www.wawision.de/Lizenzhinweis
|
||
* to obtain the text of the corresponding license version.
|
||
*
|
||
**** END OF COPYRIGHT & LICENSE NOTICE *** DO NOT REMOVE ****
|
||
*/
|
||
?>
|
||
<?php
|
||
|
||
class WawiString
|
||
{
|
||
|
||
|
||
function __construct()
|
||
{
|
||
}
|
||
|
||
function Convert($value,$input,$output)
|
||
{
|
||
if($input=="")
|
||
return $value;
|
||
|
||
|
||
/*if (strpos($a, '\\') !== false)
|
||
$input = str_replace('/','\/',$input);*/
|
||
|
||
$array = $this->FindPercentValues($input);
|
||
$regexp = $this->BuildRegExp($array);
|
||
|
||
$elements =
|
||
preg_split($regexp,$value,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||
|
||
// input und elements stimmmen ueberein
|
||
|
||
$newout = $output;
|
||
$i = 0;
|
||
foreach($array as $key=>$value)
|
||
{
|
||
$newout = str_replace($key,isset($elements[$i])?$elements[$i]:'',$newout);
|
||
$i++;
|
||
}
|
||
return $newout;
|
||
}
|
||
|
||
/**
|
||
* @param string $string
|
||
*
|
||
* @return string
|
||
*/
|
||
public function removeUtf8Bom($string) {
|
||
if(!is_string($string) || strlen($string)< 3) {
|
||
return $string;
|
||
}
|
||
if(ord($string[0]) === 239 && ord($string[1]) === 187 && ord($string[2]) === 191) {
|
||
return substr($string,3);
|
||
}
|
||
return $string;
|
||
}
|
||
|
||
function BuildRegExp($array)
|
||
{
|
||
|
||
$regexp = '/^';
|
||
foreach($array as $value)
|
||
{
|
||
$value = str_replace('.','\.',$value);
|
||
$value = str_replace('+','\+',$value);
|
||
$value = str_replace('*','\*',$value);
|
||
$value = str_replace('?','\?',$value);
|
||
$regexp .= '(\S+)'.$value;
|
||
}
|
||
$regexp .= '/';
|
||
|
||
return $regexp;
|
||
}
|
||
|
||
function FindPercentValues($pattern)
|
||
{
|
||
preg_match_all('/(?:(%[0-9]+)|.)/i', $pattern, $matches);
|
||
$hash = '';
|
||
$collect = '';
|
||
$start = true;
|
||
foreach($matches[1] as $key=>$value)
|
||
{
|
||
if($value=="")
|
||
$collecting = true;
|
||
else
|
||
{
|
||
$collecting = false;
|
||
$oldhash = isset($hash)?$hash:null;
|
||
$hash = $value;
|
||
}
|
||
|
||
if(!$collecting)
|
||
{
|
||
if(!$start)
|
||
$replace[$oldhash] = $collect;
|
||
$collect="";
|
||
}
|
||
else
|
||
$collect .=$matches[0][$key];
|
||
$start = false;
|
||
}
|
||
$replace[$hash] = $collect;
|
||
return $replace;
|
||
}
|
||
|
||
function encodeText($string)
|
||
{
|
||
$string = str_replace("\\r\\n","#BR#",$string);
|
||
$string = str_replace("\n","#BR#",$string);
|
||
$encoded = htmlspecialchars(stripslashes($string), ENT_QUOTES);
|
||
|
||
|
||
return $encoded;
|
||
}
|
||
|
||
function decodeText($_str, $_form=true)
|
||
{
|
||
if ($_form) {
|
||
$_str = str_replace("#BR#", "\r\n", $_str);
|
||
}
|
||
else {
|
||
$_str = str_replace("#BR#", "<br>", $_str);
|
||
}
|
||
return($_str);
|
||
}
|
||
|
||
function valid_utf8( $string )
|
||
{
|
||
return !((bool)preg_match('~\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF\xC0\xC1~ms',$string));
|
||
}
|
||
|
||
/**
|
||
* @param mixed $text
|
||
*
|
||
* @return string
|
||
*/
|
||
public function fixeUmlaute($text) {
|
||
if(!is_string($text)) {
|
||
return $text;
|
||
}
|
||
$umlaute = $this->getUmlauteArray();
|
||
|
||
return str_replace(array_keys($umlaute),array_values($umlaute), $text);
|
||
}
|
||
|
||
/**
|
||
* @return array
|
||
*/
|
||
public function getUmlauteArray() {
|
||
return array( 'ü'=>'ü', 'ä'=>'ä', 'ö'=>'ö', 'Ö'=>'Ö', 'Ã?'=>'ß','ß'=>'ß', 'à '=>'à', 'á'=>'á', 'â'=>'â', 'ã'=>'ã', 'ù'=>'ù', 'ú'=>'ú', 'û'=>'û', 'Ù'=>'Ù', 'Ú'=>'Ú', 'Û'=>'Û', 'Ãœ'=>'Ü', 'ò'=>'ò', 'ó'=>'ó', 'ô'=>'ô', 'è'=>'è', 'é'=>'é', 'ê'=>'ê', 'ë'=>'ë', 'À'=>'À', 'Ã<81>'=>'Á', 'Â'=>'Â', 'Ã'=>'Ã', 'Ä'=>'Ä', 'Ã…'=>'Å', 'Ç'=>'Ç', 'È'=>'È', 'É'=>'É', 'Ê'=>'Ê', 'Ë'=>'Ë', 'ÃŒ'=>'Ì', 'Ã<8d>'=>'Í', 'ÃŽ'=>'Î', 'Ã<8f>'=>'Ï', 'Ñ'=>'Ñ', 'Ã’'=>'Ò', 'Ó'=>'Ó', 'Ô'=>'Ô', 'Õ'=>'Õ', 'Ø'=>'Ø', 'Ã¥'=>'å', 'æ'=>'æ', 'ç'=>'ç', 'ì'=>'ì', 'Ã'=>'í', 'î'=>'î', 'ï'=>'ï', 'ð'=>'ð', 'ñ'=>'ñ', 'õ'=>'õ', 'ø'=>'ø', 'ý'=>'ý', 'ÿ'=>'ÿ', '€'=>'€' );
|
||
}
|
||
|
||
|
||
function unicode_decode($content) {
|
||
$ISO10646XHTMLTrans = array(
|
||
"&"."#34;" => """,
|
||
"&"."#38;" => "&",
|
||
"&"."#39;" => "'",
|
||
"&"."#60;" => "<",
|
||
"&"."#62;" => ">",
|
||
"&"."#128;" => "€",
|
||
"&"."#160;" => "",
|
||
"&"."#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;" => "⌋",
|
||
"&"."#9001;" => "⟨",
|
||
"&"."#9002;" => "⟩",
|
||
"&"."#9674;" => "◊",
|
||
"&"."#9824;" => "♠",
|
||
"&"."#9827;" => "♣",
|
||
"&"."#9829;" => "♥",
|
||
"&"."#9830;" => "♦"
|
||
);
|
||
|
||
return str_replace(array_keys($ISO10646XHTMLTrans), array_values($ISO10646XHTMLTrans), $content);
|
||
}
|
||
|
||
/**
|
||
* @param string $string
|
||
*
|
||
* @return string
|
||
*/
|
||
public function ReadyForPDF($string='')
|
||
{
|
||
return trim(
|
||
html_entity_decode(
|
||
str_replace(
|
||
['“','„','–',"’","'","NONBLOCKINGZERO"],
|
||
['"','','-',"'","'",''],
|
||
$string
|
||
),
|
||
ENT_QUOTES,
|
||
'UTF-8'
|
||
)
|
||
);
|
||
}
|
||
}
|