* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
- * @since 3.0
+ * @since 3.0.1
*/
-class TMarkdown extends TControl
+class TMarkdown extends TTextHighlighter
{
/**
- * @var TTextHighlighter
+ * Processes a text string.
+ * This method is required by the parent class.
+ * @param string text string to be processed
+ * @return string the processed text result
*/
- private $_highlighter;
-
- /**
- * Renders body content.
- * This method overrides parent implementation by removing
- * malicious javascript code from the body content
- * @param THtmlWriter writer
- */
- public function render($writer)
+ public function processText($text)
{
- $textWriter=new TTextWriter;
- parent::render(new THtmlWriter($textWriter));
- $writer->write($this->renderMarkdown($textWriter->flush()));
- }
-
- /**
- * Use MarkdownParser to render the HTML content.
- * @param string markdown content
- * @return string HTML content
- */
- protected function renderMarkdown($text)
- {
- $renderer = Prado::createComponent('System.3rdParty.Markdown.MarkdownParser');
+ $renderer = new MarkdownParser;
$result = $renderer->parse($text);
return preg_replace_callback(
- '/\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im',
+ '/\[\s*(\w+)\s*\]\n+((.|\n)*?)\s*<\\/code><\\/pre>/im',
array($this, 'highlightCode'), $result);
}
- /**
- * @return TTextHighlighter source code highlighter
- */
- public function getTextHighlighter()
- {
- if(is_null($this->_highlighter))
- $this->_highlighter = new TTextHighlighter;
- return $this->_highlighter;
- }
-
-
/**
* Highlights source code using TTextHighlighter
* @param array matches of code blocks
@@ -84,29 +67,14 @@ class TMarkdown extends TControl
*/
protected function highlightCode($matches)
{
- $text = new TTextWriter;
- $writer = new THtmlWriter($text);
- $hi = $this->getTextHighlighter();
- if($hi->getControls()->getCount() > 0)
- $hi->getControls()->removeAt(0);
- $hi->addParsedObject(html_entity_decode($matches[2]));
- $hi->setLanguage($matches[1]);
- $hi->render($writer);
- return $text->flush();
- }
+ $geshi=new GeSHi(html_entity_decode($matches[2],ENT_QUOTES,'UTF-8'), $matches[1]);
+ if($this->getShowLineNumbers())
+ $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
+ $geshi->enable_classes();
+ if($this->getEnableCopyCode())
+ $geshi->set_header_content($this->getHeaderTemplate());
- /**
- * Registers css style for the highlighted result.
- * This method overrides parent implementation.
- * @param THtmlWriter writer
- */
- public function onPreRender($writer)
- {
- parent::onPreRender($writer);
- $hi = $this->getTextHighlighter();
- $this->getControls()->insertAt(0,$hi);
- $hi->onPreRender($writer);
- $this->getControls()->removeAt(0);
+ return $geshi->parse_code();
}
}
diff --git a/framework/Web/UI/WebControls/TMultiView.php b/framework/Web/UI/WebControls/TMultiView.php
index 59b9f53d..b6001f90 100644
--- a/framework/Web/UI/WebControls/TMultiView.php
+++ b/framework/Web/UI/WebControls/TMultiView.php
@@ -213,7 +213,7 @@ class TMultiView extends TControl
* @param mixed event parameter
* @return boolean whether this event is handled
*/
- public function onBubbleEvent($sender,$param)
+ public function bubbleEvent($sender,$param)
{
if(!$this->_ignoreBubbleEvents && ($param instanceof TCommandEventParameter))
{
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 9aa7af8d..2070cb1a 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -463,7 +463,6 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Handles BubbleEvent.
* This method overrides parent's implementation to handle
* {@link onItemCommand OnItemCommand} event which is bubbled from
* {@link TRepeaterItem} child controls.
@@ -472,7 +471,7 @@ class TRepeater extends TDataBoundControl implements INamingContainer
* @param TEventParameter event parameter
* @return boolean whether the event bubbling should stop here.
*/
- public function onBubbleEvent($sender,$param)
+ public function bubbleEvent($sender,$param)
{
if($param instanceof TRepeaterCommandEventParameter)
{
@@ -717,14 +716,13 @@ class TRepeaterItem extends TControl implements INamingContainer
}
/**
- * Handles BubbleEvent.
* This method overrides parent's implementation by wrapping event parameter
* for Command event with item information.
* @param TControl the sender of the event
* @param TEventParameter event parameter
* @return boolean whether the event bubbling should stop here.
*/
- public function onBubbleEvent($sender,$param)
+ public function bubbleEvent($sender,$param)
{
if($param instanceof TCommandEventParameter)
{
diff --git a/framework/Web/UI/WebControls/TTextHighlighter.php b/framework/Web/UI/WebControls/TTextHighlighter.php
index f5c3eca9..a9ccf5bb 100644
--- a/framework/Web/UI/WebControls/TTextHighlighter.php
+++ b/framework/Web/UI/WebControls/TTextHighlighter.php
@@ -11,9 +11,10 @@
*/
/**
- * Using GeSHi and TTextWriter classes
+ * Using GeSHi and TTextProcessor classes
*/
Prado::using('System.3rdParty.geshi.geshi');
+Prado::using('System.Web.UI.WebControls.TTextProcessor');
/**
* TTextHighlighter class.
@@ -31,7 +32,7 @@ Prado::using('System.3rdParty.geshi.geshi');
* @package System.Web.UI.WebControls
* @since 3.0
*/
-class TTextHighlighter extends TWebControl
+class TTextHighlighter extends TTextProcessor
{
/**
* @return string tag name of the panel
@@ -77,39 +78,30 @@ class TTextHighlighter extends TWebControl
}
/**
- * Registers css style for the highlighted result.
- * This method overrides parent implementation.
- * @param THtmlWriter writer
+ * @return boolean true will show "Copy Code" link. Defaults to false.
*/
- public function onPreRender($writer)
+ public function getEnableCopyCode()
{
- parent::onPreRender($writer);
- $this->registerHighlightScripts();
+ return $this->getViewState('CopyCode', false);
}
/**
- * HTML-decodes static text.
- * This method overrides parent implementation.
- * @param mixed object to be added as body content
+ * @param boolean true to show the "Copy Code" link.
*/
- public function addParsedObject($object)
+ public function setEnableCopyCode($value)
{
- if(is_string($object))
- $object=html_entity_decode($object);
- parent::addParsedObject($object);
+ $this->setViewState('CopyCode', TPropertyValue::ensureBoolean($value), false);
}
/**
- * Renders body content.
- * This method overrides parent implementation by replacing
- * the body content with syntax highlighted result.
+ * Registers css style for the highlighted result.
+ * This method overrides parent implementation.
* @param THtmlWriter writer
*/
- public function renderContents($writer)
+ public function onPreRender($writer)
{
- $textWriter=new TTextWriter;
- parent::renderContents(new THtmlWriter($textWriter));
- $writer->write($this->highlightText($textWriter->flush()));
+ parent::onPreRender($writer);
+ $this->registerHighlightScripts();
}
/**
@@ -131,27 +123,12 @@ class TTextHighlighter extends TWebControl
}
/**
- * @return boolean true will show "Copy Code" link. Defaults to false.
- */
- public function getEnableCopyCode()
- {
- return $this->getViewState('CopyCode', false);
- }
-
- /**
- * @param boolean true to show the "Copy Code" link.
- */
- public function setEnableCopyCode($value)
- {
- $this->setViewState('CopyCode', TPropertyValue::ensureBoolean($value), false);
- }
-
- /**
- * Returns the highlighted text.
- * @param string text to highlight.
- * @return string highlighted text.
+ * Processes a text string.
+ * This method is required by the parent class.
+ * @param string text string to be processed
+ * @return string the processed text result
*/
- protected function highlightText($text)
+ public function processText($text)
{
$geshi = new GeSHi(trim($text), $this->getLanguage());
if($this->getShowLineNumbers())
diff --git a/framework/Web/UI/WebControls/TTextProcessor.php b/framework/Web/UI/WebControls/TTextProcessor.php
new file mode 100644
index 00000000..4c4c68f2
--- /dev/null
+++ b/framework/Web/UI/WebControls/TTextProcessor.php
@@ -0,0 +1,87 @@
+
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2005 Wei Zhuo
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TTextProcessor class.
+ *
+ * TTextProcessor is the base class for classes that process or transform
+ * text content into different forms. The text content to be processed
+ * is specified by {@link setText Text} property. If it is not set, the body
+ * content enclosed within the processor control will be processed and rendered.
+ * The body content includes static text strings and the rendering result
+ * of child controls.
+ *
+ * Note, all child classes must implement {@link processText} method.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI
+ * @since 3.0.1
+ */
+abstract class TTextProcessor extends TWebControl
+{
+ /**
+ * Processes a text string.
+ * This method must be implemented by child classes.
+ * @param string text string to be processed
+ * @return string the processed text result
+ */
+ abstract public function processText($text);
+
+ /**
+ * HTML-decodes static text.
+ * This method overrides parent implementation.
+ * @param mixed object to be added as body content
+ */
+ public function addParsedObject($object)
+ {
+ if(is_string($object))
+ $object=html_entity_decode($object,ENT_QUOTES,'UTF-8');
+ parent::addParsedObject($object);
+ }
+
+ /**
+ * @return string text to be processed
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * @param string text to be processed
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value);
+ }
+
+ /**
+ * Renders body content.
+ * This method overrides the parent implementation by replacing
+ * the body content with the processed text content.
+ * @param THtmlWriter writer
+ */
+ public function renderContents($writer)
+ {
+ if(($text=$this->getText())==='' && $this->getHasControls())
+ {
+ $textWriter=new TTextWriter;
+ parent::renderContents(new THtmlWriter($textWriter));
+ $text=$textWriter->flush();
+ }
+ if($text!=='')
+ $writer->write($this->processText($text));
+ }
+
+}
+?>
\ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TWizard.php b/framework/Web/UI/WebControls/TWizard.php
index 811c4e76..fa0fd92a 100644
--- a/framework/Web/UI/WebControls/TWizard.php
+++ b/framework/Web/UI/WebControls/TWizard.php
@@ -1332,7 +1332,7 @@ class TWizard extends TWebControl implements INamingContainer
* @param TEventParameter event parameter
* @throws TInvalidDataValueException if a navigation command is associated with an invalid parameter
*/
- public function onBubbleEvent($sender,$param)
+ public function bubbleEvent($sender,$param)
{
if($param instanceof TCommandEventParameter)
{
--
cgit v1.2.3