/**
 * Plugin smarty type modifier
 * Purpose: A partir d'un article du RSS, extrait ce qu'il faut afficher en "enclosure"
 * Input: Chaine de caractères (tout l'article)
 * Output: Chaine de caractères (tags <enclosure> avec le bonc ontenu ou chaine vide si aucun contenu multimédia
 * Example:  {$text|rss_enclosure}
 * @return string
 */
function smarty_modifier_rss_enclosure($string)
{
    $txt = '';
    //<enclosure url="http://www.scripting.com/mp3s/weatherReportSuite.mp3" length="12216320" type="audio/mpeg" />
    if (preg_match_all("/\\[\\[(.*)\\]\\]/sU", $string, $regs, PREG_SET_ORDER)) {
        //print_r($regs);
        foreach ($regs as $reg) {
            //print_r($reg);
            list($url, $type) = explode("|", $reg[1]);
            $url = rawurldecode($url);
            $length = @filesize($url);
            $ext = substr($url, strrpos($url, ".") + 1);
            $infos = MalleService::getTypeInfos('', $url);
            //print_r($infos);
            if ($length && $infos['type_mime']) {
                $file = $url;
                $pos = strrpos($file, '/');
                if ($pos === false) {
                    $name = $file;
                    $href = $name;
                } else {
                    $name = substr($file, $pos + 1);
                    $href = substr($file, 0, $pos + 1) . rawurlencode($name);
                }
                $txt .= '<enclosure url="' . CopixUrl::get() . $href . '" length="' . $length . '" type="' . $infos['type_mime'] . '" />';
            }
        }
    }
    return $txt;
}
 /**
  * Suppression d'une malle
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2006/01/09
  * @param integer $id Id de la malle
  * @return boolean true si la suppression s'est bien pass�e, false sinon
  */
 public function delete($id)
 {
     $daoMalles = _dao('malle|malle_malles');
     $rMalle = $daoMalles->get($id);
     $res = false;
     if ($rMalle) {
         // On vide le r�pertoire
         $path2data = realpath('./static/malle');
         $folder = $path2data . '/' . $rMalle->id . '_' . $rMalle->cle;
         MalleService::deleteDir($folder);
         $criteres = _daoSp()->addCondition('malle', '=', $id);
         _dao('module_malle_files')->deleteBy($criteres);
         _dao('module_malle_folders')->deleteBy($criteres);
         $daoMalles->delete($id);
         $res = true;
     }
     Kernel::unregisterModule("MOD_MALLE", $id);
     return $res;
 }
