Changeset 121

Show
Ignore:
Timestamp:
06/29/09 20:59:21 (14 months ago)
Author:
seanja
Message:

And you can now use the css/js html helper functions to include external css and js files (provided you write out the full path of course)

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • application/views/header.php

    r92 r121  
    1010        <?php css('style.css')?> 
    1111         
    12         <?php js('jquery-1.3.2.min.js'); ?> 
     12        <?php js('http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'); ?> 
    1313         
    1414        <?php js('sh_main.js'); ?> 
  • library/helpers/html.helper.php

    r99 r121  
    77 * @param array $attributes 
    88 */ 
    9 function href($url, $title, $attributes=array()){ 
     9function href($url, $title, $attributes=array()) { 
    1010        global $config; 
    1111        $attributeString = ''; 
    12         foreach($attributes as $attribute=>$value){ 
     12        foreach($attributes as $attribute=>$value) { 
    1313                $attributeString .= $attribute.'="'.$value.'"'; 
    1414        } 
    15         if(strstr($url, 'http://') !== 0){ 
     15        if(strstr($url, 'http://') === 0 ||  strstr($url, 'https://')) { 
    1616                $url = $config->base_url.$config->index_file.$url; 
    1717        } 
     
    2828 * @return str 
    2929 */ 
    30 function docType($type = 'html_trans'){ 
     30function docType($type = 'html_trans') { 
    3131        $docType = ''; 
    32         if($type == 'xhtml_strict'){ 
    33                 $docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     32        switch ($type) { 
     33                case 'xhtml_strict': 
     34                        $docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    3435   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; 
    35         } elseif ($type == 'xhtml_trans'){ 
    36                 $docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     36                        break; 
     37                case 'xhtml_trans': 
     38                        $docType = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    3739   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; 
    38         } elseif ($type == 'html_strict'){ 
    39                 $docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
     40                        break; 
     41                case 'html_strict': 
     42                        $docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    4043   "http://www.w3.org/TR/html4/strict.dtd">'; 
    41         } elseif($type == 'html_trans') { 
    42                 $docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
     44                        break; 
     45                case 'html_trans': 
     46                        $docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    4347  "http://www.w3.org/TR/html4/loose.dtd">'; 
     48                        break; 
     49                default: 
     50                        throw new Exception('Invalid doctype specified, it should be one of: xhtml_strict, xhtml_trans, html_strict, html_trans'); 
     51                        break; 
    4452        } 
    4553        echo $docType; 
    4654} 
    4755 
    48 function metaTag($attributes){ 
    49         if(!is_array($attributes)){ 
     56function metaTag($attributes) { 
     57        if(!is_array($attributes)) { 
    5058                throw new Exception('Attributes must be provided in array format'); 
    5159        } 
    5260        $attributeList = ' '; 
    53         foreach($attributes as $attribute=>$value){ 
     61        foreach($attributes as $attribute=>$value) { 
    5462                $attributeList .= sEscape::html($attribute) .'="'.sEscape::html($value).'" '; 
    5563        } 
     
    6270 * @return str 
    6371 */ 
    64 function charset(){ 
     72function charset() { 
    6573        global $config; 
    6674        $attributes = array( 
     
    7381/** 
    7482 * Generate the css include string 
    75  * @param <type> $file 
     83 * @param str $file 
     84 * @param str 
    7685 * @return <type> 
    7786 */ 
    78 function css($file){ 
     87function css($file, $media=array('all')) { 
    7988        global $config; 
    80         echo '<link rel="stylesheet" type="text/css" href="'.sEscape::html($config->base_url."public/css/$file").'" />'; 
     89        if(!is_array($media)) { 
     90                throw new Exception('media must be provided in array format'); 
     91        } 
     92        if(strpos($file, 'http://') === 0 || strpos($file, 'https://') === 0) { 
     93                $str = '<link rel="stylesheet" type="text/css" href="'.sEscape::html($file).'"'; 
     94        } else { 
     95                $str = '<link rel="stylesheet" type="text/css" href="'.sEscape::html($config->base_url.'public/css/'.$file).'"'; 
     96        } 
     97        $str .= ' media = "'.sEscape::html(implode(',', $media)).'" />'; 
     98        echo $str; 
    8199} 
    82100 
     
    86104 * @return <type> 
    87105 */ 
    88 function js($file){ 
     106function js($file) { 
    89107        global $config; 
    90         echo '<script type="text/javascript" src="'.sEscape::html($config->base_url."public/js/$file").'" ></script>'; 
     108        if(strpos($file, 'http://') === 0 || strpos($file, 'https://') === 0) { 
     109                echo '<script type="text/javascript" src="'.sEscape::html($file).'" ></script>'; 
     110        } else { 
     111                echo '<script type="text/javascript" src="'.sEscape::html($config->base_url."public/js/$file").'" ></script>'; 
     112        } 
    91113}