<commit_before><?php

/**
 * ZFDocumentor
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category  Documentation
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2010-2011 <NAME> <<EMAIL>>
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 */

class HTML_Filter extends FilterIterator
{

    public function accept()
    {
        return (substr($this->current(), -5) == '.html');
    }
}

class HighlightHTML
{

    private static $_type = 'html';
    private static $_lang = 'en';
    private static $_version = '1.11';
    private static $_versionBar = null;

    public static function main($type, $version, $lang)
    {
        if (preg_match('/[0-9]{1}\.[0-9]{1,2}/i', $version)) {
            self::$_version = $version;
        } else {
            die("Version '$version' doesn't valid");
        }
        if (in_array($type, array('html', 'htmlhelp'))) {
            self::$_type = $type;
            if (!file_exists(dirname(dirname(__FILE__)) . '/output/' . $type)) {
                die("Type '$type' doesn't exist (1)");
            }
        } else {
            die("Type '$type' doesn't valid (2)");
        }
        if (preg_match('/^([a-z]{2}(\-[a-z]{2})?)$/i', $lang, $matches)) {
            self::$_lang = strtolower($lang);
            if (!file_exists(dirname(dirname(__FILE__)) . '/output/' . $type . '/' . $version . '/' . $lang)) {
                die("Language '$lang' doesn't exist (1)");
            }
        } else {
            die("Language '$lang' doesn't valid (2)");
        }
        $toc = self::_getSubstring(file_get_contents(dirname(dirname(__FILE__)) . '/output/' . $type . '/' . $version . '/' . $lang . '/index.html'), '<dl>', '</dl>', true, true, true);
	file_put_contents(dirname(dirname(__FILE__)) . '/output/' . $type . '/' . $version . '/' . $lang . '/toc.html', $toc);
        self::$_versionBar = self::generateVersion();
        self::highlightAllFile();
        /*self::insertImageLink();
        if (substr($lang, 0, 8) == 'htmlhelp') {
            self::removeTocFirstNode();
            self::changeChmTitle();
        }*/
    }
    
    public static function generateVersion()
    {
        $allLang = array('en', 'de', 'fr', 'ja');
        $versions = array('1.11' => array('en', 'de', 'es', 'fr', 'ja', 'pt-br'),
                          '1.10' => array('en', 'de', 'es', 'fr', 'ja', 'pt-br'),
                          '1.9' => array('en', 'de', 'fr', 'ja'),
                          '1.8' => array('en', 'de', 'fr', 'ja'),
                          '1.7' => array('en', 'de', 'fr', 'ja'),
                          '1.6' => array('en', 'de', 'fr', 'ja'),
                          '1.5' => array('en', 'de', 'fr', 'ja'),
                          '1.0' => array('en', 'de', 'fr', 'ja'));
        $bar = '';
        foreach ($versions as $num => $langs) {
	    $img = '';
            foreach ($langs as $l) {
                $img .= sprintf(
                  '<img src="../../images/%s.png" title="%s" alt="%s">' . PHP_EOL,
                  $l,
                  $l,
                  $l
                );
            }
	    $bar .= sprintf(
		'<li><a href="../../%s/" class="version%s">ZF %s <span>%s</span></a></li>' . PHP_EOL,
		$num,
		($num == self::$_version ? ' active' : ''),
		$num,
		$img
	    );
        }
        return $bar;
    }

    private static function _getSubstring($text, $start, $end, $includeStart = true, $includeEnd = true, $strrpos = false)
    {
        if ($includeStart) {
            $prefix = 0;
        } else {
            $prefix = strlen($start);
        }

        if ($includeEnd) {
            $suffix = strlen($end);
        } else {
            $suffix = 0;
        }

        $start = strpos($text, $start);

        if ($strrpos) {
            $_end = strrpos($text, $end);
        } else {
            $_end = strpos($text, $end, $start);
        }

        if ($start !== FALSE) {
            return substr(
              $text,
              $start + $prefix,
              $_end - ($start + $prefix) + $suffix
            );
        } else {
            return '';
        }
    }

