[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Base class for Forum business persistence abstraction. 20 // 21 if (defined("_BD_FORUM")) 22 return; 23 24 define("_BD_FORUM", "1"); 25 26 require_once("PEAR.php"); 27 require_once(dirname(__FILE__). "/inc_rubrique_factory.php"); 28 require_once("DB.php"); 29 require_once dirname(__FILE__). "/metier.php"; 30 31 define("FORUM_ALL_FIELDS", 32 " id_forum, id_parent, id_rubrique, id_article, id_breve, date_heure, titre, texte, " . "auteur, email_auteur, nom_site, url_site, statut, ip, maj, id_auteur, " . "id_message, id_syndic, profil_auteur, alerte_mail "); 33 34 /** 35 * BD_forum is a base class for forum business persistence abstraction implementations, and must be 36 * inherited by all such. 37 * @package BD 38 * @author Antoine Angénieux <aangenieux@clever-age.com> 39 * @author Erwan Le Bescond <elebescond@clever-age.com> 40 * @access public 41 */ 42 class BD_forum extends BD_metier { 43 // {{{ properties 44 45 /** 46 * Forum ID. 47 * @var int 48 * @access private 49 */ 50 var $_forumId; 51 52 /** 53 * Parent ID. 54 * @var int 55 * @access private 56 */ 57 var $_parentId; 58 59 /** 60 * Rubrique ID. 61 * @var int 62 * @access private 63 */ 64 var $_rubriqueId; 65 66 /** 67 * Article ID. 68 * @var int 69 * @access private 70 */ 71 var $_articleId; 72 73 /** 74 * Breve ID. 75 * @var int 76 * @access private 77 */ 78 var $_breveId; 79 80 /** 81 * Time. 82 * @var Date 83 * @access private 84 */ 85 var $_dateHeure; 86 87 /** 88 * Title. 89 * @var String 90 * @access private 91 */ 92 var $_titre; 93 94 /** 95 * Text. 96 * @var String 97 * @access private 98 */ 99 var $_texte; 100 101 /** 102 * Author. 103 * @var String 104 * @access private 105 */ 106 var $_auteur; 107 108 var $id_forums; 109 /** 110 * Email Author. 111 * @var int 112 * @access public 113 */ 114 /** 115 * Email Author. 116 * @var String 117 * @access private 118 */ 119 var $_emailAuteur; 120 121 /** 122 * Site name. 123 * @var String 124 * @access private 125 */ 126 var $_nomSite; 127 128 /** 129 * Site url. 130 * @var String 131 * @access private 132 */ 133 var $_urlSite; 134 135 /** 136 * Statute. 137 * @var String 138 * @access private 139 */ 140 var $_statut; 141 142 /** 143 * IP. 144 * @var String 145 * @access private 146 */ 147 var $_ip; 148 149 /** 150 * Last Update. 151 * @var Date 152 * @access private 153 */ 154 var $_majDate; 155 156 /** 157 * Author ID. 158 * @var int 159 * @access private 160 */ 161 var $_auteurId; 162 163 /** 164 * Message ID. 165 * @var int 166 * @access private 167 */ 168 var $_messageId; 169 170 /** 171 * Syndic ID. 172 * @var int 173 * @access private 174 */ 175 var $_syndicId; 176 177 /** 178 * profilAuteur. 179 * @var Int 180 * @access private 181 */ 182 var $_profilAuteur; 183 184 /** 185 * alerte email. 186 * @var String 187 * @access private 188 */ 189 var $_emailAlerte; 190 191 // }}} 192 193 // {{{ factory() 194 function &factory ($dbParameters = null, $dbOptions = null) { 195 if (file_exists( 196 dirname( 197 __FILE__). "/" . $dbParameters->_dbEngine . "/forum_" . $dbParameters->_dbEngine . ".php") == false) 198 { 199 include_once(dirname(__FILE__). "/common/forum_common.php"); 200 $classname = "BD_forum_common"; 201 } 202 else { 203 include_once( 204 dirname(__FILE__). "/" . $dbParameters->_dbEngine . "/forum_" . $dbParameters->_dbEngine . ".php"); 205 $classname = "BD_forum_" . $dbParameters->_dbEngine; 206 } 207 208 if (!class_exists($classname)) { 209 return PEAR::raiseError("Cannot instanciate class $classname", null, null, null, null, null, false); 210 } 211 212 $obj = &new $classname; 213 $result = $obj->setDbParameters($dbParameters); 214 215 if ($dbOptions != null) { 216 $obj->setDbOptions($dbOptions); 217 } 218 219 if (PEAR::isError($result)) { 220 return $result; 221 } 222 else { 223 return $obj; 224 } 225 } 226 227 // }}} 228 229 // {{{ constructor 230 231 /** 232 * DB_forum constructor. 233 * 234 * @access public 235 */ 236 237 function BD_forum () { } 238 239 // }}} 240 241 // {{{ getForumId() 242 243 /** 244 * Returns the Forum ID 245 * @return int 246 * @access public 247 */ 248 249 function getForumId () { 250 return $this->_forumId; 251 } 252 253 // }}} 254 255 // {{{ setForumId() 256 257 /** 258 * Sets the Forum ID 259 * @param int 260 * @access public 261 */ 262 263 function setForumId ($forumId) { 264 $this->_forumId = $forumId; 265 } 266 267 // }}} 268 269 // {{{ getParentId() 270 271 /** 272 * Returns the Parent's ID 273 * @return int 274 * @access public 275 */ 276 277 function getParentId () { 278 return $this->_parentId; 279 } 280 281 // }}} 282 283 // {{{ setParentId() 284 285 /** 286 * Sets the Forum's ID 287 * @param int 288 * @access public 289 */ 290 291 function setParentId ($parentId) { 292 $this->_parentId = $parentId; 293 } 294 295 // }}} 296 297 // {{{ getRubriqueId() 298 299 /** 300 * Returns the Heading's ID 301 * @return int 302 * @access public 303 */ 304 305 function getRubriqueId () { 306 return $this->_rubriqueId; 307 } 308 309 // }}} 310 311 // {{{ setRubriqueId() 312 313 /** 314 * Sets the Heading's ID 315 * @param int 316 * @access public 317 */ 318 319 function setRubriqueId ($rubriqueId) { 320 $this->_rubriqueId = $rubriqueId; 321 } 322 323 // }}} 324 325 // {{{ getArticleId() 326 327 /** 328 * Returns the Article's ID 329 * @return int 330 * @access public 331 */ 332 333 function getArticleId () { 334 return $this->_articleId; 335 } 336 337 // }}} 338 339 // {{{ setArticleId() 340 341 /** 342 * Sets the Article's ID 343 * @param int 344 * @access public 345 */ 346 347 function setArticleId ($articleId) { 348 $this->_articleId = $articleId; 349 } 350 351 // }}} 352 353 /** 354 * Returns the Breve's ID 355 * @return int 356 * @access public 357 */ 358 359 // {{{ getBreveId() 360 361 function getBreveId () { 362 return $this->_breveId; 363 } 364 365 // }}} 366 367 // {{{ setBreveId() 368 369 /** 370 * Sets the Breve's ID 371 * @param int 372 * @access public 373 */ 374 375 function setBreveId ($breveId) { 376 $this->_breveId = $breveId; 377 } 378 379 // }}} 380 381 // {{{ getDateHeure() 382 383 /** 384 * Returns the creation date 385 * @return Date 386 * @access public 387 */ 388 389 function getDateHeure () { 390 return $this->_dateHeure; 391 } 392 393 // }}} 394 395 // {{{ setDateHeure() 396 397 /** 398 * Returns the creation date 399 * @return Date 400 * @access public 401 */ 402 403 function setDateHeure ($dateHeure) { 404 $this->_dateHeure = $dateHeure; 405 } 406 407 // }}} 408 409 // {{{ getTitre() 410 411 /** 412 * Returns the Title 413 * @return String 414 * @access public 415 */ 416 417 function getTitre () { 418 return $this->_titre; 419 } 420 421 // }}} 422 423 // {{{ setTitre() 424 425 /** 426 * Sets the Title 427 * @param String 428 * @access public 429 */ 430 431 function setTitre ($titre) { 432 $this->_titre = corriger_caracteres($titre); 433 } 434 435 // }}} 436 437 // {{{ getTexte() 438 439 /** 440 * Returns the Text 441 * @return String 442 * @access public 443 */ 444 445 function getTexte () { 446 return $this->_texte; 447 } 448 449 // }}} 450 451 // {{{ setTexte() 452 453 /** 454 * Sets the Text 455 * @param String 456 * @access public 457 */ 458 459 function setTexte ($texte) { 460 $this->_texte = corriger_caracteres($texte); 461 } 462 463 // }}} 464 465 // {{{ getAuteur() 466 467 /** 468 * Returns the Author 469 * @return String 470 * @access public 471 */ 472 473 function getAuteur () { 474 return $this->_auteur; 475 } 476 477 // }}} 478 479 // {{{ setAuteur() 480 481 /** 482 * Sets the Author 483 * @param String 484 * @access public 485 */ 486 487 function setAuteur ($auteur) { 488 $this->_auteur = corriger_caracteres($auteur); 489 } 490 491 // }}} 492 493 // {{{ getEmailAuteur() 494 495 /** 496 * Returns the Author's email 497 * @return String 498 * @access public 499 */ 500 501 function getEmailAuteur () { 502 return $this->_emailAuteur; 503 } 504 505 // }}} 506 507 // {{{ setEmailAuteur() 508 509 /** 510 * Sets the Author's email 511 * @param String 512 * @access public 513 */ 514 515 function setEmailAuteur ($emailAuteur) { 516 $this->_emailAuteur = corriger_caracteres($emailAuteur); 517 } 518 519 // }}} 520 521 // {{{ getNomSite() 522 523 /** 524 * Returns the Site's name 525 * @return String 526 * @access public 527 */ 528 529 function getNomSite () { 530 return $this->_nomSite; 531 } 532 533 // }}} 534 535 // {{{ setNomSite() 536 537 /** 538 * Returns the Site's name 539 * @param String 540 * @access public 541 */ 542 543 function setNomSite ($nomSite) { 544 $this->_nomSite = corriger_caracteres($nomSite); 545 } 546 547 // }}} 548 549 // {{{ getUrlSite() 550 551 /** 552 * Returns the Site's URL 553 * @return String 554 * @access public 555 */ 556 557 function getUrlSite () { 558 return $this->_urlSite; 559 } 560 561 // }}} 562 563 // {{{ setUrlSite() 564 565 /** 566 * Sets the Site's URL 567 * @param String 568 * @access public 569 */ 570 571 function setUrlSite ($urlSite) { 572 $this->_urlSite = corriger_caracteres($urlSite); 573 } 574 575 // }}} 576 577 /** 578 * Returns the Statute 579 * @return String 580 * @access public 581 */ 582 583 // {{{ getStatut() 584 585 function getStatut () { 586 return $this->_statut; 587 } 588 589 // }}} 590 591 // {{{ setStatut() 592 593 /** 594 * Sets the Statute 595 * @param String 596 * @access public 597 */ 598 599 function setStatut ($statut) { 600 $this->_statut = corriger_caracteres($statut); 601 } 602 603 // }}} 604 605 // {{{ getIp() 606 607 /** 608 * Returns the IP 609 * @return String 610 * @access public 611 */ 612 613 function getIp () { 614 return $this->_ip; 615 } 616 617 // }}} 618 619 // {{{ setIp() 620 621 /** 622 * Sets the IP 623 * @param String 624 * @access public 625 */ 626 627 function setIp ($ip) { 628 $this->_ip = corriger_caracteres($ip); 629 } 630 631 // }}} 632 633 // {{{ getMajDate() 634 635 /** 636 * Returns the last update 637 * @return Date 638 * @access public 639 */ 640 641 function getMajDate () { 642 return $this->_majDate; 643 } 644 645 // }}} 646 647 // {{{ setMajDate() 648 649 /** 650 * Sets the last update 651 * @param Date 652 * @access public 653 */ 654 655 function setMajDate ($majDate) { 656 $this->_majDate = $majDate; 657 } 658 659 // }}} 660 661 // {{{ getAuteurId() 662 663 /** 664 * Returns the Author's ID 665 * @return int 666 * @access public 667 */ 668 669 function getAuteurId () { 670 return $this->_auteurId; 671 } 672 673 // }}} 674 675 // {{{ setAuteurId() 676 677 /** 678 * Sets the Author's ID 679 * @param int 680 * @access public 681 */ 682 683 function setAuteurId ($auteurId) { 684 $this->_auteurId = $auteurId; 685 } 686 687 // }}} 688 689 // {{{ getMessageId() 690 691 /** 692 * Returns the Message's ID 693 * @return int 694 * @access public 695 */ 696 697 function getMessageId () { 698 return $this->_messageId; 699 } 700 701 // }}} 702 703 // {{{ setMessageId() 704 705 /** 706 * Returns the Message's ID 707 * @param int 708 * @access public 709 */ 710 711 function setMessageId ($messageId) { 712 $this->_messageId = $messageId; 713 } 714 715 // }}} 716 717 // {{{ getSyndicId() 718 719 /** 720 * Returns the Syndic's ID 721 * @return int 722 * @access public 723 */ 724 725 function getSyndicId () { 726 return $this->_syndicId; 727 } 728 729 // }}} 730 731 // {{{ setSyndicId() 732 733 /** 734 * Sets the Syndic's ID 735 * @param int 736 * @access public 737 */ 738 739 function setSyndicId ($syndicId) { 740 $this->_syndicId = $syndicId; 741 } 742 743 // {{{ getProfilAuteur() 744 745 /** 746 * Returns the profilAuteur 747 * @return Int 748 * @access public 749 */ 750 751 function getProfilAuteur () { 752 return $this->_profilAuteur; 753 } 754 755 // }}} 756 757 // {{{ setProfilAuteur() 758 759 /** 760 * Sets the ProfilAuteur 761 * @param Int 762 * @access public 763 */ 764 765 function setProfilAuteur ($profilAuteur) { 766 $this->_profilAuteur = $profilAuteur; 767 } 768 769 // }}} 770 771 // {{{ getEmailAlerte() 772 773 /** 774 * Returns the _emailAlerte 775 * @return String 776 * @access public 777 */ 778 779 function getEmailAlerte () { 780 return $this->_emailAlerte; 781 } 782 783 // }}} 784 785 // {{{ setEmailAlerte() 786 787 /** 788 * Sets the _emailAlerte 789 * @param String 790 * @access public 791 */ 792 793 function setEmailAlerte ($emailAlerte) { 794 $this->_emailAlerte = $emailAlerte; 795 } 796 797 // }}} 798 799 // {{{ create() 800 801 /** 802 * This method is used to create a new forum in the database 803 * @access public 804 */ 805 806 function create () { 807 $db = &$this->_getDB(); 808 809 if (DB::isError($db)) { 810 return PEAR::raiseError("[" . get_class($this). " DB_forum : create()] " . $db->getMessage(). "", null, 811 null, null, 812 null, null, 813 false); 814 } 815 816 $string_prefix = $GLOBALS['table_prefix']. "_forum"; 817 $forumId = $db->nextId($string_prefix, true); 818 819 if (DB::isError($forumId)) { 820 return PEAR::raiseError("[" . get_class($this). " DB_forum : create()] " . $forumId->getMessage(). "", null, 821 null, null, 822 null, null, 823 false); 824 } 825 826 $this->_forumId = $forumId; 827 828 //if ($this->_dateHeure == "NOW()") $dateValue = "NOW()"; else $dateValue = "'".$db->quoteString($this->_dateHeure)."'"; 829 830 $maDate = new Date(); 831 $this->setDateHeure($maDate->getDate(DATE_FORMAT_ISO)); 832 833 if ($this->_parentId == null) 834 $this->_parentId = 0; 835 836 if ($this->_rubriqueId == null) 837 $this->_rubriqueId = 0; 838 839 if ($this->_articleId == null) 840 $this->_articleId = 0; 841 842 if ($this->_breveId == null) 843 $this->_breveId = 0; 844 845 if ($this->_auteurId == null) 846 $this->_auteurId = 0; 847 848 if ($this->_messageId == null) 849 $this->_messageId = 0; 850 851 if ($this->_syndicId == null) 852 $this->_syndicId = 0; 853 854 $query 855 = "INSERT INTO " . $GLOBALS['table_prefix']. "_forum (" . FORUM_ALL_FIELDS . ") VALUES " . "(" . $this->_forumId . ", " . "" . $this->_parentId . ", " . "" . $this->_rubriqueId . ", " . "" . $this->_articleId . ", " . "" . $this->_breveId . ", " . "'" . $db->quoteString( 856 $this->_dateHeure). "', " . "'" . $db->quoteString( 857 $this->_titre). "', " . "'" . $db->quoteString( 858 $this->_texte). "', " . "'" . $db->quoteString( 859 $this->_auteur). "', " . "'" . $db->quoteString( 860 $this->_emailAuteur). "', " . "'" . $db->quoteString( 861 $this->_nomSite). "', " . "'" . $db->quoteString( 862 $this->_urlSite). "', " . "'" . $db->quoteString( 863 $this->_statut). "', " . "'" . $db->quoteString( 864 $this->_ip). "', " . "'" . $db->quoteString( 865 $this->_majDate). "', " . "" . $this->_auteurId . ", " . "" . $this->_messageId . ", " . "" . $this->_syndicId . ", " . "" . $this->_profilAuteur . ", " . "'" . $db->quoteString( 866 $this->_emailAlerte). "')"; 867 868 //echo '<br>' . $query . '<br>'; 869 $result = $db->query($query); 870 871 if (DB::isError($result)) { 872 return PEAR::raiseError("[" . get_class($this). " DB_forum : create()] " . $result->getMessage(). "", null, 873 null, null, 874 null, null, 875 false); 876 } 877 } 878 879 // }}} 880 881 // {{{ update() 882 883 /** 884 * This method is used to update this forum in the database 885 * @access public 886 */ 887 888 function update () { 889 $db = &$this->_getDB(); 890 891 if (DB::isError($db)) { 892 return PEAR::raiseError("[" . get_class($this). " DB_forum : update()] " . $db->getMessage(). "", null, 893 null, null, 894 null, null, 895 false); 896 } 897 898 //if ($this->_dateHeure == "NOW()") $dateValue = "NOW()"; else $dateValue = "'".$db->quoteString($this->_dateHeure)."'"; 899 900 $maDate = new Date(); 901 $this->setMajDate($maDate->getDate(DATE_FORMAT_ISO)); 902 903 $query 904 = "UPDATE " . $GLOBALS['table_prefix']. "_forum " . "SET id_parent = " . $this->_parentId . ", " . "id_rubrique = " . $this->_rubriqueId . ", id_article = " . $this->_articleId . ", " . "id_breve = " . $this->_breveId . ", date_heure = '" . $db->quoteString( 905 $this->_dateHeure). "', " . "titre = '" . $db->quoteString( 906 $this->_titre). "', texte = '" . $db->quoteString( 907 $this->_texte). "', " . "auteur = '" . $db->quoteString( 908 $this->_auteur). "', email_auteur = '" . $this->_emailAuteur . "', " . "nom_site = '" . $db->quoteString( 909 $this->_nomSite). "', url_site = '" . $db->quoteString( 910 $this->_urlSite). "', " . "statut = '" . $db->quoteString( 911 $this->_statut). "', ip = '" . $db->quoteString( 912 $this->_ip). "', " . "maj = '" . $db->quoteString( 913 $this->_majDate). "', id_auteur = " . $this->_auteurId . ", " . "id_message = " . $this->_messageId . ", id_syndic = " . $this->_syndicId . ", " . "profil_auteur = " . $this->_profilAuteur . ", alerte_mail = '" . $db->quoteString( 914 $this->_emailAlerte). "' " . "WHERE id_forum = " . $this->_forumId; 915 916 //echo '<br>' . $query . '<br>'; 917 $result = $db->query($query); 918 919 if (DB::isError($result)) { 920 return PEAR::raiseError("[" . get_class($this). " DB_forum : update()] " . $result->getMessage(). "", null, 921 null, null, 922 null, null, 923 false); 924 } 925 } 926 927 // }}} 928 929 // {{{ load() 930 931 /** 932 * This method is used to load a forum from the database 933 * @access public 934 * @param int $idForum id of forum to load 935 */ 936 937 function load ($idForum) { 938 $db = &$this->_getDB(); 939 940 if (DB::isError($db)) { 941 return PEAR::raiseError("[" . get_class($this). " DB_forum : load()] " . $db->getMessage(). "", null, null, 942 null, null, null, 943 false); 944 } 945 946 $query = "SELECT" . FORUM_ALL_FIELDS . "FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum = $idForum"; 947 948 //echo "<br><br>$query<br><br>"; 949 950 $result = $db->query($query); 951 952 if (DB::isError($result)) { 953 return PEAR::raiseError("[" . get_class($this). " DB_forum : load()] " . $result->getMessage(). "", null, 954 null, null, 955 null, null, 956 false); 957 } 958 else { 959 if ($row = $result->fetchRow()) { 960 $maDate = new Date($row['maj']); 961 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 962 963 $this->_fetchData($row); 964 } 965 else { 966 return PEAR::raiseError( 967 "[" . get_class( 968 $this). " DB_forum : load($idForum)] Aucun forum ne correspond pas à cet ID!", 969 null, 970 null, 971 null, 972 null, 973 null, 974 false); 975 } 976 $result->free(); 977 } 978 } 979 980 // }}} 981 982 // {{{ delete() 983 984 /** 985 * This method is used to delete a forum from the database 986 * @access public 987 * @param int $idForum of forum to delete 988 */ 989 990 function delete ($idForum) { 991 $db = &$this->_getDB(); 992 993 if (DB::isError($db)) { 994 return PEAR::raiseError("[" . get_class($this). " DB_forum : delete()] " . $db->getMessage(). "", null, 995 null, null, 996 null, null, 997 false); 998 } 999 1000 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum = $idForum"; 1001 1002 $result = $db->query($query); 1003 1004 if (DB::isError($result)) { 1005 return PEAR::raiseError("[" . get_class($this). " DB_forum : delete()] " . $result->getMessage(). "", null, 1006 null, null, 1007 null, null, 1008 false); 1009 } 1010 } 1011 1012 // }}} 1013 1014 // {{{ _fetchData() 1015 1016 /** 1017 * This method is used to fetch result set fields into the object fields 1018 * 1019 * @param $row resultset row 1020 * @access private 1021 */ 1022 1023 function _fetchData ($row) { 1024 $this->setForumId($row['id_forum']); 1025 $this->setParentId($row['id_parent']); 1026 $this->setRubriqueId($row['id_rubrique']); 1027 $this->setArticleId($row['id_article']); 1028 $this->setBreveId($row['id_breve']); 1029 $this->setDateHeure($row['date_heure']); 1030 $this->setTitre($row['titre']); 1031 $this->setTexte($row['texte']); 1032 $this->setAuteur($row['auteur']); 1033 $this->setEmailAuteur($row['email_auteur']); 1034 $this->setNomSite($row['nom_site']); 1035 $this->setUrlSite($row['url_site']); 1036 $this->setStatut($row['statut']); 1037 $this->setIp($row['ip']); 1038 $this->setMajDate($row['maj']); 1039 $this->setAuteurId($row['id_auteur']); 1040 $this->setMessageId($row['id_message']); 1041 $this->setSyndicId($row['id_syndic']); 1042 $this->setProfilAuteur($row['profil_auteur']); 1043 $this->setEmailAlerte($row['alerte_mail']); 1044 } 1045 1046 // }}} 1047 1048 // {{{ addForumCache($valeurs) 1049 1050 function addForumCache ($valeurs) { 1051 $db = &$this->_getDB(); 1052 1053 if (DB::isError($db)) { 1054 return PEAR::raiseError("[" . get_class($this). " DB_forum : addForumCache()] " . $db->getMessage(). "", 1055 null, 1056 null, 1057 null, 1058 null, 1059 null, 1060 false); 1061 } 1062 1063 //echo "<br>Details du parametre de la methode addForumCache()<br>"; 1064 $query 1065 = "INSERT INTO " . $GLOBALS['table_prefix']. "_forum_cache (id_article, id_rubrique, id_breve, id_forum, fichier) VALUES ($valeurs)"; 1066 1067 $result = $db->query($query); 1068 1069 if (DB::isError($result)) { 1070 return PEAR::raiseError("[" . get_class($this). " DB_forum : addForumCache()] " . $result->getMessage(). "", 1071 null, 1072 null, 1073 null, 1074 null, 1075 null, 1076 false); 1077 } 1078 } 1079 1080 // }}} 1081 1082 // {{{ deleteAllExceptArticleIds($articles) 1083 1084 function deleteAllExceptArticleIds ($articles) { 1085 $db = &$this->_getDB(); 1086 1087 if (DB::isError($db)) { 1088 return PEAR::raiseError( 1089 "[" . get_class($this). " DB_forum : deleteAllExceptArticleIds()] " . $db->getMessage(). "", 1090 null, 1091 null, 1092 null, 1093 null, 1094 null, 1095 false); 1096 } 1097 1098 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_article NOT IN (0,$articles)"; 1099 1100 $result = $db->query($query); 1101 1102 if (DB::isError($result)) { 1103 return PEAR::raiseError( 1104 "[" . get_class($this). " DB_forum : deleteAllExceptArticleIds()] " . $result->getMessage(). "", 1105 null, 1106 null, 1107 null, 1108 null, 1109 null, 1110 false); 1111 } 1112 } 1113 1114 // }}} 1115 1116 // {{{ deleteAllExceptBreveIds($breves) 1117 1118 function deleteAllExceptBreveIds ($breves) { 1119 $db = &$this->_getDB(); 1120 1121 if (DB::isError($db)) { 1122 return PEAR::raiseError( 1123 "[" . get_class($this). " DB_forum : deleteAllExceptBreveIds()] " . $db->getMessage(). "", null, 1124 null, null, 1125 null, null, 1126 false); 1127 } 1128 1129 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_breve NOT IN (0,$breves)"; 1130 1131 $result = $db->query($query); 1132 1133 if (DB::isError($result)) { 1134 return PEAR::raiseError( 1135 "[" . get_class($this). " DB_forum : deleteAllExceptBreveIds()] " . $result->getMessage(). "", 1136 null, 1137 null, 1138 null, 1139 null, 1140 null, 1141 false); 1142 } 1143 } 1144 1145 // }}} 1146 1147 // {{{ deleteAllExceptMessageIds($messages) 1148 1149 function deleteAllExceptMessageIds ($messages) { 1150 $db = &$this->_getDB(); 1151 1152 if (DB::isError($db)) { 1153 return PEAR::raiseError( 1154 "[" . get_class($this). " DB_forum : deleteAllExceptMessageIds()] " . $db->getMessage(). "", 1155 null, 1156 null, 1157 null, 1158 null, 1159 null, 1160 false); 1161 } 1162 1163 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_message NOT IN (0,$messages)"; 1164 1165 $result = $db->query($query); 1166 1167 if (DB::isError($result)) { 1168 return PEAR::raiseError( 1169 "[" . get_class($this). " DB_forum : deleteAllExceptMessageIds()] " . $result->getMessage(). "", 1170 null, 1171 null, 1172 null, 1173 null, 1174 null, 1175 false); 1176 } 1177 } 1178 1179 // }}} 1180 1181 // {{{ deleteAllExceptParentIds($parents) 1182 1183 function deleteAllExceptParentIds ($parents) { 1184 $db = &$this->_getDB(); 1185 1186 if (DB::isError($db)) { 1187 return PEAR::raiseError( 1188 "[" . get_class($this). " DB_forum : deleteAllExceptParentIds()] " . $db->getMessage(). "", null, 1189 null, null, 1190 null, null, 1191 false); 1192 } 1193 1194 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_parent NOT IN (0,$parents)"; 1195 1196 $result = $db->query($query); 1197 1198 if (DB::isError($result)) { 1199 return PEAR::raiseError( 1200 "[" . get_class($this). " DB_forum : deleteAllExceptParentIds()] " . $result->getMessage(). "", 1201 null, 1202 null, 1203 null, 1204 null, 1205 null, 1206 false); 1207 } 1208 } 1209 1210 // }}} 1211 1212 // {{{ deleteAllExceptRubriqueIds($rubriques) 1213 1214 function deleteAllExceptRubriqueIds ($rubriques) { 1215 $db = &$this->_getDB(); 1216 1217 if (DB::isError($db)) { 1218 return PEAR::raiseError( 1219 "[" . get_class($this). " DB_forum : deleteAllExceptRubriqueIds()] " . $db->getMessage(). "", 1220 null, 1221 null, 1222 null, 1223 null, 1224 null, 1225 false); 1226 } 1227 1228 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_rubrique NOT IN (0,$rubriques)"; 1229 1230 $result = $db->query($query); 1231 1232 if (DB::isError($result)) { 1233 return PEAR::raiseError( 1234 "[" . get_class($this). " DB_forum : deleteAllExceptRubriqueIds()] " . $result->getMessage(). "", 1235 null, 1236 null, 1237 null, 1238 null, 1239 null, 1240 false); 1241 } 1242 } 1243 1244 // }}} 1245 1246 // {{{ deleteForMessageId($messageId) 1247 1248 function deleteForMessageId ($messageId) { 1249 $db = &$this->_getDB(); 1250 1251 if (DB::isError($db)) { 1252 return PEAR::raiseError( 1253 "[" . get_class($this). " DB_forum : deleteForMessageId()] " . $db->getMessage(). "", null, null, 1254 null, null, null, 1255 false); 1256 } 1257 1258 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_message=$messageId"; 1259 //echo $query; 1260 1261 $result = $db->query($query); 1262 1263 if (DB::isError($result)) { 1264 return PEAR::raiseError( 1265 "[" . get_class($this). " DB_forum : deleteForMessageId()] " . $result->getMessage(). "", null, 1266 null, null, 1267 null, null, 1268 false); 1269 } 1270 } 1271 1272 // }}} 1273 1274 // {{{ deleteCacheForFichier($fichier) 1275 1276 function deleteCacheForFichier ($fichier) { 1277 $db = &$this->_getDB(); 1278 1279 if (DB::isError($db)) { 1280 return PEAR::raiseError( 1281 "[" . get_class($this). " DB_forum : deleteCacheForFichier()] " . $db->getMessage(). "", null, 1282 null, null, 1283 null, null, 1284 false); 1285 } 1286 1287 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum_cache WHERE fichier='$fichier'"; 1288 1289 $result = $db->query($query); 1290 1291 if (DB::isError($result)) { 1292 return PEAR::raiseError( 1293 "[" . get_class($this). " DB_forum : deleteCacheForFichier()] " . $result->getMessage(). "", 1294 null, 1295 null, 1296 null, 1297 null, 1298 null, 1299 false); 1300 } 1301 } 1302 1303 // }}} 1304 1305 // {{{ getAllForForumType($page, $limitdeb, $limitnb) 1306 1307 /** 1308 * Returns an array of Forum. 1309 * 1310 * @return Array of Forum 1311 * @param $page 1312 * @param $limitedeb 1313 * @param $limitnb 1314 * @param $page 1315 * @access public 1316 */ 1317 1318 function &getAllForForumType ($page, $limitdeb, $limitnb, $order = null, $statut = null, $ageMessage = null, 1319 $id_current_forum = null, $type_forum = null) { 1320 $forums = array(); 1321 $db = &$this->_getDB(); 1322 1323 if (DB::isError($db)) { 1324 return PEAR::raiseError( 1325 "[" . get_class($this). " DB_forum : getAllForForumType()] " . $db->getMessage(). "", null, null, 1326 null, null, null, 1327 false); 1328 } 1329 1330 $query = "SELECT * FROM " . $GLOBALS['table_prefix']. "_forum WHERE "; 1331 1332 switch ($page) { 1333 case 'public': 1334 if ($statut) { 1335 $statut = explode(",", $statut); 1336 $query .= "statut IN ('" . join("','", $statut). "')"; 1337 } 1338 else 1339 $query .= "statut IN ('publie', 'off', 'prop', 'poubelle')"; 1340 break; 1341 1342 case 'interne': 1343 $query .= "statut IN ('prive', 'privrac', 'privoff', 'privadm')"; 1344 break; 1345 1346 case 'vide': 1347 $query .= "statut IN ('publie', 'off', 'prive', 'privrac', 'privoff', 'privadm') AND texte like ''"; 1348 break; 1349 1350 default: 1351 $query .= "NULL IS NOT NULL"; 1352 break; 1353 1354 /* 1355 case 'public': 1356 $query .= "statut IN ('publie', 'off', 'prop') AND texte NOT LIKE ''"; 1357 break; 1358 case 'interne': 1359 $query .= "statut IN ('prive', 'privrac', 'privoff', 'privadm') AND texte NOT LIKE ''"; 1360 break; 1361 case 'vide': 1362 $query .= "statut IN ('publie', 'off', 'prive', 'privrac', 'privoff', 'privadm') AND texte LIKE ''"; 1363 break; 1364 default: 1365 $query .= "0=1"; 1366 break; 1367 */ 1368 1369 } 1370 1371 if ($id_current_forum && $type_forum) 1372 $query .= " AND id_$type_forum = $id_current_forum "; 1373 1374 if ($ageMessage) 1375 $query .= " AND date_heure>='" . $ageMessage->getDate(). "'"; 1376 1377 switch ($order) { 1378 case 'date_heure': 1379 $query .= " ORDER BY date_heure"; 1380 break; 1381 1382 case 'auteur': 1383 $query .= " ORDER BY auteur"; 1384 break; 1385 1386 case 'email_auteur': 1387 $query .= " ORDER BY email_auteur"; 1388 break; 1389 1390 default: 1391 $query .= " ORDER BY date_heure"; 1392 break; 1393 } 1394 1395 //echo "<br><br>".$query."<br><br>"; 1396 1397 $queryResult = $db->limitQuery($query, $limitdeb, $limitnb); 1398 1399 if (DB::isError($queryResult)) { 1400 return PEAR::raiseError( 1401 "[" . get_class($this). " DB_forum : getAllForForumType()] " . $queryResult->getMessage(). "", 1402 null, 1403 null, 1404 null, 1405 null, 1406 null, 1407 false); 1408 } 1409 1410 while ($row = $queryResult->fetchRow()) { 1411 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 1412 1413 $maDate = new Date($row['maj']); 1414 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 1415 1416 $resultForum->_fetchData($row); 1417 $forums[] = &$resultForum; 1418 } 1419 1420 $queryResult->free(); 1421 return $forums; 1422 } 1423 1424 // }}} 1425 1426 // {{{ getAllForStatut($statut) 1427 1428 /** 1429 * Returns an array of Forum. 1430 * 1431 * @return Array of Forum 1432 * @param $statut 1433 * @access public 1434 */ 1435 1436 function &getAllForStatut ($statut) { 1437 $forums = array(); 1438 $db = &$this->_getDB(); 1439 1440 if (DB::isError($db)) { 1441 return PEAR::raiseError("[" . get_class($this). " DB_forum : getAllForStatut()] " . $db->getMessage(). "", 1442 null, 1443 null, 1444 null, 1445 null, 1446 null, 1447 false); 1448 } 1449 1450 $query = "SELECT * FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut='$statut'"; 1451 1452 //echo "<br><br>$query<br><br>"; 1453 1454 $queryResult = $db->query($query); 1455 1456 if (DB::isError($queryResult)) { 1457 return PEAR::raiseError( 1458 "[" . get_class($this). " DB_forum : getAllForStatut()] " . $queryResult->getMessage(). "", null, 1459 null, null, 1460 null, null, 1461 false); 1462 } 1463 1464 while ($row = $queryResult->fetchRow()) { 1465 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 1466 1467 $maDate = new Date($row['maj']); 1468 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 1469 1470 $resultForum->_fetchData($row); 1471 $forums[] = &$resultForum; 1472 } 1473 1474 $queryResult->free(); 1475 return $forums; 1476 } 1477 1478 // }}} 1479 1480 // {{{ getAllEmptyMessagesForStatut($statut) 1481 1482 /** 1483 * Returns an array of Forum. 1484 * 1485 * @return Array of Forum 1486 * @param $statut 1487 * @access public 1488 */ 1489 1490 function &getAllEmptyMessagesForStatut ($statut) { 1491 $forums = array(); 1492 $db = &$this->_getDB(); 1493 1494 if (DB::isError($db)) { 1495 return PEAR::raiseError( 1496 "[" . get_class($this). " DB_forum : getAllEmptyMessagesForStatut()] " . $db->getMessage(). "", 1497 null, 1498 null, 1499 null, 1500 null, 1501 null, 1502 false); 1503 } 1504 1505 $query 1506 = "SELECT * FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut='$statut' AND OCTET_LENGTH(`texte`) <= 0"; 1507 1508 $queryResult = $db->query($query); 1509 1510 if (DB::isError($queryResult)) { 1511 return PEAR::raiseError( 1512 "[" . get_class( 1513 $this). " DB_forum : getAllEmptyMessagesForStatut()] " . $queryResult->getMessage(). "", 1514 null, 1515 null, 1516 null, 1517 null, 1518 null, 1519 false); 1520 } 1521 1522 while ($row = $queryResult->fetchRow()) { 1523 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 1524 1525 $maDate = new Date($row['maj']); 1526 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 1527 1528 $resultForum->_fetchData($row); 1529 $forums[] = &$resultForum; 1530 } 1531 1532 $queryResult->free(); 1533 return $forums; 1534 } 1535 1536 // }}} 1537 1538 // {{{ getAllForumIds() 1539 1540 /** 1541 * Returns an array of Forum ID. 1542 * 1543 * 1544 * @return an array of Forum ID 1545 * @access public 1546 */ 1547 1548 function getAllForumIds () { 1549 $forumIds = array(); 1550 $db = &$this->_getDB(); 1551 1552 if (DB::isError($db)) { 1553 return PEAR::raiseError("[" . get_class($this). " DB_forum : getAllForumIds()] " . $db->getMessage(). "", 1554 null, 1555 null, 1556 null, 1557 null, 1558 null, 1559 false); 1560 } 1561 1562 $query = "SELECT id_forum FROM " . $GLOBALS['table_prefix']. "_forum"; 1563 1564 $result = $db->query($query); 1565 1566 if (DB::isError($result)) { 1567 return PEAR::raiseError( 1568 "[" . get_class($this). " DB_forum : getAllForumIds()] " . $result->getMessage(). "", null, null, 1569 null, null, null, 1570 false); 1571 } 1572 1573 while ($row = $result->fetchRow()) { 1574 $forumIds[] = $row['id_forum']; 1575 } 1576 1577 $result->free(); 1578 return $forumIds; 1579 } 1580 1581 // }}} 1582 1583 // {{{ getAllRootMessagesForCurrentForum($id_curent_forum, $type, $maDate = null) 1584 1585 /** 1586 * Returns an array of Root Forum. 1587 * 1588 * 1589 * @return an array of Root Forum 1590 * @access public 1591 */ 1592 1593 function getAllRootMessagesForCurrentForum ($id_current_forum, $type, $maDate = null) { 1594 $forums = array(); 1595 1596 $db = &$this->_getDB(); 1597 1598 if (DB::isError($db)) { 1599 return PEAR::raiseError( 1600 "[" . get_class( 1601 $this). " DB_forum : getAllRootMessagesForCurrentForum()] " . $db->getMessage(). "", 1602 null, 1603 null, 1604 null, 1605 null, 1606 null, 1607 false); 1608 } 1609 1610 $query 1611 = "SELECT " . FORUM_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_$type=$id_current_forum AND id_parent=0"; 1612 1613 if ($maDate) 1614 $query .= " AND date_heure>='" . $maDate->getDate(DATE_FORMAT_ISO). "'"; 1615 1616 $result = $db->query($query); 1617 1618 if (DB::isError($result)) { 1619 return PEAR::raiseError( 1620 "[" . get_class( 1621 $this). " DB_forum : getAllRootMessagesForCurrentForum()] " . $result->getMessage(). "", 1622 null, 1623 null, 1624 null, 1625 null, 1626 null, 1627 false); 1628 } 1629 1630 while ($row = $result->fetchRow()) { 1631 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 1632 1633 $maDate = new Date($row['maj']); 1634 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 1635 1636 $resultForum->_fetchData($row); 1637 $forums[] = &$resultForum; 1638 } 1639 1640 $result->free(); 1641 return $forums; 1642 } 1643 1644 // }}} 1645 1646 // {{{ getAllMessagesForParentId($parentId, $maDate = null) 1647 1648 function getAllMessagesForParentId ($parentId, $maDate = null) { 1649 $forums = array(); 1650 1651 $db = &$this->_getDB(); 1652 1653 if (DB::isError($db)) { 1654 return PEAR::raiseError( 1655 "[" . get_class($this). " DB_forum : getAllMessagesForParentId()] " . $db->getMessage(). "", 1656 null, 1657 null, 1658 null, 1659 null, 1660 null, 1661 false); 1662 } 1663 1664 $query = "SELECT " . FORUM_ALL_FIELDS . " FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_parent=$parentId"; 1665 1666 if ($maDate) 1667 $query .= " AND date_heure>='" . $maDate->getDate(DATE_FORMAT_ISO). "'"; 1668 1669 $result = $db->query($query); 1670 1671 if (DB::isError($result)) { 1672 return PEAR::raiseError( 1673 "[" . get_class($this). " DB_forum : getAllMessagesForParentId()] " . $result->getMessage(). "", 1674 null, 1675 null, 1676 null, 1677 null, 1678 null, 1679 false); 1680 } 1681 1682 while ($row = $result->fetchRow()) { 1683 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 1684 1685 $maDate = new Date($row['maj']); 1686 $row['maj'] = $maDate->getDate(DATE_FORMAT_TIMESTAMP); 1687 1688 $resultForum->_fetchData($row); 1689 $forums[] = &$resultForum; 1690 } 1691 1692 $result->free(); 1693 return $forums; 1694 } 1695 1696 // }}} 1697 1698 // {{{ howManyPostByForumId($parentId) 1699 1700 function howManyPostByForumId ($parentId) { 1701 $db = &$this->_getDB(); 1702 1703 if (DB::isError($db)) { 1704 return PEAR::raiseError( 1705 "[" . get_class($this). " DB_forum : howManyPostByForumId()] " . $db->getMessage(). "", null, 1706 null, null, 1707 null, null, 1708 false); 1709 } 1710 1711 $query = "SELECT COUNT(*) as count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_parent=$parentId"; 1712 1713 $result = $db->query($query); 1714 1715 if (DB::isError($result)) { 1716 return PEAR::raiseError( 1717 "[" . get_class($this). " DB_forum : howManyPostByForumId()] " . $result->getMessage(). "", null, 1718 null, null, 1719 null, null, 1720 false); 1721 } 1722 1723 if ($row = $result->fetchRow()) { 1724 return $row['count']; 1725 } 1726 1727 $result->free(); 1728 return 0; 1729 } 1730 1731 // }}} 1732 1733 // {{{ howManyPostByForumIdAndStatut($parentId, $statut) 1734 1735 function howManyPostByForumsIdAndStatut ($statut) { 1736 $db = &$this->_getDB(); 1737 1738 if (DB::isError($db)) { 1739 return PEAR::raiseError( 1740 "[" . get_class($this). " DB_forum : howManyPostByForumIdAndStatut()] " . $db->getMessage(). "", 1741 null, 1742 null, 1743 null, 1744 null, 1745 null, 1746 false); 1747 } 1748 1749 $query 1750 = "SELECT COUNT(*) AS cnt FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut='$statut' AND id_parent=0"; 1751 1752 //echo '<br />' . $query . '<br />'; 1753 1754 $result = $db->query($query); 1755 1756 if (DB::isError($result)) { 1757 return PEAR::raiseError( 1758 "[" . get_class( 1759 $this). " DB_forum : howManyPostByForumIdAndStatut()] " . $result->getMessage(). "", 1760 null, 1761 null, 1762 null, 1763 null, 1764 null, 1765 false); 1766 } 1767 1768 if ($row = $result->fetchRow()) { 1769 return $row['count']; 1770 } 1771 1772 $result->free(); 1773 return 0; 1774 } 1775 1776 // }}} 1777 1778 // {{{ deleteFichier($forum_id_article, $forum_id_rubrique, $forum_id_breve, $forum_id_parent, $CacheDirectory) 1779 1780 /** 1781 * delete cache files. 1782 * 1783 * 1784 * @delete cache files 1785 * @access public 1786 */ 1787 1788 function deleteFichier ($forum_id_article, $forum_id_rubrique, $forum_id_breve, $forum_id_parent, $CacheDirectory) { 1789 $fichiers = array(); 1790 $db = &$this->_getDB(); 1791 1792 if (DB::isError($db)) { 1793 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteFichier()] " . $db->getMessage(). "", null, null, null, null, null, false); 1794 } 1795 1796 unset($where); 1797 1798 if ($forum_id_article) 1799 $where[] = "id_article=$forum_id_article"; 1800 1801 if ($forum_id_rubrique) 1802 $where[] = "id_rubrique=$forum_id_rubrique"; 1803 1804 if ($forum_id_breve) 1805 $where[] = "id_breve=$forum_id_breve"; 1806 1807 if ($forum_id_parent) 1808 $where[] = "id_forum=$forum_id_parent"; 1809 1810 if ($where) { 1811 $query = "SELECT fichier FROM " . $GLOBALS['table_prefix']. "_forum_cache WHERE " . join(' OR ', $where); 1812 1813 $result = $db->query($query); 1814 1815 if (DB::isError($result)) { 1816 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteFichier()] " . $result->getMessage(). "", null, null, null, null, null, false); 1817 } 1818 1819 while ($row = $result->fetchRow()) { 1820 $fichier = $row["fichier"]; 1821 @unlink("$CacheDirectory/$fichier"); 1822 @unlink("$CacheDirectory/$fichier.NEW"); 1823 $fichiers[] = "'" . $fichier . "'"; 1824 } 1825 1826 $result->free(); 1827 if ($fichiers) { 1828 $fichiers = join(',', $fichiers); 1829 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum_cache WHERE fichier IN ($fichiers)"; 1830 1831 $db->query($query); 1832 } 1833 } 1834 } 1835 1836 // }}} 1837 1838 // {{{ deleteMajDate($majDate) 1839 1840 /** 1841 * This method is used to delete all articles former to mydate 1842 * @access public 1843 */ 1844 1845 function deleteMajDate ($mydate) { 1846 $db = &$this->_getDB(); 1847 1848 if (DB::isError($db)) { 1849 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteMajDate()] " . $db->getMessage(). "", null, null, null, null, null, false); 1850 } 1851 1852 $dateTmp = new Date($mydate); 1853 $mydate = $dateTmp->getDate(DATE_FORMAT_ISO); 1854 1855 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE maj < '$mydate'"; 1856 1857 $result = $db->query($query); 1858 1859 if (DB::isError($result)) { 1860 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteMajDate()] " . $result->getMessage(). "", null, null, null, null, null, false); 1861 } 1862 } 1863 1864 // }}} 1865 1866 // {{{ howManyForumForArticleIdAndStatuts($id_article, $statuts) 1867 1868 /** 1869 * This method returns the number of message for a published, off or proposed article 1870 * @return int 1871 * @param id_article 1872 * @param statuts 1873 * @access public 1874 */ 1875 function howManyForumForArticleIdAndStatuts ($articleId, $statuts, $parentId = -1) { 1876 $howManyForum = 0; 1877 $db = &$this->_getDB(); 1878 1879 if (DB::isError($db)) { 1880 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForArticleIdAndStatuts()] " . $db->getMessage(). "", null, null, null, null, null, false); 1881 } 1882 1883 $query = "SELECT count(*) AS count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_article=$articleId AND statut IN ($statuts)"; 1884 1885 //echo '<br>'.$query.'<br>'; 1886 if ($parentId != -1) { 1887 $query .= " AND id_parent=$parentId"; 1888 } 1889 1890 //echo "<br><br>$query<br><br>"; 1891 1892 $result = $db->getOne($query); 1893 1894 if (DB::isError($result)) { 1895 return 0; 1896 } 1897 else { 1898 $howManyForum = $result; 1899 } 1900 1901 return $howManyForum; 1902 } 1903 1904 // }}} 1905 1906 // {{{ howManyForumForArticleId($id_article) 1907 1908 /** 1909 * This method returns the number of message for a article 1910 * @return int 1911 * @param id_article 1912 * @access public 1913 */ 1914 function howManyForumForArticleId ($articleId) { 1915 $howManyForum = 0; 1916 $db = &$this->_getDB(); 1917 1918 if (DB::isError($db)) { 1919 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForArticleId()] " . $db->getMessage(). "", null, null, null, null, null, false); 1920 } 1921 1922 $query = "SELECT count(*) AS count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_article=$articleId"; 1923 1924 //echo "<br><br>$query<br><br>"; 1925 1926 $result = $db->getOne($query); 1927 1928 if (DB::isError($result)) { 1929 return 0; 1930 } 1931 else { 1932 $howManyForum = $result; 1933 } 1934 1935 return $howManyForum; 1936 } 1937 1938 // }}} 1939 1940 // {{{ howManyForumForBreveId($id_breve) 1941 1942 /** 1943 * This method returns the number of message for a breve 1944 * @return int 1945 * @param id_breve 1946 * @access public 1947 */ 1948 function howManyForumForBreveId ($breveId) { 1949 $howManyForum = 0; 1950 $db = &$this->_getDB(); 1951 1952 if (DB::isError($db)) { 1953 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForBreveId()] " . $db->getMessage(). "", null, null, null, null, null, false); 1954 } 1955 1956 $query = "SELECT count(*) AS count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_breve=$breveId"; 1957 1958 //echo "<br><br>$query<br><br>"; 1959 1960 $result = $db->getOne($query); 1961 1962 if (DB::isError($result)) { 1963 return 0; 1964 } 1965 else { 1966 $howManyForum = $result; 1967 } 1968 1969 return $howManyForum; 1970 } 1971 1972 // }}} 1973 1974 // {{{ howManyForumForRubriqueId($id_rubrique) 1975 1976 /** 1977 * This method returns the number of message for a rubrique 1978 * @return int 1979 * @param id_rubrique 1980 * @access public 1981 */ 1982 function howManyForumForRubriqueId ($rubriqueId) { 1983 $howManyForum = 0; 1984 $db = &$this->_getDB(); 1985 1986 if (DB::isError($db)) { 1987 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForRubriqueId()] " . $db->getMessage(). "", null, null, null, null, null, false); 1988 } 1989 1990 $query = "SELECT count(*) AS count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_rubrique=$rubriqueId"; 1991 1992 //echo "<br><br>$query<br><br>"; 1993 1994 $result = $db->getOne($query); 1995 1996 if (DB::isError($result)) { 1997 return 0; 1998 } 1999 else { 2000 $howManyForum = $result; 2001 } 2002 2003 return $howManyForum; 2004 } 2005 2006 // }}} 2007 2008 // {{{ howManyForumForRubriqueIdAndStatuts($id_rubrique, $statuts) 2009 2010 /** 2011 * This method returns the number of message for a published, off or proposed rubrique 2012 * @return int 2013 * @param id_rubrique 2014 * @param statuts 2015 * @access public 2016 */ 2017 function howManyForumForRubriqueIdAndStatuts ($rubriqueId, $statuts, $parentId = -1) { 2018 $howManyForum = 0; 2019 $db = &$this->_getDB(); 2020 2021 if (DB::isError($db)) { 2022 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForRubriqueIdAndStatuts()] " . $db->getMessage(). "", null, null, null, null, null, false); 2023 } 2024 2025 $query = "SELECT count(*) AS count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_rubrique=$rubriqueId AND statut IN ($statuts)"; 2026 2027 //echo '<br>'.$query.'<br>'; 2028 if ($parentId != -1) { 2029 $query .= " AND id_parent=$parentId"; 2030 } 2031 2032 //echo "<br><br>$query<br><br>"; 2033 2034 $result = $db->getOne($query); 2035 2036 if (DB::isError($result)) { 2037 return 0; 2038 } 2039 else { 2040 $howManyForum = $result; 2041 } 2042 2043 return $howManyForum; 2044 } 2045 2046 // }}} 2047 2048 // {{{ howManyForumForBreveIdAndStatuts($id_breve, $statuts) 2049 2050 /** 2051 * This method returns the number of message for a published, off or proposed breve 2052 * @return int 2053 * @param id_breve 2054 * @param statuts 2055 * @access public 2056 */ 2057 function howManyForumForBreveIdAndStatuts ($breveId, $statuts, $parentId = -1) { 2058 $howManyForum = 0; 2059 $db = &$this->_getDB(); 2060 2061 if (DB::isError($db)) { 2062 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForBreveIdAndStatuts()] " . $db->getMessage(). "", null, null, null, null, null, false); 2063 } 2064 2065 $query = "SELECT count(*) AS count FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_breve=$breveId AND statut IN ($statuts)"; 2066 2067 //echo '<br>'.$query.'<br>'; 2068 if ($parentId != -1) { 2069 $query .= " AND id_parent=$parentId"; 2070 } 2071 2072 //echo "<br><br>$query<br><br>"; 2073 2074 $result = $db->getOne($query); 2075 2076 if (DB::isError($result)) { 2077 return 0; 2078 } 2079 else { 2080 $howManyForum = $result; 2081 } 2082 2083 return $howManyForum; 2084 } 2085 2086 // }}} 2087 2088 // {{{ howManyForumForStatut2($statut) 2089 2090 /** 2091 * This method returns the number of statut message 2092 * @return int 2093 * @param statut 2094 * @access public 2095 */ 2096 function howManyForumForStatut2 ($statut) { 2097 $howManyForum = 0; 2098 $db = &$this->_getDB(); 2099 2100 if (DB::isError($db)) { 2101 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForStatut()] " . $db->getMessage(). "", null, null, null, null, null, false); 2102 } 2103 2104 $query = "SELECT id_rubrique, id_article, id_breve FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut='$statut'"; 2105 2106 $result = $db->query($query); 2107 2108 if (DB::isError($result)) { 2109 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForStatut()] " . $result->getMessage(). "", null, null, null, null, null, false); 2110 } 2111 2112 while ($row = $result->fetchRow()) { 2113 if ($row['id_article'] != 0) { 2114 $type_forum = 'article'; 2115 $id_current_forum = $row['id_article']; 2116 } 2117 2118 if ($row['id_rubrique'] != 0) { 2119 $type_forum = 'rubrique'; 2120 $id_current_forum = $row['id_rubrique']; 2121 } 2122 2123 if ($row['id_breve'] != 0) { 2124 $type_forum = 'breve'; 2125 $id_current_forum = $row['id_breve']; 2126 } 2127 2128 $authorization = &recuperer_instance_authorization('controlerForum2', $GLOBALS['connect_id_auteur'], array('type_forum' => $type_forum, 'id_current_forum' => $id_current_forum)); 2129 if ($authorization->isAuthorizedAction()) { 2130 $howManyForum++; 2131 } 2132 } 2133 2134 return $howManyForum; 2135 } 2136 2137 // }}} 2138 2139 // {{{ howManyForumForStatut($statut) 2140 2141 /** 2142 * This method returns the number of statut message 2143 * @return int 2144 * @param statut 2145 * @access public 2146 */ 2147 function howManyForumForStatut ($statut) { 2148 $howManyForum = 0; 2149 $db = &$this->_getDB(); 2150 2151 if (DB::isError($db)) { 2152 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForStatut()] " . $db->getMessage(). "", null, null, null, null, null, false); 2153 } 2154 2155 $query = "SELECT count(*) AS compte FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut='$statut'"; 2156 2157 $result = $db->getOne($query); 2158 2159 if (DB::isError($result)) { 2160 return PEAR::raiseError("[" . get_class($this). " DB_forum : howManyForumForStatut()] " . $result->getMessage(). "", null, null, null, null, null, false); 2161 } 2162 else { 2163 $howManyForum = $result; 2164 } 2165 2166 return $howManyForum; 2167 } 2168 2169 // }}} 2170 2171 // {{{ deleteExpiredCache() 2172 2173 /** 2174 * delete expired cache file 2175 * @access public 2176 */ 2177 function deleteExpiredCache () { 2178 $fichiers = array(); 2179 $db = &$this->_getDB(); 2180 2181 if (DB::isError($db)) { 2182 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteExpiredCache()] " . $db->getMessage(). "", null, null, null, null, null, false); 2183 } 2184 2185 $maDate = new Date(); 2186 $maDate->subtractSeconds(14 * 24 * 3600); 2187 //$query = "SELECT fichier FROM ".$GLOBALS['table_prefix']."_forum_cache WHERE maj < DATE_SUB(NOW(), INTERVAL 14 DAY)"; 2188 $query = "SELECT fichier FROM " . $GLOBALS['table_prefix']. "_forum_cache WHERE maj < '" . $maDate->getDate(DATE_FORMAT_ISO). "'"; 2189 2190 $result = $db->query($query); 2191 2192 if (DB::isError($result)) { 2193 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteExpiredCache()] " . $result->getMessage(). "", null, null, null, null, null, false); 2194 } 2195 2196 while ($row = $result->fetchRow()) { 2197 $fichier = $row['fichier']; 2198 if (!file_exists("CACHE/$fichier")) 2199 $fichiers[] = "'$fichier'"; 2200 } 2201 2202 $result->free(); 2203 2204 if ($fichiers) { 2205 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum_cache WHERE fichier IN (" . join(',', $fichiers). ")"; 2206 2207 $db->query($query); 2208 } 2209 } 2210 2211 // }}} 2212 2213 // {{{ deleteAllCache() 2214 2215 /** 2216 * delete cache file 2217 * @access public 2218 */ 2219 function deleteAllCache () { 2220 $fichiers = array(); 2221 $db = &$this->_getDB(); 2222 2223 if (DB::isError($db)) { 2224 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteAllCache()] " . $db->getMessage(). "", null, null, null, null, null, false); 2225 } 2226 2227 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum_cache"; 2228 2229 $result = $db->query($query); 2230 2231 if (DB::isError($result)) { 2232 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteAllCache()] " . $result->getMessage(). "", null, null, null, null, null, false); 2233 } 2234 } 2235 2236 // }}} 2237 2238 // {{{ deleteForStatutAndMaj($statut, $mydate) 2239 2240 function deleteForStatutAndMaj ($statut, $mydate) { 2241 $db = &$this->_getDB(); 2242 2243 if (DB::isError($db)) { 2244 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteForStatutAndMaj()] " . $db->getMessage(). "", null, null, null, null, null, false); 2245 } 2246 2247 $query = "DELETE FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut='$statut' AND maj<'$mydate'"; 2248 //$query = "DELETE FROM ".$GLOBALS['table_prefix']."_forum WHERE statut='$statut' AND date_heure<DATE_SUB(NOW(),INTERVAL 1 DAY)"; 2249 2250 $result = $db->query($query); 2251 2252 if (DB::isError($result)) { 2253 return PEAR::raiseError("[" . get_class($this). " DB_forum : deleteForStatutAndMaj()] " . $result->getMessage(). "", null, null, null, null, null, false); 2254 } 2255 } 2256 2257 // }}} 2258 2259 // {{{ getMessageWayForStatut($id_current_forum, $type_forum, $statut) 2260 2261 function getMessageWayForStatut ($id_current_forum, $type_forum, $statut) { 2262 $ids = array(); 2263 2264 $db = &$this->_getDB(); 2265 2266 if (DB::isError($db)) { 2267 return PEAR::raiseError("[" . get_class($this). " DB_forum : getMessageWayForStatut()] " . $db->getMessage(). "", null, null, null, null, null, false); 2268 } 2269 2270 $statut = explode(",", $statut); 2271 $query = "SELECT id_forum, id_parent FROM " . $GLOBALS['table_prefix']. "_forum WHERE statut IN ('" . join("','", $statut). "') AND id_$type_forum=$id_current_forum"; 2272 //echo $query.'<br>'; 2273 2274 $result = $db->query($query); 2275 2276 if (DB::isError($result)) { 2277 return PEAR::raiseError("[" . get_class($this). " DB_forum : getMessageWayForStatut()] " . $result->getMessage(). "", null, null, null, null, null, false); 2278 } 2279 2280 while ($row = $result->fetchRow()) { 2281 $ids[] = $row['id_forum']; 2282 $ids[] = $row['id_parent']; 2283 while ($row['id_parent'] != 0) { 2284 $query = "SELECT id_parent FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum=" . $row['id_parent']; 2285 //echo $query.'<br>'; 2286 2287 $result2 = $db->query($query); 2288 2289 if (DB::isError($result2)) { 2290 return PEAR::raiseError("[" . get_class($this). " DB_forum : getMessageWayForStatut()] " . $result->getMessage(). "", null, null, null, null, null, false); 2291 } 2292 2293 if ($row = $result2->fetchRow()) { 2294 if ($row['id_parent']) 2295 $ids[] = $row['id_parent']; 2296 } 2297 $result2->free(); 2298 } 2299 } 2300 2301 $result->free(); 2302 2303 return array_unique($ids); 2304 } 2305 2306 // }}} 2307 2308 // {{{ search($recherche, $typeRecherche) 2309 2310 /** 2311 * Returns an array of Forum. 2312 * 2313 * @return Array of Forum 2314 * @param $page 2315 * @param $limitedeb 2316 * @param $limitnb 2317 * @param $page 2318 * @access public 2319 */ 2320 2321 function &search ($recherche, $typeRecherche, $id_current_forum = null, $type_forum = null) { 2322 $forums = array(); 2323 $db = &$this->_getDB(); 2324 2325 if (DB::isError($db)) { 2326 return PEAR::raiseError("[" . get_class($this). " DB_forum : search()] " . $db->getMessage(). "", null, null, null, null, null, false); 2327 } 2328 2329 $recherche = $db->quoteString($recherche); 2330 $recherche = corriger_caracteres($recherche); 2331 2332 if (ereg('danstouslesforums', $typeRecherche)) { 2333 $id_current_forum = null; 2334 $type_forum = null; 2335 2336 $query = "SELECT " . $GLOBALS['table_prefix']. "_forum.id_forum, " . $GLOBALS['table_prefix']. "_forum.id_parent, " . $GLOBALS['table_prefix']. "_forum.id_rubrique, " . $GLOBALS['table_prefix']. "_forum.id_article, " . $GLOBALS['table_prefix']. "_forum.id_breve, " . $GLOBALS['table_prefix']. "_forum.date_heure, " . $GLOBALS['table_prefix']. "_forum.titre, " . $GLOBALS['table_prefix']. "_forum.texte, " . $GLOBALS['table_prefix']. "_forum.auteur, " . $GLOBALS['table_prefix']. "_forum.email_auteur, " . $GLOBALS['table_prefix']. "_forum.nom_site, " . $GLOBALS['table_prefix']. "_forum.url_site, " . $GLOBALS['table_prefix']. "_forum.statut, " . $GLOBALS['table_prefix']. "_forum.ip, " . $GLOBALS['table_prefix']. "_forum.id_auteur FROM " . $GLOBALS['table_prefix']. "_forum, " . $GLOBALS['table_prefix']. "_rubriques WHERE 1=1 "; 2337 2338 if (ereg('sujet,message', $typeRecherche)) 2339 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_rubrique=" . $GLOBALS['table_prefix']. "_rubriques.id_rubrique AND (" . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' OR " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%') "; 2340 else { 2341 if (ereg('sujet', $typeRecherche)) 2342 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_rubrique=" . $GLOBALS['table_prefix']. "_rubriques.id_rubrique AND " . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' "; 2343 if (ereg('message', $typeRecherche)) 2344 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_rubrique=" . $GLOBALS['table_prefix']. "_rubriques.id_rubrique AND " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%' "; 2345 } 2346 2347 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.statut IN ('publie','prop','off','poubelle')"; 2348 2349 //echo '<br>'.$query.'<br>'; 2350 2351 $queryResult = $db->query($query); 2352 2353 if (DB::isError($queryResult)) { 2354 return PEAR::raiseError("[" . get_class($this). " DB_forum : search()] " . $queryResult->getMessage(). "", null, null, null, null, null, false); 2355 } 2356 2357 while ($row = $queryResult->fetchRow()) { 2358 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 2359 $resultForum->_fetchData($row); 2360 $forums[] = &$resultForum; 2361 } 2362 2363 $queryResult->free(); 2364 2365 //$query = 'SELECT DISTINCT(".$GLOBALS['table_prefix']."_forum.id_forum), ".$GLOBALS['table_prefix']."_forum.id_parent, ".$GLOBALS['table_prefix']."_forum.id_rubrique, ".$GLOBALS['table_prefix']."_forum.id_article, ".$GLOBALS['table_prefix']."_forum.id_breve, ".$GLOBALS['table_prefix']."_forum.date_heure, ".$GLOBALS['table_prefix']."_forum.titre, ".$GLOBALS['table_prefix']."_forum.texte, ".$GLOBALS['table_prefix']."_forum.auteur, ".$GLOBALS['table_prefix']."_forum.email_auteur, ".$GLOBALS['table_prefix']."_forum.nom_site, ".$GLOBALS['table_prefix']."_forum.url_site, ".$GLOBALS['table_prefix']."_forum.statut, ".$GLOBALS['table_prefix']."_forum.ip, ".$GLOBALS['table_prefix']."_forum.id_auteur FROM ".$GLOBALS['table_prefix']."_forum, ".$GLOBALS['table_prefix']."_articles WHERE 1=1 '; 2366 $query = "SELECT " . $GLOBALS['table_prefix']. "_forum.id_forum, " . $GLOBALS['table_prefix']. "_forum.id_parent, " . $GLOBALS['table_prefix']. "_forum.id_rubrique, " . $GLOBALS['table_prefix']. "_forum.id_article, " . $GLOBALS['table_prefix']. "_forum.id_breve, " . $GLOBALS['table_prefix']. "_forum.date_heure, " . $GLOBALS['table_prefix']. "_forum.titre, " . $GLOBALS['table_prefix']. "_forum.texte, " . $GLOBALS['table_prefix']. "_forum.auteur, " . $GLOBALS['table_prefix']. "_forum.email_auteur, " . $GLOBALS['table_prefix']. "_forum.nom_site, " . $GLOBALS['table_prefix']. "_forum.url_site, " . $GLOBALS['table_prefix']. "_forum.statut, " . $GLOBALS['table_prefix']. "_forum.ip, " . $GLOBALS['table_prefix']. "_forum.id_auteur FROM " . $GLOBALS['table_prefix']. "_forum, " . $GLOBALS['table_prefix']. "_articles WHERE 1=1 "; 2367 2368 if (ereg('sujet,message,danstouslesforums', $typeRecherche)) 2369 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_article=" . $GLOBALS['table_prefix']. "_articles.id_article AND (" . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' OR " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%') "; 2370 else { 2371 if (ereg('sujet,danstouslesforums', $typeRecherche)) 2372 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_article=" . $GLOBALS['table_prefix']. "_articles.id_article AND " . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' "; 2373 if (ereg('message,danstouslesforums', $typeRecherche)) 2374 $query .= "AND " . $GLOBALS['table_prefix']. "_forum.id_article=" . $GLOBALS['table_prefix']. "_articles.id_article AND " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%' "; 2375 } 2376 2377 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.statut IN ('publie','prop','off','poubelle')"; 2378 2379 //echo '<br>'.$query.'<br>'; 2380 2381 $queryResult = $db->query($query); 2382 2383 if (DB::isError($queryResult)) { 2384 return PEAR::raiseError("[" . get_class($this). " DB_forum : search()] " . $queryResult->getMessage(). "", null, null, null, null, null, false); 2385 } 2386 2387 while ($row = $queryResult->fetchRow()) { 2388 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 2389 $resultForum->_fetchData($row); 2390 $forums[] = &$resultForum; 2391 } 2392 2393 $queryResult->free(); 2394 2395 $query = "SELECT " . $GLOBALS['table_prefix']. "_forum.id_forum, " . $GLOBALS['table_prefix']. "_forum.id_parent, " . $GLOBALS['table_prefix']. "_forum.id_rubrique, " . $GLOBALS['table_prefix']. "_forum.id_article, " . $GLOBALS['table_prefix']. "_forum.id_breve, " . $GLOBALS['table_prefix']. "_forum.date_heure, " . $GLOBALS['table_prefix']. "_forum.titre, " . $GLOBALS['table_prefix']. "_forum.texte, " . $GLOBALS['table_prefix']. "_forum.auteur, " . $GLOBALS['table_prefix']. "_forum.email_auteur, " . $GLOBALS['table_prefix']. "_forum.nom_site, " . $GLOBALS['table_prefix']. "_forum.url_site, " . $GLOBALS['table_prefix']. "_forum.statut, " . $GLOBALS['table_prefix']. "_forum.ip, " . $GLOBALS['table_prefix']. "_forum.id_auteur FROM " . $GLOBALS['table_prefix']. "_forum, " . $GLOBALS['table_prefix']. "_breves WHERE 1=1 "; 2396 2397 if (ereg('sujet,message,danstouslesforums', $typeRecherche)) 2398 $query .= "AND " . $GLOBALS['table_prefix']. "_forum.id_breve=" . $GLOBALS['table_prefix']. "_breves.id_breve AND (" . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' OR " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%') "; 2399 else { 2400 if (ereg('sujet,danstouslesforums', $typeRecherche)) 2401 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_breve=" . $GLOBALS['table_prefix']. "_breves.id_breve AND " . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' "; 2402 if (ereg('message,danstouslesforums', $typeRecherche)) 2403 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_breve=" . $GLOBALS['table_prefix']. "_breves.id_breve AND " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%' "; 2404 } 2405 2406 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.statut IN ('publie','prop','off','poubelle')"; 2407 2408 //echo '<br>'.$query.'<br>'; 2409 2410 $queryResult = $db->query($query); 2411 2412 if (DB::isError($queryResult)) { 2413 return PEAR::raiseError("[" . get_class($this). " DB_forum : search()] " . $queryResult->getMessage(). "", null, null, null, null, null, false); 2414 } 2415 2416 while ($row = $queryResult->fetchRow()) { 2417 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 2418 $resultForum->_fetchData($row); 2419 $forums[] = &$resultForum; 2420 } 2421 $queryResult->free(); 2422 } 2423 2424 if (!ereg('danstouslesforums', $typeRecherche)) { 2425 if ($id_current_forum != null) { 2426 switch ($type_forum) { 2427 case 'rubrique': 2428 $query = "SELECT " . $GLOBALS['table_prefix']. "_forum.id_forum, " . $GLOBALS['table_prefix']. "_forum.id_parent, " . $GLOBALS['table_prefix']. "_forum.id_rubrique, " . $GLOBALS['table_prefix']. "_forum.id_article, " . $GLOBALS['table_prefix']. "_forum.id_breve, " . $GLOBALS['table_prefix']. "_forum.date_heure, " . $GLOBALS['table_prefix']. "_forum.titre, " . $GLOBALS['table_prefix']. "_forum.texte, " . $GLOBALS['table_prefix']. "_forum.auteur, " . $GLOBALS['table_prefix']. "_forum.email_auteur, " . $GLOBALS['table_prefix']. "_forum.nom_site, " . $GLOBALS['table_prefix']. "_forum.url_site, " . $GLOBALS['table_prefix']. "_forum.statut, " . $GLOBALS['table_prefix']. "_forum.ip, " . $GLOBALS['table_prefix']. "_forum.id_auteur FROM " . $GLOBALS['table_prefix']. "_forum, " . $GLOBALS['table_prefix']. "_rubriques WHERE 1=1 "; 2429 if (ereg('sujet,message', $typeRecherche)) 2430 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_rubrique=" . $GLOBALS['table_prefix']. "_rubriques.id_rubrique AND (" . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' OR " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%') "; 2431 else { 2432 if (ereg('sujet', $typeRecherche)) 2433 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_rubrique=" . $GLOBALS['table_prefix']. "_rubriques.id_rubrique AND " . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' "; 2434 if (ereg('message', $typeRecherche)) 2435 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_rubrique=" . $GLOBALS['table_prefix']. "_rubriques.id_rubrique AND " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%' "; 2436 } 2437 $query .= ' AND id_forum = ' . $id_current_forum; 2438 break; 2439 2440 case 'breve': 2441 $query = "SELECT " . $GLOBALS['table_prefix']. "_forum.id_forum, " . $GLOBALS['table_prefix']. "_forum.id_parent, " . $GLOBALS['table_prefix']. "_forum.id_rubrique, " . $GLOBALS['table_prefix']. "_forum.id_article, " . $GLOBALS['table_prefix']. "_forum.id_breve, " . $GLOBALS['table_prefix']. "_forum.date_heure, " . $GLOBALS['table_prefix']. "_forum.titre, " . $GLOBALS['table_prefix']. "_forum.texte, " . $GLOBALS['table_prefix']. "_forum.auteur, " . $GLOBALS['table_prefix']. "_forum.email_auteur, " . $GLOBALS['table_prefix']. "_forum.nom_site, " . $GLOBALS['table_prefix']. "_forum.url_site, " . $GLOBALS['table_prefix']. "_forum.statut, " . $GLOBALS['table_prefix']. "_forum.ip, " . $GLOBALS['table_prefix']. "_forum.id_auteur FROM " . $GLOBALS['table_prefix']. "_forum, " . $GLOBALS['table_prefix']. "_breves WHERE 1=1 "; 2442 if (ereg('sujet,message', $typeRecherche)) 2443 $query .= "AND " . $GLOBALS['table_prefix']. "_forum.id_breve=" . $GLOBALS['table_prefix']. "_breves.id_breve AND (" . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' OR " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%') "; 2444 else { 2445 if (ereg('sujet', $typeRecherche)) 2446 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_breve=" . $GLOBALS['table_prefix']. "_breves.id_breve AND " . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' "; 2447 if (ereg('message', $typeRecherche)) 2448 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_breve=" . $GLOBALS['table_prefix']. "_breves.id_breve AND " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%' "; 2449 } 2450 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_breve = " . $id_current_forum; 2451 break; 2452 2453 case 'article': 2454 //echo "c'est un article"; 2455 $query = "SELECT " . $GLOBALS['table_prefix']. "_forum.id_forum, " . $GLOBALS['table_prefix']. "_forum.id_parent, " . $GLOBALS['table_prefix']. "_forum.id_rubrique, " . $GLOBALS['table_prefix']. "_forum.id_article, " . $GLOBALS['table_prefix']. "_forum.id_breve, " . $GLOBALS['table_prefix']. "_forum.date_heure, " . $GLOBALS['table_prefix']. "_forum.titre, " . $GLOBALS['table_prefix']. "_forum.texte, " . $GLOBALS['table_prefix']. "_forum.auteur, " . $GLOBALS['table_prefix']. "_forum.email_auteur, " . $GLOBALS['table_prefix']. "_forum.nom_site, " . $GLOBALS['table_prefix']. "_forum.url_site, " . $GLOBALS['table_prefix']. "_forum.statut, " . $GLOBALS['table_prefix']. "_forum.ip, " . $GLOBALS['table_prefix']. "_forum.id_auteur FROM " . $GLOBALS['table_prefix']. "_forum, " . $GLOBALS['table_prefix']. "_articles WHERE 1=1 "; 2456 if (ereg('sujet,message', $typeRecherche)) { 2457 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_article=" . $GLOBALS['table_prefix']. "_articles.id_article AND (" . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' OR " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%') "; 2458 } 2459 else { 2460 if (ereg('sujet', $typeRecherche)) 2461 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_article=" . $GLOBALS['table_prefix']. "_articles.id_article AND " . $GLOBALS['table_prefix']. "_forum.titre like '%" . $recherche . "%' "; 2462 if (ereg('message', $typeRecherche)) 2463 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_article=" . $GLOBALS['table_prefix']. "_articles.id_article AND " . $GLOBALS['table_prefix']. "_forum.texte like '%" . $recherche . "%' "; 2464 } 2465 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.id_article = " . $id_current_forum; 2466 break; 2467 } 2468 2469 $query .= " AND " . $GLOBALS['table_prefix']. "_forum.statut IN ('publie','prop','off','poubelle')"; 2470 2471 //echo '<br>'.$query.'<br>'; 2472 2473 $queryResult = $db->query($query); 2474 2475 if (DB::isError($queryResult)) { 2476 return PEAR::raiseError("[" . get_class($this). " DB_forum : search()] " . $queryResult->getMessage(). "", null, null, null, null, null, false); 2477 } 2478 2479 while ($row = $queryResult->fetchRow()) { 2480 $resultForum = &BD_forum::factory($this->getDbParameters(), $this->getDbOptions()); 2481 2482 $resultForum->_fetchData($row); 2483 $forums[] = &$resultForum; 2484 } 2485 $queryResult->free(); 2486 } 2487 } 2488 2489 return $forums; 2490 } 2491 2492 // }}} 2493 2494 // {{{ changeStatutOK($forumId, $statut) 2495 2496 /** 2497 * Returns an boolean. 2498 * 2499 * @return boolean 2500 * @param $forumId 2501 * @param $statut 2502 * @access public 2503 */ 2504 2505 function changeStatutOK ($forumId, $statut) { 2506 $forums = array(); 2507 $db = &$this->_getDB(); 2508 2509 if (DB::isError($db)) { 2510 return PEAR::raiseError("[" . get_class($this). " DB_forum : changeStatutOK()] " . $db->getMessage(). "", null, null, null, null, null, false); 2511 } 2512 2513 if ($statut == 'publie') { 2514 $query = "SELECT id_parent FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum=" . $forumId; 2515 $row = $db->getRow($query); 2516 while ($row['id_parent'] != 0) { 2517 $query = "SELECT id_parent, statut FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum=" . $row['id_parent']; 2518 $row = $db->getRow($query); 2519 if ($row['statut'] != 'publie') 2520 return false; 2521 } 2522 } 2523 2524 if ($statut == 'poubelle') { 2525 $query = "SELECT count(*) as cpt FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_parent=" . $forumId . " AND statut!='poubelle'"; 2526 //echo '<br>'.$query.'<br>'; 2527 if ($db->getOne($query) > 0) 2528 return false; 2529 } 2530 2531 if ($statut == 'off') { 2532 $query = "SELECT count(*) as cpt FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_parent=" . $forumId . " AND statut!='poubelle' AND statut!='off'"; 2533 //echo '<br>'.$query.'<br>'; 2534 if ($db->getOne($query) > 0) 2535 return false; 2536 } 2537 2538 return true; 2539 } 2540 2541 // }}} 2542 2543 // {{{ getBranch($forumId) 2544 2545 /** 2546 * Returns a string. 2547 * 2548 * @return String 2549 * @param $forumId 2550 2551 * @access public 2552 */ 2553 2554 function getBranch ($forumId, $params = array()) { 2555 $branch = array(); 2556 $db = &$this->_getDB(); 2557 2558 $affMessage = implode(",", $params['affMessage']); 2559 2560 if (DB::isError($db)) { 2561 return PEAR::raiseError("[" . get_class($this). " DB_forum : changeStatutOK()] " . $db->getMessage(). "", null, null, null, null, null, false); 2562 } 2563 2564 $query = "SELECT id_parent FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum=" . $forumId; 2565 $row = $db->getRow($query); 2566 2567 while ($row['id_parent'] != 0) { 2568 $id_parent = $row['id_parent']; 2569 $query = "SELECT id_parent, titre FROM " . $GLOBALS['table_prefix']. "_forum WHERE id_forum=" . $row['id_parent']; 2570 $row = $db->getRow($query); 2571 $branch[] = '<a href="affichage_message.php?affMessage[]=' . $affMessage . '&id_forum=' . $id_parent . '&id_current_forum=' . $params['id_current_forum']. '&type_forum=' . $params['type_forum']. '&affType=' . $params['affType']. '&ageMessage=' . $params['ageMessage']. '">' . $row['titre']. '</a>'; 2572 } 2573 2574 return implode(" <img src=\"img_pack/fleche.gif\"> ", array_reverse($branch)); 2575 } 2576 2577 // }}} 2578 2579 // {{{ sendMail($forum) 2580 2581 function sendMail ($forum, $adresseMessage = '') { 2582 if ($adresseMessage == '') 2583 $adresseMessage = lire_meta('adresse_site'); 2584 2585 $nom_site_spip = lire_meta("nom_site"); 2586 $adresse_site = lire_meta("addresse_site"); 2587 2588 include_ecrire('inc_mail.php'); 2589 $message = _T('reponse_forum_message', array('email' => $forum->getEmailAuteur(), 'adresse_message' => $adresseMessage, 'titreMessagePere' => $this->getTitre())); 2590 2591 if ($this->getEmailAlerte() == 'oui') { 2592 envoyer_mail($this->getEmailAuteur(), '[' . $nom_site_spip . '] ' . _T('reponse_forum'), $message); 2593 } 2594 } 2595 2596 // }}} 2597 2598 // {{{ advertiseAuthorPublished($adresseMessage = '') 2599 2600 function advertiseAuthorPublished ($adresseMessage = '') { 2601 if ($adresseMessage == '') 2602 $adresseMessage = lire_meta('adresse_site'); 2603 2604 $nom_site_spip = lire_meta("nom_site"); 2605 $adresse_site = lire_meta("addresse_site"); 2606 2607 include_ecrire('inc_mail.php'); 2608 $message = _T('reponse_forum_publie', array('titre_message' => $this->getTitre(), 'adresse_message' => $adresseMessage)); 2609 2610 if ($this->getEmailAlerte() == 'oui') { 2611 envoyer_mail($this->getEmailAuteur(), '[' . $nom_site_spip . '] ' . _T('reponse_forum'), $message); 2612 } 2613 } 2614 2615 // }}} 2616 2617 // {{{ advertiseAuthorRefused() 2618 2619 function advertiseAuthorRefused () { 2620 include_ecrire('inc_mail.php'); 2621 $message = _T('reponse_forum_refuse', array('titre_message' => $this->getTitre())); 2622 2623 if ($this->getEmailAlerte() == 'oui') { 2624 envoyer_mail($this->getEmailAuteur(), '[' . $nom_site_spip . '] ' . _T('reponse_forum'), $message); 2625 } 2626 } 2627 2628 // }}} 2629 2630 // {{{ isArchive($articleId, $rubriqueId) 2631 2632 function isArchive ($articleId, $rubriqueId) { 2633 if ($articleId != 0) { 2634 $articleMetier = &recuperer_instance_article(); 2635 $loadOK = $articleMetier->load($articleId); 2636 2637 if (PEAR::isError($loadOK)) { 2638 return false; 2639 } 2640 if ($articleMetier->getStatut() == 'archi') { 2641 return false; 2642 } 2643 else { 2644 return true; 2645 } 2646 } 2647 2648 if ($rubriqueId != 0) { 2649 $rubriqueMetier = &recuperer_instance_rubrique(); 2650 $loadOK = $rubriqueMetier->load($rubriqueId); 2651 2652 if (PEAR::isError($loadOK)) { 2653 return false; 2654 } 2655 if ($rubriqueMetier->getStatut() == 'archi') { 2656 return false; 2657 } 2658 else { 2659 return true; 2660 } 2661 } 2662 2663 return true; 2664 } 2665 2666 // }}} 2667 2668 } 2669 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |