Source for file ID.php

Documentation is available at ID.php

  1. <?php
  2.  
  3. /**
  4.  * Validates the HTML attribute ID.
  5.  * @warning Even though this is the id processor, it
  6.  *           will ignore the directive Attr:IDBlacklist, since it will only
  7.  *           go according to the ID accumulator. Since the accumulator is
  8.  *           automatically generated, it will have already absorbed the
  9.  *           blacklist. If you're hacking around, make sure you use load()!
  10.  */
  11.  
  12. {
  13.     
  14.     // ref functionality disabled, since we also have to verify
  15.     // whether or not the ID it refers to exists
  16.     
  17.     public function validate($id$config$context{
  18.         
  19.         if (!$config->get('Attr''EnableID')) return false;
  20.         
  21.         $id trim($id)// trim it first
  22.         
  23.         if ($id === ''return false;
  24.         
  25.         $prefix $config->get('Attr''IDPrefix');
  26.         if ($prefix !== ''{
  27.             $prefix .= $config->get('Attr''IDPrefixLocal');
  28.             // prevent re-appending the prefix
  29.             if (strpos($id$prefix!== 0$id $prefix $id;
  30.         elseif ($config->get('Attr''IDPrefixLocal'!== ''{
  31.             trigger_error('%Attr.IDPrefixLocal cannot be used unless '.
  32.                 '%Attr.IDPrefix is set'E_USER_WARNING);
  33.         }
  34.         
  35.         //if (!$this->ref) {
  36.             $id_accumulator =$context->get('IDAccumulator');
  37.             if (isset($id_accumulator->ids[$id])) return false;
  38.         //}
  39.         
  40.         // we purposely avoid using regex, hopefully this is faster
  41.         
  42.         if (ctype_alpha($id)) {
  43.             $result true;
  44.         else {
  45.             if (!ctype_alpha(@$id[0])) return false;
  46.             $trim trim// primitive style of regexps, I suppose
  47.                 $id,
  48.                 'A..Za..z0..9:-._'
  49.               );
  50.             $result ($trim === '');
  51.         }
  52.         
  53.         $regexp $config->get('Attr''IDBlacklistRegexp');
  54.         if ($regexp && preg_match($regexp$id)) {
  55.             return false;
  56.         }
  57.         
  58.         if (/*!$this->ref && */$result$id_accumulator->add($id);
  59.         
  60.         // if no change was made to the ID, return the result
  61.         // else, return the new id if stripping whitespace made it
  62.         //     valid, or return false.
  63.         return $result $id false;
  64.         
  65.     }
  66.     
  67. }

Documentation generated on Thu, 19 Jun 2008 18:49:36 -0400 by phpDocumentor 1.4.2