summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2005-12-29 12:20:57 +0000
committerxue <>2005-12-29 12:20:57 +0000
commit3126610fdab66c4e83de00d36a762af30199238d (patch)
tree96c0e41e404303eb95d0c29c3da728dac8c29336
parent658a7e1c4cf5a53dcd61ee196658090d00f2d64a (diff)
Modified TTextHighlighter so that it can highlight its body content including output of its child controls.
Modified ViewSource to make use of TTextHighlighter.
-rw-r--r--demos/quickstart/protected/controls/TTextHighlighter.php25
-rw-r--r--demos/quickstart/protected/pages/ViewSource.page2
-rw-r--r--demos/quickstart/protected/pages/ViewSource.php23
-rw-r--r--framework/IO/TTextWriter.php8
4 files changed, 41 insertions, 17 deletions
diff --git a/demos/quickstart/protected/controls/TTextHighlighter.php b/demos/quickstart/protected/controls/TTextHighlighter.php
index 19b54ad2..b89e5274 100644
--- a/demos/quickstart/protected/controls/TTextHighlighter.php
+++ b/demos/quickstart/protected/controls/TTextHighlighter.php
@@ -2,6 +2,8 @@
require_once(dirname(__FILE__).'/Highlighter/geshi.php');
+Prado::using('System.IO.TTextWriter');
+
/**
* ${classname}
*
@@ -51,18 +53,17 @@ class TTextHighlighter extends TWebControl
$this->setViewState('Entities', TPropertyValue::ensureBoolean($value), false);
}
- /**
- * Parse the body string using GeSHi to highlight the contents.
- */
- public function addParsedObject($object)
+ protected function onPreRender($writer)
{
- if(is_string($object))
- {
- $this->registerTextHighlightStyleSheet();
- $this->getControls()->add($this->getTextHighlight($object));
- }
- else
- $this->getControls()->add($object);
+ parent::onPreRender($writer);
+ $this->registerTextHighlightStyleSheet();
+ }
+
+ protected function renderContents($writer)
+ {
+ $textWriter=new TTextWriter;
+ parent::renderContents(new THtmlWriter($textWriter));
+ $writer->write($this->highlightText($textWriter->flush()));
}
/**
@@ -83,7 +84,7 @@ class TTextHighlighter extends TWebControl
* @param string text to highlight.
* @return string highlighted text.
*/
- protected function getTextHighlight($text)
+ protected function highlightText($text)
{
if(!$this->getEnableEntities())
$text = html_entity_decode($text);
diff --git a/demos/quickstart/protected/pages/ViewSource.page b/demos/quickstart/protected/pages/ViewSource.page
index 3c175c80..21ddafa8 100644
--- a/demos/quickstart/protected/pages/ViewSource.page
+++ b/demos/quickstart/protected/pages/ViewSource.page
@@ -10,7 +10,7 @@
<com:TLiteral ID="SourceList" />
</div>
<div id="sourceView">
-<com:TTextHighlighter Language="prado" CssClass="source">
+<com:TTextHighlighter ID="Highlighter" CssClass="source">
<com:TLiteral ID="SourceView" />
</com:TTextHighlighter>
</div>
diff --git a/demos/quickstart/protected/pages/ViewSource.php b/demos/quickstart/protected/pages/ViewSource.php
index 65cefa70..2cb3df08 100644
--- a/demos/quickstart/protected/pages/ViewSource.php
+++ b/demos/quickstart/protected/pages/ViewSource.php
@@ -24,9 +24,10 @@ class ViewSource extends TPage
parent::onLoad($param);
$path=$this->Request->Items['path'];
$fullPath=realpath($this->Service->BasePath.'/'.$path);
+ $fileExt=$this->getFileExtension($fullPath);
if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false)
{
- if($this->isFileTypeAllowed($this->getFileExtension($fullPath)))
+ if($this->isFileTypeAllowed($fileExt))
{
$this->_fullPath=strtr($fullPath,'\\','/');
$this->_path=strtr(substr($fullPath,strlen($this->Service->BasePath)),'\\','/');
@@ -59,8 +60,24 @@ class ViewSource extends TPage
$this->SourceList->Text=$str;
}
- $this->SourceView->Text=highlight_string(file_get_contents($this->_fullPath),true);
- //$this->SourceView->Text=file_get_contents($this->_fullPath);
+ switch($fileExt)
+ {
+ case 'page' :
+ case 'tpl' :
+ $this->Highlighter->Language='prado';
+ break;
+ case 'php' :
+ $this->Highlighter->Language='php';
+ break;
+ case 'xml' :
+ $this->Highlighter->Language='xml';
+ break;
+ default :
+ $this->Highlighter->Language='html';
+ break;
+ }
+
+ $this->SourceView->Text=file_get_contents($this->_fullPath);
}
}
diff --git a/framework/IO/TTextWriter.php b/framework/IO/TTextWriter.php
index 17829acf..5f6a92cb 100644
--- a/framework/IO/TTextWriter.php
+++ b/framework/IO/TTextWriter.php
@@ -1,13 +1,19 @@
<?php
-class TTextWriter extends TComponent
+class TTextWriter extends TComponent implements ITextWriter
{
+ private $_str='';
+
public function flush()
{
+ $str=$this->_str;
+ $this->_str='';
+ return $str;
}
public function write($str)
{
+ $this->_str.=$str;
}
public function writeLine($str='')