From 432e97322ad518468235649ad25974eef3f3d39f Mon Sep 17 00:00:00 2001
From: Derek Allard
Date: Wed, 30 Jan 2008 16:13:57 +0000
Subject: Added link() to the HTML helper.
---
system/helpers/html_helper.php | 130 ++++++++++++++++++++++++++++++++++--
user_guide/changelog.html | 1 +
user_guide/helpers/html_helper.html | 54 ++++++++++-----
3 files changed, 163 insertions(+), 22 deletions(-)
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 56e25316c..d887be6ce 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -182,17 +182,122 @@ if (! function_exists('br'))
// ------------------------------------------------------------------------
/**
- * Generates non-breaking space entities based on number supplied
+ * Image
+ *
+ * Generates an image tag
*
* @access public
* @param integer
* @return string
*/
-if (! function_exists('nbs'))
+if (! function_exists('image'))
{
- function nbs($num = 1)
+ function image($src = '', $alt = '', $index_page = FALSE)
{
- return str_repeat(" ", $num);
+ $CI =& get_instance();
+
+ $css = '';
+
+ foreach ($stylesheets as $stylesheet)
+ {
+ if (strpos($stylesheet, '://') !== FALSE)
+ {
+ $href = ' href="'.$stylesheet.'"';
+ }
+ elseif ($index_page === TRUE)
+ {
+ $href = ' href="'.$CI->config->site_url($stylesheet).'"';
+ }
+ else
+ {
+ $href = ' href="'.$CI->config->slash_item('base_url').$stylesheet.'"';
+ }
+
+ $media = ($media !== '') ? ' media="'.$media.'"' : '';
+
+ $css .= 'link type="text/css" rel="stylesheet"'.$href.$media.' />'."\n";
+ }
+
+ return $css;
+ }
+}
+
+// ------------------------------------------------------------------------
+
+/**
+ * Link
+ *
+ * Generates link to a CSS file
+ *
+ * @access public
+ * @param mixed stylesheet name(s)
+ * @param string media type
+ * @param boolean should index_page be added to the css path
+ * @return string
+ */
+if (! function_exists('link'))
+{
+ function link($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
+ {
+ $CI =& get_instance();
+
+ $link = 'link ';
+
+ if (is_array($href))
+ {
+ foreach ($href as $k=>$v)
+ {
+ if ($k == 'href' AND strpos($k, '://') === FALSE)
+ {
+ if ($index_page === TRUE)
+ {
+ $link .= ' href="'.$CI->config->site_url($v).'" ';
+ }
+ else
+ {
+ $link .= ' href="'.$CI->config->slash_item('base_url').$v.'" ';
+ }
+ }
+ else
+ {
+ $link .= "$k=\"$v\" ";
+ }
+ }
+
+ $link .= "/>\n";
+ }
+ else
+ {
+ if ( strpos($href, '://') !== FALSE)
+ {
+ $link .= ' href="'.$href.'" ';
+ }
+ elseif ($index_page === TRUE)
+ {
+ $link .= ' href="'.$CI->config->site_url($href).'" ';
+ }
+ else
+ {
+ $link .= ' href="'.$CI->config->slash_item('base_url').$href.'" ';
+ }
+
+ $link .= 'rel="'.$rel.'" type="'.$type.'" ';
+
+ if ($media != '')
+ {
+ $link .= 'media="'.$media.'" ';
+ }
+
+ if ($title != '')
+ {
+ $link .= 'title="'.$title.'" ';
+ }
+
+ $link .= '/>'."\n";
+ }
+
+
+ return $link;
}
}
@@ -219,4 +324,21 @@ if (! function_exists('meta'))
}
}
+// ------------------------------------------------------------------------
+
+/**
+ * Generates non-breaking space entities based on number supplied
+ *
+ * @access public
+ * @param integer
+ * @return string
+ */
+if (! function_exists('nbs'))
+{
+ function nbs($num = 1)
+ {
+ return str_repeat(" ", $num);
+ }
+}
+
?>
\ No newline at end of file
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index c37b0951c..2ccfbd88c 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -131,6 +131,7 @@ Change Log
Helpers & Plugins
+ - Added link() to the HTML helper.
- Added ability to "extend" Helpers.
- Added an email helper into core helpers.
- Added strip_quotes() function to string helper.
diff --git a/user_guide/helpers/html_helper.html b/user_guide/helpers/html_helper.html
index e07f27778..7abe01af9 100644
--- a/user_guide/helpers/html_helper.html
+++ b/user_guide/helpers/html_helper.html
@@ -68,16 +68,49 @@ Directory Helper
The following functions are available:
+br()
+Generates line break tags (<br />) based on the number you submit. Example:
+echo br(3);
+The above would produce: <br /><br /><br />
heading()
-
Lets you create HTML <h1> tags. The first parameter will contain the data, the
second the size of the heading. Example:
-
echo heading('Welcome!', 3);
-
The above would produce: <h3>Welcome!</h3>
+link()
+Lets you create HTML <link /> tags. The parameters are href, with optional rel, type, title, media and index_page. index_page is a TRUE/FALSE value that specifics if the href should have the page specified by $config['index_page'] added to the address it creates.
+While stylesheets are more conveniently handled through the stylesheet() function, they can also be called here.
+
+link('css/mystyles.css');
+ // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
+Further examples:
+
+
+link('favicon.ico', 'shortcut icon', 'image/ico');
+ // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" />
+
+
+link('feed', 'alternate', 'application/rss+xml', 'My RSS Feed');
+ // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />
+
+
+
+$link = array(
+ 'href' => 'css/printer.css',
+ 'rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'media' => 'print'
+ );
+
+ link($link);
+ // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
+
+nbs()
+Generates non-breaking spaces ( ) based on the number you submit. Example:
+echo nbs(3);
+The above would produce:
ol() and ul()
@@ -196,21 +229,6 @@ echo ul($list);
</ul>
-
-nbs()
-Generates non-breaking spaces ( ) based on the number you submit. Example:
-echo nbs(3);
-The above would produce:
-
-
-br()
-Generates line break tags (<br />) based on the number you submit. Example:
-echo br(3);
-The above would produce: <br /><br /><br />
-
-
-
-
--
cgit v1.2.3-24-g4f1b