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

Class: Cnz_Html

Source Location: /Html.php

Class Overview


HTML class


Constants

Methods



Class Details

[line 197]
HTML class

This utility class provides general HTML support methods.

To use this class, load the class Cnz_Html and then call the static method init() prior to any output on the web page. The class is controlled by a configuration file.

Example INI (defaults shown as comments):


 [Html]
 domain          = www.example.com
 sslDomain       = www.example.com
 ;charSets       = utf-8
 ;languages      = en-us
 ;transitional   = no
 ;indent         = \t
 wcagLevel       = AAA
 ;brickDir       = /slib/image/brick/
 ;buttonDir      = /slib/image/button/
 ;logDir         = log
 ;tmpDir         = tmp
 ;uploadDir      = upload
 ;logFile        = html.log
 ;logLevel       = info
 phpLogFile      = php.log
 phpLogLevel     = E_STRICT
 

brickDir is for link bricks such as the W3C validation bricks. buttonDir is for control buttons such as table next/prev.

indent defines the string used for a single level of HTML indentation.

tmpDir and logDir are relative to the application root directory, which is defined to be the parent of the web document root directory.

logLevel can be any of the log levels defined by Zend_Log (debug, info, notice, warn, err, crit, alert, or severe).

Example PHP:

  1.  Zend_Loader::loadClass('Cnz_Html');

The init() method will detect the capabilities of the client web browser and send the appropriate HTTP headers. XHTML 1.1 will be chosen as the content type if the browser prefers XHTML, else the content type will be set to HTML 4.01 Strict. If transitional is true, these will instead be XHTML 1.0 Transitional and HTML 4.01 Transitional, respectively.

init() also compares the list of languages in the configuration file to those in the Accept-Language header to find the best match. If there is no match, the language defaults to the first in the configuration list. The match can be retrieved using getLanguage().

init() processes the Accept-Charset header in the same way. Use getCharSet() to retrieve the selected character set.

Based on the detections above, the appropriate HTTP response headers are generated, and all prolog information up to and including the html start tag is output.

Given that the most common scenario for a database-driven site is to have a single database, init() has an option of connecting to that database. This connection is defined by passing a second argument to init() which is the name of the database configuration file. This is allowed to be in a separate file because it contains security information. The connection is a Zend_Db_Adapter.

A third boolean parameter specifies whether the connection will be made immediately, or postponed until it is accessed.


 [Database]
 type        = pgsql
 host        = localhost
 port        = database_port
 dbname      = database_name
 username    = database_user
 password    = database_password
 

The valid database type values are: dblib, firebird, informix, mysql, oci, odbc, pgsql, sqlite. See PDO_* at http://www.php.net/manual/en/ref.pdo.php. Additionally, the non-PDO database types db2 and oracle may be used.

Leave the host undefined for socket connections.

Pages using this class must be written with XHTML syntax. If the end-tag shorthand sequence "/>" occurs anywhere else in the text, it must be replaced with "/>" or else the "/" (and any preceding whitespace) will be stripped when the page is served as HTML.

When using JavaScript, the value of the type attribute of the script tag should be set as follows.


 type = "<?php echo Cnz_Html::getJavascriptType(); ?>"
 

There are also getter methods for several other settings.

The following directory structure is recommended. The recommended * BASE is /srv/www/host/.

 $BASE --- app  Application code
        |
        |- cfg  Configurations
        |  |
        |  |- form    Form configurations
        |  |- table   Table configurations
        |
        |- dat  Data files
        |  |
        |  |- table  Table data
        |
        |- doc  Documentation
        |
        |- log  Log files
        |
        |- tmp  Temporary files
        |
        |- upload  Temporary upload directory
        |
        |- www  Web document root
           |
           |- image   Images (local to current directory)
           |- lib     Site library
           |  |- image   Images
           |  |- script  Client-side Scripts
           |  |- style   Style Sheets
           |
           |- script  Client-side Scripts (local to current directory)
           |- style   Style sheets (local to current directory)

       --- slib  Server library (Apache alias)
           |
           |- image   Images
           |  |
           |  |- brick   Link bricks
           |  |- button  Control buttons
           |
           |- script  Client-side Scripts
           |- style   Style sheets




[ Top ]


Class Methods


static method arrayToList [line 423]

static string arrayToList( array $array, [string $fieldDelimiter = NULL], [string $listDelimiter = NULL])

Convert an associative array to a list of the form key:val,key:val.

If any value is itself an array, it will be expanded as key:val1:val2...




Tags:

return:  List
access:  public


Parameters:

array   $array  
string   $fieldDelimiter  
string   $listDelimiter  

[ Top ]

static method checkFileExtension [line 538]

static mixed checkFileExtension( string $filename, string $ext)

Check file extension.



Tags:

return:  Filename without extension, or false if wrong file extension
access:  public


Parameters:

string   $filename  
string   $ext  

[ Top ]

static method configFlag [line 458]

static boolean configFlag( $value $value)

Convert a configuration file string value to boolean.



Tags:

return:  converted to boolean
access:  public


