home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / modules / forums / attachment.php next >
Encoding:
PHP Script  |  2002-09-16  |  26.2 KB  |  625 lines

  1. <?php 
  2. ###################################################################### # Modulo Splatt Forum per PHP-NUKE 
  3. #------------------------- 
  4. # Versione: 3.2 
  5. # Copyright (c) 2002 by: 
  6. # Giorgio Ciranni (~Splatt~) 
  7. # (http://www.splatt.it) 
  8. # (webmaster@splatt.it) 
  9. # Supporto tecnico disponibile sul Forum di www.splatt.it 
  10. ###################################################################### # Gestione Attachment 
  11. # ------------------------------------------------------------------- 
  12. # Realizzato da  : JoyDivision 
  13. #            url : http://www.bergamoblog.it 
  14. #          email : gava@bergamoblog.it 
  15. ###################################################################### # Splatt Forum is free software. You can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License. 
  16. # Splatt Forum is distributed in the hope that it will be useful, 
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  19. # GNU General Public License for more details. 
  20. # You should have received a copy of the GNU General Public License 
  21. # along with this program; if not, write to the Free Software 
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
  23. # 02111-1307  USA 
  24. ###################################################################### # Variabili Globali : 
  25. # $AtchCookieName          = Attachment Cookie Name 
  26. # $AtchTempDir             = Attachment Temporary Directory 
  27. #                            (If you wnat to change it you must craete #                            phisically the directory with the right permissions) 
  28. # AtchDir                  = Attachment Directory 
  29. #                            (If you wnat to change it you must craete #                            phisically the directory with the right permissions) 
  30. # $AtchUnpermittedFileType = File Ext Not Accepted : (Ex: bat, exe, cmd ..) 
  31. #                            Insert Mime type separated by (":") 
  32. # $AtchMaxUploadSize       = Total Maximum File Size Allowed (in Kb) 
  33. ###################################################################### 
  34. $AtchCookieName = "AtchForumC"; 
  35. $AtchTempDir = "modules/$name/downloadtemp"; 
  36. $AtchDir = "modules/$name/attachment"; 
  37. $AtchUnpermittedFileType = "bat:cmd:exe"; 
  38.  
  39. $result = mysql_query("select max_upfile from ${prefix}_forum_config");
  40.     list($max_upfile) = mysql_fetch_row($result);
  41.  
  42. $AtchMaxUploadSize = $max_upfile;
  43.  
  44. require_once("mainfile.php");
  45. include_once("modules/$name/functions.php");
  46. include_once("modules/$name/auth.php");
  47.  
  48. ###################################################################### # Funzione : CheckCookieEnabled() 
  49. # Input    : NONE 
  50. # Outut    : True  - Cookie Abilitati 
  51. #            False - Cookie NonAbilitati 
  52. # Il Modulo di Upload File funziona esclusivamente se il client ha 
  53. # abilitato i cookie. 
  54. # Questa funzione verifica questa condizione tornando un Boolean di 
  55. # Vero (abilitati) o Falso (Disabilitati) 
  56. ###################################################################### 
  57. function CheckCookieEnabled(){ 
  58.          global $AtchCookieName, $AtchOp, $RealAtchOp, $name; 
  59.          if (isset($GLOBALS["$AtchCookieName"])){ 
  60.             if ($AtchOp=="testcookie"){ 
  61.                 $AtchOp = $RealAtchOp; 
  62.                 echo "<html><body><script language='javascript'>document.location.href='modules.php?op=modload&name=$name&file=attachment&AtchOp=$AtchOp&".time()."';</script></body></html>"; 
  63.                 exit; 
  64.             } 
  65.             return (true); 
  66.          } else { 
  67.             if ($AtchOp=="testcookie"){ 
  68.                 echo "<html><body><center><h3>"._FORUMENABLECOOKIE 
  69.                     ."<br><a href='javascript:window.close();'>"._FORUMCLOSE."</a></hr3></center></body></html>"; 
  70.             } else { 
  71.                 $better_token = base64_encode(md5(uniqid(mt_rand())).":0"); 
  72.                 setcookie($AtchCookieName,"$better_token"); 
  73.                 echo "<html><body><script language='javascript'>document.location.href='modules.php?op=modload&name=$name&file=attachment&AtchOp=testcookie&RealAtchOp=$AtchOp&".time()."';</script></body></html>"; 
  74.             } 
  75.             return (false); 
  76.          } 
  77.  
  78. ###################################################################### # Funzione : decodeAtchCookie() 
  79. # Input    : $AtchCookie - Attachment Cookie Var 
  80. # Outut    : NONE 
  81. # Converte la Variabile cookie in Array 
  82. ###################################################################### 
  83. function decodeAtchCookie($AtchCookie) { 
  84.    $xarr = base64_decode($AtchCookie); 
  85.    return(explode(":", $xarr)); 
  86.  
  87. ###################################################################### # Funzione : checkUserModEnabled() 
  88. # Input    : $postid - Posti Unique Id 
  89. # Outut    : NONE 
  90. # Controlla se l'utente Φ abilitato per la modifica degli attachment 
  91. ###################################################################### 
  92. function checkUserModEnabled($postid){ 
  93.    global $db, $moderators, $user, $prefix; 
  94.    $sql = "SELECT poster_id FROM ${prefix}_posts WHERE (post_id = '$postid')"; 
  95.    if(!$result = mysql_query($sql, $db)){ 
  96.        return(false); 
  97.    } 
  98.    list($puid) = mysql_fetch_array($result); 
  99.    if (isset($user)) { 
  100.       if (!is_array($user)){ 
  101.            $userdata = base64_decode($user); 
  102.            $userdata = explode(":", $userdata); 
  103.       } else { 
  104.            $userdata = $user; 
  105.       } 
  106.       if ($userdata[0]==$puid){ 
  107.          return(true); 
  108.       } 
  109. //$moderators= array($moderators); 
  110.       reset ($moderators); 
  111.       while(list($null, $mods) = each($moderators)) { 
  112.             while(list($mod_id, $mod_name) = each($mods)) { 
  113.                  if ($userdata[0] == $mod_id) { 
  114.                     $mod = $mod_id; 
  115.                     break 2; 
  116.                  } 
  117.             } 
  118.       } 
  119.        if ($userdata[0]==$mod){ 
  120.          return(true); 
  121.        } else { 
  122.          return(false); 
  123.        } 
  124.    } 
  125.    return(false); 
  126.  
  127. ###################################################################### # Funzione : manageAttach() 
  128. # Input    : NONE 
  129. # Outut    : NONE 
  130. # Funzione per la gestione dei File Attachment 
  131. ###################################################################### 
  132. function manageAttach($IdAtchPostId=null){ 
  133.    global $AtchOp, $xremove, $xcancel, $xattach, $xattachlist, $attfile, $AtchTempDir, $AtchDir, $totattsize, 
  134.           $AtchCookieName, $name, $HTTP_POST_FILES, $AtchUnpermittedFileType, $AtchMaxUploadSize,$Default_Theme, $user; 
  135.    //Cancella eventuali file spazzatura 
  136.    garbageAtchFile(); 
  137.    // Recupero Informazioni del tema 
  138.    if(is_user($user)) { 
  139.      $user2 = base64_decode($user); 
  140.      $cookie = explode(":", $user2); 
  141.      if($cookie[9]=="") $cookie[9]=$Default_Theme; 
  142.      if(isset($theme)) $cookie[9]=$theme; 
  143.      if(!$file=@opendir("themes/$cookie[9]")) { 
  144.          $ThemeSel = $Default_Theme; 
  145.      } else { 
  146.          $ThemeSel = $cookie[9]; 
  147.      } 
  148.    } else { 
  149.      $ThemeSel = $Default_Theme; 
  150.    } 
  151.    include_once("themes/$ThemeSel/theme.php"); 
  152.    $StyleSheetTag = "<LINK REL=\"StyleSheet\" HREF=\"themes/$ThemeSel/style/style.css\" TYPE=\"text/css\">"; 
  153.    $arrAtchCookie=decodeAtchCookie($GLOBALS["$AtchCookieName"]); 
  154.    if ($arrAtchCookie[1]==0 && $IdAtchPostId!=null){ 
  155.        $arrAtchCookie[1]=getTotAtchSize($IdAtchPostId)/1024; 
  156.    } 
  157.    $AtchError =""; 
  158.    $AtchDisanled =""; 
  159.    if ($xremove){ 
  160.       //cancella il file selezionato 
  161.       $arrAtchCookie[1] -= filesize(realpath($AtchTempDir)."/".$xattachlist)/ 1024; 
  162.         //gio 
  163.         if (isset($xattachlist)){ 
  164.         //gio 
  165.       if (file_exists(realpath($AtchTempDir)."/".$xattachlist)){ 
  166.          $res = unlink(realpath($AtchTempDir)."/".$xattachlist); 
  167.          $cont=-1; 
  168.         } 
  169.       foreach ($arrAtchCookie as $eleVal){ 
  170.          if ($eleVal!=$xattachlist){ 
  171.             $cont++; 
  172.             $NewarrAtchCookie[] =$eleVal; 
  173.          } 
  174.       } 
  175.       $arrAtchCookie = $NewarrAtchCookie; 
  176.       unset($NewarrAtchCookie); 
  177.    } 
  178. //gio 
  179. //gio 
  180.    if ($xcancel){ 
  181.       //cancella tutti i file con lo stesso token 
  182.       $cont=-1; 
  183.       foreach ($arrAtchCookie as $eleVal){ 
  184.          $cont++; 
  185.          if ($cont>1){ 
  186.             if(file_exists(realpath($AtchTempDir)."/".$eleVal)){ 
  187.                $res = unlink(realpath($AtchTempDir)."/".$eleVal); 
  188.             } 
  189.          } else { 
  190.            $NewarrAtchCookie[]=$eleVal; 
  191.          } 
  192.       } 
  193.       $NewarrAtchCookie[1]=0; 
  194.       $arrAtchCookie = $NewarrAtchCookie; 
  195.       unset($NewarrAtchCookie); 
  196.    } 
  197.    if ($xattach){ 
  198.        if(is_uploaded_file($attfile)) { 
  199.           include("modules/$name/mime.inc.php"); 
  200.           $xprog = 0; 
  201.           if ($AtchMaxUploadSize>round($arrAtchCookie[1]+(basename($HTTP_POST_FILES['attfile']['size'])/1024))){ 
  202.               $AtchFileName =basename($HTTP_POST_FILES['attfile']['name']); 
  203.               $AtchFileType = $HTTP_POST_FILES['attfile']['type']; 
  204.               $arrTmp = explode(".",$AtchFileName); 
  205.               $AtchFileExt = $arrTmp[count($arrTmp)-1]; 
  206.               unset($arrTmp); 
  207.               SetMime($AtchFileExt,$AtchFileType); 
  208.               $AtchFileName .=".atch"; 
  209.               if (false===strpos($AtchUnpermittedFileType,$AtchFileExt)){ 
  210.                   while (file_exists(realpath($AtchTempDir)."/".$arrAtchCookie[0].".".$xprog.".".$AtchFileName)){ 
  211.                       $xprog++; 
  212.                   } 
  213.                   $res = move_uploaded_file($attfile, realpath($AtchTempDir)."/".$arrAtchCookie[0].".".$xprog.".".$AtchFileName); 
  214.                   $arrAtchCookie[] =$arrAtchCookie[0].".".$xprog.".".$AtchFileName; 
  215.                   $arrAtchCookie[1] += basename($HTTP_POST_FILES['attfile']['size'])/ 1024; 
  216.               } else { 
  217.                   $AtchError = _FORUMATCHMERRINVFILETYPE; 
  218.               } 
  219.           } else { 
  220.               $AtchError = _FORUMATCHMERRMAXSIZEREACH; 
  221.           } 
  222.        } 
  223.    } 
  224.    $cookiestr =""; 
  225.    $cont=-1; 
  226.    foreach ($arrAtchCookie as $eleVal){ 
  227.        $cont++; 
  228.        if ($cont>0){ 
  229.           $cookiestr .= ":"; 
  230.        } 
  231.        $cookiestr .= $eleVal; 
  232.    } 
  233.    header ("Cache-Control: no-cache, must-revalidate"); 
  234.    setcookie($AtchCookieName,base64_encode($cookiestr)); 
  235.    if ($xcancel){ 
  236.       echo"<html><body><script language='javascript'>window.close();</script></body></html>"; 
  237.       exit(); 
  238.    } 
  239.    if ($AtchMaxUploadSize<$arrAtchCookie[1]){ 
  240.       $AtchDisanled ="disabled"; 
  241.    } 
  242.    echo "<html>\n" 
  243.        ."$StyleSheetTag\n" 
  244.        ."<body bgcolor='$bgcolor4'>"; 
  245.    echo "<FORM action='modules.php?op=modload&name=$name&file=attachment&AtchOp=$AtchOp' enctype='multipart/form-data' method='post' name=doattach>\n" 
  246.        ."<INPUT TYPE='hidden' name='MAX_FILE_SIZE' value='".($AtchMaxUploadSize*1024)."'>" 
  247.        ."<TABLE border=0 cellPadding=0 cellSpacing=0 width=600><TR>\n" 
  248.        ."<TD rowspan=7 width=15> </TD>\n" 
  249.        ."<TD colspan=5>"._FORUMATCHMMODEINFO."\n" 
  250.        ."<HR color=#00008b size=1><BR></TD></TR>\n" 
  251.        ."<TR><TD valign=top>1.</TD>\n" 
  252.        ."<TD valign=top width='48%'>"._FORUMATCHMMODEINFO1."</TD>\n" 
  253.        ."<TD valign=top>2.</TD>\n" 
  254.        ."<TD colspan=2 width='48%'>"._FORUMATCHMMODEINFO2."<BR><BR></TD></TR>\n" 
  255.        ."<TR><TD></TD>\n" 
  256.        ."<TD rowspan=2 valign=top>"._FORUMATCHMFINDFILE.":<BR><INPUT name=attfile type=file><br><b>$AtchError</b></TD>\n" 
  257.        ."<TD></TD>\n" 
  258.        ."<TD></TD>\n" 
  259.        ."<TD>"._FORUMATCHM.":</TD></TR>\n" 
  260.        ."<TR>\n" 
  261.        ."<TD></TD>\n" 
  262.        ."<TD></TD>\n" 
  263.        ."<TD align=middle valign=top><INPUT $AtchDisanled class=sbttn name=xattach type=submit value='"._FORUMATCHMUPLOAD."'>\n" 
  264.        ."<P>\n" 
  265.        ."<INPUT class=sbttn name=xremove type=submit value='"._FORUMATCHMREMOVE."'>\n" 
  266.        ."</P></TD>\n" 
  267.        ."<TD valign=top align=left><SELECT name=xattachlist size=5>\n"; 
  268.        $xpos=-1; 
  269.        foreach ($arrAtchCookie as $eleVal){ 
  270.           $xpos++; 
  271.           if ($xpos>1){ 
  272.              $splitEle = explode(".",$eleVal); 
  273.              $AtchName=""; 
  274.              $numEle = count($splitEle); 
  275.              for($cont=2;$cont<$numEle-1;$cont++){ 
  276.                  if ($cont>2){ 
  277.                     $AtchName .="."; 
  278.                  } 
  279.                  $AtchName .=$splitEle[$cont]; 
  280.              } 
  281.              echo "<OPTION value='$eleVal'>$AtchName</OPTION>"; 
  282.           } 
  283.        } 
  284.        if ($xpos<2){ 
  285.            echo "<OPTION value=nOT>"._FORUMATCHMEMPTY."</OPTION>"; 
  286.        } 
  287.    echo "</SELECT></td></tr>\n" 
  288.        ."<tr><td> </td><td> </td><td> </td><td> </td><td>" 
  289.        ._FORUMATCHMTOTSIZE." = <B>".round($arrAtchCookie[1])." K</B><br>($AtchMaxUploadSize K "._FORUMATCHMMAXSIZE.")</TD></TR>\n" 
  290.        ."<TR>\n" 
  291.        ."<TD align=right colspan=5>\n" 
  292.        ."<HR color=#00008b SIZE=1>\n" 
  293.        ."<INPUT name=xdone type=button value=' OK ' onclick='window.close();'> <INPUT name=xcancel type=submit value='"._FORUMATCHMCANCEL."'>\n" 
  294.        ."<P></P></TD></TR>\n" 
  295.        ."</TABLE></FORM>\n"; 
  296.    echo "</body></html>"; 
  297.  
  298. ###################################################################### # Funzione : ConfirmAttach() 
  299. # Input    : $idForumPost : Post Unique Id 
  300. # Outut    : NONE 
  301. # Trasferisce gli attachment dalla temporary Directory a quella definitiva 
  302. ###################################################################### 
  303. function ConfirmAttach($idForumPost){ 
  304.    global $AtchCookieName, $AtchTempDir, $AtchDir; 
  305.    $arrAtchCookie=decodeAtchCookie($GLOBALS["$AtchCookieName"]); 
  306.    $cont=-1; 
  307.    foreach ($arrAtchCookie as $eleVal){ 
  308.        $cont++; 
  309.        if ($cont>1){ 
  310.            $splitEle = explode(".",$eleVal); 
  311.            $AtchPref=md5($idForumPost); 
  312.            $AtchName=""; 
  313.            for($cont=2;$cont<count($splitEle);$cont++){ 
  314.               $AtchName .="."; 
  315.               $AtchName .=$splitEle[$cont]; 
  316.            } 
  317.            while (file_exists(realpath($AtchDir)."/".$AtchPref.".".$splitEle[1].$AtchName)){ 
  318.               $splitEle[1]++; 
  319.            } 
  320.            $res = rename(realpath($AtchTempDir)."/".$eleVal,realpath($AtchDir)."/".$AtchPref.".".$splitEle[1].$AtchName); 
  321.        } 
  322.    } 
  323.    setcookie($AtchCookieName); 
  324.  
  325. ###################################################################### # Funzione : ShowAttach() 
  326. # Input    : $idForumPost : Post Unique Id 
  327. #            $AtchModify  : indica se abilitare l'opzione di Cancellazione 
  328. #            $FormName    : nome della form da invocare per la sottomissione 
  329. #                           della cancellazione (se lasciato vuoto verrα 
  330. #                           invocata una chiamata GET) 
  331. # Outut    : NONE 
  332. # Mostra gli attachment in forma tabellare 
  333. ###################################################################### 
  334. function ShowAttach($idForumPost,$AtchModify=false, $FormName=""){ 
  335.    global $AtchDir, $name, $file, $topic, $forum, $bgcolor2; 
  336.    // Define how many Cols Must be used 
  337.    $numCol =3; 
  338.    if ($AtchModify){ 
  339.       $canDelete = checkUserModEnabled($idForumPost); 
  340.       if($FormName!=""){ 
  341.         echo "<script language='javascript'> 
  342. function delAtch(AtchName, AtchNum){ 
  343.                    if (confirm('"._FORUMATCHMDELCONFIRM." $AtchName ?')){ 
  344.                       document.forms['$FormName'].AtchOp.value ='delAthcFile'; 
  345.                       document.forms['$FormName'].AtchName.value =AtchName; 
  346.                       document.forms['$FormName'].AtchNum.value =AtchNum; 
  347.                       document.forms['$FormName'].submit(); 
  348.                    } 
  349.               } 
  350.               </script> 
  351. <input type='hidden' name='AtchOp' value=''> 
  352. <input type='hidden' name='IdAtchPostId' value='$idForumPost'> 
  353.  
  354. <input type='hidden' name='AtchName' value=''> 
  355. <input type='hidden' name='AtchNum' value=''> 
  356. "; 
  357.       } 
  358.    } else { 
  359.       $canDelete = false; 
  360.    } 
  361.    $imgArr = array("avi","exe","gzip","htm","img","mp3","pdf","txt","word","xls","zip", "php"); 
  362.    $ShowAtchStr=""; 
  363.    $Adir = @opendir(realpath($AtchDir)); 
  364.    $countTD =0; 
  365.    $countTR =1; 
  366.    while(false!==($Afile=readdir($Adir))) { 
  367.       $splitEle = explode(".",$Afile); 
  368.       if ($splitEle[0]==md5($idForumPost)){ 
  369.           $AtchName = ""; 
  370.           $AtchNum =$splitEle[1]; 
  371.           $countTD++; 
  372.           for($cont=2;$cont<count($splitEle)-1;$cont++){ 
  373.               if ($cont>2){ 
  374.                   $AtchName .="."; 
  375.               } 
  376.              $AtchName .=$splitEle[$cont]; 
  377.           } 
  378.           $fext =$splitEle[--$cont]; 
  379.           // normalizzo l'estensione del file per recuperare l'immagine 
  380.           if ($fext=="jpg"||$fext=="gif"||$fext=="psn"||$fext=="bmp") $fext ="img"; 
  381.           if ($fext=="html"||$fext=="phtml") $fext ="htm"; 
  382.           if ($fext=="doc"||$fext=="rtf") $fext ="word"; 
  383.           if ($fext=="tar") $fext ="gzip"; 
  384.           if ($fext=="gz") $fext ="zip"; 
  385.           if ($fext=="ini"||$fext=="inc") $fext ="txt"; 
  386.                   if ($fext=="php3") $fext ="php"; 
  387.           if  (!in_array($fext,$imgArr)){ 
  388.                 $fext="unknown"; 
  389.           } 
  390.           $ShowAtchStr.="<td width=30% bgcolor=$bgcolor2 align='left' valign=center>"; 
  391.           if ($canDelete){ 
  392.               if ($FormName==""){ 
  393.                   $ShowAtchStr.="<a href=\"javascript:if(confirm('"._FORUMATCHMDELCONFIRM." $AtchName ?')){document.location.href='modules.php?op=modload&name=$name&file=$file&AtchOp=delAthcFile&postid=$idForumPost&IdAtchPostId=$idForumPost&AtchName=$AtchName&AtchNum=$AtchNum&topic=$topic&forum=$forum';}\" title='Cancella File'><img src='images/forum/attach/delete.gif' border=0></a> "; 
  394.               } else { 
  395.                   $ShowAtchStr.="<a href=\"javascript:delAtch('$AtchName','$AtchNum');\" title=\"Cancella File\"><img src=\"images/forum/attach/delete.gif\" border=\"0\"></a> "; 
  396.               } 
  397.           } 
  398.           $ShowAtchStr.="<a href=\"modules.php?op=modload&name=$name&file=attachment&AtchOp=get&postid=$idForumPost&AtchName=$AtchName&AtchNum=$AtchNum\" title=\""._FORUMATCHMDOWNFILE."\"><img src=\"images/forum/attach/download.gif\" border=\"0\"></a> <a href=\"modules.php?op=modload&name=$name&file=attachment&AtchOp=show&postid=$idForumPost&fext=$fext&AtchName=$AtchName&AtchNum=$AtchNum\" title=\""._FORUMATCHMOPENFILE."\" target=\"_blank\"><img src=\"images/forum/attach/$fext.gif\" border=\"0\"></a> $AtchName</td>"; 
  399.           if ($countTD==$numCol){ 
  400.               $countTD=0; 
  401.               $countTR++; 
  402.               $ShowAtchStr.="</td><tr>"; 
  403.           } 
  404.       } 
  405.    } 
  406.    if ($ShowAtchStr!=""){ 
  407.        if ($countTD!=0 && $countTD!=$numCol){ 
  408.           for ($td=$countTD;$td<=$numCol;$td++){ 
  409.               $ShowAtchStr.="<td width=25%> </td>"; 
  410.           } 
  411.           $ShowAtchStr.="</tr>"; 
  412.        }else{ 
  413.           $countTR--; 
  414.        } 
  415.        $ShowAtchStr = "<table border=0 width=100%><tr class='title'><td class=forumtitle width=10% rowspan=$countTR valign=middle align=right>"._FORUMATCHM." :</td>".$ShowAtchStr."</table><HR>\n"; 
  416.    } 
  417.    return($ShowAtchStr); 
  418.    closedir($Adir); 
  419.  
  420. ###################################################################### # Funzione : getAtchFile() 
  421. # Input    : $postid      : Post Unique Id 
  422. #            $AtchName    : File Name 
  423. #            $AtchNum     : File Id number 
  424. #            $AtchMode    : Attachment mode 
  425. #                           must be ""  or "attachment;" (to directly download file); 
  426. # Outut    : NONE 
  427. # Funzione permette la visualizzazione (quando possibile) o il download 
  428. # del file richiesto. 
  429. ###################################################################### 
  430. function getAtchFile($postid,$AtchName,$AtchNum, $AtchMode =""){ 
  431.     global $AtchDir, $name, $fext; 
  432.     include("modules/$name/mime.inc.php"); 
  433.     $fname=md5($postid).".".$AtchNum.".".$AtchName.".atch"; 
  434.     $arrTmp = explode(".",$AtchName); 
  435.         if($fext == "php" && $AtchMode==""){ 
  436.                 $fsize=filesize(realpath($AtchDir)."/$fname"); 
  437.         //        echo"<body bgcolor=\"E1ECEC\">"; 
  438.                 echo"<center><h2>$AtchName <i>( $fsize Bytes )</i></h2></center><hr>"; 
  439.                    highlight_file(realpath($AtchDir)."/$fname"); 
  440.                 echo"<hr><center><b>Splatt Forum 3.2 PHP Code Viewer</b></center><br>"; 
  441.         } else{ 
  442.             $AtchMimeType = GetMime($arrTmp[count($arrTmp)-1]); 
  443.            header("Content-Disposition: $AtchMode filename=$AtchName"); 
  444.            header("Content-Type: $AtchMimeType"); 
  445.            header("Content-Length: ".filesize(realpath($AtchDir)."/$fname")); 
  446.            readfile(realpath($AtchDir)."/$fname"); 
  447.         } 
  448.  
  449. ###################################################################### # Funzione : getTotAtchSize() 
  450. # Input    : $postid      : Post Unique Id 
  451. # Outut    : NONE 
  452. # Ritorna la dimensione totale degli allegati 
  453. ###################################################################### 
  454. function getTotAtchSize($postid){ 
  455.    global $AtchDir; 
  456.    $Adir = @opendir(realpath($AtchDir)); 
  457.    $tot=0; 
  458.    $positd =md5($postid); 
  459.    while(false!==($Afile=readdir($Adir))) { 
  460.          $splitEle = explode(".",$Afile); 
  461.          if ($splitEle[0]==$positd){ 
  462.             $tot += filesize(realpath($AtchDir)."/$Afile"); 
  463.          } 
  464.    } 
  465.    closedir($Adir); 
  466.    return($tot); 
  467.  
  468. ###################################################################### # Funzione : delAllAtchFile() 
  469. # Input    : $postid      : Post Unique Id 
  470. # Outut    : NONE 
  471. # Cancella fisicamente tutti i file Allegati al Post (controlla se 
  472. # l'utente Φ abilitato) 
  473. ###################################################################### 
  474. function delAllAtchFile($postid){ 
  475.    global $AtchDir; 
  476.    if (checkUserModEnabled($postid)){ 
  477.        $Adir = @opendir(realpath($AtchDir)); 
  478.        $postid=md5($postid); 
  479.        while(false!==($Afile=readdir($Adir))) { 
  480.              $splitEle = explode(".",$Afile); 
  481.              if ($splitEle[0]==$postid){ 
  482.                 $fp=fopen(realpath($AtchDir)."/$Afile","w"); 
  483.                 fclose($fp); 
  484.                 if(file_exists(realpath($AtchDir)."/$Afile")){ 
  485.                    $res = unlink(realpath($AtchDir)."/$Afile"); 
  486.                 } 
  487.              } 
  488.        } 
  489.        closedir($Adir); 
  490.    } 
  491.  
  492. ###################################################################### # Funzione : delAtchFile() 
  493. # Input    : $postid      : Post Unique Id 
  494. #            $AtchName    : File Name 
  495. #            $AtchNum     : File Id number 
  496. # Outut    : NONE 
  497. # Cancella fisicamente il file richiesto (controlla se l'utente Φ 
  498. # abilitato) 
  499. ###################################################################### 
  500. function delAtchFile($postid,$AtchName,$AtchNum){ 
  501.     global $AtchDir; 
  502.     if (checkUserModEnabled($postid)){ 
  503.         $fname=md5($postid).".".$AtchNum.".".$AtchName.".atch"; 
  504.         $fp=fopen(realpath($AtchDir)."/$fname","w"); 
  505.         fclose($fp); 
  506.         if (file_exists(realpath($AtchDir)."/$fname")){ 
  507.             $res = unlink(realpath($AtchDir)."/$fname"); 
  508.         } 
  509.    } 
  510.  
  511. ###################################################################### # Funzione : resetAtchCookie() 
  512. # Input    : NONE 
  513. # Outut    : NONE 
  514. # Resetta la variabile Cookie cancellando eventuali file presenti 
  515. # nella directory temporanea 
  516. ###################################################################### 
  517. function resetAtchCookie(){ 
  518.     global $AtchCookieName,$AtchTempDir; 
  519.     $better_token = base64_encode(md5(uniqid(mt_rand())).":0"); 
  520.     setcookie($AtchCookieName,"$better_token"); 
  521.     if (isset($GLOBALS["$AtchCookieName"])){ 
  522.        $arrAtchCookie=decodeAtchCookie($GLOBALS["$AtchCookieName"]); 
  523.        //cancella tutti i file con lo stesso token 
  524.        $cont=-1; 
  525.        foreach ($arrAtchCookie as $eleVal){ 
  526.          $cont++; 
  527.          if ($cont>1){ 
  528.              if (file_exists(realpath($AtchTempDir)."/".$eleVal)){ 
  529.                 unlink(realpath($AtchTempDir)."/".$eleVal); 
  530.              } 
  531.          } 
  532.        } 
  533.     } 
  534.     $better_token = base64_encode(md5(uniqid(mt_rand())).":0"); 
  535.     setcookie($AtchCookieName,"$better_token"); 
  536.  
  537. ###################################################################### # Funzione : garbageAtchFile() 
  538. # Input    : NONE 
  539. # Outut    : NONE 
  540. # Controlla la Directory temporanea cancellando eventuali file 
  541. # mai confermati (file spazzatura!) 
  542. ###################################################################### 
  543. function garbageAtchFile(){ 
  544.    global $AtchTempDir; 
  545.    $maxMinutes = 20; 
  546.    $Adir = @opendir(realpath($AtchTempDir)); 
  547.    $checkTime = time() - ($maxMinutes*60); 
  548.    while(false!==($Afile=readdir($Adir))) { 
  549.       if (($Afile!=".")&&($Afile!="..")&&($Afile!="index.htm")&&($Afile!="index.html")){ 
  550.          $ftime = filectime(realpath($AtchTempDir)."/".$Afile); 
  551.          if ($ftime<=$checkTime){ 
  552.             if (file_exists(realpath($AtchTempDir)."/".$Afile)){ 
  553.                 $res = unlink(realpath($AtchTempDir)."/".$Afile); 
  554.             } 
  555.          } 
  556.       } 
  557.    } 
  558.    closedir($Adir); 
  559. function getAttachCode($postid=null){ 
  560.    global $name; 
  561.    $poststr=""; 
  562.    if($postid!=null){ 
  563.      $poststr="&IdAtchPostId=$postid"; 
  564.    } 
  565.    return("<input type=button name=cattach value='"._FORUMATCHM."' onclick='window.open(\"modules.php?op=modload&name=$name&file=attachment&AtchOp=manage$poststr\",\"fattach\",\"height=400,width=610,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=50,left=50\");'> "._FORUMATCHMCODE); 
  566.  
  567. switch ($AtchOp){ 
  568.    case "manage" : 
  569.         require_once("mainfile.php"); 
  570.         include_once("modules/$name/functions.php"); 
  571.         include_once("modules/$name/auth.php"); 
  572.         if (CheckCookieEnabled()){ 
  573.            manageAttach($IdAtchPostId); 
  574.         } 
  575.         break; 
  576.    case "show" : 
  577.         getAtchFile($postid,$AtchName,$AtchNum); 
  578.         break; 
  579.    case "get"  : 
  580.         getAtchFile($postid,$AtchName,$AtchNum,"attachment;"); 
  581.         break; 
  582.    case "delAthcFile"; 
  583.         delAtchFile($IdAtchPostId,$AtchName,$AtchNum, $fext); 
  584.         break; 
  585.    case "testcookie" : 
  586.         CheckCookieEnabled(); 
  587.         break; 
  588. ?>