PHP 8.1.33
Preview: CTextHighlighter.php Size: 3.96 KB
/home/jambtst2015/www/framework/web/widgets/CTextHighlighter.php

<?php
/**
 * CTextHighlighter class file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright 2008-2013 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

require_once(Yii::getPathOfAlias('system.vendors.TextHighlighter.Text.Highlighter').'.php');
require_once(Yii::getPathOfAlias('system.vendors.TextHighlighter.Text.Highlighter.Renderer.Html').'.php');

/**
 * CTextHighlighter does syntax highlighting for its body content.
 *
 * The language of the syntax to be applied is specified via {@link language} property.
 * Currently, CTextHighlighter supports the following languages:
 * ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT, MYSQL, PERL,
 * PHP, PYTHON, RUBY, SQL, XML. By setting {@link showLineNumbers}
 * to true, the highlighted result may be shown with line numbers.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package system.web.widgets
 * @since 1.0
 */
class CTextHighlighter extends COutputProcessor
{
	/**
	 * @var string the language whose syntax is to be used for highlighting.
	 * Valid values are those file names (without suffix) that are contained
	 * in 'vendors/TextHighlighter/Text/Highlighter'. Currently, the following
	 * languages are supported:
	 * ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT,
	 * MYSQL, PERL, PHP, PYTHON, RUBY, SQL, XML
	 * If a language is not supported, it will be displayed as plain text.
	 * Language names are case-insensitive.
	 */
	public $language;
	/**
	 * @var boolean whether to show line numbers in the highlighted result. Defaults to false.
	 * @see lineNumberStyle
	 */
	public $showLineNumbers=false;
	/**
	 * @var string the style of line number display. It can be either 'list' or 'table'. Defaults to 'list'.
	 * @see showLineNumbers
	 */
	public $lineNumberStyle='list';
	/**
	 * @var integer tab size. Defaults to 4.
	 */
	public $tabSize=4;
	/**
	 * @var mixed the CSS file used for the widget. Defaults to null, meaning
	 * using the default CSS file included together with the widget.
	 * If false, no CSS file will be used. Otherwise, the specified CSS file
	 * will be included when using this widget.
	 */
	public $cssFile;
	/**
	 * @var array the HTML attributes to be applied to the container element.
	 * The highlighted content is contained in a DIV element.
	 */
	public $containerOptions=array();


	/**
	 * Processes the captured output.
     * This method highlights the output according to the syntax of the specified {@link language}.
	 * @param string $output the captured output to be processed
	 */
	public function processOutput($output)
	{
		$output=$this->highlight($output);
		parent::processOutput($output);
	}

	/**
	 * Highlights the content by the syntax of the specified language.
	 * @param string $content the content to be highlighted.
	 * @return string the highlighted content
	 */
	public function highlight($content)
	{
		$this->registerClientScript();

		$options['use_language']=true;
		$options['tabsize']=$this->tabSize;
		if($this->showLineNumbers)
			$options['numbers']=($this->lineNumberStyle==='list')?HL_NUMBERS_LI:HL_NUMBERS_TABLE;

		$highlighter=empty($this->language)?false:Text_Highlighter::factory($this->language);
		if($highlighter===false)
			$o='<pre>'.CHtml::encode($content).'</pre>';
		else
		{
			$highlighter->setRenderer(new Text_Highlighter_Renderer_Html($options));
			$o=preg_replace('/<span\s+[^>]*>(\s*)<\/span>/','\1',$highlighter->highlight($content));
		}

		return CHtml::tag('div',$this->containerOptions,$o);
	}

	/**
	 * Registers the needed CSS and JavaScript.
	 */
	public function registerClientScript()
	{
		if($this->cssFile!==false)
			self::registerCssFile($this->cssFile);
	}

	/**
	 * Registers the needed CSS file.
	 * @param string $url the CSS URL. If null, a default CSS URL will be used.
	 */
	public static function registerCssFile($url=null)
	{
		if($url===null)
			$url=CHtml::asset(Yii::getPathOfAlias('system.vendors.TextHighlighter.highlight').'.css');
		Yii::app()->getClientScript()->registerCssFile($url);
	}
}

Directory Contents

Dirs: 3 × Files: 19

Name Size Perms Modified Actions
captcha DIR
- drwxr-xr-x 2025-10-09 07:25:39
Edit Download
pagers DIR
- drwxr-xr-x 2025-10-09 07:25:56
Edit Download
views DIR
- drwxr-xr-x 2025-10-08 20:00:19
Edit Download
39.27 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
10.17 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
1.25 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.58 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.08 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.26 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.51 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
2.17 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.38 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.39 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
4.05 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
12.06 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
1.92 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
6.09 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
6.49 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
3.96 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
8.10 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
8.01 KB lrw-r--r-- 2024-11-22 17:53:15
Edit Download
90.03 KB lrw-r--r-- 2025-11-05 05:45:26
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).