    public static function highlightAllFile()
    {
        $dir = new DirectoryIterator(dirname(dirname(__FILE__)) . '/output/' . self::$_type . '/' . self::$_version . '/' . self::$_lang);
        $filter = new HTML_Filter($dir);
        $template = file_get_contents(dirname(dirname(__FILE__)) . '/page.html.in');
        foreach ($filter as $file) {
            $title   = '';
            $content = '';
            $prev    = '';
            $next    = '';

	    if ($file->getFileName() == 'toc.html') {
	        continue;
	    }

            $text = file_get_contents($file->getPathName());
            $title   = 'Zend Framework ' . self::_getZfVersion() . ' - ' . self::_getSubstring($text, '<title>', '</title>', false, false);

            $content = self::_getSubstring($text, '<div class="part"', '<div class="navfooter">', true, false);
            if (!$content) {
                $content = self::_getSubstring($text, '<div class="chapter"', '<div class="navfooter">', true, false);
            }
            if (!$content) {
                $content = self::_getSubstring($text, '<div class="appendix"', '<div class="navfooter">', true, false);
            }
            if (!$content) {
                $content = self::_getSubstring($text, '<div class="preface"', '<div class="navfooter">', true, false);
            }
            if (!$content) {<commit_msg>ZFDocumentor: colorize as PHP if no language provided<commit_after><?php

/**
 * ZFDocumentor
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category  Documentation
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2010-2011 <NAME> <<EMAIL>>
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 */

class HTML_Filter extends FilterIterator
{

    public function accept()
    {
        return (substr($this->current(), -5) == '.html');
    }
}

class HighlightHTML
{

    private static $_type = 'html';
    private static $_lang = 'en';
    private static $_version = '1.11';
    private static $_versionBar = null;

    public static function main($type, $version, $lang)
    {
        if (preg_match('/[0-9]{1}\.[0-9]{1,2}/i', $version)) {
            self::$_version = $version;
        } else {
            die("Version '$version' doesn't valid");
        }
        if (in_array($type, array('html', 'htmlhelp'))) {
            self::$_type = $type;
            if (!file_exists(dirname(dirname(__FILE__)) . '/output/' . $type)) {
                die("Type '$type' doesn't exist (1)");
            }
        } else {
            die("Type '$type' doesn't valid (2)");
        }
        if (preg_match('/^([a-z]{2}(\-[a-z]{2})?)$/i', $lang, $matches)) {
            self::$_lang = strtolower($lang);
            if (!file_exists(dirname(dirname(__FILE__)) . '/output/' . $type . '/' . $version . '/' . $lang)) {
                die("Language '$lang' doesn't exist (1)");
            }
        } else {
            die("Language '$lang' doesn't valid (2)");
        }
        $toc = self::_getSubstring(file_get_contents(dirname(dirname(__FILE__)) . '/output/' . $type . '/' . $version . '/' . $lang . '/index.html'), '<dl>', '</dl>', true, true, true);
	file_put_contents(dirname(dirname(__FILE__)) . '/output/' . $type . '/' . $version . '/' . $lang . '/toc.html', $toc);
        self::$_versionBar = self::generateVersion();
        self::highlightAllFile();
        /*self::insertImageLink();
        if (substr($lang, 0, 8) == 'htmlhelp') {
            self::removeTocFirstNode();
            self::changeChmTitle();
        }*/
    }
    
    public static function generateVersion()
    {
        $allLang = array('en', 'de', 'fr', 'ja');
        $versions = array('1.11' => array('en', 'de', 'es', 'fr', 'ja', 'pt-br'),
                          '1.10' => array('en', 'de', 'es', 'fr', 'ja', 'pt-br'),
                          '1.9' => array('en', 'de', 'fr', 'ja'),
                          '1.8' => array('en', 'de', 'fr', 'ja'),
                          '1.7' => array('en', 'de', 'fr', 'ja'),
                          '1.6' => array('en', 'de', 'fr', 'ja'),
                          '1.5' => array('en', 'de', 'fr', 'ja'),
                          '1.0' => array('en', 'de', 'fr', 'ja'));
        $bar = '';
        foreach ($versions as $num => $langs) {
	    $img = '';
            foreach ($langs as $l) {
                $img .= sprintf(
                  '<img src="../../images/%s.png" title="%s" alt="%s">' . PHP_EOL,
                  $l,
                  $l,
                  $l
                );
            }
	    $bar .= sprintf(
		'<li><a href="../../%s/" class="version%s">ZF %s <span>%s</span></a></li>' . PHP_EOL,
		$num,
		($num == self::$_version ? ' active' : ''),
		$num,
		$img
	    );
        }
        return $bar;
    }

    private static function _getSubstring($text, $start, $end, $includeStart = true, $includeEnd = true, $strrpos = false)
    {
        if ($includeStart) {
            $prefix = 0;
        } else {
            $prefix = strlen($start);
        }

        if ($includeEnd) {
            $suffix = strlen($end);
        } else {
            $suffix = 0;
        }

        $start = strpos($text, $start);

        if ($strrpos) {
            $_end = strrpos($text, $end);
        } else {
            $_end = strpos($text, $end, $start);
        }

        if ($start !== FALSE) {
            return substr(
              $text,
              $start + $prefix,
              $_end - ($start + $prefix) + $suffix
            );
        } else {
            return '';
        }
    }

    public static function highlightAllFile()
    {
        $dir = new DirectoryIterator(dirname(dirname(__FILE__)) . '/output/' . self::$_type . '/' . self::$_version . '/' . self::$_lang);
        $filter = new HTML_Filter($dir);
        $template = file_get_contents(dirname(dirname(__FILE__)) . '/page.html.in');
        foreach ($filter as $file) {
            $title   = '';
            $content = '';
            $prev    = '';
            $next    = '';

	    if ($file->getFileName() == 'toc.html') {
	        continue;
	    }

            $text = file_get_contents($file->getPathName());
	    $text = str_replace('class="programlisting"', 'class="programlisting brush: php"', $text);
            $title   = 'Zend Framework ' . self::_getZfVersion() . ' - ' . self::_getSubstring($text, '<title>', '</title>', false, false);

            $content = self::_getSubstring($text, '<div class="part"', '<div class="navfooter">', true, false);
            if (!$content) {
                $content = self::_getSubstring($text, '<div class="chapter"', '<div class="navfooter">', true, false);
            }
            if (!$content) {
                $content = self::_getSubstring($text, '<div class="appendix"', '<div class="navfooter">', true, false);
            }
            if (!$content) {
                $content = self::_getSubstring($text, '<div class="preface"', '<div class="navfooter">', true, false);
            }
            if (!$content) {
{'fraction_non_alphanumeric': 0.1955927570891698, 'fraction_numerical': 0.008028698325930988, 'mean_word_length': 1.8133109082172032, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6580688', 'n_tokens_mistral': 3663, 'n_tokens_neox': 3570, 'n_words': 843}