Parameters:

$value   $value   Value from configuration file

[ Top ]

static method dbConnect [line 485]

static boolean dbConnect( [boolean $nowFlag = false])

Create a database connection using the configuration information provided to init(). The default Zend_Db_Table_Abstract adapter is set to this connection. The connection is actually established if nowFlag is true.



Tags:

return:  Success
access:  public


Parameters:

boolean   $nowFlag   Connect to database now

[ Top ]

static method displayW3cBricks [line 556]

static void displayW3cBricks( [boolean $link = true])

Display W3C bricks for valid X/HTML, CSS, and WCAG.

The files valid-xhtml11.png, valid-html401.png, and vcss.png (all available from w3.org) must be in brickDir.




Tags:

access:  public


Parameters:

boolean   $link   Link to validator pages (unless SSL)

[ Top ]

static method docDir [line 599]

static string docDir( [relative $relative = false])

Determine the current document directory. This is necessary for use with mod_rewrite, when the script directory cannot be relied on.



Tags:

return:  Root URL
access:  public


Parameters:

relative   $relative   Relative (to web doc root) flag

[ Top ]

static method fileExtension [line 625]

static string fileExtension( string $filename)

Extrace the the extension from a file name.



Tags:

return:  File extension
access:  public


Parameters:

string   $filename  

[ Top ]

static method filepathToUri [line 638]

static string filepathToUri( string $filepath)

Convert an absolute filesystem pathname to URI.



Tags:

return:  URI of file, or NULL on error.
access:  public


Parameters:

string   $filepath   filepath Filesystem pathname

[ Top ]

static method getBrickDir [line 270]

static string getBrickDir( )



Tags:

return:  Brick directory
access:  public


[ Top ]

static method getButtonDir [line 276]

static string getButtonDir( )



Tags:

return:  Button directory
access:  public


[ Top ]

static method getContentType [line 282]

static string getContentType( )



Tags:

return:  Content type
access:  public


[ Top ]

static method getDb [line 288]

static Zend_Db getDb( )



Tags:

return:  Database connection
access:  public


[ Top ]

static method getDomain [line 294]

static string getDomain( )



Tags:

return:  Domain
access:  public


[ Top ]

static method getFieldDelimiter [line 300]

static string getFieldDelimiter( )



Tags:

return:  Config file field delimiter
access:  public


[ Top ]

static method getHtmlConfigFile [line 316]

static string getHtmlConfigFile( )



Tags:

return:  HTML configuration file
access:  public


[ Top ]

static method getIndentLevel [line 322]

static int getIndentLevel( )



Tags:

return:  Indent level
access:  public


[ Top ]

static method getIndentString [line 340]

static string getIndentString( )



Tags:

return:  Indent string
access:  public


[ Top ]

static method getJavascriptType [line 346]

static string getJavascriptType( )



Tags:

return:  Type attribute for HTML script tag
access:  public


[ Top ]

static method getLanguage [line 352]

static string getLanguage( )



Tags:

return:  Language code
access:  public


[ Top ]

static method getListDelimiter [line 358]

static string getListDelimiter( )



Tags:

return:  Config file list delimiter
access:  public


[ Top ]

static method getLogger [line 374]

static Zend_Log getLogger( )



Tags:

return:  Logger
access:  public


[ Top ]

static method getSslDomain [line 380]

static string getSslDomain( )



Tags:

return:  SSL domain
access:  public


[ Top ]

static method getTmpDir [line 386]

static string getTmpDir( )



Tags:

return:  Tmp directory
access:  public


[ Top ]

static method getUploadDir [line 392]

static string getUploadDir( )



Tags:

return:  Upload directory
access:  public


[ Top ]

static method indentDec [line 665]

static void indentDec( [int $n = 1])

Decrement the indentation level.



Tags:

access:  public


Parameters:

int   $n   Number of levels to decrement.

[ Top ]

static method indentGenerate [line 678]

static void indentGenerate( )



Tags:

access:  public


[ Top ]

static method indentInc [line 689]

static void indentInc( [int $n = 1])

Increment the indentation level.



Tags:

access:  public


Parameters:

int   $n   Number of levels to increment.

[ Top ]

static method init [line 728]

static void init( [string $configFile = NULL], [string $dbConfigFile = NULL], [boolean $dbConnectFlag = false])

Initialize the application.

This method can optionally establish a connection to a database. For security reasons, the database configuration is expected to be in a separate file, but this is not required. The default configuration files are html.ini and database.ini, both in the default configuration directory cfg adjacent to the web document root.

Configuration fields: domain Site domain (required) sslDomain Site SSL domain (default none) charSets Character set list (default utf-8) languages Language list (default en-us) transitional Transitional flag (default no) indent Indent string (default \t) wcagLevel WCAG Conformance (default none) brickDir Brick directory (default /slib/image/brick) buttonDir Button directory (default /slib/image/button) logDir Log directory (default log) tmpDir Temporary directory (default tmp) uploadDir Upload tmp directory (default upload) logFile HTML log File (default html.log) logLevel HTML log level (default info) phpLogFile PHP log File (default unchanged) phpLoglevel PHP log Level (default unchanged)




