diff options
Diffstat (limited to 'paste/include')
-rw-r--r-- | paste/include/class.geshi.php | 119 |
1 files changed, 59 insertions, 60 deletions
diff --git a/paste/include/class.geshi.php b/paste/include/class.geshi.php index ee6436e..f804af0 100644 --- a/paste/include/class.geshi.php +++ b/paste/include/class.geshi.php @@ -1,10 +1,10 @@ <?php /** * GeSHi - Generic Syntax Highlighter - * + * * For information on how to use GeSHi, please consult the documentation * found in the docs/ directory, or online at http://geshi.org/docs/ - * + * * This file is part of GeSHi. * * GeSHi is free software; you can redistribute it and/or modify @@ -29,12 +29,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2004, 2005 Nigel McNie * @version 1.1.0 - * + * */ /** * MAJOR TODOs: - * + * * @todo [blocking 1.1.1] (bug 5) Support balanced context endings * @todo [blocking 1.1.1] (bug 14) OCCs should be able to modify their parent context * @todo [blocking 1.1.1] (bug 16, 17) Better Delphi and Codeworker support @@ -168,7 +168,7 @@ define('GESHI_DEFAULT_FILE_EXTENSION', '.php'); /** * The GeSHi class * - * @package core + * @package core * @author Nigel McNie <nigel@geshi.org> * @version 1.1.0 * @since 1.0.0 @@ -207,42 +207,42 @@ class GeSHi /** * The root context to use for parsing the source - * + * * @var GeSHiContext */ var $_rootContext; - + /** * Whether this object should be prepared as if it will be used * many times - * + * * @var boolean */ var $_cacheRootContext; - + /** * The cached root context, if caching of context trees is enabled - * + * * @var GeSHiContext */ var $_cachedRootContext; - + /** * The GeSHiStyler object used by this class and all contexts for * assisting parsing. - * + * * @var GeSHiStyler */ /**#@-*/ - + /** * Sets the source and language name of the source to parse * * Also sets up other defaults, such as the default encoding - * + * * <b>USAGE:</b> - * + * * <pre>$geshi =& new GeSHi($source, $language); * if (false !== ($msg = $geshi->error())) { * // Handle error here: error message in $msg @@ -268,11 +268,11 @@ class GeSHi 'parse' => $initial_times, 'post' => $initial_times ); - + $this->_styler =& new GeSHiStyler; - // @todo [blocking 1.1.5] Make third parameter an option array thing - + // @todo [blocking 1.1.5] Make third parameter an option array thing + $this->setFileExtension(GESHI_DEFAULT_FILE_EXTENSION); //$this->setOutputFormat(GESHI_OUTPUT_HTML); //$this->setEncoding(GESHI_DEFAULT_ENCODING); @@ -285,7 +285,7 @@ class GeSHi /** * Returns an error message if there has been an error. Useful for debugging, * but not recommended for use on a live site. - * + * * The last error that occured is returned by this method * @todo [blocking 1.1.9] Documentation: has this changed from 1.0.X? * @@ -347,7 +347,7 @@ class GeSHi $this->_times['pre'][0] = microtime(); geshi_dbg('GeSHi::setLanguage('.$language_name.')', GESHI_DBG_API); $this->_language = strtolower($language_name); - + // Make a legal language name if (false === strpos($this->_language, '/')) { $this->_language .= '/'.$this->_language; @@ -378,13 +378,13 @@ class GeSHi { $this->setLanguage($language_name); } - + /** * Sets whether this object should cache the root context as loaded. Use * this if you're going to use the same language in this object to parse * multiple source codes. * - * @param boolean true if caching of context data should be used + * @param boolean true if caching of context data should be used */ function cacheRootContext ($flag = true) { @@ -393,10 +393,10 @@ class GeSHi $this->_cachedRootContext = ($this->_cacheRootContext) ? $this->_rootContext : null; geshi_dbg(' Set caching to ' . $flag . ', cached root context size = ' . count($this->_cachedRootContext), GESHI_DBG_API); } - + /** * Sets the file extension to use when getting external php files - * + * * @param string The file extension for PHP files. Can be specified with or without the leading "." */ function setFileExtension ($extension) @@ -413,7 +413,7 @@ class GeSHi * * You can pass a string to this method, it will return various timings based * on what string you pass: - * + * * <ul> * <li>If you pass <b>'total'</b> (default), you will get the time it took to * load, parse and post-process the last call to {@link GeSHi::parseCode()}.</li> @@ -442,10 +442,10 @@ class GeSHi $this->_error = GESHI_ERROR_INVALID_TIME_TYPE; return false; } - + /** * Sets styles of contexts in the source code - * + * * @param string The selector to use, this is the style name of a context. Example: php/php * @param string The CSS styles to apply to the context */ @@ -454,10 +454,10 @@ class GeSHi geshi_dbg('GeSHi::setStyles(' . $selector . ', ' . $styles . ')', GESHI_DBG_API); $this->_styler->setStyle($selector, $styles); } - + /** * Returns the version of this GeSHi - * + * * @return string The version of this GeSHi * @static */ @@ -466,10 +466,10 @@ class GeSHi geshi_dbg('GeSHi::getVersion()', GESHI_DBG_API); return GESHI_VERSION; } - + /** * Returns the version of this GeSHi - * + * * @return string The version of this GeSHi * @deprecated in favour of {@link GeSHi::getVersion()} */ @@ -480,7 +480,7 @@ class GeSHi /** * Syntax-highlights the source code - * + * * @return string The source code, highlighted */ function parseCode () @@ -493,7 +493,7 @@ class GeSHi geshi_dbg('@e Error occured!!', GESHI_DBG_PARSE); $this->_times['parse'][1] = $this->_times['post'][0] = microtime(); $result = $this->_parsePostProcess(); - $this->_times['post'][1] = microtime(); + $this->_times['post'][1] = microtime(); return $result; } @@ -502,11 +502,11 @@ class GeSHi if ($this->_cacheRootContext) { $this->_rootContext = $this->_cachedRootContext; } - + //@todo [blocking 1.1.5] does this space still need to be added? $code = ' ' . $this->_source; // Runtime setup of context tree/styler info - // Reset the parse data to nothing + // Reset the parse data to nothing $this->_styler->resetParseData(); // Remove contexts from the parse tree that aren't interesting $this->_rootContext->trimUselessChildren($code); @@ -517,7 +517,7 @@ class GeSHi $this->_times['parse'][1] = $this->_times['post'][0] = microtime(); $result = $this->_parsePostProcess(); $this->_times['post'][1] = microtime(); - + return $result; } @@ -530,7 +530,7 @@ class GeSHi */ /** * Get the error message relating to the current error code - * + * * @return string The error message relating to the current error code */ function _getErrorMessage () @@ -568,7 +568,7 @@ class GeSHi /** * Check that the language name to be used is valid - * + * * @return boolean true if the language name is valid, else false */ function _languageNameValid () @@ -578,7 +578,7 @@ class GeSHi // Check if the language contains illegal characters. If language names do // not match this regular expression, they are not valid. This is a useful // security check as well, if people blindly use a post/get variable as the - // language name... + // language name... if (!preg_match('#[a-z][a-z0-9]*(/[a-z][a-z0-9]*)+#', $this->_language)) { geshi_dbg('@e Language name contains illegal characters', GESHI_DBG_API | GESHI_DBG_ERR); $this->_error = GESHI_ERROR_LANG_NAME_ILLEGAL_CHARS; @@ -588,7 +588,7 @@ class GeSHi // Check that the language file for this language exists $language_file = $this->_getLanguageDataFile(); geshi_dbg(' Language file to use: ' . $language_file, GESHI_DBG_API); - + if (!geshi_can_include($language_file)) { geshi_dbg('@e Language does not exist on filesystem', GESHI_DBG_API | GESHI_DBG_ERR); $this->_error = GESHI_ERROR_NO_SUCH_LANG; @@ -601,13 +601,13 @@ class GeSHi /** * Checks to make sure that the source code inputted is valid - * + * * The source is valid when: - * + * * <ul> * <li>it is not empty</li> * </ul> - * + * * @return true if the source code is valid, else false */ function _sourceValid () @@ -646,22 +646,22 @@ class GeSHi } // Inform the context tree that all contexts have been loaded, so it is OK to search through - // the tree for default styles as needed. - $this->_rootContext->loadStyleData(); - - // Save a copy of the root context if we are caching + // the tree for default styles as needed. + $this->_rootContext->loadStyleData(); + + // Save a copy of the root context if we are caching $this->_cachedRootContext = ($this->_cacheRootContext) ? $this->_rootContext : null; - - geshi_dbg('Finished preprocessing', GESHI_DBG_API); + + geshi_dbg('Finished preprocessing', GESHI_DBG_API); } /** * Builds the result string to return, by looking at the context data array - * + * * This is to be moved into a new class: GeSHi_Highlighter, which will extend GeSHi to * do this job. The GeSHi class will still be able to highlight source code, but this * behaviour is deprecated and will be removed in the next major release. - * + * * @return The code, post-processed. */ function _parsePostProcess () @@ -670,7 +670,7 @@ class GeSHi // If there was an error, the source will be in string form return '<pre style="background-color:#fcc;border:1px solid #c99;">' . htmlspecialchars($this->_source) .'</pre>'; } - + // $this->_data should hold an array( // 0 => array(0=>string of code, 1=> context name identifier $result = ''; @@ -707,18 +707,18 @@ class GeSHi } } $result .= '</pre>'; - + // @todo [blocking 1.1.1] (bug 12) Evaluate feasability and get working if possible the functionality below... //$result = preg_replace('#([^"])(((https?)|(ftp))://[a-z0-9\-]+\.([a-z0-9\-\.]+)+/?([a-zA-Z0-9\.\-_%]+/?)*\??([a-zA-Z0-9=&\[\];%]+)?(\#[a-zA-Z0-9\-_]+)?)#', '\\1<a href="\\2">\\2</a>', $result); //$result = preg_replace('#([a-z0-9\._\-]+@[[a-z0-9\-\.]+[a-z]+)#si', '<a href="mailto:\\1">\\1</a>', $result); - - return $result; + + return $result; } - - + + /** * Helper function to convert a language name to the file name where its data will reside - * + * * @return The absolute path of the language file where the current language data will be sourced */ function _getLanguageDataFile () @@ -733,7 +733,6 @@ class GeSHi geshi_dbg('Language file is ' . $language_file, GESHI_DBG_API); return GESHI_LANGUAGES_ROOT . $language_file; } - /**#@-*/ + /**#@-*/ } ?> - |