[ PHPXref.com ] [ Generated: Sun Jul 20 18:04:10 2008 ] [ GuppY 4.5.12 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/install/ -> functions24.php (source)

   1  <?
   2  /*

   3      Functions - GuppY PHP Script - version 2.4

   4      CeCILL Copyright (C) 2004-2005 by Laurent Duveau

   5      Initiated by Laurent Duveau and Nicolas Alvès,

   6      followed by Albert Aymard, Jean Michel Misrachi and all the Team

   7        Web site = http://www.freeguppy.org/

   8        e-mail   = info@aldweb.com

   9  

  10      Version History :

  11        v1.0 (30 December 2002) : initial release

  12        v1.1 (02 January 2003)  : added AppendDBFields() function

  13                                  replaced WriteDBFields() by AppendDBFields() where appropriate

  14                                    (in order to avoid overwrites when more users perform "add" simultaneously)

  15        v1.2 (05 January 2003)   : created database art.dtb for quicker display

  16                                     this new database is managed by the UpdateDBart() function => see update v1.7

  17                                   created databases thread.dtb and forum.dtb for quicker display of forum threads

  18                                     these new databases are managed by the UpdateDBforum() function

  19        v1.3 (06 January 2003)   : moved InitDBlog() function from log.inc

  20                                   added eMailTo() function

  21        v1.4 (07 January 2003)   : introduced logh.dtb for not loosing all of logd.dtb data

  22                                     in case of accidental erasal of logd.dtb file

  23        v1.5 (10 January 2003)   : no change

  24        v1.6 (23 January 2003)   : added option to hide on the site the e-mail address of poster

  25                                     that is insertion of a new field ($fieldd1) in database and

  26                                     update in UpdateDBforum() and ActionOnFields() functions

  27                                   added StartTimer() and StopTimer() functions

  28        v1.7 (28 January 2003)   : updated the eMailTo() function to add destination e-mail for recommend to a friend option

  29                                   created databases links.dtb and dnload.dtb files for category sorting of links and downloads

  30                                     these new databases (and art.dtb) are managed by the UpdateDBdtb() function

  31                                     insertion of a new field ($fieldd2) in database

  32                                   migrated news.dat management from admin.inc and upgraded it

  33        v1.8 (05 February 2003)  : added category for forum

  34                                     that is update in UpdateDBforum() function

  35        v1.9 (11 February 2003)  : moved make_seed() function (renamed as MakeSeed) from boxcita.inc (also used by

  36                                     the new boxban.inc banner management)

  37        v2.0 (27 February 2003)  : added advanced photo service, that is ActionOnFields() function small update

  38                                   added BreakEMail() function

  39        v2.1 (10 March 2003)     : no change

  40        v2.2 (22 April 2003)     : added INCREP variable (needed for boxes free positionning)

  41                                   updated UpdateDBdtb() function for left and right articles boxes management

  42                                   upgraded CompteVisites() function to have it compliant to the GuppY DB

  43                                   added bmp type in IsImage() function

  44                                   updated souriez array definition for management of smileys themes

  45                                   added DrawSmileys() function

  46                                   cleanup in the images organization (Smileys)

  47        v2.3 (27 July 2003)      : replaced mtitre class by titre class in htable1()

  48                                   background of central boxes also change color according to mouse move in htable()

  49                                   removed link on counters numbers in counter box in the AfficheCompteur() function

  50                                   added US date format management

  51                                   modified DrawSmileys() function

  52                                   added PathToImage() function

  53                                   added $ special character management in PutHR()

  54        v2.4 (24 September 2003) : upgraded CompteVisites() function to capture user pseudo of registered users

  55                                   added SplitText() function

  56                                   added react to an article option , that is new UpdateDBreact() function

  57                                   slightly upgraded the FileSizeInKb() function

  58                                   upgraded eMailTo() function to accept additional specific e-mailing according to webhosters

  59                                   added ReadDoc() and WriteDoc() functions and upgraded all required functions accordingly

  60                                   added ReadDocCounter(), WriteDocCounter() and UpdateDocCounter() functions

  61                                   created many new $d[something] variables and upgraded all required functions accordingly

  62                                   added GetCurrentDateTime(), FormatDate() and FormatDateStamp() functions to ease various date and time formatings

  63                                   reviewed all Files Read & Write functions

  64                                   added lookup for png and bmp images in IsImage() function

  65                                   added FileDBExist() and DestroyDBFile() functions

  66                                   added RemoveQuote() function

  67                                   added 3 additional free boxes (by Nicolas Alves and Laurent Duveau)

  68                                   created $typ_[name] variables and updated all scripts & functions accordingly

  69                                   upgraded forum indexes for a smaller size

  70                                   moved DejaVote() function from poll.php to functions.php (now also used for documents counters)

  71                                     and upgraded CompteVisites() function accordingly

  72  */
  73  
  74  if (stristr($_SERVER["SCRIPT_NAME"], "functions24.php")) {
  75    header("location:../index.php");
  76    die();
  77  }
  78  define("CONNECTOR", "||");
  79  
  80  define("DBBASE", CHEMIN.DATAREP."doc");
  81  define("USEREP", CHEMIN.DATAREP."usermsg/");
  82  
  83  define("INCREP", "inc/");
  84  define("DBEXT", ".dtb");
  85  define("INCEXT", ".inc");
  86  
  87  define("DBBASE", CHEMIN.DATAREP."doc");
  88  define("DBIPBASE", CHEMIN.DATAREP."ipdoc");
  89  
  90  define("CONFIG", CHEMIN.DATAREP."config".INCEXT);
  91  define("NEXTID", CHEMIN.DATAREP."nextid".DBEXT);
  92  define("DOCID", CHEMIN.DATAREP."docid".DBEXT);
  93  
  94  define("TYP_ART", "ar");
  95  define("TYP_BANNER", "ba");
  96  define("TYP_DNLOAD", "dn");
  97  define("TYP_FAQ", "fa");
  98  define("TYP_FOOTER", "ft");
  99  define("TYP_FORUM", "fr");
 100  define("TYP_THREAD", "frth");
 101  define("TYP_FREEBOX1", "f1");
 102  define("TYP_FREEBOX2", "f2");
 103  define("TYP_FREEBOX3", "f3");
 104  define("TYP_FREEBOX4", "f4");
 105  define("TYP_GUESTBK", "gb");
 106  define("TYP_HOMEPG", "ed");
 107  define("TYP_LINKS", "li");
 108  define("TYP_NEWS", "ne");
 109  define("TYP_NWL", "nl");
 110  define("TYP_PHOTO", "ph");
 111  define("TYP_REACT", "ra");
 112  define("TYP_RECO", "re");
 113  define("TYP_RSS", "rs");
 114  define("TYP_SPECIAL", "sp");
 115  define("TYP_THINK", "ci");
 116  define("TYP_AGENDA", "ag");
 117  
 118  define("DBART", CHEMIN.DATAREP.TYP_ART.DBEXT);
 119  define("DBDNLOAD", CHEMIN.DATAREP.TYP_DNLOAD.DBEXT);
 120  define("DBFAQ", CHEMIN.DATAREP.TYP_FAQ.DBEXT);
 121  define("DBFORUMCAT", CHEMIN.DATAREP.TYP_FORUM."cat".DBEXT);
 122  define("DBFORUM", CHEMIN.DATAREP.TYP_FORUM.DBEXT);
 123  define("DBFORUMCOUNTER", CHEMIN.DATAREP.TYP_FORUM."count".DBEXT);
 124  define("DBTHREAD", CHEMIN.DATAREP.TYP_THREAD.DBEXT);
 125  define("DBLINKS", CHEMIN.DATAREP.TYP_LINKS.DBEXT);
 126  define("DBPHOTO", CHEMIN.DATAREP.TYP_PHOTO.DBEXT);
 127  define("DBPOLL", CHEMIN.DATAREP."poll".DBEXT);
 128  define("DBIPPOLL", CHEMIN.DATAREP."ippoll".DBEXT);
 129  define("DBREACT", CHEMIN.DATAREP.TYP_REACT.DBEXT);
 130  
 131  define("DBCOUNTER", CHEMIN.DATAREP."counter".DBEXT);
 132  define("DBSTATS", CHEMIN.DATAREP."stats".DBEXT);
 133  define("DBSTATSBK", CHEMIN.DATAREP."statsbk".DBEXT);
 134  define("DBIPSTATS", CHEMIN.DATAREP."ipstats".DBEXT);
 135  
 136  define("DBLOGH", CHEMIN.DATAREP."logh".DBEXT);
 137  define("DBLOGD", CHEMIN.DATAREP."logd".DBEXT);
 138  define("DBLOGM", CHEMIN.DATAREP."logm".DBEXT);
 139  define("DBLOGY", CHEMIN.DATAREP."logy".DBEXT);
 140  define("DBLOGP", CHEMIN.DATAREP."logp".DBEXT);
 141  
 142  define("DBHOMEPAGE", CHEMIN.DATAREP.TYP_HOMEPG.INCEXT);
 143  define("DBFOOT", CHEMIN.DATAREP.TYP_FOOTER.INCEXT);
 144  define("DBSPECIAL", CHEMIN.DATAREP.TYP_SPECIAL.INCEXT);
 145  define("DBFREEBOX1", CHEMIN.DATAREP.TYP_FREEBOX1.INCEXT);
 146  define("DBFREEBOX2", CHEMIN.DATAREP.TYP_FREEBOX2.INCEXT);
 147  define("DBFREEBOX3", CHEMIN.DATAREP.TYP_FREEBOX3.INCEXT);
 148  define("DBFREEBOX4", CHEMIN.DATAREP.TYP_FREEBOX4.INCEXT);
 149  define("DBNEWS", CHEMIN.DATAREP."news");
 150  
 151  define("HIT_TIME", 1800);
 152  
 153  $couleurs = array("bleu", "jaune", "marron", "or", "orange", "outremer", "rose", "rouge", "vert", "violet");
 154  $souriez = array(
 155               array("|:-)", "inc/img/smileys/cool.gif"),
 156               array(";-)", "inc/img/smileys/wink.gif"),
 157               array(":-))", "inc/img/smileys/biggrin.gif"),
 158               array(":-)", "inc/img/smileys/smile.gif"),
 159               array(":-o", "inc/img/smileys/frown.gif"),
 160               array(":o)", "inc/img/smileys/eek.gif"),
 161               array(":-((", "inc/img/smileys/mad.gif"),
 162               array(":-(", "inc/img/smileys/confused.gif"),
 163               array("8-)", "inc/img/smileys/rolleyes.gif"),
 164               array(":-p", "inc/img/smileys/tongue.gif"),
 165               array(";-(", "inc/img/smileys/cry.gif")
 166             );
 167  
 168  
 169  function htable($tblti, $largeur) {
 170    global $texte;
 171    echo "<table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\" width=\"".$largeur."\" class=\"bordure\"><tr><td>\n";
 172    echo "<table cellspacing=\"1\" cellpadding=\"5\" border=\"".$texte[4]."\" align=\"center\" width=\"100%\">\n";
 173    echo "<tr><td nowrap class=\"tbl1\"><p class=\"titre\"><b>".$tblti."</b></p></td></tr>\n";
 174    echo "<tr><td class=\"tbl2\" onMouseOver=\"this.className = 'tbl2over';\" onMouseOut=\"this.className = 'tbl2';\">\n\n";
 175  }
 176  
 177  function htable1($tblti) {
 178    global $texte;
 179    echo "<table cellspacing=\"0\" cellpadding=\"1\" border=\"0\" align=\"center\" width=\"100%\" class=\"bordure\"><tr><td>\n";
 180    echo "<table cellspacing=\"1\" cellpadding=\"5\" border=\"".$texte[4]."\" align=\"center\" width=\"100%\">\n";
 181    echo "<tr><td nowrap class=\"tbl1\"><p class=\"titre\" align=\"center\"><b>".$tblti."</b></p></td></tr>\n";
 182    echo "<tr><td class=\"tbl2\" onMouseOver=\"this.className = 'tbl2over';\" onMouseOut=\"this.className = 'tbl2';\">\n\n";
 183  }
 184  
 185  function btable() {
 186    echo "\n</td></tr></table>\n";
 187    echo "\n</td></tr></table>\n";
 188  }
 189  
 190  function souriez($chaine) {
 191    global $souriez;
 192    $traite = str_replace($souriez[0][0], "<img src=\\\"".$souriez[0][1]."\\\" border=\\\"0\\\">", $chaine);
 193    $traite = str_replace($souriez[1][0], "<img src=\\\"".$souriez[1][1]."\\\" border=\\\"0\\\">", $traite);
 194    $traite = str_replace($souriez[2][0], "<img src=\\\"".$souriez[2][1]."\\\" border=\\\"0\\\">", $traite);
 195    $traite = str_replace($souriez[3][0], "<img src=\\\"".$souriez[3][1]."\\\" border=\\\"0\\\">", $traite);
 196    $traite = str_replace($souriez[4][0], "<img src=\\\"".$souriez[4][1]."\\\" border=\\\"0\\\">", $traite);
 197    $traite = str_replace($souriez[5][0], "<img src=\\\"".$souriez[5][1]."\\\" border=\\\"0\\\">", $traite);
 198    $traite = str_replace($souriez[6][0], "<img src=\\\"".$souriez[6][1]."\\\" border=\\\"0\\\">", $traite);
 199    $traite = str_replace($souriez[7][0], "<img src=\\\"".$souriez[7][1]."\\\" border=\\\"0\\\">", $traite);
 200    $traite = str_replace($souriez[8][0], "<img src=\\\"".$souriez[8][1]."\\\" border=\\\"0\\\">", $traite);
 201    $traite = str_replace($souriez[9][0], "<img src=\\\"".$souriez[9][1]."\\\" border=\\\"0\\\">", $traite);
 202    $traite = str_replace($souriez[10][0], "<img src=\\\"".$souriez[10][1]."\\\" border=\\\"0\\\">", $traite);
 203    return $traite;
 204  }
 205  
 206  function DrawSmileys($num) {
 207    global $souriez;
 208    echo "<p align=\"center\">\n";
 209    for ($i = 0; $i < count($souriez); $i++) {
 210      echo "<img src=\"".CHEMIN.$souriez[$i][1]."\" class=\"clsCursor\" border=\"0\" alt=\"".$souriez[$i][0]."\" onClick=\"JavaScript:AddSmiley".$num."('".$souriez[$i][0]."')\">&nbsp;\n";
 211    }
 212    echo "</p>";
 213  }
 214  
 215  function AfficheCompteur($chemino, $hits, $grow = 1) {
 216    $spot = "";
 217    for ($lecon = 0; $lecon < $grow - strlen($hits); $lecon++ ) {
 218      $spot .= "<IMG SRC=\"".$chemino."cnt0.gif\" BORDER=0>";
 219    }
 220    for ($lecon = 0; $lecon < strlen($hits); $lecon++) {
 221      $cols = substr($hits, $lecon, 1);
 222      $spot .= "<IMG SRC=\"".$chemino."cnt".$cols.".gif\" BORDER=0>";
 223    }
 224    echo $spot;
 225  }
 226  
 227  function DejaVote($file_ip, $d_time = 0) {
 228    global $REMOTE_ADDR, $userprefs;
 229    $remoteadr = $REMOTE_ADDR;
 230    $nbr_connect = 0;
 231    $var_bool = false;
 232    $user_bool = false;
 233    $subdata = array();
 234    $var_ip = array();
 235    $k = 0;
 236    if ($d_time == 0) {
 237      $d_time = HIT_TIME;
 238    }
 239    $subdata = ReadDBFields($file_ip);
 240    $now_time = time();
 241    for ($i = 0; $i < count($subdata); $i++) {
 242      list($jour, $mois, $annee) = explode("/", substr($subdata[$i][1], 0, 10));
 243      list($heure, $minute, $seconde) = explode(":", substr($subdata[$i][1], 10, 18));
 244      if ($now_time < mktime($heure, $minute, $seconde, $mois, $jour, $annee) + $d_time) {
 245        $nbr_connect++;
 246        $var_ip[$k][0] = $subdata[$i][0];
 247        if ($remoteadr == $subdata[$i][0]) {
 248          $var_bool = true;
 249        }
 250        $var_ip[$k][1] = $subdata[$i][1];
 251        if ($userprefs[5] != "") {
 252          $uprefname = $userprefs[1];
 253        }
 254        else {
 255          $uprefname = "";
 256        }
 257        if ($remoteadr == $subdata[$i][0] && $uprefname != $subdata[$i][2]) {
 258          $user_bool = true;
 259          $var_ip[$k][2] = $uprefname;
 260        }
 261        else {
 262          $var_ip[$k][2] = $subdata[$i][2];
 263        }
 264        $k++;
 265      }
 266    }
 267    if (!$var_bool) {
 268      $var_ip[$k][0] = $remoteadr;
 269      $var_ip[$k][1] = date("d/m/Y H:i:s");
 270      $var_ip[$k][2] = $userprefs[1];
 271      WriteDBFields($file_ip,$var_ip);
 272      $nbr_connect++;
 273    }
 274    elseif ($user_bool) {
 275      WriteDBFields($file_ip,$var_ip);
 276    }
 277    $retcmpt[0] = $var_bool;
 278    $retcmpt[1] = $nbr_connect;
 279    return $retcmpt;
 280  }
 281  
 282  function CompteVisites($file_ip, $file_counter) {
 283    $subdata = DejaVote($file_ip);
 284    $nbr_visit = ReadCounter($file_counter);    
 285    if (!$subdata[0]) {
 286      $nbr_visit++;
 287      WriteCounter($file_counter,$nbr_visit);
 288    }
 289    $retcmpt[0] = $nbr_visit;
 290    $retcmpt[1] = $subdata[1];
 291    return $retcmpt;
 292  }
 293  
 294  function IsImage($extn) {
 295    $imgok = 0;
 296    $extn = strtolower($extn);
 297    if ($extn == "gif" || $extn == "jpg" || $extn == "jpeg" || $extn == "png" || $extn == "bmp") {
 298      $imgok = 1;
 299    }
 300    return $imgok;
 301  }
 302  
 303  function ExtImage($extn){
 304    $extn = strtolower($extn);
 305    if ($extn == "php"){ return "php"; }
 306    if ($extn == "php3"){ return "php"; }
 307    if ($extn == "phtml"){ return "php"; }
 308    if ($extn == "htm"){ return "html"; }
 309    if ($extn == "html"){ return "html"; }
 310    if ($extn == "js"){ return "js"; }
 311    if ($extn == "css"){ return "css"; }
 312  
 313    if ($extn == "gif"){ return "gif"; }
 314    if ($extn == "jpg"){ return "jpg"; }
 315    if ($extn == "jpeg"){ return "jpg"; }
 316    if ($extn == "png"){ return "png"; }
 317    if ($extn == "bmp"){ return "bmp"; }
 318  
 319    if ($extn == "cab"){ return "zip"; }
 320    if ($extn == "zip"){ return "zip"; }
 321    if ($extn == "ace"){ return "zip"; }
 322    if ($extn == "tgz"){ return "zip"; }
 323    if ($extn == "gz"){ return "zip"; }
 324    if ($extn == "tar"){ return "zip"; }
 325    if ($extn == "rar"){ return "zip"; }
 326  
 327    if ($extn == "wav"){ return "wav"; }
 328    if ($extn == "mid"){ return "mid"; }
 329    if ($extn == "mp3"){ return "mp3"; }
 330  
 331    if ($extn == "exe"){ return "exe"; }
 332    if ($extn == "bat"){ return "bat"; }
 333    if ($extn == "com"){ return "com"; }
 334    if ($extn == "pif"){ return "com"; }
 335  
 336    if ($extn == "mov"){ return "wav"; }
 337    if ($extn == "avi"){ return "wav"; }
 338    if ($extn == "mpg"){ return "wav"; }
 339    if ($extn == "mpeg"){ return "wav"; }
 340    if ($extn == "swf"){ return "swf"; }
 341  
 342    if ($extn == "txt"){ return "txt"; }
 343    if ($extn == "nfo"){ return "txt"; }
 344    return "inconnu";
 345  }
 346  
 347  function PathToImage($pathin) {
 348    $pathout = str_replace("img/",CHEMIN."img/",$pathin);
 349    $pathout = str_replace("inc/".CHEMIN."img/",CHEMIN."inc/img/",$pathout);
 350    return $pathout;
 351  }
 352  
 353  function SplitText($textin,$textlen) {
 354    $textout = array();
 355    $out1 = $textin;
 356    $out2 = "";
 357    if (strlen($textin) > $textlen) {
 358      $tempout = strrpos(substr($textin,0,$textlen)," ");
 359      if ($tempout < 1) {
 360        $tempout = strpos($textin," ");
 361      }
 362      if ($tempout > 0) {
 363        $out1 = substr($textin,0,$tempout);
 364        $out2 = substr($textin,$tempout+1,strlen($textin)-$tempout);
 365      }
 366    }
 367    $textout[0] = $out1;
 368    $textout[1] = $out2;
 369    return $textout;
 370  }
 371  
 372  function FormatDateStamp($datein) {
 373    global $site;
 374    if ($site[19] == "E1") {
 375      $formatout = "d/m/Y";
 376    }
 377    elseif ($site[19] == "E2") {
 378      $formatout = "d.m.Y";
 379    }
 380    elseif ($site[19] == "U1") {
 381      $formatout = "m/d/Y";
 382    }
 383    elseif ($site[19] == "U2") {
 384      $formatout = "m.d.Y";
 385    }
 386    elseif ($site[19] == "C1") {
 387      $formatout = "Y/m/d";
 388    }
 389    else {  // $site[19] == "C2"
 390      $formatout = "Y.m.d";
 391    }
 392    $formatout .= " ".$site[23]." ";
 393    if ($site[22] == "H1") {
 394      $formatout .= "H:i";
 395    }
 396    elseif ($site[22] == "H2") {
 397      $formatout .= "H\hi";
 398    }
 399    else {  // $site[22] == "H3"
 400      $formatout .= "h:i A";
 401    }
 402    $dateout = date($formatout,$datein);
 403    return $dateout;
 404  }
 405  
 406  function FormatDate($datein) {
 407    global $site;
 408      $jour = substr($datein,6,2);
 409      $mois = substr($datein,4,2);
 410      $annee = substr($datein,0,4);
 411      $heure = substr($datein,8,2);
 412      $minute = substr($datein,10,2);
 413      if ($site[19] == "E1") {
 414        $dateout = $jour."/".$mois."/".$annee;
 415      }
 416      elseif ($site[19] == "E2") {
 417        $dateout = $jour.".".$mois.".".$annee;
 418      }
 419      elseif ($site[19] == "U1") {
 420        $dateout = $mois."/".$jour."/".$annee;
 421      }
 422      elseif ($site[19] == "U2") {
 423        $dateout = $mois.".".$jour.".".$annee;
 424      }
 425      elseif ($site[19] == "C1") {
 426        $dateout = $annee."/".$mois."/".$jour;
 427      }
 428      else {  // $site[19] == "C2"
 429        $dateout = $annee.".".$mois.".".$jour;
 430      }
 431      $dateout .= " ".$site[23]." ";
 432      if ($site[22] == "H1") {
 433        $dateout .= $heure.":".$minute;
 434      }
 435      elseif ($site[22] == "H2") {
 436        $dateout .= $heure."h".$minute;
 437      }
 438      else {  // $site[22] == "H3"
 439        if ($heure < 12) {
 440          $dateout .= $heure.":".$minute." AM";
 441        }
 442        else {
 443          $dateout .= ($heure-12).":".$minute." PM";
 444        }
 445      }
 446    return $dateout;
 447  }
 448  
 449  function GetCurrentDateTime() {
 450    $dateout = date("YmdHi");
 451    return $dateout;
 452  }
 453  
 454  function FileSizeInKb($fic) {
 455    $taille=@filesize($fic);
 456    if ($taille !== false) {
 457      $taille = round($taille/1024);
 458    }
 459    return $taille;
 460  }
 461  
 462  function FileDBExist($fic) {
 463    $filetest = is_file($fic);
 464    return $filetest;
 465  }
 466  
 467  function DestroyDBFile($fic) {
 468    @chmod($fic,0755);
 469    @chmod($fic,0777);
 470    @unlink($fic);
 471  }
 472  
 473  function ReadCounter($fic) {
 474    $DataDB = 0;
 475    if (FileDBExist($fic)) {
 476      $fhandle = fopen($fic, "r");
 477      $DataDB = trim(fgets($fhandle, filesize($fic)));
 478      fclose($fhandle);
 479    }
 480    return $DataDB;
 481  }
 482  
 483  function WriteCounter($fic,$DataDB) {
 484    $fhandle = fopen($fic, "w");
 485    fputs($fhandle, $DataDB."\n");
 486    fclose($fhandle);
 487  }
 488  
 489  function ReadFullDB($fic) {
 490    $DataDB = Array();
 491    if (FileDBExist($fic)) {
 492      $DataDB = implode("", file($fic));
 493    }
 494    return $DataDB;
 495  }
 496        
 497  function WriteFullDB($fic,$DataDB) {
 498    $fhandle = fopen($fic, "w");
 499    fputs($fhandle, $DataDB);
 500    fclose($fhandle);
 501  }
 502  
 503  function AppendFullDB($fic,$DataDB) {
 504    $fhandle = fopen($fic, "a");
 505    fputs($fhandle, $DataDB);
 506    fclose($fhandle);
 507  }
 508  
 509  function ReadDBFields($fic) {
 510    $DataDB = Array();
 511    if (FileDBExist($fic)) {
 512      $DataDB = file($fic);
 513      for ($i = 0; $i < count($DataDB); $i++) {
 514        $Fields[$i] = explode(CONNECTOR,trim($DataDB[$i]));
 515      }
 516    }
 517    return $Fields;
 518  }
 519  
 520  function WriteDBFields($fic,$Fields) {
 521    $fhandle = fopen($fic, "w");
 522    $DataDB = "";
 523    for ($i = 0; $i < count($Fields); $i++) {
 524      for ($j = 0 ; $j < (count($Fields[$i])-1); $j++) {
 525        $DataDB .= trim($Fields[$i][$j]).CONNECTOR;
 526      }
 527      $DataDB .= trim($Fields[$i][count($Fields[$i])-1])."\n";
 528    }
 529    fputs($fhandle, $DataDB);
 530    fclose($fhandle);
 531  }
 532  
 533  function AppendDBFields($fic,$Fields) {
 534    $fhandle = fopen($fic, "a");
 535    $DataDB = "";
 536    for ($i = 0 ; $i < (count($Fields)-1); $i++) {
 537      $DataDB .= trim($Fields[$i]).CONNECTOR;
 538    }
 539    $DataDB .= trim($Fields[count($Fields)-1])."\n";
 540    fputs($fhandle, $DataDB);
 541    fclose($fhandle);
 542  }
 543  
 544  function SelectDBFieldsByID($Fields,$id) {
 545    $DataDB = array();
 546    $k = 0;
 547    for ($i = 0; $i < count($Fields); $i++) {
 548      if ($Fields[$i][1] == $id) {
 549        for ($j = 0 ; $j < count($Fields[$i]); $j++) {
 550          $DataDB[$k][$j] = $Fields[$i][$j];
 551        }
 552        $k++;
 553      }
 554    }
 555    return $DataDB;
 556  }
 557  
 558  function SelectDBFieldsByType($Fields,$type) {
 559    $DataDB = array();
 560    $k = 0;
 561    for ($i = 0; $i < count($Fields); $i++) {
 562      if ($Fields[$i][0] == $type) {
 563        for ($j = 0 ; $j < count($Fields[$i]); $j++) {
 564          $DataDB[$k][$j] = $Fields[$i][$j];
 565        }
 566        $k++;
 567      }
 568    }
 569    return $DataDB;
 570  }
 571  
 572  function SelectDBFieldsByNotStatus($Fields,$status) {
 573    $DataDB = array();
 574    $k = 0;
 575    for ($i = 0; $i < count($Fields); $i++) {
 576      if ($Fields[$i][2] != $status) {
 577        for ($j = 0 ; $j < count($Fields[$i]); $j++) {
 578          $DataDB[$k][$j] = $Fields[$i][$j];
 579        }
 580      $k++;
 581      }
 582    }
 583    return $DataDB;
 584  }
 585  
 586  function SelectDBFieldsByStatus($Fields,$status) {
 587    $DataDB = array();
 588    $k = 0;
 589    for ($i = 0; $i < count($Fields); $i++) {
 590      if ($Fields[$i][2] == $status) {
 591        for ($j = 0 ; $j < count($Fields[$i]); $j++) {
 592          $DataDB[$k][$j] = $Fields[$i][$j];
 593        }
 594        $k++;
 595      }
 596    }
 597    return $DataDB;
 598  }
 599  
 600  function SelectDBFields($type,$status,$id) {
 601    $DataDB = array();
 602    if (!empty($status) && !empty($id)) {
 603      $DataDB = SelectDBFieldsByID(SelectDBFieldsByStatus(SelectDBFieldsByType(ReadDBFields(DOCID),$type),$status),$id);
 604    }
 605    elseif (!empty($status)) {
 606      $DataDB = SelectDBFieldsByStatus(SelectDBFieldsByType(ReadDBFields(DOCID),$type),$status);
 607    }
 608    elseif (!empty($id)) {
 609      $DataDB = SelectDBFieldsByID(SelectDBFieldsByType(ReadDBFields(DOCID),$type),$id);
 610    }
 611    else {
 612      $DataDB = SelectDBFieldsByType(ReadDBFields(DOCID),$type);
 613    }
 614    return $DataDB;
 615  }
 616  
 617  function RemoveQuote($chaine) {
 618    $traite = str_replace("'", "", $chaine);
 619    return $traite;
 620  }
 621  
 622  function RemoveConnector($chaine) {
 623    $traite = str_replace(CONNECTOR, "", $chaine);
 624    return $traite;
 625  }
 626  
 627  function RemoveBR($chaine) {
 628    $traite = str_replace("<br />", "\n", $chaine);
 629    $traite = str_replace("<br />", "\n", $traite);
 630    $traite = str_replace("<br />", "\n", $traite);
 631    $traite = str_replace("<br />", "\n", $traite);
 632    return $traite;
 633  }
 634      
 635  function PutBR($chaine) {
 636    $traite = str_replace(chr(10),"<br />",$chaine);
 637    $traite = str_replace(chr(13),"",$traite);
 638    return $traite;
 639  }
 640  
 641  function RemoveHR($chaine) {
 642    $traite = str_replace("</p><hr /><p>", "<hr />", $chaine);
 643    return $traite;
 644  }
 645  
 646  function PutHR($chaine) {
 647    $traite = str_replace("<hr />", "</p><hr /><p>", $chaine);
 648    $traite = str_replace("<hr />", "</p><hr /><p>", $traite);
 649    $traite = str_replace("<hr />", "</p><hr /><p>", $traite);
 650    $traite = str_replace("<hr />", "</p><hr /><p>", $traite);
 651    $traite = str_replace("$","$&shy;",$traite);
 652    return $traite;
 653  }
 654  
 655  function ReadDocCounter($id) {
 656    $DataDB = ReadCounter(DBBASE.$id.DBEXT);
 657    return $DataDB;
 658  }
 659  
 660  function WriteDocCounter($id,$DataDB) {
 661    WriteCounter(DBBASE.$id.DBEXT,$DataDB);
 662  }
 663  
 664  function UpdateDocCounter($id) {
 665    $DataDB = ReadDocCounter($id);
 666    $vote = DejaVote(DBIPBASE.$id.DBEXT,300);
 667    if ($vote[0] == false) {
 668      $DataDB++;
 669      WriteDocCounter($id,$DataDB);
 670    }
 671    return $DataDB;
 672  }
 673  
 674  
 675  function ReadDoc($id) {
 676    global $type,$fileid,$status,$creadate,$moddate,$author,$email,
 677           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 678    if (FileDBExist(DBBASE.$id.INCEXT)) {
 679      include(DBBASE.$id.INCEXT);
 680    }
 681  }
 682  
 683  function WriteDoc() {
 684    global $type,$fileid,$status,$creadate,$moddate,$author,$email,
 685           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 686    $rec = "<?
 687  \$type = \"$type\";
 688  \$fileid = \"$fileid\";
 689  \$status = \"$status\";
 690  \$creadate = \"$creadate\";
 691  \$moddate = \"$moddate\";
 692  \$author = stripslashes(\"$author\");
 693  \$email = stripslashes(\"$email\");
 694  \$fielda1 = stripslashes(\"$fielda1\");
 695  \$fielda2 = stripslashes(\"$fielda2\");
 696  \$fieldb1 = stripslashes(\"$fieldb1\");
 697  \$fieldb2 = stripslashes(\"$fieldb2\");
 698  \$fieldc1 = stripslashes(\"$fieldc1\");
 699  \$fieldc2 = stripslashes(\"$fieldc2\");
 700  \$fieldd1 = stripslashes(\"$fieldd1\");
 701  \$fieldd2 = stripslashes(\"$fieldd2\");
 702  ?>"; ?> <?
 703    WriteFullDB(DBBASE.$fileid.INCEXT,$rec);
 704  }
 705  
 706  function UpdateDBnews() {
 707    global $lang,$lng,$site,$serviz,TYP_NEWS,
 708           $type,$fileid,$status,$creadate,$moddate,$author,$email,
 709           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 710    if ($serviz[16] == "on") {
 711      $dbwork1 = SelectDBFields(TYP_NEWS,"a","");
 712      if ($lang[1] != "") {
 713        include(CHEMIN."inc/lang/".$lang[1]."-web".INCEXT);
 714        $par2 = $web6;
 715        $le2 = $web7;
 716      }
 717      include(CHEMIN."inc/lang/".$lng."-web".INCEXT);
 718      $par1 = $web6;
 719      $le1 = $web7;
 720      $sito = $site[3];
 721      if ($sito[strlen($sito)] != "/") {
 722        $sito .= "/";
 723      }
 724      for ($i = 0; $i < count($dbwork1); $i++) {
 725        ReadDoc($dbwork1[$i][1]);
 726        $dbwork2[$i][0] = $fieldb1." - ".$par1." ".$author." ".$le1." ".FormatDate($creadate);
 727        $dbwork2[$i][1] = $fieldc1;
 728        $dbwork2[$i][2] = $sito."news.php?lng=".$lng."&id=".$fileid;
 729        if ($lang[1] != "") {
 730          $dbwork2[$i][3] = $fieldb2." - ".$par2." ".$author." ".$le2." ".FormatDate($creadate);
 731          $dbwork2[$i][4] = $fieldc2;
 732          $dbwork2[$i][5] = $sito."news.php?lng=".$lang[1]."&id=".$fileid;
 733        }
 734        else {
 735          $dbwork2[$i][3] = "";
 736          $dbwork2[$i][4] = "";
 737          $dbwork2[$i][5] = "";
 738        }
 739      }
 740      WriteDBFields(DBNEWS,$dbwork2);
 741    }
 742    else {
 743      WriteFullDB(DBNEWS,"\n");
 744    }
 745  }
 746  
 747  function UpdateDBdtb($dtb) {
 748    global $type,$fileid,$status,$creadate,$moddate,$author,$email,
 749           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 750    $db = SelectDBFields($dtb,"a","");
 751    $dba = array();
 752    $j = 0;
 753    for ($i = 0; $i < count($db); $i++) {
 754      ReadDoc($db[$i][1]);
 755      if (!($dtb == TYP_ART && trim($fielda1).trim($fielda2) == "")) {
 756        $dba[$j][0] = RemoveConnector($fielda1);
 757        $dba[$j][1] = RemoveConnector($fielda2);
 758        $dba[$j][2] = RemoveConnector($fieldb1);
 759        $dba[$j][3] = RemoveConnector($fieldb2);
 760        $dba[$j][4] = $fileid;
 761        if ($dtb == TYP_ART) {
 762          $dba[$j][5] = RemoveConnector($fieldd1);
 763        }
 764        $j++;
 765      }
 766    }
 767    WriteDBFields(CHEMIN.DATAREP.$dtb.DBEXT,$dba);
 768  }
 769  
 770  function UpdateDBreact($action,$id) {
 771    global $type,$fileid,$status,$creadate,$moddate,$author,$email,
 772           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 773    $db = array();
 774    if ($action == "add") {
 775      ReadDoc($id);
 776      $db[0] = $fileid;
 777      $db[1] = $fielda2;
 778      AppendDBFields(DBREACT,$db);
 779    }
 780    else {
 781      $db = SelectDBFields(TYP_REACT,"a","");
 782      sort($db);
 783      $dbf = array();
 784      for ($i = 0; $i < count($db); $i++) {
 785        ReadDoc($db[$i][1]);
 786        $dbf[$i][0] = $fileid;
 787        $dbf[$i][1] = $fielda2;
 788      }
 789      WriteDBFields(DBREACT,$dbf);
 790    }
 791  }
 792  
 793  function UpdateDBforum($action,$id) {
 794    global $site,$type,$fileid,$status,$creadate,$moddate,$author,$email,
 795           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 796    $db = array();
 797    if ($action == "add") {
 798      ReadDoc($id);
 799      $db[0] = $creadate;                               // date @ heure du thread

 800      $db[1] = $fielda1;                                // numéro de thread

 801      $db[2] = $fielda2;                                // numéro de réponse ou "0" si nouveau thread

 802      $db[3] = $fileid;                                 // id du thread

 803      $db[4] = RemoveConnector($author);                // auteur

 804      $db[5] = RemoveConnector($email);                 // e-mail auteur

 805      $db[6] = RemoveConnector($fieldb1);               // titre

 806      $db[7] = $fieldd1;                                // show or hide e-mail auteur

 807      $db[8] = $fieldb2;                                // ID catégorie thread

 808      AppendDBFields(DBTHREAD,$db);
 809    }
 810    else {
 811      $db = SelectDBFields(TYP_FORUM,"a","");
 812      sort($db);
 813      $dbf = array();
 814      for ($i = 0; $i < count($db); $i++) {
 815        ReadDoc($db[$i][1]);
 816        $dbf[$i][0] = $creadate;                        // date @ heure du thread

 817        $dbf[$i][1] = $fielda1;                         // numéro de thread

 818        $dbf[$i][2] = $fielda2;                         // numéro de réponse ou "0" si nouveau thread

 819        $dbf[$i][3] = $fileid;                          // id du thread

 820        $dbf[$i][4] = RemoveConnector($author);         // auteur

 821        $dbf[$i][5] = RemoveConnector($email);          // e-mail auteur

 822        $dbf[$i][6] = RemoveConnector($fieldb1);        // titre

 823        $dbf[$i][7] = $fieldd1;                         // show or hide e-mail auteur

 824        $dbf[$i][8] = $fieldb2;                         // ID catégorie thread

 825      }
 826      @sort($dbf,SORT_REGULAR);
 827      WriteDBFields(DBTHREAD,$dbf);
 828    }
 829    $db = array();
 830    $db = ReadDBFields(DBTHREAD);
 831    $dbf = array();
 832    $j = 0;
 833    for ($i = 0; $i < count($db); $i++) {
 834      if ($db[$i][2] == "0") {
 835        $dbf[$j][0] = $db[$i][0];            // date @ heure de la dernière réponse

 836        $dbf[$j][1] = $db[$i][1];            // numéro de thread

 837        $dbf[$j][2] = $db[$i][3];            // id de début du thread

 838        $dbf[$j][3] = $db[$i][4];            // auteur

 839        $dbf[$j][4] = $db[$i][5];            // e-mail auteur

 840        $dbf[$j][5] = $db[$i][6];            // titre

 841        $dbf[$j][6] = $db[$i][0];            // date @ heure de création du thread

 842        $dbf[$j][7] = 0;                     // nombre de réponses

 843        $dbf[$j][8] = "";                    // auteur de la dernière réponse

 844        $dbf[$j][9] = "";                    // e-mail auteur de la dernière réponse

 845        $dbf[$j][10] = $db[$i][7];           // show or hide e-mail auteur

 846        $dbf[$j][11] = "";                   // show or hide e-mail auteur de la dernière réponse

 847        $dbf[$j][12] = $db[$i][8];           // ID catégorie thread

 848        for ($k = $i+1; $k < count($db); $k++) {
 849          if ($db[$k][1] == $dbf[$j][1]) {
 850            $dbf[$j][0] = $db[$k][0];
 851            $dbf[$j][7] = $dbf[$j][7]+1;
 852            $dbf[$j][8] = $db[$k][4];
 853            $dbf[$j][9] = $db[$k][5];
 854            $dbf[$j][11] = $db[$k][7];
 855          }
 856        }
 857        $j++;
 858      }
 859    }
 860    @rsort($dbf,SORT_REGULAR);
 861    WriteDBFields(DBFORUM,$dbf);
 862  }
 863  
 864  function ActionOnFields($action,$data) {
 865    global $site,$type,$fileid,$status,$creadate,$moddate,$author,$email,
 866           $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2;
 867    if ($action == "del") {
 868      $id = $data[1];
 869      $db = ReadDBFields(DOCID);
 870      for ($i = 0; $i < count($db); $i++) {
 871        if ($db[$i][1] == $id) {
 872          $db[$i][2] = "d";
 873        }
 874      }
 875      WriteDBFields(DOCID,$db);
 876      ReadDoc($id);
 877      $status = "d";
 878      $author = addslashes($author);
 879      $email = addslashes($email);
 880      $fielda1 = addslashes($fielda1);
 881      $fielda2 = addslashes($fielda2);
 882      $fieldb1 = addslashes($fieldb1);
 883      $fieldb2 = addslashes($fieldb2);
 884      $fieldc1 = addslashes($fieldc1);
 885      $fieldc2 = addslashes($fieldc2);
 886      $fieldd1 = addslashes($fieldd1);
 887      $fieldd2 = addslashes($fieldd2);
 888      WriteDoc();
 889    }
 890    elseif ($action == "act") {
 891      $id = $data[1];
 892      $db = ReadDBFields(DOCID);
 893      for ($i = 0; $i < count($db); $i++) {
 894        if ($db[$i][1] == $id) {
 895          $db[$i][2] = $data[2];
 896        }
 897      }
 898      WriteDBFields(DOCID,$db);
 899      ReadDoc($id);
 900      $status = $data[2];
 901      $author = addslashes($author);
 902      $email = addslashes($email);
 903      $fielda1 = addslashes($fielda1);
 904      $fielda2 = addslashes($fielda2);
 905      $fieldb1 = addslashes($fieldb1);
 906      $fieldb2 = addslashes($fieldb2);
 907      $fieldc1 = addslashes($fieldc1);
 908      $fieldc2 = addslashes($fieldc2);
 909      $fieldd1 = addslashes($fieldd1);
 910      $fieldd2 = addslashes($fieldd2);
 911      WriteDoc();
 912    }
 913    elseif ($action == "add") {
 914      $id = ReadCounter(NEXTID);
 915      $id = $id+1;
 916      WriteCounter(NEXTID,$id);
 917      $db = array();
 918      $db[0] = $data[0];
 919      $db[1] = $id;
 920      $db[2] = $data[2];
 921      AppendDBFields(DOCID,$db);
 922      $type = $data[0];
 923      $fileid = $id;
 924      $status = $data[2];
 925      $creadate = GetCurrentDateTime();
 926      $moddate = $creadate;
 927      $author = addslashes(stripslashes($data[5]));
 928      $email = addslashes(stripslashes($data[6]));
 929      $fielda1 = addslashes(stripslashes($data[7]));
 930      $fielda2 = addslashes(stripslashes($data[8]));
 931      $fieldb1 = addslashes(stripslashes($data[9]));
 932      $fieldb2 = addslashes(stripslashes($data[10]));
 933      $fieldc1 = addslashes(stripslashes(souriez(PutHR(PutBR($data[11])))));
 934      $fieldc2 = addslashes(stripslashes(souriez(PutHR(PutBR($data[12])))));
 935      $fieldd1 = addslashes(stripslashes($data[13]));
 936      $fieldd2 = addslashes(stripslashes($data[14]));
 937      WriteDoc();
 938    }
 939    elseif ($action == "mod") {
 940      $id = $data[1];
 941      ReadDoc($id);
 942      $moddate = GetCurrentDateTime();
 943      $author = addslashes(stripslashes($data[5]));
 944      $email = addslashes(stripslashes($data[6]));
 945      $fielda1 = addslashes(stripslashes($data[7]));
 946      $fielda2 = addslashes(stripslashes($data[8]));
 947      $fieldb1 = addslashes(stripslashes($data[9]));
 948      $fieldb2 = addslashes(stripslashes($data[10]));
 949      $fieldc1 = addslashes(stripslashes(souriez(PutHR(PutBR($data[11])))));
 950      $fieldc2 = addslashes(stripslashes(souriez(PutHR(PutBR($data[12])))));
 951      $fieldd1 = addslashes(stripslashes($data[13]));
 952      $fieldd2 = addslashes(stripslashes($data[14]));
 953      WriteDoc();
 954    }
 955    if ($data[0] == TYP_ART || $data[0] == TYP_LINKS || $data[0] == TYP_DNLOAD || $data[0] == TYP_PHOTO || $data[0] == TYP_FAQ) {
 956      UpdateDBdtb($data[0]);
 957    }
 958    elseif ($data[0] == TYP_FORUM) {
 959      UpdateDBforum($action,$id);
 960    }
 961    elseif ($data[0] == TYP_NEWS) {
 962      UpdateDBnews();
 963    }
 964    elseif ($data[0] == TYP_REACT) {
 965      UpdateDBreact($action,$id);
 966    }
 967  }
 968  
 969  function InitDBlog($typ) {
 970    $db = array();
 971    $db[0][0] = 0;
 972    for ($i = 0; $i < 12; $i++) {$db[1][$i] = 0;}
 973    for ($i = 0; $i < 2; $i++) {$db[2][$i] = 0;}
 974    for ($i = 0; $i < 9; $i++) {$db[3][$i] = 0;}
 975    for ($i = 0; $i < 10; $i++) {$db[4][$i] = 0;}
 976    for ($i = 0; $i < $typ; $i++) {$db[5][$i] = 0;}
 977    for ($i = 0; $i < $typ; $i++) {$db[6][$i] = 0;}
 978    $db[7][0] = 1;
 979    return $db;
 980  }
 981  
 982  function eMailTo($eSubject,$eMessage,$eTo) {
 983    global $supervision,$user;
 984    $eFrom = trim($user[1]);
 985    if ($eTo == "") {
 986      $eTo = trim($user[1]);
 987    }
 988    if ($supervision[5] == "standard") {
 989      @mail($eTo,$eSubject,$eMessage,"From: ".$eFrom,"-f".$eFrom);
 990    }
 991    else {
 992      include (CHEMIN.INCREP."mail/".$supervision[5].INCEXT);
 993    }
 994  }
 995  
 996  function BreakEMail($eminput) {
 997    $eminput = trim($eminput);
 998    $em1 = strpos($eminput,"@");
 999    $em2 = strrpos($eminput,".");
1000    $emoutput[0] = substr($eminput,0,$em1);
1001    $emoutput[1] = substr($eminput,$em1+1,$em2-$em1-1);
1002    $emoutput[2] = substr($eminput,$em2+1);
1003    return $emoutput;
1004  }
1005  
1006  function StartTimer() {
1007   global $starttime;
1008   $mtime = microtime();
1009   $mtime = explode(' ', $mtime);
1010   $mtime = $mtime[1] + $mtime[0];
1011   $starttime = $mtime;
1012  }
1013  
1014  function StopTimer() {
1015    global $starttime;
1016    $mtime = microtime();
1017    $mtime = explode(' ', $mtime);
1018    $mtime = $mtime[1] + $mtime[0];
1019    $stoptime = round (($mtime - $starttime), 2);
1020    return $stoptime;
1021  }
1022  
1023  function MakeSeed() {
1024    list($usec, $sec) = explode(' ', microtime());
1025    return (float) $sec + ((float) $usec * 100000);
1026  }
1027  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]