Index: trunk/phase3/includes/Xml.php |
— | — | @@ -360,7 +360,7 @@ |
361 | 361 | public static function label( $label, $id, $attribs = array() ) { |
362 | 362 | $a = array( 'for' => $id ); |
363 | 363 | |
364 | | - # FIXME avoid copy pasting below: |
| 364 | + # FIXME avoid copy pasting below: |
365 | 365 | if( isset( $attribs['class'] ) ){ |
366 | 366 | $a['class'] = $attribs['class']; |
367 | 367 | } |
— | — | @@ -506,19 +506,24 @@ |
507 | 507 | $optgroup = false; |
508 | 508 | } |
509 | 509 | } |
| 510 | + |
510 | 511 | if( $optgroup ) $options .= self::closeElement('optgroup'); |
511 | 512 | |
512 | 513 | $attribs = array(); |
| 514 | + |
513 | 515 | if( $name ) { |
514 | 516 | $attribs['id'] = $name; |
515 | 517 | $attribs['name'] = $name; |
516 | 518 | } |
| 519 | + |
517 | 520 | if( $class ) { |
518 | 521 | $attribs['class'] = $class; |
519 | 522 | } |
| 523 | + |
520 | 524 | if( $tabindex ) { |
521 | 525 | $attribs['tabindex'] = $tabindex; |
522 | 526 | } |
| 527 | + |
523 | 528 | return Xml::openElement( 'select', $attribs ) |
524 | 529 | . "\n" |
525 | 530 | . $options |
— | — | @@ -537,9 +542,11 @@ |
538 | 543 | */ |
539 | 544 | public static function fieldset( $legend = false, $content = false, $attribs = array() ) { |
540 | 545 | $s = Xml::openElement( 'fieldset', $attribs ) . "\n"; |
| 546 | + |
541 | 547 | if ( $legend ) { |
542 | 548 | $s .= Xml::element( 'legend', null, $legend ) . "\n"; |
543 | 549 | } |
| 550 | + |
544 | 551 | if ( $content !== false ) { |
545 | 552 | $s .= $content . "\n"; |
546 | 553 | $s .= Xml::closeElement( 'fieldset' ) . "\n"; |
— | — | @@ -600,6 +607,7 @@ |
601 | 608 | "\xe2\x80\x8c" => "\\u200c", // ZERO WIDTH NON-JOINER |
602 | 609 | "\xe2\x80\x8d" => "\\u200d", // ZERO WIDTH JOINER |
603 | 610 | ); |
| 611 | + |
604 | 612 | return strtr( $string, $pairs ); |
605 | 613 | } |
606 | 614 | |
— | — | @@ -641,6 +649,7 @@ |
642 | 650 | if ( $s != '{' ) { |
643 | 651 | $s .= ', '; |
644 | 652 | } |
| 653 | + |
645 | 654 | $s .= '"' . self::escapeJsString( $name ) . '": ' . |
646 | 655 | self::encodeJsVar( $elt ); |
647 | 656 | } |
— | — | @@ -666,19 +675,22 @@ |
667 | 676 | public static function encodeJsCall( $name, $args ) { |
668 | 677 | $s = "$name("; |
669 | 678 | $first = true; |
| 679 | + |
670 | 680 | foreach ( $args as $arg ) { |
671 | 681 | if ( $first ) { |
672 | 682 | $first = false; |
673 | 683 | } else { |
674 | 684 | $s .= ', '; |
675 | 685 | } |
| 686 | + |
676 | 687 | $s .= Xml::encodeJsVar( $arg ); |
677 | 688 | } |
| 689 | + |
678 | 690 | $s .= ");\n"; |
| 691 | + |
679 | 692 | return $s; |
680 | 693 | } |
681 | 694 | |
682 | | - |
683 | 695 | /** |
684 | 696 | * Check if a string is well-formed XML. |
685 | 697 | * Must include the surrounding tag. |
— | — | @@ -702,7 +714,9 @@ |
703 | 715 | xml_parser_free( $parser ); |
704 | 716 | return false; |
705 | 717 | } |
| 718 | + |
706 | 719 | xml_parser_free( $parser ); |
| 720 | + |
707 | 721 | return true; |
708 | 722 | } |
709 | 723 | |
— | — | @@ -720,6 +734,7 @@ |
721 | 735 | '<html>' . |
722 | 736 | $text . |
723 | 737 | '</html>'; |
| 738 | + |
724 | 739 | return Xml::isWellFormed( $html ); |
725 | 740 | } |
726 | 741 | |
— | — | @@ -765,7 +780,6 @@ |
766 | 781 | |
767 | 782 | $form .= "</tbody></table>"; |
768 | 783 | |
769 | | - |
770 | 784 | return $form; |
771 | 785 | } |
772 | 786 | |
— | — | @@ -778,19 +792,31 @@ |
779 | 793 | */ |
780 | 794 | public static function buildTable( $rows, $attribs = array(), $headers = null ) { |
781 | 795 | $s = Xml::openElement( 'table', $attribs ); |
| 796 | + |
782 | 797 | if ( is_array( $headers ) ) { |
783 | 798 | foreach( $headers as $id => $header ) { |
784 | 799 | $attribs = array(); |
785 | | - if ( is_string( $id ) ) $attribs['id'] = $id; |
| 800 | + |
| 801 | + if ( is_string( $id ) ) { |
| 802 | + $attribs['id'] = $id; |
| 803 | + } |
| 804 | + |
786 | 805 | $s .= Xml::element( 'th', $attribs, $header ); |
787 | 806 | } |
788 | 807 | } |
| 808 | + |
789 | 809 | foreach( $rows as $id => $row ) { |
790 | 810 | $attribs = array(); |
791 | | - if ( is_string( $id ) ) $attribs['id'] = $id; |
| 811 | + |
| 812 | + if ( is_string( $id ) ) { |
| 813 | + $attribs['id'] = $id; |
| 814 | + } |
| 815 | + |
792 | 816 | $s .= Xml::buildTableRow( $attribs, $row ); |
793 | 817 | } |
| 818 | + |
794 | 819 | $s .= Xml::closeElement( 'table' ); |
| 820 | + |
795 | 821 | return $s; |
796 | 822 | } |
797 | 823 | |
— | — | @@ -802,12 +828,20 @@ |
803 | 829 | */ |
804 | 830 | public static function buildTableRow( $attribs, $cells ) { |
805 | 831 | $s = Xml::openElement( 'tr', $attribs ); |
| 832 | + |
806 | 833 | foreach( $cells as $id => $cell ) { |
| 834 | + |
807 | 835 | $attribs = array(); |
808 | | - if ( is_string( $id ) ) $attribs['id'] = $id; |
| 836 | + |
| 837 | + if ( is_string( $id ) ) { |
| 838 | + $attribs['id'] = $id; |
| 839 | + } |
| 840 | + |
809 | 841 | $s .= Xml::element( 'td', $attribs, $cell ); |
810 | 842 | } |
| 843 | + |
811 | 844 | $s .= Xml::closeElement( 'tr' ); |
| 845 | + |
812 | 846 | return $s; |
813 | 847 | } |
814 | 848 | } |
— | — | @@ -821,9 +855,11 @@ |
822 | 856 | if ( $name ) { |
823 | 857 | $this->setAttribute( 'name', $name ); |
824 | 858 | } |
| 859 | + |
825 | 860 | if ( $id ) { |
826 | 861 | $this->setAttribute( 'id', $id ); |
827 | 862 | } |
| 863 | + |
828 | 864 | if ( $default !== false ) { |
829 | 865 | $this->default = $default; |
830 | 866 | } |
— | — | @@ -863,6 +899,7 @@ |
864 | 900 | public function addOption( $name, $value = false ) { |
865 | 901 | // Stab stab stab |
866 | 902 | $value = ($value !== false) ? $value : $name; |
| 903 | + |
867 | 904 | $this->options[] = array( $name => $value ); |
868 | 905 | } |
869 | 906 | |
— | — | @@ -888,6 +925,7 @@ |
889 | 926 | */ |
890 | 927 | static function formatOptions( $options, $default = false ) { |
891 | 928 | $data = ''; |
| 929 | + |
892 | 930 | foreach( $options as $label => $value ) { |
893 | 931 | if ( is_array( $value ) ) { |
894 | 932 | $contents = self::formatOptions( $value, $default ); |
— | — | @@ -905,12 +943,13 @@ |
906 | 944 | */ |
907 | 945 | public function getHTML() { |
908 | 946 | $contents = ''; |
| 947 | + |
909 | 948 | foreach ( $this->options as $options ) { |
910 | 949 | $contents .= self::formatOptions( $options, $this->default ); |
911 | 950 | } |
| 951 | + |
912 | 952 | return Xml::tags( 'select', $this->attributes, rtrim( $contents ) ); |
913 | 953 | } |
914 | | - |
915 | 954 | } |
916 | 955 | |
917 | 956 | /** |