@@ -456,6 +456,10 @@ discard block |
||
456 | 456 | |
457 | 457 | |
458 | 458 | // Add warning(s) to $this->warnings[] |
459 | + |
|
460 | + /** |
|
461 | + * @param string $message |
|
462 | + */ |
|
459 | 463 | public function warning($message) { |
460 | 464 | |
461 | 465 | if (is_array($message)) { |
@@ -482,6 +486,11 @@ discard block |
||
482 | 486 | |
483 | 487 | |
484 | 488 | // Convert string between charsets -- iconv() wrapper |
489 | + |
|
490 | + /** |
|
491 | + * @param string $out_charset |
|
492 | + * @param string $string |
|
493 | + */ |
|
485 | 494 | public function iconv($in_charset, $out_charset, $string, $drop01 = false) { |
486 | 495 | |
487 | 496 | if ($drop01 && ($string === "\x00" || $string === "\x01")) { |
@@ -509,6 +518,9 @@ discard block |
||
509 | 518 | |
510 | 519 | |
511 | 520 | |
521 | + /** |
|
522 | + * @param string $name |
|
523 | + */ |
|
512 | 524 | public function include_module($name) { |
513 | 525 | |
514 | 526 | if (!file_exists($this->include_path.'module.'.$name.'.php')) { |
@@ -1342,6 +1354,10 @@ discard block |
||
1342 | 1354 | |
1343 | 1355 | |
1344 | 1356 | // Convert Big Endian byte string to int - max 32 bits |
1357 | + |
|
1358 | + /** |
|
1359 | + * @param string $byte_word |
|
1360 | + */ |
|
1345 | 1361 | public static function BigEndian2Int($byte_word, $signed = false) { |
1346 | 1362 | |
1347 | 1363 | $int_value = 0; |
@@ -1391,6 +1407,9 @@ discard block |
||
1391 | 1407 | |
1392 | 1408 | |
1393 | 1409 | |
1410 | + /** |
|
1411 | + * @param string $byte_word |
|
1412 | + */ |
|
1394 | 1413 | public static function BigEndian2Float($byte_word) { |
1395 | 1414 | |
1396 | 1415 | // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic |
@@ -1478,6 +1497,9 @@ discard block |
||
1478 | 1497 | |
1479 | 1498 | |
1480 | 1499 | |
1500 | + /** |
|
1501 | + * @param string $binary_numerator |
|
1502 | + */ |
|
1481 | 1503 | public static function DecimalBinary2Float($binary_numerator) { |
1482 | 1504 | $numerator = bindec($binary_numerator); |
1483 | 1505 | $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator))); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | $class = new $class_name($this); |
301 | 301 | |
302 | 302 | try { |
303 | - $this->option_analyze and $class->Analyze(); |
|
303 | + $this->option_analyze and $class->Analyze(); |
|
304 | 304 | } |
305 | 305 | catch (getid3_exception $e) { |
306 | 306 | throw $e; |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | // CalculateReplayGain() { |
384 | 384 | if (@$this->info['replay_gain']) { |
385 | 385 | if (!@$this->info['replay_gain']['reference_volume']) { |
386 | - $this->info['replay_gain']['reference_volume'] = 89; |
|
386 | + $this->info['replay_gain']['reference_volume'] = 89; |
|
387 | 387 | } |
388 | 388 | if (isset($this->info['replay_gain']['track']['adjustment'])) { |
389 | 389 | $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | |
404 | 404 | // ProcessAudioStreams() { |
405 | 405 | if (@!$this->info['audio']['streams'] && (@$this->info['audio']['bitrate'] || @$this->info['audio']['channels'] || @$this->info['audio']['sample_rate'])) { |
406 | - foreach ($this->info['audio'] as $key => $value) { |
|
406 | + foreach ($this->info['audio'] as $key => $value) { |
|
407 | 407 | if ($key != 'streams') { |
408 | 408 | $this->info['audio']['streams'][0][$key] = $value; |
409 | 409 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | 'group' => 'audio', |
545 | 545 | 'module' => 'ac3', |
546 | 546 | 'mime_type' => 'audio/ac3', |
547 | - ), |
|
547 | + ), |
|
548 | 548 | |
549 | 549 | // AAC - audio - Advanced Audio Coding (AAC) - ADIF format |
550 | 550 | 'adif' => array ( |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | 'module' => 'aac_adif', |
554 | 554 | 'mime_type' => 'application/octet-stream', |
555 | 555 | 'fail_ape' => 'WARNING', |
556 | - ), |
|
556 | + ), |
|
557 | 557 | |
558 | 558 | |
559 | 559 | // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | 'module' => 'aac_adts', |
564 | 564 | 'mime_type' => 'application/octet-stream', |
565 | 565 | 'fail_ape' => 'WARNING', |
566 | - ), |
|
566 | + ), |
|
567 | 567 | |
568 | 568 | |
569 | 569 | // AU - audio - NeXT/Sun AUdio (AU) |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | 'group' => 'audio', |
573 | 573 | 'module' => 'au', |
574 | 574 | 'mime_type' => 'audio/basic', |
575 | - ), |
|
575 | + ), |
|
576 | 576 | |
577 | 577 | // AVR - audio - Audio Visual Research |
578 | 578 | 'avr' => array ( |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | 'group' => 'audio', |
581 | 581 | 'module' => 'avr', |
582 | 582 | 'mime_type' => 'application/octet-stream', |
583 | - ), |
|
583 | + ), |
|
584 | 584 | |
585 | 585 | // BONK - audio - Bonk v0.9+ |
586 | 586 | 'bonk' => array ( |
@@ -588,15 +588,15 @@ discard block |
||
588 | 588 | 'group' => 'audio', |
589 | 589 | 'module' => 'bonk', |
590 | 590 | 'mime_type' => 'audio/xmms-bonk', |
591 | - ), |
|
591 | + ), |
|
592 | 592 | |
593 | 593 | // DTS - audio - Dolby Theatre System |
594 | - 'dts' => array( |
|
595 | - 'pattern' => '^\x7F\xFE\x80\x01', |
|
596 | - 'group' => 'audio', |
|
597 | - 'module' => 'dts', |
|
598 | - 'mime_type' => 'audio/dts', |
|
599 | - ), |
|
594 | + 'dts' => array( |
|
595 | + 'pattern' => '^\x7F\xFE\x80\x01', |
|
596 | + 'group' => 'audio', |
|
597 | + 'module' => 'dts', |
|
598 | + 'mime_type' => 'audio/dts', |
|
599 | + ), |
|
600 | 600 | |
601 | 601 | // FLAC - audio - Free Lossless Audio Codec |
602 | 602 | 'flac' => array ( |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | 'group' => 'audio', |
605 | 605 | 'module' => 'xiph', |
606 | 606 | 'mime_type' => 'audio/x-flac', |
607 | - ), |
|
607 | + ), |
|
608 | 608 | |
609 | 609 | // LA - audio - Lossless Audio (LA) |
610 | 610 | 'la' => array ( |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | 'group' => 'audio', |
613 | 613 | 'module' => 'la', |
614 | 614 | 'mime_type' => 'application/octet-stream', |
615 | - ), |
|
615 | + ), |
|
616 | 616 | |
617 | 617 | // LPAC - audio - Lossless Predictive Audio Compression (LPAC) |
618 | 618 | 'lpac' => array ( |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | 'group' => 'audio', |
621 | 621 | 'module' => 'lpac', |
622 | 622 | 'mime_type' => 'application/octet-stream', |
623 | - ), |
|
623 | + ), |
|
624 | 624 | |
625 | 625 | // MIDI - audio - MIDI (Musical Instrument Digital Interface) |
626 | 626 | 'midi' => array ( |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | 'group' => 'audio', |
629 | 629 | 'module' => 'midi', |
630 | 630 | 'mime_type' => 'audio/midi', |
631 | - ), |
|
631 | + ), |
|
632 | 632 | |
633 | 633 | // MAC - audio - Monkey's Audio Compressor |
634 | 634 | 'mac' => array ( |
@@ -636,31 +636,31 @@ discard block |
||
636 | 636 | 'group' => 'audio', |
637 | 637 | 'module' => 'monkey', |
638 | 638 | 'mime_type' => 'application/octet-stream', |
639 | - ), |
|
639 | + ), |
|
640 | 640 | |
641 | 641 | // MOD - audio - MODule (assorted sub-formats) |
642 | 642 | 'mod' => array ( |
643 | 643 | 'pattern' => '^.{1080}(M.K.|[5-9]CHN|[1-3][0-9]CH)', |
644 | 644 | 'mime_type' => 'audio/mod', |
645 | - ), |
|
645 | + ), |
|
646 | 646 | |
647 | 647 | // MOD - audio - MODule (Impulse Tracker) |
648 | 648 | 'it' => array ( |
649 | 649 | 'pattern' => '^IMPM', |
650 | 650 | 'mime_type' => 'audio/it', |
651 | - ), |
|
651 | + ), |
|
652 | 652 | |
653 | 653 | // MOD - audio - MODule (eXtended Module, various sub-formats) |
654 | 654 | 'xm' => array ( |
655 | 655 | 'pattern' => '^Extended Module', |
656 | 656 | 'mime_type' => 'audio/xm', |
657 | - ), |
|
657 | + ), |
|
658 | 658 | |
659 | 659 | // MOD - audio - MODule (ScreamTracker) |
660 | 660 | 's3m' => array ( |
661 | 661 | 'pattern' => '^.{44}SCRM', |
662 | 662 | 'mime_type' => 'audio/s3m', |
663 | - ), |
|
663 | + ), |
|
664 | 664 | |
665 | 665 | // MPC - audio - Musepack / MPEGplus SV7+ |
666 | 666 | 'mpc' => array ( |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | 'group' => 'audio', |
669 | 669 | 'module' => 'mpc', |
670 | 670 | 'mime_type' => 'audio/x-musepack', |
671 | - ), |
|
671 | + ), |
|
672 | 672 | |
673 | 673 | // MPC - audio - Musepack / MPEGplus SV4-6 |
674 | 674 | 'mpc_old' => array ( |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | 'group' => 'audio', |
677 | 677 | 'module' => 'mpc_old', |
678 | 678 | 'mime_type' => 'application/octet-stream', |
679 | - ), |
|
679 | + ), |
|
680 | 680 | |
681 | 681 | |
682 | 682 | // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | 'group' => 'audio', |
686 | 686 | 'module' => 'mp3', |
687 | 687 | 'mime_type' => 'audio/mpeg', |
688 | - ), |
|
688 | + ), |
|
689 | 689 | |
690 | 690 | // OFR - audio - OptimFROG |
691 | 691 | 'ofr' => array ( |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | 'group' => 'audio', |
694 | 694 | 'module' => 'optimfrog', |
695 | 695 | 'mime_type' => 'application/octet-stream', |
696 | - ), |
|
696 | + ), |
|
697 | 697 | |
698 | 698 | // RKAU - audio - RKive AUdio compressor |
699 | 699 | 'rkau' => array ( |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | 'group' => 'audio', |
702 | 702 | 'module' => 'rkau', |
703 | 703 | 'mime_type' => 'application/octet-stream', |
704 | - ), |
|
704 | + ), |
|
705 | 705 | |
706 | 706 | // SHN - audio - Shorten |
707 | 707 | 'shn' => array ( |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | 'mime_type' => 'audio/xmms-shn', |
712 | 712 | 'fail_id3' => 'ERROR', |
713 | 713 | 'fail_ape' => 'ERROR', |
714 | - ), |
|
714 | + ), |
|
715 | 715 | |
716 | 716 | // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) |
717 | 717 | 'tta' => array ( |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | 'group' => 'audio', |
720 | 720 | 'module' => 'tta', |
721 | 721 | 'mime_type' => 'application/octet-stream', |
722 | - ), |
|
722 | + ), |
|
723 | 723 | |
724 | 724 | // VOC - audio - Creative Voice (VOC) |
725 | 725 | 'voc' => array ( |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | 'group' => 'audio', |
728 | 728 | 'module' => 'voc', |
729 | 729 | 'mime_type' => 'audio/voc', |
730 | - ), |
|
730 | + ), |
|
731 | 731 | |
732 | 732 | // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) |
733 | 733 | 'vqf' => array ( |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | 'group' => 'audio', |
736 | 736 | 'module' => 'vqf', |
737 | 737 | 'mime_type' => 'application/octet-stream', |
738 | - ), |
|
738 | + ), |
|
739 | 739 | |
740 | 740 | // WV - audio - WavPack (v4.0+) |
741 | 741 | 'vw' => array( |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | 'group' => 'audio', |
744 | 744 | 'module' => 'wavpack', |
745 | 745 | 'mime_type' => 'application/octet-stream', |
746 | - ), |
|
746 | + ), |
|
747 | 747 | |
748 | 748 | |
749 | 749 | // Audio-Video formats |
@@ -754,13 +754,13 @@ discard block |
||
754 | 754 | 'group' => 'audio-video', |
755 | 755 | 'module' => 'asf', |
756 | 756 | 'mime_type' => 'video/x-ms-asf', |
757 | - ), |
|
757 | + ), |
|
758 | 758 | |
759 | 759 | // BINK - audio/video - Bink / Smacker |
760 | 760 | 'bink' => array( |
761 | 761 | 'pattern' => '^(BIK|SMK)', |
762 | 762 | 'mime_type' => 'application/octet-stream', |
763 | - ), |
|
763 | + ), |
|
764 | 764 | |
765 | 765 | // FLV - audio/video - FLash Video |
766 | 766 | 'flv' => array( |
@@ -768,13 +768,13 @@ discard block |
||
768 | 768 | 'group' => 'audio-video', |
769 | 769 | 'module' => 'flv', |
770 | 770 | 'mime_type' => 'video/x-flv', |
771 | - ), |
|
771 | + ), |
|
772 | 772 | |
773 | 773 | // MKAV - audio/video - Mastroka |
774 | 774 | 'matroska' => array ( |
775 | 775 | 'pattern' => '^\x1A\x45\xDF\xA3', |
776 | 776 | 'mime_type' => 'application/octet-stream', |
777 | - ), |
|
777 | + ), |
|
778 | 778 | |
779 | 779 | // MPEG - audio/video - MPEG (Moving Pictures Experts Group) |
780 | 780 | 'mpeg' => array ( |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | 'group' => 'audio-video', |
783 | 783 | 'module' => 'mpeg', |
784 | 784 | 'mime_type' => 'video/mpeg', |
785 | - ), |
|
785 | + ), |
|
786 | 786 | |
787 | 787 | // NSV - audio/video - Nullsoft Streaming Video (NSV) |
788 | 788 | 'nsv' => array ( |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | 'group' => 'audio-video', |
791 | 791 | 'module' => 'nsv', |
792 | 792 | 'mime_type' => 'application/octet-stream', |
793 | - ), |
|
793 | + ), |
|
794 | 794 | |
795 | 795 | // Ogg - audio/video - Ogg (Ogg Vorbis, OggFLAC, Speex, Ogg Theora(*), Ogg Tarkin(*)) |
796 | 796 | 'ogg' => array ( |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | 'mime_type' => 'application/ogg', |
801 | 801 | 'fail_id3' => 'WARNING', |
802 | 802 | 'fail_ape' => 'WARNING', |
803 | - ), |
|
803 | + ), |
|
804 | 804 | |
805 | 805 | // QT - audio/video - Quicktime |
806 | 806 | 'quicktime' => array ( |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | 'group' => 'audio-video', |
809 | 809 | 'module' => 'quicktime', |
810 | 810 | 'mime_type' => 'video/quicktime', |
811 | - ), |
|
811 | + ), |
|
812 | 812 | |
813 | 813 | // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) |
814 | 814 | 'riff' => array ( |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | 'module' => 'riff', |
818 | 818 | 'mime_type' => 'audio/x-wave', |
819 | 819 | 'fail_ape' => 'WARNING', |
820 | - ), |
|
820 | + ), |
|
821 | 821 | |
822 | 822 | // Real - audio/video - RealAudio, RealVideo |
823 | 823 | 'real' => array ( |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | 'group' => 'audio-video', |
826 | 826 | 'module' => 'real', |
827 | 827 | 'mime_type' => 'audio/x-realaudio', |
828 | - ), |
|
828 | + ), |
|
829 | 829 | |
830 | 830 | // SWF - audio/video - ShockWave Flash |
831 | 831 | 'swf' => array ( |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | 'group' => 'audio-video', |
834 | 834 | 'module' => 'swf', |
835 | 835 | 'mime_type' => 'application/x-shockwave-flash', |
836 | - ), |
|
836 | + ), |
|
837 | 837 | |
838 | 838 | |
839 | 839 | // Still-Image formats |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | 'mime_type' => 'image/bmp', |
847 | 847 | 'fail_id3' => 'ERROR', |
848 | 848 | 'fail_ape' => 'ERROR', |
849 | - ), |
|
849 | + ), |
|
850 | 850 | |
851 | 851 | // GIF - still image - Graphics Interchange Format |
852 | 852 | 'gif' => array ( |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | 'mime_type' => 'image/gif', |
857 | 857 | 'fail_id3' => 'ERROR', |
858 | 858 | 'fail_ape' => 'ERROR', |
859 | - ), |
|
859 | + ), |
|
860 | 860 | |
861 | 861 | // JPEG - still image - Joint Photographic Experts Group (JPEG) |
862 | 862 | 'jpeg' => array ( |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | 'mime_type' => 'image/jpeg', |
867 | 867 | 'fail_id3' => 'ERROR', |
868 | 868 | 'fail_ape' => 'ERROR', |
869 | - ), |
|
869 | + ), |
|
870 | 870 | |
871 | 871 | // PCD - still image - Kodak Photo CD |
872 | 872 | 'pcd' => array ( |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | 'mime_type' => 'image/x-photo-cd', |
877 | 877 | 'fail_id3' => 'ERROR', |
878 | 878 | 'fail_ape' => 'ERROR', |
879 | - ), |
|
879 | + ), |
|
880 | 880 | |
881 | 881 | |
882 | 882 | // PNG - still image - Portable Network Graphics (PNG) |
@@ -887,16 +887,16 @@ discard block |
||
887 | 887 | 'mime_type' => 'image/png', |
888 | 888 | 'fail_id3' => 'ERROR', |
889 | 889 | 'fail_ape' => 'ERROR', |
890 | - ), |
|
890 | + ), |
|
891 | 891 | |
892 | 892 | |
893 | 893 | // SVG - still image - Scalable Vector Graphics (SVG) |
894 | - 'svg' => array( |
|
895 | - 'pattern' => '<!DOCTYPE svg PUBLIC ', |
|
896 | - 'mime_type' => 'image/svg+xml', |
|
897 | - 'fail_id3' => 'ERROR', |
|
898 | - 'fail_ape' => 'ERROR', |
|
899 | - ), |
|
894 | + 'svg' => array( |
|
895 | + 'pattern' => '<!DOCTYPE svg PUBLIC ', |
|
896 | + 'mime_type' => 'image/svg+xml', |
|
897 | + 'fail_id3' => 'ERROR', |
|
898 | + 'fail_ape' => 'ERROR', |
|
899 | + ), |
|
900 | 900 | |
901 | 901 | |
902 | 902 | // TIFF - still image - Tagged Information File Format (TIFF) |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | 'mime_type' => 'image/tiff', |
908 | 908 | 'fail_id3' => 'ERROR', |
909 | 909 | 'fail_ape' => 'ERROR', |
910 | - ), |
|
910 | + ), |
|
911 | 911 | |
912 | 912 | |
913 | 913 | // Data formats |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | 'mime_type' => 'application/octet-stream', |
918 | 918 | 'fail_id3' => 'ERROR', |
919 | 919 | 'fail_ape' => 'ERROR', |
920 | - ), |
|
920 | + ), |
|
921 | 921 | |
922 | 922 | // ISO - data - International Standards Organization (ISO) CD-ROM Image |
923 | 923 | 'iso' => array ( |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | 'mime_type' => 'application/octet-stream', |
928 | 928 | 'fail_id3' => 'ERROR', |
929 | 929 | 'fail_ape' => 'ERROR', |
930 | - ), |
|
930 | + ), |
|
931 | 931 | |
932 | 932 | // RAR - data - RAR compressed data |
933 | 933 | 'rar' => array( |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | 'mime_type' => 'application/octet-stream', |
936 | 936 | 'fail_id3' => 'ERROR', |
937 | 937 | 'fail_ape' => 'ERROR', |
938 | - ), |
|
938 | + ), |
|
939 | 939 | |
940 | 940 | // SZIP - audio - SZIP compressed data |
941 | 941 | 'szip' => array ( |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | 'mime_type' => 'application/octet-stream', |
946 | 946 | 'fail_id3' => 'ERROR', |
947 | 947 | 'fail_ape' => 'ERROR', |
948 | - ), |
|
948 | + ), |
|
949 | 949 | |
950 | 950 | // TAR - data - TAR compressed data |
951 | 951 | 'tar' => array( |
@@ -955,7 +955,7 @@ discard block |
||
955 | 955 | 'mime_type' => 'application/x-tar', |
956 | 956 | 'fail_id3' => 'ERROR', |
957 | 957 | 'fail_ape' => 'ERROR', |
958 | - ), |
|
958 | + ), |
|
959 | 959 | |
960 | 960 | // GZIP - data - GZIP compressed data |
961 | 961 | 'gz' => array( |
@@ -965,7 +965,7 @@ discard block |
||
965 | 965 | 'mime_type' => 'application/x-gzip', |
966 | 966 | 'fail_id3' => 'ERROR', |
967 | 967 | 'fail_ape' => 'ERROR', |
968 | - ), |
|
968 | + ), |
|
969 | 969 | |
970 | 970 | |
971 | 971 | // ZIP - data - ZIP compressed data |
@@ -976,33 +976,33 @@ discard block |
||
976 | 976 | 'mime_type' => 'application/zip', |
977 | 977 | 'fail_id3' => 'ERROR', |
978 | 978 | 'fail_ape' => 'ERROR', |
979 | - ), |
|
979 | + ), |
|
980 | 980 | |
981 | 981 | |
982 | 982 | // PAR2 - data - Parity Volume Set Specification 2.0 |
983 | 983 | 'par2' => array ( |
984 | - 'pattern' => '^PAR2\x00PKT', |
|
985 | - 'mime_type' => 'application/octet-stream', |
|
986 | - 'fail_id3' => 'ERROR', |
|
987 | - 'fail_ape' => 'ERROR', |
|
988 | - ), |
|
984 | + 'pattern' => '^PAR2\x00PKT', |
|
985 | + 'mime_type' => 'application/octet-stream', |
|
986 | + 'fail_id3' => 'ERROR', |
|
987 | + 'fail_ape' => 'ERROR', |
|
988 | + ), |
|
989 | 989 | |
990 | 990 | |
991 | - // PDF - data - Portable Document Format |
|
992 | - 'pdf' => array( |
|
991 | + // PDF - data - Portable Document Format |
|
992 | + 'pdf' => array( |
|
993 | 993 | 'pattern' => '^\x25PDF', |
994 | 994 | 'mime_type' => 'application/pdf', |
995 | 995 | 'fail_id3' => 'ERROR', |
996 | 996 | 'fail_ape' => 'ERROR', |
997 | - ), |
|
997 | + ), |
|
998 | 998 | |
999 | - // DOC - data - Microsoft Word |
|
1000 | - 'msoffice' => array( |
|
999 | + // DOC - data - Microsoft Word |
|
1000 | + 'msoffice' => array( |
|
1001 | 1001 | 'pattern' => '^\xD0\xCF\x11\xE0', // D0CF11E == DOCFILE == Microsoft Office Document |
1002 | 1002 | 'mime_type' => 'application/octet-stream', |
1003 | 1003 | 'fail_id3' => 'ERROR', |
1004 | 1004 | 'fail_ape' => 'ERROR', |
1005 | - ), |
|
1005 | + ), |
|
1006 | 1006 | ); |
1007 | 1007 | |
1008 | 1008 | return $format_info; |
@@ -1393,99 +1393,99 @@ discard block |
||
1393 | 1393 | |
1394 | 1394 | public static function BigEndian2Float($byte_word) { |
1395 | 1395 | |
1396 | - // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic |
|
1397 | - // http://www.psc.edu/general/software/packages/ieee/ieee.html |
|
1398 | - // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html |
|
1396 | + // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic |
|
1397 | + // http://www.psc.edu/general/software/packages/ieee/ieee.html |
|
1398 | + // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html |
|
1399 | 1399 | |
1400 | - $bit_word = getid3_lib::BigEndian2Bin($byte_word); |
|
1401 | - if (!$bit_word) { |
|
1400 | + $bit_word = getid3_lib::BigEndian2Bin($byte_word); |
|
1401 | + if (!$bit_word) { |
|
1402 | 1402 | return 0; |
1403 | 1403 | } |
1404 | - $sign_bit = $bit_word{0}; |
|
1405 | - |
|
1406 | - switch (strlen($byte_word) * 8) { |
|
1407 | - case 32: |
|
1408 | - $exponent_bits = 8; |
|
1409 | - $fraction_bits = 23; |
|
1410 | - break; |
|
1411 | - |
|
1412 | - case 64: |
|
1413 | - $exponent_bits = 11; |
|
1414 | - $fraction_bits = 52; |
|
1415 | - break; |
|
1416 | - |
|
1417 | - case 80: |
|
1418 | - // 80-bit Apple SANE format |
|
1419 | - // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ |
|
1420 | - $exponent_string = substr($bit_word, 1, 15); |
|
1421 | - $is_normalized = intval($bit_word{16}); |
|
1422 | - $fraction_string = substr($bit_word, 17, 63); |
|
1423 | - $exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383); |
|
1424 | - $fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string); |
|
1425 | - $float_value = $exponent * $fraction; |
|
1426 | - if ($sign_bit == '1') { |
|
1427 | - $float_value *= -1; |
|
1428 | - } |
|
1429 | - return $float_value; |
|
1430 | - break; |
|
1431 | - |
|
1432 | - default: |
|
1433 | - return false; |
|
1434 | - break; |
|
1435 | - } |
|
1436 | - $exponent_string = substr($bit_word, 1, $exponent_bits); |
|
1437 | - $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits); |
|
1438 | - $exponent = bindec($exponent_string); |
|
1439 | - $fraction = bindec($fraction_string); |
|
1440 | - |
|
1441 | - if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) { |
|
1442 | - // Not a Number |
|
1443 | - $float_value = false; |
|
1444 | - } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) { |
|
1445 | - if ($sign_bit == '1') { |
|
1446 | - $float_value = '-infinity'; |
|
1447 | - } else { |
|
1448 | - $float_value = '+infinity'; |
|
1449 | - } |
|
1450 | - } elseif (($exponent == 0) && ($fraction == 0)) { |
|
1451 | - if ($sign_bit == '1') { |
|
1452 | - $float_value = -0; |
|
1453 | - } else { |
|
1454 | - $float_value = 0; |
|
1455 | - } |
|
1456 | - $float_value = ($sign_bit ? 0 : -0); |
|
1457 | - } elseif (($exponent == 0) && ($fraction != 0)) { |
|
1458 | - // These are 'unnormalized' values |
|
1459 | - $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fraction_string); |
|
1460 | - if ($sign_bit == '1') { |
|
1461 | - $float_value *= -1; |
|
1462 | - } |
|
1463 | - } elseif ($exponent != 0) { |
|
1464 | - $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fraction_string)); |
|
1465 | - if ($sign_bit == '1') { |
|
1466 | - $float_value *= -1; |
|
1467 | - } |
|
1468 | - } |
|
1469 | - return (float) $float_value; |
|
1470 | - } |
|
1471 | - |
|
1472 | - |
|
1473 | - |
|
1474 | - public static function LittleEndian2Float($byte_word) { |
|
1475 | - |
|
1476 | - return getid3_lib::BigEndian2Float(strrev($byte_word)); |
|
1477 | - } |
|
1478 | - |
|
1479 | - |
|
1480 | - |
|
1481 | - public static function DecimalBinary2Float($binary_numerator) { |
|
1482 | - $numerator = bindec($binary_numerator); |
|
1483 | - $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator))); |
|
1484 | - return ($numerator / $denominator); |
|
1485 | - } |
|
1486 | - |
|
1487 | - |
|
1488 | - public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) { |
|
1404 | + $sign_bit = $bit_word{0}; |
|
1405 | + |
|
1406 | + switch (strlen($byte_word) * 8) { |
|
1407 | + case 32: |
|
1408 | + $exponent_bits = 8; |
|
1409 | + $fraction_bits = 23; |
|
1410 | + break; |
|
1411 | + |
|
1412 | + case 64: |
|
1413 | + $exponent_bits = 11; |
|
1414 | + $fraction_bits = 52; |
|
1415 | + break; |
|
1416 | + |
|
1417 | + case 80: |
|
1418 | + // 80-bit Apple SANE format |
|
1419 | + // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/ |
|
1420 | + $exponent_string = substr($bit_word, 1, 15); |
|
1421 | + $is_normalized = intval($bit_word{16}); |
|
1422 | + $fraction_string = substr($bit_word, 17, 63); |
|
1423 | + $exponent = pow(2, getid3_lib::Bin2Dec($exponent_string) - 16383); |
|
1424 | + $fraction = $is_normalized + getid3_lib::DecimalBinary2Float($fraction_string); |
|
1425 | + $float_value = $exponent * $fraction; |
|
1426 | + if ($sign_bit == '1') { |
|
1427 | + $float_value *= -1; |
|
1428 | + } |
|
1429 | + return $float_value; |
|
1430 | + break; |
|
1431 | + |
|
1432 | + default: |
|
1433 | + return false; |
|
1434 | + break; |
|
1435 | + } |
|
1436 | + $exponent_string = substr($bit_word, 1, $exponent_bits); |
|
1437 | + $fraction_string = substr($bit_word, $exponent_bits + 1, $fraction_bits); |
|
1438 | + $exponent = bindec($exponent_string); |
|
1439 | + $fraction = bindec($fraction_string); |
|
1440 | + |
|
1441 | + if (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction != 0)) { |
|
1442 | + // Not a Number |
|
1443 | + $float_value = false; |
|
1444 | + } elseif (($exponent == (pow(2, $exponent_bits) - 1)) && ($fraction == 0)) { |
|
1445 | + if ($sign_bit == '1') { |
|
1446 | + $float_value = '-infinity'; |
|
1447 | + } else { |
|
1448 | + $float_value = '+infinity'; |
|
1449 | + } |
|
1450 | + } elseif (($exponent == 0) && ($fraction == 0)) { |
|
1451 | + if ($sign_bit == '1') { |
|
1452 | + $float_value = -0; |
|
1453 | + } else { |
|
1454 | + $float_value = 0; |
|
1455 | + } |
|
1456 | + $float_value = ($sign_bit ? 0 : -0); |
|
1457 | + } elseif (($exponent == 0) && ($fraction != 0)) { |
|
1458 | + // These are 'unnormalized' values |
|
1459 | + $float_value = pow(2, (-1 * (pow(2, $exponent_bits - 1) - 2))) * getid3_lib::DecimalBinary2Float($fraction_string); |
|
1460 | + if ($sign_bit == '1') { |
|
1461 | + $float_value *= -1; |
|
1462 | + } |
|
1463 | + } elseif ($exponent != 0) { |
|
1464 | + $float_value = pow(2, ($exponent - (pow(2, $exponent_bits - 1) - 1))) * (1 + getid3_lib::DecimalBinary2Float($fraction_string)); |
|
1465 | + if ($sign_bit == '1') { |
|
1466 | + $float_value *= -1; |
|
1467 | + } |
|
1468 | + } |
|
1469 | + return (float) $float_value; |
|
1470 | + } |
|
1471 | + |
|
1472 | + |
|
1473 | + |
|
1474 | + public static function LittleEndian2Float($byte_word) { |
|
1475 | + |
|
1476 | + return getid3_lib::BigEndian2Float(strrev($byte_word)); |
|
1477 | + } |
|
1478 | + |
|
1479 | + |
|
1480 | + |
|
1481 | + public static function DecimalBinary2Float($binary_numerator) { |
|
1482 | + $numerator = bindec($binary_numerator); |
|
1483 | + $denominator = bindec('1'.str_repeat('0', strlen($binary_numerator))); |
|
1484 | + return ($numerator / $denominator); |
|
1485 | + } |
|
1486 | + |
|
1487 | + |
|
1488 | + public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) { |
|
1489 | 1489 | |
1490 | 1490 | $return_string = ''; |
1491 | 1491 | for ($i = 0; $i < strlen($string); $i++) { |
@@ -27,42 +27,42 @@ discard block |
||
27 | 27 | //// Settings Section - do NOT modify this file - change setting after newing getid3! |
28 | 28 | |
29 | 29 | // Encoding |
30 | - public $encoding = 'ISO-8859-1'; // CASE SENSITIVE! - i.e. (must be supported by iconv() - see http://www.gnu.org/software/libiconv/). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE. |
|
31 | - public $encoding_id3v1 = 'ISO-8859-1'; // Override SPECIFICATION encoding for broken ID3v1 tags caused by bad tag programs. Examples: 'EUC-CN' for "Chinese MP3s" and 'CP1251' for "Cyrillic". |
|
32 | - public $encoding_id3v2 = 'ISO-8859-1'; // Override ISO-8859-1 encoding for broken ID3v2 tags caused by BRAINDEAD tag programs that writes system codepage as 'ISO-8859-1' instead of UTF-8. |
|
30 | + public $encoding = 'ISO-8859-1'; // CASE SENSITIVE! - i.e. (must be supported by iconv() - see http://www.gnu.org/software/libiconv/). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE. |
|
31 | + public $encoding_id3v1 = 'ISO-8859-1'; // Override SPECIFICATION encoding for broken ID3v1 tags caused by bad tag programs. Examples: 'EUC-CN' for "Chinese MP3s" and 'CP1251' for "Cyrillic". |
|
32 | + public $encoding_id3v2 = 'ISO-8859-1'; // Override ISO-8859-1 encoding for broken ID3v2 tags caused by BRAINDEAD tag programs that writes system codepage as 'ISO-8859-1' instead of UTF-8. |
|
33 | 33 | |
34 | 34 | // Tags - disable for speed |
35 | - public $option_tag_id3v1 = false; // Read and process ID3v1 tags. |
|
36 | - public $option_tag_id3v2 = false; // Read and process ID3v2 tags. |
|
37 | - public $option_tag_lyrics3 = false; // Read and process Lyrics3 tags. |
|
38 | - public $option_tag_apetag = false; // Read and process APE tags. |
|
35 | + public $option_tag_id3v1 = false; // Read and process ID3v1 tags. |
|
36 | + public $option_tag_id3v2 = false; // Read and process ID3v2 tags. |
|
37 | + public $option_tag_lyrics3 = false; // Read and process Lyrics3 tags. |
|
38 | + public $option_tag_apetag = false; // Read and process APE tags. |
|
39 | 39 | |
40 | 40 | // Misc calucations - disable for speed |
41 | - public $option_analyze = true; // Analyze file - disable if you only need to detect file format. |
|
42 | - public $option_accurate_results = true; // Disable to greatly speed up parsing of some file formats at the cost of accuracy. |
|
43 | - public $option_tags_process = true; // Copy tags to root key 'tags' and 'comments' and encode to $this->encoding. |
|
44 | - public $option_tags_images = false; // Scan tags for binary image data - ID3v2 and vorbiscomments only. |
|
45 | - public $option_extra_info = true; // Calculate/return additional info such as bitrate, channelmode etc. |
|
46 | - public $option_max_2gb_check = false; // Check whether file is larger than 2 Gb and thus not supported by PHP. |
|
41 | + public $option_analyze = true; // Analyze file - disable if you only need to detect file format. |
|
42 | + public $option_accurate_results = true; // Disable to greatly speed up parsing of some file formats at the cost of accuracy. |
|
43 | + public $option_tags_process = true; // Copy tags to root key 'tags' and 'comments' and encode to $this->encoding. |
|
44 | + public $option_tags_images = false; // Scan tags for binary image data - ID3v2 and vorbiscomments only. |
|
45 | + public $option_extra_info = true; // Calculate/return additional info such as bitrate, channelmode etc. |
|
46 | + public $option_max_2gb_check = false; // Check whether file is larger than 2 Gb and thus not supported by PHP. |
|
47 | 47 | |
48 | 48 | // Misc data hashes - slow - require hash module |
49 | - public $option_md5_data = false; // Get MD5 sum of data part - slow. |
|
50 | - public $option_md5_data_source = false; // Use MD5 of source file if available - only FLAC, MAC, OptimFROG and Wavpack4. |
|
51 | - public $option_sha1_data = false; // Get SHA1 sum of data part - slow. |
|
49 | + public $option_md5_data = false; // Get MD5 sum of data part - slow. |
|
50 | + public $option_md5_data_source = false; // Use MD5 of source file if available - only FLAC, MAC, OptimFROG and Wavpack4. |
|
51 | + public $option_sha1_data = false; // Get SHA1 sum of data part - slow. |
|
52 | 52 | |
53 | 53 | // Public variables |
54 | - public $filename; // Filename of file being analysed. |
|
55 | - public $fp; // Filepointer to file being analysed. |
|
56 | - public $info; // Result array. |
|
54 | + public $filename; // Filename of file being analysed. |
|
55 | + public $fp; // Filepointer to file being analysed. |
|
56 | + public $info; // Result array. |
|
57 | 57 | |
58 | 58 | // Protected variables |
59 | - protected $include_path; // getid3 include path. |
|
60 | - protected $warnings = array (); |
|
59 | + protected $include_path; // getid3 include path. |
|
60 | + protected $warnings = array(); |
|
61 | 61 | protected $iconv_present; |
62 | 62 | |
63 | 63 | // Class constants |
64 | 64 | const VERSION = '2.0.0b4'; |
65 | - const FREAD_BUFFER_SIZE = 16384; // Read buffer size in bytes. |
|
65 | + const FREAD_BUFFER_SIZE = 16384; // Read buffer size in bytes. |
|
66 | 66 | const ICONV_TEST_STRING = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~�������������������������������� �����������������������������������������������������������������������������������������������'; |
67 | 67 | |
68 | 68 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | // Get include_path |
90 | - $this->include_path = $include_path = dirname(__FILE__) . '/'; |
|
90 | + $this->include_path = $include_path = dirname(__FILE__).'/'; |
|
91 | 91 | |
92 | 92 | // Check for presence of iconv() and make sure it works (simpel test only). |
93 | 93 | if (function_exists('iconv') && @iconv('UTF-16LE', 'ISO-8859-1', @iconv('ISO-8859-1', 'UTF-16LE', getid3::ICONV_TEST_STRING)) == getid3::ICONV_TEST_STRING) { |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | |
124 | 124 | |
125 | 125 | // Check safe_mode off |
126 | - if ((bool)ini_get('safe_mode')) { |
|
126 | + if ((bool) ini_get('safe_mode')) { |
|
127 | 127 | $this->warning('Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbis/flac tag writing disabled.'); |
128 | 128 | } |
129 | 129 | |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | |
138 | 138 | // Init and save values |
139 | 139 | $this->filename = $filename; |
140 | - $this->warnings = array (); |
|
140 | + $this->warnings = array(); |
|
141 | 141 | |
142 | 142 | // Init result array and set parameters |
143 | - $this->info = array (); |
|
143 | + $this->info = array(); |
|
144 | 144 | $this->info['GETID3_VERSION'] = getid3::VERSION; |
145 | 145 | |
146 | 146 | // Remote files not supported |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | fseek($this->fp, 0, SEEK_SET); |
181 | 181 | $header = fread($this->fp, 10); |
182 | - if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) { |
|
182 | + if (substr($header, 0, 3) == 'ID3' && strlen($header) == 10) { |
|
183 | 183 | $this->info['id3v2']['header'] = true; |
184 | 184 | $this->info['id3v2']['majorversion'] = ord($header{3}); |
185 | 185 | $this->info['id3v2']['minorversion'] = ord($header{4}); |
@@ -189,13 +189,13 @@ discard block |
||
189 | 189 | |
190 | 190 | |
191 | 191 | // Handle tags |
192 | - foreach (array ("id3v2", "id3v1", "apetag", "lyrics3") as $tag_name) { |
|
192 | + foreach (array("id3v2", "id3v1", "apetag", "lyrics3") as $tag_name) { |
|
193 | 193 | |
194 | - $option_tag = 'option_tag_' . $tag_name; |
|
194 | + $option_tag = 'option_tag_'.$tag_name; |
|
195 | 195 | if ($this->$option_tag) { |
196 | 196 | $this->include_module('tag.'.$tag_name); |
197 | 197 | try { |
198 | - $tag_class = 'getid3_' . $tag_name; |
|
198 | + $tag_class = 'getid3_'.$tag_name; |
|
199 | 199 | $tag = new $tag_class($this); |
200 | 200 | $tag->Analyze(); |
201 | 201 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | return $this->info; |
232 | 232 | } |
233 | 233 | |
234 | - $determined_format = $info; // copy $info deleted by foreach() |
|
234 | + $determined_format = $info; // copy $info deleted by foreach() |
|
235 | 235 | continue; |
236 | 236 | } |
237 | 237 | } |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | |
342 | 342 | // Set playtime string |
343 | 343 | if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) { |
344 | - $this->info['playtime_string'] = floor(round($this->info['playtime_seconds']) / 60) . ':' . str_pad(floor(round($this->info['playtime_seconds']) % 60), 2, 0, STR_PAD_LEFT);; |
|
344 | + $this->info['playtime_string'] = floor(round($this->info['playtime_seconds']) / 60).':'.str_pad(floor(round($this->info['playtime_seconds']) % 60), 2, 0, STR_PAD_LEFT); ; |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | if (@$this->info['video'] && @$this->info['video']['resolution_x'] && @$this->info['video']['resolution_y'] && @$this->info['video']['bits_per_sample']) { |
350 | 350 | |
351 | 351 | // From static image formats |
352 | - if (in_array($this->info['video']['dataformat'], array ('bmp', 'gif', 'jpeg', 'jpg', 'png', 'tiff'))) { |
|
352 | + if (in_array($this->info['video']['dataformat'], array('bmp', 'gif', 'jpeg', 'jpg', 'png', 'tiff'))) { |
|
353 | 353 | $frame_rate = 1; |
354 | 354 | $bitrate_compressed = $this->info['filesize'] * 8; |
355 | 355 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | // Clear all warnings when cloning |
472 | 472 | public function __clone() { |
473 | 473 | |
474 | - $this->warnings = array (); |
|
474 | + $this->warnings = array(); |
|
475 | 475 | |
476 | 476 | // Copy info array, otherwise it will be a reference. |
477 | 477 | $temp = $this->info; |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | return $result; |
504 | 504 | } |
505 | 505 | |
506 | - $this->warning('iconv() was unable to convert the string: "' . $string . '" from ' . $in_charset . ' to ' . $out_charset); |
|
506 | + $this->warning('iconv() was unable to convert the string: "'.$string.'" from '.$in_charset.' to '.$out_charset); |
|
507 | 507 | return $string; |
508 | 508 | } |
509 | 509 | |
@@ -534,12 +534,12 @@ discard block |
||
534 | 534 | // Return array containing information about all supported formats |
535 | 535 | public static function GetFileFormatArray() { |
536 | 536 | |
537 | - static $format_info = array ( |
|
537 | + static $format_info = array( |
|
538 | 538 | |
539 | 539 | // Audio formats |
540 | 540 | |
541 | 541 | // AC-3 - audio - Dolby AC-3 / Dolby Digital |
542 | - 'ac3' => array ( |
|
542 | + 'ac3' => array( |
|
543 | 543 | 'pattern' => '^\x0B\x77', |
544 | 544 | 'group' => 'audio', |
545 | 545 | 'module' => 'ac3', |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | ), |
548 | 548 | |
549 | 549 | // AAC - audio - Advanced Audio Coding (AAC) - ADIF format |
550 | - 'adif' => array ( |
|
550 | + 'adif' => array( |
|
551 | 551 | 'pattern' => '^ADIF', |
552 | 552 | 'group' => 'audio', |
553 | 553 | 'module' => 'aac_adif', |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | |
559 | 559 | // AAC - audio - Advanced Audio Coding (AAC) - ADTS format (very similar to MP3) |
560 | - 'adts' => array ( |
|
560 | + 'adts' => array( |
|
561 | 561 | 'pattern' => '^\xFF[\xF0-\xF1\xF8-\xF9]', |
562 | 562 | 'group' => 'audio', |
563 | 563 | 'module' => 'aac_adts', |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | |
568 | 568 | |
569 | 569 | // AU - audio - NeXT/Sun AUdio (AU) |
570 | - 'au' => array ( |
|
570 | + 'au' => array( |
|
571 | 571 | 'pattern' => '^\.snd', |
572 | 572 | 'group' => 'audio', |
573 | 573 | 'module' => 'au', |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | ), |
576 | 576 | |
577 | 577 | // AVR - audio - Audio Visual Research |
578 | - 'avr' => array ( |
|
578 | + 'avr' => array( |
|
579 | 579 | 'pattern' => '^2BIT', |
580 | 580 | 'group' => 'audio', |
581 | 581 | 'module' => 'avr', |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | ), |
584 | 584 | |
585 | 585 | // BONK - audio - Bonk v0.9+ |
586 | - 'bonk' => array ( |
|
586 | + 'bonk' => array( |
|
587 | 587 | 'pattern' => '^\x00(BONK|INFO|META| ID3)', |
588 | 588 | 'group' => 'audio', |
589 | 589 | 'module' => 'bonk', |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | ), |
600 | 600 | |
601 | 601 | // FLAC - audio - Free Lossless Audio Codec |
602 | - 'flac' => array ( |
|
602 | + 'flac' => array( |
|
603 | 603 | 'pattern' => '^fLaC', |
604 | 604 | 'group' => 'audio', |
605 | 605 | 'module' => 'xiph', |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | ), |
608 | 608 | |
609 | 609 | // LA - audio - Lossless Audio (LA) |
610 | - 'la' => array ( |
|
610 | + 'la' => array( |
|
611 | 611 | 'pattern' => '^LA0[2-4]', |
612 | 612 | 'group' => 'audio', |
613 | 613 | 'module' => 'la', |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | ), |
616 | 616 | |
617 | 617 | // LPAC - audio - Lossless Predictive Audio Compression (LPAC) |
618 | - 'lpac' => array ( |
|
618 | + 'lpac' => array( |
|
619 | 619 | 'pattern' => '^LPAC', |
620 | 620 | 'group' => 'audio', |
621 | 621 | 'module' => 'lpac', |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | ), |
624 | 624 | |
625 | 625 | // MIDI - audio - MIDI (Musical Instrument Digital Interface) |
626 | - 'midi' => array ( |
|
626 | + 'midi' => array( |
|
627 | 627 | 'pattern' => '^MThd', |
628 | 628 | 'group' => 'audio', |
629 | 629 | 'module' => 'midi', |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | ), |
632 | 632 | |
633 | 633 | // MAC - audio - Monkey's Audio Compressor |
634 | - 'mac' => array ( |
|
634 | + 'mac' => array( |
|
635 | 635 | 'pattern' => '^MAC ', |
636 | 636 | 'group' => 'audio', |
637 | 637 | 'module' => 'monkey', |
@@ -639,31 +639,31 @@ discard block |
||
639 | 639 | ), |
640 | 640 | |
641 | 641 | // MOD - audio - MODule (assorted sub-formats) |
642 | - 'mod' => array ( |
|
642 | + 'mod' => array( |
|
643 | 643 | 'pattern' => '^.{1080}(M.K.|[5-9]CHN|[1-3][0-9]CH)', |
644 | 644 | 'mime_type' => 'audio/mod', |
645 | 645 | ), |
646 | 646 | |
647 | 647 | // MOD - audio - MODule (Impulse Tracker) |
648 | - 'it' => array ( |
|
648 | + 'it' => array( |
|
649 | 649 | 'pattern' => '^IMPM', |
650 | 650 | 'mime_type' => 'audio/it', |
651 | 651 | ), |
652 | 652 | |
653 | 653 | // MOD - audio - MODule (eXtended Module, various sub-formats) |
654 | - 'xm' => array ( |
|
654 | + 'xm' => array( |
|
655 | 655 | 'pattern' => '^Extended Module', |
656 | 656 | 'mime_type' => 'audio/xm', |
657 | 657 | ), |
658 | 658 | |
659 | 659 | // MOD - audio - MODule (ScreamTracker) |
660 | - 's3m' => array ( |
|
660 | + 's3m' => array( |
|
661 | 661 | 'pattern' => '^.{44}SCRM', |
662 | 662 | 'mime_type' => 'audio/s3m', |
663 | 663 | ), |
664 | 664 | |
665 | 665 | // MPC - audio - Musepack / MPEGplus SV7+ |
666 | - 'mpc' => array ( |
|
666 | + 'mpc' => array( |
|
667 | 667 | 'pattern' => '^(MP\+)', |
668 | 668 | 'group' => 'audio', |
669 | 669 | 'module' => 'mpc', |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | ), |
672 | 672 | |
673 | 673 | // MPC - audio - Musepack / MPEGplus SV4-6 |
674 | - 'mpc_old' => array ( |
|
674 | + 'mpc_old' => array( |
|
675 | 675 | 'pattern' => '^([\x00\x01\x10\x11\x40\x41\x50\x51\x80\x81\x90\x91\xC0\xC1\xD0\xD1][\x20-37][\x00\x20\x40\x60\x80\xA0\xC0\xE0])', |
676 | 676 | 'group' => 'audio', |
677 | 677 | 'module' => 'mpc_old', |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | |
681 | 681 | |
682 | 682 | // MP3 - audio - MPEG-audio Layer 3 (very similar to AAC-ADTS) |
683 | - 'mp3' => array ( |
|
683 | + 'mp3' => array( |
|
684 | 684 | 'pattern' => '^\xFF[\xE2-\xE7\xF2-\xF7\xFA-\xFF][\x00-\xEB]', |
685 | 685 | 'group' => 'audio', |
686 | 686 | 'module' => 'mp3', |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | ), |
689 | 689 | |
690 | 690 | // OFR - audio - OptimFROG |
691 | - 'ofr' => array ( |
|
691 | + 'ofr' => array( |
|
692 | 692 | 'pattern' => '^(\*RIFF|OFR)', |
693 | 693 | 'group' => 'audio', |
694 | 694 | 'module' => 'optimfrog', |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | ), |
697 | 697 | |
698 | 698 | // RKAU - audio - RKive AUdio compressor |
699 | - 'rkau' => array ( |
|
699 | + 'rkau' => array( |
|
700 | 700 | 'pattern' => '^RKA', |
701 | 701 | 'group' => 'audio', |
702 | 702 | 'module' => 'rkau', |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | ), |
705 | 705 | |
706 | 706 | // SHN - audio - Shorten |
707 | - 'shn' => array ( |
|
707 | + 'shn' => array( |
|
708 | 708 | 'pattern' => '^ajkg', |
709 | 709 | 'group' => 'audio', |
710 | 710 | 'module' => 'shorten', |
@@ -714,15 +714,15 @@ discard block |
||
714 | 714 | ), |
715 | 715 | |
716 | 716 | // TTA - audio - TTA Lossless Audio Compressor (http://tta.corecodec.org) |
717 | - 'tta' => array ( |
|
718 | - 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)' |
|
717 | + 'tta' => array( |
|
718 | + 'pattern' => '^TTA', // could also be '^TTA(\x01|\x02|\x03|2|1)' |
|
719 | 719 | 'group' => 'audio', |
720 | 720 | 'module' => 'tta', |
721 | 721 | 'mime_type' => 'application/octet-stream', |
722 | 722 | ), |
723 | 723 | |
724 | 724 | // VOC - audio - Creative Voice (VOC) |
725 | - 'voc' => array ( |
|
725 | + 'voc' => array( |
|
726 | 726 | 'pattern' => '^Creative Voice File', |
727 | 727 | 'group' => 'audio', |
728 | 728 | 'module' => 'voc', |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | ), |
731 | 731 | |
732 | 732 | // VQF - audio - transform-domain weighted interleave Vector Quantization Format (VQF) |
733 | - 'vqf' => array ( |
|
733 | + 'vqf' => array( |
|
734 | 734 | 'pattern' => '^TWIN', |
735 | 735 | 'group' => 'audio', |
736 | 736 | 'module' => 'vqf', |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | // Audio-Video formats |
750 | 750 | |
751 | 751 | // ASF - audio/video - Advanced Streaming Format, Windows Media Video, Windows Media Audio |
752 | - 'asf' => array ( |
|
752 | + 'asf' => array( |
|
753 | 753 | 'pattern' => '^\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C', |
754 | 754 | 'group' => 'audio-video', |
755 | 755 | 'module' => 'asf', |
@@ -771,13 +771,13 @@ discard block |
||
771 | 771 | ), |
772 | 772 | |
773 | 773 | // MKAV - audio/video - Mastroka |
774 | - 'matroska' => array ( |
|
774 | + 'matroska' => array( |
|
775 | 775 | 'pattern' => '^\x1A\x45\xDF\xA3', |
776 | 776 | 'mime_type' => 'application/octet-stream', |
777 | 777 | ), |
778 | 778 | |
779 | 779 | // MPEG - audio/video - MPEG (Moving Pictures Experts Group) |
780 | - 'mpeg' => array ( |
|
780 | + 'mpeg' => array( |
|
781 | 781 | 'pattern' => '^\x00\x00\x01(\xBA|\xB3)', |
782 | 782 | 'group' => 'audio-video', |
783 | 783 | 'module' => 'mpeg', |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | ), |
786 | 786 | |
787 | 787 | // NSV - audio/video - Nullsoft Streaming Video (NSV) |
788 | - 'nsv' => array ( |
|
788 | + 'nsv' => array( |
|
789 | 789 | 'pattern' => '^NSV[sf]', |
790 | 790 | 'group' => 'audio-video', |
791 | 791 | 'module' => 'nsv', |
@@ -793,7 +793,7 @@ discard block |
||
793 | 793 | ), |
794 | 794 | |
795 | 795 | // Ogg - audio/video - Ogg (Ogg Vorbis, OggFLAC, Speex, Ogg Theora(*), Ogg Tarkin(*)) |
796 | - 'ogg' => array ( |
|
796 | + 'ogg' => array( |
|
797 | 797 | 'pattern' => '^OggS', |
798 | 798 | 'group' => 'audio', |
799 | 799 | 'module' => 'xiph', |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | ), |
804 | 804 | |
805 | 805 | // QT - audio/video - Quicktime |
806 | - 'quicktime' => array ( |
|
806 | + 'quicktime' => array( |
|
807 | 807 | 'pattern' => '^.{4}(cmov|free|ftyp|mdat|moov|pnot|skip|wide)', |
808 | 808 | 'group' => 'audio-video', |
809 | 809 | 'module' => 'quicktime', |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | ), |
812 | 812 | |
813 | 813 | // RIFF - audio/video - Resource Interchange File Format (RIFF) / WAV / AVI / CD-audio / SDSS = renamed variant used by SmartSound QuickTracks (www.smartsound.com) / FORM = Audio Interchange File Format (AIFF) |
814 | - 'riff' => array ( |
|
814 | + 'riff' => array( |
|
815 | 815 | 'pattern' => '^(RIFF|SDSS|FORM)', |
816 | 816 | 'group' => 'audio-video', |
817 | 817 | 'module' => 'riff', |
@@ -820,7 +820,7 @@ discard block |
||
820 | 820 | ), |
821 | 821 | |
822 | 822 | // Real - audio/video - RealAudio, RealVideo |
823 | - 'real' => array ( |
|
823 | + 'real' => array( |
|
824 | 824 | 'pattern' => '^(\.RMF|.ra)', |
825 | 825 | 'group' => 'audio-video', |
826 | 826 | 'module' => 'real', |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | ), |
829 | 829 | |
830 | 830 | // SWF - audio/video - ShockWave Flash |
831 | - 'swf' => array ( |
|
831 | + 'swf' => array( |
|
832 | 832 | 'pattern' => '^(F|C)WS', |
833 | 833 | 'group' => 'audio-video', |
834 | 834 | 'module' => 'swf', |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | // Still-Image formats |
840 | 840 | |
841 | 841 | // BMP - still image - Bitmap (Windows, OS/2; uncompressed, RLE8, RLE4) |
842 | - 'bmp' => array ( |
|
842 | + 'bmp' => array( |
|
843 | 843 | 'pattern' => '^BM', |
844 | 844 | 'group' => 'graphic', |
845 | 845 | 'module' => 'bmp', |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | ), |
850 | 850 | |
851 | 851 | // GIF - still image - Graphics Interchange Format |
852 | - 'gif' => array ( |
|
852 | + 'gif' => array( |
|
853 | 853 | 'pattern' => '^GIF', |
854 | 854 | 'group' => 'graphic', |
855 | 855 | 'module' => 'gif', |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | ), |
860 | 860 | |
861 | 861 | // JPEG - still image - Joint Photographic Experts Group (JPEG) |
862 | - 'jpeg' => array ( |
|
862 | + 'jpeg' => array( |
|
863 | 863 | 'pattern' => '^\xFF\xD8\xFF', |
864 | 864 | 'group' => 'graphic', |
865 | 865 | 'module' => 'jpeg', |
@@ -869,7 +869,7 @@ discard block |
||
869 | 869 | ), |
870 | 870 | |
871 | 871 | // PCD - still image - Kodak Photo CD |
872 | - 'pcd' => array ( |
|
872 | + 'pcd' => array( |
|
873 | 873 | 'pattern' => '^.{2048}PCD_IPI\x00', |
874 | 874 | 'group' => 'graphic', |
875 | 875 | 'module' => 'pcd', |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | |
881 | 881 | |
882 | 882 | // PNG - still image - Portable Network Graphics (PNG) |
883 | - 'png' => array ( |
|
883 | + 'png' => array( |
|
884 | 884 | 'pattern' => '^\x89\x50\x4E\x47\x0D\x0A\x1A\x0A', |
885 | 885 | 'group' => 'graphic', |
886 | 886 | 'module' => 'png', |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | |
901 | 901 | |
902 | 902 | // TIFF - still image - Tagged Information File Format (TIFF) |
903 | - 'tiff' => array ( |
|
903 | + 'tiff' => array( |
|
904 | 904 | 'pattern' => '^(II\x2A\x00|MM\x00\x2A)', |
905 | 905 | 'group' => 'graphic', |
906 | 906 | 'module' => 'tiff', |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | ), |
921 | 921 | |
922 | 922 | // ISO - data - International Standards Organization (ISO) CD-ROM Image |
923 | - 'iso' => array ( |
|
923 | + 'iso' => array( |
|
924 | 924 | 'pattern' => '^.{32769}CD001', |
925 | 925 | 'group' => 'misc', |
926 | 926 | 'module' => 'iso', |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | ), |
939 | 939 | |
940 | 940 | // SZIP - audio - SZIP compressed data |
941 | - 'szip' => array ( |
|
941 | + 'szip' => array( |
|
942 | 942 | 'pattern' => '^SZ\x0A\x04', |
943 | 943 | 'group' => 'archive', |
944 | 944 | 'module' => 'szip', |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | |
970 | 970 | |
971 | 971 | // ZIP - data - ZIP compressed data |
972 | - 'zip' => array ( |
|
972 | + 'zip' => array( |
|
973 | 973 | 'pattern' => '^PK\x03\x04', |
974 | 974 | 'group' => 'archive', |
975 | 975 | 'module' => 'zip', |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | |
981 | 981 | |
982 | 982 | // PAR2 - data - Parity Volume Set Specification 2.0 |
983 | - 'par2' => array ( |
|
983 | + 'par2' => array( |
|
984 | 984 | 'pattern' => '^PAR2\x00PKT', |
985 | 985 | 'mime_type' => 'application/octet-stream', |
986 | 986 | 'fail_id3' => 'ERROR', |
@@ -1039,22 +1039,22 @@ discard block |
||
1039 | 1039 | protected function HandleAllTags() { |
1040 | 1040 | |
1041 | 1041 | // Key name => array (tag name, character encoding) |
1042 | - static $tags = array ( |
|
1043 | - 'asf' => array ('asf', 'UTF-16LE'), |
|
1044 | - 'midi' => array ('midi', 'ISO-8859-1'), |
|
1045 | - 'nsv' => array ('nsv', 'ISO-8859-1'), |
|
1046 | - 'ogg' => array ('vorbiscomment', 'UTF-8'), |
|
1047 | - 'png' => array ('png', 'UTF-8'), |
|
1048 | - 'tiff' => array ('tiff', 'ISO-8859-1'), |
|
1049 | - 'quicktime' => array ('quicktime', 'ISO-8859-1'), |
|
1050 | - 'real' => array ('real', 'ISO-8859-1'), |
|
1051 | - 'vqf' => array ('vqf', 'ISO-8859-1'), |
|
1052 | - 'zip' => array ('zip', 'ISO-8859-1'), |
|
1053 | - 'riff' => array ('riff', 'ISO-8859-1'), |
|
1054 | - 'lyrics3' => array ('lyrics3', 'ISO-8859-1'), |
|
1055 | - 'id3v1' => array ('id3v1', ''), // change below - cannot assign variable to static array |
|
1056 | - 'id3v2' => array ('id3v2', 'UTF-8'), // module converts all frames to UTF-8 |
|
1057 | - 'ape' => array ('ape', 'UTF-8') |
|
1042 | + static $tags = array( |
|
1043 | + 'asf' => array('asf', 'UTF-16LE'), |
|
1044 | + 'midi' => array('midi', 'ISO-8859-1'), |
|
1045 | + 'nsv' => array('nsv', 'ISO-8859-1'), |
|
1046 | + 'ogg' => array('vorbiscomment', 'UTF-8'), |
|
1047 | + 'png' => array('png', 'UTF-8'), |
|
1048 | + 'tiff' => array('tiff', 'ISO-8859-1'), |
|
1049 | + 'quicktime' => array('quicktime', 'ISO-8859-1'), |
|
1050 | + 'real' => array('real', 'ISO-8859-1'), |
|
1051 | + 'vqf' => array('vqf', 'ISO-8859-1'), |
|
1052 | + 'zip' => array('zip', 'ISO-8859-1'), |
|
1053 | + 'riff' => array('riff', 'ISO-8859-1'), |
|
1054 | + 'lyrics3' => array('lyrics3', 'ISO-8859-1'), |
|
1055 | + 'id3v1' => array('id3v1', ''), // change below - cannot assign variable to static array |
|
1056 | + 'id3v2' => array('id3v2', 'UTF-8'), // module converts all frames to UTF-8 |
|
1057 | + 'ape' => array('ape', 'UTF-8') |
|
1058 | 1058 | ); |
1059 | 1059 | $tags['id3v1'][1] = $this->encoding_id3v1; |
1060 | 1060 | |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | list($tag_name, $encoding) = $tag_name_encoding_array; |
1064 | 1064 | |
1065 | 1065 | // Fill in default encoding type if not already present |
1066 | - @$this->info[$comment_name] and $this->info[$comment_name]['encoding'] = $encoding; |
|
1066 | + @$this->info[$comment_name] and $this->info[$comment_name]['encoding'] = $encoding; |
|
1067 | 1067 | |
1068 | 1068 | // Copy comments if key name set |
1069 | 1069 | if (@$this->info[$comment_name]['comments']) { |
@@ -1142,11 +1142,11 @@ discard block |
||
1142 | 1142 | abstract class getid3_handler |
1143 | 1143 | { |
1144 | 1144 | |
1145 | - protected $getid3; // pointer |
|
1145 | + protected $getid3; // pointer |
|
1146 | 1146 | |
1147 | - protected $data_string_flag = false; // analyzing filepointer or string |
|
1148 | - protected $data_string; // string to analyze |
|
1149 | - protected $data_string_position = 0; // seek position in string |
|
1147 | + protected $data_string_flag = false; // analyzing filepointer or string |
|
1148 | + protected $data_string; // string to analyze |
|
1149 | + protected $data_string_position = 0; // seek position in string |
|
1150 | 1150 | |
1151 | 1151 | |
1152 | 1152 | public function __construct(getID3 $getid3) { |
@@ -1247,20 +1247,20 @@ discard block |
||
1247 | 1247 | public function __construct($filename) { |
1248 | 1248 | |
1249 | 1249 | if (!file_exists($filename)) { |
1250 | - throw new getid3_exception('File does not exist: "' . $filename . '"'); |
|
1250 | + throw new getid3_exception('File does not exist: "'.$filename.'"'); |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | if (!is_writeable($filename)) { |
1254 | - throw new getid3_exception('File is not writeable: "' . $filename . '"'); |
|
1254 | + throw new getid3_exception('File is not writeable: "'.$filename.'"'); |
|
1255 | 1255 | } |
1256 | 1256 | |
1257 | 1257 | if (!is_writeable(dirname($filename))) { |
1258 | - throw new getid3_exception('Directory is not writeable: ' . dirname($filename) . ' (need to write lock file).'); |
|
1258 | + throw new getid3_exception('Directory is not writeable: '.dirname($filename).' (need to write lock file).'); |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | 1261 | $this->user_abort = ignore_user_abort(true); |
1262 | 1262 | |
1263 | - $this->fp_lock = fopen($filename . '.getid3.lock', 'w'); |
|
1263 | + $this->fp_lock = fopen($filename.'.getid3.lock', 'w'); |
|
1264 | 1264 | flock($this->fp_lock, LOCK_EX); |
1265 | 1265 | |
1266 | 1266 | $this->filename = $filename; |
@@ -1271,7 +1271,7 @@ discard block |
||
1271 | 1271 | |
1272 | 1272 | flock($this->fp_lock, LOCK_UN); |
1273 | 1273 | fclose($this->fp_lock); |
1274 | - unlink($this->filename . '.getid3.lock'); |
|
1274 | + unlink($this->filename.'.getid3.lock'); |
|
1275 | 1275 | |
1276 | 1276 | ignore_user_abort($this->user_abort); |
1277 | 1277 | } |
@@ -1325,7 +1325,7 @@ discard block |
||
1325 | 1325 | |
1326 | 1326 | |
1327 | 1327 | // Convert number to Little Endian byte string |
1328 | - public static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) { |
|
1328 | + public static function LittleEndian2String($number, $minbytes = 1, $synchsafe = false) { |
|
1329 | 1329 | $intstring = ''; |
1330 | 1330 | while ($number > 0) { |
1331 | 1331 | if ($synchsafe) { |
@@ -1485,7 +1485,7 @@ discard block |
||
1485 | 1485 | } |
1486 | 1486 | |
1487 | 1487 | |
1488 | - public static function PrintHexBytes($string, $hex=true, $spaces=true, $html_safe=true) { |
|
1488 | + public static function PrintHexBytes($string, $hex = true, $spaces = true, $html_safe = true) { |
|
1489 | 1489 | |
1490 | 1490 | $return_string = ''; |
1491 | 1491 | for ($i = 0; $i < strlen($string); $i++) { |
@@ -1545,7 +1545,7 @@ discard block |
||
1545 | 1545 | |
1546 | 1546 | public static function NameLookup($name_code) { |
1547 | 1547 | |
1548 | - static $lookup = array ( |
|
1548 | + static $lookup = array( |
|
1549 | 1549 | 0 => 'not set', |
1550 | 1550 | 1 => 'Track Gain Adjustment', |
1551 | 1551 | 2 => 'Album Gain Adjustment' |
@@ -1558,7 +1558,7 @@ discard block |
||
1558 | 1558 | |
1559 | 1559 | public static function OriginatorLookup($originator_code) { |
1560 | 1560 | |
1561 | - static $lookup = array ( |
|
1561 | + static $lookup = array( |
|
1562 | 1562 | 0 => 'unspecified', |
1563 | 1563 | 1 => 'pre-set by artist/producer/mastering engineer', |
1564 | 1564 | 2 => 'set by user', |
@@ -1572,7 +1572,7 @@ discard block |
||
1572 | 1572 | |
1573 | 1573 | public static function AdjustmentLookup($raw_adjustment, $sign_bit) { |
1574 | 1574 | |
1575 | - return (float)$raw_adjustment / 10 * ($sign_bit == 1 ? -1 : 1); |
|
1575 | + return (float) $raw_adjustment / 10 * ($sign_bit == 1 ? -1 : 1); |
|
1576 | 1576 | } |
1577 | 1577 | |
1578 | 1578 |
@@ -198,8 +198,7 @@ discard block |
||
198 | 198 | $tag_class = 'getid3_' . $tag_name; |
199 | 199 | $tag = new $tag_class($this); |
200 | 200 | $tag->Analyze(); |
201 | - } |
|
202 | - catch (getid3_exception $e) { |
|
201 | + } catch (getid3_exception $e) { |
|
203 | 202 | throw $e; |
204 | 203 | } |
205 | 204 | } |
@@ -243,9 +242,7 @@ discard block |
||
243 | 242 | // use assume format on these if format detection failed |
244 | 243 | if (preg_match('/\.mp[123a]$/i', $filename)) { |
245 | 244 | $determined_format = $file_format_array['mp3']; |
246 | - } |
|
247 | - |
|
248 | - else { |
|
245 | + } else { |
|
249 | 246 | fclose($this->fp); |
250 | 247 | throw new getid3_exception('Unable to determine file format'); |
251 | 248 | } |
@@ -259,8 +256,7 @@ discard block |
||
259 | 256 | if ($determined_format['fail_id3'] === 'ERROR') { |
260 | 257 | fclose($this->fp); |
261 | 258 | throw new getid3_exception('ID3 tags not allowed on this file type.'); |
262 | - } |
|
263 | - elseif ($determined_format['fail_id3'] === 'WARNING') { |
|
259 | + } elseif ($determined_format['fail_id3'] === 'WARNING') { |
|
264 | 260 | @$this->info['id3v1'] and $this->warning('ID3v1 tags not allowed on this file type.'); |
265 | 261 | @$this->info['id3v2'] and $this->warning('ID3v2 tags not allowed on this file type.'); |
266 | 262 | } |
@@ -301,11 +297,9 @@ discard block |
||
301 | 297 | |
302 | 298 | try { |
303 | 299 | $this->option_analyze and $class->Analyze(); |
304 | - } |
|
305 | - catch (getid3_exception $e) { |
|
300 | + } catch (getid3_exception $e) { |
|
306 | 301 | throw $e; |
307 | - } |
|
308 | - catch (Exception $e) { |
|
302 | + } catch (Exception $e) { |
|
309 | 303 | throw new getid3_exception('Corrupt file.'); |
310 | 304 | } |
311 | 305 | |
@@ -460,8 +454,7 @@ discard block |
||
460 | 454 | |
461 | 455 | if (is_array($message)) { |
462 | 456 | $this->warnings = array_merge($this->warnings, $message); |
463 | - } |
|
464 | - else { |
|
457 | + } else { |
|
465 | 458 | $this->warnings[] = $message; |
466 | 459 | } |
467 | 460 | } |
@@ -1101,8 +1094,7 @@ discard block |
||
1101 | 1094 | if (empty($this->info['comments'][$tag_name])) { |
1102 | 1095 | |
1103 | 1096 | // fall through and append value |
1104 | - } |
|
1105 | - elseif ($tag_type == 'id3v1') { |
|
1097 | + } elseif ($tag_type == 'id3v1') { |
|
1106 | 1098 | |
1107 | 1099 | $new_value_length = strlen(trim($value)); |
1108 | 1100 | foreach ($this->info['comments'][$tag_name] as $existing_key => $existing_value) { |
@@ -1112,8 +1104,7 @@ discard block |
||
1112 | 1104 | break 2; |
1113 | 1105 | } |
1114 | 1106 | } |
1115 | - } |
|
1116 | - else { |
|
1107 | + } else { |
|
1117 | 1108 | |
1118 | 1109 | $new_value_length = strlen(trim($value)); |
1119 | 1110 | foreach ($this->info['comments'][$tag_name] as $existing_key => $existing_value) { |
@@ -276,6 +276,9 @@ discard block |
||
276 | 276 | public $pos; |
277 | 277 | |
278 | 278 | |
279 | + /** |
|
280 | + * @param string $bytes |
|
281 | + */ |
|
279 | 282 | public function AMFStream($bytes) { |
280 | 283 | |
281 | 284 | $this->bytes = $bytes; |
@@ -389,6 +392,9 @@ discard block |
||
389 | 392 | { |
390 | 393 | public $stream; |
391 | 394 | |
395 | + /** |
|
396 | + * @param AMFStream $stream |
|
397 | + */ |
|
392 | 398 | public function __construct($stream) { |
393 | 399 | |
394 | 400 | $this->stream = $stream; |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | */ |
48 | 48 | class getid3_flv extends getid3_handler { |
49 | 49 | |
50 | - const TAG_AUDIO = 8; |
|
51 | - const TAG_VIDEO = 9; |
|
50 | + const TAG_AUDIO = 8; |
|
51 | + const TAG_VIDEO = 9; |
|
52 | 52 | const TAG_META = 18; |
53 | 53 | |
54 | 54 | const VIDEO_H263 = 2; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | $info = &$this->getid3->info; |
62 | 62 | |
63 | - $info['flv'] = array (); |
|
63 | + $info['flv'] = array(); |
|
64 | 64 | $info_flv = &$info['flv']; |
65 | 65 | |
66 | 66 | fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $flv_header = fread($this->getid3->fp, 5); |
70 | 70 | |
71 | 71 | $info['fileformat'] = 'flv'; |
72 | - $info_flv['header']['signature'] = substr($flv_header, 0, 3); |
|
72 | + $info_flv['header']['signature'] = substr($flv_header, 0, 3); |
|
73 | 73 | $info_flv['header']['version'] = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1)); |
74 | 74 | $type_flags = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1)); |
75 | 75 | |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | |
88 | 88 | $this_tag_header = fread($this->getid3->fp, 16); |
89 | 89 | |
90 | - $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4)); |
|
91 | - $tag_type = getid3_lib::BigEndian2Int(substr($this_tag_header, 4, 1)); |
|
92 | - $data_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 5, 3)); |
|
93 | - $timestamp = getid3_lib::BigEndian2Int(substr($this_tag_header, 8, 3)); |
|
90 | + $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4)); |
|
91 | + $tag_type = getid3_lib::BigEndian2Int(substr($this_tag_header, 4, 1)); |
|
92 | + $data_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 5, 3)); |
|
93 | + $timestamp = getid3_lib::BigEndian2Int(substr($this_tag_header, 8, 3)); |
|
94 | 94 | $last_header_byte = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1)); |
95 | 95 | $next_offset = ftell($this->getid3->fp) - 1 + $data_length; |
96 | 96 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | case getid3_flv::TAG_AUDIO: |
100 | 100 | if (!isset($info_flv['audio']['audioFormat'])) { |
101 | - $info_flv['audio']['audioFormat'] = $last_header_byte & 0x07; |
|
101 | + $info_flv['audio']['audioFormat'] = $last_header_byte & 0x07; |
|
102 | 102 | $info_flv['audio']['audioRate'] = ($last_header_byte & 0x30) / 0x10; |
103 | 103 | $info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40; |
104 | 104 | $info_flv['audio']['audioType'] = ($last_header_byte & 0x80) / 0x80; |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | |
402 | 402 | $type = $this->stream->readByte(); |
403 | 403 | |
404 | - switch($type) { |
|
404 | + switch ($type) { |
|
405 | 405 | // Double |
406 | 406 | case 0: |
407 | 407 | $value = $this->readDouble(); |
@@ -56,522 +56,522 @@ |
||
56 | 56 | const VIDEO_VP6 = 4; |
57 | 57 | |
58 | 58 | |
59 | - public function Analyze() |
|
60 | - { |
|
61 | - $info = &$this->getid3->info; |
|
62 | - |
|
63 | - $info['flv'] = array (); |
|
64 | - $info_flv = &$info['flv']; |
|
65 | - |
|
66 | - fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); |
|
67 | - |
|
68 | - $flv_data_length = $info['avdataend'] - $info['avdataoffset']; |
|
69 | - $flv_header = fread($this->getid3->fp, 5); |
|
70 | - |
|
71 | - $info['fileformat'] = 'flv'; |
|
72 | - $info_flv['header']['signature'] = substr($flv_header, 0, 3); |
|
73 | - $info_flv['header']['version'] = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1)); |
|
74 | - $type_flags = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1)); |
|
75 | - |
|
76 | - $info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04); |
|
77 | - $info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01); |
|
78 | - |
|
79 | - $frame_size_data_length = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4)); |
|
80 | - $flv_header_frame_length = 9; |
|
81 | - if ($frame_size_data_length > $flv_header_frame_length) { |
|
82 | - fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR); |
|
83 | - } |
|
84 | - |
|
85 | - $duration = 0; |
|
86 | - while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) { |
|
87 | - |
|
88 | - $this_tag_header = fread($this->getid3->fp, 16); |
|
89 | - |
|
90 | - $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4)); |
|
91 | - $tag_type = getid3_lib::BigEndian2Int(substr($this_tag_header, 4, 1)); |
|
92 | - $data_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 5, 3)); |
|
93 | - $timestamp = getid3_lib::BigEndian2Int(substr($this_tag_header, 8, 3)); |
|
94 | - $last_header_byte = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1)); |
|
95 | - $next_offset = ftell($this->getid3->fp) - 1 + $data_length; |
|
96 | - |
|
97 | - switch ($tag_type) { |
|
98 | - |
|
99 | - case getid3_flv::TAG_AUDIO: |
|
100 | - if (!isset($info_flv['audio']['audioFormat'])) { |
|
101 | - $info_flv['audio']['audioFormat'] = $last_header_byte & 0x07; |
|
102 | - $info_flv['audio']['audioRate'] = ($last_header_byte & 0x30) / 0x10; |
|
103 | - $info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40; |
|
104 | - $info_flv['audio']['audioType'] = ($last_header_byte & 0x80) / 0x80; |
|
105 | - } |
|
106 | - break; |
|
107 | - |
|
108 | - |
|
109 | - case getid3_flv::TAG_VIDEO: |
|
110 | - if (!isset($info_flv['video']['videoCodec'])) { |
|
111 | - $info_flv['video']['videoCodec'] = $last_header_byte & 0x07; |
|
112 | - |
|
113 | - $flv_video_header = fread($this->getid3->fp, 11); |
|
114 | - |
|
115 | - if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) { |
|
116 | - |
|
117 | - $picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7; |
|
118 | - $picture_size_type = $picture_size_type & 0x0007; |
|
119 | - $info_flv['header']['videoSizeType'] = $picture_size_type; |
|
120 | - |
|
121 | - switch ($picture_size_type) { |
|
122 | - case 0: |
|
123 | - $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2)); |
|
124 | - $picture_size_enc <<= 1; |
|
125 | - $info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8; |
|
126 | - $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 6, 2)); |
|
127 | - $picture_size_enc <<= 1; |
|
128 | - $info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8; |
|
129 | - break; |
|
130 | - |
|
131 | - case 1: |
|
132 | - $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 4)); |
|
133 | - $picture_size_enc <<= 1; |
|
134 | - $info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16; |
|
135 | - |
|
136 | - $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 7, 4)); |
|
137 | - $picture_size_enc <<= 1; |
|
138 | - $info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16; |
|
139 | - break; |
|
140 | - |
|
141 | - case 2: |
|
142 | - $info['video']['resolution_x'] = 352; |
|
143 | - $info['video']['resolution_y'] = 288; |
|
144 | - break; |
|
145 | - |
|
146 | - case 3: |
|
147 | - $info['video']['resolution_x'] = 176; |
|
148 | - $info['video']['resolution_y'] = 144; |
|
149 | - break; |
|
150 | - |
|
151 | - case 4: |
|
152 | - $info['video']['resolution_x'] = 128; |
|
153 | - $info['video']['resolution_y'] = 96; |
|
154 | - break; |
|
155 | - |
|
156 | - case 5: |
|
157 | - $info['video']['resolution_x'] = 320; |
|
158 | - $info['video']['resolution_y'] = 240; |
|
159 | - break; |
|
160 | - |
|
161 | - case 6: |
|
162 | - $info['video']['resolution_x'] = 160; |
|
163 | - $info['video']['resolution_y'] = 120; |
|
164 | - break; |
|
165 | - |
|
166 | - default: |
|
167 | - $info['video']['resolution_x'] = 0; |
|
168 | - $info['video']['resolution_y'] = 0; |
|
169 | - break; |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - break; |
|
174 | - |
|
175 | - |
|
176 | - // Meta tag |
|
177 | - case getid3_flv::TAG_META: |
|
178 | - |
|
179 | - fseek($this->getid3->fp, -1, SEEK_CUR); |
|
180 | - $reader = new AMFReader(new AMFStream(fread($this->getid3->fp, $data_length))); |
|
181 | - $event_name = $reader->readData(); |
|
182 | - $info['meta'][$event_name] = $reader->readData(); |
|
183 | - unset($reader); |
|
184 | - |
|
185 | - $info['video']['frame_rate'] = @$info['meta']['onMetaData']['framerate']; |
|
186 | - $info['video']['resolution_x'] = @$info['meta']['onMetaData']['width']; |
|
187 | - $info['video']['resolution_y'] = @$info['meta']['onMetaData']['height']; |
|
188 | - break; |
|
189 | - |
|
190 | - default: |
|
191 | - // noop |
|
192 | - break; |
|
193 | - } |
|
194 | - |
|
195 | - if ($timestamp > $duration) { |
|
196 | - $duration = $timestamp; |
|
197 | - } |
|
198 | - |
|
199 | - fseek($this->getid3->fp, $next_offset, SEEK_SET); |
|
200 | - } |
|
201 | - |
|
202 | - if ($info['playtime_seconds'] = $duration / 1000) { |
|
203 | - $info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']; |
|
204 | - } |
|
205 | - |
|
206 | - if ($info_flv['header']['hasAudio']) { |
|
207 | - $info['audio']['codec'] = $this->FLVaudioFormat($info_flv['audio']['audioFormat']); |
|
208 | - $info['audio']['sample_rate'] = $this->FLVaudioRate($info_flv['audio']['audioRate']); |
|
209 | - $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']); |
|
210 | - |
|
211 | - $info['audio']['channels'] = $info_flv['audio']['audioType'] + 1; // 0=mono,1=stereo |
|
212 | - $info['audio']['lossless'] = ($info_flv['audio']['audioFormat'] ? false : true); // 0=uncompressed |
|
213 | - $info['audio']['dataformat'] = 'flv'; |
|
214 | - } |
|
215 | - if (@$info_flv['header']['hasVideo']) { |
|
216 | - $info['video']['codec'] = $this->FLVvideoCodec($info_flv['video']['videoCodec']); |
|
217 | - $info['video']['dataformat'] = 'flv'; |
|
218 | - $info['video']['lossless'] = false; |
|
219 | - } |
|
220 | - |
|
221 | - return true; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - public static function FLVaudioFormat($id) { |
|
226 | - |
|
227 | - static $lookup = array( |
|
228 | - 0 => 'uncompressed', |
|
229 | - 1 => 'ADPCM', |
|
230 | - 2 => 'mp3', |
|
231 | - 5 => 'Nellymoser 8kHz mono', |
|
232 | - 6 => 'Nellymoser', |
|
233 | - ); |
|
234 | - return (@$lookup[$id] ? @$lookup[$id] : false); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - public static function FLVaudioRate($id) { |
|
239 | - |
|
240 | - static $lookup = array( |
|
241 | - 0 => 5500, |
|
242 | - 1 => 11025, |
|
243 | - 2 => 22050, |
|
244 | - 3 => 44100, |
|
245 | - ); |
|
246 | - return (@$lookup[$id] ? @$lookup[$id] : false); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - public static function FLVaudioBitDepth($id) { |
|
251 | - |
|
252 | - static $lookup = array( |
|
253 | - 0 => 8, |
|
254 | - 1 => 16, |
|
255 | - ); |
|
256 | - return (@$lookup[$id] ? @$lookup[$id] : false); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - public static function FLVvideoCodec($id) { |
|
261 | - |
|
262 | - static $lookup = array( |
|
263 | - getid3_flv::VIDEO_H263 => 'Sorenson H.263', |
|
264 | - getid3_flv::VIDEO_SCREEN => 'Screen video', |
|
265 | - getid3_flv::VIDEO_VP6 => 'On2 VP6', |
|
266 | - ); |
|
267 | - return (@$lookup[$id] ? @$lookup[$id] : false); |
|
268 | - } |
|
59 | + public function Analyze() |
|
60 | + { |
|
61 | + $info = &$this->getid3->info; |
|
62 | + |
|
63 | + $info['flv'] = array (); |
|
64 | + $info_flv = &$info['flv']; |
|
65 | + |
|
66 | + fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET); |
|
67 | + |
|
68 | + $flv_data_length = $info['avdataend'] - $info['avdataoffset']; |
|
69 | + $flv_header = fread($this->getid3->fp, 5); |
|
70 | + |
|
71 | + $info['fileformat'] = 'flv'; |
|
72 | + $info_flv['header']['signature'] = substr($flv_header, 0, 3); |
|
73 | + $info_flv['header']['version'] = getid3_lib::BigEndian2Int(substr($flv_header, 3, 1)); |
|
74 | + $type_flags = getid3_lib::BigEndian2Int(substr($flv_header, 4, 1)); |
|
75 | + |
|
76 | + $info_flv['header']['hasAudio'] = (bool) ($type_flags & 0x04); |
|
77 | + $info_flv['header']['hasVideo'] = (bool) ($type_flags & 0x01); |
|
78 | + |
|
79 | + $frame_size_data_length = getid3_lib::BigEndian2Int(fread($this->getid3->fp, 4)); |
|
80 | + $flv_header_frame_length = 9; |
|
81 | + if ($frame_size_data_length > $flv_header_frame_length) { |
|
82 | + fseek($this->getid3->fp, $frame_size_data_length - $flv_header_frame_length, SEEK_CUR); |
|
83 | + } |
|
84 | + |
|
85 | + $duration = 0; |
|
86 | + while ((ftell($this->getid3->fp) + 1) < $info['avdataend']) { |
|
87 | + |
|
88 | + $this_tag_header = fread($this->getid3->fp, 16); |
|
89 | + |
|
90 | + $previous_tag_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 0, 4)); |
|
91 | + $tag_type = getid3_lib::BigEndian2Int(substr($this_tag_header, 4, 1)); |
|
92 | + $data_length = getid3_lib::BigEndian2Int(substr($this_tag_header, 5, 3)); |
|
93 | + $timestamp = getid3_lib::BigEndian2Int(substr($this_tag_header, 8, 3)); |
|
94 | + $last_header_byte = getid3_lib::BigEndian2Int(substr($this_tag_header, 15, 1)); |
|
95 | + $next_offset = ftell($this->getid3->fp) - 1 + $data_length; |
|
96 | + |
|
97 | + switch ($tag_type) { |
|
98 | + |
|
99 | + case getid3_flv::TAG_AUDIO: |
|
100 | + if (!isset($info_flv['audio']['audioFormat'])) { |
|
101 | + $info_flv['audio']['audioFormat'] = $last_header_byte & 0x07; |
|
102 | + $info_flv['audio']['audioRate'] = ($last_header_byte & 0x30) / 0x10; |
|
103 | + $info_flv['audio']['audioSampleSize'] = ($last_header_byte & 0x40) / 0x40; |
|
104 | + $info_flv['audio']['audioType'] = ($last_header_byte & 0x80) / 0x80; |
|
105 | + } |
|
106 | + break; |
|
107 | + |
|
108 | + |
|
109 | + case getid3_flv::TAG_VIDEO: |
|
110 | + if (!isset($info_flv['video']['videoCodec'])) { |
|
111 | + $info_flv['video']['videoCodec'] = $last_header_byte & 0x07; |
|
112 | + |
|
113 | + $flv_video_header = fread($this->getid3->fp, 11); |
|
114 | + |
|
115 | + if ($info_flv['video']['videoCodec'] != getid3_flv::VIDEO_VP6) { |
|
116 | + |
|
117 | + $picture_size_type = (getid3_lib::BigEndian2Int(substr($flv_video_header, 3, 2))) >> 7; |
|
118 | + $picture_size_type = $picture_size_type & 0x0007; |
|
119 | + $info_flv['header']['videoSizeType'] = $picture_size_type; |
|
120 | + |
|
121 | + switch ($picture_size_type) { |
|
122 | + case 0: |
|
123 | + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 2)); |
|
124 | + $picture_size_enc <<= 1; |
|
125 | + $info['video']['resolution_x'] = ($picture_size_enc & 0xFF00) >> 8; |
|
126 | + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 6, 2)); |
|
127 | + $picture_size_enc <<= 1; |
|
128 | + $info['video']['resolution_y'] = ($picture_size_enc & 0xFF00) >> 8; |
|
129 | + break; |
|
130 | + |
|
131 | + case 1: |
|
132 | + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 5, 4)); |
|
133 | + $picture_size_enc <<= 1; |
|
134 | + $info['video']['resolution_x'] = ($picture_size_enc & 0xFFFF0000) >> 16; |
|
135 | + |
|
136 | + $picture_size_enc = getid3_lib::BigEndian2Int(substr($flv_video_header, 7, 4)); |
|
137 | + $picture_size_enc <<= 1; |
|
138 | + $info['video']['resolution_y'] = ($picture_size_enc & 0xFFFF0000) >> 16; |
|
139 | + break; |
|
140 | + |
|
141 | + case 2: |
|
142 | + $info['video']['resolution_x'] = 352; |
|
143 | + $info['video']['resolution_y'] = 288; |
|
144 | + break; |
|
145 | + |
|
146 | + case 3: |
|
147 | + $info['video']['resolution_x'] = 176; |
|
148 | + $info['video']['resolution_y'] = 144; |
|
149 | + break; |
|
150 | + |
|
151 | + case 4: |
|
152 | + $info['video']['resolution_x'] = 128; |
|
153 | + $info['video']['resolution_y'] = 96; |
|
154 | + break; |
|
155 | + |
|
156 | + case 5: |
|
157 | + $info['video']['resolution_x'] = 320; |
|
158 | + $info['video']['resolution_y'] = 240; |
|
159 | + break; |
|
160 | + |
|
161 | + case 6: |
|
162 | + $info['video']['resolution_x'] = 160; |
|
163 | + $info['video']['resolution_y'] = 120; |
|
164 | + break; |
|
165 | + |
|
166 | + default: |
|
167 | + $info['video']['resolution_x'] = 0; |
|
168 | + $info['video']['resolution_y'] = 0; |
|
169 | + break; |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + break; |
|
174 | + |
|
175 | + |
|
176 | + // Meta tag |
|
177 | + case getid3_flv::TAG_META: |
|
178 | + |
|
179 | + fseek($this->getid3->fp, -1, SEEK_CUR); |
|
180 | + $reader = new AMFReader(new AMFStream(fread($this->getid3->fp, $data_length))); |
|
181 | + $event_name = $reader->readData(); |
|
182 | + $info['meta'][$event_name] = $reader->readData(); |
|
183 | + unset($reader); |
|
184 | + |
|
185 | + $info['video']['frame_rate'] = @$info['meta']['onMetaData']['framerate']; |
|
186 | + $info['video']['resolution_x'] = @$info['meta']['onMetaData']['width']; |
|
187 | + $info['video']['resolution_y'] = @$info['meta']['onMetaData']['height']; |
|
188 | + break; |
|
189 | + |
|
190 | + default: |
|
191 | + // noop |
|
192 | + break; |
|
193 | + } |
|
194 | + |
|
195 | + if ($timestamp > $duration) { |
|
196 | + $duration = $timestamp; |
|
197 | + } |
|
198 | + |
|
199 | + fseek($this->getid3->fp, $next_offset, SEEK_SET); |
|
200 | + } |
|
201 | + |
|
202 | + if ($info['playtime_seconds'] = $duration / 1000) { |
|
203 | + $info['bitrate'] = ($info['avdataend'] - $info['avdataoffset']) / $info['playtime_seconds']; |
|
204 | + } |
|
205 | + |
|
206 | + if ($info_flv['header']['hasAudio']) { |
|
207 | + $info['audio']['codec'] = $this->FLVaudioFormat($info_flv['audio']['audioFormat']); |
|
208 | + $info['audio']['sample_rate'] = $this->FLVaudioRate($info_flv['audio']['audioRate']); |
|
209 | + $info['audio']['bits_per_sample'] = $this->FLVaudioBitDepth($info_flv['audio']['audioSampleSize']); |
|
210 | + |
|
211 | + $info['audio']['channels'] = $info_flv['audio']['audioType'] + 1; // 0=mono,1=stereo |
|
212 | + $info['audio']['lossless'] = ($info_flv['audio']['audioFormat'] ? false : true); // 0=uncompressed |
|
213 | + $info['audio']['dataformat'] = 'flv'; |
|
214 | + } |
|
215 | + if (@$info_flv['header']['hasVideo']) { |
|
216 | + $info['video']['codec'] = $this->FLVvideoCodec($info_flv['video']['videoCodec']); |
|
217 | + $info['video']['dataformat'] = 'flv'; |
|
218 | + $info['video']['lossless'] = false; |
|
219 | + } |
|
220 | + |
|
221 | + return true; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + public static function FLVaudioFormat($id) { |
|
226 | + |
|
227 | + static $lookup = array( |
|
228 | + 0 => 'uncompressed', |
|
229 | + 1 => 'ADPCM', |
|
230 | + 2 => 'mp3', |
|
231 | + 5 => 'Nellymoser 8kHz mono', |
|
232 | + 6 => 'Nellymoser', |
|
233 | + ); |
|
234 | + return (@$lookup[$id] ? @$lookup[$id] : false); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + public static function FLVaudioRate($id) { |
|
239 | + |
|
240 | + static $lookup = array( |
|
241 | + 0 => 5500, |
|
242 | + 1 => 11025, |
|
243 | + 2 => 22050, |
|
244 | + 3 => 44100, |
|
245 | + ); |
|
246 | + return (@$lookup[$id] ? @$lookup[$id] : false); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + public static function FLVaudioBitDepth($id) { |
|
251 | + |
|
252 | + static $lookup = array( |
|
253 | + 0 => 8, |
|
254 | + 1 => 16, |
|
255 | + ); |
|
256 | + return (@$lookup[$id] ? @$lookup[$id] : false); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + public static function FLVvideoCodec($id) { |
|
261 | + |
|
262 | + static $lookup = array( |
|
263 | + getid3_flv::VIDEO_H263 => 'Sorenson H.263', |
|
264 | + getid3_flv::VIDEO_SCREEN => 'Screen video', |
|
265 | + getid3_flv::VIDEO_VP6 => 'On2 VP6', |
|
266 | + ); |
|
267 | + return (@$lookup[$id] ? @$lookup[$id] : false); |
|
268 | + } |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | |
272 | 272 | |
273 | 273 | class AMFStream |
274 | 274 | { |
275 | - public $bytes; |
|
276 | - public $pos; |
|
275 | + public $bytes; |
|
276 | + public $pos; |
|
277 | 277 | |
278 | 278 | |
279 | - public function AMFStream($bytes) { |
|
279 | + public function AMFStream($bytes) { |
|
280 | 280 | |
281 | - $this->bytes = $bytes; |
|
282 | - $this->pos = 0; |
|
283 | - } |
|
281 | + $this->bytes = $bytes; |
|
282 | + $this->pos = 0; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | - public function readByte() { |
|
286 | + public function readByte() { |
|
287 | 287 | |
288 | - return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); |
|
289 | - } |
|
288 | + return getid3_lib::BigEndian2Int(substr($this->bytes, $this->pos++, 1)); |
|
289 | + } |
|
290 | 290 | |
291 | 291 | |
292 | - public function readInt() { |
|
292 | + public function readInt() { |
|
293 | 293 | |
294 | - return ($this->readByte() << 8) + $this->readByte(); |
|
295 | - } |
|
294 | + return ($this->readByte() << 8) + $this->readByte(); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | |
298 | - public function readLong() { |
|
298 | + public function readLong() { |
|
299 | 299 | |
300 | - return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); |
|
301 | - } |
|
300 | + return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte(); |
|
301 | + } |
|
302 | 302 | |
303 | 303 | |
304 | - public function readDouble() { |
|
304 | + public function readDouble() { |
|
305 | 305 | |
306 | - return getid3_lib::BigEndian2Float($this->read(8)); |
|
307 | - } |
|
306 | + return getid3_lib::BigEndian2Float($this->read(8)); |
|
307 | + } |
|
308 | 308 | |
309 | 309 | |
310 | - public function readUTF() { |
|
310 | + public function readUTF() { |
|
311 | 311 | |
312 | - $length = $this->readInt(); |
|
313 | - return $this->read($length); |
|
314 | - } |
|
312 | + $length = $this->readInt(); |
|
313 | + return $this->read($length); |
|
314 | + } |
|
315 | 315 | |
316 | 316 | |
317 | - public function readLongUTF() { |
|
317 | + public function readLongUTF() { |
|
318 | 318 | |
319 | - $length = $this->readLong(); |
|
320 | - return $this->read($length); |
|
321 | - } |
|
319 | + $length = $this->readLong(); |
|
320 | + return $this->read($length); |
|
321 | + } |
|
322 | 322 | |
323 | 323 | |
324 | - public function read($length) { |
|
324 | + public function read($length) { |
|
325 | 325 | |
326 | - $val = substr($this->bytes, $this->pos, $length); |
|
327 | - $this->pos += $length; |
|
328 | - return $val; |
|
329 | - } |
|
326 | + $val = substr($this->bytes, $this->pos, $length); |
|
327 | + $this->pos += $length; |
|
328 | + return $val; |
|
329 | + } |
|
330 | 330 | |
331 | 331 | |
332 | - public function peekByte() { |
|
332 | + public function peekByte() { |
|
333 | 333 | |
334 | - $pos = $this->pos; |
|
335 | - $val = $this->readByte(); |
|
336 | - $this->pos = $pos; |
|
337 | - return $val; |
|
338 | - } |
|
334 | + $pos = $this->pos; |
|
335 | + $val = $this->readByte(); |
|
336 | + $this->pos = $pos; |
|
337 | + return $val; |
|
338 | + } |
|
339 | 339 | |
340 | 340 | |
341 | - public function peekInt() { |
|
341 | + public function peekInt() { |
|
342 | 342 | |
343 | - $pos = $this->pos; |
|
344 | - $val = $this->readInt(); |
|
345 | - $this->pos = $pos; |
|
346 | - return $val; |
|
347 | - } |
|
343 | + $pos = $this->pos; |
|
344 | + $val = $this->readInt(); |
|
345 | + $this->pos = $pos; |
|
346 | + return $val; |
|
347 | + } |
|
348 | 348 | |
349 | 349 | |
350 | - public function peekLong() { |
|
350 | + public function peekLong() { |
|
351 | 351 | |
352 | - $pos = $this->pos; |
|
353 | - $val = $this->readLong(); |
|
354 | - $this->pos = $pos; |
|
355 | - return $val; |
|
356 | - } |
|
352 | + $pos = $this->pos; |
|
353 | + $val = $this->readLong(); |
|
354 | + $this->pos = $pos; |
|
355 | + return $val; |
|
356 | + } |
|
357 | 357 | |
358 | 358 | |
359 | - public function peekDouble() { |
|
359 | + public function peekDouble() { |
|
360 | 360 | |
361 | - $pos = $this->pos; |
|
362 | - $val = $this->readDouble(); |
|
363 | - $this->pos = $pos; |
|
364 | - return $val; |
|
365 | - } |
|
361 | + $pos = $this->pos; |
|
362 | + $val = $this->readDouble(); |
|
363 | + $this->pos = $pos; |
|
364 | + return $val; |
|
365 | + } |
|
366 | 366 | |
367 | 367 | |
368 | - public function peekUTF() { |
|
368 | + public function peekUTF() { |
|
369 | 369 | |
370 | - $pos = $this->pos; |
|
371 | - $val = $this->readUTF(); |
|
372 | - $this->pos = $pos; |
|
373 | - return $val; |
|
374 | - } |
|
370 | + $pos = $this->pos; |
|
371 | + $val = $this->readUTF(); |
|
372 | + $this->pos = $pos; |
|
373 | + return $val; |
|
374 | + } |
|
375 | 375 | |
376 | 376 | |
377 | - public function peekLongUTF() { |
|
377 | + public function peekLongUTF() { |
|
378 | 378 | |
379 | - $pos = $this->pos; |
|
380 | - $val = $this->readLongUTF(); |
|
381 | - $this->pos = $pos; |
|
382 | - return $val; |
|
383 | - } |
|
379 | + $pos = $this->pos; |
|
380 | + $val = $this->readLongUTF(); |
|
381 | + $this->pos = $pos; |
|
382 | + return $val; |
|
383 | + } |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | |
387 | 387 | |
388 | 388 | class AMFReader |
389 | 389 | { |
390 | - public $stream; |
|
390 | + public $stream; |
|
391 | 391 | |
392 | - public function __construct($stream) { |
|
392 | + public function __construct($stream) { |
|
393 | 393 | |
394 | - $this->stream = $stream; |
|
395 | - } |
|
394 | + $this->stream = $stream; |
|
395 | + } |
|
396 | 396 | |
397 | 397 | |
398 | - public function readData() { |
|
398 | + public function readData() { |
|
399 | 399 | |
400 | - $value = null; |
|
400 | + $value = null; |
|
401 | 401 | |
402 | - $type = $this->stream->readByte(); |
|
402 | + $type = $this->stream->readByte(); |
|
403 | 403 | |
404 | - switch($type) { |
|
405 | - // Double |
|
406 | - case 0: |
|
407 | - $value = $this->readDouble(); |
|
408 | - break; |
|
404 | + switch($type) { |
|
405 | + // Double |
|
406 | + case 0: |
|
407 | + $value = $this->readDouble(); |
|
408 | + break; |
|
409 | 409 | |
410 | - // Boolean |
|
411 | - case 1: |
|
412 | - $value = $this->readBoolean(); |
|
413 | - break; |
|
410 | + // Boolean |
|
411 | + case 1: |
|
412 | + $value = $this->readBoolean(); |
|
413 | + break; |
|
414 | 414 | |
415 | - // String |
|
416 | - case 2: |
|
417 | - $value = $this->readString(); |
|
418 | - break; |
|
415 | + // String |
|
416 | + case 2: |
|
417 | + $value = $this->readString(); |
|
418 | + break; |
|
419 | 419 | |
420 | - // Object |
|
421 | - case 3: |
|
422 | - $value = $this->readObject(); |
|
423 | - break; |
|
420 | + // Object |
|
421 | + case 3: |
|
422 | + $value = $this->readObject(); |
|
423 | + break; |
|
424 | 424 | |
425 | - // null |
|
426 | - case 6: |
|
427 | - return null; |
|
428 | - break; |
|
425 | + // null |
|
426 | + case 6: |
|
427 | + return null; |
|
428 | + break; |
|
429 | 429 | |
430 | - // Mixed array |
|
431 | - case 8: |
|
432 | - $value = $this->readMixedArray(); |
|
433 | - break; |
|
430 | + // Mixed array |
|
431 | + case 8: |
|
432 | + $value = $this->readMixedArray(); |
|
433 | + break; |
|
434 | 434 | |
435 | - // Array |
|
436 | - case 10: |
|
437 | - $value = $this->readArray(); |
|
438 | - break; |
|
435 | + // Array |
|
436 | + case 10: |
|
437 | + $value = $this->readArray(); |
|
438 | + break; |
|
439 | 439 | |
440 | - // Date |
|
441 | - case 11: |
|
442 | - $value = $this->readDate(); |
|
443 | - break; |
|
440 | + // Date |
|
441 | + case 11: |
|
442 | + $value = $this->readDate(); |
|
443 | + break; |
|
444 | 444 | |
445 | - // Long string |
|
446 | - case 13: |
|
447 | - $value = $this->readLongString(); |
|
448 | - break; |
|
445 | + // Long string |
|
446 | + case 13: |
|
447 | + $value = $this->readLongString(); |
|
448 | + break; |
|
449 | 449 | |
450 | - // XML (handled as string) |
|
451 | - case 15: |
|
452 | - $value = $this->readXML(); |
|
453 | - break; |
|
450 | + // XML (handled as string) |
|
451 | + case 15: |
|
452 | + $value = $this->readXML(); |
|
453 | + break; |
|
454 | 454 | |
455 | - // Typed object (handled as object) |
|
456 | - case 16: |
|
457 | - $value = $this->readTypedObject(); |
|
458 | - break; |
|
455 | + // Typed object (handled as object) |
|
456 | + case 16: |
|
457 | + $value = $this->readTypedObject(); |
|
458 | + break; |
|
459 | 459 | |
460 | - // Long string |
|
461 | - default: |
|
462 | - $value = '(unknown or unsupported data type)'; |
|
463 | - break; |
|
464 | - } |
|
460 | + // Long string |
|
461 | + default: |
|
462 | + $value = '(unknown or unsupported data type)'; |
|
463 | + break; |
|
464 | + } |
|
465 | 465 | |
466 | - return $value; |
|
467 | - } |
|
466 | + return $value; |
|
467 | + } |
|
468 | 468 | |
469 | 469 | |
470 | - public function readDouble() { |
|
470 | + public function readDouble() { |
|
471 | 471 | |
472 | - return $this->stream->readDouble(); |
|
473 | - } |
|
472 | + return $this->stream->readDouble(); |
|
473 | + } |
|
474 | 474 | |
475 | 475 | |
476 | - public function readBoolean() { |
|
476 | + public function readBoolean() { |
|
477 | 477 | |
478 | - return $this->stream->readByte() == 1; |
|
479 | - } |
|
478 | + return $this->stream->readByte() == 1; |
|
479 | + } |
|
480 | 480 | |
481 | 481 | |
482 | - public function readString() { |
|
482 | + public function readString() { |
|
483 | 483 | |
484 | - return $this->stream->readUTF(); |
|
485 | - } |
|
484 | + return $this->stream->readUTF(); |
|
485 | + } |
|
486 | 486 | |
487 | 487 | |
488 | - public function readObject() { |
|
488 | + public function readObject() { |
|
489 | 489 | |
490 | - // Get highest numerical index - ignored |
|
491 | - $highestIndex = $this->stream->readLong(); |
|
490 | + // Get highest numerical index - ignored |
|
491 | + $highestIndex = $this->stream->readLong(); |
|
492 | 492 | |
493 | - $data = array(); |
|
493 | + $data = array(); |
|
494 | 494 | |
495 | - while ($key = $this->stream->readUTF()) { |
|
496 | - // Mixed array record ends with empty string (0x00 0x00) and 0x09 |
|
497 | - if (($key == '') && ($this->stream->peekByte() == 0x09)) { |
|
498 | - // Consume byte |
|
499 | - $this->stream->readByte(); |
|
500 | - break; |
|
501 | - } |
|
495 | + while ($key = $this->stream->readUTF()) { |
|
496 | + // Mixed array record ends with empty string (0x00 0x00) and 0x09 |
|
497 | + if (($key == '') && ($this->stream->peekByte() == 0x09)) { |
|
498 | + // Consume byte |
|
499 | + $this->stream->readByte(); |
|
500 | + break; |
|
501 | + } |
|
502 | 502 | |
503 | - $data[$key] = $this->readData(); |
|
504 | - } |
|
503 | + $data[$key] = $this->readData(); |
|
504 | + } |
|
505 | 505 | |
506 | - return $data; |
|
507 | - } |
|
506 | + return $data; |
|
507 | + } |
|
508 | 508 | |
509 | 509 | |
510 | - public function readMixedArray() { |
|
510 | + public function readMixedArray() { |
|
511 | 511 | |
512 | - // Get highest numerical index - ignored |
|
513 | - $highestIndex = $this->stream->readLong(); |
|
512 | + // Get highest numerical index - ignored |
|
513 | + $highestIndex = $this->stream->readLong(); |
|
514 | 514 | |
515 | - $data = array(); |
|
515 | + $data = array(); |
|
516 | 516 | |
517 | - while ($key = $this->stream->readUTF()) { |
|
518 | - // Mixed array record ends with empty string (0x00 0x00) and 0x09 |
|
519 | - if (($key == '') && ($this->stream->peekByte() == 0x09)) { |
|
520 | - // Consume byte |
|
521 | - $this->stream->readByte(); |
|
522 | - break; |
|
523 | - } |
|
517 | + while ($key = $this->stream->readUTF()) { |
|
518 | + // Mixed array record ends with empty string (0x00 0x00) and 0x09 |
|
519 | + if (($key == '') && ($this->stream->peekByte() == 0x09)) { |
|
520 | + // Consume byte |
|
521 | + $this->stream->readByte(); |
|
522 | + break; |
|
523 | + } |
|
524 | 524 | |
525 | - if (is_numeric($key)) { |
|
526 | - $key = (float) $key; |
|
527 | - } |
|
525 | + if (is_numeric($key)) { |
|
526 | + $key = (float) $key; |
|
527 | + } |
|
528 | 528 | |
529 | - $data[$key] = $this->readData(); |
|
530 | - } |
|
529 | + $data[$key] = $this->readData(); |
|
530 | + } |
|
531 | 531 | |
532 | - return $data; |
|
533 | - } |
|
532 | + return $data; |
|
533 | + } |
|
534 | 534 | |
535 | 535 | |
536 | - public function readArray() { |
|
536 | + public function readArray() { |
|
537 | 537 | |
538 | - $length = $this->stream->readLong(); |
|
538 | + $length = $this->stream->readLong(); |
|
539 | 539 | |
540 | - $data = array(); |
|
540 | + $data = array(); |
|
541 | 541 | |
542 | - for ($i = 0; $i < count($length); $i++) { |
|
543 | - $data[] = $this->readData(); |
|
544 | - } |
|
542 | + for ($i = 0; $i < count($length); $i++) { |
|
543 | + $data[] = $this->readData(); |
|
544 | + } |
|
545 | 545 | |
546 | - return $data; |
|
547 | - } |
|
546 | + return $data; |
|
547 | + } |
|
548 | 548 | |
549 | 549 | |
550 | - public function readDate() { |
|
550 | + public function readDate() { |
|
551 | 551 | |
552 | - $timestamp = $this->stream->readDouble(); |
|
553 | - $timezone = $this->stream->readInt(); |
|
554 | - return $timestamp; |
|
555 | - } |
|
552 | + $timestamp = $this->stream->readDouble(); |
|
553 | + $timezone = $this->stream->readInt(); |
|
554 | + return $timestamp; |
|
555 | + } |
|
556 | 556 | |
557 | 557 | |
558 | - public function readLongString() { |
|
558 | + public function readLongString() { |
|
559 | 559 | |
560 | - return $this->stream->readLongUTF(); |
|
561 | - } |
|
560 | + return $this->stream->readLongUTF(); |
|
561 | + } |
|
562 | 562 | |
563 | 563 | |
564 | - public function readXML() { |
|
564 | + public function readXML() { |
|
565 | 565 | |
566 | - return $this->stream->readLongUTF(); |
|
567 | - } |
|
566 | + return $this->stream->readLongUTF(); |
|
567 | + } |
|
568 | 568 | |
569 | 569 | |
570 | - public function readTypedObject() { |
|
570 | + public function readTypedObject() { |
|
571 | 571 | |
572 | - $className = $this->stream->readUTF(); |
|
573 | - return $this->readObject(); |
|
574 | - } |
|
572 | + $className = $this->stream->readUTF(); |
|
573 | + return $this->readObject(); |
|
574 | + } |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | ?> |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * This functions stores the glossary in the database |
87 | 87 | * |
88 | 88 | * @param array Array of title + description (glossary_title => $title, glossary_comment => $comment) |
89 | - * @return mixed Term id on success, false on failure |
|
89 | + * @return false|string Term id on success, false on failure |
|
90 | 90 | * @author Christian Fasanando <[email protected]> |
91 | 91 | * @author Patrick Cool <[email protected]>, Ghent University, Belgium |
92 | 92 | * @version januari 2009, dokeos 1.8.6 |
@@ -443,6 +443,10 @@ discard block |
||
443 | 443 | * @param integer Number of items to collect |
444 | 444 | * @param string Name of column on which to order |
445 | 445 | * @param string Whether to sort in ascending (ASC) or descending (DESC) |
446 | + * @param integer $from |
|
447 | + * @param integer $number_of_items |
|
448 | + * @param integer $column |
|
449 | + * @param string $direction |
|
446 | 450 | * @return unknown |
447 | 451 | * |
448 | 452 | * @author Patrick Cool <[email protected]> |
@@ -520,6 +524,7 @@ discard block |
||
520 | 524 | * @param integer $glossary_id |
521 | 525 | * @param array Parameters to use to affect links |
522 | 526 | * @param array The line of results from a query on the glossary table |
527 | + * @param string $url_params |
|
523 | 528 | * @return string HTML string for the action icons columns |
524 | 529 | * |
525 | 530 | * @author Patrick Cool <[email protected]>, Ghent University, Belgium |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | * @param int $glossary_id |
40 | 40 | * @return string The glossary description |
41 | 41 | */ |
42 | - public static function get_glossary_term_by_glossary_id ($glossary_id) |
|
42 | + public static function get_glossary_term_by_glossary_id($glossary_id) |
|
43 | 43 | { |
44 | - $glossary_table = Database::get_course_table(TABLE_GLOSSARY); |
|
44 | + $glossary_table = Database::get_course_table(TABLE_GLOSSARY); |
|
45 | 45 | $course_id = api_get_course_int_id(); |
46 | 46 | $sql = "SELECT description FROM $glossary_table |
47 | 47 | WHERE c_id = $course_id AND glossary_id =".intval($glossary_id); |
48 | - $rs=Database::query($sql); |
|
48 | + $rs = Database::query($sql); |
|
49 | 49 | if (Database::num_rows($rs) > 0) { |
50 | 50 | $row = Database::fetch_array($rs); |
51 | 51 | |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * @param string The glossary term name |
62 | 62 | * @return string The glossary description |
63 | 63 | */ |
64 | - public static function get_glossary_term_by_glossary_name ($glossary_name) |
|
64 | + public static function get_glossary_term_by_glossary_name($glossary_name) |
|
65 | 65 | { |
66 | - $glossary_table = Database::get_course_table(TABLE_GLOSSARY); |
|
66 | + $glossary_table = Database::get_course_table(TABLE_GLOSSARY); |
|
67 | 67 | $session_id = api_get_session_id(); |
68 | 68 | $course_id = api_get_course_int_id(); |
69 | 69 | $sql_filter = api_get_session_condition($session_id); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $course_id = api_get_course_int_id(); |
164 | 164 | |
165 | 165 | // check if the glossary term already exists |
166 | - if (GlossaryManager::glossary_exists($values['glossary_title'],$values['glossary_id'])) { |
|
166 | + if (GlossaryManager::glossary_exists($values['glossary_title'], $values['glossary_id'])) { |
|
167 | 167 | // display the feedback message |
168 | 168 | if ($message) |
169 | 169 | Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt')); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $get_max = "SELECT MAX(display_order) FROM $t_glossary |
211 | 211 | WHERE c_id = $course_id "; |
212 | 212 | $res_max = Database::query($get_max); |
213 | - if (Database::num_rows($res_max)==0) { |
|
213 | + if (Database::num_rows($res_max) == 0) { |
|
214 | 214 | return 0; |
215 | 215 | } |
216 | 216 | $row = Database::fetch_array($res_max); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @author Patrick Cool <[email protected]>, Ghent University, Belgium |
232 | 232 | * @version januari 2009, dokeos 1.8.6 |
233 | 233 | */ |
234 | - public static function glossary_exists($term, $not_id='') |
|
234 | + public static function glossary_exists($term, $not_id = '') |
|
235 | 235 | { |
236 | 236 | // Database table definition |
237 | 237 | $t_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | WHERE |
242 | 242 | c_id = $course_id AND |
243 | 243 | name = '".Database::escape_string($term)."'"; |
244 | - if ($not_id<>'') { |
|
244 | + if ($not_id <> '') { |
|
245 | 245 | $sql .= " AND glossary_id <> '".intval($not_id)."'"; |
246 | 246 | } |
247 | 247 | $result = Database::query($sql); |
@@ -347,27 +347,27 @@ discard block |
||
347 | 347 | // action links |
348 | 348 | echo '<div class="actions">'; |
349 | 349 | |
350 | - if (api_is_allowed_to_edit(null,true)) { |
|
350 | + if (api_is_allowed_to_edit(null, true)) { |
|
351 | 351 | echo '<a href="index.php?'.api_get_cidreq().'&action=addglossary&msg=add?'.api_get_cidreq().'">'. |
352 | - Display::return_icon('new_glossary_term.png',get_lang('TermAddNew'),'', ICON_SIZE_MEDIUM).'</a>'; |
|
352 | + Display::return_icon('new_glossary_term.png', get_lang('TermAddNew'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | echo '<a href="index.php?'.api_get_cidreq().'&action=export">'. |
356 | - Display::return_icon('export_csv.png',get_lang('ExportGlossaryAsCSV'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
357 | - if (api_is_allowed_to_edit(null,true)) { |
|
356 | + Display::return_icon('export_csv.png', get_lang('ExportGlossaryAsCSV'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
357 | + if (api_is_allowed_to_edit(null, true)) { |
|
358 | 358 | echo '<a href="index.php?'.api_get_cidreq().'&action=import">'. |
359 | - Display::return_icon('import_csv.png',get_lang('ImportGlossary'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
359 | + Display::return_icon('import_csv.png', get_lang('ImportGlossary'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | echo '<a href="index.php?'.api_get_cidreq().'&action=export_to_pdf">'. |
363 | - Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>'; |
|
363 | + Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
364 | 364 | |
365 | - if ((isset($_SESSION['glossary_view']) && $_SESSION['glossary_view'] == 'table') or (!isset($_SESSION['glossary_view']))){ |
|
365 | + if ((isset($_SESSION['glossary_view']) && $_SESSION['glossary_view'] == 'table') or (!isset($_SESSION['glossary_view']))) { |
|
366 | 366 | echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=list">'. |
367 | - Display::return_icon('view_detailed.png',get_lang('ListView'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
367 | + Display::return_icon('view_detailed.png', get_lang('ListView'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
368 | 368 | } else { |
369 | 369 | echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=table">'. |
370 | - Display::return_icon('view_text.png',get_lang('TableView'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
370 | + Display::return_icon('view_text.png', get_lang('TableView'), '', ICON_SIZE_MEDIUM).'</a>'; |
|
371 | 371 | } |
372 | 372 | echo '</div>'; |
373 | 373 | if (!$_SESSION['glossary_view'] || $_SESSION['glossary_view'] == 'table') { |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | //$table->set_header(0, '', false); |
381 | 381 | $table->set_header(0, get_lang('TermName'), true); |
382 | 382 | $table->set_header(1, get_lang('TermDefinition'), true); |
383 | - if (api_is_allowed_to_edit(null,true)) { |
|
383 | + if (api_is_allowed_to_edit(null, true)) { |
|
384 | 384 | $table->set_header(2, get_lang('Actions'), false, 'width=90px', array('class' => 'td_actions')); |
385 | - $table->set_column_filter(2, array('GlossaryManager','actions_filter')); |
|
385 | + $table->set_column_filter(2, array('GlossaryManager', 'actions_filter')); |
|
386 | 386 | } |
387 | 387 | $table->display(); |
388 | 388 | } |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | */ |
400 | 400 | public static function display_glossary_list() |
401 | 401 | { |
402 | - $glossary_data = self::get_glossary_data(0,1000,0,'ASC'); |
|
402 | + $glossary_data = self::get_glossary_data(0, 1000, 0, 'ASC'); |
|
403 | 403 | foreach ($glossary_data as $key => $glossary_item) { |
404 | 404 | $actions = ''; |
405 | - if (api_is_allowed_to_edit(null,true)) { |
|
406 | - $actions = '<div class="pull-right">'.self::actions_filter($glossary_item[2], '',$glossary_item).'</div>'; |
|
405 | + if (api_is_allowed_to_edit(null, true)) { |
|
406 | + $actions = '<div class="pull-right">'.self::actions_filter($glossary_item[2], '', $glossary_item).'</div>'; |
|
407 | 407 | } |
408 | 408 | echo Display::panel($glossary_item[1], $glossary_item[0].' '.$actions); |
409 | 409 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * @author Patrick Cool <[email protected]>, Ghent University, Belgium |
419 | 419 | * @version januari 2009, dokeos 1.8.6 |
420 | 420 | */ |
421 | - public static function get_number_glossary_terms($session_id=0) |
|
421 | + public static function get_number_glossary_terms($session_id = 0) |
|
422 | 422 | { |
423 | 423 | // Database table definition |
424 | 424 | $t_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $t_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
457 | 457 | $t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
458 | 458 | |
459 | - if (api_is_allowed_to_edit(null,true)) { |
|
459 | + if (api_is_allowed_to_edit(null, true)) { |
|
460 | 460 | $col2 = " glossary.glossary_id as col2, "; |
461 | 461 | } else { |
462 | 462 | $col2 = " "; |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | 'glossary.session_id' |
472 | 472 | ); |
473 | 473 | $column = intval($column); |
474 | - if (!in_array($direction,array('DESC', 'ASC'))) { |
|
475 | - $direction = 'ASC'; |
|
474 | + if (!in_array($direction, array('DESC', 'ASC'))) { |
|
475 | + $direction = 'ASC'; |
|
476 | 476 | } |
477 | 477 | $from = intval($from); |
478 | 478 | $number_of_items = intval($number_of_items); |
@@ -497,15 +497,15 @@ discard block |
||
497 | 497 | while ($data = Database::fetch_array($res)) { |
498 | 498 | // Validation when belongs to a session |
499 | 499 | $session_img = api_get_session_image($data['session_id'], $_user['status']); |
500 | - $array[0] = $data[0] . $session_img; |
|
500 | + $array[0] = $data[0].$session_img; |
|
501 | 501 | |
502 | 502 | if (!$_SESSION['glossary_view'] || $_SESSION['glossary_view'] == 'table') { |
503 | - $array[1] = str_replace(array('<p>','</p>'),array('','<br />'),$data[1]); |
|
503 | + $array[1] = str_replace(array('<p>', '</p>'), array('', '<br />'), $data[1]); |
|
504 | 504 | } else { |
505 | 505 | $array[1] = $data[1]; |
506 | 506 | } |
507 | 507 | |
508 | - if (api_is_allowed_to_edit(null,true)) { |
|
508 | + if (api_is_allowed_to_edit(null, true)) { |
|
509 | 509 | $array[2] = $data[2]; |
510 | 510 | } |
511 | 511 | $return[] = $array; |
@@ -528,14 +528,14 @@ discard block |
||
528 | 528 | public static function actions_filter($glossary_id, $url_params, $row) |
529 | 529 | { |
530 | 530 | $glossary_id = $row[2]; |
531 | - $return = '<a href="'.api_get_self().'?action=edit_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>'; |
|
531 | + $return = '<a href="'.api_get_self().'?action=edit_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'.Display::return_icon('edit.png', get_lang('Edit'), '', 22).'</a>'; |
|
532 | 532 | $glossary_data = GlossaryManager::get_glossary_information($glossary_id); |
533 | 533 | |
534 | 534 | $glossary_term = $glossary_data['glossary_title']; |
535 | 535 | |
536 | 536 | if (api_is_allowed_to_edit(null, true)) { |
537 | 537 | if ($glossary_data['session_id'] == api_get_session_id()) { |
538 | - $return .= '<a href="'.api_get_self().'?action=delete_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossary_term.'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>'; |
|
538 | + $return .= '<a href="'.api_get_self().'?action=delete_glossary&glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossary_term.'\');">'.Display::return_icon('delete.png', get_lang('Delete'), '', 22).'</a>'; |
|
539 | 539 | } else { |
540 | 540 | $return = get_lang('EditionNotAvailableFromSession'); |
541 | 541 | } |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | { |
557 | 557 | return "<script type=\"text/javascript\"> |
558 | 558 | function confirmation (name) { |
559 | - if (confirm(\" ". get_lang("TermConfirmDelete") ." \"+ name + \" ?\")) |
|
559 | + if (confirm(\" ". get_lang("TermConfirmDelete")." \"+ name + \" ?\")) |
|
560 | 560 | {return true;} |
561 | 561 | else |
562 | 562 | {return false;} |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | $res = Database::query($sql); |
617 | 617 | $found = false; |
618 | 618 | while ($row = Database::fetch_array($res)) { |
619 | - if ($found && empty($next_id)) { |
|
619 | + if ($found && empty($next_id)) { |
|
620 | 620 | $next_id = $row['glossary_id']; |
621 | 621 | $next_display_order = $row['display_order']; |
622 | 622 | } |
@@ -108,8 +108,9 @@ discard block |
||
108 | 108 | // check if the glossary term already exists |
109 | 109 | if (GlossaryManager::glossary_exists($values['glossary_title'])) { |
110 | 110 | // display the feedback message |
111 | - if ($message) |
|
112 | - Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt')); |
|
111 | + if ($message) { |
|
112 | + Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt')); |
|
113 | + } |
|
113 | 114 | return false; |
114 | 115 | } else { |
115 | 116 | |
@@ -165,8 +166,9 @@ discard block |
||
165 | 166 | // check if the glossary term already exists |
166 | 167 | if (GlossaryManager::glossary_exists($values['glossary_title'],$values['glossary_id'])) { |
167 | 168 | // display the feedback message |
168 | - if ($message) |
|
169 | - Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt')); |
|
169 | + if ($message) { |
|
170 | + Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt')); |
|
171 | + } |
|
170 | 172 | return false; |
171 | 173 | } else { |
172 | 174 | $sql = "UPDATE $t_glossary SET |
@@ -188,8 +190,9 @@ discard block |
||
188 | 190 | api_get_user_id() |
189 | 191 | ); |
190 | 192 | // display the feedback message |
191 | - if ($message) |
|
192 | - Display::display_confirmation_message(get_lang('TermUpdated')); |
|
193 | + if ($message) { |
|
194 | + Display::display_confirmation_message(get_lang('TermUpdated')); |
|
195 | + } |
|
193 | 196 | } |
194 | 197 | |
195 | 198 | return true; |
@@ -323,8 +326,9 @@ discard block |
||
323 | 326 | // reorder the remaining terms |
324 | 327 | GlossaryManager::reorder_glossary(); |
325 | 328 | $_SESSION['max_glossary_display'] = GlossaryManager::get_max_glossary_item(); |
326 | - if ($message) |
|
327 | - Display::display_confirmation_message(get_lang('TermDeleted')); |
|
329 | + if ($message) { |
|
330 | + Display::display_confirmation_message(get_lang('TermDeleted')); |
|
331 | + } |
|
328 | 332 | return true; |
329 | 333 | } |
330 | 334 | |
@@ -633,8 +637,9 @@ discard block |
||
633 | 637 | WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($next_id)."'"; |
634 | 638 | Database::query($sql1); |
635 | 639 | Database::query($sql2); |
636 | - if ($message) |
|
637 | - Display::display_confirmation_message(get_lang('TermMoved')); |
|
640 | + if ($message) { |
|
641 | + Display::display_confirmation_message(get_lang('TermMoved')); |
|
642 | + } |
|
638 | 643 | } |
639 | 644 | |
640 | 645 | /** |
@@ -160,7 +160,7 @@ |
||
160 | 160 | * @todo the form should be auto generated |
161 | 161 | * @param string url |
162 | 162 | * @param string action add, edit |
163 | - * @return obj form validator obj |
|
163 | + * @return FormValidator form validator obj |
|
164 | 164 | */ |
165 | 165 | public function show_skill_form($gradebook_id, $url, $header = null) |
166 | 166 | { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | $c_id = $c_id ? intval($c_id) : api_get_course_int_id(); |
59 | - $table = Database::get_course_table(TABLE_TOOL_LIST); |
|
59 | + $table = Database::get_course_table(TABLE_TOOL_LIST); |
|
60 | 60 | $sql = "SELECT * from $table |
61 | 61 | WHERE c_id = $c_id and name='$name' |
62 | 62 | LIMIT 1"; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $clean_gradebook = array(); |
114 | 114 | |
115 | 115 | if (!empty($skill_gradebooks_source)) { |
116 | - foreach($skill_gradebooks_source as $source) { |
|
116 | + foreach ($skill_gradebooks_source as $source) { |
|
117 | 117 | $clean_gradebook[] = $source['skill_id']; |
118 | 118 | } |
119 | 119 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $selected_skills = self::get_skills_by_gradebook($gradebook_id); |
193 | 193 | $clean_selected_skills = array(); |
194 | 194 | if (!empty($selected_skills)) { |
195 | - foreach($selected_skills as $skill) { |
|
195 | + foreach ($selected_skills as $skill) { |
|
196 | 196 | $clean_selected_skills[] = $skill['id']; |
197 | 197 | } |
198 | 198 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param int $visibility is active or not |
22 | 22 | * @param string $picture |
23 | 23 | * |
24 | - * @return boolean if success |
|
24 | + * @return string|false if success |
|
25 | 25 | */ |
26 | 26 | public static function add($name, $description, $url, $visibility, $picture = '') |
27 | 27 | { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @param int $visibility |
58 | 58 | * @param string $picture_uri |
59 | 59 | * @param bool $allowMemberGroupToLeave |
60 | - * @return bool if success |
|
60 | + * @return Statement|null if success |
|
61 | 61 | */ |
62 | 62 | public static function update($group_id, $name, $description, $url, $visibility, $picture_uri, $allowMemberGroupToLeave = null) |
63 | 63 | { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * Deletes a group |
88 | 88 | * @author Julio Montoya |
89 | 89 | * @param int $id |
90 | - * @return boolean true if success |
|
90 | + * @return Statement|null true if success |
|
91 | 91 | * */ |
92 | 92 | public static function delete($id) |
93 | 93 | { |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @param int $group_id |
176 | 176 | * @param int $parent_group_id if 0, we delete the parent_group association |
177 | 177 | * @param int $relation_type |
178 | - * @return resource |
|
178 | + * @return Statement|null |
|
179 | 179 | **/ |
180 | 180 | public static function set_parent_group($group_id, $parent_group_id, $relation_type = 1) |
181 | 181 | { |
@@ -652,6 +652,7 @@ discard block |
||
652 | 652 | * @author Julio Montoya |
653 | 653 | * @param int user_id |
654 | 654 | * @param int url_id |
655 | + * @param integer $relation_type |
|
655 | 656 | * @return boolean true if success |
656 | 657 | **/ |
657 | 658 | public static function add_user_to_group($user_id, $group_id, $relation_type = GROUP_USER_PERMISSION_READER) |
@@ -735,7 +736,7 @@ discard block |
||
735 | 736 | * @author Julio Montoya |
736 | 737 | * @param int $group_id |
737 | 738 | * @param int $relation_type (optional) |
738 | - * @return boolean true if success |
|
739 | + * @return Statement|null true if success |
|
739 | 740 | * */ |
740 | 741 | public static function delete_users($group_id, $relation_type = null) |
741 | 742 | { |
@@ -916,6 +917,7 @@ discard block |
||
916 | 917 | * If an empty name is provided, then old user photos are deleted only, @see UserManager::delete_user_picture() |
917 | 918 | * as the prefered way for deletion. |
918 | 919 | * @param string $source_file The full system name of the image from which user photos will be created. |
920 | + * @param integer $group_id |
|
919 | 921 | * @return string/bool Returns the resulting file name of created images which usually should be stored in DB. |
920 | 922 | * When deletion is recuested returns empty string. In case of internal error or negative validation returns FALSE. |
921 | 923 | */ |
@@ -1074,7 +1076,9 @@ discard block |
||
1074 | 1076 | * |
1075 | 1077 | * @param string file picture |
1076 | 1078 | * @param int size in pixels |
1077 | - * @return obj image object |
|
1079 | + * @param string|null $file |
|
1080 | + * @param integer $max_size_for_picture |
|
1081 | + * @return Image image object |
|
1078 | 1082 | */ |
1079 | 1083 | public static function resize_picture($file, $max_size_for_picture) |
1080 | 1084 | { |
@@ -1335,27 +1335,27 @@ |
||
1335 | 1335 | public static function get_groups_by_user_count($user_id = null, $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) |
1336 | 1336 | { |
1337 | 1337 | $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); |
1338 | - $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); |
|
1339 | - $user_id = intval($user_id); |
|
1338 | + $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); |
|
1339 | + $user_id = intval($user_id); |
|
1340 | 1340 | |
1341 | - if ($relation_type == 0) { |
|
1342 | - $where_relation_condition = ''; |
|
1343 | - } else { |
|
1344 | - $relation_type = intval($relation_type); |
|
1345 | - $where_relation_condition = "AND gu.relation_type = $relation_type "; |
|
1346 | - } |
|
1341 | + if ($relation_type == 0) { |
|
1342 | + $where_relation_condition = ''; |
|
1343 | + } else { |
|
1344 | + $relation_type = intval($relation_type); |
|
1345 | + $where_relation_condition = "AND gu.relation_type = $relation_type "; |
|
1346 | + } |
|
1347 | 1347 | |
1348 | - $sql = "SELECT count(g.id) as count |
|
1348 | + $sql = "SELECT count(g.id) as count |
|
1349 | 1349 | FROM $tbl_group g |
1350 | 1350 | INNER JOIN $table_group_rel_user gu |
1351 | 1351 | ON gu.group_id = g.id WHERE gu.user_id = $user_id $where_relation_condition "; |
1352 | 1352 | |
1353 | - $result = Database::query($sql); |
|
1354 | - if (Database::num_rows($result) > 0) { |
|
1355 | - $row = Database::fetch_array($result, 'ASSOC'); |
|
1353 | + $result = Database::query($sql); |
|
1354 | + if (Database::num_rows($result) > 0) { |
|
1355 | + $row = Database::fetch_array($result, 'ASSOC'); |
|
1356 | 1356 | return $row['count']; |
1357 | - } |
|
1358 | - return 0; |
|
1357 | + } |
|
1358 | + return 0; |
|
1359 | 1359 | } |
1360 | 1360 | |
1361 | 1361 | /** |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | if ($i == $max_level) { |
332 | 332 | $select_part .= "rg$rg_number.group_id as id_$rg_number "; |
333 | 333 | } else { |
334 | - $select_part .="rg$rg_number.group_id as id_$rg_number, "; |
|
334 | + $select_part .= "rg$rg_number.group_id as id_$rg_number, "; |
|
335 | 335 | } |
336 | 336 | if ($i == 1) { |
337 | 337 | $cond_part .= "FROM $t_rel_group rg0 LEFT JOIN $t_rel_group rg$i on rg$rg_number.group_id = rg$i.subgroup_id "; |
@@ -1334,14 +1334,14 @@ discard block |
||
1334 | 1334 | */ |
1335 | 1335 | public static function get_groups_by_user_count($user_id = null, $relation_type = GROUP_USER_PERMISSION_READER, $with_image = false) |
1336 | 1336 | { |
1337 | - $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); |
|
1338 | - $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); |
|
1337 | + $table_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP); |
|
1338 | + $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP); |
|
1339 | 1339 | $user_id = intval($user_id); |
1340 | 1340 | |
1341 | 1341 | if ($relation_type == 0) { |
1342 | 1342 | $where_relation_condition = ''; |
1343 | 1343 | } else { |
1344 | - $relation_type = intval($relation_type); |
|
1344 | + $relation_type = intval($relation_type); |
|
1345 | 1345 | $where_relation_condition = "AND gu.relation_type = $relation_type "; |
1346 | 1346 | } |
1347 | 1347 | |
@@ -1394,7 +1394,7 @@ discard block |
||
1394 | 1394 | |
1395 | 1395 | // Picture |
1396 | 1396 | $form->addElement('file', 'picture', get_lang('AddPicture')); |
1397 | - $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); |
|
1397 | + $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif'); |
|
1398 | 1398 | $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types); |
1399 | 1399 | |
1400 | 1400 | if (!empty($groupData)) { |
@@ -563,8 +563,9 @@ discard block |
||
563 | 563 | $new_relation_type[] = "'$rel'"; |
564 | 564 | } |
565 | 565 | $relation_type = implode(',', $new_relation_type); |
566 | - if (!empty($relation_type)) |
|
567 | - $where_relation_condition = "AND gu.relation_type IN ($relation_type) "; |
|
566 | + if (!empty($relation_type)) { |
|
567 | + $where_relation_condition = "AND gu.relation_type IN ($relation_type) "; |
|
568 | + } |
|
568 | 569 | } |
569 | 570 | |
570 | 571 | $sql = "SELECT |
@@ -1086,8 +1087,9 @@ discard block |
||
1086 | 1087 | $thumbwidth = $max_size_for_picture; |
1087 | 1088 | } |
1088 | 1089 | $new_height = round(($thumbwidth / $picture_infos['width']) * $picture_infos['height']); |
1089 | - if ($new_height > $max_size_for_picture) |
|
1090 | - $new_height = $thumbwidth; |
|
1090 | + if ($new_height > $max_size_for_picture) { |
|
1091 | + $new_height = $thumbwidth; |
|
1092 | + } |
|
1091 | 1093 | $temp->resize($thumbwidth, $new_height, 0); |
1092 | 1094 | } |
1093 | 1095 |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @author Christophe Gesche <[email protected]> |
370 | 370 | * @author Hugues Peeters <[email protected]> |
371 | 371 | * @author Bart Mollet |
372 | - * @param mixed $groupIdList - group(s) to delete. It can be a single id |
|
372 | + * @param mixed $group_ids - group(s) to delete. It can be a single id |
|
373 | 373 | * (int) or a list of id (array). |
374 | 374 | * @param string $course_code Default is current course |
375 | 375 | * @return integer - number of groups deleted. |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | * @param bool Whether self registration is allowed or not |
574 | 574 | * @param bool Whether self unregistration is allowed or not |
575 | 575 | * @param int $categoryId |
576 | - * @return bool TRUE if properties are successfully changed, false otherwise |
|
576 | + * @return Statement|null TRUE if properties are successfully changed, false otherwise |
|
577 | 577 | */ |
578 | 578 | public static function set_group_properties( |
579 | 579 | $group_id, |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | * @param int $group_id The id of the group |
725 | 725 | * @param string $course_code The course in which the group is (default = |
726 | 726 | * current course) |
727 | - * @return array The category |
|
727 | + * @return integer The category |
|
728 | 728 | */ |
729 | 729 | public static function get_category_from_group($group_id, $course_code = null) |
730 | 730 | { |
@@ -786,9 +786,9 @@ discard block |
||
786 | 786 | * Create group category |
787 | 787 | * @param string $title The title of the new category |
788 | 788 | * @param string $description The description of the new category |
789 | - * @param bool $self_registration_allowed |
|
790 | - * @param bool $self_unregistration_allowed |
|
791 | - * @param int $max_number_of_students |
|
789 | + * @param integer $self_registration_allowed |
|
790 | + * @param integer $self_unregistration_allowed |
|
791 | + * @param int $maximum_number_of_students |
|
792 | 792 | * @param int $groups_per_user |
793 | 793 | */ |
794 | 794 | public static function create_category( |
@@ -994,6 +994,8 @@ discard block |
||
994 | 994 | * @param int $limit |
995 | 995 | * @param bool $getCount |
996 | 996 | * @param int $courseId |
997 | + * @param string $column |
|
998 | + * @param string $direction |
|
997 | 999 | * @return array list of user id |
998 | 1000 | */ |
999 | 1001 | public static function get_users( |
@@ -1172,7 +1174,7 @@ discard block |
||
1172 | 1174 | * Hugues Peeters <[email protected]> - original version |
1173 | 1175 | * @author Roan Embrechts - virtual course support, code cleaning |
1174 | 1176 | * @author Bart Mollet - code cleaning, use other GroupManager-functions |
1175 | - * @return void |
|
1177 | + * @return false|null |
|
1176 | 1178 | */ |
1177 | 1179 | public static function fill_groups($group_ids) |
1178 | 1180 | { |
@@ -1625,7 +1627,7 @@ discard block |
||
1625 | 1627 | * Unsubscribe user(s) from a specified group in current course |
1626 | 1628 | * @param mixed $user_ids Can be an array with user-id's or a single user-id |
1627 | 1629 | * @param int $group_id |
1628 | - * @return bool TRUE if successful |
|
1630 | + * @return boolean|null TRUE if successful |
|
1629 | 1631 | */ |
1630 | 1632 | public static function unsubscribe_users($user_ids, $group_id) |
1631 | 1633 | { |
@@ -1644,7 +1646,7 @@ discard block |
||
1644 | 1646 | |
1645 | 1647 | /** |
1646 | 1648 | * Unsubscribe all users from one or more groups |
1647 | - * @param mixed $group_id Can be an array with group-id's or a single group-id |
|
1649 | + * @param mixed $group_ids Can be an array with group-id's or a single group-id |
|
1648 | 1650 | * @return bool TRUE if successful |
1649 | 1651 | */ |
1650 | 1652 | public static function unsubscribe_all_users($group_ids) |
@@ -1676,7 +1678,7 @@ discard block |
||
1676 | 1678 | |
1677 | 1679 | /** |
1678 | 1680 | * Unsubscribe all tutors from one or more groups |
1679 | - * @param mixed $group_id Can be an array with group-id's or a single group-id |
|
1681 | + * @param mixed $group_ids Can be an array with group-id's or a single group-id |
|
1680 | 1682 | * @see unsubscribe_all_users. This function is almost an exact copy of that function. |
1681 | 1683 | * @return bool TRUE if successful |
1682 | 1684 | * @author Patrick Cool <[email protected]>, Ghent University |
@@ -1861,6 +1863,7 @@ discard block |
||
1861 | 1863 | * |
1862 | 1864 | * @param $user_array_in list of users (must be sorted). |
1863 | 1865 | * @param string $compare_field, the field to be compared |
1866 | + * @param string $compare_field |
|
1864 | 1867 | */ |
1865 | 1868 | public static function filter_duplicates($user_array_in, $compare_field) |
1866 | 1869 | { |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | $sql = "UPDATE $table_group SET id = iid WHERE iid = $lastId"; |
222 | 222 | Database::query($sql); |
223 | 223 | |
224 | - $desired_dir_name= '/'.api_replace_dangerous_char($name).'_groupdocs'; |
|
225 | - $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document'; |
|
224 | + $desired_dir_name = '/'.api_replace_dangerous_char($name).'_groupdocs'; |
|
225 | + $my_path = api_get_path(SYS_COURSE_PATH).$currentCourseRepository.'/document'; |
|
226 | 226 | |
227 | 227 | $newFolderData = create_unexisting_directory( |
228 | 228 | $_course, |
@@ -285,11 +285,11 @@ discard block |
||
285 | 285 | $values['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view'); |
286 | 286 | $values['group_forum'] = $lastId; |
287 | 287 | if ($forumState == '1') { |
288 | - $values['public_private_group_forum_group']['public_private_group_forum']='public'; |
|
288 | + $values['public_private_group_forum_group']['public_private_group_forum'] = 'public'; |
|
289 | 289 | } elseif ($forumState == '2') { |
290 | - $values['public_private_group_forum_group']['public_private_group_forum']='private'; |
|
290 | + $values['public_private_group_forum_group']['public_private_group_forum'] = 'private'; |
|
291 | 291 | } elseif ($forumState == '0') { |
292 | - $values['public_private_group_forum_group']['public_private_group_forum']='unavailable'; |
|
292 | + $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable'; |
|
293 | 293 | } |
294 | 294 | store_forum($values); |
295 | 295 | } |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | 1 |
321 | 321 | ); |
322 | 322 | $users = self::get_users($group_id); |
323 | - $group_ids = array (); |
|
323 | + $group_ids = array(); |
|
324 | 324 | |
325 | - for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr ++) { |
|
325 | + for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr++) { |
|
326 | 326 | $group_ids[] = self::create_group( |
327 | 327 | get_lang('Subgroup').' '.$group_nr, |
328 | 328 | $category_id, |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | 0, |
367 | 367 | count($users_ids) |
368 | 368 | ); |
369 | - self::subscribe_users($users_ids,$group_id); |
|
369 | + self::subscribe_users($users_ids, $group_id); |
|
370 | 370 | $group_ids[] = $group_id; |
371 | 371 | } |
372 | 372 | return $group_ids; |
@@ -391,14 +391,14 @@ discard block |
||
391 | 391 | $group_table = Database:: get_course_table(TABLE_GROUP); |
392 | 392 | $forum_table = Database:: get_course_table(TABLE_FORUM); |
393 | 393 | |
394 | - $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); |
|
395 | - $group_ids = array_map('intval',$group_ids); |
|
394 | + $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); |
|
395 | + $group_ids = array_map('intval', $group_ids); |
|
396 | 396 | |
397 | 397 | if (api_is_course_coach()) { |
398 | 398 | //a coach can only delete courses from his session |
399 | - for ($i=0 ; $i<count($group_ids) ; $i++) { |
|
400 | - if (!api_is_element_in_the_session(TOOL_GROUP,$group_ids[$i])) { |
|
401 | - array_splice($group_ids,$i,1); |
|
399 | + for ($i = 0; $i < count($group_ids); $i++) { |
|
400 | + if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { |
|
401 | + array_splice($group_ids, $i, 1); |
|
402 | 402 | $i--; |
403 | 403 | } |
404 | 404 | } |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | } elseif ($forum_state === 0) { |
634 | 634 | $sql2 .= " forum_group_public_private='unavailable' "; |
635 | 635 | } |
636 | - $sql2 .=" WHERE c_id = $course_id AND forum_of_group=".$group_id; |
|
636 | + $sql2 .= " WHERE c_id = $course_id AND forum_of_group=".$group_id; |
|
637 | 637 | Database::query($sql2); |
638 | 638 | return $result; |
639 | 639 | } |
@@ -662,13 +662,13 @@ discard block |
||
662 | 662 | public static function get_categories($course_code = null) |
663 | 663 | { |
664 | 664 | $course_info = api_get_course_info($course_code); |
665 | - $course_id = $course_info['real_id']; |
|
665 | + $course_id = $course_info['real_id']; |
|
666 | 666 | $table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY); |
667 | 667 | $sql = "SELECT * FROM $table_group_cat |
668 | 668 | WHERE c_id = $course_id |
669 | 669 | ORDER BY display_order"; |
670 | 670 | $res = Database::query($sql); |
671 | - $cats = array (); |
|
671 | + $cats = array(); |
|
672 | 672 | while ($cat = Database::fetch_array($res)) { |
673 | 673 | $cats[] = $cat; |
674 | 674 | } |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | WHERE c_id = $course_id AND category_id='".$cat_id."'"; |
780 | 780 | $res = Database::query($sql); |
781 | 781 | if (Database::num_rows($res) > 0) { |
782 | - $groups_to_delete = array (); |
|
782 | + $groups_to_delete = array(); |
|
783 | 783 | while ($group = Database::fetch_object($res)) { |
784 | 784 | $groups_to_delete[] = $group->id; |
785 | 785 | } |
@@ -947,7 +947,7 @@ discard block |
||
947 | 947 | */ |
948 | 948 | public static function get_current_max_groups_per_user($category_id = null, $course_code = null) |
949 | 949 | { |
950 | - $course_info = api_get_course_info ($course_code); |
|
950 | + $course_info = api_get_course_info($course_code); |
|
951 | 951 | $group_table = Database :: get_course_table(TABLE_GROUP); |
952 | 952 | $group_user_table = Database :: get_course_table(TABLE_GROUP_USER); |
953 | 953 | $sql = 'SELECT COUNT(gu.group_id) AS current_max |
@@ -1186,17 +1186,17 @@ discard block |
||
1186 | 1186 | { |
1187 | 1187 | $_course = api_get_course_info(); |
1188 | 1188 | |
1189 | - $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); |
|
1189 | + $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); |
|
1190 | 1190 | $group_ids = array_map('intval', $group_ids); |
1191 | 1191 | |
1192 | 1192 | if (api_is_course_coach()) { |
1193 | - for ($i=0 ; $i< count($group_ids) ; $i++) { |
|
1194 | - if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])){ |
|
1195 | - array_splice($group_ids,$i,1); |
|
1193 | + for ($i = 0; $i < count($group_ids); $i++) { |
|
1194 | + if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { |
|
1195 | + array_splice($group_ids, $i, 1); |
|
1196 | 1196 | $i--; |
1197 | 1197 | } |
1198 | 1198 | } |
1199 | - if (count($group_ids)==0) { |
|
1199 | + if (count($group_ids) == 0) { |
|
1200 | 1200 | return false; |
1201 | 1201 | } |
1202 | 1202 | } |
@@ -1235,9 +1235,9 @@ discard block |
||
1235 | 1235 | * Retrieve course users (reverse) ordered by the number |
1236 | 1236 | * of group they are already enrolled |
1237 | 1237 | */ |
1238 | - for ($i = 0; $i < count($complete_user_list); $i ++) { |
|
1238 | + for ($i = 0; $i < count($complete_user_list); $i++) { |
|
1239 | 1239 | //find # of groups the user is enrolled in |
1240 | - $number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"], (isset($category['id'])?$category['id']:null)); |
|
1240 | + $number_of_groups = self :: user_in_number_of_groups($complete_user_list[$i]["user_id"], (isset($category['id']) ? $category['id'] : null)); |
|
1241 | 1241 | //add # of groups to user list |
1242 | 1242 | $complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; |
1243 | 1243 | } |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | |
1250 | 1250 | //now sort by # of group left |
1251 | 1251 | $complete_user_list = TableSort :: sort_table($complete_user_list, 'number_groups_left', SORT_DESC); |
1252 | - $userToken = array (); |
|
1252 | + $userToken = array(); |
|
1253 | 1253 | foreach ($complete_user_list as $this_user) { |
1254 | 1254 | if ($this_user['number_groups_left'] > 0) { |
1255 | 1255 | $userToken[$this_user['user_id']] = $this_user['number_groups_left']; |
@@ -1444,7 +1444,7 @@ discard block |
||
1444 | 1444 | if ($category['groups_per_user'] == self::GROUP_PER_MEMBER_NO_LIMIT) { |
1445 | 1445 | $category['groups_per_user'] = self::INFINITE; |
1446 | 1446 | } |
1447 | - $result = self:: user_in_number_of_groups($user_id, $category['id'] ) < $category['groups_per_user']; |
|
1447 | + $result = self:: user_in_number_of_groups($user_id, $category['id']) < $category['groups_per_user']; |
|
1448 | 1448 | if ($result == false) { |
1449 | 1449 | return false; |
1450 | 1450 | } |
@@ -1555,7 +1555,7 @@ discard block |
||
1555 | 1555 | tg.group_id='".$group_id."' AND |
1556 | 1556 | tg.user_id=u.user_id".$order_clause; |
1557 | 1557 | $db_result = Database::query($sql); |
1558 | - $users = array (); |
|
1558 | + $users = array(); |
|
1559 | 1559 | while ($user = Database::fetch_object($db_result)) { |
1560 | 1560 | if (!$id_only) { |
1561 | 1561 | $member['user_id'] = $user->user_id; |
@@ -1620,8 +1620,8 @@ discard block |
||
1620 | 1620 | foreach ($user_ids as $user_id) { |
1621 | 1621 | $user_id = intval($user_id); |
1622 | 1622 | if (self::can_user_subscribe($user_id, $group_id, false)) { |
1623 | - $sql = "INSERT INTO " . $table_group_tutor . " (c_id, user_id, group_id) |
|
1624 | - VALUES ('$course_id', '" . $user_id . "', '" . $group_id . "')"; |
|
1623 | + $sql = "INSERT INTO ".$table_group_tutor." (c_id, user_id, group_id) |
|
1624 | + VALUES ('$course_id', '".$user_id."', '".$group_id."')"; |
|
1625 | 1625 | $result &= Database::query($sql); |
1626 | 1626 | } |
1627 | 1627 | } |
@@ -1637,7 +1637,7 @@ discard block |
||
1637 | 1637 | */ |
1638 | 1638 | public static function unsubscribe_users($user_ids, $group_id) |
1639 | 1639 | { |
1640 | - $user_ids = is_array($user_ids) ? $user_ids : array ($user_ids); |
|
1640 | + $user_ids = is_array($user_ids) ? $user_ids : array($user_ids); |
|
1641 | 1641 | $table_group_user = Database :: get_course_table(TABLE_GROUP_USER); |
1642 | 1642 | $group_id = intval($group_id); |
1643 | 1643 | $course_id = api_get_course_int_id(); |
@@ -2183,7 +2183,7 @@ discard block |
||
2183 | 2183 | * Retrieve course users (reverse) ordered by the number |
2184 | 2184 | * of group they are already enrolled |
2185 | 2185 | */ |
2186 | - for ($i = 0; $i < count($complete_user_list); $i ++) { |
|
2186 | + for ($i = 0; $i < count($complete_user_list); $i++) { |
|
2187 | 2187 | // find # of groups the user is enrolled in |
2188 | 2188 | $number_of_groups = self:: user_in_number_of_groups( |
2189 | 2189 | $complete_user_list[$i]["user_id"], |
@@ -2315,14 +2315,14 @@ discard block |
||
2315 | 2315 | !(api_is_course_coach() && intval($this_group['session_id']) != $session_id) |
2316 | 2316 | ) { |
2317 | 2317 | $edit_actions = '<a href="'.$url.'settings.php?'.api_get_cidreq(true, false).'&gidReq='.$this_group['id'].'" title="'.get_lang('Edit').'">'. |
2318 | - Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a> '; |
|
2318 | + Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).'</a> '; |
|
2319 | 2319 | |
2320 | 2320 | if ($this_group['status'] == 1) { |
2321 | - $edit_actions .= '<a href="' . api_get_self() . '?' . api_get_cidreq(true,false) . '&category=' . $category_id . '&action=set_invisible&id=' . $this_group['id'] . '" title="' . get_lang('Hide') . '">' . |
|
2322 | - Display::return_icon('visible.png', get_lang('Hide'), '', ICON_SIZE_SMALL) . '</a> '; |
|
2321 | + $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(true, false).'&category='.$category_id.'&action=set_invisible&id='.$this_group['id'].'" title="'.get_lang('Hide').'">'. |
|
2322 | + Display::return_icon('visible.png', get_lang('Hide'), '', ICON_SIZE_SMALL).'</a> '; |
|
2323 | 2323 | } else { |
2324 | - $edit_actions .= '<a href="' . api_get_self() . '?' . api_get_cidreq(true, false) . '&category=' . $category_id . '&action=set_visible&id=' . $this_group['id'] . '" title="' . get_lang('Show') . '">' . |
|
2325 | - Display::return_icon('invisible.png', get_lang('Show'), '', ICON_SIZE_SMALL) . '</a> '; |
|
2324 | + $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(true, false).'&category='.$category_id.'&action=set_visible&id='.$this_group['id'].'" title="'.get_lang('Show').'">'. |
|
2325 | + Display::return_icon('invisible.png', get_lang('Show'), '', ICON_SIZE_SMALL).'</a> '; |
|
2326 | 2326 | } |
2327 | 2327 | |
2328 | 2328 | $edit_actions .= '<a href="'.$url.'member_settings.php?'.api_get_cidreq(true, false).'&gidReq='.$this_group['id'].'" title="'.get_lang('GroupMembers').'">'. |
@@ -2335,10 +2335,10 @@ discard block |
||
2335 | 2335 | Display::return_icon('clean.png',get_lang('EmptyGroup'),'',ICON_SIZE_SMALL).'</a> ';*/ |
2336 | 2336 | |
2337 | 2337 | $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(true, false).'&category='.$category_id.'&action=fill_one&id='.$this_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('FillGroup').'">'. |
2338 | - Display::return_icon('fill.png',get_lang('FillGroup'),'',ICON_SIZE_SMALL).'</a> '; |
|
2338 | + Display::return_icon('fill.png', get_lang('FillGroup'), '', ICON_SIZE_SMALL).'</a> '; |
|
2339 | 2339 | |
2340 | 2340 | $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(true, false).'&category='.$category_id.'&action=delete_one&id='.$this_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'">'. |
2341 | - Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a> '; |
|
2341 | + Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a> '; |
|
2342 | 2342 | |
2343 | 2343 | $row[] = $edit_actions; |
2344 | 2344 | } |
@@ -2710,7 +2710,7 @@ discard block |
||
2710 | 2710 | $activeTutor = null; |
2711 | 2711 | $activeMember = null; |
2712 | 2712 | |
2713 | - switch($default) { |
|
2713 | + switch ($default) { |
|
2714 | 2714 | case 'settings': |
2715 | 2715 | $activeSettings = 'active'; |
2716 | 2716 | break; |
@@ -138,7 +138,7 @@ |
||
138 | 138 | |
139 | 139 | /** |
140 | 140 | * Return a list an associative array where keys are the active hook observer class name |
141 | - * @param $eventName |
|
141 | + * @param string $eventName |
|
142 | 142 | * |
143 | 143 | * @return array |
144 | 144 | */ |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | public function listHookObservers($eventName) |
146 | 146 | { |
147 | 147 | $array = array(); |
148 | - $joinTable = $this->tables[TABLE_HOOK_CALL] . ' hc' . |
|
149 | - ' INNER JOIN ' . $this->tables[TABLE_HOOK_EVENT] . ' he' . |
|
150 | - ' ON hc.hook_event_id = he.id ' . |
|
151 | - ' INNER JOIN ' . $this->tables[TABLE_HOOK_OBSERVER] . ' ho ' . |
|
148 | + $joinTable = $this->tables[TABLE_HOOK_CALL].' hc'. |
|
149 | + ' INNER JOIN '.$this->tables[TABLE_HOOK_EVENT].' he'. |
|
150 | + ' ON hc.hook_event_id = he.id '. |
|
151 | + ' INNER JOIN '.$this->tables[TABLE_HOOK_OBSERVER].' ho '. |
|
152 | 152 | ' ON hc.hook_observer_id = ho.id '; |
153 | 153 | $columns = 'ho.class_name, ho.path, ho.plugin_name, hc.enabled'; |
154 | 154 | $where = array('where' => array('he.class_name = ? ' => $eventName, 'AND hc.enabled = ? ' => 1)); |
@@ -202,10 +202,10 @@ discard block |
||
202 | 202 | public function listAllHookCalls() |
203 | 203 | { |
204 | 204 | $array = array(); |
205 | - $joinTable = $this->tables[TABLE_HOOK_CALL] . ' hc' . |
|
206 | - ' INNER JOIN ' . $this->tables[TABLE_HOOK_EVENT] . ' he' . |
|
207 | - ' ON hc.hook_event_id = he.id ' . |
|
208 | - ' INNER JOIN ' . $this->tables[TABLE_HOOK_OBSERVER] . ' ho ' . |
|
205 | + $joinTable = $this->tables[TABLE_HOOK_CALL].' hc'. |
|
206 | + ' INNER JOIN '.$this->tables[TABLE_HOOK_EVENT].' he'. |
|
207 | + ' ON hc.hook_event_id = he.id '. |
|
208 | + ' INNER JOIN '.$this->tables[TABLE_HOOK_OBSERVER].' ho '. |
|
209 | 209 | ' ON hc.hook_observer_id = ho.id '; |
210 | 210 | $columns = 'he.class_name AS event_class_name, ho.class_name AS observer_class_name, hc.id AS id, hc.type AS type'; |
211 | 211 | $rows = Database::select($columns, $joinTable); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | if (isset($eventName) && !isset($this->hookEvents[$eventName])) { |
232 | 232 | $attributes = array( |
233 | 233 | 'class_name' => $eventName, |
234 | - 'description' => get_lang('HookDescription' . $eventName), |
|
234 | + 'description' => get_lang('HookDescription'.$eventName), |
|
235 | 235 | ); |
236 | 236 | $id = Database::insert($this->tables[TABLE_HOOK_EVENT], $attributes); |
237 | 237 | $this->hookEvents[$eventName] = $id; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | // Check if exists hook observer |
241 | 241 | if (isset($observerClassName) && |
242 | 242 | !isset($this->hookObservers[$observerClassName]) |
243 | - ){ |
|
243 | + ) { |
|
244 | 244 | $object = $observerClassName::create(); |
245 | 245 | $attributes = array( |
246 | 246 | 'class_name' => $observerClassName, |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | $eventName = Database::escape_string($eventName); |
339 | 339 | $observerClassName($observerClassName); |
340 | 340 | $type = Database::escape_string($type); |
341 | - $joinTable = $this->tables[TABLE_HOOK_CALL] . ' hc' . |
|
342 | - ' INNER JOIN ' . $this->tables[TABLE_HOOK_EVENT] . ' he' . |
|
343 | - ' ON hc.hook_event_id = he.id ' . |
|
344 | - ' INNER JOIN ' . $this->tables[TABLE_HOOK_OBSERVER] . ' ho ' . |
|
341 | + $joinTable = $this->tables[TABLE_HOOK_CALL].' hc'. |
|
342 | + ' INNER JOIN '.$this->tables[TABLE_HOOK_EVENT].' he'. |
|
343 | + ' ON hc.hook_event_id = he.id '. |
|
344 | + ' INNER JOIN '.$this->tables[TABLE_HOOK_OBSERVER].' ho '. |
|
345 | 345 | ' ON hc.hook_observer_id = ho.id '; |
346 | 346 | $row = Database::select( |
347 | 347 | 'id', |
@@ -52,6 +52,9 @@ discard block |
||
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | + /** |
|
56 | + * @param string|null $cropParameters |
|
57 | + */ |
|
55 | 58 | public function crop($cropParameters) { |
56 | 59 | $image_size = $this->get_image_size($this->image_wrapper->path); |
57 | 60 | $src_width = $image_size['width']; |
@@ -66,6 +69,9 @@ discard block |
||
66 | 69 | return $image; |
67 | 70 | } |
68 | 71 | |
72 | + /** |
|
73 | + * @param string $convert_file_to |
|
74 | + */ |
|
69 | 75 | public function send_image( |
70 | 76 | $file = '', |
71 | 77 | $compress = -1, |
@@ -147,6 +153,9 @@ discard block |
||
147 | 153 | public $image; |
148 | 154 | public $filter = Imagick::FILTER_LANCZOS; |
149 | 155 | |
156 | + /** |
|
157 | + * @param string $path |
|
158 | + */ |
|
150 | 159 | public function __construct($path) |
151 | 160 | { |
152 | 161 | parent::__construct($path); |
@@ -194,6 +203,10 @@ discard block |
||
194 | 203 | } |
195 | 204 | |
196 | 205 | //@todo implement border logic case for Imagick |
206 | + |
|
207 | + /** |
|
208 | + * @param integer $border |
|
209 | + */ |
|
197 | 210 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
198 | 211 | { |
199 | 212 | if (!$this->image_validated) return false; |
@@ -275,6 +288,9 @@ discard block |
||
275 | 288 | { |
276 | 289 | public $bg; |
277 | 290 | |
291 | + /** |
|
292 | + * @param string $path |
|
293 | + */ |
|
278 | 294 | function __construct($path) { |
279 | 295 | parent::__construct($path); |
280 | 296 | } |
@@ -332,6 +348,9 @@ discard block |
||
332 | 348 | } |
333 | 349 | } |
334 | 350 | |
351 | + /** |
|
352 | + * @param integer $border |
|
353 | + */ |
|
335 | 354 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
336 | 355 | { |
337 | 356 | if (!$this->image_validated) return false; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | if ($height >= $max_size_for_picture) { |
48 | 48 | // scale width |
49 | 49 | $new_width = round($width * ($max_size_for_picture / $height)); |
50 | - $this->image_wrapper->resize($new_width, $max_size_for_picture, 0); |
|
50 | + $this->image_wrapper->resize($new_width, $max_size_for_picture, 0); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | public function __construct($path) |
151 | 151 | { |
152 | - parent::__construct($path); |
|
152 | + parent::__construct($path); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function set_image_wrapper() |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | - public function get_image_size() |
|
187 | + public function get_image_size() |
|
188 | 188 | { |
189 | - $imagesize = array('width'=>0,'height'=>0); |
|
190 | - if ($this->image_validated) { |
|
189 | + $imagesize = array('width'=>0,'height'=>0); |
|
190 | + if ($this->image_validated) { |
|
191 | 191 | $imagesize = $this->image->getImageGeometry(); |
192 | - } |
|
193 | - return $imagesize; |
|
194 | - } |
|
192 | + } |
|
193 | + return $imagesize; |
|
194 | + } |
|
195 | 195 | |
196 | - //@todo implement border logic case for Imagick |
|
197 | - public function resize($thumbw, $thumbh, $border, $specific_size = false) |
|
196 | + //@todo implement border logic case for Imagick |
|
197 | + public function resize($thumbw, $thumbh, $border, $specific_size = false) |
|
198 | 198 | { |
199 | - if (!$this->image_validated) return false; |
|
199 | + if (!$this->image_validated) return false; |
|
200 | 200 | |
201 | 201 | if ($specific_size) { |
202 | 202 | $width = $thumbw; |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | $width = (int)($this->width * $scale); |
207 | 207 | $height = (int)($this->height * $scale); |
208 | 208 | } |
209 | - $result = $this->image->resizeImage($width, $height, $this->filter, 1); |
|
210 | - $this->width = $thumbw; |
|
211 | - $this->height = $thumbh; |
|
212 | - } |
|
209 | + $result = $this->image->resizeImage($width, $height, $this->filter, 1); |
|
210 | + $this->width = $thumbw; |
|
211 | + $this->height = $thumbh; |
|
212 | + } |
|
213 | 213 | |
214 | 214 | /** |
215 | 215 | * @author José Loguercio <[email protected]> |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
225 | 225 | if (!$this->image_validated) return false; |
226 | 226 | $this->image->cropimage($width, $height, $x, $y); |
227 | - $this->width = $width; |
|
228 | - $this->height = $height; |
|
227 | + $this->width = $width; |
|
228 | + $this->height = $height; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
@@ -235,35 +235,35 @@ discard block |
||
235 | 235 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
236 | 236 | $type = $convert_file_to; |
237 | 237 | } |
238 | - switch ($type) { |
|
239 | - case 'jpeg': |
|
240 | - case 'jpg': |
|
241 | - if (!$file) header("Content-type: image/jpeg"); |
|
242 | - break; |
|
243 | - case 'png': |
|
244 | - if (!$file) header("Content-type: image/png"); |
|
245 | - break; |
|
246 | - case 'gif': |
|
247 | - if (!$file) header("Content-type: image/gif"); |
|
248 | - break; |
|
249 | - } |
|
250 | - $result = false; |
|
251 | - try { |
|
252 | - $result = $this->image->writeImage($file); |
|
253 | - } catch(ImagickException $e) { |
|
238 | + switch ($type) { |
|
239 | + case 'jpeg': |
|
240 | + case 'jpg': |
|
241 | + if (!$file) header("Content-type: image/jpeg"); |
|
242 | + break; |
|
243 | + case 'png': |
|
244 | + if (!$file) header("Content-type: image/png"); |
|
245 | + break; |
|
246 | + case 'gif': |
|
247 | + if (!$file) header("Content-type: image/gif"); |
|
248 | + break; |
|
249 | + } |
|
250 | + $result = false; |
|
251 | + try { |
|
252 | + $result = $this->image->writeImage($file); |
|
253 | + } catch(ImagickException $e) { |
|
254 | 254 | if ($this->debug) error_log($e->getMessage()); |
255 | 255 | } |
256 | 256 | |
257 | - if (!$file) { |
|
258 | - echo $this->image; |
|
259 | - $this->image->clear(); |
|
257 | + if (!$file) { |
|
258 | + echo $this->image; |
|
259 | + $this->image->clear(); |
|
260 | 260 | $this->image->destroy(); |
261 | - } else { |
|
262 | - $this->image->clear(); |
|
261 | + } else { |
|
262 | + $this->image->clear(); |
|
263 | 263 | $this->image->destroy(); |
264 | - return $result; |
|
265 | - } |
|
266 | - } |
|
264 | + return $result; |
|
265 | + } |
|
266 | + } |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
@@ -285,21 +285,21 @@ discard block |
||
285 | 285 | $this->fill_image_info(); |
286 | 286 | |
287 | 287 | switch ($this->type) { |
288 | - case 0: |
|
289 | - $handler = false; |
|
290 | - break; |
|
291 | - case 1 : |
|
288 | + case 0: |
|
289 | + $handler = false; |
|
290 | + break; |
|
291 | + case 1 : |
|
292 | 292 | $handler = @imagecreatefromgif($this->path); |
293 | 293 | $this->type = 'gif'; |
294 | 294 | break; |
295 | - case 2 : |
|
295 | + case 2 : |
|
296 | 296 | $handler = @imagecreatefromjpeg($this->path); |
297 | 297 | $this->type = 'jpg'; |
298 | 298 | break; |
299 | - case 3 : |
|
300 | - $handler = @imagecreatefrompng($this->path); |
|
301 | - $this->type = 'png'; |
|
302 | - break; |
|
299 | + case 3 : |
|
300 | + $handler = @imagecreatefrompng($this->path); |
|
301 | + $this->type = 'png'; |
|
302 | + break; |
|
303 | 303 | } |
304 | 304 | if ($handler) { |
305 | 305 | $this->image_validated = true; |
@@ -313,29 +313,29 @@ discard block |
||
313 | 313 | { |
314 | 314 | $return_array = array('width'=>0,'height'=>0); |
315 | 315 | if ($this->image_validated) { |
316 | - $return_array = array('width'=>$this->width,'height'=>$this->height); |
|
316 | + $return_array = array('width'=>$this->width,'height'=>$this->height); |
|
317 | 317 | } |
318 | 318 | return $return_array; |
319 | - } |
|
319 | + } |
|
320 | 320 | |
321 | 321 | public function fill_image_info() |
322 | 322 | { |
323 | - if (file_exists($this->path)) { |
|
324 | - $image_info = getimagesize($this->path); |
|
325 | - $this->width = $image_info[0]; |
|
326 | - $this->height = $image_info[1]; |
|
327 | - $this->type = $image_info[2]; |
|
328 | - } else { |
|
329 | - $this->width = 0; |
|
330 | - $this->height = 0; |
|
331 | - $this->type = 0; |
|
332 | - } |
|
323 | + if (file_exists($this->path)) { |
|
324 | + $image_info = getimagesize($this->path); |
|
325 | + $this->width = $image_info[0]; |
|
326 | + $this->height = $image_info[1]; |
|
327 | + $this->type = $image_info[2]; |
|
328 | + } else { |
|
329 | + $this->width = 0; |
|
330 | + $this->height = 0; |
|
331 | + $this->type = 0; |
|
332 | + } |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
336 | 336 | { |
337 | 337 | if (!$this->image_validated) return false; |
338 | - if ($border == 1) { |
|
338 | + if ($border == 1) { |
|
339 | 339 | if ($specific_size) { |
340 | 340 | $width = $thumbw; |
341 | 341 | $height = $thumbh; |
@@ -344,17 +344,17 @@ discard block |
||
344 | 344 | $width = (int)($this->width * $scale); |
345 | 345 | $height = (int)($this->height * $scale); |
346 | 346 | } |
347 | - $deltaw = (int)(($thumbw - $width) / 2); |
|
348 | - $deltah = (int)(($thumbh - $height) / 2); |
|
349 | - $dst_img = @ImageCreateTrueColor($thumbw, $thumbh); |
|
350 | - @imagealphablending($dst_img, false); |
|
351 | - @imagesavealpha($dst_img, true); |
|
352 | - if (!empty($this->color)) { |
|
353 | - @imagefill($dst_img, 0, 0, $this->color); |
|
354 | - } |
|
355 | - $this->width = $thumbw; |
|
356 | - $this->height = $thumbh; |
|
357 | - } elseif ($border == 0) { |
|
347 | + $deltaw = (int)(($thumbw - $width) / 2); |
|
348 | + $deltah = (int)(($thumbh - $height) / 2); |
|
349 | + $dst_img = @ImageCreateTrueColor($thumbw, $thumbh); |
|
350 | + @imagealphablending($dst_img, false); |
|
351 | + @imagesavealpha($dst_img, true); |
|
352 | + if (!empty($this->color)) { |
|
353 | + @imagefill($dst_img, 0, 0, $this->color); |
|
354 | + } |
|
355 | + $this->width = $thumbw; |
|
356 | + $this->height = $thumbh; |
|
357 | + } elseif ($border == 0) { |
|
358 | 358 | if ($specific_size) { |
359 | 359 | $width = $thumbw; |
360 | 360 | $height = $thumbh; |
@@ -363,19 +363,19 @@ discard block |
||
363 | 363 | $width = (int)($this->width * $scale); |
364 | 364 | $height = (int)($this->height * $scale); |
365 | 365 | } |
366 | - $deltaw = 0; |
|
367 | - $deltah = 0; |
|
368 | - $dst_img = @ImageCreateTrueColor($width, $height); |
|
369 | - @imagealphablending($dst_img, false); |
|
370 | - @imagesavealpha($dst_img, true); |
|
371 | - $this->width = $width; |
|
372 | - $this->height = $height; |
|
373 | - } |
|
374 | - $src_img = $this->bg; |
|
375 | - @ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img)); |
|
376 | - $this->bg = $dst_img; |
|
377 | - @imagedestroy($src_img); |
|
378 | - } |
|
366 | + $deltaw = 0; |
|
367 | + $deltah = 0; |
|
368 | + $dst_img = @ImageCreateTrueColor($width, $height); |
|
369 | + @imagealphablending($dst_img, false); |
|
370 | + @imagesavealpha($dst_img, true); |
|
371 | + $this->width = $width; |
|
372 | + $this->height = $height; |
|
373 | + } |
|
374 | + $src_img = $this->bg; |
|
375 | + @ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img)); |
|
376 | + $this->bg = $dst_img; |
|
377 | + @imagedestroy($src_img); |
|
378 | + } |
|
379 | 379 | |
380 | 380 | /** |
381 | 381 | * @author José Loguercio <[email protected]> |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
390 | 390 | if (!$this->image_validated) return false; |
391 | 391 | $this->width = $width; |
392 | - $this->height = $height; |
|
392 | + $this->height = $height; |
|
393 | 393 | $src = null; |
394 | 394 | $dest = @imagecreatetruecolor($width, $height); |
395 | 395 | $type = $this->type; |
@@ -400,56 +400,56 @@ discard block |
||
400 | 400 | @imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height); |
401 | 401 | @imagejpeg($dest, $this->path); |
402 | 402 | break; |
403 | - case 'png' : |
|
403 | + case 'png' : |
|
404 | 404 | $src = @imagecreatefrompng($this->path); |
405 | 405 | @imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height); |
406 | 406 | @imagepng($dest, $this->path); |
407 | 407 | break; |
408 | - case 'gif' : |
|
409 | - $src = @imagecreatefromgif($this->path); |
|
408 | + case 'gif' : |
|
409 | + $src = @imagecreatefromgif($this->path); |
|
410 | 410 | @imagecopy($dest, $src, 0, 0, $x, $y, $src_width, $src_height); |
411 | 411 | @imagegif($dest, $this->path); |
412 | - break; |
|
412 | + break; |
|
413 | 413 | default: return 0; |
414 | 414 | } |
415 | 415 | @imagedestroy($dest); |
416 | 416 | @imagedestroy($src); |
417 | 417 | } |
418 | 418 | |
419 | - public function send_image($file = '', $compress = -1, $convert_file_to = null) |
|
419 | + public function send_image($file = '', $compress = -1, $convert_file_to = null) |
|
420 | 420 | { |
421 | - if (!$this->image_validated) return false; |
|
421 | + if (!$this->image_validated) return false; |
|
422 | 422 | $compress = (int)$compress; |
423 | 423 | $type = $this->type; |
424 | 424 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
425 | 425 | $type = $convert_file_to; |
426 | 426 | } |
427 | - switch ($type) { |
|
428 | - case 'jpeg': |
|
429 | - case 'jpg': |
|
430 | - if (!$file) header("Content-type: image/jpeg"); |
|
431 | - if ($compress == -1) $compress = 100; |
|
432 | - return imagejpeg($this->bg, $file, $compress); |
|
433 | - break; |
|
434 | - case 'png': |
|
435 | - if (!$file) header("Content-type: image/png"); |
|
436 | - if ($compress != -1) { |
|
437 | - @imagetruecolortopalette($this->bg, true, $compress); |
|
438 | - } |
|
439 | - return imagepng($this->bg, $file, $compress); |
|
440 | - break; |
|
441 | - case 'gif': |
|
442 | - if (!$file) header("Content-type: image/gif"); |
|
443 | - if ($compress != -1) { |
|
444 | - @imagetruecolortopalette($this->bg, true, $compress); |
|
445 | - } |
|
446 | - return imagegif($this->bg, $file, $compress); |
|
447 | - break; |
|
448 | - default: return 0; |
|
449 | - } |
|
450 | - // TODO: Occupied memory is not released, because the following fragment of code is actually dead. |
|
451 | - @imagedestroy($this->bg); |
|
452 | - } |
|
427 | + switch ($type) { |
|
428 | + case 'jpeg': |
|
429 | + case 'jpg': |
|
430 | + if (!$file) header("Content-type: image/jpeg"); |
|
431 | + if ($compress == -1) $compress = 100; |
|
432 | + return imagejpeg($this->bg, $file, $compress); |
|
433 | + break; |
|
434 | + case 'png': |
|
435 | + if (!$file) header("Content-type: image/png"); |
|
436 | + if ($compress != -1) { |
|
437 | + @imagetruecolortopalette($this->bg, true, $compress); |
|
438 | + } |
|
439 | + return imagepng($this->bg, $file, $compress); |
|
440 | + break; |
|
441 | + case 'gif': |
|
442 | + if (!$file) header("Content-type: image/gif"); |
|
443 | + if ($compress != -1) { |
|
444 | + @imagetruecolortopalette($this->bg, true, $compress); |
|
445 | + } |
|
446 | + return imagegif($this->bg, $file, $compress); |
|
447 | + break; |
|
448 | + default: return 0; |
|
449 | + } |
|
450 | + // TODO: Occupied memory is not released, because the following fragment of code is actually dead. |
|
451 | + @imagedestroy($this->bg); |
|
452 | + } |
|
453 | 453 | |
454 | 454 | /** |
455 | 455 | * Convert image to black & white |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | $this->path = preg_match(VALID_WEB_PATH, $path) ? (api_is_internal_path($path) ? api_get_path(TO_SYS, $path) : $path) : $path; |
118 | - $this->set_image_wrapper(); //Creates image obj |
|
118 | + $this->set_image_wrapper(); //Creates image obj |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | abstract function set_image_wrapper(); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | if ($this->debug) error_log('Image::set_image_wrapper loaded'); |
158 | 158 | try { |
159 | 159 | if (file_exists($this->path)) { |
160 | - $this->image = new Imagick($this->path); |
|
160 | + $this->image = new Imagick($this->path); |
|
161 | 161 | |
162 | 162 | if ($this->image) { |
163 | 163 | $this->fill_image_info(); //Fills height, width and type |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } else { |
166 | 166 | if ($this->debug) error_log('Image::image does not exist'); |
167 | 167 | } |
168 | - } catch(ImagickException $e) { |
|
168 | + } catch (ImagickException $e) { |
|
169 | 169 | if ($this->debug) error_log($e->getMessage()); |
170 | 170 | } |
171 | 171 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | public function get_image_size() |
188 | 188 | { |
189 | - $imagesize = array('width'=>0,'height'=>0); |
|
189 | + $imagesize = array('width'=>0, 'height'=>0); |
|
190 | 190 | if ($this->image_validated) { |
191 | 191 | $imagesize = $this->image->getImageGeometry(); |
192 | 192 | } |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $height = $thumbh; |
204 | 204 | } else { |
205 | 205 | $scale = ($this->width > 0 && $this->height > 0) ? min($thumbw / $this->width, $thumbh / $this->height) : 0; |
206 | - $width = (int)($this->width * $scale); |
|
207 | - $height = (int)($this->height * $scale); |
|
206 | + $width = (int) ($this->width * $scale); |
|
207 | + $height = (int) ($this->height * $scale); |
|
208 | 208 | } |
209 | 209 | $result = $this->image->resizeImage($width, $height, $this->filter, 1); |
210 | 210 | $this->width = $thumbw; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $result = false; |
251 | 251 | try { |
252 | 252 | $result = $this->image->writeImage($file); |
253 | - } catch(ImagickException $e) { |
|
253 | + } catch (ImagickException $e) { |
|
254 | 254 | if ($this->debug) error_log($e->getMessage()); |
255 | 255 | } |
256 | 256 | |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | |
312 | 312 | public function get_image_size() |
313 | 313 | { |
314 | - $return_array = array('width'=>0,'height'=>0); |
|
314 | + $return_array = array('width'=>0, 'height'=>0); |
|
315 | 315 | if ($this->image_validated) { |
316 | - $return_array = array('width'=>$this->width,'height'=>$this->height); |
|
316 | + $return_array = array('width'=>$this->width, 'height'=>$this->height); |
|
317 | 317 | } |
318 | 318 | return $return_array; |
319 | 319 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | public function fill_image_info() |
322 | 322 | { |
323 | 323 | if (file_exists($this->path)) { |
324 | - $image_info = getimagesize($this->path); |
|
324 | + $image_info = getimagesize($this->path); |
|
325 | 325 | $this->width = $image_info[0]; |
326 | 326 | $this->height = $image_info[1]; |
327 | 327 | $this->type = $image_info[2]; |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | $height = $thumbh; |
342 | 342 | } else { |
343 | 343 | $scale = min($thumbw / $this->width, $thumbh / $this->height); |
344 | - $width = (int)($this->width * $scale); |
|
345 | - $height = (int)($this->height * $scale); |
|
344 | + $width = (int) ($this->width * $scale); |
|
345 | + $height = (int) ($this->height * $scale); |
|
346 | 346 | } |
347 | - $deltaw = (int)(($thumbw - $width) / 2); |
|
348 | - $deltah = (int)(($thumbh - $height) / 2); |
|
347 | + $deltaw = (int) (($thumbw - $width) / 2); |
|
348 | + $deltah = (int) (($thumbh - $height) / 2); |
|
349 | 349 | $dst_img = @ImageCreateTrueColor($thumbw, $thumbh); |
350 | 350 | @imagealphablending($dst_img, false); |
351 | 351 | @imagesavealpha($dst_img, true); |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | $height = $thumbh; |
361 | 361 | } else { |
362 | 362 | $scale = ($this->width > 0 && $this->height > 0) ? min($thumbw / $this->width, $thumbh / $this->height) : 0; |
363 | - $width = (int)($this->width * $scale); |
|
364 | - $height = (int)($this->height * $scale); |
|
363 | + $width = (int) ($this->width * $scale); |
|
364 | + $height = (int) ($this->height * $scale); |
|
365 | 365 | } |
366 | 366 | $deltaw = 0; |
367 | 367 | $deltah = 0; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
420 | 420 | { |
421 | 421 | if (!$this->image_validated) return false; |
422 | - $compress = (int)$compress; |
|
422 | + $compress = (int) $compress; |
|
423 | 423 | $type = $this->type; |
424 | 424 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
425 | 425 | $type = $convert_file_to; |
@@ -463,11 +463,11 @@ discard block |
||
463 | 463 | * so that we can use black (0,0,0) as transparent, which is what |
464 | 464 | * the image is filled with when created. |
465 | 465 | */ |
466 | - $transparent = imagecolorallocate($dest_img, 0,0,0); |
|
466 | + $transparent = imagecolorallocate($dest_img, 0, 0, 0); |
|
467 | 467 | imagealphablending($dest_img, false); |
468 | 468 | imagesavealpha($dest_img, true); |
469 | 469 | imagecolortransparent($dest_img, $transparent); |
470 | - imagecopy($dest_img, $this->bg, 0,0, 0, 0,imagesx($this->bg), imagesx($this->bg)); |
|
470 | + imagecopy($dest_img, $this->bg, 0, 0, 0, 0, imagesx($this->bg), imagesx($this->bg)); |
|
471 | 471 | imagefilter($dest_img, IMG_FILTER_GRAYSCALE); |
472 | 472 | $this->bg = $dest_img; |
473 | 473 |
@@ -154,7 +154,9 @@ discard block |
||
154 | 154 | |
155 | 155 | public function set_image_wrapper() |
156 | 156 | { |
157 | - if ($this->debug) error_log('Image::set_image_wrapper loaded'); |
|
157 | + if ($this->debug) { |
|
158 | + error_log('Image::set_image_wrapper loaded'); |
|
159 | + } |
|
158 | 160 | try { |
159 | 161 | if (file_exists($this->path)) { |
160 | 162 | $this->image = new Imagick($this->path); |
@@ -163,10 +165,14 @@ discard block |
||
163 | 165 | $this->fill_image_info(); //Fills height, width and type |
164 | 166 | } |
165 | 167 | } else { |
166 | - if ($this->debug) error_log('Image::image does not exist'); |
|
168 | + if ($this->debug) { |
|
169 | + error_log('Image::image does not exist'); |
|
170 | + } |
|
167 | 171 | } |
168 | 172 | } catch(ImagickException $e) { |
169 | - if ($this->debug) error_log($e->getMessage()); |
|
173 | + if ($this->debug) { |
|
174 | + error_log($e->getMessage()); |
|
175 | + } |
|
170 | 176 | } |
171 | 177 | } |
172 | 178 | |
@@ -180,7 +186,9 @@ discard block |
||
180 | 186 | |
181 | 187 | if (in_array($this->type, $this->allowed_extensions)) { |
182 | 188 | $this->image_validated = true; |
183 | - if ($this->debug) error_log('image_validated true'); |
|
189 | + if ($this->debug) { |
|
190 | + error_log('image_validated true'); |
|
191 | + } |
|
184 | 192 | } |
185 | 193 | } |
186 | 194 | |
@@ -196,7 +204,9 @@ discard block |
||
196 | 204 | //@todo implement border logic case for Imagick |
197 | 205 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
198 | 206 | { |
199 | - if (!$this->image_validated) return false; |
|
207 | + if (!$this->image_validated) { |
|
208 | + return false; |
|
209 | + } |
|
200 | 210 | |
201 | 211 | if ($specific_size) { |
202 | 212 | $width = $thumbw; |
@@ -222,7 +232,9 @@ discard block |
||
222 | 232 | */ |
223 | 233 | |
224 | 234 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
225 | - if (!$this->image_validated) return false; |
|
235 | + if (!$this->image_validated) { |
|
236 | + return false; |
|
237 | + } |
|
226 | 238 | $this->image->cropimage($width, $height, $x, $y); |
227 | 239 | $this->width = $width; |
228 | 240 | $this->height = $height; |
@@ -230,7 +242,9 @@ discard block |
||
230 | 242 | |
231 | 243 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
232 | 244 | { |
233 | - if (!$this->image_validated) return false; |
|
245 | + if (!$this->image_validated) { |
|
246 | + return false; |
|
247 | + } |
|
234 | 248 | $type = $this->type; |
235 | 249 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
236 | 250 | $type = $convert_file_to; |
@@ -238,20 +252,28 @@ discard block |
||
238 | 252 | switch ($type) { |
239 | 253 | case 'jpeg': |
240 | 254 | case 'jpg': |
241 | - if (!$file) header("Content-type: image/jpeg"); |
|
255 | + if (!$file) { |
|
256 | + header("Content-type: image/jpeg"); |
|
257 | + } |
|
242 | 258 | break; |
243 | 259 | case 'png': |
244 | - if (!$file) header("Content-type: image/png"); |
|
260 | + if (!$file) { |
|
261 | + header("Content-type: image/png"); |
|
262 | + } |
|
245 | 263 | break; |
246 | 264 | case 'gif': |
247 | - if (!$file) header("Content-type: image/gif"); |
|
265 | + if (!$file) { |
|
266 | + header("Content-type: image/gif"); |
|
267 | + } |
|
248 | 268 | break; |
249 | 269 | } |
250 | 270 | $result = false; |
251 | 271 | try { |
252 | 272 | $result = $this->image->writeImage($file); |
253 | 273 | } catch(ImagickException $e) { |
254 | - if ($this->debug) error_log($e->getMessage()); |
|
274 | + if ($this->debug) { |
|
275 | + error_log($e->getMessage()); |
|
276 | + } |
|
255 | 277 | } |
256 | 278 | |
257 | 279 | if (!$file) { |
@@ -334,7 +356,9 @@ discard block |
||
334 | 356 | |
335 | 357 | public function resize($thumbw, $thumbh, $border, $specific_size = false) |
336 | 358 | { |
337 | - if (!$this->image_validated) return false; |
|
359 | + if (!$this->image_validated) { |
|
360 | + return false; |
|
361 | + } |
|
338 | 362 | if ($border == 1) { |
339 | 363 | if ($specific_size) { |
340 | 364 | $width = $thumbw; |
@@ -387,7 +411,9 @@ discard block |
||
387 | 411 | * @param int $src_height the source height of the original image |
388 | 412 | */ |
389 | 413 | public function crop($x, $y, $width, $height, $src_width, $src_height) { |
390 | - if (!$this->image_validated) return false; |
|
414 | + if (!$this->image_validated) { |
|
415 | + return false; |
|
416 | + } |
|
391 | 417 | $this->width = $width; |
392 | 418 | $this->height = $height; |
393 | 419 | $src = null; |
@@ -418,7 +444,9 @@ discard block |
||
418 | 444 | |
419 | 445 | public function send_image($file = '', $compress = -1, $convert_file_to = null) |
420 | 446 | { |
421 | - if (!$this->image_validated) return false; |
|
447 | + if (!$this->image_validated) { |
|
448 | + return false; |
|
449 | + } |
|
422 | 450 | $compress = (int)$compress; |
423 | 451 | $type = $this->type; |
424 | 452 | if (!empty($convert_file_to) && in_array($convert_file_to, $this->allowed_extensions)) { |
@@ -427,19 +455,27 @@ discard block |
||
427 | 455 | switch ($type) { |
428 | 456 | case 'jpeg': |
429 | 457 | case 'jpg': |
430 | - if (!$file) header("Content-type: image/jpeg"); |
|
431 | - if ($compress == -1) $compress = 100; |
|
458 | + if (!$file) { |
|
459 | + header("Content-type: image/jpeg"); |
|
460 | + } |
|
461 | + if ($compress == -1) { |
|
462 | + $compress = 100; |
|
463 | + } |
|
432 | 464 | return imagejpeg($this->bg, $file, $compress); |
433 | 465 | break; |
434 | 466 | case 'png': |
435 | - if (!$file) header("Content-type: image/png"); |
|
467 | + if (!$file) { |
|
468 | + header("Content-type: image/png"); |
|
469 | + } |
|
436 | 470 | if ($compress != -1) { |
437 | 471 | @imagetruecolortopalette($this->bg, true, $compress); |
438 | 472 | } |
439 | 473 | return imagepng($this->bg, $file, $compress); |
440 | 474 | break; |
441 | 475 | case 'gif': |
442 | - if (!$file) header("Content-type: image/gif"); |
|
476 | + if (!$file) { |
|
477 | + header("Content-type: image/gif"); |
|
478 | + } |
|
443 | 479 | if ($compress != -1) { |
444 | 480 | @imagetruecolortopalette($this->bg, true, $compress); |
445 | 481 | } |
@@ -456,7 +492,9 @@ discard block |
||
456 | 492 | */ |
457 | 493 | function convert2bw() |
458 | 494 | { |
459 | - if (!$this->image_validated) return false; |
|
495 | + if (!$this->image_validated) { |
|
496 | + return false; |
|
497 | + } |
|
460 | 498 | |
461 | 499 | $dest_img = imagecreatetruecolor(imagesx($this->bg), imagesy($this->bg)); |
462 | 500 | /* copy ignore the transparent color |
@@ -408,6 +408,9 @@ discard block |
||
408 | 408 | } # function kses_no_null |
409 | 409 | |
410 | 410 | |
411 | +/** |
|
412 | + * @return string |
|
413 | + */ |
|
411 | 414 | function kses_stripslashes($string) |
412 | 415 | ############################################################################### |
413 | 416 | # This function changes the character sequence \" to just " |
@@ -442,6 +445,9 @@ discard block |
||
442 | 445 | } # function kses_array_lc |
443 | 446 | |
444 | 447 | |
448 | +/** |
|
449 | + * @return string |
|
450 | + */ |
|
445 | 451 | function kses_js_entities($string) |
446 | 452 | ############################################################################### |
447 | 453 | # This function removes the HTML JavaScript entities found in early versions of |
@@ -506,6 +512,9 @@ discard block |
||
506 | 512 | } # function kses_bad_protocol_once2 |
507 | 513 | |
508 | 514 | |
515 | +/** |
|
516 | + * @return string |
|
517 | + */ |
|
509 | 518 | function kses_normalize_entities($string) |
510 | 519 | ############################################################################### |
511 | 520 | # This function normalizes HTML entities. It will convert "AT&T" to the correct |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | |
32 | 32 | |
33 | 33 | function kses($string, $allowed_html, $allowed_protocols = |
34 | - array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', |
|
35 | - 'gopher', 'mailto')) |
|
34 | + array('http', 'https', 'ftp', 'news', 'nntp', 'telnet', |
|
35 | + 'gopher', 'mailto')) |
|
36 | 36 | ############################################################################### |
37 | 37 | # This function makes sure that only the allowed HTML element names, attribute |
38 | 38 | # names and attribute values plus only sane HTML entities will occur in |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | # call this function. |
41 | 41 | ############################################################################### |
42 | 42 | { |
43 | - $string = kses_no_null($string); |
|
44 | - $string = kses_js_entities($string); |
|
45 | - $string = kses_normalize_entities($string); |
|
46 | - $string = kses_hook($string); |
|
47 | - $allowed_html_fixed = kses_array_lc($allowed_html); |
|
48 | - return kses_split($string, $allowed_html_fixed, $allowed_protocols); |
|
43 | + $string = kses_no_null($string); |
|
44 | + $string = kses_js_entities($string); |
|
45 | + $string = kses_normalize_entities($string); |
|
46 | + $string = kses_hook($string); |
|
47 | + $allowed_html_fixed = kses_array_lc($allowed_html); |
|
48 | + return kses_split($string, $allowed_html_fixed, $allowed_protocols); |
|
49 | 49 | } # function kses |
50 | 50 | |
51 | 51 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | # You add any kses hooks here. |
55 | 55 | ############################################################################### |
56 | 56 | { |
57 | - return $string; |
|
57 | + return $string; |
|
58 | 58 | } # function kses_hook |
59 | 59 | |
60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | # This function returns kses' version number. |
64 | 64 | ############################################################################### |
65 | 65 | { |
66 | - return '0.2.2'; |
|
66 | + return '0.2.2'; |
|
67 | 67 | } # function kses_version |
68 | 68 | |
69 | 69 | |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | # matches stray ">" characters. |
74 | 74 | ############################################################################### |
75 | 75 | { |
76 | - return preg_replace('%(<'. # EITHER: < |
|
77 | - '[^>]*'. # things that aren't > |
|
78 | - '(>|$)'. # > or end of string |
|
79 | - '|>)%e', # OR: just a > |
|
80 | - "kses_split2('\\1', \$allowed_html, ". |
|
81 | - '$allowed_protocols)', |
|
82 | - $string); |
|
76 | + return preg_replace('%(<'. # EITHER: < |
|
77 | + '[^>]*'. # things that aren't > |
|
78 | + '(>|$)'. # > or end of string |
|
79 | + '|>)%e', # OR: just a > |
|
80 | + "kses_split2('\\1', \$allowed_html, ". |
|
81 | + '$allowed_protocols)', |
|
82 | + $string); |
|
83 | 83 | } # function kses_split |
84 | 84 | |
85 | 85 | |
@@ -91,30 +91,30 @@ discard block |
||
91 | 91 | # attribute list. |
92 | 92 | ############################################################################### |
93 | 93 | { |
94 | - $string = kses_stripslashes($string); |
|
94 | + $string = kses_stripslashes($string); |
|
95 | 95 | |
96 | - if (substr($string, 0, 1) != '<') |
|
96 | + if (substr($string, 0, 1) != '<') |
|
97 | 97 | return '>'; |
98 | 98 | # It matched a ">" character |
99 | 99 | |
100 | - if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) |
|
100 | + if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) |
|
101 | 101 | return ''; |
102 | 102 | # It's seriously malformed |
103 | 103 | |
104 | - $slash = trim($matches[1]); |
|
105 | - $elem = $matches[2]; |
|
106 | - $attrlist = $matches[3]; |
|
104 | + $slash = trim($matches[1]); |
|
105 | + $elem = $matches[2]; |
|
106 | + $attrlist = $matches[3]; |
|
107 | 107 | |
108 | - if (!@isset($allowed_html[strtolower($elem)])) |
|
108 | + if (!@isset($allowed_html[strtolower($elem)])) |
|
109 | 109 | return ''; |
110 | 110 | # They are using a not allowed HTML element |
111 | 111 | |
112 | - if ($slash != '') |
|
112 | + if ($slash != '') |
|
113 | 113 | return "<$slash$elem>"; |
114 | - # No attributes are allowed for closing elements |
|
114 | + # No attributes are allowed for closing elements |
|
115 | 115 | |
116 | - return kses_attr("$slash$elem", $attrlist, $allowed_html, |
|
117 | - $allowed_protocols); |
|
116 | + return kses_attr("$slash$elem", $attrlist, $allowed_html, |
|
117 | + $allowed_protocols); |
|
118 | 118 | } # function kses_split2 |
119 | 119 | |
120 | 120 | |
@@ -130,56 +130,56 @@ discard block |
||
130 | 130 | { |
131 | 131 | # Is there a closing XHTML slash at the end of the attributes? |
132 | 132 | |
133 | - $xhtml_slash = ''; |
|
134 | - if (preg_match('%\s/\s*$%', $attr)) |
|
133 | + $xhtml_slash = ''; |
|
134 | + if (preg_match('%\s/\s*$%', $attr)) |
|
135 | 135 | $xhtml_slash = ' /'; |
136 | 136 | |
137 | 137 | # Are any attributes allowed at all for this element? |
138 | 138 | |
139 | - if (@count($allowed_html[strtolower($element)]) == 0) |
|
139 | + if (@count($allowed_html[strtolower($element)]) == 0) |
|
140 | 140 | return "<$element$xhtml_slash>"; |
141 | 141 | |
142 | 142 | # Split it |
143 | 143 | |
144 | - $attrarr = kses_hair($attr, $allowed_protocols); |
|
144 | + $attrarr = kses_hair($attr, $allowed_protocols); |
|
145 | 145 | |
146 | 146 | # Go through $attrarr, and save the allowed attributes for this element |
147 | 147 | # in $attr2 |
148 | 148 | |
149 | - $attr2 = ''; |
|
149 | + $attr2 = ''; |
|
150 | 150 | |
151 | - foreach ($attrarr as $arreach) |
|
152 | - { |
|
151 | + foreach ($attrarr as $arreach) |
|
152 | + { |
|
153 | 153 | if (!@isset($allowed_html[strtolower($element)] |
154 | 154 | [strtolower($arreach['name'])])) |
155 | - continue; # the attribute is not allowed |
|
155 | + continue; # the attribute is not allowed |
|
156 | 156 | |
157 | 157 | $current = $allowed_html[strtolower($element)] |
158 | 158 | [strtolower($arreach['name'])]; |
159 | 159 | |
160 | 160 | if (!is_array($current)) |
161 | - $attr2 .= ' '.$arreach['whole']; |
|
161 | + $attr2 .= ' '.$arreach['whole']; |
|
162 | 162 | # there are no checks |
163 | 163 | |
164 | 164 | else |
165 | 165 | { |
166 | 166 | # there are some checks |
167 | - $ok = true; |
|
168 | - foreach ($current as $currkey => $currval) |
|
167 | + $ok = true; |
|
168 | + foreach ($current as $currkey => $currval) |
|
169 | 169 | if (!kses_check_attr_val($arreach['value'], $arreach['vless'], |
170 | - $currkey, $currval)) |
|
170 | + $currkey, $currval)) |
|
171 | 171 | { $ok = false; break; } |
172 | 172 | |
173 | - if ($ok) |
|
173 | + if ($ok) |
|
174 | 174 | $attr2 .= ' '.$arreach['whole']; # it passed them |
175 | 175 | } # if !is_array($current) |
176 | - } # foreach |
|
176 | + } # foreach |
|
177 | 177 | |
178 | 178 | # Remove any "<" or ">" characters |
179 | 179 | |
180 | - $attr2 = preg_replace('/[<>]/', '', $attr2); |
|
180 | + $attr2 = preg_replace('/[<>]/', '', $attr2); |
|
181 | 181 | |
182 | - return "<$element$attr2$xhtml_slash>"; |
|
182 | + return "<$element$attr2$xhtml_slash>"; |
|
183 | 183 | } # function kses_attr |
184 | 184 | |
185 | 185 | |
@@ -193,96 +193,96 @@ discard block |
||
193 | 193 | # from attribute values. |
194 | 194 | ############################################################################### |
195 | 195 | { |
196 | - $attrarr = array(); |
|
197 | - $mode = 0; |
|
198 | - $attrname = ''; |
|
196 | + $attrarr = array(); |
|
197 | + $mode = 0; |
|
198 | + $attrname = ''; |
|
199 | 199 | |
200 | 200 | # Loop through the whole attribute list |
201 | 201 | |
202 | - while (strlen($attr) != 0) |
|
203 | - { |
|
202 | + while (strlen($attr) != 0) |
|
203 | + { |
|
204 | 204 | $working = 0; # Was the last operation successful? |
205 | 205 | |
206 | 206 | switch ($mode) |
207 | 207 | { |
208 | - case 0: # attribute name, href for instance |
|
208 | + case 0: # attribute name, href for instance |
|
209 | 209 | |
210 | 210 | if (preg_match('/^([-a-zA-Z]+)/', $attr, $match)) |
211 | 211 | { |
212 | - $attrname = $match[1]; |
|
213 | - $working = $mode = 1; |
|
214 | - $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr); |
|
212 | + $attrname = $match[1]; |
|
213 | + $working = $mode = 1; |
|
214 | + $attr = preg_replace('/^[-a-zA-Z]+/', '', $attr); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | break; |
218 | 218 | |
219 | - case 1: # equals sign or valueless ("selected") |
|
219 | + case 1: # equals sign or valueless ("selected") |
|
220 | 220 | |
221 | 221 | if (preg_match('/^\s*=\s*/', $attr)) # equals sign |
222 | 222 | { |
223 | - $working = 1; $mode = 2; |
|
224 | - $attr = preg_replace('/^\s*=\s*/', '', $attr); |
|
225 | - break; |
|
223 | + $working = 1; $mode = 2; |
|
224 | + $attr = preg_replace('/^\s*=\s*/', '', $attr); |
|
225 | + break; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | if (preg_match('/^\s+/', $attr)) # valueless |
229 | 229 | { |
230 | - $working = 1; $mode = 0; |
|
231 | - $attrarr[] = array |
|
230 | + $working = 1; $mode = 0; |
|
231 | + $attrarr[] = array |
|
232 | 232 | ('name' => $attrname, |
233 | - 'value' => '', |
|
234 | - 'whole' => $attrname, |
|
235 | - 'vless' => 'y'); |
|
236 | - $attr = preg_replace('/^\s+/', '', $attr); |
|
233 | + 'value' => '', |
|
234 | + 'whole' => $attrname, |
|
235 | + 'vless' => 'y'); |
|
236 | + $attr = preg_replace('/^\s+/', '', $attr); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | break; |
240 | 240 | |
241 | - case 2: # attribute value, a URL after href= for instance |
|
241 | + case 2: # attribute value, a URL after href= for instance |
|
242 | 242 | |
243 | 243 | if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) |
244 | - # "value" |
|
244 | + # "value" |
|
245 | 245 | { |
246 | - $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
|
246 | + $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
|
247 | 247 | |
248 | - $attrarr[] = array |
|
248 | + $attrarr[] = array |
|
249 | 249 | ('name' => $attrname, |
250 | - 'value' => $thisval, |
|
251 | - 'whole' => "$attrname=\"$thisval\"", |
|
252 | - 'vless' => 'n'); |
|
253 | - $working = 1; $mode = 0; |
|
254 | - $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr); |
|
255 | - break; |
|
250 | + 'value' => $thisval, |
|
251 | + 'whole' => "$attrname=\"$thisval\"", |
|
252 | + 'vless' => 'n'); |
|
253 | + $working = 1; $mode = 0; |
|
254 | + $attr = preg_replace('/^"[^"]*"(\s+|$)/', '', $attr); |
|
255 | + break; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) |
259 | - # 'value' |
|
259 | + # 'value' |
|
260 | 260 | { |
261 | - $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
|
261 | + $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
|
262 | 262 | |
263 | - $attrarr[] = array |
|
263 | + $attrarr[] = array |
|
264 | 264 | ('name' => $attrname, |
265 | - 'value' => $thisval, |
|
266 | - 'whole' => "$attrname='$thisval'", |
|
267 | - 'vless' => 'n'); |
|
268 | - $working = 1; $mode = 0; |
|
269 | - $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr); |
|
270 | - break; |
|
265 | + 'value' => $thisval, |
|
266 | + 'whole' => "$attrname='$thisval'", |
|
267 | + 'vless' => 'n'); |
|
268 | + $working = 1; $mode = 0; |
|
269 | + $attr = preg_replace("/^'[^']*'(\s+|$)/", '', $attr); |
|
270 | + break; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) |
274 | - # value |
|
274 | + # value |
|
275 | 275 | { |
276 | - $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
|
276 | + $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
|
277 | 277 | |
278 | - $attrarr[] = array |
|
278 | + $attrarr[] = array |
|
279 | 279 | ('name' => $attrname, |
280 | - 'value' => $thisval, |
|
281 | - 'whole' => "$attrname=\"$thisval\"", |
|
282 | - 'vless' => 'n'); |
|
283 | - # We add quotes to conform to W3C's HTML spec. |
|
284 | - $working = 1; $mode = 0; |
|
285 | - $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr); |
|
280 | + 'value' => $thisval, |
|
281 | + 'whole' => "$attrname=\"$thisval\"", |
|
282 | + 'vless' => 'n'); |
|
283 | + # We add quotes to conform to W3C's HTML spec. |
|
284 | + $working = 1; $mode = 0; |
|
285 | + $attr = preg_replace("%^[^\s\"']+(\s+|$)%", '', $attr); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | break; |
@@ -290,21 +290,21 @@ discard block |
||
290 | 290 | |
291 | 291 | if ($working == 0) # not well formed, remove and try again |
292 | 292 | { |
293 | - $attr = kses_html_error($attr); |
|
294 | - $mode = 0; |
|
293 | + $attr = kses_html_error($attr); |
|
294 | + $mode = 0; |
|
295 | 295 | } |
296 | - } # while |
|
296 | + } # while |
|
297 | 297 | |
298 | - if ($mode == 1) |
|
299 | - # special case, for when the attribute list ends with a valueless |
|
300 | - # attribute like "selected" |
|
298 | + if ($mode == 1) |
|
299 | + # special case, for when the attribute list ends with a valueless |
|
300 | + # attribute like "selected" |
|
301 | 301 | $attrarr[] = array |
302 | - ('name' => $attrname, |
|
303 | - 'value' => '', |
|
304 | - 'whole' => $attrname, |
|
305 | - 'vless' => 'y'); |
|
302 | + ('name' => $attrname, |
|
303 | + 'value' => '', |
|
304 | + 'whole' => $attrname, |
|
305 | + 'vless' => 'y'); |
|
306 | 306 | |
307 | - return $attrarr; |
|
307 | + return $attrarr; |
|
308 | 308 | } # function kses_hair |
309 | 309 | |
310 | 310 | |
@@ -315,10 +315,10 @@ discard block |
||
315 | 315 | # with even more checks to come soon. |
316 | 316 | ############################################################################### |
317 | 317 | { |
318 | - $ok = true; |
|
318 | + $ok = true; |
|
319 | 319 | |
320 | - switch (strtolower($checkname)) |
|
321 | - { |
|
320 | + switch (strtolower($checkname)) |
|
321 | + { |
|
322 | 322 | case 'maxlen': |
323 | 323 | # The maxlen check makes sure that the attribute value has a length not |
324 | 324 | # greater than the given value. This can be used to avoid Buffer Overflows |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | |
327 | 327 | if (strlen($value) > $checkvalue) |
328 | 328 | $ok = false; |
329 | - break; |
|
329 | + break; |
|
330 | 330 | |
331 | 331 | case 'minlen': |
332 | 332 | # The minlen check makes sure that the attribute value has a length not |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | |
335 | 335 | if (strlen($value) < $checkvalue) |
336 | 336 | $ok = false; |
337 | - break; |
|
337 | + break; |
|
338 | 338 | |
339 | 339 | case 'maxval': |
340 | 340 | # The maxval check does two things: it checks that the attribute value is |
@@ -345,9 +345,9 @@ discard block |
||
345 | 345 | |
346 | 346 | if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
347 | 347 | $ok = false; |
348 | - if ($value > $checkvalue) |
|
348 | + if ($value > $checkvalue) |
|
349 | 349 | $ok = false; |
350 | - break; |
|
350 | + break; |
|
351 | 351 | |
352 | 352 | case 'minval': |
353 | 353 | # The minval check checks that the attribute value is a positive integer, |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | |
356 | 356 | if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
357 | 357 | $ok = false; |
358 | - if ($value < $checkvalue) |
|
358 | + if ($value < $checkvalue) |
|
359 | 359 | $ok = false; |
360 | - break; |
|
360 | + break; |
|
361 | 361 | |
362 | 362 | case 'valueless': |
363 | 363 | # The valueless check checks if the attribute has a value |
@@ -367,10 +367,10 @@ discard block |
||
367 | 367 | |
368 | 368 | if (strtolower($checkvalue) != $vless) |
369 | 369 | $ok = false; |
370 | - break; |
|
371 | - } # switch |
|
370 | + break; |
|
371 | + } # switch |
|
372 | 372 | |
373 | - return $ok; |
|
373 | + return $ok; |
|
374 | 374 | } # function kses_check_attr_val |
375 | 375 | |
376 | 376 | |
@@ -382,17 +382,17 @@ discard block |
||
382 | 382 | # fooled by a string like "javascript:javascript:alert(57)". |
383 | 383 | ############################################################################### |
384 | 384 | { |
385 | - $string = kses_no_null($string); |
|
386 | - $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature" |
|
387 | - $string2 = $string.'a'; |
|
385 | + $string = kses_no_null($string); |
|
386 | + $string = preg_replace('/\xad+/', '', $string); # deals with Opera "feature" |
|
387 | + $string2 = $string.'a'; |
|
388 | 388 | |
389 | - while ($string != $string2) |
|
390 | - { |
|
389 | + while ($string != $string2) |
|
390 | + { |
|
391 | 391 | $string2 = $string; |
392 | 392 | $string = kses_bad_protocol_once($string, $allowed_protocols); |
393 | - } # while |
|
393 | + } # while |
|
394 | 394 | |
395 | - return $string; |
|
395 | + return $string; |
|
396 | 396 | } # function kses_bad_protocol |
397 | 397 | |
398 | 398 | |
@@ -401,10 +401,10 @@ discard block |
||
401 | 401 | # This function removes any NULL characters in $string. |
402 | 402 | ############################################################################### |
403 | 403 | { |
404 | - $string = preg_replace('/\0+/', '', $string); |
|
405 | - $string = preg_replace('/(\\\\0)+/', '', $string); |
|
404 | + $string = preg_replace('/\0+/', '', $string); |
|
405 | + $string = preg_replace('/(\\\\0)+/', '', $string); |
|
406 | 406 | |
407 | - return $string; |
|
407 | + return $string; |
|
408 | 408 | } # function kses_no_null |
409 | 409 | |
410 | 410 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | # preg_replace(//e) seems to require this. |
416 | 416 | ############################################################################### |
417 | 417 | { |
418 | - return preg_replace('%\\\\"%', '"', $string); |
|
418 | + return preg_replace('%\\\\"%', '"', $string); |
|
419 | 419 | } # function kses_stripslashes |
420 | 420 | |
421 | 421 | |
@@ -424,21 +424,21 @@ discard block |
||
424 | 424 | # This function goes through an array, and changes the keys to all lower case. |
425 | 425 | ############################################################################### |
426 | 426 | { |
427 | - $outarray = array(); |
|
427 | + $outarray = array(); |
|
428 | 428 | |
429 | - foreach ($inarray as $inkey => $inval) |
|
430 | - { |
|
429 | + foreach ($inarray as $inkey => $inval) |
|
430 | + { |
|
431 | 431 | $outkey = strtolower($inkey); |
432 | 432 | $outarray[$outkey] = array(); |
433 | 433 | |
434 | 434 | foreach ($inval as $inkey2 => $inval2) |
435 | 435 | { |
436 | - $outkey2 = strtolower($inkey2); |
|
437 | - $outarray[$outkey][$outkey2] = $inval2; |
|
436 | + $outkey2 = strtolower($inkey2); |
|
437 | + $outarray[$outkey][$outkey2] = $inval2; |
|
438 | 438 | } # foreach $inval |
439 | - } # foreach $inarray |
|
439 | + } # foreach $inarray |
|
440 | 440 | |
441 | - return $outarray; |
|
441 | + return $outarray; |
|
442 | 442 | } # function kses_array_lc |
443 | 443 | |
444 | 444 | |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | # Netscape 4. |
449 | 449 | ############################################################################### |
450 | 450 | { |
451 | - return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string); |
|
451 | + return preg_replace('%&\s*\{[^}]*(\}\s*;?|$)%', '', $string); |
|
452 | 452 | } # function kses_js_entities |
453 | 453 | |
454 | 454 | |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | # quotes and apostrophes as well. |
460 | 460 | ############################################################################### |
461 | 461 | { |
462 | - return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string); |
|
462 | + return preg_replace('/^("[^"]*("|$)|\'[^\']*(\'|$)|\S)*\s*/', '', $string); |
|
463 | 463 | } # function kses_html_error |
464 | 464 | |
465 | 465 | |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | # handling whitespace and HTML entities. |
470 | 470 | ############################################################################### |
471 | 471 | { |
472 | - $string2 = preg_split('/:|:|:/i', $string, 2); |
|
473 | - if(isset($string2[1]) && !preg_match('%/\?%',$string2[0])) |
|
474 | - { |
|
475 | - $string = kses_bad_protocol_once2($string2[0],$allowed_protocols).trim($string2[1]); |
|
476 | - } |
|
477 | - return $string; |
|
472 | + $string2 = preg_split('/:|:|:/i', $string, 2); |
|
473 | + if(isset($string2[1]) && !preg_match('%/\?%',$string2[0])) |
|
474 | + { |
|
475 | + $string = kses_bad_protocol_once2($string2[0],$allowed_protocols).trim($string2[1]); |
|
476 | + } |
|
477 | + return $string; |
|
478 | 478 | } # function kses_bad_protocol_once |
479 | 479 | |
480 | 480 | |
@@ -484,24 +484,24 @@ discard block |
||
484 | 484 | # list or not, and returns different data depending on the answer. |
485 | 485 | ############################################################################### |
486 | 486 | { |
487 | - $string2 = kses_decode_entities($string); |
|
488 | - $string2 = preg_replace('/\s/', '', $string2); |
|
489 | - $string2 = kses_no_null($string2); |
|
490 | - $string2 = preg_replace('/\xad+/', '', $string2); |
|
491 | - # deals with Opera "feature" |
|
492 | - $string2 = strtolower($string2); |
|
493 | - |
|
494 | - $allowed = false; |
|
495 | - foreach ($allowed_protocols as $one_protocol) |
|
487 | + $string2 = kses_decode_entities($string); |
|
488 | + $string2 = preg_replace('/\s/', '', $string2); |
|
489 | + $string2 = kses_no_null($string2); |
|
490 | + $string2 = preg_replace('/\xad+/', '', $string2); |
|
491 | + # deals with Opera "feature" |
|
492 | + $string2 = strtolower($string2); |
|
493 | + |
|
494 | + $allowed = false; |
|
495 | + foreach ($allowed_protocols as $one_protocol) |
|
496 | 496 | if (strtolower($one_protocol) == $string2) |
497 | 497 | { |
498 | - $allowed = true; |
|
499 | - break; |
|
498 | + $allowed = true; |
|
499 | + break; |
|
500 | 500 | } |
501 | 501 | |
502 | - if ($allowed) |
|
502 | + if ($allowed) |
|
503 | 503 | return "$string2:"; |
504 | - else |
|
504 | + else |
|
505 | 505 | return ''; |
506 | 506 | } # function kses_bad_protocol_once2 |
507 | 507 | |
@@ -514,18 +514,18 @@ discard block |
||
514 | 514 | { |
515 | 515 | # Disarm all entities by converting & to & |
516 | 516 | |
517 | - $string = str_replace('&', '&', $string); |
|
517 | + $string = str_replace('&', '&', $string); |
|
518 | 518 | |
519 | 519 | # Change back the allowed entities in our entity whitelist |
520 | 520 | |
521 | - $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', |
|
522 | - '&\\1;', $string); |
|
523 | - $string = preg_replace('/&#0*([0-9]{1,5});/e', |
|
524 | - 'kses_normalize_entities2("\\1")', $string); |
|
525 | - $string = preg_replace('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', |
|
526 | - '&#\\1\\2;', $string); |
|
521 | + $string = preg_replace('/&([A-Za-z][A-Za-z0-9]{0,19});/', |
|
522 | + '&\\1;', $string); |
|
523 | + $string = preg_replace('/&#0*([0-9]{1,5});/e', |
|
524 | + 'kses_normalize_entities2("\\1")', $string); |
|
525 | + $string = preg_replace('/&#([Xx])0*(([0-9A-Fa-f]{2}){1,2});/', |
|
526 | + '&#\\1\\2;', $string); |
|
527 | 527 | |
528 | - return $string; |
|
528 | + return $string; |
|
529 | 529 | } # function kses_normalize_entities |
530 | 530 | |
531 | 531 | |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | # and nothing more for &#number; entities. |
536 | 536 | ############################################################################### |
537 | 537 | { |
538 | - return (($i > 65535) ? "&#$i;" : "&#$i;"); |
|
538 | + return (($i > 65535) ? "&#$i;" : "&#$i;"); |
|
539 | 539 | } # function kses_normalize_entities2 |
540 | 540 | |
541 | 541 | |
@@ -546,11 +546,11 @@ discard block |
||
546 | 546 | # URL protocol whitelisting system anyway. |
547 | 547 | ############################################################################### |
548 | 548 | { |
549 | - $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string); |
|
550 | - $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))', |
|
551 | - $string); |
|
549 | + $string = preg_replace('/&#([0-9]+);/e', 'chr("\\1")', $string); |
|
550 | + $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', 'chr(hexdec("\\1"))', |
|
551 | + $string); |
|
552 | 552 | |
553 | - return $string; |
|
553 | + return $string; |
|
554 | 554 | } # function kses_decode_entities |
555 | 555 | |
556 | 556 | ?> |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | # matches stray ">" characters. |
74 | 74 | ############################################################################### |
75 | 75 | { |
76 | - return preg_replace('%(<'. # EITHER: < |
|
77 | - '[^>]*'. # things that aren't > |
|
78 | - '(>|$)'. # > or end of string |
|
76 | + return preg_replace('%(<'.# EITHER: < |
|
77 | + '[^>]*'.# things that aren't > |
|
78 | + '(>|$)'.# > or end of string |
|
79 | 79 | '|>)%e', # OR: just a > |
80 | 80 | "kses_split2('\\1', \$allowed_html, ". |
81 | 81 | '$allowed_protocols)', |
@@ -228,8 +228,7 @@ discard block |
||
228 | 228 | if (preg_match('/^\s+/', $attr)) # valueless |
229 | 229 | { |
230 | 230 | $working = 1; $mode = 0; |
231 | - $attrarr[] = array |
|
232 | - ('name' => $attrname, |
|
231 | + $attrarr[] = array('name' => $attrname, |
|
233 | 232 | 'value' => '', |
234 | 233 | 'whole' => $attrname, |
235 | 234 | 'vless' => 'y'); |
@@ -245,8 +244,7 @@ discard block |
||
245 | 244 | { |
246 | 245 | $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
247 | 246 | |
248 | - $attrarr[] = array |
|
249 | - ('name' => $attrname, |
|
247 | + $attrarr[] = array('name' => $attrname, |
|
250 | 248 | 'value' => $thisval, |
251 | 249 | 'whole' => "$attrname=\"$thisval\"", |
252 | 250 | 'vless' => 'n'); |
@@ -260,8 +258,7 @@ discard block |
||
260 | 258 | { |
261 | 259 | $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
262 | 260 | |
263 | - $attrarr[] = array |
|
264 | - ('name' => $attrname, |
|
261 | + $attrarr[] = array('name' => $attrname, |
|
265 | 262 | 'value' => $thisval, |
266 | 263 | 'whole' => "$attrname='$thisval'", |
267 | 264 | 'vless' => 'n'); |
@@ -275,8 +272,7 @@ discard block |
||
275 | 272 | { |
276 | 273 | $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
277 | 274 | |
278 | - $attrarr[] = array |
|
279 | - ('name' => $attrname, |
|
275 | + $attrarr[] = array('name' => $attrname, |
|
280 | 276 | 'value' => $thisval, |
281 | 277 | 'whole' => "$attrname=\"$thisval\"", |
282 | 278 | 'vless' => 'n'); |
@@ -298,8 +294,7 @@ discard block |
||
298 | 294 | if ($mode == 1) |
299 | 295 | # special case, for when the attribute list ends with a valueless |
300 | 296 | # attribute like "selected" |
301 | - $attrarr[] = array |
|
302 | - ('name' => $attrname, |
|
297 | + $attrarr[] = array('name' => $attrname, |
|
303 | 298 | 'value' => '', |
304 | 299 | 'whole' => $attrname, |
305 | 300 | 'vless' => 'y'); |
@@ -470,9 +465,9 @@ discard block |
||
470 | 465 | ############################################################################### |
471 | 466 | { |
472 | 467 | $string2 = preg_split('/:|:|:/i', $string, 2); |
473 | - if(isset($string2[1]) && !preg_match('%/\?%',$string2[0])) |
|
468 | + if (isset($string2[1]) && !preg_match('%/\?%', $string2[0])) |
|
474 | 469 | { |
475 | - $string = kses_bad_protocol_once2($string2[0],$allowed_protocols).trim($string2[1]); |
|
470 | + $string = kses_bad_protocol_once2($string2[0], $allowed_protocols).trim($string2[1]); |
|
476 | 471 | } |
477 | 472 | return $string; |
478 | 473 | } # function kses_bad_protocol_once |
@@ -93,24 +93,28 @@ discard block |
||
93 | 93 | { |
94 | 94 | $string = kses_stripslashes($string); |
95 | 95 | |
96 | - if (substr($string, 0, 1) != '<') |
|
97 | - return '>'; |
|
96 | + if (substr($string, 0, 1) != '<') { |
|
97 | + return '>'; |
|
98 | + } |
|
98 | 99 | # It matched a ">" character |
99 | 100 | |
100 | - if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) |
|
101 | - return ''; |
|
101 | + if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9]+)([^>]*)>?$%', $string, $matches)) { |
|
102 | + return ''; |
|
103 | + } |
|
102 | 104 | # It's seriously malformed |
103 | 105 | |
104 | 106 | $slash = trim($matches[1]); |
105 | 107 | $elem = $matches[2]; |
106 | 108 | $attrlist = $matches[3]; |
107 | 109 | |
108 | - if (!@isset($allowed_html[strtolower($elem)])) |
|
109 | - return ''; |
|
110 | + if (!@isset($allowed_html[strtolower($elem)])) { |
|
111 | + return ''; |
|
112 | + } |
|
110 | 113 | # They are using a not allowed HTML element |
111 | 114 | |
112 | - if ($slash != '') |
|
113 | - return "<$slash$elem>"; |
|
115 | + if ($slash != '') { |
|
116 | + return "<$slash$elem>"; |
|
117 | + } |
|
114 | 118 | # No attributes are allowed for closing elements |
115 | 119 | |
116 | 120 | return kses_attr("$slash$elem", $attrlist, $allowed_html, |
@@ -131,13 +135,15 @@ discard block |
||
131 | 135 | # Is there a closing XHTML slash at the end of the attributes? |
132 | 136 | |
133 | 137 | $xhtml_slash = ''; |
134 | - if (preg_match('%\s/\s*$%', $attr)) |
|
135 | - $xhtml_slash = ' /'; |
|
138 | + if (preg_match('%\s/\s*$%', $attr)) { |
|
139 | + $xhtml_slash = ' /'; |
|
140 | + } |
|
136 | 141 | |
137 | 142 | # Are any attributes allowed at all for this element? |
138 | 143 | |
139 | - if (@count($allowed_html[strtolower($element)]) == 0) |
|
140 | - return "<$element$xhtml_slash>"; |
|
144 | + if (@count($allowed_html[strtolower($element)]) == 0) { |
|
145 | + return "<$element$xhtml_slash>"; |
|
146 | + } |
|
141 | 147 | |
142 | 148 | # Split it |
143 | 149 | |
@@ -151,27 +157,34 @@ discard block |
||
151 | 157 | foreach ($attrarr as $arreach) |
152 | 158 | { |
153 | 159 | if (!@isset($allowed_html[strtolower($element)] |
154 | - [strtolower($arreach['name'])])) |
|
155 | - continue; # the attribute is not allowed |
|
160 | + [strtolower($arreach['name'])])) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + # the attribute is not allowed |
|
156 | 164 | |
157 | 165 | $current = $allowed_html[strtolower($element)] |
158 | 166 | [strtolower($arreach['name'])]; |
159 | 167 | |
160 | - if (!is_array($current)) |
|
161 | - $attr2 .= ' '.$arreach['whole']; |
|
168 | + if (!is_array($current)) { |
|
169 | + $attr2 .= ' '.$arreach['whole']; |
|
170 | + } |
|
162 | 171 | # there are no checks |
163 | 172 | |
164 | 173 | else |
165 | 174 | { |
166 | 175 | # there are some checks |
167 | 176 | $ok = true; |
168 | - foreach ($current as $currkey => $currval) |
|
169 | - if (!kses_check_attr_val($arreach['value'], $arreach['vless'], |
|
177 | + foreach ($current as $currkey => $currval) { |
|
178 | + if (!kses_check_attr_val($arreach['value'], $arreach['vless'], |
|
170 | 179 | $currkey, $currval)) |
171 | - { $ok = false; break; } |
|
172 | - |
|
173 | - if ($ok) |
|
174 | - $attr2 .= ' '.$arreach['whole']; # it passed them |
|
180 | + { $ok = false; |
|
181 | + } |
|
182 | + break; } |
|
183 | + |
|
184 | + if ($ok) { |
|
185 | + $attr2 .= ' '.$arreach['whole']; |
|
186 | + } |
|
187 | + # it passed them |
|
175 | 188 | } # if !is_array($current) |
176 | 189 | } # foreach |
177 | 190 | |
@@ -218,16 +231,22 @@ discard block |
||
218 | 231 | |
219 | 232 | case 1: # equals sign or valueless ("selected") |
220 | 233 | |
221 | - if (preg_match('/^\s*=\s*/', $attr)) # equals sign |
|
234 | + if (preg_match('/^\s*=\s*/', $attr)) { |
|
235 | + # equals sign |
|
222 | 236 | { |
223 | - $working = 1; $mode = 2; |
|
237 | + $working = 1; |
|
238 | + } |
|
239 | + $mode = 2; |
|
224 | 240 | $attr = preg_replace('/^\s*=\s*/', '', $attr); |
225 | 241 | break; |
226 | 242 | } |
227 | 243 | |
228 | - if (preg_match('/^\s+/', $attr)) # valueless |
|
244 | + if (preg_match('/^\s+/', $attr)) { |
|
245 | + # valueless |
|
229 | 246 | { |
230 | - $working = 1; $mode = 0; |
|
247 | + $working = 1; |
|
248 | + } |
|
249 | + $mode = 0; |
|
231 | 250 | $attrarr[] = array |
232 | 251 | ('name' => $attrname, |
233 | 252 | 'value' => '', |
@@ -240,10 +259,11 @@ discard block |
||
240 | 259 | |
241 | 260 | case 2: # attribute value, a URL after href= for instance |
242 | 261 | |
243 | - if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) |
|
244 | - # "value" |
|
262 | + if (preg_match('/^"([^"]*)"(\s+|$)/', $attr, $match)) { |
|
263 | + # "value" |
|
245 | 264 | { |
246 | 265 | $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
266 | + } |
|
247 | 267 | |
248 | 268 | $attrarr[] = array |
249 | 269 | ('name' => $attrname, |
@@ -255,10 +275,11 @@ discard block |
||
255 | 275 | break; |
256 | 276 | } |
257 | 277 | |
258 | - if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) |
|
259 | - # 'value' |
|
278 | + if (preg_match("/^'([^']*)'(\s+|$)/", $attr, $match)) { |
|
279 | + # 'value' |
|
260 | 280 | { |
261 | 281 | $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
282 | + } |
|
262 | 283 | |
263 | 284 | $attrarr[] = array |
264 | 285 | ('name' => $attrname, |
@@ -270,10 +291,11 @@ discard block |
||
270 | 291 | break; |
271 | 292 | } |
272 | 293 | |
273 | - if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) |
|
274 | - # value |
|
294 | + if (preg_match("%^([^\s\"']+)(\s+|$)%", $attr, $match)) { |
|
295 | + # value |
|
275 | 296 | { |
276 | 297 | $thisval = kses_bad_protocol($match[1], $allowed_protocols); |
298 | + } |
|
277 | 299 | |
278 | 300 | $attrarr[] = array |
279 | 301 | ('name' => $attrname, |
@@ -288,21 +310,24 @@ discard block |
||
288 | 310 | break; |
289 | 311 | } # switch |
290 | 312 | |
291 | - if ($working == 0) # not well formed, remove and try again |
|
313 | + if ($working == 0) { |
|
314 | + # not well formed, remove and try again |
|
292 | 315 | { |
293 | 316 | $attr = kses_html_error($attr); |
317 | + } |
|
294 | 318 | $mode = 0; |
295 | 319 | } |
296 | 320 | } # while |
297 | 321 | |
298 | - if ($mode == 1) |
|
299 | - # special case, for when the attribute list ends with a valueless |
|
322 | + if ($mode == 1) { |
|
323 | + # special case, for when the attribute list ends with a valueless |
|
300 | 324 | # attribute like "selected" |
301 | 325 | $attrarr[] = array |
302 | 326 | ('name' => $attrname, |
303 | 327 | 'value' => '', |
304 | 328 | 'whole' => $attrname, |
305 | 329 | 'vless' => 'y'); |
330 | + } |
|
306 | 331 | |
307 | 332 | return $attrarr; |
308 | 333 | } # function kses_hair |
@@ -324,16 +349,18 @@ discard block |
||
324 | 349 | # greater than the given value. This can be used to avoid Buffer Overflows |
325 | 350 | # in WWW clients and various Internet servers. |
326 | 351 | |
327 | - if (strlen($value) > $checkvalue) |
|
328 | - $ok = false; |
|
352 | + if (strlen($value) > $checkvalue) { |
|
353 | + $ok = false; |
|
354 | + } |
|
329 | 355 | break; |
330 | 356 | |
331 | 357 | case 'minlen': |
332 | 358 | # The minlen check makes sure that the attribute value has a length not |
333 | 359 | # smaller than the given value. |
334 | 360 | |
335 | - if (strlen($value) < $checkvalue) |
|
336 | - $ok = false; |
|
361 | + if (strlen($value) < $checkvalue) { |
|
362 | + $ok = false; |
|
363 | + } |
|
337 | 364 | break; |
338 | 365 | |
339 | 366 | case 'maxval': |
@@ -343,20 +370,24 @@ discard block |
||
343 | 370 | # value is not greater than the given value. |
344 | 371 | # This check can be used to avoid Denial of Service attacks. |
345 | 372 | |
346 | - if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
347 | - $ok = false; |
|
348 | - if ($value > $checkvalue) |
|
349 | - $ok = false; |
|
373 | + if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) { |
|
374 | + $ok = false; |
|
375 | + } |
|
376 | + if ($value > $checkvalue) { |
|
377 | + $ok = false; |
|
378 | + } |
|
350 | 379 | break; |
351 | 380 | |
352 | 381 | case 'minval': |
353 | 382 | # The minval check checks that the attribute value is a positive integer, |
354 | 383 | # and that it is not smaller than the given value. |
355 | 384 | |
356 | - if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) |
|
357 | - $ok = false; |
|
358 | - if ($value < $checkvalue) |
|
359 | - $ok = false; |
|
385 | + if (!preg_match('/^\s{0,6}[0-9]{1,6}\s{0,6}$/', $value)) { |
|
386 | + $ok = false; |
|
387 | + } |
|
388 | + if ($value < $checkvalue) { |
|
389 | + $ok = false; |
|
390 | + } |
|
360 | 391 | break; |
361 | 392 | |
362 | 393 | case 'valueless': |
@@ -365,8 +396,9 @@ discard block |
||
365 | 396 | # is a "y" or a "Y", the attribute must not have a value. |
366 | 397 | # If the given value is an "n" or an "N", the attribute must have one. |
367 | 398 | |
368 | - if (strtolower($checkvalue) != $vless) |
|
369 | - $ok = false; |
|
399 | + if (strtolower($checkvalue) != $vless) { |
|
400 | + $ok = false; |
|
401 | + } |
|
370 | 402 | break; |
371 | 403 | } # switch |
372 | 404 | |
@@ -492,18 +524,20 @@ discard block |
||
492 | 524 | $string2 = strtolower($string2); |
493 | 525 | |
494 | 526 | $allowed = false; |
495 | - foreach ($allowed_protocols as $one_protocol) |
|
496 | - if (strtolower($one_protocol) == $string2) |
|
527 | + foreach ($allowed_protocols as $one_protocol) { |
|
528 | + if (strtolower($one_protocol) == $string2) |
|
497 | 529 | { |
498 | 530 | $allowed = true; |
531 | + } |
|
499 | 532 | break; |
500 | 533 | } |
501 | 534 | |
502 | - if ($allowed) |
|
503 | - return "$string2:"; |
|
504 | - else |
|
505 | - return ''; |
|
506 | -} # function kses_bad_protocol_once2 |
|
535 | + if ($allowed) { |
|
536 | + return "$string2:"; |
|
537 | + } else { |
|
538 | + return ''; |
|
539 | + } |
|
540 | + } # function kses_bad_protocol_once2 |
|
507 | 541 | |
508 | 542 | |
509 | 543 | function kses_normalize_entities($string) |