* @license MIT https://opensource.org/licenses/MIT */ namespace Findus23; /** * For development: dump variable * * @param mixed $var */ function debug($var) { // echo "
";
    var_dump($var);
    // echo "
"; } /** * clean html created by editor * * * no inline css * * no unnecessary tags * * remove empty tags () * * remove without attributes * * add target="_blank" to all links * * @param string $input * input-HTML * @param string $linkify * auto-link URLs * @return string clean HTML */ function clean_html($input, $linkify = true) { $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $config->set('HTML.ForbiddenAttributes', 'style,class,size'); $config->set('HTML.ForbiddenElements', 'font,div'); $config->set('AutoFormat.RemoveEmpty', true); $config->set('AutoFormat.Linkify', $linkify); $config->set('AutoFormat.RemoveSpansWithoutAttributes', true); $config->set('HTML.TargetBlank', true); $config->set('Output.TidyFormat', true); // doesn't work without tidy $purifier = new HTMLPurifier($config); $clean_html = $purifier->purify($input); return $clean_html; } /** * shorten text for preview * * @param string $text * input text * @param integer $lenght * @param integer $tolerance * how much additional lenght is acceptable * @return string shortend string */ function text_preview($text, $lenght, $tolerance) { $text = str_replace("$message"; // TODO: -> return } /** * convert HTML-Code to text * * @param string $input * @param boolean $admin * @return string text */ function html2text($input, $admin = true) { if ($admin) { $path = "../"; } else { $path = ""; } // require_once $path . "include/libs/html2text/src/Html2Text.php"; if (! empty($input)) { // https://github.com/soundasleep/html2text/issues/6 $input = mb_convert_encoding($input, 'HTML-ENTITIES', 'UTF-8'); $text = Html2Text\Html2Text::convert($input); return $text; } else { return ""; } } /** * Generate Date from Timestamp * * @param integer $time * timestamp * @param string $lang * @return string 20. Jänner 2014 */ function format_date($timestamp, $lang) { if ($lang == "de") { $day = strftime("%d", $timestamp)*1; //without leading 0 $month_number = strftime("%m", $timestamp); $year = strftime("%Y", $timestamp); $months = array ( "Jänner", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" ); $month = $months[$month_number - 1]; return "$day. $month $year"; } else { return strftime("%d. %B %Y", $timestamp); } }