Special Functions

  Previous topic Next topic  

Special functions are called when certain events occur. These special functions can be used in the configuration's "functions" program or in the "user functions" file, which can be specified in the Config Files Option Page of the Validator Engine Options.

Also see the Sample 'User Functions' File topic.

NOTE: Two or more functions with the same function name is OK. Each function will be executed, but the order of execution is undefined.

Special Functions

onAttributeQuotedMessage()

This function is called when an error message is being generated for a quoted attribute value. In special cases, one may want to allow this and perform special processing for quoted attributes. (New v10.9912)

$oaqm_attname - the name of the unknown attribute

$oaqm_msgtext - the message text of the validator message that will be generated

$oaqm_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$oaqm_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$oaqm_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR

onAttributeValueID_(id)()

Replace (id) with the actual ID of the attribute value in the current configuration. This function is executed when an attribute value is validated because it matches the attribute value with (id). For example, use the function name onAttributeValueID_5 if you want the function to execute when an attribute value is validated with the attribute value that has an ID of 5 in the configuration. (New v10.9913)

onCommentHTML()

This function is called for every HTML/XHTML comment. This function can be used to setup your own custom validation directives using standard HTML comments. (New v10.9921)

$commentstring - the contents of the HTML comment, excluding the angle brackets; for example, if the comment is <!--test-->, then $commentstring will be "!--test--"

Example:

function onHTMLComment() {
 MessageEx(13|1024,2011083000,MSG_COMMENT,'HTML comment: '+$commentstring);
 if beginsWithCase($commentstring,"!--SETMYOPTION_") {
  if matchCase($commentstring,"!--SETMYOPTION_EXTRACHECKING--") {
   #myoption_extrachecking=true;
   MessageEx(13|1024,2011083001,MSG_COMMENT,'Extra checking enabled!');
  }
  else { if matchCase($commentstring,"!--SETMYOPTION_LOOSECHECKING--") {
   #myoption_loosechecking=true;
   MessageEx(13|1024,2011083002,MSG_COMMENT,'Loose checking enabled!');
  }}
 }
}

onConfigLoad()

This function is called when a configuration is loaded.

Some things that can be done in this function:

setValueString(10,typeface) - recognize typeface as a "web-safe" typeface; can specify multiple typefaces

setValueString(11,typeface) - recognize typeface as a valid typeface so they won't be unknown; can specify multiple typefaces

setValueString(21,excludewords) - additional words to exclude from the search engine keyword density message

See the setValueString() function for more options.

Example:

function onConfigLoad() {
 // add words to exclude from the search engine keyword density message
 setValueString(21,"apple,orange");
 
 // recognize the following typefaces as "web-safe"
 setValueString(10,"Titillium","ubuntu-title","Bebas","Cantarell");
 
 // recognize the following typefaces as valid
 setValueString(11,"Titillium","ubuntu-title","Bebas","Cantarell");
}

onConfigLoad2()

This is like the onConfigLoad() function, but it is run after onConfigLoad(). New validation modes should be added here to avoid out-of-order problems with those set in the onConfigLoad() function of the main config file.

Example:

function onConfigLoad2() {
 // add a new job subtype/validation mode
 setValueString(2,"My Validation Mode");
}

onCSSInvalidValueMessage()

This function is called when an error is being generated because of an invalid CSS property value. This function can be used to ignore certain property values and/or to change or display additional messages when certain unknown property values are used. The following variables are defined when this function is called and may be modified before the validator message is displayed: (New v10.9922)

$oicvm_property - the name of the CSS property with the invalid value

$oicvm_value - the invalid CSS property value

$oicvm_msgtext - the message text of the validator message that will be generated

$oicvm_msgcat - the message category of the validator message that will be generated; the default is "General"

$oicvm_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$oicvm_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$oicvm_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR

onDocTypeFlagsChange()

This function is called when doctypeflags changes, either by encountering a DOCTYPE in the document or when programmatically changed. (New v9.9913)

onEndingValidation()

This function runs near the end of a validation, but before running other checkers like HTML Tidy, nsgmls, the PHP syntax checker, and the JavaScript linter, and before the end validation program is run. (New v10.9912)

onEndTag_(tagname)()

Replace (tagname) with the actual tag name. When an end tag with that tagname is encountered, this function is executed after any other end tag programs assigned to the element. For example, use the function name onEndTag_textarea if you want the function to execute when a "textarea" end tag is encountered. (New v10.9912)

