Skip to content

Instantly share code, notes, and snippets.

@cj
Created December 30, 2010 22:31
Show Gist options
  • Save cj/760416 to your computer and use it in GitHub Desktop.
Save cj/760416 to your computer and use it in GitHub Desktop.
if( ! function_exists('link_tag') )
{
function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
{
$ob = this();
$link = '<link ';
$vi = Ssc::instance(); // obullo changes ..
// When user use view_set_folder('css', 'iphone'); .. /sources/iphone/css/welcome.css
$path = '';
if(isset($vi->_ew->css_folder{1}))
{
$path = $vi->_ew->css_folder .'/';
}
if (is_array($href))
{
foreach ($href as $k => $v)
{
$v = ltrim($v, '/'); // remove first slash
if ($k == 'href' AND strpos($v, '://') === FALSE)
{
if ($index_page === TRUE)
{
$link .= ' href="'.$ob->config->site_url($v).'" ';
}
else
{
$link .= ' href="'.$ob->config->public_url() . $path . $v.'" ';
}
}
else
{
$link .= "$k=\"$v\" ";
}
}
$link .= "/>";
}
else
{
$href = ltrim($href, '/'); // remove first slash
if ( strpos($href, '://') !== FALSE)
{
$link .= ' href="'.$href.'" ';
}
elseif ($index_page === TRUE)
{
$link .= ' href="'. $ob->config->site_url($href) .'" ';
}
else
{
switch($type)
{
case 'text/javascript':
$folder= 'js/';
$extension=".js";
break;
case 'text/css':
$extension=".css";
$folder= 'css/';
break;
default:
$folder= '';
$extension= '';
}
if(strpos($href, '../') === 0)
$path= DS.preg_replace('/(\w+)\/(.+)/i', '$1/public/'.$folder.'$2', substr($href, 3));
else
$path= $ob->config->public_url() . $path . $folder . $href;
$link .= ' href="'. $path . $extension .'" ';
}
$link .= 'rel="'.$rel.'" type="'.$type.'" ';
if ($media != '')
{
$link .= 'media="'.$media.'" ';
}
if ($title != '')
{
$link .= 'title="'.$title.'" ';
}
$link .= '/>';
}
return $link;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment