<?
######################################################################
# Modulo Splatt Forum per PHP-NUKE 
#-------------------------
# Versione: 3.1
#
# Copyright (c) 2002 by:
#
# Giorgio Ciranni (~Splatt~)
# (http://www.splatt.it)
# (webmaster@splatt.it)
#
#
# Supporto tecnico disponibile sul Forum di www.splatt.it
######################################################################
# PHP-NUKE Add-On 2.0 :
# =====================
#
#              PHPBB Integration 1.0.BETA
#        Brought to you by PHPNuke Add-On Team
#
# Copyright (c) 2000 by Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)
#                       Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)
# http://www.phpnuke.web.id
#
#
######################################################################
# PHPBB
#
# Copyright (C) 2000 by James Atkinson (james@totalgeek.org)
# http://www.phpbb.com
#
#
######################################################################
######################################################################
# Gestione Mime Type
# -------------------------------------------------------------------
# Realizzato da  : JoyDivision
#            url : http://www.bergamoblog.it
#          email : joydivision@bergamoblog.it
######################################################################
# 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.
# Splatt Forum is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   
# 02111-1307  USA
######################################################################

if (!file_exists(realpath("modules/$name")."/mimetype.txt")){
    $fp = fopen(realpath("modules/$name")."/mimetype.txt","w");
    fclose($fp);
    unset($fp);
}

######################################################################
# Funzione : SetMime()
# Input    : fileext  - file Extension
#            mimetype - associated mimetype
# Outut    : NONE
#
# Setta nel file contenente tutti i mime-type un nuovo mime associato
# all'estensione (se non esiste già)
######################################################################
function SetMime($fileext, $mimetype){
    global $name;
    $MimeFN = realpath("modules/$name")."/mimetype.txt";
    $fp = fopen($MimeFN,"r+");
    flock($fp,LOCK_EX);
    $fileext.="|";
    $fcontent = fread($fp,filesize($MimeFN));
    $pos=strpos($fcontent,$fileext);
    if (!$pos){
        $fcontent.=$fileext.$mimetype."||\n";
        rewind($fp);
        fwrite($fp,$fcontent);
    }
    flock($fp,LOCK_UN);
    fclose($fp);
    unset($fp);
}

######################################################################
# Funzione : GetMime()
# Input    : fileext  - file Extension
# Outpu    : mimetype - associated mimetype
#
# Ritorna il mimetype associato all'estensione specificata
######################################################################
function GetMime($fileext){
    global $name;
    $MimeFN = realpath("modules/$name")."/mimetype.txt";
    $fileext.="|";
    $fp = fopen($MimeFN,"r");
    $fcontent = fread($fp,filesize($MimeFN));
    fclose($fp);
    unset($fp);
    $pos=strpos($fcontent,$fileext);
    if (is_string($pos) && !$pos){
       $mimetype = "text/plain";
    } else {
       $mimetype = substr($fcontent,$pos);
       $mimetype = substr($mimetype,0,strpos($mimetype,"||"));
       $mimetype = substr($mimetype,strpos($mimetype,"|")+1);
    }
    return($mimetype);
}
?>