function iconito_multimedia($contents, $attr)
{
    $mode = 'auto';
    $cnt = count($contents);
    if ($cnt > 2) {
        $cnt = 2;
    }
    //print_r($contents);
    switch ($cnt) {
        case 2:
            $mode = $contents[1];
        case 1:
        default:
            $file = rawurldecode($contents[0]);
            if ($mode == 'download') {
                $path = COPIX_WWW_PATH . substr($file, strpos($file, 'static'));
                if (file_exists($path) || fopen($path, 'r')) {
                    $size = @filesize($path);
                    $size = $size ? ' - ' . KernelMalle::human_file_size($size) : '';
                    $point = strrpos($file, ".");
                    if ($point !== false) {
                        $ext = substr($file, $point + 1);
                    }
                    $ext = MalleService::getTypeInfos($ext);
                    $pos = strrpos($file, '/');
                    if ($pos === false) {
                        $name = $file;
                        $href = $name;
                    } else {
                        $name = substr($file, $pos + 1);
                        $href = substr($file, 0, $pos + 1) . rawurlencode($name);
                    }
                    if (strlen($name) > 35) {
                        $name = substr($name, 0, 35) . '...';
                    }
                    //        print_r();
                    $ret = '<div class="file_dl"><a href="' . $href . '" title="' . htmlentities($file) . '"><img src="' . _resource('img/malle/' . $ext['type_icon32']) . '" width="32" height="32" border="0" title="' . htmlentities($ext['type_text']) . '" alt="' . htmlentities($ext['type_text']) . '" /><div class="name">' . $name . '</div></a><div class="desc">' . $ext['type_text'] . '' . $size . '</div></div>';
                } else {
                    $ret = '<div>Fichier ' . $file . ' introuvable</div>';
                }
            } elseif ($mode == 'view') {
                $point = strrpos($file, ".");
                if ($point !== false) {
                    $ext = substr($file, $point + 1);
                }
                //print_r("ext=$ext");
                switch (strtolower($ext)) {
                    case "jpg":
                    case "jpeg":
                    case "gif":
                    case "png":
                    case "bmp":
                        $link = array($file, 'image');
                        break;
                    case "mp3":
                        $link = array($file, 'mp3');
                        break;
                    case "wmv":
                    case "mpg":
                    case "mpeg":
                    case "avi":
                        $link = array($file, 'wmv');
                        break;
                    case "mov":
                    case "mp4":
                    case "m4a":
                        $link = array($file, 'mov');
                        break;
                    case "amr":
                        $link = array($file, 'amr');
                        break;
                    case "flv":
                        $link = array($file, 'flv');
                        break;
                    default:
                        $path = $_SERVER['PHP_SELF'];
                        $pos = strrpos($path, "/");
                        if ($pos !== false) {
                            $abspath = substr($path, 0, $pos + 1);
                        }
                        if (substr($file, 0, strlen($abspath)) == $abspath) {
                            $file = substr($file, strlen($abspath));
                        }
                        $link = array($file, 'download');
                }
                $ret = iconito_multimedia($link, NULL);
            } elseif ($mode == 'mp3') {
                $width = 200;
                $height = 20;
                $ret = '<div><object type="application/x-shockwave-flash" data="' . CopixUrl::getRequestedScriptPath() . 'dewplayer/dewplayer.swf?son=' . $file . '" width="' . $width . '" height="' . $height . '"> <param name="movie" value="' . CopixUrl::getRequestedScriptPath() . 'dewplayer/dewplayer.swf?son=' . $file . '" /><img src="' . _resource('img/music.png') . '" width="16" height="16" border="0" title="MP3" alt="MP3" /></object></div>';
            } elseif ($mode == 'wmv') {
                $id = "media-Player" . md5(mt_rand());
                $width = 480;
                $height = 385;
                $ret = '<div><object id="' . $id . '" width="' . $width . '" height="' . $height . '"
      classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
      codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
      standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">
      <param name="fileName" value="' . $file . '">
      <param name="animationatStart" value="true">
      <param name="transparentatStart" value="true">
      <param name="autoStart" value="false">
      <param name="showControls" value="true">
      <param name="loop" value="false">
      <embed type="application/x-mplayer2"
        pluginspage="http://microsoft.com/windows/mediaplayer/fr/download/"
        id="' . $id . '" name="' . $id . '" displaysize="4" autosize="-1"
        bgcolor="darkblue" showcontrols="true" showtracker="-1"
        showdisplay="0" showstatusbar="-1" videoborder3d="-1" width="' . $width . '" height="' . $height . '"
        src="' . $file . '" autostart="0" designtimesp="5311" loop="false">
      </embed>
      <img src="' . _resource('img/film.png') . '" width="16" height="16" border="0" title="vidéo" alt="vidéo" />
      </object></div>';
            } elseif ($mode == 'mov' || $mode == 'amr' || $mode == 'mp4' || $mode == 'm4a') {
                $width = 480;
                $height = $mode == 'amr' ? 20 : 385;
                //$id = "media-Player".md5(mt_rand());
                $ret = '<div><object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' . $width . '"
        height="' . $height . '" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
        <param name="src" value="' . $file . '">
        <param name="autoplay" value="false">
        <param name="controller" value="true">
        <param name="loop" value="false">
        <embed src="' . $file . '" width="' . $width . '" height="' . $height . '" autoplay="false"
        controller="true" loop="false" pluginspage="http://www.apple.com/quicktime/download/">
        </embed>
        <img src="' . _resource('img/film.png') . '" width="16" height="16" border="0" title="vidéo" alt="vidéo" />
        </object></div>';
            } elseif ($mode == 'image') {
                $ret = '<div><img src="' . $file . '" alt="' . htmlentities($file) . '" title="" /></div>';
            } elseif ($mode == 'flv') {
                $rand = md5(mt_rand());
                $width = 480;
                $height = 385;
                $ret = '
<p id="player-' . $rand . '"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
        var FU = { movie:"' . CopixUrl::getRequestedScriptPath() . 'flvplayer/flvplayer.swf",width:"' . $width . '",height:"' . $height . '",majorversion:"7",build:"0",bgcolor:"#FFFFFF",
                                flashvars:"file=' . (!preg_match("/^https?:\\/\\//", $file) ? CopixUrl::get() : "") . $file . '&showdigits=true&autostart=false" };
        UFO.create(FU, "player-' . $rand . '");
</script>';
            } elseif ($mode == 'youtube') {
                if (preg_match("/^([a-zA-Z0-9_-]+)\$/", $file)) {
                    $id = $file;
                } elseif (preg_match("/v=([a-zA-Z0-9_-]+)/", $file, $regs)) {
                    $id = $regs[1];
                }
                if ($id) {
                    $ret = '<div><object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/' . $id . '"><param name="movie" value="http://www.youtube.com/v/' . $id . '" /><param name="wmode" value="transparent" /><img src="' . _resource('img/film.png') . '" width="16" height="16" border="0" title="vidéo" alt="vidéo" /></object></div>';
                } else {
                    $ret = '<div>Problème de paramètre</div>';
                }
            } elseif ($mode == 'googlevideo') {
                if (preg_match("/^([0-9-]+)\$/", $file)) {
                    $id = $contents[0];
                } elseif (preg_match("/docid=([0-9-]+)/", $file, $regs)) {
                    $id = $regs[1];
                }
                if ($id) {
                    $ret = '<div><object width="400" height="326" type="application/x-shockwave-flash" data="http://video.google.com/googleplayer.swf?docId=' . $id . '"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=' . $id . '" /><param name="allowScriptAccess" value="sameDomain" /><param name="quality" value="best" /><param name="scale" value="noScale" /><param name="wmode" value="transparent" /><param name="salign" value="TL" /><param name="FlashVars" value="playerMode=embedded" /><img src="' . _resource('img/film.png') . '" width="16" height="16" border="0" title="vidéo" alt="vidéo" /></object></div>';
                } else {
                    $ret = '<div>Problème de paramètre</div>';
                }
            } else {
                //$ret = '<div>Mode indéfini</div>';
                $ret = iconito_multimedia(array($file, 'download'), NULL);
            }
    }
    return $ret;
}
 /**
  * A partir d'un nom de fichier, renvoie son type MIME
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2010/09/24
  * @param string $iFilename Nom (ou chemin) du fichier
  * @return
  */
 public function getMimeType($iFilename)
 {
     $point = strrpos($iFilename, ".");
     if ($point !== false) {
         $ext = substr($iFilename, $point + 1);
         $ext = strtolower($ext);
     } else {
         $ext = $iFilename;
     }
     $oMimeType = CopixMIMETypes::getFromExtension($ext);
     // On regarde si on veut pas ecraser le type mime
     if ($oMimeType == 'application/octet-stream') {
         $tmp = MalleService::getTypeInfos($ext);
         if ($tmp && isset($tmp['type_mime'])) {
             $oMimeType = $tmp['type_mime'];
         }
     }
     return $oMimeType;
 }
 /**
  * delAlbum
  *
  * Efface un album
  *
  * @author Fr�d�ric Mossmann <*****@*****.**>
  * @param integer $album_id Id de l'album
  */
 public function delAlbum($album_id)
 {
     $photo_dao = _dao("album|photo");
     _classInclude('malle|malleservice');
     $photos = $photo_dao->findAllByAlbum($album_id);
     foreach ($photos as $photo) {
         Album::delPhoto($photo->photo_id);
     }
     $album_dao = _dao("album|album");
     $album = $album_dao->get($album_id);
     if ($album) {
         $path2data = realpath("static");
         $pathfolder = $path2data . '/album/' . $album->album_id . "_" . $album->album_cle;
         MalleService::deleteDir($pathfolder);
         $album_dao->delete($album_id);
     }
     Kernel::unregisterModule("MOD_ALBUM", $album_id);
 }