summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/THead.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/UI/WebControls/THead.php')
-rw-r--r--framework/Web/UI/WebControls/THead.php99
1 files changed, 74 insertions, 25 deletions
diff --git a/framework/Web/UI/WebControls/THead.php b/framework/Web/UI/WebControls/THead.php
index 3a949e34..30f6cbbd 100644
--- a/framework/Web/UI/WebControls/THead.php
+++ b/framework/Web/UI/WebControls/THead.php
@@ -13,14 +13,22 @@
/**
* THead class
*
- * THead displays a <head> element on a page. It displays the content
- * enclosed in its body. In addition, it displays the page title set by the
- * {@link setTitle Title} property, and the meta tags registered via
- * {@link registerMetaTag}. Stylesheet and JavaScripts registered via
+ * THead displays a head element on a page. It displays the content
+ * enclosed in its body and the page title set by the
+ * {@link setTitle Title} property. In addition, stylesheets and JavaScripts registered via
* {@link TClientScriptManager::registerStyleSheet}, {@link TClientScriptManager::registerStyleSheetFile}
* {@link TClientScriptManager::registerHeadJavaScript}, and
* {@link TClientScriptManager::registerHeadJavaScriptFile} will also be displayed
* in the head.
+ * THead also manages and displays meta tags through its {@link getMetaTags MetaTags}
+ * property. You can add a meta object to the collection in code dynamically,
+ * or add it in template using the following syntax,
+ * <code>
+ * <com:THead>
+ * <com:TMetaTag HttpEquiv="Pragma" Content="no-cache" />
+ * <com:TMetaTag Name="keywords" Content="Prado" />
+ * </com:THead>
+ * </code>
*
* Note, {@link TPage} has a property {@link TPage::getHead Head} that refers to
* the THead control currently on the page. A page can have at most once THead
@@ -36,9 +44,9 @@
class THead extends TControl
{
/**
- * @var array list of meta name tags to be loaded by {@link THead}
+ * @var TList list of meta name tags to be loaded by {@link THead}
*/
- private $_metaTags=array();
+ private $_metaTags=null;
/**
* Registers the head control with the current page.
@@ -55,6 +63,21 @@ class THead extends TControl
}
/**
+ * Processes an object that is created during parsing template.
+ * This method adds TMetaTag components into the {@link getMetaTags MetaTags}
+ * collection of the head control.
+ * @param string|TComponent text string or component parsed and instantiated in template
+ * @see createdOnTemplate
+ */
+ public function addParsedObject($object)
+ {
+ if($object instanceof TMetaTag)
+ $this->getMetaTags()->add($object);
+ else
+ parent::addParsedObject($object);
+ }
+
+ /**
* @return string the page title.
*/
public function getTitle()
@@ -74,24 +97,16 @@ class THead extends TControl
}
/**
- * Registers a meta tag to be imported with the page body
- * @param string a key that identifies the meta tag to avoid repetitive registration
- * @param TMetaTag the meta tag to be registered
- * @see isTagRegistered()
- */
- public function registerMetaTag($key,$metaTag)
- {
- $this->_metaTags[$key]=$metaTag;
- }
-
- /**
- * @param string a key identifying the meta tag.
- * @return boolean whether the named meta tag has been registered before
- * @see registerMetaTag()
+ * @return TMetaTagCollection meta tag collection
*/
- public function isMetaTagRegistered($key)
+ public function getMetaTags()
{
- return isset($this->_metaTags[$key]);
+ if(($metaTags=$this->getViewState('MetaTags',null))===null)
+ {
+ $metaTags=new TMetaTagCollection;
+ $this->setViewState('MetaTags',$metaTags,null);
+ }
+ return $metaTags;
}
/**
@@ -104,10 +119,13 @@ class THead extends TControl
if(($title=$page->getTitle())==='')
$title=$this->getTitle();
$writer->write("<head>\n<title>".THttpUtility::htmlEncode($title)."</title>\n");
- foreach($this->_metaTags as $metaTag)
+ if(($metaTags=$this->getMetaTags())!==null)
{
- $metaTag->render($writer);
- $writer->writeLine();
+ foreach($metaTags as $metaTag)
+ {
+ $metaTag->render($writer);
+ $writer->writeLine();
+ }
}
$cs=$page->getClientScript();
$cs->renderStyleSheetFiles($writer);
@@ -256,4 +274,35 @@ class TMetaTag extends TComponent
}
}
+
+/**
+ * TMetaTagCollection class
+ *
+ * TMetaTagCollection represents a collection of meta tags
+ * contained in a {@link THead} control.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TMetaTagCollection extends TList
+{
+ /**
+ * Inserts an item at the specified position.
+ * This overrides the parent implementation by performing type
+ * check on the item being added.
+ * @param integer the speicified position.
+ * @param mixed new item
+ * @throws TInvalidDataTypeException if the item to be inserted is not a {@link TMetaTag}
+ */
+ public function insertAt($index,$item)
+ {
+ if($item instanceof TMetaTag)
+ parent::insertAt($index,$item);
+ else
+ throw new TInvalidDataTypeException('metatagcollection_metatag_invalid');
+ }
+}
+
?> \ No newline at end of file