Permalink
Browse files

Add full support for header link tags, including a shortcut method fo…

…r linking favorites icons (addFavicon). (Jason Giangrande)

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Page/trunk@154863 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 9d594ae commit 119d218eb63fcc52ec0964c8f3bd0204dee6411d Klaus Guenther committed Mar 29, 2004
Showing with 47 additions and 0 deletions.
  1. +47 −0 Page.php
View
47 Page.php
@@ -260,6 +260,14 @@ class HTML_Page extends HTML_Common {
var $_styleSheets = array();
/**
+ * Array of Header <link> tags
+ *
+ * @var array
+ * @access private
+ */
+ var $_links = array();
+
+ /**
* HTML page title
*
* @var string
@@ -451,6 +459,11 @@ function _generateHead()
// http-equiv character set declarations.
$strHtml .= $tab . '<title>' . $this->getTitle() . '</title>' . $lnEnd;
+ // Generate link declarations
+ foreach ($this->_links as $link) {
+ $strHtml .= $tab . $link . $tagEnd . $lnEnd;
+ }
+
// Generate stylesheet links
foreach ($this->_styleSheets as $strSrc => $strAttr ) {
$strHtml .= $tab . "<link rel=\"stylesheet\" href=\"$strSrc\" type=\"".$strAttr['mime'].'"';
@@ -793,6 +806,40 @@ function addStyleDeclaration($content, $type = 'text/css')
} // end func addStyleDeclaration
/**
+ * Adds a favicon
+ * This adds a link to the icon shown in the favorites list or on the left
+ * of the url in the address bar. Some browsers also display it on the tab,
+ * as well.
+ *
+ * @access public
+ * @param string $href The link that is being related.
+ * @param string $type File type
+ * @param string $relation Relation of link
+ * @return void
+ */
+ function addFavicon($href, $type = 'image/x-icon', $relation = 'shortcut icon') {
+ $this->_links[] = "<link href=\"$href\" rel=\"$relation\" type=\"$type\"";
+ } // end func addFavicon
+
+ /**
+ * Adds &lt;link&gt; tags to the head of the document.
+ * $relType defaults to 'rel' as it is the most common relation type used.
+ *
+ * @access public
+ * @param string $href The link that is being related.
+ * @param string $relation Relation of link.
+ * @param string $relType Relation type attribute. Either rel or rev.
+ * @param array $attributes Associative array of remaining attributes.
+ * @return void
+ */
+ function addHeadLink($href, $relation, $relType = 'rel', $attributes = array()) {
+ $attributes = $this->_parseAttributes($attributes);
+ $generatedTag = $this->_getAttrString($attributes);
+ $generatedTag = "<link href=\"$href\" $relType=\"$relation\"" . $generatedTag;
+ $this->_links[] = $generatedTag;
+ } // end func addHeadLink
+
+ /**
* Returns the current API version
*
* @access public

0 comments on commit 119d218

Please sign in to comment.