From 0f3a577bed4d828472469675e90fcab032e33f44 Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 2 Jun 2006 18:27:02 +0000 Subject: merge from 3.0 branch till 1133. --- framework/Web/UI/TTemplateManager.php | 34 +++++-- framework/Web/UI/WebControls/TDataBoundControl.php | 2 +- framework/Web/UI/WebControls/TMarkdown.php | 113 +++++++++++++++++++++ framework/Web/UI/WebControls/TRepeater.php | 3 +- .../Web/UI/WebControls/TValidationSummary.php | 17 +++- framework/Web/UI/WebControls/TWizard.php | 6 +- 6 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 framework/Web/UI/WebControls/TMarkdown.php (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 60ce11ca..cb05fa35 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -383,16 +383,37 @@ class TTemplate extends TApplicationComponent implements ITemplate * @param string property name * @param mixed property initial value */ + protected function configureControl2($control,$name,$value) + { + if(strncasecmp($name,'on',2)===0) // is an event + $this->configureEvent($control,$name,$value,$control); + else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute + $this->configureProperty($control,$name,$value); + else // is a subproperty + { + $subName=substr($name,$pos+1); + if(strncasecmp($subName,'on',2)===0) // is an event: XXX.YYY.OnZZZ + { + $object=$control->getSubProperty(substr($name,0,$pos)); + if(($object instanceof TControl)) + $this->configureEvent($object,$subName,$value,$control); + else + $this->configureSubProperty($control,$name,$value); + } + else + $this->configureSubProperty($control,$name,$value); + } + } + protected function configureControl($control,$name,$value) { if(strncasecmp($name,'on',2)===0) // is an event - $this->configureEvent($control,$name,$value); - else if(strpos($name,'.')===false) // is a simple property or custom attribute + $this->configureEvent($control,$name,$value,$control); + else if(($pos=strrpos($name,'.'))===false) // is a simple property or custom attribute $this->configureProperty($control,$name,$value); else // is a subproperty $this->configureSubProperty($control,$name,$value); } - /** * Configures a property of a non-control component. * @param TComponent component to be configured @@ -412,13 +433,14 @@ class TTemplate extends TApplicationComponent implements ITemplate * @param TControl control to be configured * @param string event name * @param string event handler + * @param TControl context control */ - protected function configureEvent($component,$name,$value) + protected function configureEvent($control,$name,$value,$contextControl) { if(strpos($value,'.')===false) - $component->attachEventHandler($name,array($component,'TemplateControl.'.$value)); + $control->attachEventHandler($name,array($contextControl,'TemplateControl.'.$value)); else - $component->attachEventHandler($name,array($component,$value)); + $control->attachEventHandler($name,array($contextControl,$value)); } /** diff --git a/framework/Web/UI/WebControls/TDataBoundControl.php b/framework/Web/UI/WebControls/TDataBoundControl.php index 0bb771bf..9e6ecbf3 100644 --- a/framework/Web/UI/WebControls/TDataBoundControl.php +++ b/framework/Web/UI/WebControls/TDataBoundControl.php @@ -59,7 +59,7 @@ abstract class TDataBoundControl extends TWebControl */ public function setDataSource($value) { - $this->_dataSource=$this->validateDataSource($value);; + $this->_dataSource=$this->validateDataSource($value); $this->onDataSourceChanged(); } diff --git a/framework/Web/UI/WebControls/TMarkdown.php b/framework/Web/UI/WebControls/TMarkdown.php new file mode 100644 index 00000000..49660b4e --- /dev/null +++ b/framework/Web/UI/WebControls/TMarkdown.php @@ -0,0 +1,113 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TMarkdown class + * + * TMarkdown is a control that produces HTML from code with markdown syntax. + * + * Markdown is a text-to-HTML conversion tool for web writers. Markdown allows + * you to write using an easy-to-read, easy-to-write plain text format, then + * convert it to structurally valid XHTML (or HTML). + * Further documentation regarding Markdown can be found at + * http://daringfireball.net/projects/markdown/ + * + * To use TMarkdown, simply enclose the content to be rendered within + * the body of TMarkdown in a template. + * + * See http://www.pradosoft.com/demos/quickstart/?page=Markdown for + * details on the Markdown syntax usage. + * + * @author Wei Zhuo + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TMarkdown extends TControl +{ + /** + * @var TTextHighlighter + */ + 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) + { + $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'); + $result = $renderer->parse($text); + return preg_replace_callback( + '/
\[\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
+	 * @return string highlighted code.
+	 */
+	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();
+	}
+
+	/**
+	 * 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);
+	}
+}
+
+?>
\ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 1acdc766..9aa7af8d 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -11,9 +11,10 @@
  */
 
 /**
- * Using TDataBoundControl cass
+ * Using TDataBoundControl and TDataFieldAccessor cass
  */
 Prado::using('System.Web.UI.WebControls.TDataBoundControl');
+Prado::using('System.Util.TDataFieldAccessor');
 
 /**
  * TRepeater class
diff --git a/framework/Web/UI/WebControls/TValidationSummary.php b/framework/Web/UI/WebControls/TValidationSummary.php
index 8148036b..cfb57c5b 100644
--- a/framework/Web/UI/WebControls/TValidationSummary.php
+++ b/framework/Web/UI/WebControls/TValidationSummary.php
@@ -223,9 +223,24 @@ class TValidationSummary extends TWebControl
 	{
 		if(!$this->getEnabled(true) || !$this->getEnableClientScript())
 			return;
+		$cs = $this->getPage()->getClientScript();
+		$cs->registerPradoScript('validator');
+
+		//need to register the validation manager is validation summary is alone.
+		$formID=$this->getPage()->getForm()->getClientID();
+		$scriptKey = "TBaseValidator:$formID";
+		if($this->getEnableClientScript() && !$cs->isEndScriptRegistered($scriptKey))
+		{
+			$manager['FormID'] = $formID;
+			$options = TJavaScript::encode($manager); 
+			$cs->registerPradoScript('validator');
+			$cs->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});");
+		}
+
+
 		$options=TJavaScript::encode($this->getClientScriptOptions());
 		$script = "new Prado.WebUI.TValidationSummary({$options});";
-		$this->getPage()->getClientScript()->registerEndScript($this->getClientID(), $script);
+		$cs->registerEndScript($this->getClientID(), $script);
 	}
 
 	/**
diff --git a/framework/Web/UI/WebControls/TWizard.php b/framework/Web/UI/WebControls/TWizard.php
index 2d2815ba..811c4e76 100644
--- a/framework/Web/UI/WebControls/TWizard.php
+++ b/framework/Web/UI/WebControls/TWizard.php
@@ -622,7 +622,7 @@ class TWizard extends TWebControl implements INamingContainer
 	}
 
 	/**
-	 * @var TWizardNavigationContainer container of the start navigation
+	 * @return TWizardNavigationContainer container of the start navigation
 	 */
 	public function getStartNavigation()
 	{
@@ -630,7 +630,7 @@ class TWizard extends TWebControl implements INamingContainer
 	}
 
 	/**
-	 * @var TWizardNavigationContainer container of the step navigation
+	 * @return TWizardNavigationContainer container of the step navigation
 	 */
 	public function getStepNavigation()
 	{
@@ -638,7 +638,7 @@ class TWizard extends TWebControl implements INamingContainer
 	}
 
 	/**
-	 * @var TWizardNavigationContainer container of the finish navigation
+	 * @return TWizardNavigationContainer container of the finish navigation
 	 */
 	public function getFinishNavigation()
 	{
-- 
cgit v1.2.3