Tags:

access:  public


Parameters:

string   $configFile   Configuration file
string   $dbConfigFile   Database configuration file
boolean   $dbConnectFlag   Connect to database now

[ Top ]

static method isSsl [line 400]

static boolean isSsl( )



Tags:

return:  True if SSL
access:  public


[ Top ]

static method isXhtml [line 406]

static boolean isXhtml( )



Tags:

return:  True if content type is XHTML
access:  public


[ Top ]

static method listAppendToArray [line 1023]

static void listAppendToArray( &$array, $list)

This function converts a list to an array and appends the results to an existing array.



Tags:

access:  public


Parameters:

   &$array  
   $list  

[ Top ]

static method listToArray [line 1038]

static array listToArray( $list)

Convert a list of the form key:val,key:val to an associative array.

If a list item has more then 2 fields, the value is set to an array of all the fields beyond the key.




Tags:

return:  List as assocative array.
access:  public


Parameters:

   $list  

[ Top ]

static method loadAndDisplay [line 1077]

static object Created loadAndDisplay( $className, [array $options = array()], [string $style = NULL])

Load class, create object, then display with a single statement.



Tags:

return:  object of type $className
access:  public


Parameters:

array   $options   Common options
string   $style   Value for outermost style attribute
   $className  

[ Top ]

static method parseAcceptHeader [line 1092]

static array parseAcceptHeader( string $header)

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for details on the format of Accept headers.



Tags:

return:  Header as an associative array of form type => Q value
access:  public


Parameters:

string   $header   Header

[ Top ]

static method setFieldDelimiter [line 309]

static void setFieldDelimiter( [string $fieldDelimiter = self::DEFAULT_FIELD_DELIMITER])



Tags:

access:  public


Parameters:

string   $fieldDelimiter   New config file field delimiter

[ Top ]

static method setIndentLevel [line 331]

static void setIndentLevel( int $indentLevel)



Tags:

access:  public


Parameters:

int   $indentLevel   New indentation level

[ Top ]

static method setListDelimiter [line 367]

static void setListDelimiter( [string $listDelimiter = self::DEFAULT_LIST_DELIMITER])



Tags:

access:  public


Parameters:

string   $listDelimiter   New config file list delimiter

[ Top ]

static method uriRoot [line 1113]

static string uriRoot( )

Generate the root URI (without trailing /).



Tags:

return:  Root URL
access:  public


[ Top ]

static method xhtmlToHtml [line 1128]

static string xhtmlToHtml( string $buffer)

Strips short-hand end-tags from XHTML to make valid HTML.

This method is public for use by output buffering functions. It would not be called directly by the application.




Tags:

return:  Modified output buffer
access:  public


Parameters:

string   $buffer   Output buffer

[ Top ]


Class Constants

CONFIG_SEC_DATABASE =  'Database'

[line 200]


[ Top ]

CONFIG_SEC_HTML =  'Html'

[line 199]


[ Top ]

CONTENT_TYPE_HTML =  'text/html'

[line 202]


[ Top ]

CONTENT_TYPE_XHTML =  'application/xhtml+xml'

[line 201]


[ Top ]

DEFAULT_BRICK_DIR =  '/slib/image/brick/'

[line 206]


[ Top ]

DEFAULT_BUTTON_DIR =  '/slib/image/button/'

[line 207]


[ Top ]

DEFAULT_CFG_FILE =  '../cfg/html.ini'

[line 208]


[ Top ]

DEFAULT_CHARSET =  'utf-8'

[line 210]


[ Top ]

DEFAULT_DBCFG_FILE =  '../cfg/database.ini'

[line 209]


[ Top ]

DEFAULT_FIELD_DELIMITER =  ':'

[line 212]


[ Top ]

DEFAULT_LANGUAGE =  'en-us'

[line 211]


[ Top ]

DEFAULT_LIST_DELIMITER =  ','

[line 213]


[ Top ]

DEFAULT_LOG_DIR =  'log'

[line 214]


[ Top ]

DEFAULT_LOG_FILE =  'html.log'

[line 215]


[ Top ]

DEFAULT_LOG_LEVEL =  Zend_Log::INFO

[line 216]


[ Top ]

DEFAULT_TMP_DIR =  'tmp'

[line 217]


[ Top ]

DEFAULT_UPLOAD_DIR =  'upload'

[line 218]


[ Top ]

JAVASCRIPT_TYPE_HTML =  'text/javascript'

[line 204]


[ Top ]

JAVASCRIPT_TYPE_XHTML =  'application/javascript'

[line 203]


[ Top ]

SCRIPT_FILE_EXT =  'js'

[line 219]


[ Top ]

STYLE_FILE_EXT =  'css'

[line 220]


[ Top ]

STYLE_TYPE =  'text/css'

[line 205]


[ Top ]



Documentation generated on Thu, 19 Jul 2007 15:02:11 -0400 by phpDocumentor 1.4.0RC2