phpUserTrack
[ class tree: phpUserTrack ] [ index: phpUserTrack ] [ all elements ]

Source for file function.html_doctype.php

Documentation is available at function.html_doctype.php

  1. <?php
  2. /**
  3.  * Smarty plugin to generate page header
  4.  * @package phpUserTrack
  5.  */
  6.  
  7. /**
  8.  * Adds a (X)HTML doctype to the current document.
  9.  *
  10.  * @param array $params
  11.  * @param object &$smarty
  12.  * @author Andr? Rabold
  13.  * @author S. Shah
  14.  * @return string HTML Header
  15.  */
  16. function smarty_function_html_doctype($params&$smarty)
  17. {
  18.   // Default values:
  19.   $xhtml            true;
  20.   $type             "Transitional";
  21.   $dtd              true;
  22.   $omitxml          true;
  23.   $encoding         "UTF-8";
  24.   $sendheaders      true;
  25.   $force_opera_html false;
  26.   
  27.   extract($params);
  28.   
  29.   $type ucfirststrtolower($type) )// standardise $type's case
  30.   if (headers_sent())
  31.     $sendheaders false;
  32.  
  33.   // DOCTYPE Header  
  34.   $header "";
  35.  
  36.   // Impliment opera check and overide
  37.   if($force_opera_html && $xhtml)
  38.   {
  39.       if (stristr($_SERVER['HTTP_USER_AGENT'],"Opera 7")||stristr($_SERVER['HTTP_USER_AGENT'],"Opera/7"))
  40.       {
  41.           $xhtml false;
  42.           $version 4.01;
  43.       }
  44.   }
  45.   
  46.   
  47.   // XHTML
  48.   if ($xhtml{
  49.     if ($sendheaders{
  50.       // first check if browser accepts application/xhtml+xml content type
  51.       if (stristr($_SERVER['HTTP_ACCEPT'],"application/xhtml+xml")) {
  52.         header("Content-Typeapplication/xhtml+xmlcharset=$encoding");
  53.         $GLOBALS["HTML_DOCTYPE""xml";//******
  54.       }
  55.       elseif (stristr($_SERVER['HTTP_ACCEPT'],"application/xml")) {
  56.         header("Content-Typeapplication/xmlcharset=$encoding");
  57.         $GLOBALS["HTML_DOCTYPE""xml";//******
  58.       }
  59.       elseif (stristr($_SERVER['HTTP_ACCEPT'],"text/xml")) {
  60.         header("Content-Typetext/xmlcharset=$encoding");
  61.         $GLOBALS["HTML_DOCTYPE""xml";//******
  62.       }
  63.       //Send Opera 7.0 application/xhtml+xml
  64.       elseif (stristr($_SERVER['HTTP_USER_AGENT'],"Opera 7")||stristr($_SERVER['HTTP_USER_AGENT'],"Opera/7")) {
  65.         header("Content-Typeapplication/xhtml+xmlcharset=$encoding");
  66.         $GLOBALS["HTML_DOCTYPE""xml";//******
  67.       }
  68.       //Send everyone else text/html
  69.       else {
  70.         header("Content-Typetext/htmlcharset=$encoding");
  71.         $GLOBALS["HTML_DOCTYPE""html";//******
  72.       }
  73.     }
  74.    
  75.     if (!isset($version|| $version 1.1{
  76.       $version "1.0";  // default version for XHMTL
  77.     }
  78.     if ($dtd === true{
  79.       // Add default DTD
  80.       if ($version == "1.0" && strtolower($type== "strict")
  81.         $dtd "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
  82.       else if ($version == "1.0" && strtolower($type== "transitional")
  83.         $dtd "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
  84.       else if ($version == "1.0" && strtolower($type== "frameset")
  85.         $dtd "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";
  86.       else if ($version == "1.1")
  87.         $dtd "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
  88.       else
  89.         $dtd ""// unknown XHTML version and/or type
  90.     }
  91.  
  92.     if (!$omitxml{
  93.       if (trim($encoding!= "")
  94.         $header .= "<?xml version=\"1.0\" encoding=\"$encoding\"?>\n";
  95.       else
  96.         $header .= "<?xml version=\"1.0\"?>\n";
  97.     }
  98.     
  99.     // For some reasons "html" is written in lowercase here (check w3.org)
  100.     if ($version == "1.1")
  101.       $header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"";
  102.     else //default
  103.       $header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML $version $type//EN\"";
  104.  
  105.     if ($dtd != "" && $dtd !== false)
  106.       $header .= " \"$dtd\"";
  107.     $header .= ">\n";
  108.   }
  109.   // HTML
  110.   else {
  111.     if ($sendheaders{
  112.       header("Content-Typetext/htmlcharset=$encoding");
  113.         $GLOBALS["HTML_DOCTYPE""html";
  114.     }
  115.     
  116.     if ($version == "2.0" || intval($version== 2{
  117.       // does anybody still uses this?
  118.       $header .= "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n";
  119.     }
  120.     else if ($version == "3.2" || intval($version== 3{
  121.       // does anybody still uses this?
  122.       $header .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n";
  123.     }
  124.     else {
  125.       if (!isset($version))
  126.         $version "4.01"// default version for HTML
  127.       elseif ($version == "4.0" || $version == "4.00")
  128.         $version "4.0";
  129.       
  130.       if ($dtd === true{
  131.         // Add default DTD
  132.         if ($version === "4.01" && (strtolower($type== "strict" || empty($type)))
  133.           $dtd "http://www.w3.org/TR/html4/strict.dtd";
  134.         elseif ($version === "4.01" && strtolower($type== "transitional"
  135.           $dtd "http://www.w3.org/TR/html4/loose.dtd";
  136.         elseif ($version === "4.01" && strtolower($type== "frameset")
  137.           $dtd "http://www.w3.org/TR/html4/frameset.dtd";
  138.         elseif ($version === "4.0" && (strtolower($type== "strict" || empty($type)))
  139.           $dtd "http://www.w3.org/TR/REC-html40/strict.dtd";
  140.         elseif ($version === "4.0" && strtolower($type== "transitional")
  141.           $dtd "http://www.w3.org/TR/REC-html40/loose.dtd";
  142.         elseif ($version === "4.0" && strtolower($type== "frameset")
  143.           $dtd "http://www.w3.org/TR/REC-html40/frameset.dtd";
  144.         else
  145.           $dtd ""// no default DTD (e.g. version 3.2 and 2.0 doesn't use a DTD)
  146.       }
  147.       
  148.       if (empty($type|| strtolower($type== "strict")
  149.         $header .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML $version//EN\"";
  150.       else
  151.         $header .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML $version $type//EN\"";
  152.       if ($dtd != "" && $dtd !== false)
  153.         $header .= " \"$dtd\"";
  154.       $header .= ">\n";
  155.     }
  156.   }
  157.     
  158.   return $header;
  159. }
  160. ?>

Documentation generated on Tue, 06 Nov 2007 09:21:40 -0800 by phpDocumentor 1.4.0a2