[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TTextHighlighter class file 4 * 5 * @author Wei Zhuo<weizhuo[at]gmail[dot]com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 Wei Zhuo 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TTextHighlighter.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * Using GeSHi and TTextProcessor classes 15 */ 16 Prado::using('System.3rdParty.geshi.geshi'); 17 Prado::using('System.Web.UI.WebControls.TTextProcessor'); 18 19 /** 20 * TTextHighlighter class. 21 * 22 * TTextHighlighter does syntax highlighting its body content, including 23 * static text and rendering results of child controls. 24 * You can set {@link setLanguage Language} to specify what kind of syntax 25 * the body content is. Currently, TTextHighlighter supports the following 26 * languages: 'php','prado','css','html','javascript' and 'xml', where 'prado' 27 * refers to PRADO template syntax. By setting {@link setShowLineNumbers ShowLineNumbers} 28 * to true, the highlighted result may be shown with line numbers. 29 * 30 * @author Wei Zhuo<weizhuo[at]gmail[dot]com> 31 * @version $Id: TTextHighlighter.php 1397 2006-09-07 07:55:53Z wei $ 32 * @package System.Web.UI.WebControls 33 * @since 3.0 34 */ 35 class TTextHighlighter extends TTextProcessor 36 { 37 /** 38 * @return string tag name of the panel 39 */ 40 protected function getTagName() 41 { 42 return 'div'; 43 } 44 45 /** 46 * @return string language whose syntax is to be used for highlighting. Defaults to 'php'. 47 */ 48 public function getLanguage() 49 { 50 return $this->getViewState('Language', 'php'); 51 } 52 53 /** 54 * @param string language whose syntax is to be used for highlighting. 55 * Valid values are those file names (without suffix) that are contained 56 * in '3rdParty/geshi/geshi' (e.g. 'php','prado','css','html','javascript', 57 * 'xml'.) 58 */ 59 public function setLanguage($value) 60 { 61 $this->setViewState('Language', $value, 'php'); 62 } 63 64 /** 65 * @return boolean whether to show line numbers in the highlighted result. 66 */ 67 public function getShowLineNumbers() 68 { 69 return $this->getViewState('ShowLineNumbers', false); 70 } 71 72 /** 73 * @param boolean whether to show line numbers in the highlighted result. 74 */ 75 public function setShowLineNumbers($value) 76 { 77 $this->setViewState('ShowLineNumbers', TPropertyValue::ensureBoolean($value), false); 78 } 79 80 /** 81 * @return boolean true will show "Copy Code" link. Defaults to false. 82 */ 83 public function getEnableCopyCode() 84 { 85 return $this->getViewState('CopyCode', false); 86 } 87 88 /** 89 * @param boolean true to show the "Copy Code" link. 90 */ 91 public function setEnableCopyCode($value) 92 { 93 $this->setViewState('CopyCode', TPropertyValue::ensureBoolean($value), false); 94 } 95 96 /** 97 * Registers css style for the highlighted result. 98 * This method overrides parent implementation. 99 * @param THtmlWriter writer 100 */ 101 public function onPreRender($writer) 102 { 103 parent::onPreRender($writer); 104 $this->registerHighlightScripts(); 105 } 106 107 /** 108 * Register CSS stylesheet file and javascript file. 109 * @throws TConfigurationException if highlight.css file cannot be found 110 */ 111 protected function registerHighlightScripts() 112 { 113 $cs=$this->getPage()->getClientScript(); 114 $cssKey='prado:TTextHighlighter'; 115 if(!$cs->isStyleSheetFileRegistered($cssKey)) 116 { 117 if(($cssFile=Prado::getPathOfNamespace('System.3rdParty.geshi.highlight','.css'))===null) 118 throw new TConfigurationException('texthighlighter_stylesheet_invalid'); 119 $styleSheet = $this->publishFilePath($cssFile); 120 $cs->registerStyleSheetFile($cssKey, $styleSheet); 121 } 122 $cs->registerPradoScript('prado'); 123 } 124 125 /** 126 * Processes a text string. 127 * This method is required by the parent class. 128 * @param string text string to be processed 129 * @return string the processed text result 130 */ 131 public function processText($text) 132 { 133 $geshi = new GeSHi(trim($text), $this->getLanguage()); 134 if($this->getShowLineNumbers()) 135 $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); 136 $geshi->enable_classes(); 137 if($this->getEnableCopyCode()) 138 $geshi->set_header_content($this->getHeaderTemplate()); 139 140 return $geshi->parse_code(); 141 } 142 143 /** 144 * @return string header template with "Copy code" link. 145 */ 146 protected function getHeaderTemplate() 147 { 148 $id = $this->getClientID(); 149 return TJavaScript::renderScriptBlock("new Prado.WebUI.TTextHighlighter('{$id}');"); 150 } 151 } 152 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |