Created
September 4, 2017 15:49
-
-
Save dejurin/fc4e3c916eeef5801180991590b9dcda to your computer and use it in GitHub Desktop.
[CodeIgniter] Modified functions: link_tag, meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('link_tag')) { | |
/** | |
* Link. | |
* | |
* Generates link to a CSS file | |
* | |
* @param mixed stylesheet hrefs or an array | |
* @param string rel | |
* @param string type | |
* @param string title | |
* @param string media | |
* @param bool should index_page be added to the css path | |
* | |
* @return string | |
*/ | |
function link_tag($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' && !preg_match('#^([a-z]+:)?//#i', $v)) { | |
if ($index_page === true) { | |
$link .= 'href="'.$CI->config->site_url($v).'" '; | |
} else { | |
$link .= 'href="'.$v.'" '; | |
} | |
} else { | |
$link .= $k.'="'.$v.'" '; | |
} | |
} | |
} else { | |
if (preg_match('#^([a-z]+:)?//#i', $href)) { | |
$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.'" '; | |
} | |
} | |
return trim($link).">"; | |
} | |
} | |
if (!function_exists('meta')) { | |
/** | |
* Generates meta tags from an array of key/values. | |
* | |
* @param array | |
* @param string | |
* @param string | |
* @param string | |
* | |
* @return string | |
*/ | |
function meta($name = '', $content = '', $type = 'name', $newline = "") | |
{ | |
if (!is_array($name)) { | |
$name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline)); | |
} elseif (isset($name['name'])) { | |
// Turn single array into multidimensional | |
$name = array($name); | |
} | |
$str = ''; | |
foreach ($name as $meta) { | |
$type = (isset($meta['type']) && $meta['type'] !== 'name') ?: 'name'; | |
$name = isset($meta['name']) ? $meta['name'] : ''; | |
$content = isset($meta['content']) ? $meta['content'] : ''; | |
$newline = isset($meta['newline']) ? $meta['newline'] : ""; | |
if (isset($meta['type']) && $meta['type'] !== 'name') { | |
$type = 'http-equiv'; | |
} elseif (isset($meta['property'])) { | |
$type = 'property'; | |
$name = $meta['property']; | |
} else { | |
$type = 'name'; | |
} | |
$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'">'.$newline; | |
} | |
return $str; | |
} | |
} | |
/* You can use "property" | |
Example | |
meta([ | |
['name' => 'description', 'content' => ''], | |
['property' => 'fb:app_id', 'content' => ''], | |
['property' => 'og:type', 'content' => ''], | |
['property' => 'og:title', 'content' => ''], | |
['property' => 'og:url', 'content' => ''], | |
['property' => 'og:description', 'content' => ''], | |
['property' => 'og:image', 'content' => ''], | |
]); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment