Guest User

Untitled

a guest
Nov 20th, 2017
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 177.47 KB | None | 0 0
  1. <?php
  2. /*******************************************************************************
  3.  *   Functions
  4.  *******************************************************************************
  5.  *   GuppY PHP Script - version 5.0
  6.  *   CeCILL Copyright (C) 2004-2014 by Laurent Duveau
  7.  *   Initiated by Laurent Duveau and Nicolas Alves
  8.  *   Web site = http://www.freeguppy.org/
  9.  *   e-mail   = guppy@freeguppy.org
  10.  *   V5 developed by Lud Bienaimé
  11.  *      with the participation of Jean-Michel Misrachi and the GuppY Team
  12.  *******************************************************************************
  13.  *   Version History :
  14.  * v5.0.0 (February 15, 2014)    : initial release.
  15.  * v5.0.1 (March 08, 2014)       : correction calculation of maximum id in IncrNextID()
  16.  *                               : adding functions SetChmod() ans MakeDir()
  17.  * v5.0.2 (March 25, 2014)       : correction image display for new document
  18.  *                               : corrected writing in robots.txt for sitemaps
  19.  *                               : corrected import docs with &#36;
  20.  * v5.0.3 (April 15, 2014)       : corrected sitemaps url
  21.  *                               : corrected update index for confirmation
  22.  * v5.0.4 (April 30, 2014)       : corrected list of adressees in eMailHtmlTo()
  23.  *                               : function corrected for duplicates
  24.  * v5.0.5 (June 07, 2014)        : add plugins rules for url_rw
  25.  * v5.0.7 (August 21, 2014)      : corrected displayErrorMsg() function
  26.  * v5.0.8 (October 02, 2014)     : corrected email function
  27.  *                               : changed the calculation of the number of characters
  28.  *                                 in the CutLongWord() function (thanks Ludo)
  29.  * v5.0.9 (November 28, 2014)    : add types of mail standard_3 and standard_4
  30.  *                               : corrected UpdateDBforum() in edit mode of thread
  31.  * v5.00.11 (March 02, 2015)     : improve displayQuickConfig() function
  32.  *                               : add hyphen in the nickname
  33.  * v5.01.00 (June 12, 2015)      : add ckeckbox for hostings behind a cache (thanks jcp)
  34.  *                               : corrected quick admin access (thanks Icare)
  35.  * v5.01.01 (September 02, 2015) : add parameter $ancre in GetNavbar()
  36.  * v5.01.03 (June 07, 2016)      : corrected $eFrom in eMailHtmlTo() function
  37.  *                               : replace css properties by class rules
  38.  *                               : correction of the import() function to the $value management
  39.  *                               : add getIPadress() function
  40.  * v5.01.04 (September 07, 2016) : correction for quick admin icons display
  41.  *                               : adding a height limitation of the display article
  42.  * v5.01.07 (January 04, 2016)   : correction of the import() function for array value
  43.  *                               : correction of eMailHtmlTo() function with phpmailer 5.2.21
  44.  * v5.02.00 (May 09, 2017)       : adding $_DOMAIN and $_SECURE for cookies management
  45.  *                               : suppress flash management
  46.  * v5.02.00-1 (May 22, 2017)     : correction of getNewUpdateDoc() function
  47.  * v5.02.01 (August 28, 2017)    : improve checkEmail() function (thanks jchouix)
  48.  *                               : adding function getPGTXT()
  49.  *                               : addition of the choice of date formats for both languages
  50.  *                               : adding function is_ssl()
  51.  ******************************************************************************/
  52.  
  53. if (stristr($_SERVER['SCRIPT_NAME'], 'functions.php')) {
  54.   header('location:../index.php');
  55.   die();
  56. }
  57.  
  58. include_once CHEMIN.'inc/constantes.php';
  59.  
  60. function is_ssl() {
  61.     if (isset($_SERVER['HTTPS'])) {
  62.         if ('on' == strtolower($_SERVER['HTTPS'])) return true;
  63.         if ('1' == $_SERVER['HTTPS']) return true;
  64.     } elseif (isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] )) {
  65.         return true;
  66.     } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']))) {
  67.         return true;
  68.     } elseif (isset($_SERVER['X_FORWARDED_PROTO']) && ('https' == strtolower($_SERVER['X_FORWARDED_PROTO']))) {
  69.         return true;
  70.     } elseif (isset($_SERVER['HTTP_X_FORWARDED_SSL']) && 'on' == strtolower($_SERVER['HTTP_X_FORWARDED_SSL'])) {
  71.         return true;
  72.     } elseif (isset($_SERVER['X_FORWARDED_SSL']) && 'on' == strtolower($_SERVER['X_FORWARDED_SSL'])) {
  73.         return true;
  74.     } elseif (isset($_SERVER['HTTP_X_FORWARDED_HTTPS']) && 'on' == strtolower($_SERVER['HTTP_X_FORWARDED_HTTPS'])) {
  75.         return true;
  76.     } elseif (isset($_SERVER['X_FORWARDED_HTTPS']) && 'on' == strtolower($_SERVER['X_FORWARDED_HTTPS'])) {
  77.         return true;
  78.     }
  79.     return false;
  80. }
  81.  
  82. $_DOMAIN = strtolower($_SERVER['HTTP_HOST']) != 'localhost' ? $_SERVER['HTTP_HOST'] : false;
  83. $_SECURE = is_ssl() ? true : false;
  84.  
  85. $show_progbar  = FALSE;
  86. $widepage      = '';
  87. $headinc       = '';
  88. $boutonleft    = '';
  89. $boutoncenter  = '';
  90. $boutonright   = '';
  91. $meskin        = '';
  92. $screen_choice = '';
  93. $screen_icon   = '';
  94. $mod_css       = '';
  95. $mod_scr       = '';
  96. $skn_logo      = '';
  97. $skinCopyright = '';
  98. $reptheme      = '';
  99.  
  100. $couleurs = array(
  101.     'bleu', 'jaune', 'marron', 'or', 'orange', 'outremer', 'rose', 'rouge', 'vert', 'violet'
  102.     );
  103.  
  104. $souriez = array(
  105.     array('|:-)', 'inc/img/smileys/cool.gif',     'cool'),
  106.     array(';-)',  'inc/img/smileys/wink.gif',     'wink'),
  107.     array(':-))', 'inc/img/smileys/biggrin.gif',  'biggrin'),
  108.     array(':-)',  'inc/img/smileys/smile.gif',    'smile'),
  109.     array(':-o',  'inc/img/smileys/frown.gif',    'frown'),
  110.     array(':o)',  'inc/img/smileys/eek.gif',      'eek'),
  111.     array(':-((', 'inc/img/smileys/mad.gif',      'mad'),
  112.     array(':-(',  'inc/img/smileys/confused.gif', 'confused'),
  113.     array('8-)',  'inc/img/smileys/rolleyes.gif', 'rolleyes'),
  114.     array(':-p',  'inc/img/smileys/tongue.gif',   'tongue'),
  115.     array(';-(',  'inc/img/smileys/cry.gif',      'cry')
  116.     );
  117.  
  118.  
  119. function souriez($chaine) {
  120.     global $souriez;
  121.     foreach($souriez as $item) {
  122.         $chaine = str_replace($item[0], '<img src="'.$item[1].'" title="'.$item[2].'" alt="'.$item[2].'" />', $chaine);
  123.     }
  124.     return $chaine;
  125. }
  126.  
  127. function replaceimg($chaine) {
  128.     global $souriez,$site;
  129.     foreach($souriez as $item) {
  130.         $chaine = str_replace($item[0], '<img src="'.$site[3].$item[1].'" title="'.$item[2].'" alt="'.$item[2].'" />', $chaine);
  131.     }
  132.     return $chaine;
  133. }
  134.  
  135. function DrawSmileys($num) {
  136.     global $souriez;
  137.     for ($i = 0; $i < count($souriez); $i++) {
  138.         echo '<a href="JavaScript:AddSmiley'.$num.'(\''.$souriez[$i][0].'\')"><img src="'.CHEMIN.$souriez[$i][1].'" class="clsCursor" title="'.$souriez[$i][0].'" alt="'.$souriez[$i][0].'" /></a>&nbsp;';
  139.     }
  140. }
  141.  
  142. function DrawSmileys2() {
  143.     global $souriez;
  144.     echo '&nbsp;';
  145.     for ($i = 0; $i < count($souriez); $i++) {
  146.         echo '&nbsp;<img src="'.CHEMIN.$souriez[$i][1].'" alt="'.$souriez[$i][2].'" title="'.$souriez[$i][2].'" />';
  147.     }
  148. }
  149.  
  150. function AfficheCompteur($chemino, $hits, $grow = 1) {
  151.     $spot = '';
  152.     for ($lecon = 0; $lecon < $grow - strlen($hits); $lecon++ ) {
  153.         $spot .= '<img src="'.$chemino.'cnt0.gif" alt="" title="" />';
  154.     }
  155.     for ($lecon = 0; $lecon < strlen($hits); $lecon++) {
  156.         $cols = substr($hits, $lecon, 1);
  157.         $spot .= '<img src="'.$chemino.'cnt'.$cols.'.gif" alt="" title="" />';
  158.     }
  159.     return $spot;
  160. }
  161.  
  162. function DejaVote($file_ip, $d_time = 0) {
  163.     global $userprefs, $site;
  164.     $remoteadr   = getIPadress($_SERVER[$site[6] == 'on' ? 'HTTP_X_FORWARDED_FOR' : 'REMOTE_ADDR']);
  165.     $nbr_connect = 0;
  166.     $var_bool    = FALSE;
  167.     $user_bool   = FALSE;
  168.     $subdata     = array();
  169.     $var_ip      = array();
  170.     $k           = 0;
  171.     if ($d_time == 0) {
  172.         $d_time = HIT_TIME;
  173.     }
  174.     $subdata  = ReadDBFields($file_ip);
  175.     $now_time = time();
  176.     foreach($subdata as $sub) {
  177.         list($jour, $mois, $annee) = explode('/', substr($sub[1], 0, 10));
  178.         list($heure, $minute, $seconde) = explode(':', substr($sub[1], 10, 18));
  179.         if ($now_time < mktime((int)$heure, (int)$minute, (int)$seconde, (int)$mois, (int)$jour, (int)$annee) + $d_time) {
  180.             $nbr_connect++;
  181.             $var_ip[$k][0] = $sub[0];
  182.             if ($remoteadr == $sub[0]) {
  183.                 $var_bool = TRUE;
  184.             }
  185.             $var_ip[$k][1] = $sub[1];
  186.             if ($userprefs[5] != '') {
  187.                 $uprefname = $userprefs[1];
  188.             }
  189.             else {
  190.                 $uprefname = '';
  191.             }
  192.             if ($remoteadr == $sub[0] && $uprefname != $sub[2]) {
  193.                 $user_bool = TRUE;
  194.                 $var_ip[$k][2] = $uprefname;
  195.             }
  196.             else {
  197.                 $var_ip[$k][2] = $sub[2];
  198.             }
  199.             $k++;
  200.         }
  201.     }
  202.     if (!$var_bool) {
  203.         $var_ip[$k][0] = $remoteadr;
  204.         $var_ip[$k][1] = date('d/m/Y H:i:s');
  205.         $var_ip[$k][2] = $userprefs[1];
  206.         WriteDBFields($file_ip,$var_ip);
  207.         $nbr_connect++;
  208.     }
  209.     elseif ($user_bool) {
  210.         WriteDBFields($file_ip, $var_ip);
  211.     }
  212.     return array($var_bool, $nbr_connect);
  213. }
  214.  
  215. function CompteVisites($file_ip, $file_counter) {
  216.     $subdata = DejaVote($file_ip);
  217.     $nbr_visit = ReadCounter($file_counter);
  218.     if (!$subdata[0] && ($nbr_visit >= 0)) {
  219.         $nbr_visit++;
  220.         WriteCounter($file_counter,$nbr_visit);
  221.     }
  222.     return array($nbr_visit, $subdata[1]);
  223. }
  224.  
  225. function IsImage($extn) {
  226.     $extn = strtolower($extn);
  227.     if ($extn == 'gif' || $extn == 'jpg' || $extn == 'jpeg' || $extn == 'png' || $extn == 'bmp') {
  228.         return TRUE;
  229.     } else {
  230.         return FALSE;
  231.     }
  232. }
  233.  
  234. function ExtImage($extn){
  235.     switch(strtolower($extn)) {
  236.     case 'bat'  : return 'bat';
  237.     case 'bmp'  : return 'bmp';
  238.     case 'com'  : return 'com';
  239.     case 'css'  : return 'css';
  240.     case 'doc'  : return 'doc';
  241.     case 'exe'  : return 'exe';
  242.     case 'gif'  : return 'gif';
  243.     case 'js'   : return 'js';
  244.     case 'mid'  : return 'mid';
  245.     case 'mp3'  : return 'mp3';
  246.     case 'pdf'  : return 'pdf';
  247.     case 'ppt'  : return 'ppt';
  248.     case 'png'  : return 'png';
  249.     case 'swf'  : return 'swf';
  250.     case 'xls'  : return 'xls';
  251.  
  252.     case 'com'  :
  253.     case 'pif'  : return 'com';
  254.  
  255.     case 'htm'  :
  256.     case 'html' : return 'html';
  257.    
  258.     case 'jpeg' :
  259.     case 'jpg'  : return 'jpg';
  260.    
  261.     case 'odf'  : // OpenOffice
  262.     case 'odg'  :
  263.     case 'odm'  :
  264.     case 'odp'  :
  265.     case 'ods'  :
  266.     case 'odt'  : return 'ooo';
  267.  
  268.     case 'inc'  :
  269.     case 'php'  :
  270.     case 'php3' :
  271.     case 'php4' :
  272.     case 'php5' :
  273.     case 'phtml' : return 'php';
  274.  
  275.     case 'dtb'  :
  276.     case 'ini'  :
  277.     case 'nfo'  :
  278.     case 'txt'  : return 'txt';
  279.  
  280.     case 'avi'  :
  281.     case 'mpeg' :
  282.     case 'mpg'  :
  283.     case 'mov'  :
  284.     case 'wav'  : return 'wav';
  285.  
  286.     case 'ace'  :
  287.     case 'cab'  :
  288.     case 'gz'   :
  289.     case 'rar'  :
  290.     case 'tar'  :
  291.     case 'tgz'  :
  292.     case 'zip'  : return 'zip';
  293.    
  294.     default     : return 'inconnu';
  295.     }
  296. }
  297.  
  298. function PathAbs($matches) {
  299.     if(!preg_match('`^(https?|ftp|mailto|javascript)\:`i', $matches[3])) {
  300.         $matches[0] = $matches[1].$matches[2].CHEMIN.$matches[3];
  301.     }
  302.     return $matches[0];
  303. }
  304.  
  305. function PathToImage($text) {
  306.     return preg_replace_callback("`( href=| src=| action=)(\"|')?([^ >]+)`i", 'PathAbs', $text);
  307. }
  308.  
  309. function SplitText($textin, $textlen) {
  310.     $out1 = $textin;
  311.     $out2 = '';
  312.     if (strlen($textin) > $textlen) {
  313.         $tempout = strrpos(substr($textin,0,$textlen),' ');
  314.         if ($tempout < 1) {
  315.             $tempout = strpos($textin,' ');
  316.         }
  317.         if ($tempout > 0) {
  318.             $out1 = substr($textin,0,$tempout);
  319.             $out2 = substr($textin,$tempout+1,strlen($textin)-$tempout);
  320.         }
  321.     }
  322.     return array($out1, $out2);
  323. }
  324.  
  325. function CutLongWord($textin, $textlen = 50) {
  326.     return (mb_strlen($textin) > $textlen ? mb_substr(mb_substr($textin, 0, $textlen), 0, strrpos(mb_substr($textin, 0, $textlen), ' ')) : $textin);
  327. }
  328.  
  329. function WrapLongWords($textin, $textlen = 50, $textrep = ' ') {
  330.     return wordwrap($textin, $textlen, $textrep, 1);
  331. }
  332.  
  333. function FormatDateStamp($datein) {
  334.     global $site, $lng, $lang;
  335.     $l       = ($lng == $lang[0]) ? 0 : 1;
  336.     $asite19 = explode('|', $site[19]);
  337.     if ($asite19[$l] == 'E1') {
  338.         $formatout = 'd/m/Y';
  339.     }
  340.     elseif ($asite19[$l] == 'E2') {
  341.         $formatout = 'd.m.Y';
  342.     }
  343.     elseif ($asite19[$l] == 'U1') {
  344.         $formatout = 'm/d/Y';
  345.     }
  346.     elseif ($asite19[$l] == 'U2') {
  347.         $formatout = 'm.d.Y';
  348.     }
  349.     elseif ($asite19[$l] == 'C1') {
  350.         $formatout = 'Y/m/d';
  351.     }
  352.     else {
  353.         $formatout = 'Y.m.d';
  354.     }
  355.     $formatout .= ' '.$site[23].' ';
  356.     if ($site[22] == 'H1') {
  357.         $formatout .= 'H:i';
  358.     }
  359.     elseif ($site[22] == 'H2') {
  360.         $formatout .= 'H\hi';
  361.     }
  362.     else {
  363.         $formatout .= 'h:i A';
  364.     }
  365.     $dateout = date($formatout,$datein);
  366.     return $dateout;
  367. }
  368.  
  369. function FormatDate($datein) {
  370.     global $site, $lng, $lang;
  371.     $l       = ($lng == $lang[0]) ? 0 : 1;
  372.     $asite19 = explode('|', $site[19]);
  373.     $jour    = substr($datein,6,2);
  374.     $mois    = substr($datein,4,2);
  375.     $annee   = substr($datein,0,4);
  376.     $heure   = substr($datein,8,2);
  377.     $minute  = substr($datein,10,2);
  378.     if ($asite19[$l] == 'E1') {
  379.         $dateout = $jour.'/'.$mois.'/'.$annee;
  380.     }
  381.     elseif ($asite19[$l] == 'E2') {
  382.         $dateout = $jour.'.'.$mois.'.'.$annee;
  383.     }
  384.     elseif ($asite19[$l] == 'U1') {
  385.         $dateout = $mois.'/'.$jour.'/'.$annee;
  386.     }
  387.     elseif ($asite19[$l] == 'U2') {
  388.         $dateout = $mois.'.'.$jour.'.'.$annee;
  389.     }
  390.     elseif ($asite19[$l] == 'C1') {
  391.         $dateout = $annee.'/'.$mois.'/'.$jour;
  392.     }
  393.     else {
  394.         $dateout = $annee.'.'.$mois.'.'.$jour;
  395.     }
  396.     if ($heure.$minute != '') {
  397.         $dateout .= ' '.$site[23].' ';
  398.         $suffixe  = '';
  399.         if ($site[22] == "H1") {
  400.             $separe   = ':';
  401.         }
  402.         elseif ($site[22] == "H2") {
  403.             $separe = 'h';
  404.         }
  405.         else {
  406.             $separe = ':';
  407.             if ($heure < 12) {
  408.                 $suffixe = ' AM';
  409.             }
  410.             else {
  411.                 $suffixe = ' PM';
  412.                 $heure = $heure - 12;
  413.             }
  414.         }
  415.         $dateout .= $heure.$separe.$minute.$suffixe;
  416.     }
  417.     return $dateout;
  418. }
  419.  
  420. function GetCurrentDateTime() {
  421.     return date('YmdHi');
  422. }
  423.  
  424. function FileSizeInKb($fic) {
  425.     $taille = @filesize($fic);
  426.     if ($taille !== false) {
  427.         $taille = round($taille/1024);
  428.     }
  429.     return $taille;
  430. }
  431.  
  432. function FileDBExist($fic) {
  433.     return is_file($fic);
  434. }
  435.  
  436. function DestroyDBFile($fic) {
  437.     SetChmod($fic);
  438.     SetChmod($fic);
  439.     @unlink($fic);
  440. }
  441.  
  442. function ReadCounter($fic) {
  443.     $DataDB = 0;
  444.     if (FileDBExist($fic)) {
  445.         $fhandle = fopen($fic, 'r');
  446.         if (filesize($fic)) {
  447.             $DataDB = trim(fgets($fhandle, filesize($fic)));
  448.         }
  449.         fclose($fhandle);
  450.     }
  451.     return $DataDB;
  452. }
  453.  
  454. function WriteCounter($fic, $DataDB) {
  455.     $fhandle = fopen($fic, 'w');
  456.     fputs($fhandle, $DataDB."\n");
  457.     fclose($fhandle);
  458. }
  459.  
  460. function ReadFullDB($fic) {
  461.     $DataDB = Array();
  462.     if (FileDBExist($fic)) {
  463.         $DataDB = implode('', file($fic));
  464.     }
  465.     return $DataDB;
  466. }
  467.  
  468. function WriteFullDB($fic, $DataDB) {
  469.     $fhandle = fopen($fic, 'w');
  470.     fputs($fhandle, $DataDB);
  471.     fclose($fhandle);
  472. }
  473.  
  474. function AppendFullDB($fic, $DataDB) {
  475.     $fhandle = fopen($fic, 'a');
  476.     fputs($fhandle, $DataDB);
  477.     fclose($fhandle);
  478. }
  479.  
  480. function CountDBFields($fic) {
  481.     $DataNB = 0;
  482.     if (FileDBExist($fic)) {
  483.         $DataDB = file($fic);
  484.         $DataNB = count($DataDB);
  485.     }
  486.     return $DataNB;
  487. }
  488.  
  489. function ReadDBFields($fic) {
  490.     $DataDB = array();
  491.     $Fields = array();
  492.     if (FileDBExist($fic)) {
  493.         $DataDB = file($fic);
  494.         $i = 0;
  495.         foreach($DataDB as $Data) {
  496.             $Fields[$i] = explode(CONNECTOR, trim($Data));
  497.             $i++;
  498.         }
  499.     }
  500.     return $Fields;
  501. }
  502.  
  503. function WriteDBFields($fic, $Fields) {
  504.     $fhandle = fopen($fic, 'w');
  505.     $out = '';
  506.     foreach($Fields as $row) {
  507.         $out .= implode(CONNECTOR, $row)."\n";
  508.     }
  509.     fputs($fhandle, $out);
  510.     fclose($fhandle);
  511. }
  512.  
  513. function AppendDBFields($fic, $Fields) {
  514.     $fhandle = fopen($fic, 'a');
  515.     $DataDB = '';
  516.     for ($i = 0 ; $i < (count($Fields)-1); $i++) {
  517.         $DataDB .= trim($Fields[$i]).CONNECTOR;
  518.     }
  519.     $DataDB .= trim($Fields[count($Fields)-1])."\n";
  520.     fputs($fhandle, $DataDB);
  521.     fclose($fhandle);
  522. }
  523.  
  524. function DeleteDBFieldById($fic, $id = 0) {
  525.     $array = explode("\n", fread(fopen($fic, 'r'), filesize($fic)));
  526.     $delete = array_pop($array);
  527.     unset($array[$id]);
  528.     $newarray = array_values($array);
  529.     $fhandle = fopen($fic,'w');
  530.     foreach($newarray as $new){
  531.         fwrite($fhandle, $new."\n");
  532.     }
  533.     fclose($fhandle);
  534. }
  535.  
  536. function CheckDB1Field($fic, $submit, $FieldNB) {
  537.     if (FileDBExist($fic)) {
  538.         $DataDB = ReadDBFields($fic);
  539.         foreach($DataDB as $Data) {
  540.             if (@stristr($Data[$FieldNB], $submit)) {
  541.                 return TRUE;
  542.             }
  543.         }
  544.     }
  545.     return FALSE;
  546. }
  547.  
  548. function CheckDB2Fields($fic,$submit1,$FieldNB1,$submit2,$FieldNB2) {
  549.     if (FileDBExist($fic)) {
  550.         $DataDB = ReadDBFields($fic);
  551.         foreach($DataDB as $Data) {
  552.             if (@stristr($Data[$FieldNB1],$submit1) && @stristr($Data[$FieldNB2],$submit2)) {
  553.                 return TRUE;
  554.             }
  555.         }
  556.     }
  557.     return FALSE;
  558. }
  559.  
  560. function SelectDBFieldsByID($Fields,$id) {
  561.     $DataDB = array();
  562.     foreach ($Fields as $row) {
  563.         if ($row[1] == $id) {
  564.             $DataDB[] = $row;
  565.         }
  566.     }
  567.     return $DataDB;
  568. }
  569.  
  570. function SelectDBFieldsByField($Fields, $index, $value) {
  571.     $DataDB = array();
  572.     foreach ($Fields as $row) {
  573.         if ($row[$index] == $value) {
  574.             $DataDB[] = $row;
  575.         }
  576.     }
  577.     return $DataDB;
  578. }
  579.  
  580. function IndexDBFieldsByField($Fields, $index) {
  581.     $DataDB = array();
  582.     foreach ($Fields as $row) {
  583.         $DataDB[$row[$index]] = $row;
  584.     }
  585.     return $DataDB;
  586. }
  587.  
  588. function SelectDBFieldsByType($Fields, $type) {
  589.     $DataDB = array();
  590.     foreach ($Fields as $row) {
  591.         if ($row[0] == $type) {
  592.             $DataDB[] = $row;
  593.         }
  594.     }
  595.     return $DataDB;
  596. }
  597.  
  598. function SelectDBFieldsByNotStatus($Fields, $status) {
  599.     $DataDB = array();
  600.     foreach ($Fields as $row) {
  601.         if ($row[2] != $status) {
  602.             $DataDB[] = $row;
  603.         }
  604.     }
  605.     return $DataDB;
  606. }
  607.  
  608. function SelectDBFieldsByStatus($Fields, $status) {
  609.     $DataDB = array();
  610.     foreach ($Fields as $row) {
  611.         if ($row[2] == $status) {
  612.             $DataDB[] = $row;
  613.         }
  614.     }
  615.     return $DataDB;
  616. }
  617.  
  618. function SelectDBFields($type,$status,$id,$docid=DOCID) {
  619.     if (!empty($status) && !empty($id)) {
  620.         return SelectDBFieldsByID(SelectDBFieldsByStatus(SelectDBFieldsByType(ReadDBFields($docid), $type), $status), $id);
  621.     }
  622.     elseif (!empty($status)) {
  623.         return SelectDBFieldsByStatus(SelectDBFieldsByType(ReadDBFields($docid), $type), $status);
  624.     }
  625.     elseif (!empty($id)) {
  626.         return SelectDBFieldsByID(SelectDBFieldsByType(ReadDBFields($docid), $type), $id);
  627.     }
  628.     else {
  629.         return SelectDBFieldsByType(ReadDBFields($docid), $type);
  630.     }
  631. }
  632.  
  633. function RemoveQuote($chaine) {
  634.     return str_replace(array('"', "'"), '', $chaine);
  635. }
  636.  
  637. function RemoveConnector($chaine) {
  638.     return str_replace(CONNECTOR, '', $chaine);
  639. }
  640.  
  641. function RemoveBR($chaine) {
  642.     return preg_replace('!<br />!i', "\n", $chaine);
  643. }
  644.  
  645. function PutBR($chaine) {
  646.     return str_replace(array(chr(10), chr(13)), array("\n", "\r"), $chaine);
  647. }
  648.  
  649. function ReplaceDolar($chaine) {
  650.     return str_replace('$','&#36;',$chaine);
  651. }
  652.  
  653. function TestFileId($id, $format='%08d') {
  654.     if (1 == preg_match('|^[0-9]+$|', $id)) {
  655.         return sprintf($format, $id);
  656.     } else {
  657.         return FALSE;
  658.     }
  659. }
  660.  
  661. function ReadDocCounter($id, $dir = DBCOUNT) {
  662.     $id = TestFileID($id);
  663.     if ($id === FALSE) {
  664.         return FALSE;
  665.     } else {
  666.         return ReadCounter($dir.$id.DBEXT);
  667.     }
  668. }
  669.  
  670. function WriteDocCounter($id, $DataDB, $dir = DBCOUNT) {
  671.     WriteCounter($dir.$id.DBEXT, $DataDB);
  672. }
  673.  
  674. function UpdateDocCounter($id) {
  675.     $id = TestFileID($id);
  676.     if ($id === FALSE) return FALSE;
  677.     $DataDB = ReadDocCounter($id);
  678.     $vote = DejaVote(DBIPBASE.$id.DBEXT,300);
  679.     if ($vote[0] == FALSE) {
  680.         $DataDB++;
  681.         WriteDocCounter($id, $DataDB);
  682.     }
  683.     return $DataDB;
  684. }
  685.  
  686. function ReadDoc($id, $dir = DBBASE) {
  687.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  688.          $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2,
  689.          $fieldd1, $fieldd2, $fieldweb, $fieldmail, $fieldmod;
  690.     $type       = '';
  691.     $fileid     = '';
  692.     $status     = '';
  693.     $creadate   = '';
  694.     $moddate    = '';
  695.     $author     = '';
  696.     $email      = '';
  697.     $fielda1    = '';
  698.     $fielda2    = '';
  699.     $fieldb1    = '';
  700.     $fieldb2    = '';
  701.     $fieldc1    = '';
  702.     $fieldc2    = '';
  703.     $fieldd1    = '';
  704.     $fieldd2    = '';
  705.     $fieldweb   = '';
  706.     $fieldmail  = '';
  707.     $fieldmod   = '';
  708.     $id = TestFileID($id);
  709.     if ($id === FALSE) return FALSE;
  710.     if (FileDBExist($dir.$id.INCEXT)) {
  711.         include($dir.$id.INCEXT);
  712.     }
  713.     return TRUE;
  714. }
  715.  
  716. function WriteDoc($action = '', $dir = DBBASE) {
  717.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  718.          $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2,
  719.          $fieldd1, $fieldd2, $fieldweb, $fieldmail, $fieldmod;
  720.     $id = TestFileID($fileid);
  721.     if ($id === FALSE) return FALSE;
  722.     if ($action != 'migr' && in_array($type, array(TYP_ART, TYP_BLOG, TYP_FAQ, TYP_FREEBOX, TYP_MENUBOX, TYP_OPTDDMENU))) {
  723.         $fieldc1 = str_replace('&#36;', '$', $fieldc1);
  724.         $fieldc2 = str_replace('&#36;', '$', $fieldc2);
  725.     }
  726.     $rec = "<?php
  727. \$type = '".$type."';
  728. \$fileid = '".$fileid."';
  729. \$status = '".$status."';
  730. \$creadate = '".$creadate."';
  731. \$moddate = '".$moddate."';
  732. \$author = stripslashes('".$author."');
  733. \$email = stripslashes('".$email."');
  734. \$fielda1 = stripslashes('".$fielda1."');
  735. \$fielda2 = stripslashes('".$fielda2."');
  736. \$fieldb1 = stripslashes('".$fieldb1."');
  737. \$fieldb2 = stripslashes('".$fieldb2."');
  738. \$fieldc1 = stripslashes('".$fieldc1."');
  739. \$fieldc2 = stripslashes('".$fieldc2."');
  740. \$fieldd1 = stripslashes('".$fieldd1."');
  741. \$fieldd2 = stripslashes('".$fieldd2."');
  742. \$fieldweb = stripslashes('".$fieldweb."');
  743. \$fieldmail = stripslashes('".$fieldmail."');
  744. \$fieldmod = stripslashes('".$fieldmod."');
  745. ?>
  746. ";
  747.     WriteFullDB($dir.$id.INCEXT, $rec);
  748.     return TRUE;
  749. }
  750.  
  751. function UpdateDBdtb($dtb) {
  752.     global $type,$fileid,$status,$creadate,$moddate,$author,$email,
  753.         $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldd1,$fieldd2,$fieldweb,$fieldmail,$fieldmod;
  754.     $db  = SelectDBFields($dtb, 'a', '');
  755.     $dba = array();
  756.     $j   = 0;
  757.     foreach($db as $dbs) {
  758.         ReadDoc($dbs[1]);
  759.         $dba[$j]= array(
  760.             RemoveConnector($fielda1),
  761.             RemoveConnector($fielda2),
  762.             RemoveConnector($fieldb1),
  763.             RemoveConnector($fieldb2),
  764.             $fileid,
  765.             $creadate,
  766.             $fieldmod,
  767.             $type
  768.             );
  769.         if ($dtb == TYP_ART) {
  770.             $dba[$j][5] = RemoveConnector($fieldd1);
  771.         } elseif ($dtb == TYP_OPTMENU || $dtb == TYP_OPTDDMENU) {
  772.             $dba[$j][5] = $fieldweb;
  773.         }
  774.         $j++;
  775.     }
  776.     WriteDBFields(DBINDEX.$dtb.DBEXT, $dba);
  777. }
  778.  
  779. function UpdateDBreact($action, $id) {
  780.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  781.         $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2, $fieldd1, $fieldd2,
  782.         $fieldweb, $fieldmail, $fieldmod;
  783.     $db = array();
  784.     if ($action == 'add' || $action == 'migr') {
  785.         ReadDoc($id);
  786.         if ($status == 'a') {
  787.             $db = array_pad(array(), 7, '');
  788.             $db[0] = $fileid;
  789.             $db[1] = $fielda2;
  790.             ReadDoc($fielda2);
  791.             $db[2] = $fieldb1;
  792.             $db[3] = $fieldb2;
  793.             $db[5] = $creadate;
  794.             $db[6] = $fieldmod;
  795.             $db[7] = TYP_REACT;
  796.             AppendDBFields(DBREACT, $db);
  797.         }
  798.     }
  799.     else {
  800.         $db = SelectDBFields(TYP_REACT,'a','');
  801.         sort($db);
  802.         $dbart = ReadDbFields(DBART);
  803.         $dbf = array();
  804.         $i   = 0;
  805.         foreach($db as $dbs) {
  806.             $dbf[$i] = array_pad(array(), 7, '');
  807.             ReadDoc($dbs[1]);
  808.             $dbf[$i][0] = $fileid;
  809.             $dbf[$i][1] = $fielda2;
  810.             $art = SelectDBFieldsByField($dbart, 4, $fielda2);
  811.             if (!empty($art)) {
  812.                 $dbf[$i][2] = $art[0][2];
  813.                 $dbf[$i][3] = $art[0][3];
  814.                 $dbf[$i][5] = $art[0][5];
  815.                 $dbf[$i][6] = $art[0][6];
  816.                 $dbf[$i][7] = TYP_REACT;
  817.             }
  818.             $i++;
  819.         }
  820.         WriteDBFields(DBREACT, $dbf);
  821.     }
  822. }
  823.  
  824. function UpdateDBreblog($action, $id) {
  825.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  826.         $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2, $fieldd1, $fieldd2,
  827.         $fieldweb, $fieldmail, $fieldmod;
  828.     $db = array();
  829.     if ($action == 'add' || $action == 'migr') {
  830.         ReadDoc($id);
  831.         if ($status == 'a') {
  832.             $db = array_pad(array(), 7, '');
  833.             $db[0] = $fileid;
  834.             $db[1] = $fielda2;
  835.             ReadDoc($fielda2);
  836.             $db[2] = $fieldb1;
  837.             $db[3] = $fieldb2;
  838.             $db[5] = $creadate;
  839.             $db[6] = $fieldmod;
  840.             $db[7] = TYP_REBLOG;
  841.             AppendDBFields(DBREBLOG, $db);
  842.         }
  843.     }
  844.     else {
  845.         $db = SelectDBFields(TYP_REBLOG,'a','');
  846.         sort($db);
  847.         $dbblog = ReadDbFields(DBBLOG);
  848.         $dbf = array();
  849.         $i   = 0;
  850.         foreach($db as $dbs) {
  851.             $dbf[$i] = array_pad(array(), 7, '');
  852.             ReadDoc($dbs[1]);
  853.             $dbf[$i][0] = $fileid;
  854.             $dbf[$i][1] = $fielda2;
  855.             $blog = SelectDBFieldsByField($dbblog, 4, $fielda2);
  856.             if (!empty($blog)) {
  857.                 $dbf[$i][2] = $blog[0][2];
  858.                 $dbf[$i][3] = $blog[0][3];
  859.                 $dbf[$i][5] = $blog[0][5];
  860.                 $dbf[$i][6] = $blog[0][6];
  861.                 $dbf[$i][7] = TYP_REBLOG;
  862.             }
  863.             $i++;
  864.         }
  865.         WriteDBFields(DBREBLOG, $dbf);
  866.     }
  867. }
  868.  
  869. function UpdateDBforum($action, $id) {
  870.     global $type,$fileid,$status,$creadate,$moddate,$author,$email,
  871.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,$fieldweb,$fieldmail;$fieldmod;
  872.     $db = array();
  873.     if ($action == 'add' || $action == 'migr') {
  874.         ReadDoc($id);
  875.         if ($status == 'a') {
  876.             $db[0]  = $creadate;
  877.             $db[1]  = $fielda1;
  878.             $db[2]  = $fielda2;
  879.             $db[3]  = $fileid;
  880.             $db[4]  = RemoveConnector($author);
  881.             $db[5]  = RemoveConnector($email);
  882.             $db[6]  = RemoveConnector($fieldb1);
  883.             $db[7]  = $fieldd1;
  884.             $db[8]  = $fieldb2;
  885.             $db[9]  = $fieldmail;
  886.             $db[10] = TYP_FORUM;
  887.             AppendDBFields(DBTHREAD, $db);
  888.         }
  889.     } else {
  890.         $db = SelectDBFields(TYP_FORUM, 'a', '');
  891.         sort($db);
  892.         $dbf    = array();
  893.         $ns2cat = array();
  894.         $i      = 0;
  895.         foreach($db as $dbs) {
  896.             ReadDoc($dbs[1]);
  897.             $dbf[$i][0]  = $creadate;
  898.             $dbf[$i][1]  = $fielda1;
  899.             $dbf[$i][2]  = $fielda2;
  900.             $dbf[$i][3]  = $fileid;
  901.             $dbf[$i][4]  = RemoveConnector($author);
  902.             $dbf[$i][5]  = RemoveConnector($email);
  903.             $dbf[$i][6]  = RemoveConnector($fieldb1);
  904.             $dbf[$i][7]  = $fieldd1;
  905.             $dbf[$i][8]  = $fieldb2;
  906.             $dbf[$i][9]  = $fieldmail;
  907.             $dbf[$i][10] = TYP_FORUM;
  908.             if (0 == $fielda2) {
  909.                 $ns2cat[$fielda1] = $fieldb2;
  910.             } elseif (isset($ns2cat[$fielda1])) {
  911.                 $dbf[$i][8] = $ns2cat[$fielda1];
  912.             }
  913.             $i++;
  914.         }
  915.         @sort($dbf, SORT_REGULAR);
  916.         WriteDBFields(DBTHREAD, $dbf);
  917.     }
  918.     $db  = array();
  919.     $db  = ReadDBFields(DBTHREAD);
  920.     $dbf = array();
  921.     $i   = 0;
  922.     $j   = 0;
  923.     foreach ($db as $dbs) {
  924.         if ($db[$i][2] == '0') {
  925.             $dbf[$j][0]  = $dbs[0];
  926.             $dbf[$j][1]  = $dbs[1];
  927.             $dbf[$j][2]  = $dbs[3];
  928.             $dbf[$j][3]  = $dbs[4];
  929.             $dbf[$j][4]  = $dbs[5];
  930.             $dbf[$j][5]  = $dbs[6];
  931.             $dbf[$j][6]  = $dbs[3] == $fileid ? $creadate : $dbs[0];
  932.             $dbf[$j][7]  = GetLastChildNumber(TYP_FORUM, $dbs[1]);
  933.             $dbf[$j][8]  = '';
  934.             $dbf[$j][9]  = '';
  935.             $dbf[$j][10] = $dbs[7];
  936.             $dbf[$j][11] = '';
  937.             $dbf[$j][12] = $dbs[8];
  938.             $dbf[$j][13] = $dbs[10];
  939.             $k           = 0;
  940.             foreach ($db as $dbk) {
  941.                 if ($dbk[1] == $dbf[$j][1]) {
  942.                     $dbf[$j][0]  = $dbk[0] > $dbf[$j][0] ? $dbk[0] : $dbf[$j][0];
  943.                     $dbf[$j][8]  = $dbk[4];
  944.                     $dbf[$j][9]  = $dbk[5];
  945.                     $dbf[$j][11] = $dbk[7];
  946.                 }
  947.                 $k++;
  948.             }
  949.             $j++;
  950.         }
  951.         $i++;
  952.     }
  953.     @rsort($dbf, SORT_REGULAR);
  954.     WriteDBFields(DBFORUM, $dbf);
  955. }
  956.  
  957. function UpdateDocid($id, $status) {
  958.     $db = ReadDBFields(DOCID);
  959.     for ($i = 0; $i < count($db); $i++) {
  960.         if ($db[$i][1] == $id) {
  961.             $db[$i][2] = $status;
  962.             break;
  963.         }
  964.     }
  965.     WriteDBFields(DOCID,$db);
  966.     unset($db);
  967. }
  968.  
  969. function UpdateDocdates($action, $id, $mdate='', $cdate='') {
  970.     $db = ReadDBFields(DOCDATES);
  971.     switch ($action) {
  972.     case 'add'  :
  973.     case 'migr' :
  974.         $datespub    = explode('-', $cdate);
  975.         $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  976.         $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  977.         $cdate       = $datespub[0].'-'.$datespub[1];
  978.         $mdate       = $action == 'add' ? $datespub[0] : $mdate;
  979.         $db[]        = array($id, $cdate, $mdate);
  980.         break;
  981.     case 'mod' :
  982.         for ($i = 0; $i < count($db); $i++) {
  983.             if ($db[$i][0] == $id) {
  984.                 if ($cdate != '' && $db[$i][1] != $cdate) {
  985.                     $datespub    = explode('-', $cdate);
  986.                     $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  987.                     $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  988.                     $db[$i][1]   = $datespub[0].'-'.$datespub[1];
  989.                 }
  990.                 $db[$i][2] = $mdate == '' ? GetCurrentDateTime() : $mdate;
  991.                 break;
  992.             }
  993.         }
  994.         break;
  995.     case 'del' :
  996.         for ($i = 0; $i < count($db); $i++) {
  997.             if ($db[$i][0] == $id) {
  998.                 unset($db[$i]);
  999.                 break;
  1000.             }
  1001.         }
  1002.         break;
  1003.     }
  1004.     sort($db);
  1005.     WriteDBFields(DOCDATES, $db);
  1006.     unset($db);
  1007. }
  1008.  
  1009. function GetLastChildNumber($type, $parentId = NULL) {
  1010.     $db = SelectDbFieldsByField(ReadDbFields(CHILDREN), 1, $type);
  1011.     if (isset($parentId)) {
  1012.         $db = SelectDbFieldsByField($db, 3, $parentId);
  1013.     }
  1014.     if (count($db) > 0) {
  1015.         rsort($db);
  1016.         return $db[0][2];
  1017.     } else {
  1018.         return 0;
  1019.     }
  1020.     unset($db);
  1021. }
  1022.  
  1023. function GetNextChildNumber($type, $parentId = NULL) {
  1024.     return 1 + GetLastChildNumber($type, $parentId);
  1025. }
  1026.  
  1027. function UpdateChildren($action, $data) {
  1028.     $db = IndexDbFieldsByField(ReadDbFields(CHILDREN), 0);
  1029.     switch ($data[0]) {
  1030.     case TYP_GUESTBK :
  1031.     case TYP_REACT :
  1032.     case TYP_REBLOG :
  1033.         switch ($action) {
  1034.         case 'add' :
  1035.             $db[$data[1]] = array($data[1], $data[0], $data[7], $data[8]);
  1036.             WriteDbFields(CHILDREN, $db);
  1037.             break;
  1038.         case 'del' :
  1039.             unset($db[$data[1]]);
  1040.             WriteDbFields(CHILDREN, $db);
  1041.             break;
  1042.         }
  1043.         break;
  1044.     case TYP_FORUM :
  1045.         if (0 == $data[8]) break;
  1046.         switch ($action) {
  1047.         case 'add' :
  1048.             $db[$data[1]] = array($data[1], $data[0], $data[8], $data[7]);
  1049.             WriteDbFields(CHILDREN, $db);
  1050.             break;
  1051.         case 'del' :
  1052.             if (isset($db[$data[1]])) unset($db[$data[1]]);
  1053.             WriteDbFields(CHILDREN, $db);
  1054.             break;
  1055.         }
  1056.         break;
  1057.     }
  1058.     unset($db);
  1059. }
  1060.  
  1061. function UpdateDocFromDoc($action, $id, $newStatus) {
  1062.     global $type,$fileid,$status,$creadate,$moddate,$author,$email,
  1063.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  1064.     $fieldweb,$fieldmail,$fieldmod, $lang, $urlrw;
  1065.     ReadDoc($id);
  1066.     $status    = $newStatus;
  1067.     $author    = addslashes($author);
  1068.     $email     = addslashes($email);
  1069.     $fielda1   = addslashes($fielda1);
  1070.     $fielda2   = addslashes($fielda2);
  1071.     $fieldb1   = addslashes($fieldb1);
  1072.     $fieldb2   = addslashes($fieldb2);
  1073.     $fieldc1   = addslashes($fieldc1);
  1074.     $fieldc2   = addslashes($fieldc2);
  1075.     $fieldd1   = addslashes($fieldd1);
  1076.     $fieldd2   = addslashes($fieldd2);
  1077.     $fieldweb  = addslashes($fieldweb);
  1078.     $fieldmail = addslashes($fieldmail);
  1079.     $fieldmod  = addslashes($fieldmod);
  1080.     WriteDoc($action);
  1081.     if ($type == TYP_ART) {
  1082.         $mnu_id = substr($fieldd1, 4);
  1083.         $dbw    = SelectDbFieldsByField(ReadDBFields(DBOPTMENU), 5, $mnu_id);
  1084.         foreach ($dbw as $item) {
  1085.             ReadDoc($item[4]);
  1086.             $urls = explode('||', $fieldd1);
  1087.             if (!empty($urls[0]) && strpos($urls[0], 'articles.php') !== false) {
  1088.                 $pg  = substr($urls[0], strpos($urls[0], 'pg=') + 3);
  1089.                 $pos = strpos($pg, '&');
  1090.                 $pg  = $pos === false ? $pg : substr($pg, 0, $pos);
  1091.             }
  1092.             if ($pg == $id && $fieldweb == $mnu_id) {
  1093.                 $opt_id = $item[4];
  1094.                 UpdateDocid($opt_id, $newStatus);
  1095.                 UpdateDocFromDoc($action, $opt_id, $newStatus);
  1096.                 UpdateDBdtb(TYP_OPTMENU);
  1097.                 break;
  1098.             }                
  1099.         }
  1100.         unset($dbw);
  1101.     }
  1102. }
  1103.  
  1104. function UpdateDocFromInput($action, $id, $data) {
  1105.     global $site,$type,$fileid,$status,$creadate,$moddate,$author,$email,
  1106.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  1107.     $fieldweb,$fieldmail,$fieldmod;
  1108.     ReadDoc($id);
  1109.     if (in_array($action, array('add', 'migr'))) {
  1110.         $type   = $data[0];
  1111.         $fileid = $id;
  1112.         $status = $data[2];
  1113.        
  1114.         $datespub    = explode('-', $data[3]);
  1115.         $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  1116.         $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  1117.         $creadate    = $datespub[0].'-'.$datespub[1];
  1118.         $moddate     = $action == 'add' ? $datespub[0] : $data[4];
  1119.     } else {
  1120.         /// $action == 'mod'
  1121.         if ($creadate != $data[3] && $data[0] != TYP_FORUM) {
  1122.             $datespub    = explode('-', $data[3]);
  1123.             $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  1124.             $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  1125.             $creadate    = $datespub[0].'-'.$datespub[1];
  1126.         }
  1127.         $moddate = $data[4];
  1128.     }
  1129.     $author  = addslashes(stripslashes($data[5]));
  1130.     $email   = addslashes(stripslashes($data[6]));
  1131.     $fielda1 = addslashes(stripslashes($data[7]));
  1132.     $fielda2 = addslashes(stripslashes($data[8]));
  1133.     $fieldb1 = addslashes(stripslashes($data[9]));
  1134.     $fieldb2 = addslashes(stripslashes($data[10]));
  1135.     if ($data[0] == TYP_NWL) {
  1136.         $fieldc1 = addslashes(stripslashes(replaceimg(ReplaceDolar(PutBR($data[11])))));
  1137.         $fieldc2 = addslashes(stripslashes(replaceimg(ReplaceDolar(PutBR($data[12])))));
  1138.     }
  1139.     else {
  1140.         $fieldc1 = addslashes(stripslashes(souriez(ReplaceDolar(PutBR($data[11])))));
  1141.         $fieldc2 = addslashes(stripslashes(souriez(ReplaceDolar(PutBR($data[12])))));
  1142.     }
  1143.     $fieldd1   = addslashes(stripslashes($data[13]));
  1144.     $fieldd2   = addslashes(stripslashes($data[14]));
  1145.     $fieldweb  = addslashes(stripslashes($data[15]));
  1146.     $fieldmail = addslashes(stripslashes($data[16]));
  1147.     $fieldmod  = addslashes(stripslashes($data[17]));
  1148.     WriteDoc($action);
  1149. }
  1150.  
  1151. function DeactivateInCascade($type, $parentId) {
  1152.     // Désactivation en cascade des réactions, réponses et commentaires actifs
  1153.     switch ($type) {
  1154.     case TYP_ART :
  1155.         $db1 = SelectDbFieldsByField(ReadDbFields(DBREACT), 1, $parentId);
  1156.         foreach ($db1 as $db) {
  1157.             ActionOnFields('act', array(TYP_REACT, $db[0], 'i'), FALSE);
  1158.         }
  1159.         if (count($db1) > 0) {
  1160.             ActionOnFields('reindex', array(TYP_REACT, 0));
  1161.         }
  1162.         unset($db1, $db);
  1163.         break;
  1164.     case TYP_BLOG :
  1165.         $db1 = SelectDbFieldsByField(ReadDbFields(DBREBLOG), 1, $parentId);
  1166.         foreach ($db1 as $db) {
  1167.             ActionOnFields('act', array(TYP_REBLOG, $db[0], 'i'), FALSE);
  1168.         }
  1169.         if (count($db1) > 0) {
  1170.             ActionOnFields('reindex', array(TYP_REBLOG, 0));
  1171.         }
  1172.         unset($db1, $db);
  1173.         break;
  1174.     case TYP_FORUM :
  1175.         global $fielda1, $fielda2;
  1176.         if (0 == $fielda2) {
  1177.             $db1 = SelectDbFieldsByField(ReadDbFields(DBTHREAD), 1, $fielda1);
  1178.             foreach ($db1 as $db) {
  1179.                 if ($db[2] > 0) {
  1180.                     ActionOnFields('act', array(TYP_FORUM, $db[3], 'i'), FALSE);
  1181.                 }
  1182.             }
  1183.             if (count($db1) > 1) {
  1184.                 ActionOnFields('reindex', array(TYP_FORUM, 0));
  1185.             }
  1186.             unset($db1, $db);
  1187.         }
  1188.         break;
  1189.     }
  1190. }
  1191.  
  1192. function DeleteInCascade($type, $parentId) {
  1193.     // Suppression en cascade des réactions, réponses et commentaires actifs
  1194.     $db1 = array();
  1195.     $typechildren = array(TYP_ART=>TYP_REACT, TYP_BLOG=>TYP_REBLOG);
  1196.     switch ($type) {
  1197.     case TYP_ART :
  1198.     case TYP_BLOG :
  1199.         $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $typechildren[$type]), 3, $parentId);
  1200.         foreach ($db1 as $db) {
  1201.             ActionOnFields('del', array($typechildren[$type], $db[0]), FALSE);
  1202.         }
  1203.         break;
  1204.     case TYP_FORUM :
  1205.         global $fielda1, $fielda2;
  1206.         if (0 == $fielda2) {
  1207.             $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $type), 3, $fielda1);
  1208.             foreach ($db1 as $db) {
  1209.                 ActionOnFields('del', array($type, $db[0]), FALSE);
  1210.             }
  1211.         }
  1212.         break;
  1213.     }
  1214.     if (count($db1) > 0) {
  1215.         ActionOnFields('reindex', array($type, 0));
  1216.     }
  1217.     unset($db1);
  1218. }
  1219.  
  1220. function DestroyInCascade($type, $parentId) {
  1221.     // Destruction définitive en cascade des réactions, réponses et commentaires actifs
  1222.     $db1 = array();
  1223.     $typechildren = array(TYP_ART=>TYP_REACT, TYP_BLOG=>TYP_REBLOG);
  1224.     switch ($type) {
  1225.     case TYP_ART :
  1226.     case TYP_BLOG :
  1227.         $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $typechildren[$type]), 3, $parentId);
  1228.         foreach ($db1 as $db) {
  1229.             ActionOnFields('sup', array($typechildren[$type], $db[0]), FALSE);
  1230.         }
  1231.         break;
  1232.     case TYP_FORUM :
  1233.         global $fielda1, $fielda2;
  1234.         if (0 == $fielda2) {
  1235.             $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $type), 3, $fielda1);
  1236.             foreach ($db1 as $db) {
  1237.                 ActionOnFields('sup', array($type, $db[0]), FALSE);
  1238.             }
  1239.         }
  1240.         break;
  1241.     }
  1242.     if (count($db1) > 0) {
  1243.         ActionOnFields('reindex', array($type, 0));
  1244.     }
  1245. }
  1246.    
  1247. function CreateSitemapFile($file, $db) {
  1248.     global $charset;
  1249.     $smtxt = '<?xml version="1.0" encoding="'.$charset.'"?>
  1250. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
  1251.     foreach($db as $url) {
  1252.         $smtxt .= '
  1253.  <url>
  1254.    <loc>'.$url['LOC'].'</loc>
  1255.     <lastmod>'.$url['LM'].'</lastmod>
  1256.    <changefreq>'.$url['CF'].'</changefreq>
  1257.    <priority>'.$url['PR'].'</priority>
  1258.  </url>';
  1259.     }
  1260.     $smtxt .= '
  1261. </urlset>';
  1262.     WriteFullDB($file, $smtxt);
  1263. }
  1264.  
  1265. function UpdateSitemaps($typ) {
  1266.     global $lang, $site, $urlrw, $sitemap, $charset, $z2,
  1267.     $type, $fileid, $status, $creadate, $moddate, $author, $email, $fielda1, $fielda2, $fieldb1,
  1268.     $fieldb2, $fieldc1, $fieldc2, $fieldd1, $fieldd2, $fieldweb, $fieldmail, $fieldmod;
  1269.    
  1270.     $smtyps = array(TYP_BLOG, TYP_ART, TYP_NEWS, TYP_PHOTO, TYP_DNLOAD, TYP_FAQ, TYP_LINKS, TYP_GUESTBK, TYP_FORUM, TYP_AGENDA);
  1271.     if ($typ != 'URLS' && !in_array($typ, $smtyps)) return;
  1272.    
  1273.     @unlink(SITEMAPS);
  1274.     @unlink(SM_URLS);
  1275.     $dbws = array();
  1276.     if ($sitemap['SM'] == 'on') {
  1277.         $home = array('index.php?lng='.$lang[0], ($lang[1] != '') ? 'index.php?lng='.$lang[1] : NULL);
  1278.         $urls = file_exists(MAPSURLS) ? array_merge(file(MAPSURLS), $home) : $home;
  1279.        
  1280.         $smslcts = array(TYP_BLOG=>$sitemap['BL'], TYP_ART=>$sitemap['AR'], TYP_NEWS=>$sitemap['NE'], TYP_PHOTO=>$sitemap['PH'], TYP_DNLOAD=>$sitemap['DN'],
  1281.                          TYP_FAQ=>$sitemap['FA'], TYP_LINKS=>$sitemap['LI'], TYP_GUESTBK=>$sitemap['GB'], TYP_FORUM=>$sitemap['FR'], TYP_AGENDA=>$sitemap['AG']);
  1282.         $smfiles = array(TYP_BLOG=>SM_BLOG, TYP_ART=>SM_ART, TYP_NEWS=>SM_NEWS, TYP_PHOTO=>SM_PHOTO, TYP_DNLOAD=>SM_DNLOAD,
  1283.                          TYP_FAQ=>SM_FAQ, TYP_LINKS=>SM_LINKS, TYP_GUESTBK=>SM_GUESTBK, TYP_FORUM=>SM_FORUM, TYP_AGENDA=>SM_AGENDA);
  1284.         $smfreqs = array(TYP_BLOG=>'weekly', TYP_ART=>'monthly', TYP_NEWS=>'weekly', TYP_PHOTO=>'monthly', TYP_DNLOAD=>'monthly',
  1285.                          TYP_FAQ=>'yearly', TYP_LINKS=>'monthly', TYP_GUESTBK=>'monthly', TYP_FORUM=>'daily', TYP_AGENDA=>'monthly');
  1286.        
  1287.         foreach($smtyps as $smtyp) if ($smslcts[$smtyp] != 'on') @unlink($smfiles[$smtyp]);
  1288.  
  1289.         $dbw = array();
  1290.         foreach($urls as $url) {
  1291.             $url = str_replace('&amp;', '&', $url);
  1292.             $url = str_replace('&', '&amp;', $url);
  1293.             $dbw[] = array('LOC'=>$site[3].$url, 'LM'=>date('Y-m-d'), 'CF'=>'yearly', 'PR'=>'0.5');
  1294.         }
  1295.         CreateSitemapFile(SM_URLS, $dbw);
  1296.        
  1297.         foreach($smtyps as $smtyp) {
  1298.             if ($typ != $smtyp || $smslcts[$smtyp] != 'on') continue;
  1299.             $dbw  = array();
  1300.             $docs = SelectDBFields($smtyp, 'a', '');
  1301.             foreach ($docs as $doc) {
  1302.                 ReadDoc($doc[1]);
  1303.                 if ($typ == TYP_FORUM && $fielda2 != '0') continue;
  1304.                 $fieldmail = empty($fieldmail) ? 0 : $fieldmail;
  1305.                 if (isAuthorizedPublication($creadate) && $fieldmod == '') {
  1306.                     foreach($lang as $lng) {
  1307.                         if ($lang[1] == $lng && ($fieldc2 == '' || in_array(array(TYP_GUESTBK, TYP_FORUM), $smtyps))) continue;
  1308.                         switch ($smtyp) {
  1309.                         case TYP_BLOG    : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[1].'-4-'.$fileid.$z2 : $site['BL'].'.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  1310.                         case TYP_ART     : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[20].'-102-'.$fileid.'-'.$fieldmail.$z2 : 'articles.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;tconfig='.$fieldmail.$z2); break;
  1311.                         case TYP_NEWS    : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[8].'-2-'.$fileid.$z2 : $site['NE'].'.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  1312.                         case TYP_PHOTO   : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[9].'-2-'.$fileid.'-'.$fieldmail.$z2 : 'photorama2.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;tconfig='.$fieldmail.$z2); break;
  1313.                         case TYP_DNLOAD  : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[11].'-4-'.$fileid.'-'.$fieldmail.$z2 : $site['DN'].'.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;tconfig='.$fieldmail.$z2); break;
  1314.                         case TYP_FAQ     : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[4].'-3-'.$fileid.$z2 : 'faq.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  1315.                         case TYP_LINKS   : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[6].'-1-'.$fileid.$z2 : 'links.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  1316.                         case TYP_GUESTBK : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[7].'-3-'.$fileid.$z2 : $site['GB'].'.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  1317.                         case TYP_FORUM   : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[5].'-500-'.$fileid.'-'.$fielda1.'-1'.$z2 : $site['TH'].'.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;cat='.$fielda1.'&amp;fid=1'.$z2); break;
  1318.                         case TYP_AGENDA  : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[17].'-22-'.$fileid.'-'.$fileid.'-1-'.$fieldmail.$z2 : 'agenda.php?lng='.$lng.'&amp;idpg='.$fileid.'-'.'&amp;pg='.$fileid.'&amp;agv=1&amp;tconfig='.$fieldmail.$z2); break;
  1319.                         }
  1320.                         $dbw[] = array(
  1321.                             'LOC'=>$site[3].$smloc,
  1322.                             'LM'=>substr($moddate, 0, 4).'-'.substr($moddate, 4, 2).'-'.substr($moddate, 6, 2),
  1323.                             'CF'=>$smfreqs[$smtyp], 'PR'=>'0.5');
  1324.                     }
  1325.                 }
  1326.             }
  1327.             if (!empty($dbw)) CreateSitemapFile($smfiles[$smtyp], $dbw); else @unlink($smfiles[$smtyp]);
  1328.         }
  1329.         if (file_exists(SM_URLS))    $dbws[] = array('LOC'=>substr(SM_URLS, 3), 'LM'=>date('Y-m-d', filemtime(SM_URLS)));
  1330.         if (file_exists(SM_BLOG))    $dbws[] = array('LOC'=>substr(SM_BLOG, 3), 'LM'=>date('Y-m-d', filemtime(SM_BLOG)));
  1331.         if (file_exists(SM_ART))     $dbws[] = array('LOC'=>substr(SM_ART, 3), 'LM'=>date('Y-m-d', filemtime(SM_ART)));
  1332.         if (file_exists(SM_NEWS))    $dbws[] = array('LOC'=>substr(SM_NEWS, 3), 'LM'=>date('Y-m-d', filemtime(SM_NEWS)));
  1333.         if (file_exists(SM_PHOTO))   $dbws[] = array('LOC'=>substr(SM_PHOTO, 3), 'LM'=>date('Y-m-d', filemtime(SM_PHOTO)));
  1334.         if (file_exists(SM_DNLOAD))  $dbws[] = array('LOC'=>substr(SM_DNLOAD, 3), 'LM'=>date('Y-m-d', filemtime(SM_DNLOAD)));
  1335.         if (file_exists(SM_FAQ))     $dbws[] = array('LOC'=>substr(SM_FAQ, 3), 'LM'=>date('Y-m-d', filemtime(SM_FAQ)));
  1336.         if (file_exists(SM_LINKS))   $dbws[] = array('LOC'=>substr(SM_LINKS, 3), 'LM'=>date('Y-m-d', filemtime(SM_LINKS)));
  1337.         if (file_exists(SM_GUESTBK)) $dbws[] = array('LOC'=>substr(SM_GUESTBK, 3), 'LM'=>date('Y-m-d', filemtime(SM_GUESTBK)));
  1338.         if (file_exists(SM_FORUM))   $dbws[] = array('LOC'=>substr(SM_FORUM, 3), 'LM'=>date('Y-m-d', filemtime(SM_FORUM)));
  1339.         if (file_exists(SM_AGENDA))  $dbws[] = array('LOC'=>substr(SM_AGENDA, 3), 'LM'=>date('Y-m-d', filemtime(SM_AGENDA)));
  1340.         if (!empty($dbws)) {
  1341.             $smtxt = '<?xml version="1.0" encoding="'.$charset.'"?>
  1342. <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
  1343.             foreach($dbws as $sm) {
  1344.                 $smtxt .= '
  1345.  <sitemap>
  1346.    <loc>'.$site[3].$sm['LOC'].'</loc>
  1347.    <lastmod>'.$sm['LM'].'</lastmod>
  1348.  </sitemap>';
  1349.             }
  1350.             $smtxt .= '
  1351. </sitemapindex>';
  1352.             WriteFullDB(SITEMAPS, $smtxt);
  1353.         }
  1354.     }
  1355.     if (file_exists(CHEMIN.'robots.txt')) {
  1356.         $robots = file(CHEMIN.'robots.txt');
  1357.         $dbr    = array();
  1358.         foreach($robots as $line)
  1359.             if (substr($line, 0, 8) != 'Sitemap:') $dbr[] = $line;
  1360.         if (!empty($dbws)) $dbr[] = 'Sitemap: '.$site[3].substr(SITEMAPS, 3);
  1361.         $rh = fopen(CHEMIN.'robots.txt', 'w');
  1362.         foreach($dbr as $line) fwrite($rh, $line);
  1363.         fclose($rh);
  1364.     }
  1365. }
  1366.  
  1367. function ActionOnFields($action, $data, $reindex = TRUE) {
  1368.     global $site,$type,$fileid,$status,$creadate,$moddate,$author,$email,
  1369.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  1370.     $fieldweb,$fieldmail,$fieldmod;
  1371.     $id = $action == 'reindex' ? false : $data[AOF_ID];
  1372.     switch ($action) {
  1373.     case 'add'  :
  1374.     case 'migr' :
  1375.         $id = $data[AOF_ID] = IncrNextID();
  1376.         AppendDBFields(DOCID, array($data[AOF_TYPE], $id, $data[AOF_STATUS]));
  1377.         UpdateDocFromInput($action, $id, $data);
  1378.         UpdateDocdates($action, $id, $data[4], $data[3]);
  1379.         UpdateChildren($action, $data);
  1380.         break;
  1381.     case 'mod' :
  1382.         UpdateDocFromInput($action, $id, $data);
  1383.         UpdateDocdates($action, $id, $data[4], $data[3]);
  1384.         break;
  1385.     case 'act' :
  1386.         UpdateDocid($data[AOF_ID], $data[AOF_STATUS]);
  1387.         UpdateDocFromDoc($action, $id, $data[AOF_STATUS]);
  1388.         if ('i' == $data[AOF_STATUS]) {
  1389.             DeactivateInCascade($data[AOF_TYPE], $id);
  1390.         }
  1391.         break;
  1392.     case 'del' :
  1393.         UpdateDocid($id, 'd');
  1394.         UpdateDocFromDoc($action, $id, 'd');
  1395.         UpdateDocdates($action, $id);
  1396.         DeleteInCascade($data[AOF_TYPE], $id);
  1397.         break;
  1398.     case 'sup' :
  1399.         ReadDoc($id);
  1400.         DestroyDBFile(DBBASE.TestFileId($id).INCEXT);
  1401.         DestroyDBFile(DBBASE.TestFileId($id).DBEXT);
  1402.         DestroyDBFile(DBIPBASE.TestFileId($id).DBEXT);
  1403.         $dbdocid = IndexDbFieldsByField(ReadDBFields(DOCID), 1);
  1404.         unset($dbdocid[$id]);
  1405.         WriteDBFields(DOCID, $dbdocid);
  1406.         $dbdates = IndexDbFieldsByField(ReadDBFields(DOCDATES), 0);
  1407.         unset($dbdates[$id]);
  1408.         WriteDBFields(DOCDATES, $dbdates);
  1409.         $dbchild = IndexDbFieldsByField(ReadDBFields(CHILDREN), 0);
  1410.         unset($dbchild[$id]);
  1411.         WriteDBFields(CHILDREN, $dbchild);
  1412.         DestroyInCascade($data[AOF_TYPE], $id);
  1413.         if ($data[AOF_TYPE] == TYP_ART) DestroyKeywords($id);
  1414.         break;
  1415.     }
  1416.     if ($reindex) {
  1417.         switch ($data[0]) {
  1418.         case TYP_LINKS     :
  1419.         case TYP_DNLOAD    :
  1420.         case TYP_PHOTO     :
  1421.         case TYP_FAQ       :
  1422.         case TYP_RSS       :
  1423.         case TYP_BSS       :
  1424.         case TYP_AGENDA    :
  1425.         case TYP_FREEBOX   :
  1426.         case TYP_MENUBOX   :
  1427.         case TYP_OPTMENU   :
  1428.         case TYP_DDMENUBOX :
  1429.         case TYP_OPTDDMENU :
  1430.         case TYP_MENUICO   :
  1431.         case TYP_SOCNET    :
  1432.             UpdateDBdtb($data[0]);
  1433.             break;
  1434.         case TYP_ART :
  1435.             UpdateDBdtb($data[0]);
  1436.             include_once CHEMIN.INCREP."funcrss.php";
  1437.             UpdateRSSart();
  1438.             UpdateRSSall();
  1439.             break;
  1440.         case TYP_BLOG :
  1441.             UpdateDBdtb($data[0]);
  1442.             include_once CHEMIN.INCREP."funcrss.php";
  1443.             UpdateRSSblog();
  1444.             UpdateRSSall();
  1445.             break;
  1446.         case TYP_NEWS :
  1447.             UpdateDBdtb($data[0]);
  1448.             include_once CHEMIN.INCREP."funcrss.php";
  1449.             UpdateRSSnews();
  1450.             UpdateRSSall();
  1451.             break;
  1452.         case TYP_REACT :
  1453.             UpdateDBreact($action, $id);
  1454.             break;
  1455.         case TYP_REBLOG :
  1456.             UpdateDBreblog($action, $id);
  1457.             break;
  1458.         case TYP_FORUM :
  1459.             UpdateDBforum($action, $id);
  1460.             break;
  1461.         }
  1462.         UpdateSitemaps($data[0]);
  1463.     }
  1464.     return $id;
  1465. }
  1466.  
  1467. function InitDBlog($typ) {
  1468.     global $site;
  1469.     $db = array();
  1470.     date_default_timezone_set('UTC');
  1471.     switch ($typ) {
  1472.     case 1  : $db[0] = array(date('H'), 'H', date('Y-m-d-H '));  break;
  1473.     case 12 : $db[0] = array(date('Y'), 'Y', date('Y'));         break;
  1474.     case 24 : $db[0] = array(date('D'), 'D', date('Y-m-d'));     break;
  1475.     case 31 : $db[0] = array(date('M'), 'M', date('Y-m'));       break;
  1476.     default : $db[0] = array(0,         '?', date('Y-m-d-H-i')); break;
  1477.     }
  1478.     date_default_timezone_set($site['TZ']);
  1479.     $db[1] = array_pad(array(), STATS_NBPAGE, 0);
  1480.     $db[2] = array_pad(array(), STATS_NBLANGUE, 0);
  1481.     $db[3] = array_pad(array(), STATS_NBBROWSER, 0);
  1482.     $db[4] = array_pad(array(), STATS_NBOS, 0);
  1483.     $db[5] = array_pad(array(), $typ, 0);
  1484.     $db[6] = array_pad(array(), $typ, 0);
  1485.     $db[7] = array(1);
  1486.     return $db;
  1487. }
  1488.  
  1489. function SaveOldDbLog($db) {
  1490.     global $statscfg;
  1491.     if (!empty($db[0][1])) {
  1492.         switch ($db[0][1]) {
  1493.         case 'D' :
  1494.         case 'M' :
  1495.             if ($statscfg[$db[0][1]] == 'on') {
  1496.                 WriteDbFields(OLDSSTATSREP.$db[0][2].DBEXT, $db);
  1497.             }
  1498.             break;
  1499.         case 'Y' :
  1500.             if ($statscfg[$db[0][1]] == 'on') {
  1501.                 WriteDbFields(OLDSSTATSREP.$db[0][2].DBEXT, $db);
  1502.                 $last = substr($db[0][2], 0, 4) - $statscfg['NBY'];
  1503.                 $files = ExploreFile(OLDSSTATSREP);
  1504.                 foreach ($files as $file) {
  1505.                     if (substr($file, 0, 4) <= $last) {
  1506.                         DestroyDbFile(OLDSSTATSREP.$file);
  1507.                     }
  1508.                 }
  1509.             }
  1510.             break;
  1511.         }
  1512.     }
  1513. }
  1514.  
  1515. function eMailTo($eSubject, $eMessage, $eTo)  {
  1516.     eMailHtmlTo($eSubject, "", $eTo, "", $eMessage);
  1517. }
  1518.  
  1519. function eMailHtmlTo($eSubject, $eMsgHtml, $eTo = '', $eFrom = '', $eMsgTxt = '')  {
  1520.     global $supervision, $user, $charset, $smtp;
  1521.     if (empty($eFrom)) $eFrom = trim($user[1]);
  1522.     $eFromF = $eFrom;
  1523.     $FromTo = $user[0];
  1524.     if ($eMsgTxt == '') {
  1525.         $eMsgText = strip_tags(preg_replace("!<br />|<br />|</p>!i", "\n", preg_replace("!<hr>|<hr />!i", "\n \n", $eMsgHtml)));
  1526.     }
  1527.     if ($eMsgHtml == '') {
  1528.         $eMsgHtml = str_replace("\n", "<br />", str_replace("\n \n", "<hr />", $eMsgTxt));
  1529.     }
  1530.     $std = $supervision[5] == 'standard_3' || $supervision[5] == 'standard_4';
  1531.     $eol = $std ? "\n" : "\r\n";
  1532.  
  1533.     $eSubject      = strtr($eSubject, array('à'=>'a', 'é'=>'e', 'è'=>'e', 'ê'=>'e', 'ë'=>'e', 'î'=>'i', 'ï'=>'i', 'ô'=>'o', 'û'=>'u', 'û'=>'u'));
  1534.     $eSubject      = preg_replace('![^-a-zA-Z0-9_ ]!i', '.', $eSubject);
  1535.     $eHeadersHtml  = "Content-Type: text/html; charset=\"".$charset."\"".$eol;
  1536.     $eHeadersHtml .= "Content-Transfer-Encoding: 8bit".$eol;
  1537.     $eSeparator    = $std ? '-----='.md5(uniqid(rand())) : "==S=E=P=A=R=A=T=O=R==";
  1538.     $eHeaders      = "MIME-Version: 1.0".$eol;
  1539.     $eHeaders     .= "Content-Type: multipart/alternative; boundary=\"".$eSeparator."\"".$eol;
  1540.     $eMessage      = '';
  1541.  
  1542.     if ($supervision[5] == 'standard' || $supervision[5] == 'standard_2' || $supervision[5] == 'phpmailer') {
  1543.         $eHeadersText  = "Content-Type: text/plain; charset=".$charset."\r\n";
  1544.         $eHeadersText .= "Content-Transfer-Encoding: 8bit\r\n";
  1545.         $eMessage      = "--".$eSeparator."\r\n".$eHeadersText."\r\n".$eMsgText."\r\n";
  1546.     }
  1547.     $eMessage .= "--".$eSeparator.$eol.$eHeadersHtml.$eol.$eMsgHtml.$eol;
  1548.     $eMessage .= "--".$eSeparator."--".$eol;
  1549.  
  1550.     $allTo = $eTo == '' ? explode(' ', trim($supervision[10])) : explode(' ', $eTo);
  1551.     $allTo = array_unique($allTo);
  1552.     $eTo   = count($allTo) == 1 ? $allTo[0] : $user[1];
  1553.     $cque  = '';
  1554.     foreach ($allTo as $adr) if ($adr != $eTo) $cque .= ' '.$adr;
  1555.     $allCC = explode(' ', trim($cque));
  1556.     $cque  = count($allTo) == 1 || $supervision[5] == 'phpmailer' ? '' : $eol."Cc: ".str_replace(' ', ',', trim($cque));
  1557.     $eFrom = $eFrom.$cque;
  1558.     if ($supervision[5] == 'standard') {
  1559.         @mail($eTo, $eSubject, $eMessage, 'From: '.$eFrom.$eol.$eHeaders);
  1560.     }
  1561.     else {
  1562.         if ($supervision[5] == 'phpmailer') {
  1563.             $eFiles = array();
  1564.         }
  1565.         include (CHEMIN.INCREP."mail/".$supervision[5].INCEXT);
  1566.     }
  1567. }
  1568.  
  1569. function BreakEMail($eminput) {
  1570.     $eminput = trim($eminput);
  1571.     $em1 = strpos($eminput,"@");
  1572.     $em2 = strrpos($eminput,".");
  1573.     $emoutput[0] = substr($eminput,0,$em1);
  1574.     $emoutput[1] = substr($eminput,$em1+1,$em2-$em1-1);
  1575.     $emoutput[2] = substr($eminput,$em2+1);
  1576.     return $emoutput;
  1577. }
  1578.  
  1579. function StartTimer() {
  1580.     global $starttime;
  1581.     $starttime = microtime(TRUE);
  1582. }
  1583.  
  1584. function StopTimer() {
  1585.     global $starttime;
  1586.     return round ((microtime(TRUE) - $starttime), 2);
  1587. }
  1588.  
  1589. function MakeSeed() {
  1590.     return microtime(TRUE);
  1591. }
  1592.  
  1593. function GenerateUID() {
  1594.     srand(MakeSeed());
  1595.     $gene = rand(1,9);
  1596.     for ($i = 0; $i <9; $i++) {
  1597.         $gene .= rand(0,9);
  1598.     }
  1599.     return $gene;
  1600. }
  1601.  
  1602. function KeepGoodChars($textin) {
  1603.     $textin  = strtr($textin, array(' '=>'_', 'à'=>'a', 'é'=>'e', 'è'=>'e', 'ê'=>'e', 'ë'=>'e', 'î'=>'i', 'ï'=>'i', 'ô'=>'o', 'û'=>'u', 'û'=>'u'));
  1604.     $textout = preg_replace("![^-a-zA-Z0-9_]!i","",$textin);
  1605.     return $textout;
  1606. }
  1607.  
  1608. function ValUnique($tableau) {
  1609.     for ($i = 0, $n = count($tableau); $i < $n; $i++) {
  1610.         $NewTableau[$tableau[$i]] = 1;
  1611.     }
  1612.     @reset($NewTableau);
  1613.     $KeyUnique = array();
  1614.     for ($i = 0, $n = count($NewTableau); $i < $n; $i++) {
  1615.         $KeyUnique[] = key($NewTableau);
  1616.         @next($NewTableau);
  1617.     }
  1618.     return $KeyUnique;
  1619. }
  1620.  
  1621. function compare_id1($a, $b) {
  1622.     return ($a[1] < $b[1] ? -1 : +1 );
  1623. }
  1624.  
  1625. function compare_db2($a, $b) {
  1626.     if ($a[1] == $b[1]) {
  1627.         return($a[2] < $b[2] ? -1 : +1);
  1628.     } else {
  1629.         return($a[1] < $b[1] ? -1 : +1);
  1630.     }
  1631. }
  1632.  
  1633. function GetNavBar(
  1634.     $url,
  1635.     $maxItem,
  1636.     $currentPage = 1,
  1637.     $nbItemPage = 10,
  1638.     $ancre = '',
  1639.     $imgBegin = '',
  1640.     $imgPrev = '',
  1641.     $imgNext = '',
  1642.     $imgEnd = '',
  1643.     $imgBeginN = '',
  1644.     $imgPrevN = '',
  1645.     $imgNextN = '',
  1646.     $imgEndN = '',
  1647.     $imgMinus = '',
  1648.     $imgPlus = '',
  1649.     $decade = 10,
  1650.     $tri = ''
  1651.     )
  1652. {
  1653.     global  $page, $site, $reptheme, $lng, $web;
  1654.     if (empty($web)) include_once CHEMIN.INCREP.'lang/'.$lng.'-web'.INCEXT;
  1655.     $imgBegin  = empty($imgBegin)  ? $reptheme.'/debut.png'      : $imgBegin;
  1656.     $imgPrev   = empty($imgPrev)   ? $reptheme.'/precedent.png'   : $imgPrev;
  1657.     $imgNext   = empty($imgNext)   ? $reptheme.'/suivant.png'     : $imgNext;
  1658.     $imgEnd    = empty($imgEnd)    ? $reptheme.'/fin.png'         : $imgEnd;
  1659.     $imgBeginN = empty($imgBeginN) ? $reptheme.'/debut_n.png'     : $imgBeginN;
  1660.     $imgPrevN  = empty($imgPrevN)  ? $reptheme.'/precedent_n.png' : $imgPrevN;
  1661.     $imgNextN  = empty($imgNextN)  ? $reptheme.'/suivant_n.png'   : $imgNextN;
  1662.     $imgEndN   = empty($imgEndN)   ? $reptheme.'/fin_n.png'       : $imgEndN;
  1663.     $imgMinus  = empty($imgMinus)  ? $reptheme.'/minuspg.png'     : $imgMinus;
  1664.     $imgPlus   = empty($imgPlus)   ? $reptheme.'/pluspg.png'      : $imgPlus;
  1665.     $decade    = TYP_SCREEN == 'WEB' ? $decade : 5;
  1666.  
  1667.     $out   = '';
  1668.     if ($maxItem > $nbItemPage) {
  1669.         $nbPage= $nbItemPage > 0 ? (ceil($maxItem/$nbItemPage)) : 1;
  1670.         $out .= '<div class="textCenter">';
  1671.         $out .= '<table class="textCenter marginAuto"><tr>';
  1672.         if ($currentPage > 1) {
  1673.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1674.                       <a href="'.$url.'1'.$ancre.'"><img src="'.$imgBegin.'" alt="'.$web[339].'" title="'.$web[339].'" /></a>
  1675.                     </td>';
  1676.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1677.                       <a href="'.$url.($currentPage-1).$ancre.'"><img src="'.$imgPrev.'" alt="'.$web[32].'" title="'.$web[32].'" /></a>
  1678.                     </td>';
  1679.         }
  1680.         else {
  1681.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1682.                       <img src="'.$imgBeginN.'" alt="'.$web[339].'" title="'.$web[339].'" />
  1683.                     </td>';
  1684.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1685.                       <img src="'.$imgPrevN.'" alt="'.$web[32].'" title="'.$web[32].'" />
  1686.                     </td>';
  1687.         }
  1688.         $out .= '<td class="navbarLeftW">';
  1689.         $nbpg = 1;
  1690.         $pgDebut = floor($currentPage / $decade) * $decade;
  1691.         $pgFin = ceil($currentPage / $decade) * $decade;
  1692.         if ($pgDebut == $pgFin) {
  1693.             $pgDebut = $pgFin - $decade;
  1694.         }
  1695.         if ($currentPage > $pgDebut && $currentPage <= $pgFin) {
  1696.             $decadeDebut = $pgDebut;
  1697.             $decadeFin   = $pgFin;
  1698.             $paq = $nbPage >= $decadeFin ? $decade : $nbPage - $decadeDebut;
  1699.         }
  1700.         if ($currentPage > $decade && $decadeDebut < $nbPage) {
  1701.             if ($nbPage - $decade + $decadeFin > $decade) {
  1702.                 $nbPrevPage = $decade;
  1703.             }
  1704.             else {
  1705.                 $nbPrevPage = $nbPage - $decade + $decadeFin;
  1706.             }
  1707.             if ($nbPrevPage > 1) {
  1708.                 $txtPrevPage = $nbPrevPage." ".$web[340];
  1709.             }
  1710.             else {
  1711.                 $txtPrevPage = $nbPrevPage." ".$web[341];
  1712.             }
  1713.             $out .= '<a href="'.$url.($currentPage + $decadeDebut - $decadeFin).$ancre.'">
  1714.                       <img src="'.$imgMinus.'" alt="'.$txtPrevPage.'" title="'.$txtPrevPage.'" class="imgMinus'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'" />
  1715.                     </a>';
  1716.         }
  1717.         $out .= ' [ ';
  1718.         for($i = 1; $i <= $paq; $i++) {
  1719.             if ($i + $decadeDebut <> $currentPage) {
  1720.                 $out .= '<a href="'.$url.($i + $decadeDebut).'">'.($nbpg + $decadeDebut).'</a> ';
  1721.             } else {
  1722.                 $out .= '
  1723. <style type="text/css">
  1724.  .currNum {
  1725.      text-decoration: underline;
  1726.      font: bold '.($page[2]+2).'px '.$page[1].';
  1727.  }
  1728. </style>
  1729.                <span class="currNum">'.($nbpg + $decadeDebut).'</span> ';
  1730.             }
  1731.             $nbpg++;
  1732.         }
  1733.         $out .= '] ';
  1734.         if($currentPage <= $decadeFin && $decadeFin < $nbPage) {
  1735.             if($nbPage - $decade - $decadeDebut > $decade) {
  1736.                 $nbSuivPage = $decade;
  1737.             }
  1738.             else {
  1739.                 $nbSuivPage = $nbPage - $decade - $decadeDebut;
  1740.             }
  1741.             if ($nbSuivPage > 1) {
  1742.                 $txtSuivPage = $nbSuivPage." ".$web[337];
  1743.             }
  1744.             else {
  1745.                 $txtSuivPage = $nbSuivPage." ".$web[336];
  1746.             }
  1747.             $out .= '<a href="'.$url.$tri.($i + $decadeDebut).$ancre.'">
  1748.                       <img src="'.$imgPlus.'" alt="'.$txtSuivPage.'" title="'.$txtSuivPage.'" class="imgPlus'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'" />
  1749.                     </a>';
  1750.         }
  1751.         $out .='</td>';
  1752.         if ($currentPage < $nbPage) {
  1753.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1754.                       <a href="'.$url.($currentPage + 1).$ancre.'"><img src="'.$imgNext.'" alt="'.$web[34].'" title="'.$web[34].'" /></a>
  1755.                     </td>';
  1756.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1757.                       <a href="'.$url.$nbPage.$ancre.'"><img src="'.$imgEnd.'" alt="'.$web[338].'" title="'.$web[338].'" /></a>
  1758.                     </td>';
  1759.         }
  1760.         else {
  1761.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1762.                       <img src="'.$imgNextN.'" alt="'.$web[34].'" title="'.$web[34].'" />
  1763.                     </td>';
  1764.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  1765.                       <img src="'.$imgEndN.'" alt="'.$web[338].'" title="'.$web[338].'" />
  1766.                     </td>';
  1767.         }
  1768.         $out .= '</tr></table></div>';
  1769.     }
  1770.     return $out;    
  1771. }
  1772.  
  1773. function Formatage($format, $in) {
  1774.     $out = '';
  1775.     if (!empty($in) && !empty($format)) {
  1776.         $out = str_replace(' ', '&nbsp;', sprintf($format, $in));
  1777.     }
  1778.     return $out;
  1779. }
  1780.  
  1781. function import($name, $origine = '', $striptags = TRUE, $value='') {
  1782.     switch ($origine) {
  1783.     case 'POST' :
  1784.         $var = isset($_POST[$name]) ? (empty($_POST[$name]) && $value != '' ? $value : $_POST[$name]) : $value;
  1785.         break;
  1786.     case 'GET':
  1787.         $var = isset($_GET[$name]) ? (empty($_GET[$name]) && $value != '' ? $value : $_GET[$name]) : $value;
  1788.         break;
  1789.     default :
  1790.         $var = isset($_POST[$name]) ? (empty($_POST[$name]) && $value != '' ? $value : $_POST[$name]) : (isset($_GET[$name]) ? (empty($_GET[$name]) && $value != '' ? $value : $_GET[$name]) : $value);
  1791.     }
  1792.     if (is_array($var) && $striptags) {
  1793.         foreach ($var as &$v1) {
  1794.             if (is_array($v1)) {
  1795.                 foreach ($v1 as &$v2) {
  1796.                     if (is_array($v2)) {
  1797.                         foreach ($v2 as &$v3) {
  1798.                             $v3 = strip_tags($v3);
  1799.                         }
  1800.                     } else {
  1801.                         $v2 = strip_tags($v2);
  1802.                     }
  1803.                 }
  1804.             } else {
  1805.                 $v1 = strip_tags($v1);
  1806.             }
  1807.         }
  1808.         return $var;
  1809.     } else {
  1810.         return $striptags ? strip_tags($var) : $var;
  1811.     }
  1812. }
  1813.  
  1814. function IncrNextID() {
  1815.     $nextidbk = ReadCounter(NEXTIDBK);
  1816.     $nextid   = ReadCounter(NEXTID) + 1;
  1817.     if ($nextid < $nextidbk) {
  1818.         $nextid = $nextidbk + 10;
  1819.     }
  1820.     while (file_exists(DBBASE.TestFileId($nextid).INCEXT)) {
  1821.         $nextid++;
  1822.     }
  1823.     WriteCounter(NEXTID, $nextid);
  1824.     if ($nextid > $nextidbk) {
  1825.         WriteCounter(NEXTIDBK, $nextid);
  1826.     }
  1827.     return $nextid;
  1828. }
  1829.  
  1830. function AsciiCompare($left,$right) {
  1831.     return strcasecmp($left,$right);
  1832. }
  1833.  
  1834. function SearchOption($serviz_actif, $members_inactif, $typ_code, $typ_nom) {
  1835.     global $userprefs, $members;
  1836.     if (!$serviz_actif) return;
  1837.     if ($userprefs[1] != '' || $members[0] != 'on' || $members_inactif) {
  1838.         return '
  1839.        <option value="'.$typ_code.'">'.$typ_nom.'</option>';
  1840.     }
  1841. }
  1842.  
  1843. function AddCHEMIN($dir) {
  1844.     if ('' == CHEMIN) return $dir;
  1845.     $pos = strpos($dir, CHEMIN);
  1846.     if (0 === $pos) {
  1847.         return $dir;
  1848.     } else {
  1849.         return CHEMIN.$dir;
  1850.     }
  1851. }
  1852.  
  1853. function ExploreDir($dir) {
  1854.     $dir = AddCHEMIN($dir);
  1855.     $array = array();
  1856.     $dossier = opendir($dir);
  1857.     while ($fichier = readdir($dossier)) {
  1858.         if ($fichier != "." && $fichier != ".." && is_dir($dir.$fichier) ) {
  1859.             $array[] = $fichier;
  1860.         }
  1861.     }
  1862.     closedir($dossier);
  1863.     sort($array);
  1864.     return $array;
  1865. }
  1866.  
  1867. function ExploreFile($dir) {
  1868.     $dir = AddCHEMIN($dir);
  1869.     $array = array();
  1870.     $dossier = opendir($dir);
  1871.     while ($fichier = readdir($dossier)) {
  1872.         if (is_file($dir.$fichier) && $fichier != 'index.php') {
  1873.             $array[] = $fichier;
  1874.         }
  1875.     }
  1876.     closedir($dossier);
  1877.     sort($array);
  1878.     return $array;
  1879. }
  1880.  
  1881. function ExploreImg($dir) {
  1882.     $dir = AddCHEMIN($dir);
  1883.     $array = array();
  1884.     $dossier = opendir($dir);
  1885.     while ($fichier = readdir($dossier)) {
  1886.         if (is_file($dir.$fichier) && $fichier != 'index.php') {
  1887.             $path_parts = basename($fichier);
  1888.             $path_parts = substr($path_parts,strrpos($path_parts,".")+1);
  1889.             if (IsImage($path_parts)) {
  1890.                 $array[] = $fichier;
  1891.             }
  1892.         }
  1893.     }
  1894.     closedir($dossier);
  1895.     sort($array);
  1896.     return $array;
  1897. }
  1898.  
  1899. function ForceToAbsolute_callback($m) {
  1900.     global $site;
  1901.     if (preg_match('!^(http|ftp|mailto)s?:!', $m[2])) {
  1902.         return $m[0];
  1903.     } else {
  1904.         if (strpos('#', $m[2]) === 0 ) {
  1905.             return $m[0];
  1906.         } else {
  1907.             return $m[1].$site[3].$m[2];
  1908.         }
  1909.     }
  1910. }
  1911.  
  1912. function ForceToAbsolute($s) {
  1913.     $s = preg_replace_callback('!( src=")([^"]*")!', 'ForceToAbsolute_callback', $s);
  1914.     $s = preg_replace_callback('!( href=")([^"]*")!', 'ForceToAbsolute_callback', $s);
  1915.     return $s;
  1916. }
  1917.  
  1918. function ReadFrSigns() {
  1919.     $tmp = parse_ini_file(FRSIGNS_INI, TRUE);
  1920.     ksort($tmp);
  1921.     return $tmp;
  1922. }
  1923.  
  1924. function WriteFrSigns($datas) {
  1925.     $tmp = '';
  1926.     foreach($datas as $code => $data) {
  1927.         $tmp .= '
  1928. ['.$code.']'.'
  1929. image='.$data['image'].'
  1930. status='.$data['status'].'
  1931. origine='.$data['origine'].'
  1932. ';
  1933.     }
  1934.     file_put_contents(FRSIGNS_INI, $tmp);
  1935. }
  1936.  
  1937. function ReplaceFrSigns($sign) {
  1938.     $sign    = str_replace(array(chr(10), chr(13)), '<br />', $sign);
  1939.     $frsigns = ReadFrSigns();
  1940.     foreach ($frsigns as $code => $frsign) {
  1941.         if ('a' == $frsign['status']) {
  1942.             if ('i' == $frsign['origine']) {
  1943.                 $sign = str_replace($code, '<img src="'.FRSIGNS_IMG.$frsign['image'].'" alt="" title="" />', $sign);
  1944.             } else {
  1945.                 $sign = str_replace($code, '<img src="'.$frsign['image'].'" alt="" title="" />', $sign);
  1946.             }
  1947.         } else {
  1948.             $sign = str_replace($code, '', $sign);
  1949.         }
  1950.     }
  1951.     return $sign;
  1952. }
  1953.  
  1954. function SelectDBThreadByThread($Fields, $id) {
  1955.     $DataDB = array();
  1956.     foreach ($Fields as $Field) {
  1957.         if ($Field[1] == $id && $Field[2] != '0') {
  1958.             $DataDB[] = $Field;
  1959.         }
  1960.     }
  1961.     return $DataDB;
  1962. }
  1963.  
  1964. function SelectDBForumByID($Fields, $id) {
  1965.     $DataDB = array();
  1966.     foreach ($Fields as $Field) {
  1967.         if ($Field[2] == $id) {
  1968.             $DataDB[] = $Field;
  1969.         }
  1970.     }
  1971.     return $DataDB;
  1972. }
  1973.  
  1974. function SelectDBForumByCat($Fields, $cat) {
  1975.     $DataDB = array();
  1976.     foreach ($Fields as $Field) {
  1977.         $temp = explode(',', $Field[12]);
  1978.         if ($cat == $temp[0]) {
  1979.             $DataDB[] = $Field;
  1980.         }
  1981.     }
  1982.     return $DataDB;
  1983. }
  1984.  
  1985. function PollCalculation() {
  1986.     $nb_rep_total = 0;
  1987.     $nb_rep_max   = 1;
  1988.     $dbpoll       = ReadDBFields(DBPOLL);
  1989.     $count_dbpoll = count($dbpoll);
  1990.     for ($i = 1; $i < $count_dbpoll; $i++) {
  1991.         $nb_rep_total = $nb_rep_total + $dbpoll[$i][3];
  1992.         $nb_rep_max = Max($nb_rep_max, $dbpoll[$i][3]);
  1993.     }
  1994.     $dbpoll[0][2] = $nb_rep_total;
  1995.     $dbpoll[0][3] = $nb_rep_max;
  1996.     for ($i = 1; $i < $count_dbpoll; $i++) {
  1997.         if (empty($dbpoll[$i][3])) {
  1998.             $dbpoll[$i][3] = 0;
  1999.             $dbpoll[$i][4] = 0;
  2000.         }
  2001.         else {
  2002.             $dbpoll[$i][4] = round($dbpoll[$i][3]/$nb_rep_total*10000)/100;
  2003.         }
  2004.     }
  2005.     return $dbpoll;
  2006. }
  2007.  
  2008. function SubmitButton($title, $onclick = '', $left = '', $right = '', $typ = 'submit') {
  2009.     global $boutonleft, $boutonright;
  2010.     $onclick = empty($onclick) ? ''           : ' onclick="'.$onclick.'"';
  2011.     $left    = empty($left)    ? $boutonleft  : $left;
  2012.     $right   = empty($right)   ? $boutonright : $right;
  2013.     return $left.'<button type="'.$typ.'" class="clsCursor submitButton" title="'.$title.'"'.$onclick.'>'.$title.'</button>'.$right;
  2014. }
  2015.  
  2016. function ImgSubmitButton($title, $left = '', $right = '', $background = '') {
  2017.     global $page, $reptheme;
  2018.     $left       = empty($left)       ? $reptheme.'/b_last.png'   : $left;
  2019.     $right      = empty($right)      ? $reptheme.'/b_right.png' : $right;
  2020.     $background = empty($background) ? $reptheme.'/b_ton.png'    : $background;
  2021.     return '<img src="'.CHEMIN.$left.'" style="vertical-align:top;" alt="" />'.
  2022. '<button type="submit" style="background:transparent url('.CHEMIN.$background.
  2023. ') repeat-x;  height:22px; margin:0; padding:0; border-radius:0; cursor:pointer;" title="'.$title.'">
  2024. '.$title.'</button><img src="'.CHEMIN.$right.'" style="vertical-align:top;" alt="" />';
  2025. }
  2026.  
  2027. function JavascriptFile($file) {
  2028.     return '
  2029. <script type="text/javascript" src="'.$file.'"></script>';
  2030. }
  2031.  
  2032. function BeginJavascript() {
  2033.     return '
  2034. <script type="text/javascript">
  2035. //<![CDATA[
  2036. <!--
  2037. ';
  2038. }
  2039.  
  2040. function EndJavascript() {
  2041.     return '
  2042. //-->
  2043. //]]>
  2044. </script>
  2045. ';
  2046. }
  2047.  
  2048. function ExecFunctionBox($pos, $box) {
  2049.     global $lng, $lang, $members, $nom, $page, $site, $serviz, $userprefs,
  2050.         $endurl, $npage, $pgtype, $topmess, $skn_logo, $flag1, $flag2,
  2051.         $tabcounter, $plugin_admin_name, $plugin_bar_name;
  2052.     $out = FALSE;
  2053.     if (!empty($box)) {
  2054.         $temp = explode(CONNECTOR, $box);
  2055.         $incl = isset($temp[0]) ? $temp[0] : '';
  2056.         $fnct = isset($temp[1]) ? $temp[1] : '';
  2057.         $args = isset($temp[2]) ? $temp[2] : '';
  2058.         if (!empty($incl) && is_file(CHEMIN.$incl.INCEXT)) {
  2059.             include_once CHEMIN.$incl.INCEXT;
  2060.         }
  2061.         if (!empty($fnct)) {
  2062.             if (empty($args)) {
  2063.                 $args = array_pad(array(), 5, '');
  2064.             } else {
  2065.                 $args = FALSE === strpos($args, ',') ? array($args) : explode(',', $args);
  2066.                 $args = array_pad($args, 5, '');
  2067.             }
  2068.             $out = $fnct($pos, $args);
  2069.         }
  2070.     }
  2071.     return $out;
  2072. }
  2073.  
  2074. function Checked($bool) {
  2075.     return $bool ? ' checked="checked"' : '';
  2076. }
  2077.  
  2078. function Selected($bool) {
  2079.     return $bool ? ' selected="selected"' : '';
  2080. }
  2081.  
  2082. function IsNotEmptyTitle($var) {
  2083.     global $lng, $lang;
  2084.     return $lng == $lang[0] ? !empty($var[2]) : !empty($var[3]);
  2085. }
  2086.  
  2087. function BreakIRC($ircinput) {
  2088.     $ircinput = trim($ircinput);
  2089.     $idirc = explode('@', $ircinput, 2);
  2090.     $ircoutput[0] = $idirc[0];
  2091.     $idtemp = explode('.', $idirc[1], 9);
  2092.     $ircoutput[1] = $idtemp[0];
  2093.     $ircoutput[2] = $idtemp[1];
  2094.     return $ircoutput;
  2095. }
  2096.    
  2097. // Utilisé pour trouver l'ID à partir du numéro de sujet (évite les &thrd=123 remplacé par pg=234)
  2098. function GetThreadId($thrd, $file = DBTHREAD) {
  2099.     $db = ReadDbFields($file);
  2100.     foreach ($db as $dbs) {
  2101.         if ($dbs[1] == $thrd && 0 == $dbs[2]) {
  2102.             return $dbs[3];
  2103.         }
  2104.     }
  2105.     return FALSE;
  2106. }
  2107.  
  2108. function getThreadName($thrd) {
  2109.     $db = ReadDbFields(DBFORUM);
  2110.     foreach ($db as $dbs) {
  2111.         if ($dbs[1] == $thrd) {
  2112.             return $dbs[5];
  2113.         }
  2114.     }
  2115.     return FALSE;
  2116. }
  2117.  
  2118. // Utilisé pour éviter des urls contenant &cat=&id=
  2119. function GetOptionnalArg($name, $value = '') {
  2120.     if (empty($value)) return '';
  2121.     return '&amp;'.$name.'='.$value;
  2122. }
  2123.  
  2124. // Utilisé avec array_reduce($array , 'EstNonVide') pour savoir si le tableau est vide
  2125. function EstNonVide ($r, $i) {
  2126.     return $r && empty($i);
  2127. }
  2128.  
  2129. function legend($legend) {
  2130.     return '<legend class="legend">'.$legend.'</legend>';
  2131. }
  2132.  
  2133. function getForumCat() {
  2134.     static $db_frcat = NULL;
  2135.     if (!isset($db_frcat)) {
  2136.         $frcat = ReadDBFields(DBFORUMCAT);
  2137.         $db_frcat = array();
  2138.         foreach ($frcat as $frc) {
  2139.             if (FALSE !== strpos($frc[0], ',')) {
  2140.                 $temp = explode(',', $frc[0]);
  2141.                 $db_frcat[$temp[0]] = $frc;
  2142.             } else {
  2143.                 $db_frcat[$frc[0]] = $frc;
  2144.             }
  2145.         }
  2146.     }
  2147.     return $db_frcat;
  2148. }
  2149.  
  2150. function getForumCatName($cat) {
  2151.     global $lng, $lang;
  2152.     $cat = getForumCatId($cat);
  2153.     $db_frcat = getForumCat();
  2154.     if (isset($db_frcat[$cat])) {
  2155.         return $db_frcat[$cat][$lng == $lang[0] ? 1 : 2];
  2156.     } else {
  2157.         return '--unknown--';
  2158.     }
  2159. }
  2160.  
  2161. function getForumCatFull($cat) {
  2162.     $cat = getForumCatId($cat);
  2163.     $db_frcat = getForumCat();
  2164.     if (isset($db_frcat[$cat])) {
  2165.         return $db_frcat[$cat][0];
  2166.     } else {
  2167.         return $cat;
  2168.     }
  2169. }
  2170.  
  2171. function getForumCatId($cat) {
  2172.     if (FALSE !== strpos($cat, ',')) {
  2173.         $temp = explode(',', $cat);
  2174.         $cat = $temp[0];
  2175.     }
  2176.     return $cat;
  2177. }
  2178.  
  2179. function AddPluginBox($label= '', $include = NULL, $function = '', $accept = 'LR', $args = '') {
  2180.     global $boxes;
  2181.     if ('' == $label || '' == $function) return FALSE;
  2182.     $boxes[] = array(
  2183.         'label' => $label,
  2184.         'include' => $include,
  2185.         'accept' => $accept,
  2186.         'function' => $function,
  2187.         'args' => $args
  2188.         );
  2189.     return TRUE;
  2190. }
  2191.  
  2192. function checkUserWebsiteUrl($url) {
  2193.     $url = trim($url);
  2194.     if (preg_match('/(ftp|http|https):\/\/[a-z0-9à-ö-]+(.[a-z0-9à-ö-]+)*(:[0-9]+)?(\/.*)?$/i', $url)) {
  2195.         return $url;
  2196.     }
  2197.     return 'http://';    
  2198. }
  2199.  
  2200. function checkEmail($email) {
  2201.     $email = trim($email);
  2202.     return filter_var($email, FILTER_VALIDATE_EMAIL) ? $email : '';
  2203. }
  2204.  
  2205. function displayWriteEmail($org, $author, $email, $img='', $class='') {
  2206.     global $web, $meskin;
  2207.     $lbl   = $img == '' ? ' <b>'.addslashes($author).'</b>' : $img;
  2208.     $class = empty($class) ? $org : $class;
  2209.     $em    = BreakEMail($email);
  2210.     if (TYP_SCREEN == 'MOB') {
  2211.         $out = $lbl;
  2212.     } else {
  2213.         $out = '
  2214.        <a class="'.$class.' gypoplight" href="#?w=300&amp;rel=popup_'.$org.'&amp;btn='.$web[57].'&amp;msk='.$meskin.'" title="'.$web[173].' '.$author.'">'.$lbl.'</a>
  2215.        <div class="'.$class.' gypopup_block" id="popup_'.$org.'">
  2216.          <p class="textCenter popupMail">'.$web[644].'</p>
  2217.          <p class="textCenter popupMail">
  2218.            <a href="javascript:showEmails'.$org.'(\''.$em[0].'\',\''.$em[1].'\',\''.$em[2].'\');">'.addslashes($author).'</a>
  2219.          </p>
  2220.          <p class="textCenter popupMail"><b><span id="lblemail'.$org.'">(--------------)</span></b></p>
  2221.        </div>';
  2222.         $out .=
  2223.         BeginJavascript().'
  2224.          function showEmails'.$org.'(em1, em2, em3) {
  2225.          var emailFinal = "<a href=\'mailto:" + em1 + "@" + em2 + "." + em3 + "\' onclick=\'{$(\'#gyfade , .gypopup_block\').fadeOut(function() {$(\'#gyfade, a.close\').remove();})};\'>" + em1 + " @ " + em2 + "." + em3 + "</a>";
  2226.            document.getElementById("lblemail'.$org.'").innerHTML = emailFinal;
  2227.          }
  2228.        '.EndJavascript();
  2229.     }
  2230.     return $out;
  2231. }
  2232.  
  2233. function getLabel($lbl, $idx=0) {
  2234.     if ($lbl == '' || $idx > 1) return '';
  2235.     $db = explode(CONNECTOR, $lbl);
  2236.     if (empty($db[$idx])) $db[$idx] = $db[0];
  2237.     return trim($db[$idx]);
  2238. }
  2239.  
  2240. function displayErrorMsg($label, $msg) {
  2241.     $sto = str_replace('<li>', '- ', str_replace('</li>', '\n', $msg));
  2242.     $out = '
  2243. <noscript>
  2244.  <fieldset class="bord dispError">
  2245.    <div dispError2>'.$label.'</div>
  2246.    <ul class="textLeft">'.$msg.'</ul>
  2247.  </fieldset>
  2248. </noscript>'.
  2249. BeginJavascript().'
  2250. sto = "'.$label.'\n\n" + "'.$sto.'";
  2251. alert(sto);
  2252. '.EndJavascript();
  2253.     return $out;
  2254. }
  2255.  
  2256. function DestroyKeywords($id) {
  2257.     $db = ReadDBFields(DBKEYWORDS);
  2258.     if (!empty($db)) {
  2259.         sort($db);
  2260.         $n = count($db);
  2261.         $j = 0;
  2262.         while ($db[$j][0] != $id && $j < $n - 1) $j++;
  2263.         for ($i = $j; $i < $n; $i++) {
  2264.             if ($db[$i][0] == $id) unset($db[$i]); else break;
  2265.         }
  2266.         WriteDBFields(DBKEYWORDS, $db);
  2267.     }
  2268. }
  2269.  
  2270. function UpdateKeywords($pg, $t1, $t2='', $k1='', $k2='', $tc=0) {
  2271.     $t1   = strip_tags($t1);
  2272.     $t2   = strip_tags($t2);
  2273.     $k1   = strtolower(substr($k1, -1) == ';' ? substr($k1, 0, -1) : $k1);
  2274.     $k2   = strtolower(substr($k2, -1) == ';' ? substr($k2, 0, -1) : $k2);
  2275.     $atc  = explode('|', $tc);
  2276.     $db   = ReadDBFields(DBKEYWORDS);
  2277.     $i    = 0;
  2278.     $find = false;
  2279.     foreach ($db as $dbs) {
  2280.         if ($pg == $dbs[0]) {
  2281.             $db[$i][1] = $t1;
  2282.             $db[$i][2] = $t2;
  2283.             $db[$i][3] = $k1;
  2284.             $db[$i][4] = $k2;
  2285.             $db[$i][5] = $atc[0];
  2286.             $find      = true;
  2287.             if (trim($k1.$k2) == '') unset($db[$i]);
  2288.             break;
  2289.         }
  2290.         $i++;
  2291.     }
  2292.     if (!$find) {
  2293.         $i         = count($db);
  2294.         $db[$i][0] = $pg;
  2295.         $db[$i][1] = $t1;
  2296.         $db[$i][2] = $t2;
  2297.         $db[$i][3] = $k1;
  2298.         $db[$i][4] = $k2;
  2299.         $db[$i][5] = $atc[0];
  2300.     }
  2301.     WriteDBFields(DBKEYWORDS, $db);
  2302. }
  2303.  
  2304. function GetKeywords($pg) {
  2305.     global $lang, $lng, $site, $urlrw, $z2,
  2306.     $fileid,$status,$creadate,$moddate,$author,$email,
  2307.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  2308.     $fieldweb,$fieldmail,$fieldmod;
  2309.     $keywords = '';
  2310.     $dbks     = ReadDBFields(DBKEYWORDS);
  2311.     $dbw      = array();
  2312.     foreach ($dbks as $dbk) {
  2313.         if ($pg == $dbk[0]) {
  2314.             $dbw = explode(';', ($lng == $lang[0] ? $dbk[3] : $dbk[4]));
  2315.             break;
  2316.         }
  2317.     }
  2318.     if (!empty($dbw)) {
  2319.         $dbwords = array();
  2320.         $i       = 0;
  2321.         $j       = -1;
  2322.         foreach ($dbks as $dbk) {
  2323.             if ($pg == $dbk[0]) continue;
  2324.             $kws = explode(';', ($lng == $lang[0] ? $dbk[3] : $dbk[4]));
  2325.             foreach ($kws as $kw) {
  2326.                 $dbwords[$i][0] = $kw;
  2327.                 $dbwords[$i][1] = $dbk[0];
  2328.                 $dbwords[$i][2] = $lng == $lang[0] ? $dbk[1] : $dbk[2];
  2329.                 $dbwords[$i][3] = empty($dbk[5]) ? 0 : $dbk[5];
  2330.                 $i++;
  2331.             }
  2332.         }
  2333.         sort($dbwords);
  2334.         $wexist = false;
  2335.         $words  = '';
  2336.         $i      = count($dbwords);
  2337.         foreach ($dbw as $word) {
  2338.             $kw = ' ';
  2339.             $nk = 0;
  2340.             if (!empty($dbwords)) {
  2341.                 $j = 0;
  2342.                 while ($dbwords[$j][0] != $word && $j < $i - 1) $j++;
  2343.                 for ($k = $j; $k < $i; $k++) {
  2344.                     if ($dbwords[$k][0] != $word) break;
  2345.                     ReadDoc($dbwords[$k][1]);
  2346.                     if (isAuthorizedPublication($creadate) && isAccessGranted($fieldmod) && $status == 'a') {
  2347.                         $dbwo = ReadDBFields(DBOPTMENU);
  2348.                         foreach ($dbwo as $item) {
  2349.                             ReadDoc($item[4]);
  2350.                             if (!isAuthorizedPublication($creadate) || !isAccessGranted($fieldmod)) continue;
  2351.                             $urls = explode('||', $lng == $lang[0] ? $fieldd1 : $fieldd2);
  2352.                             $pg   = substr($urls[0], strpos($urls[0], 'pg=') + 3);
  2353.                             $pos  = strpos($pg, '&');
  2354.                             $pg   = $pos === false ? $pg : substr($pg, 0, $pos);
  2355.                             if ($pg == $dbwords[$k][1]) {
  2356.                                 $url0 = 'articles.php?lng='.$lng.'&pg='.$pg.'&mnuid='.$item[5].'&tconfig='.$fieldmail.$z2;
  2357.                                 $url1 = $lng.'-'.$urlrw[20].'-103-'.$pg.'-'.$item[5].'-'.$fieldmail.$z2;
  2358.                                 $url = $site['URLR'] == 'on' ? $url1 : $url0;
  2359.                                 $kw .= '<a href="'.$url.'">'.$dbwords[$k][2].'</a><br />';
  2360.                                 $nk++;
  2361.                                 $wexist = true;
  2362.                                 break;
  2363.                             }
  2364.                         }
  2365.                     }
  2366.                 }
  2367.             }
  2368.             $kw = trim($kw) != '' ? '<div>'.$kw.'</div>' : '';
  2369.             if ($nk > 5) $class = 'keyword3';
  2370.             elseif ($nk > 3) $class = 'keyword2';
  2371.             elseif ($nk > 1) $class = 'keyword1';
  2372.             else $class = 'keyword0';
  2373.             if (trim($word) != '' && $nk > 0) {
  2374.                 if ($kw != '')
  2375.                     $word = '
  2376.       <li class="dir"><span class="'.$class.'">'.$word.'</span><ul><li>'.$kw.'</li></ul></li>';
  2377.                 else
  2378.                     $word = '
  2379.       <li><span class="'.$class.'">'.$word.'</span></li>';
  2380.                 $words .= $word;
  2381.             }
  2382.         }
  2383.         if ($words != '')
  2384.             $keywords = '
  2385.     <ul class="keyword keyword-horizontal">
  2386.       '.$words.'
  2387.     </ul>';
  2388.     }
  2389.     return $keywords;
  2390. }
  2391.  
  2392. function displayQuickConfig($pos, $id = false, $edit = '', $desact = '', $del = '', $drt = false) {
  2393.     global $lng, $page, $reptheme, $web, $userprefs, $serviz, $drtuser;
  2394.     $drtuser[42] = $serviz[31] == $userprefs[1] ? 'admin' : '';
  2395.     if (is_file(CHEMIN.'admin/'.REDACREP.$userprefs[1].INCEXT)) include CHEMIN.'admin/'.REDACREP.$userprefs[1].INCEXT;
  2396.     $isdrt  = $drt ? $drtuser[$drt] == "on" : false;
  2397.     $access = true;
  2398.     $id     = TestFileID($id);
  2399.     if ($drtuser[42] != 'admin' && $id !== FALSE && FileDBExist(DBBASE.$id.INCEXT)) {
  2400.         include(DBBASE.$id.INCEXT);
  2401.         $temp   = explode('|', $author);
  2402.         $author = $temp[0];
  2403.         $grpc   = isset($temp[1]) ? $temp[1] : '';
  2404.         $access = $grpc == '' ? ($author == $userprefs[1]) : isAccessGrantedCol($grpc);
  2405.     }
  2406.     if ($serviz[32] == "on" && ($drtuser[42] == 'admin' || $isdrt) && TYP_SCREEN == 'WEB') {
  2407.         $config = $pos == BOX_EDITO ? 'config3' : 'config6';
  2408.         $img    = $pos == BOX_EDITO ? 'cfgaccueil' : 'cfgboites';
  2409.         $txt    = $pos == BOX_EDITO ? $web[686] : $web[689];
  2410.         $ret = '
  2411.    <div class="f-right">';
  2412.         $ret .= !$access || in_array($drtuser[42], array('redac1', 'redac2')) || is_null($pos) ? '' : '
  2413.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$config.'&amp;selskin='.$page[14].'">
  2414.        <img src="'.$reptheme.'/'.$img.'.png" alt="'.$txt.'" title="'.$txt.'" class="valignMiddle img11x11" />
  2415.      </a>';
  2416.         $ret .= !$access || $edit == '' ? '' : '
  2417.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$edit.'">
  2418.        <img src="'.$reptheme.'/edit.png" alt="'.$web[308].'" title="'.$web[308].'" class="valignMiddle" />
  2419.      </a>';
  2420.         $ret .= !$access || $desact == '' ? '' : '
  2421.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$desact.'">
  2422.        <img src="'.$reptheme.'/desact.png" alt="'.$web[333].'" title="'.$web[333].'" class="valignMiddle" />
  2423.      </a>';
  2424.         $ret .= !$access || $del == '' ? '' : '
  2425.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$del.'">
  2426.        <img src="'.$reptheme.'/del.png" alt="'.$web[324].'" title="'.$web[324].'" class="valignMiddle" />
  2427.      </a>';
  2428.         $ret .= '
  2429.    </div>';
  2430.     } else
  2431.         $ret = '';
  2432.     return $ret;
  2433. }
  2434.  
  2435. function getNewUpdateDoc($crea, $mod, $accept='off') {
  2436.     global $reptheme, $userprefs, $web, $serviz;
  2437.     if ($accept == 'off' || ($accept == 'mbr' && $userprefs[1] == '') || $serviz[135] <= 0) return '';
  2438.     $img     = '';
  2439.     $ctrlday = date('Ymdhi', strtotime('-'.$serviz[135].' day'));
  2440.     if ($mod > $crea && $mod > $ctrlday) $img = 'majdoc';
  2441.     if (($mod - $crea) == 0 && $crea > $ctrlday) $img = 'newdoc';
  2442.     $title = $img == 'majdoc' ? $web[196] : $web[371];
  2443.     return empty($img) ? '' : '<img src="'.$reptheme.'/'.$img.'.gif" alt="'.$title.'" title="'.$title.'" class="valignMiddle" />&nbsp;';
  2444. }
  2445.  
  2446. function setURLrewriting($mode) {
  2447.     global $urlrw, $site;
  2448.     if (!is_file(CHEMIN.'.htaccess')) return;
  2449.     $stop     = '# URL rewriting'.chr(13).chr(10);
  2450.     $htaccess = file(CHEMIN.'.htaccess');
  2451.     switch ($mode) {
  2452.     case 'on' :
  2453.         if (in_array($stop, $htaccess)) break;
  2454.         $uheader = file(CONFIGREP.'uheader.dtb');
  2455.         $urules  = file(CONFIGREP.'urules.dtb');       
  2456.         for ($i = 0; $i < count($urules); $i++) {
  2457.             $pos = strpos($urules[$i], '##');
  2458.             $st = $pos === false ? '' : substr($urules[$i], $pos + 2);
  2459.             $st = $st == '' ? '' : substr($st, 0, strpos($st, '##'));
  2460.             if ($st != '') $urules[$i] = str_replace('##'.$st.'##', $site[$st], $urules[$i]);
  2461.             $pos = strpos($urules[$i], '#');
  2462.             $st = $pos === false ? '' : substr($urules[$i], $pos + 1);
  2463.             $st = $st == '' ? '' : substr($st, 0, strpos($st, '#'));
  2464.             if ($st != '') $urules[$i] = str_replace('#'.$st.'#', $urlrw[$st], $urules[$i]);
  2465.         }
  2466.         if ($htaccess[count($htaccess) - 1] == chr(13).chr(10)) unset($htaccess[count($htaccess) - 1]);
  2467.         $htaccess = array_merge($htaccess, $uheader, $urules);
  2468.         $dir      = CONFIGREP.'rules/';
  2469.         if (is_dir($dir)) {
  2470.             $files = scandir($dir);
  2471.             if ($files !== false) {
  2472.                 foreach ($files as $file) {
  2473.                     $info = pathinfo($file);
  2474.                     if (isset($info['extension']) && $info['extension'] == 'dtb') {
  2475.                         $rules    = file($dir.$file);
  2476.                         $htaccess = array_merge($htaccess, $rules);
  2477.                         unset($rules);
  2478.                     }
  2479.                 }
  2480.                 unset($allrules);
  2481.             }
  2482.         }      
  2483.         $st = '';
  2484.         foreach ($htaccess as $hta) $st .= $hta;
  2485.         $perms = substr(sprintf('%o', fileperms(CHEMIN.'.htaccess')), -4);
  2486.         SetChmod(CHEMIN.'.htaccess');
  2487.         $handle = fopen(CHEMIN.'.htaccess', 'w');
  2488.         fwrite($handle, $st);
  2489.         fclose($handle);
  2490.         SetChmod(CHEMIN.'.htaccess', $perms);
  2491.         break;
  2492.     case '' :
  2493.         if (!in_array($stop, $htaccess)) break;
  2494.         $st = '';
  2495.         foreach ($htaccess as $hta)
  2496.             if ($hta != $stop) $st .= $hta; else break;
  2497.         $perms = substr(sprintf('%o', fileperms(CHEMIN.'.htaccess')), -4);
  2498.         SetChmod(CHEMIN.'.htaccess');
  2499.         $handle = fopen(CHEMIN.'.htaccess', 'w');
  2500.         fwrite($handle, $st);
  2501.         fclose($handle);
  2502.         SetChmod(CHEMIN.'.htaccess', $perms);
  2503.         break;
  2504.     }
  2505. }
  2506.  
  2507. function isAuthorizedPublication($pdate) {
  2508.     $datespub = explode('-', $pdate);
  2509.     $datenow  = GetCurrentDateTime();
  2510.     return ($datespub[0] <= $datenow) && (empty($datespub[1]) ? true : $datespub[1] > $datenow);
  2511. }
  2512.  
  2513. function GetListCollaboratorEmail($typ) {
  2514.     global $drtuser;
  2515.     $drt    = array(TYP_NEWS => 14, TYP_BLOG => 39, TYP_REBLOG => 40, TYP_GUESTBK => 22, TYP_FORUM => 23, TYP_REACT => 16);
  2516.     $drtsv  = array(TYP_NEWS => 2,  TYP_BLOG => 3,  TYP_REBLOG => 4,  TYP_GUESTBK => 5,  TYP_FORUM => 6,  TYP_REACT => 1);
  2517.     $dbcoll = array();
  2518.     $dbwork = scandir(CHEMIN.'admin/'.REDACREP);
  2519.     foreach($dbwork as $file) {
  2520.         $info = pathinfo($file);
  2521.         if (isset($info['extension']) && $info['extension'] == 'inc') {
  2522.             $coll = $info['filename'];
  2523.             if (is_file(CHEMIN.'admin/'.REDACREP.$coll.INCEXT)) {
  2524.                 include CHEMIN.'admin/'.REDACREP.$coll.INCEXT;
  2525.                 if ($drtuser[$drt[$typ]] == 'on' && $drtusersv[$drtsv[$typ]] == 'on' && file_exists(MSGREP.$coll.DBEXT)) {
  2526.                     $userdb = ReadDBFields(MSGREP.$coll.DBEXT);
  2527.                     $dbcoll[] = $userdb[1][3];
  2528.                 }
  2529.             }
  2530.         }
  2531.     }
  2532.     return $dbcoll;
  2533. }
  2534.  
  2535. function RecursiveRemoteDir($dir) {
  2536.     if (is_dir($dir)) {
  2537.         $files = scandir($dir);
  2538.         foreach ($files as $file) {
  2539.             if ($file != '.' && $file != '..') {
  2540.                 if (filetype($dir.'/'.$file) == 'dir')
  2541.                     RecursiveRemoteDir($dir.'/'.$file);
  2542.                 else
  2543.                     DestroyDBFile($dir.'/'.$file);
  2544.             }
  2545.         }
  2546.         reset($files);
  2547.         SetChmod($dir);
  2548.         @rmdir($dir);
  2549.     }
  2550. }
  2551.  
  2552. function RecursiveDeleteDir($dir, $bad = array('index.php', '.htaccess')) {
  2553.     if (is_dir($dir)) {
  2554.         $files = scandir($dir);
  2555.         foreach ($files as $file) {
  2556.             if ($file != '.' && $file != '..') {
  2557.                 if (filetype($dir.'/'.$file) == 'dir')
  2558.                     RecursiveDeleteDir($dir.'/'.$file);
  2559.                 elseif (!in_array($file, $bad))
  2560.                     DestroyDBFile($dir.'/'.$file);
  2561.             }
  2562.         }
  2563.         reset($files);
  2564.     }
  2565. }
  2566.  
  2567. function DeleteDir($dir, $bad = array('index.php', '.htaccess')) {
  2568.     if (is_dir($dir)) {
  2569.         $files = scandir($dir);
  2570.         foreach ($files as $file) {
  2571.             if ($file != '.' && $file != '..') {
  2572.                 if (!in_array($file, $bad))
  2573.                     DestroyDBFile($dir.'/'.$file);
  2574.             }
  2575.         }
  2576.         reset($files);
  2577.     }
  2578. }
  2579.  
  2580. function recursiveCopy($src, $dest) {
  2581.     $dir = opendir($src);
  2582.     MakeDir($dest);
  2583.     while (false !== ($file = readdir($dir))) {
  2584.         if (($file != '.') && ($file != '..')) {
  2585.             if (is_dir($src.'/'.$file))
  2586.                 recursiveCopy($src.'/'.$file, $dest.'/'.$file);
  2587.             else
  2588.                 copy($src.'/'.$file, $dest.'/'.$file);
  2589.         }
  2590.     }
  2591.     closedir($dir);
  2592. }
  2593.  
  2594. function ReplaceSpecialChars($text) {
  2595.     $chars_in  = array('$', '%', '.', '/', ':', '<', '=', '>', '?', '[', ']', '^', '{', '}');
  2596.     $chars_out = array('&#036;', '&#037;', '&#046;', '&#047;', '&#058;', '&#060;', '&#061;', '&#062;', '&#063;', '&#091;', '&#093;', '&#094;', '&#123;', '&#125;');
  2597.     return str_replace($chars_in, $chars_out, $text);
  2598. }
  2599.  
  2600. function SetChmod($file, $mode='') {
  2601.     global $site;
  2602.     $site['MF'] = empty($site['MF']) ? '0644' : $site['MF'];
  2603.     $site['MD'] = empty($site['MD']) ? '0755' : $site['MD'];
  2604.     $typ        = is_dir($file) ? 'dir' : 'file';
  2605.     $value      = empty($typ) || $typ == 'file' ? $site['MF'] : $site['MD'];
  2606.     $value      = empty($mode) ? $value : $mode;
  2607.     return @chmod($file, intval($value, 8));
  2608. }
  2609.  
  2610. function MakeDir($dir, $mode='') {
  2611.     global $site;
  2612.     $value = empty($site['MD']) ? '0755' : $site['MD'];
  2613.     $value = empty($mode) ? $value : $mode;
  2614.     return @mkdir($dir, intval($value, 8));
  2615. }
  2616.  
  2617. function DisplayDownArrow($dynbox) {
  2618.     $rarrow = '<span class="dispArrow" title="">&#xe807;</span>';
  2619.     return TYP_SCREEN == 'WEB' ? '' : ($dynbox == 'off' ? '' : $rarrow);
  2620. }
  2621.  
  2622. function getIPadress($adress) {
  2623.     if (strstr($adress, ', ')) {
  2624.         $ips = explode(', ', $adress);
  2625.         $adress = $ips[0];
  2626.     }
  2627.     return $adress;
  2628. }
  2629.  
  2630. function getPGTXT($stxt='') {
  2631.     $txt = '';
  2632.     while(!empty($stxt)) {
  2633.         $pos0 = mb_strpos($stxt, '<pre class=');
  2634.         $pos1 = mb_strlen($stxt);
  2635.         $txt0 = htmlspecialchars_decode(mb_substr($stxt, 0, $pos0 !== false ? $pos0 : $pos1));
  2636.         if (!empty($txt0)) {
  2637.             $simg = $txt0;
  2638.             $txt1 = '';
  2639.             while(!empty($simg)) {
  2640.                 $sp0 = mb_strpos($simg, '<img');
  2641.                 $sp1 = mb_strlen($simg);
  2642.                 if ($sp0 !== false) {
  2643.                     $sp1  = mb_strpos(mb_substr($simg, $sp0), '>');
  2644.                     $img  = mb_substr($simg, $sp0, $sp1 + 1);
  2645.                     $txt0 = preg_match('!https?://|ftps?://|www.!', $img) ? str_replace($img, '', $txt0) : $txt0;
  2646.                 }
  2647.                 $simg = trim(mb_substr($simg, $sp1 + 1));
  2648.             }
  2649.         }
  2650.         $txt .= $txt0;
  2651.         if ($pos0 !== false) {
  2652.             $pos1 = mb_strpos($stxt, '</pre>') + 6;
  2653.             $txt .= mb_substr($stxt, $pos0, $pos1 - $pos0);
  2654.         }
  2655.         $stxt = trim(mb_substr($stxt, $pos1));
  2656.     }
  2657.     return $txt;
  2658. }
  2659.  
  2660. ?>
  2661. <?php
  2662. /*******************************************************************************
  2663.  *   Functions
  2664.  *******************************************************************************
  2665.  *   GuppY PHP Script - version 5.0
  2666.  *   CeCILL Copyright (C) 2004-2014 by Laurent Duveau
  2667.  *   Initiated by Laurent Duveau and Nicolas Alves
  2668.  *   Web site = http://www.freeguppy.org/
  2669.  *   e-mail   = guppy@freeguppy.org
  2670.  *   V5 developed by Lud Bienaimé
  2671.  *      with the participation of Jean-Michel Misrachi and the GuppY Team
  2672.  *******************************************************************************
  2673.  *   Version History :
  2674.  * v5.0.0 (February 15, 2014)    : initial release.
  2675.  * v5.0.1 (March 08, 2014)       : correction calculation of maximum id in IncrNextID()
  2676.  *                               : adding functions SetChmod() ans MakeDir()
  2677.  * v5.0.2 (March 25, 2014)       : correction image display for new document
  2678.  *                               : corrected writing in robots.txt for sitemaps
  2679.  *                               : corrected import docs with &#36;
  2680.  * v5.0.3 (April 15, 2014)       : corrected sitemaps url
  2681.  *                               : corrected update index for confirmation
  2682.  * v5.0.4 (April 30, 2014)       : corrected list of adressees in eMailHtmlTo()
  2683.  *                               : function corrected for duplicates
  2684.  * v5.0.5 (June 07, 2014)        : add plugins rules for url_rw
  2685.  * v5.0.7 (August 21, 2014)      : corrected displayErrorMsg() function
  2686.  * v5.0.8 (October 02, 2014)     : corrected email function
  2687.  *                               : changed the calculation of the number of characters
  2688.  *                                 in the CutLongWord() function (thanks Ludo)
  2689.  * v5.0.9 (November 28, 2014)    : add types of mail standard_3 and standard_4
  2690.  *                               : corrected UpdateDBforum() in edit mode of thread
  2691.  * v5.00.11 (March 02, 2015)     : improve displayQuickConfig() function
  2692.  *                               : add hyphen in the nickname
  2693.  * v5.01.00 (June 12, 2015)      : add ckeckbox for hostings behind a cache (thanks jcp)
  2694.  *                               : corrected quick admin access (thanks Icare)
  2695.  * v5.01.01 (September 02, 2015) : add parameter $ancre in GetNavbar()
  2696.  * v5.01.03 (June 07, 2016)      : corrected $eFrom in eMailHtmlTo() function
  2697.  *                               : replace css properties by class rules
  2698.  *                               : correction of the import() function to the $value management
  2699.  *                               : add getIPadress() function
  2700.  * v5.01.04 (September 07, 2016) : correction for quick admin icons display
  2701.  *                               : adding a height limitation of the display article
  2702.  * v5.01.07 (January 04, 2016)   : correction of the import() function for array value
  2703.  *                               : correction of eMailHtmlTo() function with phpmailer 5.2.21
  2704.  * v5.02.00 (May 09, 2017)       : adding $_DOMAIN and $_SECURE for cookies management
  2705.  *                               : suppress flash management
  2706.  * v5.02.00-1 (May 22, 2017)     : correction of getNewUpdateDoc() function
  2707.  * v5.02.01 (August 28, 2017)    : improve checkEmail() function (thanks jchouix)
  2708.  *                               : adding function getPGTXT()
  2709.  *                               : addition of the choice of date formats for both languages
  2710.  *                               : adding function is_ssl()
  2711.  ******************************************************************************/
  2712.  
  2713. if (stristr($_SERVER['SCRIPT_NAME'], 'functions.php')) {
  2714.   header('location:../index.php');
  2715.   die();
  2716. }
  2717.  
  2718. include_once CHEMIN.'inc/constantes.php';
  2719.  
  2720. function is_ssl() {
  2721.     if (isset($_SERVER['HTTPS'])) {
  2722.         if ('on' == strtolower($_SERVER['HTTPS'])) return true;
  2723.         if ('1' == $_SERVER['HTTPS']) return true;
  2724.     } elseif (isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] )) {
  2725.         return true;
  2726.     } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']))) {
  2727.         return true;
  2728.     } elseif (isset($_SERVER['X_FORWARDED_PROTO']) && ('https' == strtolower($_SERVER['X_FORWARDED_PROTO']))) {
  2729.         return true;
  2730.     } elseif (isset($_SERVER['HTTP_X_FORWARDED_SSL']) && 'on' == strtolower($_SERVER['HTTP_X_FORWARDED_SSL'])) {
  2731.         return true;
  2732.     } elseif (isset($_SERVER['X_FORWARDED_SSL']) && 'on' == strtolower($_SERVER['X_FORWARDED_SSL'])) {
  2733.         return true;
  2734.     } elseif (isset($_SERVER['HTTP_X_FORWARDED_HTTPS']) && 'on' == strtolower($_SERVER['HTTP_X_FORWARDED_HTTPS'])) {
  2735.         return true;
  2736.     } elseif (isset($_SERVER['X_FORWARDED_HTTPS']) && 'on' == strtolower($_SERVER['X_FORWARDED_HTTPS'])) {
  2737.         return true;
  2738.     }
  2739.     return false;
  2740. }
  2741.  
  2742. $_DOMAIN = strtolower($_SERVER['HTTP_HOST']) != 'localhost' ? $_SERVER['HTTP_HOST'] : false;
  2743. $_SECURE = is_ssl() ? true : false;
  2744.  
  2745. $show_progbar  = FALSE;
  2746. $widepage      = '';
  2747. $headinc       = '';
  2748. $boutonleft    = '';
  2749. $boutoncenter  = '';
  2750. $boutonright   = '';
  2751. $meskin        = '';
  2752. $screen_choice = '';
  2753. $screen_icon   = '';
  2754. $mod_css       = '';
  2755. $mod_scr       = '';
  2756. $skn_logo      = '';
  2757. $skinCopyright = '';
  2758. $reptheme      = '';
  2759.  
  2760. $couleurs = array(
  2761.     'bleu', 'jaune', 'marron', 'or', 'orange', 'outremer', 'rose', 'rouge', 'vert', 'violet'
  2762.     );
  2763.  
  2764. $souriez = array(
  2765.     array('|:-)', 'inc/img/smileys/cool.gif',     'cool'),
  2766.     array(';-)',  'inc/img/smileys/wink.gif',     'wink'),
  2767.     array(':-))', 'inc/img/smileys/biggrin.gif',  'biggrin'),
  2768.     array(':-)',  'inc/img/smileys/smile.gif',    'smile'),
  2769.     array(':-o',  'inc/img/smileys/frown.gif',    'frown'),
  2770.     array(':o)',  'inc/img/smileys/eek.gif',      'eek'),
  2771.     array(':-((', 'inc/img/smileys/mad.gif',      'mad'),
  2772.     array(':-(',  'inc/img/smileys/confused.gif', 'confused'),
  2773.     array('8-)',  'inc/img/smileys/rolleyes.gif', 'rolleyes'),
  2774.     array(':-p',  'inc/img/smileys/tongue.gif',   'tongue'),
  2775.     array(';-(',  'inc/img/smileys/cry.gif',      'cry')
  2776.     );
  2777.  
  2778.  
  2779. function souriez($chaine) {
  2780.     global $souriez;
  2781.     foreach($souriez as $item) {
  2782.         $chaine = str_replace($item[0], '<img src="'.$item[1].'" title="'.$item[2].'" alt="'.$item[2].'" />', $chaine);
  2783.     }
  2784.     return $chaine;
  2785. }
  2786.  
  2787. function replaceimg($chaine) {
  2788.     global $souriez,$site;
  2789.     foreach($souriez as $item) {
  2790.         $chaine = str_replace($item[0], '<img src="'.$site[3].$item[1].'" title="'.$item[2].'" alt="'.$item[2].'" />', $chaine);
  2791.     }
  2792.     return $chaine;
  2793. }
  2794.  
  2795. function DrawSmileys($num) {
  2796.     global $souriez;
  2797.     for ($i = 0; $i < count($souriez); $i++) {
  2798.         echo '<a href="JavaScript:AddSmiley'.$num.'(\''.$souriez[$i][0].'\')"><img src="'.CHEMIN.$souriez[$i][1].'" class="clsCursor" title="'.$souriez[$i][0].'" alt="'.$souriez[$i][0].'" /></a>&nbsp;';
  2799.     }
  2800. }
  2801.  
  2802. function DrawSmileys2() {
  2803.     global $souriez;
  2804.     echo '&nbsp;';
  2805.     for ($i = 0; $i < count($souriez); $i++) {
  2806.         echo '&nbsp;<img src="'.CHEMIN.$souriez[$i][1].'" alt="'.$souriez[$i][2].'" title="'.$souriez[$i][2].'" />';
  2807.     }
  2808. }
  2809.  
  2810. function AfficheCompteur($chemino, $hits, $grow = 1) {
  2811.     $spot = '';
  2812.     for ($lecon = 0; $lecon < $grow - strlen($hits); $lecon++ ) {
  2813.         $spot .= '<img src="'.$chemino.'cnt0.gif" alt="" title="" />';
  2814.     }
  2815.     for ($lecon = 0; $lecon < strlen($hits); $lecon++) {
  2816.         $cols = substr($hits, $lecon, 1);
  2817.         $spot .= '<img src="'.$chemino.'cnt'.$cols.'.gif" alt="" title="" />';
  2818.     }
  2819.     return $spot;
  2820. }
  2821.  
  2822. function DejaVote($file_ip, $d_time = 0) {
  2823.     global $userprefs, $site;
  2824.     $remoteadr   = getIPadress($_SERVER[$site[6] == 'on' ? 'HTTP_X_FORWARDED_FOR' : 'REMOTE_ADDR']);
  2825.     $nbr_connect = 0;
  2826.     $var_bool    = FALSE;
  2827.     $user_bool   = FALSE;
  2828.     $subdata     = array();
  2829.     $var_ip      = array();
  2830.     $k           = 0;
  2831.     if ($d_time == 0) {
  2832.         $d_time = HIT_TIME;
  2833.     }
  2834.     $subdata  = ReadDBFields($file_ip);
  2835.     $now_time = time();
  2836.     foreach($subdata as $sub) {
  2837.         list($jour, $mois, $annee) = explode('/', substr($sub[1], 0, 10));
  2838.         list($heure, $minute, $seconde) = explode(':', substr($sub[1], 10, 18));
  2839.         if ($now_time < mktime((int)$heure, (int)$minute, (int)$seconde, (int)$mois, (int)$jour, (int)$annee) + $d_time) {
  2840.             $nbr_connect++;
  2841.             $var_ip[$k][0] = $sub[0];
  2842.             if ($remoteadr == $sub[0]) {
  2843.                 $var_bool = TRUE;
  2844.             }
  2845.             $var_ip[$k][1] = $sub[1];
  2846.             if ($userprefs[5] != '') {
  2847.                 $uprefname = $userprefs[1];
  2848.             }
  2849.             else {
  2850.                 $uprefname = '';
  2851.             }
  2852.             if ($remoteadr == $sub[0] && $uprefname != $sub[2]) {
  2853.                 $user_bool = TRUE;
  2854.                 $var_ip[$k][2] = $uprefname;
  2855.             }
  2856.             else {
  2857.                 $var_ip[$k][2] = $sub[2];
  2858.             }
  2859.             $k++;
  2860.         }
  2861.     }
  2862.     if (!$var_bool) {
  2863.         $var_ip[$k][0] = $remoteadr;
  2864.         $var_ip[$k][1] = date('d/m/Y H:i:s');
  2865.         $var_ip[$k][2] = $userprefs[1];
  2866.         WriteDBFields($file_ip,$var_ip);
  2867.         $nbr_connect++;
  2868.     }
  2869.     elseif ($user_bool) {
  2870.         WriteDBFields($file_ip, $var_ip);
  2871.     }
  2872.     return array($var_bool, $nbr_connect);
  2873. }
  2874.  
  2875. function CompteVisites($file_ip, $file_counter) {
  2876.     $subdata = DejaVote($file_ip);
  2877.     $nbr_visit = ReadCounter($file_counter);
  2878.     if (!$subdata[0] && ($nbr_visit >= 0)) {
  2879.         $nbr_visit++;
  2880.         WriteCounter($file_counter,$nbr_visit);
  2881.     }
  2882.     return array($nbr_visit, $subdata[1]);
  2883. }
  2884.  
  2885. function IsImage($extn) {
  2886.     $extn = strtolower($extn);
  2887.     if ($extn == 'gif' || $extn == 'jpg' || $extn == 'jpeg' || $extn == 'png' || $extn == 'bmp') {
  2888.         return TRUE;
  2889.     } else {
  2890.         return FALSE;
  2891.     }
  2892. }
  2893.  
  2894. function ExtImage($extn){
  2895.     switch(strtolower($extn)) {
  2896.     case 'bat'  : return 'bat';
  2897.     case 'bmp'  : return 'bmp';
  2898.     case 'com'  : return 'com';
  2899.     case 'css'  : return 'css';
  2900.     case 'doc'  : return 'doc';
  2901.     case 'exe'  : return 'exe';
  2902.     case 'gif'  : return 'gif';
  2903.     case 'js'   : return 'js';
  2904.     case 'mid'  : return 'mid';
  2905.     case 'mp3'  : return 'mp3';
  2906.     case 'pdf'  : return 'pdf';
  2907.     case 'ppt'  : return 'ppt';
  2908.     case 'png'  : return 'png';
  2909.     case 'swf'  : return 'swf';
  2910.     case 'xls'  : return 'xls';
  2911.  
  2912.     case 'com'  :
  2913.     case 'pif'  : return 'com';
  2914.  
  2915.     case 'htm'  :
  2916.     case 'html' : return 'html';
  2917.    
  2918.     case 'jpeg' :
  2919.     case 'jpg'  : return 'jpg';
  2920.    
  2921.     case 'odf'  : // OpenOffice
  2922.     case 'odg'  :
  2923.     case 'odm'  :
  2924.     case 'odp'  :
  2925.     case 'ods'  :
  2926.     case 'odt'  : return 'ooo';
  2927.  
  2928.     case 'inc'  :
  2929.     case 'php'  :
  2930.     case 'php3' :
  2931.     case 'php4' :
  2932.     case 'php5' :
  2933.     case 'phtml' : return 'php';
  2934.  
  2935.     case 'dtb'  :
  2936.     case 'ini'  :
  2937.     case 'nfo'  :
  2938.     case 'txt'  : return 'txt';
  2939.  
  2940.     case 'avi'  :
  2941.     case 'mpeg' :
  2942.     case 'mpg'  :
  2943.     case 'mov'  :
  2944.     case 'wav'  : return 'wav';
  2945.  
  2946.     case 'ace'  :
  2947.     case 'cab'  :
  2948.     case 'gz'   :
  2949.     case 'rar'  :
  2950.     case 'tar'  :
  2951.     case 'tgz'  :
  2952.     case 'zip'  : return 'zip';
  2953.    
  2954.     default     : return 'inconnu';
  2955.     }
  2956. }
  2957.  
  2958. function PathAbs($matches) {
  2959.     if(!preg_match('`^(https?|ftp|mailto|javascript)\:`i', $matches[3])) {
  2960.         $matches[0] = $matches[1].$matches[2].CHEMIN.$matches[3];
  2961.     }
  2962.     return $matches[0];
  2963. }
  2964.  
  2965. function PathToImage($text) {
  2966.     return preg_replace_callback("`( href=| src=| action=)(\"|')?([^ >]+)`i", 'PathAbs', $text);
  2967. }
  2968.  
  2969. function SplitText($textin, $textlen) {
  2970.     $out1 = $textin;
  2971.     $out2 = '';
  2972.     if (strlen($textin) > $textlen) {
  2973.         $tempout = strrpos(substr($textin,0,$textlen),' ');
  2974.         if ($tempout < 1) {
  2975.             $tempout = strpos($textin,' ');
  2976.         }
  2977.         if ($tempout > 0) {
  2978.             $out1 = substr($textin,0,$tempout);
  2979.             $out2 = substr($textin,$tempout+1,strlen($textin)-$tempout);
  2980.         }
  2981.     }
  2982.     return array($out1, $out2);
  2983. }
  2984.  
  2985. function CutLongWord($textin, $textlen = 50) {
  2986.     return (mb_strlen($textin) > $textlen ? mb_substr(mb_substr($textin, 0, $textlen), 0, strrpos(mb_substr($textin, 0, $textlen), ' ')) : $textin);
  2987. }
  2988.  
  2989. function WrapLongWords($textin, $textlen = 50, $textrep = ' ') {
  2990.     return wordwrap($textin, $textlen, $textrep, 1);
  2991. }
  2992.  
  2993. function FormatDateStamp($datein) {
  2994.     global $site, $lng, $lang;
  2995.     $l       = ($lng == $lang[0]) ? 0 : 1;
  2996.     $asite19 = explode('|', $site[19]);
  2997.     if ($asite19[$l] == 'E1') {
  2998.         $formatout = 'd/m/Y';
  2999.     }
  3000.     elseif ($asite19[$l] == 'E2') {
  3001.         $formatout = 'd.m.Y';
  3002.     }
  3003.     elseif ($asite19[$l] == 'U1') {
  3004.         $formatout = 'm/d/Y';
  3005.     }
  3006.     elseif ($asite19[$l] == 'U2') {
  3007.         $formatout = 'm.d.Y';
  3008.     }
  3009.     elseif ($asite19[$l] == 'C1') {
  3010.         $formatout = 'Y/m/d';
  3011.     }
  3012.     else {
  3013.         $formatout = 'Y.m.d';
  3014.     }
  3015.     $formatout .= ' '.$site[23].' ';
  3016.     if ($site[22] == 'H1') {
  3017.         $formatout .= 'H:i';
  3018.     }
  3019.     elseif ($site[22] == 'H2') {
  3020.         $formatout .= 'H\hi';
  3021.     }
  3022.     else {
  3023.         $formatout .= 'h:i A';
  3024.     }
  3025.     $dateout = date($formatout,$datein);
  3026.     return $dateout;
  3027. }
  3028.  
  3029. function FormatDate($datein) {
  3030.     global $site, $lng, $lang;
  3031.     $l       = ($lng == $lang[0]) ? 0 : 1;
  3032.     $asite19 = explode('|', $site[19]);
  3033.     $jour    = substr($datein,6,2);
  3034.     $mois    = substr($datein,4,2);
  3035.     $annee   = substr($datein,0,4);
  3036.     $heure   = substr($datein,8,2);
  3037.     $minute  = substr($datein,10,2);
  3038.     if ($asite19[$l] == 'E1') {
  3039.         $dateout = $jour.'/'.$mois.'/'.$annee;
  3040.     }
  3041.     elseif ($asite19[$l] == 'E2') {
  3042.         $dateout = $jour.'.'.$mois.'.'.$annee;
  3043.     }
  3044.     elseif ($asite19[$l] == 'U1') {
  3045.         $dateout = $mois.'/'.$jour.'/'.$annee;
  3046.     }
  3047.     elseif ($asite19[$l] == 'U2') {
  3048.         $dateout = $mois.'.'.$jour.'.'.$annee;
  3049.     }
  3050.     elseif ($asite19[$l] == 'C1') {
  3051.         $dateout = $annee.'/'.$mois.'/'.$jour;
  3052.     }
  3053.     else {
  3054.         $dateout = $annee.'.'.$mois.'.'.$jour;
  3055.     }
  3056.     if ($heure.$minute != '') {
  3057.         $dateout .= ' '.$site[23].' ';
  3058.         $suffixe  = '';
  3059.         if ($site[22] == "H1") {
  3060.             $separe   = ':';
  3061.         }
  3062.         elseif ($site[22] == "H2") {
  3063.             $separe = 'h';
  3064.         }
  3065.         else {
  3066.             $separe = ':';
  3067.             if ($heure < 12) {
  3068.                 $suffixe = ' AM';
  3069.             }
  3070.             else {
  3071.                 $suffixe = ' PM';
  3072.                 $heure = $heure - 12;
  3073.             }
  3074.         }
  3075.         $dateout .= $heure.$separe.$minute.$suffixe;
  3076.     }
  3077.     return $dateout;
  3078. }
  3079.  
  3080. function GetCurrentDateTime() {
  3081.     return date('YmdHi');
  3082. }
  3083.  
  3084. function FileSizeInKb($fic) {
  3085.     $taille = @filesize($fic);
  3086.     if ($taille !== false) {
  3087.         $taille = round($taille/1024);
  3088.     }
  3089.     return $taille;
  3090. }
  3091.  
  3092. function FileDBExist($fic) {
  3093.     return is_file($fic);
  3094. }
  3095.  
  3096. function DestroyDBFile($fic) {
  3097.     SetChmod($fic);
  3098.     SetChmod($fic);
  3099.     @unlink($fic);
  3100. }
  3101.  
  3102. function ReadCounter($fic) {
  3103.     $DataDB = 0;
  3104.     if (FileDBExist($fic)) {
  3105.         $fhandle = fopen($fic, 'r');
  3106.         if (filesize($fic)) {
  3107.             $DataDB = trim(fgets($fhandle, filesize($fic)));
  3108.         }
  3109.         fclose($fhandle);
  3110.     }
  3111.     return $DataDB;
  3112. }
  3113.  
  3114. function WriteCounter($fic, $DataDB) {
  3115.     $fhandle = fopen($fic, 'w');
  3116.     fputs($fhandle, $DataDB."\n");
  3117.     fclose($fhandle);
  3118. }
  3119.  
  3120. function ReadFullDB($fic) {
  3121.     $DataDB = Array();
  3122.     if (FileDBExist($fic)) {
  3123.         $DataDB = implode('', file($fic));
  3124.     }
  3125.     return $DataDB;
  3126. }
  3127.  
  3128. function WriteFullDB($fic, $DataDB) {
  3129.     $fhandle = fopen($fic, 'w');
  3130.     fputs($fhandle, $DataDB);
  3131.     fclose($fhandle);
  3132. }
  3133.  
  3134. function AppendFullDB($fic, $DataDB) {
  3135.     $fhandle = fopen($fic, 'a');
  3136.     fputs($fhandle, $DataDB);
  3137.     fclose($fhandle);
  3138. }
  3139.  
  3140. function CountDBFields($fic) {
  3141.     $DataNB = 0;
  3142.     if (FileDBExist($fic)) {
  3143.         $DataDB = file($fic);
  3144.         $DataNB = count($DataDB);
  3145.     }
  3146.     return $DataNB;
  3147. }
  3148.  
  3149. function ReadDBFields($fic) {
  3150.     $DataDB = array();
  3151.     $Fields = array();
  3152.     if (FileDBExist($fic)) {
  3153.         $DataDB = file($fic);
  3154.         $i = 0;
  3155.         foreach($DataDB as $Data) {
  3156.             $Fields[$i] = explode(CONNECTOR, trim($Data));
  3157.             $i++;
  3158.         }
  3159.     }
  3160.     return $Fields;
  3161. }
  3162.  
  3163. function WriteDBFields($fic, $Fields) {
  3164.     $fhandle = fopen($fic, 'w');
  3165.     $out = '';
  3166.     foreach($Fields as $row) {
  3167.         $out .= implode(CONNECTOR, $row)."\n";
  3168.     }
  3169.     fputs($fhandle, $out);
  3170.     fclose($fhandle);
  3171. }
  3172.  
  3173. function AppendDBFields($fic, $Fields) {
  3174.     $fhandle = fopen($fic, 'a');
  3175.     $DataDB = '';
  3176.     for ($i = 0 ; $i < (count($Fields)-1); $i++) {
  3177.         $DataDB .= trim($Fields[$i]).CONNECTOR;
  3178.     }
  3179.     $DataDB .= trim($Fields[count($Fields)-1])."\n";
  3180.     fputs($fhandle, $DataDB);
  3181.     fclose($fhandle);
  3182. }
  3183.  
  3184. function DeleteDBFieldById($fic, $id = 0) {
  3185.     $array = explode("\n", fread(fopen($fic, 'r'), filesize($fic)));
  3186.     $delete = array_pop($array);
  3187.     unset($array[$id]);
  3188.     $newarray = array_values($array);
  3189.     $fhandle = fopen($fic,'w');
  3190.     foreach($newarray as $new){
  3191.         fwrite($fhandle, $new."\n");
  3192.     }
  3193.     fclose($fhandle);
  3194. }
  3195.  
  3196. function CheckDB1Field($fic, $submit, $FieldNB) {
  3197.     if (FileDBExist($fic)) {
  3198.         $DataDB = ReadDBFields($fic);
  3199.         foreach($DataDB as $Data) {
  3200.             if (@stristr($Data[$FieldNB], $submit)) {
  3201.                 return TRUE;
  3202.             }
  3203.         }
  3204.     }
  3205.     return FALSE;
  3206. }
  3207.  
  3208. function CheckDB2Fields($fic,$submit1,$FieldNB1,$submit2,$FieldNB2) {
  3209.     if (FileDBExist($fic)) {
  3210.         $DataDB = ReadDBFields($fic);
  3211.         foreach($DataDB as $Data) {
  3212.             if (@stristr($Data[$FieldNB1],$submit1) && @stristr($Data[$FieldNB2],$submit2)) {
  3213.                 return TRUE;
  3214.             }
  3215.         }
  3216.     }
  3217.     return FALSE;
  3218. }
  3219.  
  3220. function SelectDBFieldsByID($Fields,$id) {
  3221.     $DataDB = array();
  3222.     foreach ($Fields as $row) {
  3223.         if ($row[1] == $id) {
  3224.             $DataDB[] = $row;
  3225.         }
  3226.     }
  3227.     return $DataDB;
  3228. }
  3229.  
  3230. function SelectDBFieldsByField($Fields, $index, $value) {
  3231.     $DataDB = array();
  3232.     foreach ($Fields as $row) {
  3233.         if ($row[$index] == $value) {
  3234.             $DataDB[] = $row;
  3235.         }
  3236.     }
  3237.     return $DataDB;
  3238. }
  3239.  
  3240. function IndexDBFieldsByField($Fields, $index) {
  3241.     $DataDB = array();
  3242.     foreach ($Fields as $row) {
  3243.         $DataDB[$row[$index]] = $row;
  3244.     }
  3245.     return $DataDB;
  3246. }
  3247.  
  3248. function SelectDBFieldsByType($Fields, $type) {
  3249.     $DataDB = array();
  3250.     foreach ($Fields as $row) {
  3251.         if ($row[0] == $type) {
  3252.             $DataDB[] = $row;
  3253.         }
  3254.     }
  3255.     return $DataDB;
  3256. }
  3257.  
  3258. function SelectDBFieldsByNotStatus($Fields, $status) {
  3259.     $DataDB = array();
  3260.     foreach ($Fields as $row) {
  3261.         if ($row[2] != $status) {
  3262.             $DataDB[] = $row;
  3263.         }
  3264.     }
  3265.     return $DataDB;
  3266. }
  3267.  
  3268. function SelectDBFieldsByStatus($Fields, $status) {
  3269.     $DataDB = array();
  3270.     foreach ($Fields as $row) {
  3271.         if ($row[2] == $status) {
  3272.             $DataDB[] = $row;
  3273.         }
  3274.     }
  3275.     return $DataDB;
  3276. }
  3277.  
  3278. function SelectDBFields($type,$status,$id,$docid=DOCID) {
  3279.     if (!empty($status) && !empty($id)) {
  3280.         return SelectDBFieldsByID(SelectDBFieldsByStatus(SelectDBFieldsByType(ReadDBFields($docid), $type), $status), $id);
  3281.     }
  3282.     elseif (!empty($status)) {
  3283.         return SelectDBFieldsByStatus(SelectDBFieldsByType(ReadDBFields($docid), $type), $status);
  3284.     }
  3285.     elseif (!empty($id)) {
  3286.         return SelectDBFieldsByID(SelectDBFieldsByType(ReadDBFields($docid), $type), $id);
  3287.     }
  3288.     else {
  3289.         return SelectDBFieldsByType(ReadDBFields($docid), $type);
  3290.     }
  3291. }
  3292.  
  3293. function RemoveQuote($chaine) {
  3294.     return str_replace(array('"', "'"), '', $chaine);
  3295. }
  3296.  
  3297. function RemoveConnector($chaine) {
  3298.     return str_replace(CONNECTOR, '', $chaine);
  3299. }
  3300.  
  3301. function RemoveBR($chaine) {
  3302.     return preg_replace('!<br />!i', "\n", $chaine);
  3303. }
  3304.  
  3305. function PutBR($chaine) {
  3306.     return str_replace(array(chr(10), chr(13)), array("\n", "\r"), $chaine);
  3307. }
  3308.  
  3309. function ReplaceDolar($chaine) {
  3310.     return str_replace('$','&#36;',$chaine);
  3311. }
  3312.  
  3313. function TestFileId($id, $format='%08d') {
  3314.     if (1 == preg_match('|^[0-9]+$|', $id)) {
  3315.         return sprintf($format, $id);
  3316.     } else {
  3317.         return FALSE;
  3318.     }
  3319. }
  3320.  
  3321. function ReadDocCounter($id, $dir = DBCOUNT) {
  3322.     $id = TestFileID($id);
  3323.     if ($id === FALSE) {
  3324.         return FALSE;
  3325.     } else {
  3326.         return ReadCounter($dir.$id.DBEXT);
  3327.     }
  3328. }
  3329.  
  3330. function WriteDocCounter($id, $DataDB, $dir = DBCOUNT) {
  3331.     WriteCounter($dir.$id.DBEXT, $DataDB);
  3332. }
  3333.  
  3334. function UpdateDocCounter($id) {
  3335.     $id = TestFileID($id);
  3336.     if ($id === FALSE) return FALSE;
  3337.     $DataDB = ReadDocCounter($id);
  3338.     $vote = DejaVote(DBIPBASE.$id.DBEXT,300);
  3339.     if ($vote[0] == FALSE) {
  3340.         $DataDB++;
  3341.         WriteDocCounter($id, $DataDB);
  3342.     }
  3343.     return $DataDB;
  3344. }
  3345.  
  3346. function ReadDoc($id, $dir = DBBASE) {
  3347.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  3348.          $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2,
  3349.          $fieldd1, $fieldd2, $fieldweb, $fieldmail, $fieldmod;
  3350.     $type       = '';
  3351.     $fileid     = '';
  3352.     $status     = '';
  3353.     $creadate   = '';
  3354.     $moddate    = '';
  3355.     $author     = '';
  3356.     $email      = '';
  3357.     $fielda1    = '';
  3358.     $fielda2    = '';
  3359.     $fieldb1    = '';
  3360.     $fieldb2    = '';
  3361.     $fieldc1    = '';
  3362.     $fieldc2    = '';
  3363.     $fieldd1    = '';
  3364.     $fieldd2    = '';
  3365.     $fieldweb   = '';
  3366.     $fieldmail  = '';
  3367.     $fieldmod   = '';
  3368.     $id = TestFileID($id);
  3369.     if ($id === FALSE) return FALSE;
  3370.     if (FileDBExist($dir.$id.INCEXT)) {
  3371.         include($dir.$id.INCEXT);
  3372.     }
  3373.     return TRUE;
  3374. }
  3375.  
  3376. function WriteDoc($action = '', $dir = DBBASE) {
  3377.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  3378.          $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2,
  3379.          $fieldd1, $fieldd2, $fieldweb, $fieldmail, $fieldmod;
  3380.     $id = TestFileID($fileid);
  3381.     if ($id === FALSE) return FALSE;
  3382.     if ($action != 'migr' && in_array($type, array(TYP_ART, TYP_BLOG, TYP_FAQ, TYP_FREEBOX, TYP_MENUBOX, TYP_OPTDDMENU))) {
  3383.         $fieldc1 = str_replace('&#36;', '$', $fieldc1);
  3384.         $fieldc2 = str_replace('&#36;', '$', $fieldc2);
  3385.     }
  3386.     $rec = "<?php
  3387. \$type = '".$type."';
  3388. \$fileid = '".$fileid."';
  3389. \$status = '".$status."';
  3390. \$creadate = '".$creadate."';
  3391. \$moddate = '".$moddate."';
  3392. \$author = stripslashes('".$author."');
  3393. \$email = stripslashes('".$email."');
  3394. \$fielda1 = stripslashes('".$fielda1."');
  3395. \$fielda2 = stripslashes('".$fielda2."');
  3396. \$fieldb1 = stripslashes('".$fieldb1."');
  3397. \$fieldb2 = stripslashes('".$fieldb2."');
  3398. \$fieldc1 = stripslashes('".$fieldc1."');
  3399. \$fieldc2 = stripslashes('".$fieldc2."');
  3400. \$fieldd1 = stripslashes('".$fieldd1."');
  3401. \$fieldd2 = stripslashes('".$fieldd2."');
  3402. \$fieldweb = stripslashes('".$fieldweb."');
  3403. \$fieldmail = stripslashes('".$fieldmail."');
  3404. \$fieldmod = stripslashes('".$fieldmod."');
  3405. ?>
  3406. ";
  3407.     WriteFullDB($dir.$id.INCEXT, $rec);
  3408.     return TRUE;
  3409. }
  3410.  
  3411. function UpdateDBdtb($dtb) {
  3412.     global $type,$fileid,$status,$creadate,$moddate,$author,$email,
  3413.         $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldd1,$fieldd2,$fieldweb,$fieldmail,$fieldmod;
  3414.     $db  = SelectDBFields($dtb, 'a', '');
  3415.     $dba = array();
  3416.     $j   = 0;
  3417.     foreach($db as $dbs) {
  3418.         ReadDoc($dbs[1]);
  3419.         $dba[$j]= array(
  3420.             RemoveConnector($fielda1),
  3421.             RemoveConnector($fielda2),
  3422.             RemoveConnector($fieldb1),
  3423.             RemoveConnector($fieldb2),
  3424.             $fileid,
  3425.             $creadate,
  3426.             $fieldmod,
  3427.             $type
  3428.             );
  3429.         if ($dtb == TYP_ART) {
  3430.             $dba[$j][5] = RemoveConnector($fieldd1);
  3431.         } elseif ($dtb == TYP_OPTMENU || $dtb == TYP_OPTDDMENU) {
  3432.             $dba[$j][5] = $fieldweb;
  3433.         }
  3434.         $j++;
  3435.     }
  3436.     WriteDBFields(DBINDEX.$dtb.DBEXT, $dba);
  3437. }
  3438.  
  3439. function UpdateDBreact($action, $id) {
  3440.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  3441.         $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2, $fieldd1, $fieldd2,
  3442.         $fieldweb, $fieldmail, $fieldmod;
  3443.     $db = array();
  3444.     if ($action == 'add' || $action == 'migr') {
  3445.         ReadDoc($id);
  3446.         if ($status == 'a') {
  3447.             $db = array_pad(array(), 7, '');
  3448.             $db[0] = $fileid;
  3449.             $db[1] = $fielda2;
  3450.             ReadDoc($fielda2);
  3451.             $db[2] = $fieldb1;
  3452.             $db[3] = $fieldb2;
  3453.             $db[5] = $creadate;
  3454.             $db[6] = $fieldmod;
  3455.             $db[7] = TYP_REACT;
  3456.             AppendDBFields(DBREACT, $db);
  3457.         }
  3458.     }
  3459.     else {
  3460.         $db = SelectDBFields(TYP_REACT,'a','');
  3461.         sort($db);
  3462.         $dbart = ReadDbFields(DBART);
  3463.         $dbf = array();
  3464.         $i   = 0;
  3465.         foreach($db as $dbs) {
  3466.             $dbf[$i] = array_pad(array(), 7, '');
  3467.             ReadDoc($dbs[1]);
  3468.             $dbf[$i][0] = $fileid;
  3469.             $dbf[$i][1] = $fielda2;
  3470.             $art = SelectDBFieldsByField($dbart, 4, $fielda2);
  3471.             if (!empty($art)) {
  3472.                 $dbf[$i][2] = $art[0][2];
  3473.                 $dbf[$i][3] = $art[0][3];
  3474.                 $dbf[$i][5] = $art[0][5];
  3475.                 $dbf[$i][6] = $art[0][6];
  3476.                 $dbf[$i][7] = TYP_REACT;
  3477.             }
  3478.             $i++;
  3479.         }
  3480.         WriteDBFields(DBREACT, $dbf);
  3481.     }
  3482. }
  3483.  
  3484. function UpdateDBreblog($action, $id) {
  3485.     global $type, $fileid, $status, $creadate, $moddate, $author, $email,
  3486.         $fielda1, $fielda2, $fieldb1, $fieldb2, $fieldc1, $fieldc2, $fieldd1, $fieldd2,
  3487.         $fieldweb, $fieldmail, $fieldmod;
  3488.     $db = array();
  3489.     if ($action == 'add' || $action == 'migr') {
  3490.         ReadDoc($id);
  3491.         if ($status == 'a') {
  3492.             $db = array_pad(array(), 7, '');
  3493.             $db[0] = $fileid;
  3494.             $db[1] = $fielda2;
  3495.             ReadDoc($fielda2);
  3496.             $db[2] = $fieldb1;
  3497.             $db[3] = $fieldb2;
  3498.             $db[5] = $creadate;
  3499.             $db[6] = $fieldmod;
  3500.             $db[7] = TYP_REBLOG;
  3501.             AppendDBFields(DBREBLOG, $db);
  3502.         }
  3503.     }
  3504.     else {
  3505.         $db = SelectDBFields(TYP_REBLOG,'a','');
  3506.         sort($db);
  3507.         $dbblog = ReadDbFields(DBBLOG);
  3508.         $dbf = array();
  3509.         $i   = 0;
  3510.         foreach($db as $dbs) {
  3511.             $dbf[$i] = array_pad(array(), 7, '');
  3512.             ReadDoc($dbs[1]);
  3513.             $dbf[$i][0] = $fileid;
  3514.             $dbf[$i][1] = $fielda2;
  3515.             $blog = SelectDBFieldsByField($dbblog, 4, $fielda2);
  3516.             if (!empty($blog)) {
  3517.                 $dbf[$i][2] = $blog[0][2];
  3518.                 $dbf[$i][3] = $blog[0][3];
  3519.                 $dbf[$i][5] = $blog[0][5];
  3520.                 $dbf[$i][6] = $blog[0][6];
  3521.                 $dbf[$i][7] = TYP_REBLOG;
  3522.             }
  3523.             $i++;
  3524.         }
  3525.         WriteDBFields(DBREBLOG, $dbf);
  3526.     }
  3527. }
  3528.  
  3529. function UpdateDBforum($action, $id) {
  3530.     global $type,$fileid,$status,$creadate,$moddate,$author,$email,
  3531.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,$fieldweb,$fieldmail;$fieldmod;
  3532.     $db = array();
  3533.     if ($action == 'add' || $action == 'migr') {
  3534.         ReadDoc($id);
  3535.         if ($status == 'a') {
  3536.             $db[0]  = $creadate;
  3537.             $db[1]  = $fielda1;
  3538.             $db[2]  = $fielda2;
  3539.             $db[3]  = $fileid;
  3540.             $db[4]  = RemoveConnector($author);
  3541.             $db[5]  = RemoveConnector($email);
  3542.             $db[6]  = RemoveConnector($fieldb1);
  3543.             $db[7]  = $fieldd1;
  3544.             $db[8]  = $fieldb2;
  3545.             $db[9]  = $fieldmail;
  3546.             $db[10] = TYP_FORUM;
  3547.             AppendDBFields(DBTHREAD, $db);
  3548.         }
  3549.     } else {
  3550.         $db = SelectDBFields(TYP_FORUM, 'a', '');
  3551.         sort($db);
  3552.         $dbf    = array();
  3553.         $ns2cat = array();
  3554.         $i      = 0;
  3555.         foreach($db as $dbs) {
  3556.             ReadDoc($dbs[1]);
  3557.             $dbf[$i][0]  = $creadate;
  3558.             $dbf[$i][1]  = $fielda1;
  3559.             $dbf[$i][2]  = $fielda2;
  3560.             $dbf[$i][3]  = $fileid;
  3561.             $dbf[$i][4]  = RemoveConnector($author);
  3562.             $dbf[$i][5]  = RemoveConnector($email);
  3563.             $dbf[$i][6]  = RemoveConnector($fieldb1);
  3564.             $dbf[$i][7]  = $fieldd1;
  3565.             $dbf[$i][8]  = $fieldb2;
  3566.             $dbf[$i][9]  = $fieldmail;
  3567.             $dbf[$i][10] = TYP_FORUM;
  3568.             if (0 == $fielda2) {
  3569.                 $ns2cat[$fielda1] = $fieldb2;
  3570.             } elseif (isset($ns2cat[$fielda1])) {
  3571.                 $dbf[$i][8] = $ns2cat[$fielda1];
  3572.             }
  3573.             $i++;
  3574.         }
  3575.         @sort($dbf, SORT_REGULAR);
  3576.         WriteDBFields(DBTHREAD, $dbf);
  3577.     }
  3578.     $db  = array();
  3579.     $db  = ReadDBFields(DBTHREAD);
  3580.     $dbf = array();
  3581.     $i   = 0;
  3582.     $j   = 0;
  3583.     foreach ($db as $dbs) {
  3584.         if ($db[$i][2] == '0') {
  3585.             $dbf[$j][0]  = $dbs[0];
  3586.             $dbf[$j][1]  = $dbs[1];
  3587.             $dbf[$j][2]  = $dbs[3];
  3588.             $dbf[$j][3]  = $dbs[4];
  3589.             $dbf[$j][4]  = $dbs[5];
  3590.             $dbf[$j][5]  = $dbs[6];
  3591.             $dbf[$j][6]  = $dbs[3] == $fileid ? $creadate : $dbs[0];
  3592.             $dbf[$j][7]  = GetLastChildNumber(TYP_FORUM, $dbs[1]);
  3593.             $dbf[$j][8]  = '';
  3594.             $dbf[$j][9]  = '';
  3595.             $dbf[$j][10] = $dbs[7];
  3596.             $dbf[$j][11] = '';
  3597.             $dbf[$j][12] = $dbs[8];
  3598.             $dbf[$j][13] = $dbs[10];
  3599.             $k           = 0;
  3600.             foreach ($db as $dbk) {
  3601.                 if ($dbk[1] == $dbf[$j][1]) {
  3602.                     $dbf[$j][0]  = $dbk[0] > $dbf[$j][0] ? $dbk[0] : $dbf[$j][0];
  3603.                     $dbf[$j][8]  = $dbk[4];
  3604.                     $dbf[$j][9]  = $dbk[5];
  3605.                     $dbf[$j][11] = $dbk[7];
  3606.                 }
  3607.                 $k++;
  3608.             }
  3609.             $j++;
  3610.         }
  3611.         $i++;
  3612.     }
  3613.     @rsort($dbf, SORT_REGULAR);
  3614.     WriteDBFields(DBFORUM, $dbf);
  3615. }
  3616.  
  3617. function UpdateDocid($id, $status) {
  3618.     $db = ReadDBFields(DOCID);
  3619.     for ($i = 0; $i < count($db); $i++) {
  3620.         if ($db[$i][1] == $id) {
  3621.             $db[$i][2] = $status;
  3622.             break;
  3623.         }
  3624.     }
  3625.     WriteDBFields(DOCID,$db);
  3626.     unset($db);
  3627. }
  3628.  
  3629. function UpdateDocdates($action, $id, $mdate='', $cdate='') {
  3630.     $db = ReadDBFields(DOCDATES);
  3631.     switch ($action) {
  3632.     case 'add'  :
  3633.     case 'migr' :
  3634.         $datespub    = explode('-', $cdate);
  3635.         $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  3636.         $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  3637.         $cdate       = $datespub[0].'-'.$datespub[1];
  3638.         $mdate       = $action == 'add' ? $datespub[0] : $mdate;
  3639.         $db[]        = array($id, $cdate, $mdate);
  3640.         break;
  3641.     case 'mod' :
  3642.         for ($i = 0; $i < count($db); $i++) {
  3643.             if ($db[$i][0] == $id) {
  3644.                 if ($cdate != '' && $db[$i][1] != $cdate) {
  3645.                     $datespub    = explode('-', $cdate);
  3646.                     $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  3647.                     $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  3648.                     $db[$i][1]   = $datespub[0].'-'.$datespub[1];
  3649.                 }
  3650.                 $db[$i][2] = $mdate == '' ? GetCurrentDateTime() : $mdate;
  3651.                 break;
  3652.             }
  3653.         }
  3654.         break;
  3655.     case 'del' :
  3656.         for ($i = 0; $i < count($db); $i++) {
  3657.             if ($db[$i][0] == $id) {
  3658.                 unset($db[$i]);
  3659.                 break;
  3660.             }
  3661.         }
  3662.         break;
  3663.     }
  3664.     sort($db);
  3665.     WriteDBFields(DOCDATES, $db);
  3666.     unset($db);
  3667. }
  3668.  
  3669. function GetLastChildNumber($type, $parentId = NULL) {
  3670.     $db = SelectDbFieldsByField(ReadDbFields(CHILDREN), 1, $type);
  3671.     if (isset($parentId)) {
  3672.         $db = SelectDbFieldsByField($db, 3, $parentId);
  3673.     }
  3674.     if (count($db) > 0) {
  3675.         rsort($db);
  3676.         return $db[0][2];
  3677.     } else {
  3678.         return 0;
  3679.     }
  3680.     unset($db);
  3681. }
  3682.  
  3683. function GetNextChildNumber($type, $parentId = NULL) {
  3684.     return 1 + GetLastChildNumber($type, $parentId);
  3685. }
  3686.  
  3687. function UpdateChildren($action, $data) {
  3688.     $db = IndexDbFieldsByField(ReadDbFields(CHILDREN), 0);
  3689.     switch ($data[0]) {
  3690.     case TYP_GUESTBK :
  3691.     case TYP_REACT :
  3692.     case TYP_REBLOG :
  3693.         switch ($action) {
  3694.         case 'add' :
  3695.             $db[$data[1]] = array($data[1], $data[0], $data[7], $data[8]);
  3696.             WriteDbFields(CHILDREN, $db);
  3697.             break;
  3698.         case 'del' :
  3699.             unset($db[$data[1]]);
  3700.             WriteDbFields(CHILDREN, $db);
  3701.             break;
  3702.         }
  3703.         break;
  3704.     case TYP_FORUM :
  3705.         if (0 == $data[8]) break;
  3706.         switch ($action) {
  3707.         case 'add' :
  3708.             $db[$data[1]] = array($data[1], $data[0], $data[8], $data[7]);
  3709.             WriteDbFields(CHILDREN, $db);
  3710.             break;
  3711.         case 'del' :
  3712.             if (isset($db[$data[1]])) unset($db[$data[1]]);
  3713.             WriteDbFields(CHILDREN, $db);
  3714.             break;
  3715.         }
  3716.         break;
  3717.     }
  3718.     unset($db);
  3719. }
  3720.  
  3721. function UpdateDocFromDoc($action, $id, $newStatus) {
  3722.     global $type,$fileid,$status,$creadate,$moddate,$author,$email,
  3723.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  3724.     $fieldweb,$fieldmail,$fieldmod, $lang, $urlrw;
  3725.     ReadDoc($id);
  3726.     $status    = $newStatus;
  3727.     $author    = addslashes($author);
  3728.     $email     = addslashes($email);
  3729.     $fielda1   = addslashes($fielda1);
  3730.     $fielda2   = addslashes($fielda2);
  3731.     $fieldb1   = addslashes($fieldb1);
  3732.     $fieldb2   = addslashes($fieldb2);
  3733.     $fieldc1   = addslashes($fieldc1);
  3734.     $fieldc2   = addslashes($fieldc2);
  3735.     $fieldd1   = addslashes($fieldd1);
  3736.     $fieldd2   = addslashes($fieldd2);
  3737.     $fieldweb  = addslashes($fieldweb);
  3738.     $fieldmail = addslashes($fieldmail);
  3739.     $fieldmod  = addslashes($fieldmod);
  3740.     WriteDoc($action);
  3741.     if ($type == TYP_ART) {
  3742.         $mnu_id = substr($fieldd1, 4);
  3743.         $dbw    = SelectDbFieldsByField(ReadDBFields(DBOPTMENU), 5, $mnu_id);
  3744.         foreach ($dbw as $item) {
  3745.             ReadDoc($item[4]);
  3746.             $urls = explode('||', $fieldd1);
  3747.             if (!empty($urls[0]) && strpos($urls[0], 'articles.php') !== false) {
  3748.                 $pg  = substr($urls[0], strpos($urls[0], 'pg=') + 3);
  3749.                 $pos = strpos($pg, '&');
  3750.                 $pg  = $pos === false ? $pg : substr($pg, 0, $pos);
  3751.             }
  3752.             if ($pg == $id && $fieldweb == $mnu_id) {
  3753.                 $opt_id = $item[4];
  3754.                 UpdateDocid($opt_id, $newStatus);
  3755.                 UpdateDocFromDoc($action, $opt_id, $newStatus);
  3756.                 UpdateDBdtb(TYP_OPTMENU);
  3757.                 break;
  3758.             }                
  3759.         }
  3760.         unset($dbw);
  3761.     }
  3762. }
  3763.  
  3764. function UpdateDocFromInput($action, $id, $data) {
  3765.     global $site,$type,$fileid,$status,$creadate,$moddate,$author,$email,
  3766.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  3767.     $fieldweb,$fieldmail,$fieldmod;
  3768.     ReadDoc($id);
  3769.     if (in_array($action, array('add', 'migr'))) {
  3770.         $type   = $data[0];
  3771.         $fileid = $id;
  3772.         $status = $data[2];
  3773.        
  3774.         $datespub    = explode('-', $data[3]);
  3775.         $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  3776.         $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  3777.         $creadate    = $datespub[0].'-'.$datespub[1];
  3778.         $moddate     = $action == 'add' ? $datespub[0] : $data[4];
  3779.     } else {
  3780.         /// $action == 'mod'
  3781.         if ($creadate != $data[3] && $data[0] != TYP_FORUM) {
  3782.             $datespub    = explode('-', $data[3]);
  3783.             $datespub[0] = empty($datespub[0]) ? GetCurrentDateTime() : $datespub[0];
  3784.             $datespub[1] = empty($datespub[1]) ? '' : $datespub[1];
  3785.             $creadate    = $datespub[0].'-'.$datespub[1];
  3786.         }
  3787.         $moddate = $data[4];
  3788.     }
  3789.     $author  = addslashes(stripslashes($data[5]));
  3790.     $email   = addslashes(stripslashes($data[6]));
  3791.     $fielda1 = addslashes(stripslashes($data[7]));
  3792.     $fielda2 = addslashes(stripslashes($data[8]));
  3793.     $fieldb1 = addslashes(stripslashes($data[9]));
  3794.     $fieldb2 = addslashes(stripslashes($data[10]));
  3795.     if ($data[0] == TYP_NWL) {
  3796.         $fieldc1 = addslashes(stripslashes(replaceimg(ReplaceDolar(PutBR($data[11])))));
  3797.         $fieldc2 = addslashes(stripslashes(replaceimg(ReplaceDolar(PutBR($data[12])))));
  3798.     }
  3799.     else {
  3800.         $fieldc1 = addslashes(stripslashes(souriez(ReplaceDolar(PutBR($data[11])))));
  3801.         $fieldc2 = addslashes(stripslashes(souriez(ReplaceDolar(PutBR($data[12])))));
  3802.     }
  3803.     $fieldd1   = addslashes(stripslashes($data[13]));
  3804.     $fieldd2   = addslashes(stripslashes($data[14]));
  3805.     $fieldweb  = addslashes(stripslashes($data[15]));
  3806.     $fieldmail = addslashes(stripslashes($data[16]));
  3807.     $fieldmod  = addslashes(stripslashes($data[17]));
  3808.     WriteDoc($action);
  3809. }
  3810.  
  3811. function DeactivateInCascade($type, $parentId) {
  3812.     // Désactivation en cascade des réactions, réponses et commentaires actifs
  3813.     switch ($type) {
  3814.     case TYP_ART :
  3815.         $db1 = SelectDbFieldsByField(ReadDbFields(DBREACT), 1, $parentId);
  3816.         foreach ($db1 as $db) {
  3817.             ActionOnFields('act', array(TYP_REACT, $db[0], 'i'), FALSE);
  3818.         }
  3819.         if (count($db1) > 0) {
  3820.             ActionOnFields('reindex', array(TYP_REACT, 0));
  3821.         }
  3822.         unset($db1, $db);
  3823.         break;
  3824.     case TYP_BLOG :
  3825.         $db1 = SelectDbFieldsByField(ReadDbFields(DBREBLOG), 1, $parentId);
  3826.         foreach ($db1 as $db) {
  3827.             ActionOnFields('act', array(TYP_REBLOG, $db[0], 'i'), FALSE);
  3828.         }
  3829.         if (count($db1) > 0) {
  3830.             ActionOnFields('reindex', array(TYP_REBLOG, 0));
  3831.         }
  3832.         unset($db1, $db);
  3833.         break;
  3834.     case TYP_FORUM :
  3835.         global $fielda1, $fielda2;
  3836.         if (0 == $fielda2) {
  3837.             $db1 = SelectDbFieldsByField(ReadDbFields(DBTHREAD), 1, $fielda1);
  3838.             foreach ($db1 as $db) {
  3839.                 if ($db[2] > 0) {
  3840.                     ActionOnFields('act', array(TYP_FORUM, $db[3], 'i'), FALSE);
  3841.                 }
  3842.             }
  3843.             if (count($db1) > 1) {
  3844.                 ActionOnFields('reindex', array(TYP_FORUM, 0));
  3845.             }
  3846.             unset($db1, $db);
  3847.         }
  3848.         break;
  3849.     }
  3850. }
  3851.  
  3852. function DeleteInCascade($type, $parentId) {
  3853.     // Suppression en cascade des réactions, réponses et commentaires actifs
  3854.     $db1 = array();
  3855.     $typechildren = array(TYP_ART=>TYP_REACT, TYP_BLOG=>TYP_REBLOG);
  3856.     switch ($type) {
  3857.     case TYP_ART :
  3858.     case TYP_BLOG :
  3859.         $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $typechildren[$type]), 3, $parentId);
  3860.         foreach ($db1 as $db) {
  3861.             ActionOnFields('del', array($typechildren[$type], $db[0]), FALSE);
  3862.         }
  3863.         break;
  3864.     case TYP_FORUM :
  3865.         global $fielda1, $fielda2;
  3866.         if (0 == $fielda2) {
  3867.             $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $type), 3, $fielda1);
  3868.             foreach ($db1 as $db) {
  3869.                 ActionOnFields('del', array($type, $db[0]), FALSE);
  3870.             }
  3871.         }
  3872.         break;
  3873.     }
  3874.     if (count($db1) > 0) {
  3875.         ActionOnFields('reindex', array($type, 0));
  3876.     }
  3877.     unset($db1);
  3878. }
  3879.  
  3880. function DestroyInCascade($type, $parentId) {
  3881.     // Destruction définitive en cascade des réactions, réponses et commentaires actifs
  3882.     $db1 = array();
  3883.     $typechildren = array(TYP_ART=>TYP_REACT, TYP_BLOG=>TYP_REBLOG);
  3884.     switch ($type) {
  3885.     case TYP_ART :
  3886.     case TYP_BLOG :
  3887.         $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $typechildren[$type]), 3, $parentId);
  3888.         foreach ($db1 as $db) {
  3889.             ActionOnFields('sup', array($typechildren[$type], $db[0]), FALSE);
  3890.         }
  3891.         break;
  3892.     case TYP_FORUM :
  3893.         global $fielda1, $fielda2;
  3894.         if (0 == $fielda2) {
  3895.             $db1 = SelectDbFieldsByField(SelectDbFieldsByField(ReadDbFields(CHILDREN),1, $type), 3, $fielda1);
  3896.             foreach ($db1 as $db) {
  3897.                 ActionOnFields('sup', array($type, $db[0]), FALSE);
  3898.             }
  3899.         }
  3900.         break;
  3901.     }
  3902.     if (count($db1) > 0) {
  3903.         ActionOnFields('reindex', array($type, 0));
  3904.     }
  3905. }
  3906.    
  3907. function CreateSitemapFile($file, $db) {
  3908.     global $charset;
  3909.     $smtxt = '<?xml version="1.0" encoding="'.$charset.'"?>
  3910. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
  3911.     foreach($db as $url) {
  3912.         $smtxt .= '
  3913.  <url>
  3914.    <loc>'.$url['LOC'].'</loc>
  3915.     <lastmod>'.$url['LM'].'</lastmod>
  3916.    <changefreq>'.$url['CF'].'</changefreq>
  3917.    <priority>'.$url['PR'].'</priority>
  3918.  </url>';
  3919.     }
  3920.     $smtxt .= '
  3921. </urlset>';
  3922.     WriteFullDB($file, $smtxt);
  3923. }
  3924.  
  3925. function UpdateSitemaps($typ) {
  3926.     global $lang, $site, $urlrw, $sitemap, $charset, $z2,
  3927.     $type, $fileid, $status, $creadate, $moddate, $author, $email, $fielda1, $fielda2, $fieldb1,
  3928.     $fieldb2, $fieldc1, $fieldc2, $fieldd1, $fieldd2, $fieldweb, $fieldmail, $fieldmod;
  3929.    
  3930.     $smtyps = array(TYP_BLOG, TYP_ART, TYP_NEWS, TYP_PHOTO, TYP_DNLOAD, TYP_FAQ, TYP_LINKS, TYP_GUESTBK, TYP_FORUM, TYP_AGENDA);
  3931.     if ($typ != 'URLS' && !in_array($typ, $smtyps)) return;
  3932.    
  3933.     @unlink(SITEMAPS);
  3934.     @unlink(SM_URLS);
  3935.     $dbws = array();
  3936.     if ($sitemap['SM'] == 'on') {
  3937.         $home = array('index.php?lng='.$lang[0], ($lang[1] != '') ? 'index.php?lng='.$lang[1] : NULL);
  3938.         $urls = file_exists(MAPSURLS) ? array_merge(file(MAPSURLS), $home) : $home;
  3939.        
  3940.         $smslcts = array(TYP_BLOG=>$sitemap['BL'], TYP_ART=>$sitemap['AR'], TYP_NEWS=>$sitemap['NE'], TYP_PHOTO=>$sitemap['PH'], TYP_DNLOAD=>$sitemap['DN'],
  3941.                          TYP_FAQ=>$sitemap['FA'], TYP_LINKS=>$sitemap['LI'], TYP_GUESTBK=>$sitemap['GB'], TYP_FORUM=>$sitemap['FR'], TYP_AGENDA=>$sitemap['AG']);
  3942.         $smfiles = array(TYP_BLOG=>SM_BLOG, TYP_ART=>SM_ART, TYP_NEWS=>SM_NEWS, TYP_PHOTO=>SM_PHOTO, TYP_DNLOAD=>SM_DNLOAD,
  3943.                          TYP_FAQ=>SM_FAQ, TYP_LINKS=>SM_LINKS, TYP_GUESTBK=>SM_GUESTBK, TYP_FORUM=>SM_FORUM, TYP_AGENDA=>SM_AGENDA);
  3944.         $smfreqs = array(TYP_BLOG=>'weekly', TYP_ART=>'monthly', TYP_NEWS=>'weekly', TYP_PHOTO=>'monthly', TYP_DNLOAD=>'monthly',
  3945.                          TYP_FAQ=>'yearly', TYP_LINKS=>'monthly', TYP_GUESTBK=>'monthly', TYP_FORUM=>'daily', TYP_AGENDA=>'monthly');
  3946.        
  3947.         foreach($smtyps as $smtyp) if ($smslcts[$smtyp] != 'on') @unlink($smfiles[$smtyp]);
  3948.  
  3949.         $dbw = array();
  3950.         foreach($urls as $url) {
  3951.             $url = str_replace('&amp;', '&', $url);
  3952.             $url = str_replace('&', '&amp;', $url);
  3953.             $dbw[] = array('LOC'=>$site[3].$url, 'LM'=>date('Y-m-d'), 'CF'=>'yearly', 'PR'=>'0.5');
  3954.         }
  3955.         CreateSitemapFile(SM_URLS, $dbw);
  3956.        
  3957.         foreach($smtyps as $smtyp) {
  3958.             if ($typ != $smtyp || $smslcts[$smtyp] != 'on') continue;
  3959.             $dbw  = array();
  3960.             $docs = SelectDBFields($smtyp, 'a', '');
  3961.             foreach ($docs as $doc) {
  3962.                 ReadDoc($doc[1]);
  3963.                 if ($typ == TYP_FORUM && $fielda2 != '0') continue;
  3964.                 $fieldmail = empty($fieldmail) ? 0 : $fieldmail;
  3965.                 if (isAuthorizedPublication($creadate) && $fieldmod == '') {
  3966.                     foreach($lang as $lng) {
  3967.                         if ($lang[1] == $lng && ($fieldc2 == '' || in_array(array(TYP_GUESTBK, TYP_FORUM), $smtyps))) continue;
  3968.                         switch ($smtyp) {
  3969.                         case TYP_BLOG    : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[1].'-4-'.$fileid.$z2 : $site['BL'].'.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  3970.                         case TYP_ART     : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[20].'-102-'.$fileid.'-'.$fieldmail.$z2 : 'articles.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;tconfig='.$fieldmail.$z2); break;
  3971.                         case TYP_NEWS    : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[8].'-2-'.$fileid.$z2 : $site['NE'].'.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  3972.                         case TYP_PHOTO   : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[9].'-2-'.$fileid.'-'.$fieldmail.$z2 : 'photorama2.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;tconfig='.$fieldmail.$z2); break;
  3973.                         case TYP_DNLOAD  : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[11].'-4-'.$fileid.'-'.$fieldmail.$z2 : $site['DN'].'.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;tconfig='.$fieldmail.$z2); break;
  3974.                         case TYP_FAQ     : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[4].'-3-'.$fileid.$z2 : 'faq.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  3975.                         case TYP_LINKS   : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[6].'-1-'.$fileid.$z2 : 'links.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  3976.                         case TYP_GUESTBK : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[7].'-3-'.$fileid.$z2 : $site['GB'].'.php?lng='.$lng.'&amp;pg='.$fileid.$z2); break;
  3977.                         case TYP_FORUM   : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[5].'-500-'.$fileid.'-'.$fielda1.'-1'.$z2 : $site['TH'].'.php?lng='.$lng.'&amp;pg='.$fileid.'&amp;cat='.$fielda1.'&amp;fid=1'.$z2); break;
  3978.                         case TYP_AGENDA  : $smloc = ($site['URLR'] == 'on' ? $lng.'-'.$urlrw[17].'-22-'.$fileid.'-'.$fileid.'-1-'.$fieldmail.$z2 : 'agenda.php?lng='.$lng.'&amp;idpg='.$fileid.'-'.'&amp;pg='.$fileid.'&amp;agv=1&amp;tconfig='.$fieldmail.$z2); break;
  3979.                         }
  3980.                         $dbw[] = array(
  3981.                             'LOC'=>$site[3].$smloc,
  3982.                             'LM'=>substr($moddate, 0, 4).'-'.substr($moddate, 4, 2).'-'.substr($moddate, 6, 2),
  3983.                             'CF'=>$smfreqs[$smtyp], 'PR'=>'0.5');
  3984.                     }
  3985.                 }
  3986.             }
  3987.             if (!empty($dbw)) CreateSitemapFile($smfiles[$smtyp], $dbw); else @unlink($smfiles[$smtyp]);
  3988.         }
  3989.         if (file_exists(SM_URLS))    $dbws[] = array('LOC'=>substr(SM_URLS, 3), 'LM'=>date('Y-m-d', filemtime(SM_URLS)));
  3990.         if (file_exists(SM_BLOG))    $dbws[] = array('LOC'=>substr(SM_BLOG, 3), 'LM'=>date('Y-m-d', filemtime(SM_BLOG)));
  3991.         if (file_exists(SM_ART))     $dbws[] = array('LOC'=>substr(SM_ART, 3), 'LM'=>date('Y-m-d', filemtime(SM_ART)));
  3992.         if (file_exists(SM_NEWS))    $dbws[] = array('LOC'=>substr(SM_NEWS, 3), 'LM'=>date('Y-m-d', filemtime(SM_NEWS)));
  3993.         if (file_exists(SM_PHOTO))   $dbws[] = array('LOC'=>substr(SM_PHOTO, 3), 'LM'=>date('Y-m-d', filemtime(SM_PHOTO)));
  3994.         if (file_exists(SM_DNLOAD))  $dbws[] = array('LOC'=>substr(SM_DNLOAD, 3), 'LM'=>date('Y-m-d', filemtime(SM_DNLOAD)));
  3995.         if (file_exists(SM_FAQ))     $dbws[] = array('LOC'=>substr(SM_FAQ, 3), 'LM'=>date('Y-m-d', filemtime(SM_FAQ)));
  3996.         if (file_exists(SM_LINKS))   $dbws[] = array('LOC'=>substr(SM_LINKS, 3), 'LM'=>date('Y-m-d', filemtime(SM_LINKS)));
  3997.         if (file_exists(SM_GUESTBK)) $dbws[] = array('LOC'=>substr(SM_GUESTBK, 3), 'LM'=>date('Y-m-d', filemtime(SM_GUESTBK)));
  3998.         if (file_exists(SM_FORUM))   $dbws[] = array('LOC'=>substr(SM_FORUM, 3), 'LM'=>date('Y-m-d', filemtime(SM_FORUM)));
  3999.         if (file_exists(SM_AGENDA))  $dbws[] = array('LOC'=>substr(SM_AGENDA, 3), 'LM'=>date('Y-m-d', filemtime(SM_AGENDA)));
  4000.         if (!empty($dbws)) {
  4001.             $smtxt = '<?xml version="1.0" encoding="'.$charset.'"?>
  4002. <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
  4003.             foreach($dbws as $sm) {
  4004.                 $smtxt .= '
  4005.  <sitemap>
  4006.    <loc>'.$site[3].$sm['LOC'].'</loc>
  4007.    <lastmod>'.$sm['LM'].'</lastmod>
  4008.  </sitemap>';
  4009.             }
  4010.             $smtxt .= '
  4011. </sitemapindex>';
  4012.             WriteFullDB(SITEMAPS, $smtxt);
  4013.         }
  4014.     }
  4015.     if (file_exists(CHEMIN.'robots.txt')) {
  4016.         $robots = file(CHEMIN.'robots.txt');
  4017.         $dbr    = array();
  4018.         foreach($robots as $line)
  4019.             if (substr($line, 0, 8) != 'Sitemap:') $dbr[] = $line;
  4020.         if (!empty($dbws)) $dbr[] = 'Sitemap: '.$site[3].substr(SITEMAPS, 3);
  4021.         $rh = fopen(CHEMIN.'robots.txt', 'w');
  4022.         foreach($dbr as $line) fwrite($rh, $line);
  4023.         fclose($rh);
  4024.     }
  4025. }
  4026.  
  4027. function ActionOnFields($action, $data, $reindex = TRUE) {
  4028.     global $site,$type,$fileid,$status,$creadate,$moddate,$author,$email,
  4029.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  4030.     $fieldweb,$fieldmail,$fieldmod;
  4031.     $id = $action == 'reindex' ? false : $data[AOF_ID];
  4032.     switch ($action) {
  4033.     case 'add'  :
  4034.     case 'migr' :
  4035.         $id = $data[AOF_ID] = IncrNextID();
  4036.         AppendDBFields(DOCID, array($data[AOF_TYPE], $id, $data[AOF_STATUS]));
  4037.         UpdateDocFromInput($action, $id, $data);
  4038.         UpdateDocdates($action, $id, $data[4], $data[3]);
  4039.         UpdateChildren($action, $data);
  4040.         break;
  4041.     case 'mod' :
  4042.         UpdateDocFromInput($action, $id, $data);
  4043.         UpdateDocdates($action, $id, $data[4], $data[3]);
  4044.         break;
  4045.     case 'act' :
  4046.         UpdateDocid($data[AOF_ID], $data[AOF_STATUS]);
  4047.         UpdateDocFromDoc($action, $id, $data[AOF_STATUS]);
  4048.         if ('i' == $data[AOF_STATUS]) {
  4049.             DeactivateInCascade($data[AOF_TYPE], $id);
  4050.         }
  4051.         break;
  4052.     case 'del' :
  4053.         UpdateDocid($id, 'd');
  4054.         UpdateDocFromDoc($action, $id, 'd');
  4055.         UpdateDocdates($action, $id);
  4056.         DeleteInCascade($data[AOF_TYPE], $id);
  4057.         break;
  4058.     case 'sup' :
  4059.         ReadDoc($id);
  4060.         DestroyDBFile(DBBASE.TestFileId($id).INCEXT);
  4061.         DestroyDBFile(DBBASE.TestFileId($id).DBEXT);
  4062.         DestroyDBFile(DBIPBASE.TestFileId($id).DBEXT);
  4063.         $dbdocid = IndexDbFieldsByField(ReadDBFields(DOCID), 1);
  4064.         unset($dbdocid[$id]);
  4065.         WriteDBFields(DOCID, $dbdocid);
  4066.         $dbdates = IndexDbFieldsByField(ReadDBFields(DOCDATES), 0);
  4067.         unset($dbdates[$id]);
  4068.         WriteDBFields(DOCDATES, $dbdates);
  4069.         $dbchild = IndexDbFieldsByField(ReadDBFields(CHILDREN), 0);
  4070.         unset($dbchild[$id]);
  4071.         WriteDBFields(CHILDREN, $dbchild);
  4072.         DestroyInCascade($data[AOF_TYPE], $id);
  4073.         if ($data[AOF_TYPE] == TYP_ART) DestroyKeywords($id);
  4074.         break;
  4075.     }
  4076.     if ($reindex) {
  4077.         switch ($data[0]) {
  4078.         case TYP_LINKS     :
  4079.         case TYP_DNLOAD    :
  4080.         case TYP_PHOTO     :
  4081.         case TYP_FAQ       :
  4082.         case TYP_RSS       :
  4083.         case TYP_BSS       :
  4084.         case TYP_AGENDA    :
  4085.         case TYP_FREEBOX   :
  4086.         case TYP_MENUBOX   :
  4087.         case TYP_OPTMENU   :
  4088.         case TYP_DDMENUBOX :
  4089.         case TYP_OPTDDMENU :
  4090.         case TYP_MENUICO   :
  4091.         case TYP_SOCNET    :
  4092.             UpdateDBdtb($data[0]);
  4093.             break;
  4094.         case TYP_ART :
  4095.             UpdateDBdtb($data[0]);
  4096.             include_once CHEMIN.INCREP."funcrss.php";
  4097.             UpdateRSSart();
  4098.             UpdateRSSall();
  4099.             break;
  4100.         case TYP_BLOG :
  4101.             UpdateDBdtb($data[0]);
  4102.             include_once CHEMIN.INCREP."funcrss.php";
  4103.             UpdateRSSblog();
  4104.             UpdateRSSall();
  4105.             break;
  4106.         case TYP_NEWS :
  4107.             UpdateDBdtb($data[0]);
  4108.             include_once CHEMIN.INCREP."funcrss.php";
  4109.             UpdateRSSnews();
  4110.             UpdateRSSall();
  4111.             break;
  4112.         case TYP_REACT :
  4113.             UpdateDBreact($action, $id);
  4114.             break;
  4115.         case TYP_REBLOG :
  4116.             UpdateDBreblog($action, $id);
  4117.             break;
  4118.         case TYP_FORUM :
  4119.             UpdateDBforum($action, $id);
  4120.             break;
  4121.         }
  4122.         UpdateSitemaps($data[0]);
  4123.     }
  4124.     return $id;
  4125. }
  4126.  
  4127. function InitDBlog($typ) {
  4128.     global $site;
  4129.     $db = array();
  4130.     date_default_timezone_set('UTC');
  4131.     switch ($typ) {
  4132.     case 1  : $db[0] = array(date('H'), 'H', date('Y-m-d-H '));  break;
  4133.     case 12 : $db[0] = array(date('Y'), 'Y', date('Y'));         break;
  4134.     case 24 : $db[0] = array(date('D'), 'D', date('Y-m-d'));     break;
  4135.     case 31 : $db[0] = array(date('M'), 'M', date('Y-m'));       break;
  4136.     default : $db[0] = array(0,         '?', date('Y-m-d-H-i')); break;
  4137.     }
  4138.     date_default_timezone_set($site['TZ']);
  4139.     $db[1] = array_pad(array(), STATS_NBPAGE, 0);
  4140.     $db[2] = array_pad(array(), STATS_NBLANGUE, 0);
  4141.     $db[3] = array_pad(array(), STATS_NBBROWSER, 0);
  4142.     $db[4] = array_pad(array(), STATS_NBOS, 0);
  4143.     $db[5] = array_pad(array(), $typ, 0);
  4144.     $db[6] = array_pad(array(), $typ, 0);
  4145.     $db[7] = array(1);
  4146.     return $db;
  4147. }
  4148.  
  4149. function SaveOldDbLog($db) {
  4150.     global $statscfg;
  4151.     if (!empty($db[0][1])) {
  4152.         switch ($db[0][1]) {
  4153.         case 'D' :
  4154.         case 'M' :
  4155.             if ($statscfg[$db[0][1]] == 'on') {
  4156.                 WriteDbFields(OLDSSTATSREP.$db[0][2].DBEXT, $db);
  4157.             }
  4158.             break;
  4159.         case 'Y' :
  4160.             if ($statscfg[$db[0][1]] == 'on') {
  4161.                 WriteDbFields(OLDSSTATSREP.$db[0][2].DBEXT, $db);
  4162.                 $last = substr($db[0][2], 0, 4) - $statscfg['NBY'];
  4163.                 $files = ExploreFile(OLDSSTATSREP);
  4164.                 foreach ($files as $file) {
  4165.                     if (substr($file, 0, 4) <= $last) {
  4166.                         DestroyDbFile(OLDSSTATSREP.$file);
  4167.                     }
  4168.                 }
  4169.             }
  4170.             break;
  4171.         }
  4172.     }
  4173. }
  4174.  
  4175. function eMailTo($eSubject, $eMessage, $eTo)  {
  4176.     eMailHtmlTo($eSubject, "", $eTo, "", $eMessage);
  4177. }
  4178.  
  4179. function eMailHtmlTo($eSubject, $eMsgHtml, $eTo = '', $eFrom = '', $eMsgTxt = '')  {
  4180.     global $supervision, $user, $charset, $smtp;
  4181.     if (empty($eFrom)) $eFrom = trim($user[1]);
  4182.     $eFromF = $eFrom;
  4183.     $FromTo = $user[0];
  4184.     if ($eMsgTxt == '') {
  4185.         $eMsgText = strip_tags(preg_replace("!<br />|<br />|</p>!i", "\n", preg_replace("!<hr>|<hr />!i", "\n \n", $eMsgHtml)));
  4186.     }
  4187.     if ($eMsgHtml == '') {
  4188.         $eMsgHtml = str_replace("\n", "<br />", str_replace("\n \n", "<hr />", $eMsgTxt));
  4189.     }
  4190.     $std = $supervision[5] == 'standard_3' || $supervision[5] == 'standard_4';
  4191.     $eol = $std ? "\n" : "\r\n";
  4192.  
  4193.     $eSubject      = strtr($eSubject, array('à'=>'a', 'é'=>'e', 'è'=>'e', 'ê'=>'e', 'ë'=>'e', 'î'=>'i', 'ï'=>'i', 'ô'=>'o', 'û'=>'u', 'û'=>'u'));
  4194.     $eSubject      = preg_replace('![^-a-zA-Z0-9_ ]!i', '.', $eSubject);
  4195.     $eHeadersHtml  = "Content-Type: text/html; charset=\"".$charset."\"".$eol;
  4196.     $eHeadersHtml .= "Content-Transfer-Encoding: 8bit".$eol;
  4197.     $eSeparator    = $std ? '-----='.md5(uniqid(rand())) : "==S=E=P=A=R=A=T=O=R==";
  4198.     $eHeaders      = "MIME-Version: 1.0".$eol;
  4199.     $eHeaders     .= "Content-Type: multipart/alternative; boundary=\"".$eSeparator."\"".$eol;
  4200.     $eMessage      = '';
  4201.  
  4202.     if ($supervision[5] == 'standard' || $supervision[5] == 'standard_2' || $supervision[5] == 'phpmailer') {
  4203.         $eHeadersText  = "Content-Type: text/plain; charset=".$charset."\r\n";
  4204.         $eHeadersText .= "Content-Transfer-Encoding: 8bit\r\n";
  4205.         $eMessage      = "--".$eSeparator."\r\n".$eHeadersText."\r\n".$eMsgText."\r\n";
  4206.     }
  4207.     $eMessage .= "--".$eSeparator.$eol.$eHeadersHtml.$eol.$eMsgHtml.$eol;
  4208.     $eMessage .= "--".$eSeparator."--".$eol;
  4209.  
  4210.     $allTo = $eTo == '' ? explode(' ', trim($supervision[10])) : explode(' ', $eTo);
  4211.     $allTo = array_unique($allTo);
  4212.     $eTo   = count($allTo) == 1 ? $allTo[0] : $user[1];
  4213.     $cque  = '';
  4214.     foreach ($allTo as $adr) if ($adr != $eTo) $cque .= ' '.$adr;
  4215.     $allCC = explode(' ', trim($cque));
  4216.     $cque  = count($allTo) == 1 || $supervision[5] == 'phpmailer' ? '' : $eol."Cc: ".str_replace(' ', ',', trim($cque));
  4217.     $eFrom = $eFrom.$cque;
  4218.     if ($supervision[5] == 'standard') {
  4219.         @mail($eTo, $eSubject, $eMessage, 'From: '.$eFrom.$eol.$eHeaders);
  4220.     }
  4221.     else {
  4222.         if ($supervision[5] == 'phpmailer') {
  4223.             $eFiles = array();
  4224.         }
  4225.         include (CHEMIN.INCREP."mail/".$supervision[5].INCEXT);
  4226.     }
  4227. }
  4228.  
  4229. function BreakEMail($eminput) {
  4230.     $eminput = trim($eminput);
  4231.     $em1 = strpos($eminput,"@");
  4232.     $em2 = strrpos($eminput,".");
  4233.     $emoutput[0] = substr($eminput,0,$em1);
  4234.     $emoutput[1] = substr($eminput,$em1+1,$em2-$em1-1);
  4235.     $emoutput[2] = substr($eminput,$em2+1);
  4236.     return $emoutput;
  4237. }
  4238.  
  4239. function StartTimer() {
  4240.     global $starttime;
  4241.     $starttime = microtime(TRUE);
  4242. }
  4243.  
  4244. function StopTimer() {
  4245.     global $starttime;
  4246.     return round ((microtime(TRUE) - $starttime), 2);
  4247. }
  4248.  
  4249. function MakeSeed() {
  4250.     return microtime(TRUE);
  4251. }
  4252.  
  4253. function GenerateUID() {
  4254.     srand(MakeSeed());
  4255.     $gene = rand(1,9);
  4256.     for ($i = 0; $i <9; $i++) {
  4257.         $gene .= rand(0,9);
  4258.     }
  4259.     return $gene;
  4260. }
  4261.  
  4262. function KeepGoodChars($textin) {
  4263.     $textin  = strtr($textin, array(' '=>'_', 'à'=>'a', 'é'=>'e', 'è'=>'e', 'ê'=>'e', 'ë'=>'e', 'î'=>'i', 'ï'=>'i', 'ô'=>'o', 'û'=>'u', 'û'=>'u'));
  4264.     $textout = preg_replace("![^-a-zA-Z0-9_]!i","",$textin);
  4265.     return $textout;
  4266. }
  4267.  
  4268. function ValUnique($tableau) {
  4269.     for ($i = 0, $n = count($tableau); $i < $n; $i++) {
  4270.         $NewTableau[$tableau[$i]] = 1;
  4271.     }
  4272.     @reset($NewTableau);
  4273.     $KeyUnique = array();
  4274.     for ($i = 0, $n = count($NewTableau); $i < $n; $i++) {
  4275.         $KeyUnique[] = key($NewTableau);
  4276.         @next($NewTableau);
  4277.     }
  4278.     return $KeyUnique;
  4279. }
  4280.  
  4281. function compare_id1($a, $b) {
  4282.     return ($a[1] < $b[1] ? -1 : +1 );
  4283. }
  4284.  
  4285. function compare_db2($a, $b) {
  4286.     if ($a[1] == $b[1]) {
  4287.         return($a[2] < $b[2] ? -1 : +1);
  4288.     } else {
  4289.         return($a[1] < $b[1] ? -1 : +1);
  4290.     }
  4291. }
  4292.  
  4293. function GetNavBar(
  4294.     $url,
  4295.     $maxItem,
  4296.     $currentPage = 1,
  4297.     $nbItemPage = 10,
  4298.     $ancre = '',
  4299.     $imgBegin = '',
  4300.     $imgPrev = '',
  4301.     $imgNext = '',
  4302.     $imgEnd = '',
  4303.     $imgBeginN = '',
  4304.     $imgPrevN = '',
  4305.     $imgNextN = '',
  4306.     $imgEndN = '',
  4307.     $imgMinus = '',
  4308.     $imgPlus = '',
  4309.     $decade = 10,
  4310.     $tri = ''
  4311.     )
  4312. {
  4313.     global  $page, $site, $reptheme, $lng, $web;
  4314.     if (empty($web)) include_once CHEMIN.INCREP.'lang/'.$lng.'-web'.INCEXT;
  4315.     $imgBegin  = empty($imgBegin)  ? $reptheme.'/debut.png'      : $imgBegin;
  4316.     $imgPrev   = empty($imgPrev)   ? $reptheme.'/precedent.png'   : $imgPrev;
  4317.     $imgNext   = empty($imgNext)   ? $reptheme.'/suivant.png'     : $imgNext;
  4318.     $imgEnd    = empty($imgEnd)    ? $reptheme.'/fin.png'         : $imgEnd;
  4319.     $imgBeginN = empty($imgBeginN) ? $reptheme.'/debut_n.png'     : $imgBeginN;
  4320.     $imgPrevN  = empty($imgPrevN)  ? $reptheme.'/precedent_n.png' : $imgPrevN;
  4321.     $imgNextN  = empty($imgNextN)  ? $reptheme.'/suivant_n.png'   : $imgNextN;
  4322.     $imgEndN   = empty($imgEndN)   ? $reptheme.'/fin_n.png'       : $imgEndN;
  4323.     $imgMinus  = empty($imgMinus)  ? $reptheme.'/minuspg.png'     : $imgMinus;
  4324.     $imgPlus   = empty($imgPlus)   ? $reptheme.'/pluspg.png'      : $imgPlus;
  4325.     $decade    = TYP_SCREEN == 'WEB' ? $decade : 5;
  4326.  
  4327.     $out   = '';
  4328.     if ($maxItem > $nbItemPage) {
  4329.         $nbPage= $nbItemPage > 0 ? (ceil($maxItem/$nbItemPage)) : 1;
  4330.         $out .= '<div class="textCenter">';
  4331.         $out .= '<table class="textCenter marginAuto"><tr>';
  4332.         if ($currentPage > 1) {
  4333.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4334.                       <a href="'.$url.'1'.$ancre.'"><img src="'.$imgBegin.'" alt="'.$web[339].'" title="'.$web[339].'" /></a>
  4335.                     </td>';
  4336.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4337.                       <a href="'.$url.($currentPage-1).$ancre.'"><img src="'.$imgPrev.'" alt="'.$web[32].'" title="'.$web[32].'" /></a>
  4338.                     </td>';
  4339.         }
  4340.         else {
  4341.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4342.                       <img src="'.$imgBeginN.'" alt="'.$web[339].'" title="'.$web[339].'" />
  4343.                     </td>';
  4344.             $out .= '<td class="navbarLeft'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4345.                       <img src="'.$imgPrevN.'" alt="'.$web[32].'" title="'.$web[32].'" />
  4346.                     </td>';
  4347.         }
  4348.         $out .= '<td class="navbarLeftW">';
  4349.         $nbpg = 1;
  4350.         $pgDebut = floor($currentPage / $decade) * $decade;
  4351.         $pgFin = ceil($currentPage / $decade) * $decade;
  4352.         if ($pgDebut == $pgFin) {
  4353.             $pgDebut = $pgFin - $decade;
  4354.         }
  4355.         if ($currentPage > $pgDebut && $currentPage <= $pgFin) {
  4356.             $decadeDebut = $pgDebut;
  4357.             $decadeFin   = $pgFin;
  4358.             $paq = $nbPage >= $decadeFin ? $decade : $nbPage - $decadeDebut;
  4359.         }
  4360.         if ($currentPage > $decade && $decadeDebut < $nbPage) {
  4361.             if ($nbPage - $decade + $decadeFin > $decade) {
  4362.                 $nbPrevPage = $decade;
  4363.             }
  4364.             else {
  4365.                 $nbPrevPage = $nbPage - $decade + $decadeFin;
  4366.             }
  4367.             if ($nbPrevPage > 1) {
  4368.                 $txtPrevPage = $nbPrevPage." ".$web[340];
  4369.             }
  4370.             else {
  4371.                 $txtPrevPage = $nbPrevPage." ".$web[341];
  4372.             }
  4373.             $out .= '<a href="'.$url.($currentPage + $decadeDebut - $decadeFin).$ancre.'">
  4374.                       <img src="'.$imgMinus.'" alt="'.$txtPrevPage.'" title="'.$txtPrevPage.'" class="imgMinus'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'" />
  4375.                     </a>';
  4376.         }
  4377.         $out .= ' [ ';
  4378.         for($i = 1; $i <= $paq; $i++) {
  4379.             if ($i + $decadeDebut <> $currentPage) {
  4380.                 $out .= '<a href="'.$url.($i + $decadeDebut).'">'.($nbpg + $decadeDebut).'</a> ';
  4381.             } else {
  4382.                 $out .= '
  4383. <style type="text/css">
  4384.  .currNum {
  4385.      text-decoration: underline;
  4386.      font: bold '.($page[2]+2).'px '.$page[1].';
  4387.  }
  4388. </style>
  4389.                <span class="currNum">'.($nbpg + $decadeDebut).'</span> ';
  4390.             }
  4391.             $nbpg++;
  4392.         }
  4393.         $out .= '] ';
  4394.         if($currentPage <= $decadeFin && $decadeFin < $nbPage) {
  4395.             if($nbPage - $decade - $decadeDebut > $decade) {
  4396.                 $nbSuivPage = $decade;
  4397.             }
  4398.             else {
  4399.                 $nbSuivPage = $nbPage - $decade - $decadeDebut;
  4400.             }
  4401.             if ($nbSuivPage > 1) {
  4402.                 $txtSuivPage = $nbSuivPage." ".$web[337];
  4403.             }
  4404.             else {
  4405.                 $txtSuivPage = $nbSuivPage." ".$web[336];
  4406.             }
  4407.             $out .= '<a href="'.$url.$tri.($i + $decadeDebut).$ancre.'">
  4408.                       <img src="'.$imgPlus.'" alt="'.$txtSuivPage.'" title="'.$txtSuivPage.'" class="imgPlus'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'" />
  4409.                     </a>';
  4410.         }
  4411.         $out .='</td>';
  4412.         if ($currentPage < $nbPage) {
  4413.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4414.                       <a href="'.$url.($currentPage + 1).$ancre.'"><img src="'.$imgNext.'" alt="'.$web[34].'" title="'.$web[34].'" /></a>
  4415.                     </td>';
  4416.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4417.                       <a href="'.$url.$nbPage.$ancre.'"><img src="'.$imgEnd.'" alt="'.$web[338].'" title="'.$web[338].'" /></a>
  4418.                     </td>';
  4419.         }
  4420.         else {
  4421.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4422.                       <img src="'.$imgNextN.'" alt="'.$web[34].'" title="'.$web[34].'" />
  4423.                     </td>';
  4424.             $out .= '<td class="navbarRight'.(TYP_SCREEN == 'WEB' ? 'W' : 'M').'">
  4425.                       <img src="'.$imgEndN.'" alt="'.$web[338].'" title="'.$web[338].'" />
  4426.                     </td>';
  4427.         }
  4428.         $out .= '</tr></table></div>';
  4429.     }
  4430.     return $out;    
  4431. }
  4432.  
  4433. function Formatage($format, $in) {
  4434.     $out = '';
  4435.     if (!empty($in) && !empty($format)) {
  4436.         $out = str_replace(' ', '&nbsp;', sprintf($format, $in));
  4437.     }
  4438.     return $out;
  4439. }
  4440.  
  4441. function import($name, $origine = '', $striptags = TRUE, $value='') {
  4442.     switch ($origine) {
  4443.     case 'POST' :
  4444.         $var = isset($_POST[$name]) ? (empty($_POST[$name]) && $value != '' ? $value : $_POST[$name]) : $value;
  4445.         break;
  4446.     case 'GET':
  4447.         $var = isset($_GET[$name]) ? (empty($_GET[$name]) && $value != '' ? $value : $_GET[$name]) : $value;
  4448.         break;
  4449.     default :
  4450.         $var = isset($_POST[$name]) ? (empty($_POST[$name]) && $value != '' ? $value : $_POST[$name]) : (isset($_GET[$name]) ? (empty($_GET[$name]) && $value != '' ? $value : $_GET[$name]) : $value);
  4451.     }
  4452.     if (is_array($var) && $striptags) {
  4453.         foreach ($var as &$v1) {
  4454.             if (is_array($v1)) {
  4455.                 foreach ($v1 as &$v2) {
  4456.                     if (is_array($v2)) {
  4457.                         foreach ($v2 as &$v3) {
  4458.                             $v3 = strip_tags($v3);
  4459.                         }
  4460.                     } else {
  4461.                         $v2 = strip_tags($v2);
  4462.                     }
  4463.                 }
  4464.             } else {
  4465.                 $v1 = strip_tags($v1);
  4466.             }
  4467.         }
  4468.         return $var;
  4469.     } else {
  4470.         return $striptags ? strip_tags($var) : $var;
  4471.     }
  4472. }
  4473.  
  4474. function IncrNextID() {
  4475.     $nextidbk = ReadCounter(NEXTIDBK);
  4476.     $nextid   = ReadCounter(NEXTID) + 1;
  4477.     if ($nextid < $nextidbk) {
  4478.         $nextid = $nextidbk + 10;
  4479.     }
  4480.     while (file_exists(DBBASE.TestFileId($nextid).INCEXT)) {
  4481.         $nextid++;
  4482.     }
  4483.     WriteCounter(NEXTID, $nextid);
  4484.     if ($nextid > $nextidbk) {
  4485.         WriteCounter(NEXTIDBK, $nextid);
  4486.     }
  4487.     return $nextid;
  4488. }
  4489.  
  4490. function AsciiCompare($left,$right) {
  4491.     return strcasecmp($left,$right);
  4492. }
  4493.  
  4494. function SearchOption($serviz_actif, $members_inactif, $typ_code, $typ_nom) {
  4495.     global $userprefs, $members;
  4496.     if (!$serviz_actif) return;
  4497.     if ($userprefs[1] != '' || $members[0] != 'on' || $members_inactif) {
  4498.         return '
  4499.        <option value="'.$typ_code.'">'.$typ_nom.'</option>';
  4500.     }
  4501. }
  4502.  
  4503. function AddCHEMIN($dir) {
  4504.     if ('' == CHEMIN) return $dir;
  4505.     $pos = strpos($dir, CHEMIN);
  4506.     if (0 === $pos) {
  4507.         return $dir;
  4508.     } else {
  4509.         return CHEMIN.$dir;
  4510.     }
  4511. }
  4512.  
  4513. function ExploreDir($dir) {
  4514.     $dir = AddCHEMIN($dir);
  4515.     $array = array();
  4516.     $dossier = opendir($dir);
  4517.     while ($fichier = readdir($dossier)) {
  4518.         if ($fichier != "." && $fichier != ".." && is_dir($dir.$fichier) ) {
  4519.             $array[] = $fichier;
  4520.         }
  4521.     }
  4522.     closedir($dossier);
  4523.     sort($array);
  4524.     return $array;
  4525. }
  4526.  
  4527. function ExploreFile($dir) {
  4528.     $dir = AddCHEMIN($dir);
  4529.     $array = array();
  4530.     $dossier = opendir($dir);
  4531.     while ($fichier = readdir($dossier)) {
  4532.         if (is_file($dir.$fichier) && $fichier != 'index.php') {
  4533.             $array[] = $fichier;
  4534.         }
  4535.     }
  4536.     closedir($dossier);
  4537.     sort($array);
  4538.     return $array;
  4539. }
  4540.  
  4541. function ExploreImg($dir) {
  4542.     $dir = AddCHEMIN($dir);
  4543.     $array = array();
  4544.     $dossier = opendir($dir);
  4545.     while ($fichier = readdir($dossier)) {
  4546.         if (is_file($dir.$fichier) && $fichier != 'index.php') {
  4547.             $path_parts = basename($fichier);
  4548.             $path_parts = substr($path_parts,strrpos($path_parts,".")+1);
  4549.             if (IsImage($path_parts)) {
  4550.                 $array[] = $fichier;
  4551.             }
  4552.         }
  4553.     }
  4554.     closedir($dossier);
  4555.     sort($array);
  4556.     return $array;
  4557. }
  4558.  
  4559. function ForceToAbsolute_callback($m) {
  4560.     global $site;
  4561.     if (preg_match('!^(http|ftp|mailto)s?:!', $m[2])) {
  4562.         return $m[0];
  4563.     } else {
  4564.         if (strpos('#', $m[2]) === 0 ) {
  4565.             return $m[0];
  4566.         } else {
  4567.             return $m[1].$site[3].$m[2];
  4568.         }
  4569.     }
  4570. }
  4571.  
  4572. function ForceToAbsolute($s) {
  4573.     $s = preg_replace_callback('!( src=")([^"]*")!', 'ForceToAbsolute_callback', $s);
  4574.     $s = preg_replace_callback('!( href=")([^"]*")!', 'ForceToAbsolute_callback', $s);
  4575.     return $s;
  4576. }
  4577.  
  4578. function ReadFrSigns() {
  4579.     $tmp = parse_ini_file(FRSIGNS_INI, TRUE);
  4580.     ksort($tmp);
  4581.     return $tmp;
  4582. }
  4583.  
  4584. function WriteFrSigns($datas) {
  4585.     $tmp = '';
  4586.     foreach($datas as $code => $data) {
  4587.         $tmp .= '
  4588. ['.$code.']'.'
  4589. image='.$data['image'].'
  4590. status='.$data['status'].'
  4591. origine='.$data['origine'].'
  4592. ';
  4593.     }
  4594.     file_put_contents(FRSIGNS_INI, $tmp);
  4595. }
  4596.  
  4597. function ReplaceFrSigns($sign) {
  4598.     $sign    = str_replace(array(chr(10), chr(13)), '<br />', $sign);
  4599.     $frsigns = ReadFrSigns();
  4600.     foreach ($frsigns as $code => $frsign) {
  4601.         if ('a' == $frsign['status']) {
  4602.             if ('i' == $frsign['origine']) {
  4603.                 $sign = str_replace($code, '<img src="'.FRSIGNS_IMG.$frsign['image'].'" alt="" title="" />', $sign);
  4604.             } else {
  4605.                 $sign = str_replace($code, '<img src="'.$frsign['image'].'" alt="" title="" />', $sign);
  4606.             }
  4607.         } else {
  4608.             $sign = str_replace($code, '', $sign);
  4609.         }
  4610.     }
  4611.     return $sign;
  4612. }
  4613.  
  4614. function SelectDBThreadByThread($Fields, $id) {
  4615.     $DataDB = array();
  4616.     foreach ($Fields as $Field) {
  4617.         if ($Field[1] == $id && $Field[2] != '0') {
  4618.             $DataDB[] = $Field;
  4619.         }
  4620.     }
  4621.     return $DataDB;
  4622. }
  4623.  
  4624. function SelectDBForumByID($Fields, $id) {
  4625.     $DataDB = array();
  4626.     foreach ($Fields as $Field) {
  4627.         if ($Field[2] == $id) {
  4628.             $DataDB[] = $Field;
  4629.         }
  4630.     }
  4631.     return $DataDB;
  4632. }
  4633.  
  4634. function SelectDBForumByCat($Fields, $cat) {
  4635.     $DataDB = array();
  4636.     foreach ($Fields as $Field) {
  4637.         $temp = explode(',', $Field[12]);
  4638.         if ($cat == $temp[0]) {
  4639.             $DataDB[] = $Field;
  4640.         }
  4641.     }
  4642.     return $DataDB;
  4643. }
  4644.  
  4645. function PollCalculation() {
  4646.     $nb_rep_total = 0;
  4647.     $nb_rep_max   = 1;
  4648.     $dbpoll       = ReadDBFields(DBPOLL);
  4649.     $count_dbpoll = count($dbpoll);
  4650.     for ($i = 1; $i < $count_dbpoll; $i++) {
  4651.         $nb_rep_total = $nb_rep_total + $dbpoll[$i][3];
  4652.         $nb_rep_max = Max($nb_rep_max, $dbpoll[$i][3]);
  4653.     }
  4654.     $dbpoll[0][2] = $nb_rep_total;
  4655.     $dbpoll[0][3] = $nb_rep_max;
  4656.     for ($i = 1; $i < $count_dbpoll; $i++) {
  4657.         if (empty($dbpoll[$i][3])) {
  4658.             $dbpoll[$i][3] = 0;
  4659.             $dbpoll[$i][4] = 0;
  4660.         }
  4661.         else {
  4662.             $dbpoll[$i][4] = round($dbpoll[$i][3]/$nb_rep_total*10000)/100;
  4663.         }
  4664.     }
  4665.     return $dbpoll;
  4666. }
  4667.  
  4668. function SubmitButton($title, $onclick = '', $left = '', $right = '', $typ = 'submit') {
  4669.     global $boutonleft, $boutonright;
  4670.     $onclick = empty($onclick) ? ''           : ' onclick="'.$onclick.'"';
  4671.     $left    = empty($left)    ? $boutonleft  : $left;
  4672.     $right   = empty($right)   ? $boutonright : $right;
  4673.     return $left.'<button type="'.$typ.'" class="clsCursor submitButton" title="'.$title.'"'.$onclick.'>'.$title.'</button>'.$right;
  4674. }
  4675.  
  4676. function ImgSubmitButton($title, $left = '', $right = '', $background = '') {
  4677.     global $page, $reptheme;
  4678.     $left       = empty($left)       ? $reptheme.'/b_last.png'   : $left;
  4679.     $right      = empty($right)      ? $reptheme.'/b_right.png' : $right;
  4680.     $background = empty($background) ? $reptheme.'/b_ton.png'    : $background;
  4681.     return '<img src="'.CHEMIN.$left.'" style="vertical-align:top;" alt="" />'.
  4682. '<button type="submit" style="background:transparent url('.CHEMIN.$background.
  4683. ') repeat-x;  height:22px; margin:0; padding:0; border-radius:0; cursor:pointer;" title="'.$title.'">
  4684. '.$title.'</button><img src="'.CHEMIN.$right.'" style="vertical-align:top;" alt="" />';
  4685. }
  4686.  
  4687. function JavascriptFile($file) {
  4688.     return '
  4689. <script type="text/javascript" src="'.$file.'"></script>';
  4690. }
  4691.  
  4692. function BeginJavascript() {
  4693.     return '
  4694. <script type="text/javascript">
  4695. //<![CDATA[
  4696. <!--
  4697. ';
  4698. }
  4699.  
  4700. function EndJavascript() {
  4701.     return '
  4702. //-->
  4703. //]]>
  4704. </script>
  4705. ';
  4706. }
  4707.  
  4708. function ExecFunctionBox($pos, $box) {
  4709.     global $lng, $lang, $members, $nom, $page, $site, $serviz, $userprefs,
  4710.         $endurl, $npage, $pgtype, $topmess, $skn_logo, $flag1, $flag2,
  4711.         $tabcounter, $plugin_admin_name, $plugin_bar_name;
  4712.     $out = FALSE;
  4713.     if (!empty($box)) {
  4714.         $temp = explode(CONNECTOR, $box);
  4715.         $incl = isset($temp[0]) ? $temp[0] : '';
  4716.         $fnct = isset($temp[1]) ? $temp[1] : '';
  4717.         $args = isset($temp[2]) ? $temp[2] : '';
  4718.         if (!empty($incl) && is_file(CHEMIN.$incl.INCEXT)) {
  4719.             include_once CHEMIN.$incl.INCEXT;
  4720.         }
  4721.         if (!empty($fnct)) {
  4722.             if (empty($args)) {
  4723.                 $args = array_pad(array(), 5, '');
  4724.             } else {
  4725.                 $args = FALSE === strpos($args, ',') ? array($args) : explode(',', $args);
  4726.                 $args = array_pad($args, 5, '');
  4727.             }
  4728.             $out = $fnct($pos, $args);
  4729.         }
  4730.     }
  4731.     return $out;
  4732. }
  4733.  
  4734. function Checked($bool) {
  4735.     return $bool ? ' checked="checked"' : '';
  4736. }
  4737.  
  4738. function Selected($bool) {
  4739.     return $bool ? ' selected="selected"' : '';
  4740. }
  4741.  
  4742. function IsNotEmptyTitle($var) {
  4743.     global $lng, $lang;
  4744.     return $lng == $lang[0] ? !empty($var[2]) : !empty($var[3]);
  4745. }
  4746.  
  4747. function BreakIRC($ircinput) {
  4748.     $ircinput = trim($ircinput);
  4749.     $idirc = explode('@', $ircinput, 2);
  4750.     $ircoutput[0] = $idirc[0];
  4751.     $idtemp = explode('.', $idirc[1], 9);
  4752.     $ircoutput[1] = $idtemp[0];
  4753.     $ircoutput[2] = $idtemp[1];
  4754.     return $ircoutput;
  4755. }
  4756.    
  4757. // Utilisé pour trouver l'ID à partir du numéro de sujet (évite les &thrd=123 remplacé par pg=234)
  4758. function GetThreadId($thrd, $file = DBTHREAD) {
  4759.     $db = ReadDbFields($file);
  4760.     foreach ($db as $dbs) {
  4761.         if ($dbs[1] == $thrd && 0 == $dbs[2]) {
  4762.             return $dbs[3];
  4763.         }
  4764.     }
  4765.     return FALSE;
  4766. }
  4767.  
  4768. function getThreadName($thrd) {
  4769.     $db = ReadDbFields(DBFORUM);
  4770.     foreach ($db as $dbs) {
  4771.         if ($dbs[1] == $thrd) {
  4772.             return $dbs[5];
  4773.         }
  4774.     }
  4775.     return FALSE;
  4776. }
  4777.  
  4778. // Utilisé pour éviter des urls contenant &cat=&id=
  4779. function GetOptionnalArg($name, $value = '') {
  4780.     if (empty($value)) return '';
  4781.     return '&amp;'.$name.'='.$value;
  4782. }
  4783.  
  4784. // Utilisé avec array_reduce($array , 'EstNonVide') pour savoir si le tableau est vide
  4785. function EstNonVide ($r, $i) {
  4786.     return $r && empty($i);
  4787. }
  4788.  
  4789. function legend($legend) {
  4790.     return '<legend class="legend">'.$legend.'</legend>';
  4791. }
  4792.  
  4793. function getForumCat() {
  4794.     static $db_frcat = NULL;
  4795.     if (!isset($db_frcat)) {
  4796.         $frcat = ReadDBFields(DBFORUMCAT);
  4797.         $db_frcat = array();
  4798.         foreach ($frcat as $frc) {
  4799.             if (FALSE !== strpos($frc[0], ',')) {
  4800.                 $temp = explode(',', $frc[0]);
  4801.                 $db_frcat[$temp[0]] = $frc;
  4802.             } else {
  4803.                 $db_frcat[$frc[0]] = $frc;
  4804.             }
  4805.         }
  4806.     }
  4807.     return $db_frcat;
  4808. }
  4809.  
  4810. function getForumCatName($cat) {
  4811.     global $lng, $lang;
  4812.     $cat = getForumCatId($cat);
  4813.     $db_frcat = getForumCat();
  4814.     if (isset($db_frcat[$cat])) {
  4815.         return $db_frcat[$cat][$lng == $lang[0] ? 1 : 2];
  4816.     } else {
  4817.         return '--unknown--';
  4818.     }
  4819. }
  4820.  
  4821. function getForumCatFull($cat) {
  4822.     $cat = getForumCatId($cat);
  4823.     $db_frcat = getForumCat();
  4824.     if (isset($db_frcat[$cat])) {
  4825.         return $db_frcat[$cat][0];
  4826.     } else {
  4827.         return $cat;
  4828.     }
  4829. }
  4830.  
  4831. function getForumCatId($cat) {
  4832.     if (FALSE !== strpos($cat, ',')) {
  4833.         $temp = explode(',', $cat);
  4834.         $cat = $temp[0];
  4835.     }
  4836.     return $cat;
  4837. }
  4838.  
  4839. function AddPluginBox($label= '', $include = NULL, $function = '', $accept = 'LR', $args = '') {
  4840.     global $boxes;
  4841.     if ('' == $label || '' == $function) return FALSE;
  4842.     $boxes[] = array(
  4843.         'label' => $label,
  4844.         'include' => $include,
  4845.         'accept' => $accept,
  4846.         'function' => $function,
  4847.         'args' => $args
  4848.         );
  4849.     return TRUE;
  4850. }
  4851.  
  4852. function checkUserWebsiteUrl($url) {
  4853.     $url = trim($url);
  4854.     if (preg_match('/(ftp|http|https):\/\/[a-z0-9à-ö-]+(.[a-z0-9à-ö-]+)*(:[0-9]+)?(\/.*)?$/i', $url)) {
  4855.         return $url;
  4856.     }
  4857.     return 'http://';    
  4858. }
  4859.  
  4860. function checkEmail($email) {
  4861.     $email = trim($email);
  4862.     return filter_var($email, FILTER_VALIDATE_EMAIL) ? $email : '';
  4863. }
  4864.  
  4865. function displayWriteEmail($org, $author, $email, $img='', $class='') {
  4866.     global $web, $meskin;
  4867.     $lbl   = $img == '' ? ' <b>'.addslashes($author).'</b>' : $img;
  4868.     $class = empty($class) ? $org : $class;
  4869.     $em    = BreakEMail($email);
  4870.     if (TYP_SCREEN == 'MOB') {
  4871.         $out = $lbl;
  4872.     } else {
  4873.         $out = '
  4874.        <a class="'.$class.' gypoplight" href="#?w=300&amp;rel=popup_'.$org.'&amp;btn='.$web[57].'&amp;msk='.$meskin.'" title="'.$web[173].' '.$author.'">'.$lbl.'</a>
  4875.        <div class="'.$class.' gypopup_block" id="popup_'.$org.'">
  4876.          <p class="textCenter popupMail">'.$web[644].'</p>
  4877.          <p class="textCenter popupMail">
  4878.            <a href="javascript:showEmails'.$org.'(\''.$em[0].'\',\''.$em[1].'\',\''.$em[2].'\');">'.addslashes($author).'</a>
  4879.          </p>
  4880.          <p class="textCenter popupMail"><b><span id="lblemail'.$org.'">(--------------)</span></b></p>
  4881.        </div>';
  4882.         $out .=
  4883.         BeginJavascript().'
  4884.          function showEmails'.$org.'(em1, em2, em3) {
  4885.          var emailFinal = "<a href=\'mailto:" + em1 + "@" + em2 + "." + em3 + "\' onclick=\'{$(\'#gyfade , .gypopup_block\').fadeOut(function() {$(\'#gyfade, a.close\').remove();})};\'>" + em1 + " @ " + em2 + "." + em3 + "</a>";
  4886.            document.getElementById("lblemail'.$org.'").innerHTML = emailFinal;
  4887.          }
  4888.        '.EndJavascript();
  4889.     }
  4890.     return $out;
  4891. }
  4892.  
  4893. function getLabel($lbl, $idx=0) {
  4894.     if ($lbl == '' || $idx > 1) return '';
  4895.     $db = explode(CONNECTOR, $lbl);
  4896.     if (empty($db[$idx])) $db[$idx] = $db[0];
  4897.     return trim($db[$idx]);
  4898. }
  4899.  
  4900. function displayErrorMsg($label, $msg) {
  4901.     $sto = str_replace('<li>', '- ', str_replace('</li>', '\n', $msg));
  4902.     $out = '
  4903. <noscript>
  4904.  <fieldset class="bord dispError">
  4905.    <div dispError2>'.$label.'</div>
  4906.    <ul class="textLeft">'.$msg.'</ul>
  4907.  </fieldset>
  4908. </noscript>'.
  4909. BeginJavascript().'
  4910. sto = "'.$label.'\n\n" + "'.$sto.'";
  4911. alert(sto);
  4912. '.EndJavascript();
  4913.     return $out;
  4914. }
  4915.  
  4916. function DestroyKeywords($id) {
  4917.     $db = ReadDBFields(DBKEYWORDS);
  4918.     if (!empty($db)) {
  4919.         sort($db);
  4920.         $n = count($db);
  4921.         $j = 0;
  4922.         while ($db[$j][0] != $id && $j < $n - 1) $j++;
  4923.         for ($i = $j; $i < $n; $i++) {
  4924.             if ($db[$i][0] == $id) unset($db[$i]); else break;
  4925.         }
  4926.         WriteDBFields(DBKEYWORDS, $db);
  4927.     }
  4928. }
  4929.  
  4930. function UpdateKeywords($pg, $t1, $t2='', $k1='', $k2='', $tc=0) {
  4931.     $t1   = strip_tags($t1);
  4932.     $t2   = strip_tags($t2);
  4933.     $k1   = strtolower(substr($k1, -1) == ';' ? substr($k1, 0, -1) : $k1);
  4934.     $k2   = strtolower(substr($k2, -1) == ';' ? substr($k2, 0, -1) : $k2);
  4935.     $atc  = explode('|', $tc);
  4936.     $db   = ReadDBFields(DBKEYWORDS);
  4937.     $i    = 0;
  4938.     $find = false;
  4939.     foreach ($db as $dbs) {
  4940.         if ($pg == $dbs[0]) {
  4941.             $db[$i][1] = $t1;
  4942.             $db[$i][2] = $t2;
  4943.             $db[$i][3] = $k1;
  4944.             $db[$i][4] = $k2;
  4945.             $db[$i][5] = $atc[0];
  4946.             $find      = true;
  4947.             if (trim($k1.$k2) == '') unset($db[$i]);
  4948.             break;
  4949.         }
  4950.         $i++;
  4951.     }
  4952.     if (!$find) {
  4953.         $i         = count($db);
  4954.         $db[$i][0] = $pg;
  4955.         $db[$i][1] = $t1;
  4956.         $db[$i][2] = $t2;
  4957.         $db[$i][3] = $k1;
  4958.         $db[$i][4] = $k2;
  4959.         $db[$i][5] = $atc[0];
  4960.     }
  4961.     WriteDBFields(DBKEYWORDS, $db);
  4962. }
  4963.  
  4964. function GetKeywords($pg) {
  4965.     global $lang, $lng, $site, $urlrw, $z2,
  4966.     $fileid,$status,$creadate,$moddate,$author,$email,
  4967.     $fielda1,$fielda2,$fieldb1,$fieldb2,$fieldc1,$fieldc2,$fieldd1,$fieldd2,
  4968.     $fieldweb,$fieldmail,$fieldmod;
  4969.     $keywords = '';
  4970.     $dbks     = ReadDBFields(DBKEYWORDS);
  4971.     $dbw      = array();
  4972.     foreach ($dbks as $dbk) {
  4973.         if ($pg == $dbk[0]) {
  4974.             $dbw = explode(';', ($lng == $lang[0] ? $dbk[3] : $dbk[4]));
  4975.             break;
  4976.         }
  4977.     }
  4978.     if (!empty($dbw)) {
  4979.         $dbwords = array();
  4980.         $i       = 0;
  4981.         $j       = -1;
  4982.         foreach ($dbks as $dbk) {
  4983.             if ($pg == $dbk[0]) continue;
  4984.             $kws = explode(';', ($lng == $lang[0] ? $dbk[3] : $dbk[4]));
  4985.             foreach ($kws as $kw) {
  4986.                 $dbwords[$i][0] = $kw;
  4987.                 $dbwords[$i][1] = $dbk[0];
  4988.                 $dbwords[$i][2] = $lng == $lang[0] ? $dbk[1] : $dbk[2];
  4989.                 $dbwords[$i][3] = empty($dbk[5]) ? 0 : $dbk[5];
  4990.                 $i++;
  4991.             }
  4992.         }
  4993.         sort($dbwords);
  4994.         $wexist = false;
  4995.         $words  = '';
  4996.         $i      = count($dbwords);
  4997.         foreach ($dbw as $word) {
  4998.             $kw = ' ';
  4999.             $nk = 0;
  5000.             if (!empty($dbwords)) {
  5001.                 $j = 0;
  5002.                 while ($dbwords[$j][0] != $word && $j < $i - 1) $j++;
  5003.                 for ($k = $j; $k < $i; $k++) {
  5004.                     if ($dbwords[$k][0] != $word) break;
  5005.                     ReadDoc($dbwords[$k][1]);
  5006.                     if (isAuthorizedPublication($creadate) && isAccessGranted($fieldmod) && $status == 'a') {
  5007.                         $dbwo = ReadDBFields(DBOPTMENU);
  5008.                         foreach ($dbwo as $item) {
  5009.                             ReadDoc($item[4]);
  5010.                             if (!isAuthorizedPublication($creadate) || !isAccessGranted($fieldmod)) continue;
  5011.                             $urls = explode('||', $lng == $lang[0] ? $fieldd1 : $fieldd2);
  5012.                             $pg   = substr($urls[0], strpos($urls[0], 'pg=') + 3);
  5013.                             $pos  = strpos($pg, '&');
  5014.                             $pg   = $pos === false ? $pg : substr($pg, 0, $pos);
  5015.                             if ($pg == $dbwords[$k][1]) {
  5016.                                 $url0 = 'articles.php?lng='.$lng.'&pg='.$pg.'&mnuid='.$item[5].'&tconfig='.$fieldmail.$z2;
  5017.                                 $url1 = $lng.'-'.$urlrw[20].'-103-'.$pg.'-'.$item[5].'-'.$fieldmail.$z2;
  5018.                                 $url = $site['URLR'] == 'on' ? $url1 : $url0;
  5019.                                 $kw .= '<a href="'.$url.'">'.$dbwords[$k][2].'</a><br />';
  5020.                                 $nk++;
  5021.                                 $wexist = true;
  5022.                                 break;
  5023.                             }
  5024.                         }
  5025.                     }
  5026.                 }
  5027.             }
  5028.             $kw = trim($kw) != '' ? '<div>'.$kw.'</div>' : '';
  5029.             if ($nk > 5) $class = 'keyword3';
  5030.             elseif ($nk > 3) $class = 'keyword2';
  5031.             elseif ($nk > 1) $class = 'keyword1';
  5032.             else $class = 'keyword0';
  5033.             if (trim($word) != '' && $nk > 0) {
  5034.                 if ($kw != '')
  5035.                     $word = '
  5036.       <li class="dir"><span class="'.$class.'">'.$word.'</span><ul><li>'.$kw.'</li></ul></li>';
  5037.                 else
  5038.                     $word = '
  5039.       <li><span class="'.$class.'">'.$word.'</span></li>';
  5040.                 $words .= $word;
  5041.             }
  5042.         }
  5043.         if ($words != '')
  5044.             $keywords = '
  5045.     <ul class="keyword keyword-horizontal">
  5046.       '.$words.'
  5047.     </ul>';
  5048.     }
  5049.     return $keywords;
  5050. }
  5051.  
  5052. function displayQuickConfig($pos, $id = false, $edit = '', $desact = '', $del = '', $drt = false) {
  5053.     global $lng, $page, $reptheme, $web, $userprefs, $serviz, $drtuser;
  5054.     $drtuser[42] = $serviz[31] == $userprefs[1] ? 'admin' : '';
  5055.     if (is_file(CHEMIN.'admin/'.REDACREP.$userprefs[1].INCEXT)) include CHEMIN.'admin/'.REDACREP.$userprefs[1].INCEXT;
  5056.     $isdrt  = $drt ? $drtuser[$drt] == "on" : false;
  5057.     $access = true;
  5058.     $id     = TestFileID($id);
  5059.     if ($drtuser[42] != 'admin' && $id !== FALSE && FileDBExist(DBBASE.$id.INCEXT)) {
  5060.         include(DBBASE.$id.INCEXT);
  5061.         $temp   = explode('|', $author);
  5062.         $author = $temp[0];
  5063.         $grpc   = isset($temp[1]) ? $temp[1] : '';
  5064.         $access = $grpc == '' ? ($author == $userprefs[1]) : isAccessGrantedCol($grpc);
  5065.     }
  5066.     if ($serviz[32] == "on" && ($drtuser[42] == 'admin' || $isdrt) && TYP_SCREEN == 'WEB') {
  5067.         $config = $pos == BOX_EDITO ? 'config3' : 'config6';
  5068.         $img    = $pos == BOX_EDITO ? 'cfgaccueil' : 'cfgboites';
  5069.         $txt    = $pos == BOX_EDITO ? $web[686] : $web[689];
  5070.         $ret = '
  5071.    <div class="f-right">';
  5072.         $ret .= !$access || in_array($drtuser[42], array('redac1', 'redac2')) || is_null($pos) ? '' : '
  5073.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$config.'&amp;selskin='.$page[14].'">
  5074.        <img src="'.$reptheme.'/'.$img.'.png" alt="'.$txt.'" title="'.$txt.'" class="valignMiddle img11x11" />
  5075.      </a>';
  5076.         $ret .= !$access || $edit == '' ? '' : '
  5077.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$edit.'">
  5078.        <img src="'.$reptheme.'/edit.png" alt="'.$web[308].'" title="'.$web[308].'" class="valignMiddle" />
  5079.      </a>';
  5080.         $ret .= !$access || $desact == '' ? '' : '
  5081.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$desact.'">
  5082.        <img src="'.$reptheme.'/desact.png" alt="'.$web[333].'" title="'.$web[333].'" class="valignMiddle" />
  5083.      </a>';
  5084.         $ret .= !$access || $del == '' ? '' : '
  5085.      <a href="'.CHEMIN.'admin/admin.php?lng='.$lng.'&amp;pg='.$del.'">
  5086.        <img src="'.$reptheme.'/del.png" alt="'.$web[324].'" title="'.$web[324].'" class="valignMiddle" />
  5087.      </a>';
  5088.         $ret .= '
  5089.    </div>';
  5090.     } else
  5091.         $ret = '';
  5092.     return $ret;
  5093. }
  5094.  
  5095. function getNewUpdateDoc($crea, $mod, $accept='off') {
  5096.     global $reptheme, $userprefs, $web, $serviz;
  5097.     if ($accept == 'off' || ($accept == 'mbr' && $userprefs[1] == '') || $serviz[135] <= 0) return '';
  5098.     $img     = '';
  5099.     $ctrlday = date('Ymdhi', strtotime('-'.$serviz[135].' day'));
  5100.     if ($mod > $crea && $mod > $ctrlday) $img = 'majdoc';
  5101.     if (($mod - $crea) == 0 && $crea > $ctrlday) $img = 'newdoc';
  5102.     $title = $img == 'majdoc' ? $web[196] : $web[371];
  5103.     return empty($img) ? '' : '<img src="'.$reptheme.'/'.$img.'.gif" alt="'.$title.'" title="'.$title.'" class="valignMiddle" />&nbsp;';
  5104. }
  5105.  
  5106. function setURLrewriting($mode) {
  5107.     global $urlrw, $site;
  5108.     if (!is_file(CHEMIN.'.htaccess')) return;
  5109.     $stop     = '# URL rewriting'.chr(13).chr(10);
  5110.     $htaccess = file(CHEMIN.'.htaccess');
  5111.     switch ($mode) {
  5112.     case 'on' :
  5113.         if (in_array($stop, $htaccess)) break;
  5114.         $uheader = file(CONFIGREP.'uheader.dtb');
  5115.         $urules  = file(CONFIGREP.'urules.dtb');       
  5116.         for ($i = 0; $i < count($urules); $i++) {
  5117.             $pos = strpos($urules[$i], '##');
  5118.             $st = $pos === false ? '' : substr($urules[$i], $pos + 2);
  5119.             $st = $st == '' ? '' : substr($st, 0, strpos($st, '##'));
  5120.             if ($st != '') $urules[$i] = str_replace('##'.$st.'##', $site[$st], $urules[$i]);
  5121.             $pos = strpos($urules[$i], '#');
  5122.             $st = $pos === false ? '' : substr($urules[$i], $pos + 1);
  5123.             $st = $st == '' ? '' : substr($st, 0, strpos($st, '#'));
  5124.             if ($st != '') $urules[$i] = str_replace('#'.$st.'#', $urlrw[$st], $urules[$i]);
  5125.         }
  5126.         if ($htaccess[count($htaccess) - 1] == chr(13).chr(10)) unset($htaccess[count($htaccess) - 1]);
  5127.         $htaccess = array_merge($htaccess, $uheader, $urules);
  5128.         $dir      = CONFIGREP.'rules/';
  5129.         if (is_dir($dir)) {
  5130.             $files = scandir($dir);
  5131.             if ($files !== false) {
  5132.                 foreach ($files as $file) {
  5133.                     $info = pathinfo($file);
  5134.                     if (isset($info['extension']) && $info['extension'] == 'dtb') {
  5135.                         $rules    = file($dir.$file);
  5136.                         $htaccess = array_merge($htaccess, $rules);
  5137.                         unset($rules);
  5138.                     }
  5139.                 }
  5140.                 unset($allrules);
  5141.             }
  5142.         }      
  5143.         $st = '';
  5144.         foreach ($htaccess as $hta) $st .= $hta;
  5145.         $perms = substr(sprintf('%o', fileperms(CHEMIN.'.htaccess')), -4);
  5146.         SetChmod(CHEMIN.'.htaccess');
  5147.         $handle = fopen(CHEMIN.'.htaccess', 'w');
  5148.         fwrite($handle, $st);
  5149.         fclose($handle);
  5150.         SetChmod(CHEMIN.'.htaccess', $perms);
  5151.         break;
  5152.     case '' :
  5153.         if (!in_array($stop, $htaccess)) break;
  5154.         $st = '';
  5155.         foreach ($htaccess as $hta)
  5156.             if ($hta != $stop) $st .= $hta; else break;
  5157.         $perms = substr(sprintf('%o', fileperms(CHEMIN.'.htaccess')), -4);
  5158.         SetChmod(CHEMIN.'.htaccess');
  5159.         $handle = fopen(CHEMIN.'.htaccess', 'w');
  5160.         fwrite($handle, $st);
  5161.         fclose($handle);
  5162.         SetChmod(CHEMIN.'.htaccess', $perms);
  5163.         break;
  5164.     }
  5165. }
  5166.  
  5167. function isAuthorizedPublication($pdate) {
  5168.     $datespub = explode('-', $pdate);
  5169.     $datenow  = GetCurrentDateTime();
  5170.     return ($datespub[0] <= $datenow) && (empty($datespub[1]) ? true : $datespub[1] > $datenow);
  5171. }
  5172.  
  5173. function GetListCollaboratorEmail($typ) {
  5174.     global $drtuser;
  5175.     $drt    = array(TYP_NEWS => 14, TYP_BLOG => 39, TYP_REBLOG => 40, TYP_GUESTBK => 22, TYP_FORUM => 23, TYP_REACT => 16);
  5176.     $drtsv  = array(TYP_NEWS => 2,  TYP_BLOG => 3,  TYP_REBLOG => 4,  TYP_GUESTBK => 5,  TYP_FORUM => 6,  TYP_REACT => 1);
  5177.     $dbcoll = array();
  5178.     $dbwork = scandir(CHEMIN.'admin/'.REDACREP);
  5179.     foreach($dbwork as $file) {
  5180.         $info = pathinfo($file);
  5181.         if (isset($info['extension']) && $info['extension'] == 'inc') {
  5182.             $coll = $info['filename'];
  5183.             if (is_file(CHEMIN.'admin/'.REDACREP.$coll.INCEXT)) {
  5184.                 include CHEMIN.'admin/'.REDACREP.$coll.INCEXT;
  5185.                 if ($drtuser[$drt[$typ]] == 'on' && $drtusersv[$drtsv[$typ]] == 'on' && file_exists(MSGREP.$coll.DBEXT)) {
  5186.                     $userdb = ReadDBFields(MSGREP.$coll.DBEXT);
  5187.                     $dbcoll[] = $userdb[1][3];
  5188.                 }
  5189.             }
  5190.         }
  5191.     }
  5192.     return $dbcoll;
  5193. }
  5194.  
  5195. function RecursiveRemoteDir($dir) {
  5196.     if (is_dir($dir)) {
  5197.         $files = scandir($dir);
  5198.         foreach ($files as $file) {
  5199.             if ($file != '.' && $file != '..') {
  5200.                 if (filetype($dir.'/'.$file) == 'dir')
  5201.                     RecursiveRemoteDir($dir.'/'.$file);
  5202.                 else
  5203.                     DestroyDBFile($dir.'/'.$file);
  5204.             }
  5205.         }
  5206.         reset($files);
  5207.         SetChmod($dir);
  5208.         @rmdir($dir);
  5209.     }
  5210. }
  5211.  
  5212. function RecursiveDeleteDir($dir, $bad = array('index.php', '.htaccess')) {
  5213.     if (is_dir($dir)) {
  5214.         $files = scandir($dir);
  5215.         foreach ($files as $file) {
  5216.             if ($file != '.' && $file != '..') {
  5217.                 if (filetype($dir.'/'.$file) == 'dir')
  5218.                     RecursiveDeleteDir($dir.'/'.$file);
  5219.                 elseif (!in_array($file, $bad))
  5220.                     DestroyDBFile($dir.'/'.$file);
  5221.             }
  5222.         }
  5223.         reset($files);
  5224.     }
  5225. }
  5226.  
  5227. function DeleteDir($dir, $bad = array('index.php', '.htaccess')) {
  5228.     if (is_dir($dir)) {
  5229.         $files = scandir($dir);
  5230.         foreach ($files as $file) {
  5231.             if ($file != '.' && $file != '..') {
  5232.                 if (!in_array($file, $bad))
  5233.                     DestroyDBFile($dir.'/'.$file);
  5234.             }
  5235.         }
  5236.         reset($files);
  5237.     }
  5238. }
  5239.  
  5240. function recursiveCopy($src, $dest) {
  5241.     $dir = opendir($src);
  5242.     MakeDir($dest);
  5243.     while (false !== ($file = readdir($dir))) {
  5244.         if (($file != '.') && ($file != '..')) {
  5245.             if (is_dir($src.'/'.$file))
  5246.                 recursiveCopy($src.'/'.$file, $dest.'/'.$file);
  5247.             else
  5248.                 copy($src.'/'.$file, $dest.'/'.$file);
  5249.         }
  5250.     }
  5251.     closedir($dir);
  5252. }
  5253.  
  5254. function ReplaceSpecialChars($text) {
  5255.     $chars_in  = array('$', '%', '.', '/', ':', '<', '=', '>', '?', '[', ']', '^', '{', '}');
  5256.     $chars_out = array('&#036;', '&#037;', '&#046;', '&#047;', '&#058;', '&#060;', '&#061;', '&#062;', '&#063;', '&#091;', '&#093;', '&#094;', '&#123;', '&#125;');
  5257.     return str_replace($chars_in, $chars_out, $text);
  5258. }
  5259.  
  5260. function SetChmod($file, $mode='') {
  5261.     global $site;
  5262.     $site['MF'] = empty($site['MF']) ? '0644' : $site['MF'];
  5263.     $site['MD'] = empty($site['MD']) ? '0755' : $site['MD'];
  5264.     $typ        = is_dir($file) ? 'dir' : 'file';
  5265.     $value      = empty($typ) || $typ == 'file' ? $site['MF'] : $site['MD'];
  5266.     $value      = empty($mode) ? $value : $mode;
  5267.     return @chmod($file, intval($value, 8));
  5268. }
  5269.  
  5270. function MakeDir($dir, $mode='') {
  5271.     global $site;
  5272.     $value = empty($site['MD']) ? '0755' : $site['MD'];
  5273.     $value = empty($mode) ? $value : $mode;
  5274.     return @mkdir($dir, intval($value, 8));
  5275. }
  5276.  
  5277. function DisplayDownArrow($dynbox) {
  5278.     $rarrow = '<span class="dispArrow" title="">&#xe807;</span>';
  5279.     return TYP_SCREEN == 'WEB' ? '' : ($dynbox == 'off' ? '' : $rarrow);
  5280. }
  5281.  
  5282. function getIPadress($adress) {
  5283.     if (strstr($adress, ', ')) {
  5284.         $ips = explode(', ', $adress);
  5285.         $adress = $ips[0];
  5286.     }
  5287.     return $adress;
  5288. }
  5289.  
  5290. function getPGTXT($stxt='') {
  5291.     $txt = '';
  5292.     while(!empty($stxt)) {
  5293.         $pos0 = mb_strpos($stxt, '<pre class=');
  5294.         $pos1 = mb_strlen($stxt);
  5295.         $txt0 = htmlspecialchars_decode(mb_substr($stxt, 0, $pos0 !== false ? $pos0 : $pos1));
  5296.         if (!empty($txt0)) {
  5297.             $simg = $txt0;
  5298.             $txt1 = '';
  5299.             while(!empty($simg)) {
  5300.                 $sp0 = mb_strpos($simg, '<img');
  5301.                 $sp1 = mb_strlen($simg);
  5302.                 if ($sp0 !== false) {
  5303.                     $sp1  = mb_strpos(mb_substr($simg, $sp0), '>');
  5304.                     $img  = mb_substr($simg, $sp0, $sp1 + 1);
  5305.                     $txt0 = preg_match('!https?://|ftps?://|www.!', $img) ? str_replace($img, '', $txt0) : $txt0;
  5306.                 }
  5307.                 $simg = trim(mb_substr($simg, $sp1 + 1));
  5308.             }
  5309.         }
  5310.         $txt .= $txt0;
  5311.         if ($pos0 !== false) {
  5312.             $pos1 = mb_strpos($stxt, '</pre>') + 6;
  5313.             $txt .= mb_substr($stxt, $pos0, $pos1 - $pos0);
  5314.         }
  5315.         $stxt = trim(mb_substr($stxt, $pos1));
  5316.     }
  5317.     return $txt;
  5318. }
  5319.  
  5320. ?>
Add Comment
Please, Sign In to add comment