HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

ocPortal Developer's Guide: XHTML

» Return to Contents



An important and intriguing new feature in ocPortal is the XHTML checker. This nifty system will optionally check all outgoing XHTML code for errors, and report them to you, which is an absolute godsend for template development (and makes you wonder why web browsers do not have an option for this).
It can also be used to display XHTML source whether there are errors or not, presenting a colour coded, indented, and numbered, representation of your XHTML output.

validation.php performs a validation of given XHTML, CSS, accessibility, as well as finding common bugs and browser incompatibilities. To see what it does look at the language file and see what errors are given out.

Blockers for XHTML-strict (which we don't actually use: we use transitional without deprecated tags/attributes)
  • iframe
  • a.target, form.target

Technically, innerHTML shouldn't be used for XHTML. However, Firefox 1.5 and Opera 8 support it, and IE doesn't support proper-XHTML. Regardless, ocPortal does not require parsing as proper-HTML (because if it did, IE wouldn't work with it). More technically, innerHTML isn't even a part of DOM, but it is a defacto standard: Javascript is such a mess, that de-facto standards need to be used and browser-specific workarounds deployed.

Blockers for WCAG2 (standard still a working draft).
  • All radio button groups are marked using fieldset and legend elements. (don't agree with this one, as the name attribute groups them already and fieldset adds a frame around them, which is unwanted because it breaks up the UI too much)
  • No layout tables [make summary attribute have mandatory length, yet layout tables must have no summary => no layout tables] (we'd like to do this, wherever possible; some times CSS is not powerful or stable enough, but this is only in a handful of instances)

The following need to be checked manually
  • <noscript> is given whenever appropriate and possible
  • When plugins are used, info about it must be displayed
  • When an appropriate markup language exists, use markup rather than images to convey information.
  • Mark up lists and list items properly.
  • Ensure that all information conveyed with color is also available without color, for example from context or markup.
  • <blockquote> not used for non-quoting

The following are up to websites
  • Until user agents allow users to freeze moving content, avoid movement in pages AND Until user agents allow users to control flickering, avoid causing the screen to flicker. : by default, nothing flickers, but Comcode allows it. It's a question of whether a site is designed to be accessible for all, or 'fancy' for the majority
  • Alternatives given to multimedia content
  • Use the clearest and simplest language appropriate for a site's content.
  • Divide large blocks of information into more manageable groups where natural and appropriate.
  • Specify the expansion of each abbreviation or acronym in a document where it first occurs.
  • Place distinguishing information at the beginning of headings, paragraphs, lists, etc.

Level 3 accessibility
  • Create a logical tab order through links, form controls, and objects. : impossible to construct a site modularly to do this; easily arguably, this only needs doing in specific cases, which we do do
  • Form control default text invalid (null) : I don't think this one exists in the latest standard ("until user agents"), and rightly so: it is often necessary to have blank inputs. Turn $strict_form_accessibility for this.

sources/validation.php

Global_functions_validation.php

Function summary

void init__validation ()
string html_entity_decode (string input, integer quote_style, ?string charset)
mixed str_word_count (string input, integer format)
URLPATH qualify_url (URLPATH url, URLPATH url_base)
?string http_download_file (URLPATH url, ?integer byte_limit, boolean trigger_error, boolean no_redirect, string ua, ?array post_params, ?array cookies, ?string accept, ?string accept_charset, ?string accept_language, ?resource write_to_file, ?string referer, ?array auth, float timeout, boolean is_xml, ?array files)
?mixed do_lang (ID_TEXT a, ?mixed param_a, ?mixed param_b, ?mixed param_c, ?LANGUAGE_NAME lang, boolean require_result)
string get_forum_type ()
string ocp_srv (string value)
string mailto_obfuscated ()
?mixed mixed ()
?map check_xhtml (string out, boolean well_formed_only, boolean is_fragment, boolean validation_javascript, boolean validation_css, boolean validation_wcag, boolean validation_compat, boolean validation_ext_files, boolean validation_manual)
map _xhtml_error (string error, string param_a, string param_b, string param_c, boolean raw, integer rel_pos)
boolean is_hex (string string)
?mixed test_entity (integer offset)
string fix_entities (string in)
?mixed _get_next_tag ()
mixed _check_tag (string tag, map attributes, boolean self_close, boolean close, list errors)
string _get_tag_basis (string full)

void init__validation()

Standard code module initialisation function.

Parameters…

(No return value)


Return to the function index for this class Expand: View the source code to this function

string html_entity_decode(string input, integer quote_style, ?string charset)

Decode the HTML entitity encoded input string. Can give warning if unrecognised character set.

Parameters…

Name input
Description The text to decode
Type string

Name quote_style
Description The quote style code
Type integer

Name charset
Description Character set to decode to (NULL: default)
Default value
Type ?string

Returns…

Description The decoded text
Type string

Return to the function index for this class Expand: View the source code to this function

mixed str_word_count(string input, integer format)

Isolate the words in the input string.

Parameters…

Name input
Description String to count words in
Type string

Name format
Description The format
Default value 0
Type integer
Values restricted to 0 1

Returns…

Description Typically a list - the words of the input string
Type mixed

Return to the function index for this class Expand: View the source code to this function

URLPATH qualify_url(URLPATH url, URLPATH url_base)

Take a URL and base-URL, and fully qualify the URL according to it.

Parameters…

Name url
Description The URL to fully qualified
Type URLPATH

Name url_base
Description The base-URL
Type URLPATH

Returns…

Description Fully qualified URL
Type URLPATH

Return to the function index for this class Expand: View the source code to this function

?string http_download_file(URLPATH url, ?integer byte_limit, boolean trigger_error, boolean no_redirect, string ua, ?array post_params, ?array cookies, ?string accept, ?string accept_charset, ?string accept_language, ?resource write_to_file, ?string referer, ?array auth, float timeout, boolean is_xml, ?array files)

Return the file in the URL by downloading it over HTTP. If a byte limit is given, it will only download that many bytes. It outputs warnings, returning NULL, on error.

Parameters…

Name url
Description The URL to download
Type URLPATH

Name byte_limit
Description The number of bytes to download. This is not a guarantee, it is a minimum (NULL: all bytes)
Default value
Type ?integer
Value range 1 max

Name trigger_error
Description Whether to throw an ocPortal error, on error
Default value boolean-true
Type boolean

Name no_redirect
Description Whether to block redirects (returns NULL when found)
Default value boolean-false
Type boolean

Name ua
Description The user-agent to identify as
Default value ocPortal
Type string

Name post_params
Description An optional array of POST parameters to send; if this is NULL, a GET request is used (NULL: none)
Default value
Type ?array

Name cookies
Description An optional array of cookies to send (NULL: none)
Default value
Type ?array

Name accept
Description 'accept' header value (NULL: don't pass one)
Default value
Type ?string

Name accept_charset
Description 'accept-charset' header value (NULL: don't pass one)
Default value
Type ?string

Name accept_language
Description 'accept-language' header value (NULL: don't pass one)
Default value
Type ?string

Name write_to_file
Description File handle to write to (NULL: do not do that)
Default value
Type ?resource

Name referer
Description The HTTP referer (NULL: none)
Default value
Type ?string

Name auth
Description A pair: authentication username and password (NULL: none)
Default value
Type ?array

Name timeout
Description The timeout
Default value 6
Type float

Name is_xml
Description Whether to treat the POST parameters as a raw POST (rather than using MIME)
Default value boolean-false
Type boolean

Name files
Description Files to send. Map between field to file path (NULL: none)
Default value
Type ?array

Returns…

Description The data downloaded (NULL: error)
Type ?string

Return to the function index for this class Expand: View the source code to this function

?mixed do_lang(ID_TEXT a, ?mixed param_a, ?mixed param_b, ?mixed param_c, ?LANGUAGE_NAME lang, boolean require_result)

Get the human-readable form of a language id, or a language entry from a language INI file. (STUB)

Parameters…

Name a
Description The language id
Type ID_TEXT

Name param_a
Description The first token [string or tempcode] (replaces {1}) (NULL: none)
Default value
Type ?mixed

Name param_b
Description The second token [string or tempcode] (replaces {2}) (NULL: none)
Default value
Type ?mixed

Name param_c
Description The third token (replaces {3}). May be an array of [of string], to allow any number of additional args (NULL: none)
Default value
Type ?mixed

Name lang
Description The language to use (NULL: users language)
Default value
Type ?LANGUAGE_NAME

Name require_result
Description Whether to cause ocPortal to exit if the lookup does not succeed
Default value boolean-true
Type boolean

Returns…

Description The human-readable content (NULL: not found). String normally. Tempcode if tempcode parameters.
Type ?mixed

Return to the function index for this class Expand: View the source code to this function

string get_forum_type()

Get the type of forums installed.

Parameters…

Returns…

Description The type of forum installed
Type string

Return to the function index for this class Expand: View the source code to this function

string ocp_srv(string value)

Get server environment variables. (STUB)

Parameters…

Name value
Description The variable name
Type string

Returns…

Description The variable value ('' means unknown)
Type string

Return to the function index for this class Expand: View the source code to this function

string mailto_obfuscated()

Get obfuscate version of 'mailto:' (which'll hopefully fool e-mail scavengers to not pick up these e-mail addresses).

Parameters…

Returns…

Description The obfuscated 'mailto:' string
Type string

Return to the function index for this class Expand: View the source code to this function

?mixed mixed()

Assign this to explicitly declare that a variable may be of mixed type, and initialise to NULL.

Parameters…

Returns…

Description Of mixed type (NULL: default)
Type ?mixed

Return to the function index for this class Expand: View the source code to this function

?map check_xhtml(string out, boolean well_formed_only, boolean is_fragment, boolean validation_javascript, boolean validation_css, boolean validation_wcag, boolean validation_compat, boolean validation_ext_files, boolean validation_manual)

Check the specified XHTML, and return the results.

Parameters…

Name out
Description The XHTML to validate
Type string

Name well_formed_only
Description Whether to avoid checking for relational errors (false implies just a quick structural check, aka a 'well formed' check)
Default value boolean-false
Type boolean

Name is_fragment
Description Whether what is being validated is an HTML fragment, rather than a whole document
Default value boolean-false
Type boolean

Name validation_javascript
Description Validate javascript
Default value boolean-true
Type boolean

Name validation_css
Description Validate CSS
Default value boolean-true
Type boolean

Name validation_wcag
Description Validate WCAG
Default value boolean-true
Type boolean

Name validation_compat
Description Validate for compatibility
Default value boolean-true
Type boolean

Name validation_ext_files
Description Validate external files
Default value boolean-true
Type boolean

Name validation_manual
Description Bring up messages about manual checks
Default value boolean-false
Type boolean

Returns…

Description Error information (NULL: no error)
Type ?map

Return to the function index for this class Expand: View the source code to this function

map _xhtml_error(string error, string param_a, string param_b, string param_c, boolean raw, integer rel_pos)

Get some general debugging information for an identified XHTML error.

Parameters…

Name error
Description The error that occurred
Type string

Name param_a
Description The first parameter of the error
Default value
Type string

Name param_b
Description The second parameter of the error
Default value
Type string

Name param_c
Description The third parameter of the error
Default value
Type string

Name raw
Description Whether to not do a lang lookup
Default value boolean-false
Type boolean

Name rel_pos
Description Offset position
Default value 0
Type integer

Returns…

Description A map of the error information
Type map

Return to the function index for this class Expand: View the source code to this function

boolean is_hex(string string)

Checks to see if a string holds a hexadecimal number.

Parameters…

Name string
Description The string to check
Type string

Returns…

Description Whether the string holds a hexadecimal number
Type boolean

Return to the function index for this class Expand: View the source code to this function

?mixed test_entity(integer offset)

Test the next entity in the output stream.

Parameters…

Name offset
Description Checking offset
Default value 0
Type integer

Returns…

Description An array of error details (NULL: no errors)
Type ?mixed

Return to the function index for this class Expand: View the source code to this function

string fix_entities(string in)

Fix any invalid entities in the text.

Parameters…

Name in
Description Text to fix in
Type string

Returns…

Description Fixed result
Type string

Return to the function index for this class Expand: View the source code to this function

?mixed _get_next_tag()

Get the next tag in the current XHTML document.

Parameters…

Returns…

Description Either an array of error details, a string of the tag, or NULL for finished (NULL: no next tag)
Type ?mixed

Return to the function index for this class Expand: View the source code to this function

mixed _check_tag(string tag, map attributes, boolean self_close, boolean close, list errors)

Checks an XHTML tag for validity, including attributes. Return the results.

Parameters…

Name tag
Description The name of the tag to check
Type string

Name attributes
Description A map of attributes (name=>value) the tag has
Type map

Name self_close
Description Whether this is a self-closing tag
Type boolean

Name close
Description Whether this is a closing tag
Type boolean

Name errors
Description Errors detected so far. We will add to these and return
Type list

Returns…

Description String for tag basis form, or array of error information
Type mixed

Return to the function index for this class Expand: View the source code to this function

string _get_tag_basis(string full)

Get the tag basis for the specified tag. e.g. '<br />' would become 'br'. Note: tags with parameters given are not supported.

Parameters…

Name full
Description The full tag
Type string

Returns…

Description The basis of the tag
Type string

Return to the function index for this class Expand: View the source code to this function