onEndTagImpliedFromEndTag()

This function is executed when an implied end tag is encountered due to an explicit end tag. NOTE: Never called for XML (XHTML) based documents because all end tags should be explicit. (New v10.9924)

Use CurrentParentTagName to get the element name that is being ended by the implied end tag.

onEndTagImpliedFromStartTag()

This function is executed when an implied end tag is encountered due to an explicit start tag. NOTE: Never called for XML (XHTML) based documents because all end tags should be explicit. (New v10.9924)

onEndTagPre_(tagname)()

Replace (tagname) with the actual tag name. When an end tag with tagname is encountered, this function is executed before the tag is added to the document structure. (New v10.9914)

onInvalidAttValueMessage()

This function is called when the default invalid attribute value message is about to be generated; this function can be used to ignore unknown attribute values and/or to change or display additional messages when certain unknown attribute values are used. The following variables are defined when this function is called and may be modified before the validator message is displayed: (New v11.0047)

CurrentAttName - the name of the attribute

CurrentAttValue - the attribute value that is invalid

$oiavm_msgtext - the message text of the validator message that will be generated

$oiavm_msgtextappend - an additional message that is appended to the end of $oiavm_msgtext; the default (if extended message info is enabled) is what the value may be, else an empty string

$oiavm_msgtextprepend - an additional message that is prepended to the front of $oiavm_msgtext; the default is an empty string

$oiavm_msgcat - the message category of the validator message that will be generated; the default is "" for no category

$oiavm_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$oiavm_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$oiavm_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR

onKeywordDensityStart()

The function is called before beginning to generate the keyword density message.

$okds_excludewords - set to a comma separated list of words to exclude in the keyword density message; words are case-insensitive

Example:

// if the html tag indicates a German document, then change the excluded words to German 
function onKeywordDensityStart() {
 if isDefined("htmllangvalue") {
  if matchNoCase($htmllangvalue,"de") {
   $okds_excludewords="ab,aber,alle,allen,alles,als,am,an,auch,auf,aus,bei,beide,beim,bekam,bis,bisher,da,dabei,dann,das,dass,daß,dein,deine,dem,den,der,des,dich,die,diese,diesem,diesen,dieser,dieses,dir,doch,du,durch,e,ein,eine,einem,einen,einer,eines,er,es,etc,etwas,euch,für,ganz,gibt,haben,hast,hat,hier,ich,ihr,im,immer,in,ist,kann,keine,können,konnte,man,mehr,mich,mir,mit,nach,nächste,nicht,noch,nur,oder,schon,sehr,sein,sich,sie,sind,so,über,um,und,uns,unser,unsere,unserer,viel,viele,vom,von,vor,vorher,vorherige,vorherigen,war,waren,was,weg,weil,weiter,weiteren,wenn,werden,wie,wieder,wir,wird,wo,wurde,wurden,zu,zum,zur,zurück";
  }
 }
}

onKeywordDensityWord()

The function is called when generating the keyword density message. It's called for each word that can potentially be included in the message.

$okdw_exclude - set to true to exclude the word or false to include the word in the keyword density message; the default may be true or false, depending on whether the word is in the exclude list

$okdw_word - the word under consideration

Example:

