de

designoir

Preprocess

Preprocess.php

Requires: NestedToken

<?php

/**
 * class Preprocess
 * Copyright (C) 2006  Dao Gottwald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact information:
 *   Dao Gottwald  <dao at design-noir.de>
 *   Herltestraße 12
 *   D-01307, Germany
 *
 * @version  1.0.1
 */

require_once 'NestedToken.php';

abstract class Preprocess {
    protected
        $text,
        $token;
    
    abstract public function run ($text);
    
    protected function _escape_init ($t = null) {
        return $this->token = $t ? $t : new NestedToken ('<', '/>');
    }
    protected function _escape_init_plain() {
        return $this->token = new NestedToken;
    }
    protected function _escape_init_plenk() {
        return $this->token = new NestedToken (' ', ' ');
    }
    protected function _escape_init_plenkXml() {
        return $this->token = new NestedToken (' <', '/> ');
    }
    protected function _escape_fin() {
        $this->token->decode ($this->text);
    }
    protected function _escape (array $match) {
        $match = isset ($match[1]) ? $match[1] : $match[0];
        $this->token->encode_string ($match, $match);
        return $match;
    }
    protected function _escape_comments_cdata() {
        $this->text = preg_replace_callback ('~<!--.*?-->~s', array ($this,'_escape'), $this->text);
        $this->text = preg_replace_callback ('~<!\[CDATA\[.*?\]\]>~s', array ($this,'_escape'), $this->text);
    }
    protected function _escape_tags() {
        $tags = func_get_args();
        $this->text = preg_replace_callback ('~</?(?:'. implode ('|', $tags) .')(?: .*?|/)?>~is', array ($this, '_escape'), $this->text);
    }
    protected function _escape_inline_tags() {
        $this->_escape_tags ('a','abbr','acronym','area','b','bdo','big','button','cite','code','del','dfn','em','font','i','img','input','ins','kbd','label','q','s','samp','small','span','strike','strong','sub','sup','tt','u','var','xmp');
    }
    protected function _escape_content() {
        $tags = func_get_args();
        $this->text = preg_replace_callback ('~(<('. implode ('|', $tags) .')(?: .*?)?>.*?</\2>)~is', array ($this, '_escape'), $this->text);
    }
}

?>

Comments

HTML will not be interpreted.

Last changed on March 31, 2006 Dão G., 2005–2010
aggressiv akt andromeda bar beine blue efeu frontal fugaetu industriell komet land noir rost rot sonnenblume splash split winter wolke zeit