当前位置: 首页>>代码示例>>PHP>>正文


PHP GeSHi::error方法代码示例

本文整理汇总了PHP中GeSHi::error方法的典型用法代码示例。如果您正苦于以下问题:PHP GeSHi::error方法的具体用法?PHP GeSHi::error怎么用?PHP GeSHi::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GeSHi的用法示例。


在下文中一共展示了GeSHi::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: format_code

 public function format_code($text, $post = null)
 {
     if (isset($post)) {
         $code = $text;
         if (preg_match("/\\[gist: ([0-9]+)\\]/i", $code, $matches)) {
             return '<script src="http://gist.github.com/' . $matches[1] . '.js"></script>';
         }
         $post->code_unformatted = $post->code;
         $languages = getLanguages();
         $geshi = new GeSHi($code, $languages[$post->language]);
         if ($geshi->error() !== false) {
             return "<pre id='geshi_code'>" . $geshi->error() . "</pre>";
         }
         $geshi->set_overall_id('geshi_code');
         $return = $geshi->parse_code();
         return $return;
     } else {
         return "<pre id='geshi_code'>" . $text . "</pre>";
     }
 }
开发者ID:stevestreza,项目名称:code-feather,代码行数:20,代码来源:code.php

示例2: main

 /**
  * The main method of the Plugin
  *
  * @param	string		$content: The PlugIn content
  * @param	array		$conf: The PlugIn configuration
  * @return	The content that is displayed on the website
  */
 function main($content, $config)
 {
     if (!t3lib_extMgm::isLoaded('geshilib')) {
         return "Geshi library not loaded";
     }
     // get content
     $this->pi_initPIflexForm();
     $config['content.']['lang'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cLang', 'sVIEW');
     $config['content.']['code'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cCode', 'sVIEW');
     $config['content.']['highlight'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cHighlight', 'sOPTIONS');
     $config['content.']['startnumber'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'cStartnumber', 'sOPTIONS');
     // init geshi library
     $this->geshi = new GeSHi($config['content.']['code'], $config['content.']['lang']);
     // defaults
     $this->geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     // set highlighted lines
     if ($config['content.']['highlight'] !== '') {
         $this->geshi->highlight_lines_extra(split(',', $config['content.']['highlight']));
     }
     // set startnumber
     if (isset($config['content.']['startnumber'])) {
         $this->geshi->start_line_numbers_at($config['content.']['startnumber']);
     }
     // style
     if (isset($config['default.'])) {
         $this->_styleSubjects($config['default.']);
     }
     if (isset($config[$config['content.']['lang'] . '.'])) {
         $this->_styleSubjects($config[$config['content.']['lang'] . '.']);
     }
     // external stylesheets
     if (isset($config['global.']['external']) && $config['global.']['external'] == 0) {
         // do not use external style sheets
     } else {
         // mtness.net modification: I love stylesheets!
         $this->geshi->enable_classes();
         // Echo out the stylesheet for this code block And continue echoing the page
         $this->geshiCSS = '<style type="text/css"><!--' . $this->geshi->get_stylesheet() . '--></style>';
         // additional headerdata to include the styles
         $GLOBALS['TSFE']->additionalHeaderData['sema_sourcecode:' . $config['content.']['lang']] = $this->geshiCSS;
     }
     // xhtml compliance
     if (isset($config['global.']['xhtmlcompliant']) && $config['global.']['xhtmlcompliant'] == 1) {
         $this->geshi->force_xhtml_compliance = true;
     }
     // check for errors
     if ($this->geshi->error() !== false) {
         // log an error, this happens if the language file is missing or non-readable. Other input
         // specific errors can also occour, eg. if a non-existing container type is set for the engine.
         $GLOBALS['BE_USER']->simplelog($this->geshi->error(), $extKey = 'sema_sourcecode', 1);
     }
     // render
     return $this->pi_wrapInBaseClass($this->geshi->parse_code());
 }
开发者ID:sema,项目名称:typo3-source-code-highlighter,代码行数:61,代码来源:class.tx_semasourcecode_pi1.php

示例3: code

 public function code(&$buff)
 {
     $geshi = new GeSHi($buff, $this->lang_alias($this->lang));
     $geshi->set_header_type(GESHI_HEADER_PRE);
     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     $geshi->code_style = $geshi->line_style1 = '';
     $geshi->keyword_links = false;
     $error = $geshi->error();
     if ($error) {
         debug($error);
     }
     return '<span class="code">' . ($error ? nl2br(htmlspecialchars($buff)) : $geshi->parse_code()) . '</span>';
 }
开发者ID:laiello,项目名称:xiv,代码行数:13,代码来源:source_color.php

示例4: bbcode_highlite

function bbcode_highlite($s, $language = false)
{
    $s = base64_decode($s);
    if (!$language) {
        return '<code>' . htmlspecialchars($s, ENT_COMPAT, 'UTF-8') . '</code>';
    }
    $geshi = new GeSHi($s, $language);
    $geshi->enable_classes(true);
    $geshi->set_header_type(GESHI_HEADER_DIV);
    $geshi->enable_keyword_links(false);
    $geshi->set_tab_width(4);
    $output = $geshi->parse_code();
    if ($geshi->error()) {
        return false;
    }
    head('stylesheet', 'geshi/' . $language, 'screen');
    return '<div class="geshi">' . $output . '</div>';
}
开发者ID:RazorMarx,项目名称:izend,代码行数:18,代码来源:bbcode.php

示例5: highlight

 function highlight($code, $lang, $path)
 {
     if (empty($lang)) {
         $lang = 'c';
     }
     $geshi = new GeSHi($code, $lang);
     $geshi->enable_classes();
     $geshi->set_overall_class('highlight');
     $geshi->set_header_type(GESHI_HEADER_NONE);
     /* Now this feature works, maybe activate it? */
     /* $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 1); */
     $result = $geshi->parse_code();
     /* This thing fixes styles when line numbers are disabled */
     $result = '<div class="highlight ' . $lang . '">' . $result . '</div>';
     if ($geshi->error()) {
         $result = $code;
     }
     return $result;
 }
开发者ID:vladimir-g,项目名称:rulinux-engine,代码行数:19,代码来源:mark.class.php

示例6: pretty_file

function pretty_file($file, $language, $startline = 0, $endline = 0, $number = false)
{
    if (!$file) {
        return false;
    }
    $s = read_file($file, $startline, $endline);
    if (!$s) {
        return false;
    }
    if (!$language) {
        return $s;
    }
    $output = false;
    switch ($language) {
        case 'plain':
            $s = preg_replace("/\\]\\=\\>\n(\\s+)/m", "] => ", $s);
            $s = htmlentities($s, ENT_COMPAT, 'UTF-8');
            $output = '<pre class="plain">' . PHP_EOL . $s . '</pre>' . PHP_EOL;
            break;
        default:
            $geshi = new GeSHi($s, $language);
            $geshi->enable_classes(true);
            $geshi->set_header_type(GESHI_HEADER_DIV);
            if ($number) {
                $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
                $geshi->start_line_numbers_at($startline > 0 ? $startline : 1);
            }
            $geshi->enable_keyword_links(false);
            $geshi->set_tab_width(4);
            //			echo '<pre>' . PHP_EOL .$geshi->get_stylesheet( ). '</pre>' . PHP_EOL;
            $output = $geshi->parse_code();
            if ($geshi->error()) {
                return false;
            }
    }
    return $output;
}
开发者ID:RazorMarx,项目名称:izend,代码行数:37,代码来源:prettyfile.php

示例7: GeSHi

 /**
  * Easy way to highlight stuff. Behaves just like highlight_string
  * 
  * @param string The code to highlight
  * @param string The language to highlight the code in
  * @param string The path to the language files. You can leave this blank if you need
  *               as from version 1.0.7 the path should be automatically detected
  * @param boolean Whether to return the result or to echo
  * @return string The code highlighted (if $return is true)
  * @since 1.0.2
  */
 function geshi_highlight($string, $language, $path, $return = false)
 {
     $geshi = new GeSHi($string, $language, $path);
     $geshi->set_header_type(GESHI_HEADER_NONE);
     if ($return) {
         return '<code>' . $geshi->parse_code() . '</code>';
     }
     echo '<code>' . $geshi->parse_code() . '</code>';
     if ($geshi->error()) {
         return false;
     }
     return true;
 }
开发者ID:carriercomm,项目名称:pastebin,代码行数:24,代码来源:geshi.php

示例8: GeSHi

 /**
  * Easy way to highlight stuff. Behaves just like highlight_string
  *
  * @param string The code to highlight
  * @param string The language to highlight the code in
  * @param string The path to the language files. You can leave this blank if you need
  *               as from version 1.0.7 the path should be automatically detected
  * @param boolean Whether to return the result or to echo
  * @return string The code highlighted (if $return is true)
  * @since 1.0.2
  */
 function geshi_highlight($string, $language, $path = null, $return = false)
 {
     $geshi = new GeSHi($string, $language, $path);
     $geshi->set_header_type(GESHI_HEADER_NONE);
     $code = $geshi->parse_code();
     /**
      * changed some code here to properly work with my blogsystem (BadBoy_, 05/23/2008, http://badboy.pytalhost.de)
      */
     if ($geshi->error()) {
         return $string;
         #$geshi->error();
     }
     if ($return) {
         return '<code>' . $code . '</code>';
     }
     echo '<code>' . $code . '</code>';
     return true;
 }
开发者ID:badboy,项目名称:devbird,代码行数:29,代码来源:geshi.php

示例9: prepare

 /**
  * Initialise a GeSHi object to format some code, performing
  * common setup for all our uses of it
  *
  * @param string $text
  * @param string $lang
  * @return GeSHi
  */
 private static function prepare($text, $lang)
 {
     self::initialise();
     $geshi = new GeSHi($text, $lang);
     if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) {
         return null;
     }
     $geshi->set_encoding('UTF-8');
     $geshi->enable_classes();
     $geshi->set_overall_class("source-{$lang}");
     $geshi->enable_keyword_links(false);
     return $geshi;
 }
开发者ID:akoehn,项目名称:wikireader,代码行数:21,代码来源:SyntaxHighlight_GeSHi.class.php

示例10: GeSHi

 /**
  * Easy way to highlight stuff. Behaves just like highlight_string
  *
  * @param string The code to highlight
  * @param string The language to highlight the code in
  * @param string The path to the language files. You can leave this blank if you need
  *               as from version 1.0.7 the path should be automatically detected
  * @param boolean Whether to return the result or to echo
  * @return string The code highlighted (if $return is true)
  * @since 1.0.2
  */
 function geshi_highlight($string, $language, $path = null, $return = false)
 {
     $geshi = new GeSHi($string, $language, $path);
     $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
     $geshi->enable_classes();
     $geshi->enable_keyword_links(false);
     $geshi->highlight_lines_extra(array(8, 9, 10, 11, 13, 14, 15, 16, 18, 19, 24, 32, 80));
     if ($return) {
         return '<code>' . $geshi->parse_code() . '</code>';
     }
     echo '<code>' . $geshi->parse_code() . '</code>';
     if ($geshi->error()) {
         return false;
     }
     return true;
 }
开发者ID:robingchan,项目名称:Code-Viewer-Syntax-Highlighter,代码行数:27,代码来源:geshi.php

示例11: prepare

 /**
  * Initialise a GeSHi object to format some code, performing
  * common setup for all our uses of it
  *
  * @param string $text
  * @param string $lang
  * @return GeSHi
  */
 public static function prepare($text, $lang)
 {
     global $wgTitle, $wgOut;
     self::initialise();
     $geshi = new GeSHi($text, $lang);
     if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) {
         return null;
     }
     $geshi->set_encoding('UTF-8');
     $geshi->enable_classes();
     $geshi->set_overall_class("source-{$lang}");
     $geshi->enable_keyword_links(false);
     // Wikia change start
     if ($wgTitle instanceof Title && EditPageLayoutHelper::isCodeSyntaxHighlightingEnabled($wgTitle)) {
         $theme = 'solarized-light';
         if (SassUtil::isThemeDark()) {
             $theme = 'solarized-dark';
         }
         $geshi->set_language_path(GESHI_ROOT . $theme . DIRECTORY_SEPARATOR);
         $geshi->set_overall_id('theme-' . $theme);
         $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL('extensions/SyntaxHighlight_GeSHi/styles/solarized.scss'));
     }
     // Wikia change end
     return $geshi;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:33,代码来源:SyntaxHighlight_GeSHi.class.php

示例12: prepare

	/**
	 * Initialise a GeSHi object to format some code, performing
	 * common setup for all our uses of it
	 *
	 * @note Used only until MW 1.20
	 *
	 * @param string $text
	 * @param string $lang
	 * @return GeSHi
	 */
	public static function prepare( $text, $lang ) {

		global $wgSyntaxHighlightKeywordLinks;

		self::initialise();
		$geshi = new GeSHi( $text, $lang );
		if( $geshi->error() == GESHI_ERROR_NO_SUCH_LANG ) {
			return null;
		}
		$geshi->set_encoding( 'UTF-8' );
		$geshi->enable_classes();
		$geshi->set_overall_class( "source-$lang" );
		$geshi->enable_keyword_links( $wgSyntaxHighlightKeywordLinks );

		// If the source code is over 100 kB, disable higlighting of symbols.
		// If over 200 kB, disable highlighting of strings too.
		$bytes = strlen( $text );
		if ( $bytes > 102400 ) {
			$geshi->set_symbols_highlighting( false );
			if ( $bytes > 204800 ) {
				$geshi->set_strings_highlighting( false );
			}
		}

		return $geshi;
	}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:36,代码来源:SyntaxHighlight_GeSHi.class.php

示例13: prepare

 /**
  * Initialise a GeSHi object to format some code, performing
  * common setup for all our uses of it
  *
  * @param string $text
  * @param string $lang
  * @return GeSHi
  */
 public static function prepare($text, $lang)
 {
     global $wgSyntaxHighlightKeywordLinks;
     self::initialise();
     $geshi = new GeSHi($text, $lang);
     if ($geshi->error() == GESHI_ERROR_NO_SUCH_LANG) {
         return null;
     }
     $geshi->set_encoding('UTF-8');
     $geshi->enable_classes();
     $geshi->set_overall_class("source-{$lang}");
     $geshi->enable_keyword_links($wgSyntaxHighlightKeywordLinks);
     // If the source code is over 100 kB, disable higlighting of symbols.
     // If over 200 kB, disable highlighting of strings too.
     $bytes = strlen($text);
     if ($bytes > 102400) {
         $geshi->set_symbols_highlighting(false);
         if ($bytes > 204800) {
             $geshi->set_strings_highlighting(false);
         }
     }
     /**
      * GeSHi comes by default with a font-family set to monospace, which
      * causes the font-size to be smaller than one would expect.
      * We append a CSS hack to the default GeSHi styles: specifying 'monospace'
      * twice "resets" the browser font-size specified for monospace.
      *
      * The hack is documented in MediaWiki core under
      * docs/uidesign/monospace.html and in bug 33496.
      */
     // Preserve default since we don't want to override the other style
     // properties set by geshi (padding, font-size, vertical-align etc.)
     $geshi->set_code_style('font-family: monospace, monospace;', true);
     // No need to preserve default (which is just "font-family: monospace;")
     // outputting both is unnecessary
     $geshi->set_overall_style('font-family: monospace, monospace;', false);
     return $geshi;
 }
开发者ID:rploaiza,项目名称:dbpedia-latinoamerica,代码行数:46,代码来源:SyntaxHighlight_GeSHi.class.php

示例14: _code

 public static function _code($action, $attributes, $content, $params, &$node_object)
 {
     if ($action == 'validate') {
         if (isset($attributes['default'])) {
             $highlighter = new GeSHi($content, $attributes['default']);
             if ($highlighter->error() === false) {
                 $highlighter->enable_strict_mode(GESHI_MAYBE);
                 $highlighter->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
                 $node_object->highlighter =& $highlighter;
                 return true;
             }
             return false;
         }
         return true;
     } else {
         $content = trim($content, "\r\n");
         if (isset($attributes['default'])) {
             $content = $node_object->highlighter->parse_code();
         } else {
             $content = htmlspecialchars($content);
             $content = '<pre><ol><li>' . preg_replace("/\\s*\n/", '</li><li>', $content) . '</li></ol></div>';
         }
         /**
          * STATISCHE SPRACHE
          */
         return '<div class="code"><h4>' . 'Code-Ansicht' . ':</h4>' . $content . '</div>';
     }
 }
开发者ID:GamerSource,项目名称:Infected-CMS-2,代码行数:28,代码来源:bbcode.php

示例15: dirname


//.........这里部分代码省略.........
         $cache_dir = realpath($cache_dir) . '/';
         if (!is_writable($cache_dir)) {
             // try to chmod it
             @chmod($cache_dir, 0777);
             if (!is_writable($cache_dir)) {
                 // still not writable? display a warning
                 print '<b>Warning</b>: Your <i>' . $this->name . '</i> cache directory <b>' . $cache_dir . '</b> is not writable! This will cause severe performance problems, so I suggest you chmod that dir.';
             }
         }
     } else {
         if (!mkdir($cache_dir, 0777)) {
             print '<b>Warning</b>: Your <i>' . $this->name . '</i> cache directory <b>' . $cache_dir . '</b> could not be created! This will cause severe performance problems, so I suggest you create and chmod that dir.';
         } else {
             // create an index.html so the contents will not be listed.
             @touch($cache_dir . 'index.html');
         }
     }
     if (mt_rand(0, 10) == 10) {
         // on every 10th visit do the garbage collection
         $cur = time();
         $d = dir($cache_dir);
         while (($f = $d->read()) !== FALSE) {
             if ($f != 'index.html' && $f[0] != '.') {
                 if ($cur - filemtime($cache_dir . $f) > $this->settings['cache_cutoff']) {
                     // File is older than cutoff, delete it.
                     @unlink($cache_dir . $f);
                 }
             }
         }
     }
     // loop through the code snippets
     $i = 0;
     foreach ($pos as $code_pos => $match) {
         $error = FALSE;
         if (($code_end_pos = strpos($str, $this->rlimit, (int) $code_pos + strlen($match['match']))) !== FALSE) {
             // we have a matching end tag.
             // make sure cache is regenerated when changing options, too!
             $md5 = md5(($not_geshified = substr($str, $code_pos + strlen($match['match']), $code_end_pos - $code_pos - strlen($match['match']))) . print_r($match, TRUE) . print_r($this->settings, TRUE));
             // check whether we already have this in a cache file
             if (is_file($cache_dir . $md5) && is_readable($cache_dir . $md5)) {
                 if (is_callable('file_get_contents')) {
                     $geshified = file_get_contents($cache_dir . $md5);
                     // this is for the garbage collection
                     touch($cache_dir . $md5);
                 } else {
                     // screw PHP4!
                     $f = fopen($cache_dir . $md5, 'r');
                     $geshified = fread($f, filesize($cache_dir . $md5));
                     fclose($f);
                     touch($cache_dir . $md5);
                 }
             } else {
                 // no cache so do the GeSHi thing
                 if ($this->settings['geshi_version'] == '1.1') {
                     // use GeSHi 1.1
                     include_once dirname(__FILE__) . '/geshi-1.1/class.geshi.php';
                     // highlight code according to type setting, default to setting
                     $geshi = new GeSHi($not_geshified, $match['type'] !== NULL ? $match['type'] : $this->settings['default_type']);
                     $str_error = $geshi->error();
                     if (empty($str_error)) {
                         // neither line numbers, nor strict mode is supported in GeSHi 1.1 yet.
                         // in fact it does pretty much nothing
                         // there used to be a rather large block of code here, testing wether methods were callable and call them if
                         // that's the case.
                         // parse the code
                         $geshified = $geshi->parseCode();
开发者ID:neverpanic,项目名称:GeSHify,代码行数:67,代码来源:ext.geshify.php


注:本文中的GeSHi::error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。