Beispiel #1
0
function get_autolink_pattern_sub(&$pages, $start, $end, $pos)
{
    if ($end == 0) {
        return '(?!)';
    }
    $result = '';
    $count = $i = $j = 0;
    $x = mb_strlen($pages[$start]) <= $pos;
    if ($x) {
        ++$start;
    }
    for ($i = $start; $i < $end; $i = $j) {
        $char = mb_substr($pages[$i], $pos, 1);
        for ($j = $i; $j < $end; $j++) {
            if (mb_substr($pages[$j], $pos, 1) != $char) {
                break;
            }
        }
        if ($i != $start) {
            $result .= '|';
        }
        if ($i >= $j - 1) {
            $result .= str_replace(' ', '\\ ', preg_quote(mb_substr($pages[$i], $pos), '/'));
        } else {
            $result .= str_replace(' ', '\\ ', preg_quote($char, '/')) . get_autolink_pattern_sub($pages, $i, $j, $pos + 1);
        }
        ++$count;
    }
    if ($x || $count > 1) {
        $result = '(?:' . $result . ')';
    }
    if ($x) {
        $result .= '?';
    }
    return $result;
}
function plugin_update_entities_create($do = FALSE)
{
    $files = array('xhtml-lat1.ent', 'xhtml-special.ent', 'xhtml-symbol.ent');
    $entities = array_map('plugin_update_entities_strtr', array_values(get_html_translation_table(HTML_ENTITIES)));
    $items = array('php:html_translation_table');
    $matches = array();
    foreach ($files as $file) {
        $source = file(W3C_XHTML_DTD_LOCATION . $file);
        //			or die_message('cannot receive ' . W3C_XHTML_DTD_LOCATION . $file . '.');
        if (!is_array($source)) {
            $items[] = 'w3c:' . $file . ' COLOR(red):not found.';
            continue;
        }
        $items[] = 'w3c:' . $file;
        if (preg_match_all('/<!ENTITY\\s+([A-Za-z0-9]+)/', join('', $source), $matches, PREG_PATTERN_ORDER)) {
            $entities = array_merge($entities, $matches[1]);
        }
    }
    if (!$do) {
        return $items;
    }
    $entities = array_unique($entities);
    sort($entities, SORT_STRING);
    $min = 999;
    $max = 0;
    foreach ($entities as $entity) {
        $len = strlen($entity);
        $max = max($max, $len);
        $min = min($min, $len);
    }
    $pattern = "(?=[a-zA-Z0-9]\\{{$min},{$max}})" . get_autolink_pattern_sub($entities, 0, count($entities), 0);
    $fp = fopen(CACHE_DIR . 'entities.dat', 'w') or die_message('cannot write file ' . CACHE_DIR . 'entities.dat<br />' . "\n" . 'maybe permission is not writable or filename is too long');
    fwrite($fp, $pattern);
    fclose($fp);
    return $items;
}