// exclude numbers and words ending in ".com" (case insensitive)
function onKeywordDensityWord() {
 if matchRegEx("^\d+$",0,$okdw_word) { #okdw_exclude=true; }
 else if matchRegEx("\.com$",1,$okdw_word) { #okdw_exclude=true; }
}

onMessageID_(msgid)()

Replace (msgid) with the actual message ID. When a message is generated with the specified message ID, this function is executed. For example, use the function name onMessageID_1020715192 if you want the function to execute when a message with message ID 1020715192 is being generated. This function can be used to cancel a message or to change it. (New v10.9912)

$omid_cancel - set this to true to cancel the message

$omid_msgid - the message ID of the validator message that is being generated

$omid_msgtext - the message text of the validator message that is being generated

$omid_msgtype - the message type of the validator message that is being generated

NOTE: This function is executed before the message ID configuration is checked.

onMisspelledWord()

The function is called when generating the misspelled word message. It's called for each word that can potentially be included in the message.

$omw_exclude - set to true to exclude the word or false to include the word in the misspelled word message; the default is false

$omw_word - the word under consideration

Example:

// exclude words ending in ".com" (case insensitive)
function onMisspelledWord() {
 if matchRegEx("\.com$",1,$omw_word) { #omw_exclude=true; }
}

onStartTag_(tagname)()

Replace (tagname) with the actual tag name. When a start tag with the tagname is encountered, this function is executed after any other start tag programs assigned to the element. For example, use the function name onStartTag_textarea if you want the function to execute when a "textarea" start tag is encountered. (New v10.9912)

Example:

function onStartTag_h1() {
 #h1tagcounter++;
 Message(1,$MSG_MESSAGE,'This is "h1" element #'+$h1tagcounter);
}

onStartTagPre_(tagname)()

Replace (tagname) with the actual tag name. When a start tag with tagname is encountered, this function is executed before the tag is added to the document structure. (New v10.9914)

onStartTagFirst()

This function is called before any start tag programs are run for the first start tag in the document. Useful for simulating a DOCTYPE or setting options based on any preceeding DOCTYPE. (New v10.9914)

onStartValidation()

This function runs after the start validation program. (New v10.9912)

Example:

function onStartValidation() {
 if matchNoCase(CSEJOBSUBTYPESTRING,"My Validation Mode") {
  #enablemycheck=true;
  // set more variables here for "My Validation Mode" jobs
 }
 else {
  #enablemycheck=false;
 }
}

onTextHTML()

This function is run when a node of non-whitespace text is encountered in an HTML/XHTML type document. (New v11.0000)

onTool_QuoteAttVal_Value()

This function executes for every attribute value being processed by the Quick Quote Attribute Values Tool. It allows attribute value modification, like search & replace operations with the replaceString[No]Case() functions. (New v10.9914)

$attvalue - the attribute value (not including any enclosing quotation marks)

$quotechar - the quotation character to surround the attribute value in (default is the double quote character)

Example:

// When using the Quick Quote Attribute Values Tool, convert
// some characters to character references.
function onTool_QuoteAttVal_Value() {
 $attvalue=replaceStringCase($attvalue,'<','&lt;');
 $attvalue=replaceStringCase($attvalue,'"','&quot;');
 $attvalue=replaceStringCase($attvalue,'\'','&apos;');
}

onUnknownCSSPropertyMessage()

This function is called when a CSS property is unknown and a validator error message is about to be generated; this function can be used to ignore unknown CSS properties and/or to change or display additional messages when certain unknown CSS properties are used; the following variables are defined when this function is called and may be modified before the validator message is displayed: (New v7.9910)

$oucpm_property - the name of the unknown CSS property

$oucpm_msgtext - the message text of the validator message that will be generated

$oucpm_msgcat - the message category of the validator message that will be generated

$oucpm_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$oucpm_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$oucpm_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR

onUnknownAttributeMessage()

This function is called when an attribute is unknown and a validator error message is about to be generated; this function can be used to ignore unknown attributes and/or to change or display additional messages when certain unknown attributes are used. The following variables are defined when this function is called and may be modified before the validator message is displayed: (New v10.9912)

$ouam_attname - the name of the unknown attribute

$ouam_msgtext - the message text of the validator message that will be generated

$ouam_msgtextappend - an additional message that is appended to the end of $ouam_msgtext

$ouam_msgtextprepend - an additional message that is prepended to the front of $ouam_msgtext; the default is an empty string

$ouam_msgcat - the message category of the validator message that will be generated; the default is "" for no category

$ouam_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$ouam_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$ouam_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR

onUnknownElementMessage()

This function is called when an HTML/XHTML element is unknown and a validator error message is about to be generated; this function can be used to ignore unknown elements and/or to change or display additional messages when certain unknown elements are used; the following variables are defined when this function is called and may be modified before the validator message is displayed: (New v7.9910)

$ouem_element - the name of the unknown element

$ouem_msgtext - the message text of the validator message that will be generated

$ouem_msgtextappend - an additional message that is appended to the end of $ouem_msgtext; the default is " Did you misspell it?"

$ouem_msgtextprepend - an additional message that is prepended to the front of $ouem_msgtext; the default is an empty string (New v8.0100)

$ouem_msgcat - the message category of the validator message that will be generated; the default is "" for no category

$ouem_msgflags - the message flags value used when calling MessageEx() to generate the message; set to 0 to cancel the message

$ouem_msgid - the message ID of the validator message that will be generated; the default is -1 for no message ID

$ouem_msgtype - the message type of the validator message that will be generated; the default is $MSG_ERROR