[ Index ]

Source Code Reference for V1.00

title

Body

[close]

/lib/xajax/xajax_controls/ -> validate_XHTML10TRANSITIONAL.inc.php (source)

   1  <?php
   2  
   3  $aAttributes = array(
   4      '%coreattrs' => array(
   5          'id',
   6          'class',
   7          'style',
   8          'title'
   9          ),
  10      '%i18n' => array(
  11          'lang',
  12          'xml:lang',
  13          'dir'
  14          ),
  15      '%events' => array(
  16          'onclick',
  17          'ondblclick',
  18          'onmousedown',
  19          'onmouseup',
  20          'onmouseover',
  21          'onmousemove',
  22          'onmouseout',
  23          'onkeypress',
  24          'onkeydown',
  25          'onkeyup'
  26          ),
  27      '%focus' => array(
  28          'accesskey',
  29          'tabindex',
  30          'onfocus',
  31          'onblur'
  32          ),
  33      '%attrs' => array(
  34          '%coreattrs',
  35          '%i18n',
  36          '%events'
  37          ),
  38      '%TextAlign' => array('align'),
  39      'html' => array(
  40          '%i18n',
  41          'id',
  42          'xmlns'
  43          ),
  44      'head' => array(
  45          '%i18n',
  46          'id',
  47          'profile'
  48          ),
  49      'title' => array(
  50          '%i18n',
  51          'id'
  52          ),
  53      'base' => array(
  54          'id',
  55          'href',
  56          'target'
  57          ),
  58      'meta' => array(
  59          '%i18n',
  60          'id',
  61          'http-equiv',
  62          'name',
  63          'content',
  64          'scheme'
  65          ),
  66      'link' => array(
  67          '%attrs',
  68          'charset',
  69          'href',
  70          'hreflang',
  71          'type',
  72          'rel',
  73          'rev',
  74          'media',
  75          'target'
  76          ),
  77      'style' => array(
  78          '%i18n',
  79          'id',
  80          'type',
  81          'media',
  82          'title',
  83          'xml:space'
  84          ),
  85      'script' => array(
  86          'id',
  87          'charset',
  88          'type',
  89          'language',
  90          'src',
  91          'defer',
  92          'xml:space'
  93          ),
  94      'noscript' => array('%attrs'),
  95      'iframe' => array(
  96          '%coreattrs',
  97          'longdesc',
  98          'name',
  99          'src',
 100          'frameborder',
 101          'marginwidth',
 102          'marginheight',
 103          'scrolling',
 104          'align',
 105          'height',
 106          'width'
 107          ),
 108      'noframes' => array('%attrs'),
 109      'body' => array(
 110          '%attrs',
 111          'onload',
 112          'onunload',
 113          'background',
 114          'bgcolor',
 115          'text',
 116          'link',
 117          'vlink',
 118          'alink'
 119          ),
 120      'div' => array(
 121          '%attrs',
 122          '%TextAlign'
 123          ),
 124      'p' => array(
 125          '%attrs',
 126          '%TextAlign'
 127          ),
 128      'h1' => array(
 129          '%attrs',
 130          '%TextAlign'
 131          ),
 132      'h2' => array(
 133          '%attrs',
 134          '%TextAlign'
 135          ),
 136      'h3' => array(
 137          '%attrs',
 138          '%TextAlign'
 139          ),
 140      'h4' => array(
 141          '%attrs',
 142          '%TextAlign'
 143          ),
 144      'h5' => array(
 145          '%attrs',
 146          '%TextAlign'
 147          ),
 148      'h6' => array(
 149          '%attrs',
 150          '%TextAlign'
 151          ),
 152      'ul' => array(
 153          '%attrs',
 154          'type',
 155          'compact'
 156          ),
 157      'ol' => array(
 158          '%attrs',
 159          'type',
 160          'compact',
 161          'start'
 162          ),
 163      'menu' => array(
 164          '%attrs',
 165          'compact'
 166          ),
 167      'dir' => array(
 168          '%attrs',
 169          'compact'
 170          ),
 171      'li' => array(
 172          '%attrs',
 173          'type',
 174          'value'
 175          ),
 176      'dl' => array(
 177          '%attrs',
 178          'compact'
 179          ),
 180      'dt' => array('%attrs'),
 181      'dd' => array('%attrs'),
 182      'address' => array(
 183          '%attrs'
 184          ),
 185      'hr' => array(
 186          '%attrs',
 187          'align',
 188          'noshade',
 189          'size',
 190          'width'
 191          ),
 192      'pre' => array(
 193          '%attrs',
 194          'width',
 195          'xml:space'
 196          ),
 197      'blockquote' => array(
 198          '%attrs',
 199          'cite'
 200          ),
 201      'center' => array('%attrs'),
 202      'ins' => array(
 203          '%attrs',
 204          'cite',
 205          'datetime'
 206          ),
 207      'del' => array(
 208          '%attrs',
 209          'cite',
 210          'datetime'
 211          ),
 212      'a' => array(
 213          '%attrs',
 214          '%focus',
 215          'charset',
 216          'type',
 217          'name',
 218          'href',
 219          'hreflang',
 220          'rel',
 221          'rev',
 222          'shape',
 223          'coords',
 224          'target'
 225          ),
 226      'span' => array('%attrs'),
 227      'bdo' => array(
 228          '%coreattrs',
 229          '%events',
 230          'lang',
 231          'xml:lang',
 232          'dir'
 233          ),
 234      'br' => array(
 235          '%coreattrs',
 236          'clear'
 237          ),
 238      'em' => array('%attrs'),
 239      'strong' => array('%attrs'),
 240      'dfn' => array('%attrs'),
 241      'code' => array('%attrs'),
 242      'samp' => array('%attrs'),
 243      'kbd' => array('%attrs'),
 244      'var' => array('%attrs'),
 245      'cite' => array('%attrs'),
 246      'abbr' => array('%attrs'),
 247      'acronym' => array('%attrs'),
 248      'q' => array('%attrs','cite'),
 249      'sub' => array('%attrs'),
 250      'sup' => array('%attrs'),
 251      'tt' => array('%attrs'),
 252      'i' => array('%attrs'),
 253      'b' => array('%attrs'),
 254      'big' => array('%attrs'),
 255      'small' => array('%attrs'),
 256      'u' => array('%attrs'),
 257      's' => array('%attrs'),
 258      'strike' => array('%attrs'),
 259      'basefont' => array(
 260          'id',
 261          'size',
 262          'color',
 263          'face'
 264          ),
 265      'font' => array(
 266          '%coreattrs',
 267          '%i18n',
 268          'size',
 269          'color',
 270          'face'
 271          ),
 272      'object' => array(
 273          '%attrs',
 274          'declare',
 275          'classid',
 276          'codebase',
 277          'data',
 278          'type',
 279          'codetype',
 280          'archive',
 281          'standby',
 282          'height',
 283          'width',
 284          'usemap',
 285          'name',
 286          'tabindex',
 287          'align',
 288          'border',
 289          'hspace',
 290          'vspace'
 291          ),
 292      'param' => array(
 293          'id',
 294          'name',
 295          'value',
 296          'valuetype',
 297          'type'
 298          ),
 299      'applet' => array(
 300          '%coreattrs',
 301          'codebase',
 302          'archive',
 303          'code',
 304          'object',
 305          'alt',
 306          'name',
 307          'width',
 308          'height',
 309          'align',
 310          'hspace',
 311          'vspace'
 312          ),
 313      'img' => array(
 314          '%attrs',
 315          'src',
 316          'alt',
 317          'name',
 318          'longdesc',
 319          'height',
 320          'width',
 321          'usemap',
 322          'ismap',
 323          'align',
 324          'border',
 325          'hspace',
 326          'vspace'
 327          ),
 328      'map' => array(
 329          '%i18n',
 330          '%events',
 331          'id',
 332          'class',
 333          'style',
 334          'title',
 335          'name'
 336          ),
 337      'area' => array(
 338          '%attrs',
 339          '%focus',
 340          'shape',
 341          'coords',
 342          'href',
 343          'nohref',
 344          'alt',
 345          'target'
 346          ),
 347      'form' => array(
 348          '%attrs',
 349          'action',
 350          'method',
 351          'name',
 352          'enctype',
 353          'onsubmit',
 354          'onreset',
 355          'accept',
 356          'accept-charset',
 357          'target'
 358          ),
 359      'label' => array(
 360          '%attrs',
 361          'for',
 362          'accesskey',
 363          'onfocus',
 364          'onblur'
 365          ),
 366      'input' => array(
 367          '%attrs',
 368          '%focus',
 369          'type',
 370          'name',
 371          'value',
 372          'checked',
 373          'disabled',
 374          'readonly',
 375          'size',
 376          'maxlength',
 377          'src',
 378          'alt',
 379          'usemap',
 380          'onselect',
 381          'onchange',
 382          'accept',
 383          'align'
 384          ),
 385      'select' => array(
 386          '%attrs',
 387          'name',
 388          'size',
 389          'multiple',
 390          'disabled',
 391          'tabindex',
 392          'onfocus',
 393          'onblur',
 394          'onchange'
 395          ),
 396      'optgroup' => array(
 397          '%attrs',
 398          'disabled',
 399          'label'
 400          ),
 401      'option' => array(
 402          '%attrs',
 403          'selected',
 404          'disabled',
 405          'label',
 406          'value'
 407          ),
 408      'textarea' => array(
 409          '%attrs',
 410          '%focus',
 411          'name',
 412          'rows',
 413          'cols',
 414          'disabled',
 415          'readonly',
 416          'onselect',
 417          'onchange'
 418          ),
 419      'fieldset' => array('%attrs'),
 420      'legend' => array(
 421          '%attrs',
 422          'accesskey',
 423          'align'
 424          ),
 425      'button' => array(
 426          '%attrs',
 427          '%focus',
 428          'name',
 429          'value',
 430          'type',
 431          'disabled'
 432          ),
 433      'isindex' => array(
 434          '%coreattrs',
 435          '%i18n',
 436          'prompt'
 437          ),
 438      'table' => array(
 439          '%attrs',
 440          'summary',
 441          'width',
 442          'border',
 443          'frame',
 444          'rules',
 445          'cellspacing',
 446          'cellpadding',
 447          'align',
 448          'bgcolor'
 449          ),
 450      'caption' => array(
 451          '%attrs',
 452          'align'
 453          ),
 454      'colgroup' => array(
 455          '%attrs',
 456          'span',
 457          'width',
 458          '%cellhalign',
 459          '%cellvalign'
 460          ),
 461      'col' => array(
 462          '%attrs',
 463          'span',
 464          'width',
 465          '%cellhalign',
 466          '%cellvalign'
 467          ),
 468      'thead' => array(
 469          '%attrs',
 470          '%cellhalign',
 471          '%cellvalign'
 472          ),
 473      'tfoot' => array(
 474          '%attrs',
 475          '%cellhalign',
 476          '%cellvalign'
 477          ),
 478      'tbody' => array(
 479          '%attrs',
 480          '%cellhalign',
 481          '%cellvalign'
 482          ),
 483      'tr' => array(
 484          '%attrs',
 485          '%cellhalign',
 486          '%cellvalign',
 487          'bgcolor'
 488          ),
 489      'th' => array(
 490          '%attrs',
 491          'abbr',
 492          'axis',
 493          'headers',
 494          'scope',
 495          'rowspan',
 496          'colspan',
 497          '%cellhalign',
 498          '%cellvalign',
 499          'nowrap',
 500          'bgcolor',
 501          'width',
 502          'height'
 503          ),
 504      'td' => array(
 505          '%attrs',
 506          'abbr',
 507          'axis',
 508          'headers',
 509          'scope',
 510          'rowspan',
 511          'colspan',
 512          '%cellhalign',
 513          '%cellvalign',
 514          'nowrap',
 515          'bgcolor',
 516          'width',
 517          'height'
 518          ),
 519      );
 520  
 521  
 522  $aTags = array(
 523      '%special.extra' => array(
 524          'object',
 525          'applet',
 526          'img',
 527          'map',
 528          'iframe'
 529          ),
 530      '%special.basic' => array(
 531          'br',
 532          'span',
 533          'bdo'
 534          ),
 535      '%special' => array(
 536          '%special.basic',
 537          '%special.extra'
 538          ),
 539      '%fontstyle.extra' => array(
 540          'big',
 541          'small',
 542          'font',
 543          'basefont'
 544          ),
 545      '%fontstyle.basic' => array(
 546          'tt',
 547          'i',
 548          'b',
 549          'u',
 550          's',
 551          'strike'
 552          ),
 553      '%fontstyle' => array(
 554          '%fontstyle.basic',
 555          '%fontstyle.extra'
 556          ),
 557      '%phrase.extra' => array(
 558          'sub',
 559          'sup'
 560          ),
 561      '%phrase.basic' => array(
 562          'em',
 563          'strong',
 564          'dfn',
 565          'code',
 566          'q',
 567          'samp',
 568          'kbd',
 569          'var',
 570          'cite',
 571          'abbr',
 572          'acronym'
 573          ),
 574      '%phrase' => array(
 575          '%phrase.basic',
 576          '%phrase.extra'
 577          ),
 578      '%inline.forms' => array(
 579          'input',
 580          'select',
 581          'textarea',
 582          'label',
 583          'button'
 584          ),
 585      '%misc.inline' => array(
 586          'ins',
 587          'del',
 588          'script'
 589          ),
 590      '%misc' => array(
 591          'noscript',
 592          '%misc.inline'
 593          ),
 594      '%inline' => array(
 595          'a',
 596          '%special',
 597          '%fontstyle',
 598          '%phrase',
 599          '%inline.forms'
 600          ),
 601      '%Inline' => array(
 602          'cdata',
 603          '%inline',
 604          '%misc.inline'
 605          ),
 606      '%heading' => array(
 607          'h1',
 608          'h2',
 609          'h3',
 610          'h4',
 611          'h5',
 612          'h6'
 613          ),
 614      '%lists' => array(
 615          'ul',
 616          'ol',
 617          'dl',
 618          'menu',
 619          'dir'
 620          ),
 621      '%blocktext' => array(
 622          'pre',
 623          'hr',
 624          'blockquote',
 625          'address',
 626          'center',
 627          'noframes'
 628          ),
 629      '%block' => array(
 630          'p',
 631          '%heading',
 632          'div',
 633          '%lists',
 634          '%blocktext',
 635          'isindex',
 636          'fieldset',
 637          'table'
 638          ),
 639      '%Flow' => array(
 640          'cdata',
 641          '%block',
 642          'form',
 643          '%inline',
 644          '%misc'
 645          ),
 646      '%a.content' => array(
 647          'cdata',
 648          '%special',
 649          '%fontstyle',
 650          '%phrase',
 651          '%inline.forms',
 652          '%misc.inline'
 653          ),
 654      '%pre.content' => array(
 655          'cdata',
 656          'a',
 657          '%special.basic',
 658          '%fontstyle.basic',
 659          '%phrase.basic',
 660          '%inline.forms',
 661          '%misc.inline'
 662          ),
 663      '%form.content' => array(
 664          'cdata',
 665          '%block',
 666          '%inline',
 667          '%misc'
 668          ),
 669      '%button.content' => array(
 670          'cdata',
 671          'p',
 672          '%heading',
 673          'div',
 674          '%lists',
 675          '%blocktext',
 676          'table',
 677          'br',
 678          'span',
 679          'bdo',
 680          'object',
 681          'applet',
 682          'img',
 683          'map',
 684          '%fontstyle',
 685          '%phrase',
 686          '%misc'
 687          ),
 688      '%head.misc' => array(
 689          'script',
 690          'style',
 691          'meta',
 692          'link',
 693          'object'
 694          ),
 695      'html' => array(
 696          'head',
 697          'body'
 698          ),
 699      'head' => array(
 700          '%head.misc',
 701          'title',
 702          'base'
 703          ),
 704      'title' => array('cdata'),
 705      'base' => array(),
 706      'meta' => array(),
 707      'link' => array(),
 708      'style' => array('cdata'),
 709      'script' => array('cdata'),
 710      'noscript' => array('%Flow'),
 711      'iframe' => array('%Flow'),
 712      'noframes' => array('%Flow'),
 713      'body' => array('%Flow'),
 714      'div' => array('%Flow'),
 715      'p' => array('%Inline'),
 716      'h1' => array('%Inline'),
 717      'h2' => array('%Inline'),
 718      'h3' => array('%Inline'),
 719      'h4' => array('%Inline'),
 720      'h5' => array('%Inline'),
 721      'h6' => array('%Inline'),
 722      'ul' => array('li'),
 723      'ol' => array('li'),
 724      'menu' => array('li'),
 725      'dir' => array('li'),
 726      'li' => array('%Flow'),
 727      'dl' => array(
 728          'dt',
 729          'dd'
 730          ),
 731      'dt' => array('%Inline'),
 732      'dd' => array('%Flow'),
 733      'address' => array('cdata', '%inline', '%misc.inline', 'p'),
 734      'hr' => array(),
 735      'pre' => array('%pre.content'),
 736      'blockquote' => array('%Flow'),
 737      'center' => array('%Flow'),
 738      'ins' => array('%Flow'),
 739      'del' => array('%Flow'),
 740      'a' => array('%a.content'),
 741      'span' => array('%Inline'),
 742      'bdo' => array('%Inline'),
 743      'br' => array(),
 744      'em' => array('%Inline'),
 745      'strong' => array('%Inline'),
 746      'dfn' => array('%Inline'),
 747      'code' => array('%Inline'),
 748      'samp' => array('%Inline'),
 749      'kbd' => array('%Inline'),
 750      'var' => array('%Inline'),
 751      'cite' => array('%Inline'),
 752      'abbr' => array('%Inline'),
 753      'acronym' => array('%Inline'),
 754      'q' => array('%Inline'),
 755      'sub' => array('%Inline'),
 756      'sup' => array('%Inline'),
 757      'tt' => array('%Inline'),
 758      'i' => array('%Inline'),
 759      'b' => array('%Inline'),
 760      'big' => array('%Inline'),
 761      'small' => array('%Inline'),
 762      'u' => array('%Inline'),
 763      's' => array('%Inline'),
 764      'strike' => array('%Inline'),
 765      'basefont' => array(),
 766      'font' => array('%Inline'),
 767      'object' => array(
 768          'cdata',
 769          'param',
 770          '%block',
 771          'form',
 772          '%inline',
 773          '%misc'
 774          ),
 775      'param' => array(),
 776      'applet' => array(
 777          'cdata',
 778          'param',
 779          '%block',
 780          'form',
 781          '%inline',
 782          '%misc'
 783          ),
 784      'img' => array(),
 785      'map' => array(
 786          '%block',
 787          'form',
 788          '%misc',
 789          'area'
 790          ),
 791      'area' => array(),
 792      'form' => array('%form.content'),
 793      'label' => array('%Inline'),
 794      'input' => array(),
 795      'select' => array('optgroup','option'),
 796      'optgroup' => array('option'),
 797      'option' => array('cdata'),
 798      'textarea' => array('cdata'),
 799      'fieldset' => array('cdata','legend','%block','form','%inline','%misc'),
 800      'legend' => array('%Inline'),
 801      'button' => array('%button.content'),
 802      'isindex' => array(),
 803      'table' => array('caption','col','colgroup','thead','tfoot','tbody','tr'),
 804      'caption' => array('%Inline'),
 805      'thead' => array('tr'),
 806      'tfoot' => array('tr'),
 807      'tbody' => array('tr'),
 808      'colgroup' => array('col'),
 809      'col' => array(),
 810      'tr' => array('th','td'),
 811      'th' => array('%Flow'),
 812      'td' => array('%Flow'),
 813      'document' => array(
 814          'doctype',
 815          'html'
 816          ),
 817      'doctype' => array(
 818          'cdata'
 819          )
 820      );
 821  
 822  $aRequiredAttributes = array(
 823      'html' => array(
 824          'xmlns',
 825          'xml:lang',
 826          'lang'
 827          ),
 828      'style' => array('type'),
 829      'script' => array('type'),
 830      'meta' => array('content'),
 831      'optgroup' => array('label'),
 832      'textarea' => array('rows', 'cols'),
 833      'img' => array('src', 'alt')
 834      );
 835  
 836  class clsValidator
 837  {
 838      var $aTags;
 839      var $aAttributes;
 840      var $aRequiredAttributes;
 841      
 842  	function clsValidator()
 843      {
 844          global $aTags;
 845          global $aAttributes;
 846          global $aRequiredAttributes;
 847          
 848          $this->aTags = array();
 849          $this->aAttributes = array();
 850          $this->aRequiredAttributes = array();
 851          
 852          foreach (array_keys($aTags) as $sTag)
 853          {
 854              $this->aTags[$sTag] = array();
 855              $this->_expand($this->aTags[$sTag], $aTags[$sTag], $aTags);
 856          }
 857          
 858          foreach (array_keys($aAttributes) as $sAttribute)
 859          {
 860              $this->aAttributes[$sAttribute] = array();
 861              $this->_expand($this->aAttributes[$sAttribute], $aAttributes[$sAttribute], $aAttributes);
 862          }
 863          
 864          foreach (array_keys($aRequiredAttributes) as $sElement)
 865          {
 866              $this->aRequiredAttributes[$sElement] = array();
 867              $this->_expand($this->aRequiredAttributes[$sElement], $aRequiredAttributes[$sElement], $aRequiredAttributes);
 868          }
 869      }
 870      
 871      function &getInstance()
 872      {
 873          static $obj;
 874          if (!$obj) {
 875              $obj = new clsValidator();
 876          }
 877          return $obj;
 878      }
 879      
 880  	function _expand(&$aDestination, &$aSource, &$aDictionary)
 881      {
 882          foreach ($aSource as $sChild)
 883          {
 884              if ('%' == substr($sChild, 0, 1))
 885                  $this->_expand($aDestination, $aDictionary[$sChild], $aDictionary);
 886              else
 887                  $aDestination[] = $sChild;
 888          }
 889      }
 890      
 891  	function elementValid($sElement)
 892      {
 893          return isset($this->aTags[strtolower($sElement)]);
 894      }
 895      
 896  	function attributeValid($sElement, $sAttribute)
 897      {
 898          if (false == isset($this->aAttributes[strtolower($sElement)]))
 899              return false;
 900          return in_array(strtolower($sAttribute), $this->aAttributes[strtolower($sElement)]);
 901      }
 902      
 903  	function childValid($sParent, $sElement)
 904      {
 905          if (false == isset($this->aTags[strtolower($sParent)]))
 906              return false;
 907          return in_array(strtolower($sElement), $this->aTags[strtolower($sParent)]);
 908      }
 909      
 910      // verify that required attributes have been specified
 911  	function checkRequiredAttributes($sElement, &$aAttributes, &$sMissing)
 912      {
 913          if (isset($this->aRequiredAttributes[strtolower($sElement)]))
 914              foreach ($this->aRequiredAttributes[strtolower($sElement)] as $sRequiredAttribute)
 915                  if (false == isset($aAttributes[$sRequiredAttribute]))
 916                  {
 917                      $sMissing = $sRequiredAttribute;
 918                      return false;
 919                  }
 920  
 921          return true;
 922      }
 923  }


Generated: Thu Jan 8 03:00:03 2009 Cross-referenced by PHPXref 0.7