Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\TransferSmartyTemplate\TemplateHelper;
|
||||
|
||||
final class CommonHelper
|
||||
{
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $replaceChar
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function replaceLineBreaks($string, $replaceChar = ' ')
|
||||
{
|
||||
return (string)preg_replace("/\r\n|\r|\n/", (string)$replaceChar, (string)$string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a template variable
|
||||
*
|
||||
* @example {$var|dump}
|
||||
*
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dumpVariable($data)
|
||||
{
|
||||
return var_export($data, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\TransferSmartyTemplate\TemplateHelper;
|
||||
|
||||
use Xentral\Modules\TransferSmartyTemplate\Exception\InvalidArgumentException;
|
||||
|
||||
final class CsvHelper
|
||||
{
|
||||
/**
|
||||
* Quotes and escapes an CSV value
|
||||
*
|
||||
* @param string $string
|
||||
* @param string $enclosure
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function quoteCsv($string, $enclosure = '"')
|
||||
{
|
||||
if (!is_string($enclosure)) {
|
||||
throw new InvalidArgumentException('Invalid argument. Enclosure need to be type string.');
|
||||
}
|
||||
if (strlen($enclosure) !== 1) {
|
||||
throw new InvalidArgumentException('Invalid argument. Enclosure can only be a single character.');
|
||||
}
|
||||
|
||||
$escapedString = (string)str_replace($enclosure, $enclosure . $enclosure, $string);
|
||||
|
||||
return $enclosure . $escapedString . $enclosure;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\TransferSmartyTemplate\TemplateHelper;
|
||||
|
||||
final class HtmlUrlHelper
|
||||
{
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decodeHtmlEntities($string, $charset = 'UTF-8')
|
||||
{
|
||||
// ENT_HTML5 wird benötigt für Umwandlung von '
|
||||
return html_entity_decode($string, ENT_QUOTES | ENT_HTML5, $charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decodeHtmlSpecialChars($string)
|
||||
{
|
||||
// ENT_HTML5 wird benötigt für Umwandlung von '
|
||||
return htmlspecialchars_decode($string, ENT_QUOTES | ENT_HTML5);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encodeUrl($string)
|
||||
{
|
||||
$string = $this->stripUrlControlChars($string);
|
||||
|
||||
return rawurlencode($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decodeUrl($string)
|
||||
{
|
||||
$string = $this->stripUrlControlChars($string);
|
||||
|
||||
return rawurldecode($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param bool $lineFeed
|
||||
* @param bool $carriageReturn
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function convertBr2LineBreak($string, $lineFeed = true, $carriageReturn = true)
|
||||
{
|
||||
$breakChars = '';
|
||||
if ((bool)$carriageReturn === true) {
|
||||
$breakChars .= "\r";
|
||||
}
|
||||
if ((bool)$lineFeed === true) {
|
||||
$breakChars .= "\n";
|
||||
}
|
||||
|
||||
$string = str_replace(['<br>', '<br/>', '<br />'], $breakChars, $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter alle Steuerzeichen aus; auch Zeilenumbrüche
|
||||
*
|
||||
* @see https://www.ascii-code.com/l
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function stripUrlControlChars($string)
|
||||
{
|
||||
return (string)preg_replace('/[\x00-\x1f\x7f]/', '', (string)$string);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\TransferSmartyTemplate\TemplateHelper;
|
||||
|
||||
final class XmlHelper
|
||||
{
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function escapeXml($string, $charset = 'UTF-8')
|
||||
{
|
||||
$string = $this->stripControlChars($string);
|
||||
|
||||
return htmlspecialchars($string, ENT_XML1 | ENT_QUOTES, $charset, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* CDATA-Abschnitt erzeugen
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function createXmlCdataSection($string)
|
||||
{
|
||||
return sprintf('<![CDATA[%s]]>', (string)$string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtert alle Steuerzeichen aus; außer Zeilenumbrüche, Tabs und Leerzeichen
|
||||
*
|
||||
* @see https://www.ascii-code.com/
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function stripControlChars($string)
|
||||
{
|
||||
// Erlaubte Steuerzeichen
|
||||
// \x09 = Horintal tab (HT) = \t
|
||||
// \x0a = Line feed (LF) = \n
|
||||
// \x0d = Carriage return (CR) = \r
|
||||
$string = (string)preg_replace('/[\x00-\x08]/', '', (string)$string); // Steuerzeichen bis HT und LF
|
||||
$string = (string)preg_replace('/[\x0b\x0c]/', '', (string)$string); // Steuerzeichen zwischen LF und CR
|
||||
$string = (string)preg_replace('/[\x0e-\x1f]/', '', (string)$string); // Steuerzeichen ab CR
|
||||
$string = (string)preg_replace('/[\x7f]/', '', (string)$string); // DELETE
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user