<commit_before><?php
/**
 * $Id$
 *
 * Various HTML, Javascript and CSS utility functions
 *
 * @author <NAME>, 2007-2012 <<EMAIL>>
 */

require_once('XmlDocumentHandler.php');

require_once('XhtmlComponentA.php');

//STATUS: wip

//TODO in js_reload() & js_redirect(): throw exception if server outputted errors during this page load. how to check that?

function is_html_color($s)
{
    $regexp = '/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/';

    preg_match($regexp, $s, $matches);

    if ($matches && $matches[0] == $s)
        return true;

    return false;
}

/** Decodes html entities from input string */
function htmlchars_decode($s)
{
    return html_entity_decode($s, ENT_QUOTES, 'UTF-8');
}

/** similar to strip_tags() but also removes all javascript / css inside <script> or <style> tags */
function strip_html($s)
{
    $search = array(
    '@<(script|style)[^>]*?>.*?</(script|style)>@si', // javascript, css
    '@<[\/\!]*?[^<>]*?>@si',                          // HTML tags
    '@<![\s\S]*?--[ \t\n\r]*>@',    // strip multi-line comments including CDATA
    );

    $s = preg_replace($search, '', $s);

    $s = htmlchars_decode($s);
    return $s;
}

/** Like htmlentities() but only handles predefined xml entities */
function xmlentities($s)
{
    $from = array('<',    '>',    "'",      '"',      '&');
    $to   = array('&lt;', '&gt;', '&apos;', '&quot;', '&amp;');

    return str_replace($from, $to, $s);
}

/** @param $dst redirects user to destination url relative to website base url */
function redir($dst)
{
    $page = XmlDocumentHandler::getInstance();
    header('Location: '.$page->getRelativeUrl().$dst);
    die;
}

/** @param $url partial url to generate a url relative website base */
function relurl($url)
{
    if (strpos($url, '://') !== false || substr($url, 0, 1) == '/' || substr($url, 0, 1) == '?')
        return $url;

    $page = XmlDocumentHandler::getInstance();
    return $page->getRelativeUrl().$url;<commit_msg>FIX: allow redir() to take absolute url:s<commit_after><?php
/**
 * $Id$
 *
 * Various HTML, Javascript and CSS utility functions
 *
 * @author <NAME>, 2007-2012 <<EMAIL>>
 */

require_once('XmlDocumentHandler.php');

require_once('XhtmlComponentA.php');

//STATUS: wip

//TODO in js_reload() & js_redirect(): throw exception if server outputted errors during this page load. how to check that?

function is_html_color($s)
{
    $regexp = '/^\#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/';

    preg_match($regexp, $s, $matches);

    if ($matches && $matches[0] == $s)
        return true;

    return false;
}

/** Decodes html entities from input string */
function htmlchars_decode($s)
{
    return html_entity_decode($s, ENT_QUOTES, 'UTF-8');
}

/** similar to strip_tags() but also removes all javascript / css inside <script> or <style> tags */
function strip_html($s)
{
    $search = array(
    '@<(script|style)[^>]*?>.*?</(script|style)>@si', // javascript, css
    '@<[\/\!]*?[^<>]*?>@si',                          // HTML tags
    '@<![\s\S]*?--[ \t\n\r]*>@',    // strip multi-line comments including CDATA
    );

    $s = preg_replace($search, '', $s);

    $s = htmlchars_decode($s);
    return $s;
}

/** Like htmlentities() but only handles predefined xml entities */
function xmlentities($s)
{
    $from = array('<',    '>',    "'",      '"',      '&');
    $to   = array('&lt;', '&gt;', '&apos;', '&quot;', '&amp;');

    return str_replace($from, $to, $s);
}

/** @param $dst redirects user to destination url relative to website base url */
function redir($dst)
{
    if (strpos($dst, '://') !== false || substr($dst, 0, 1) == '/' || substr($dst, 0, 1) == '?') {
        $loc = $dst;
    } else {
        $page = XmlDocumentHandler::getInstance();
        $loc = $page->getRelativeUrl().$dst;
    }

    header('Location: '.$loc);
    die;
}

/** @param $url partial url to generate a url relative website base */
function relurl($url)
{
    if (strpos($url, '://') !== false || substr($url, 0, 1) == '/' || substr($url, 0, 1) == '?')
        return $url;

    $page = XmlDocumentHandler::getInstance();
    return $page->getRelativeUrl().$url;
{'fraction_non_alphanumeric': 0.21510075260985675, 'fraction_numerical': 0.010682204418548192, 'mean_word_length': 3.1912512716174977, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2239758', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1410, 'n_words': 357}