hi
when i replace the function get_media_code() with the the functions below. details.html is not working (i got a blank page )
THX plz help me
function get_media_code($media_file_name, $image_id = 0, $cat_id = 0, $image_name = "", $mode = "", $show_link = 0, $detailed_view = 0) {
global $site_template, $site_sess, $lang, $mode;
if (!get_file_path($media_file_name, "media", $cat_id, 0, 0)) {
$media = "<img src=\"".ICON_PATH."/404.gif\" border=\"0\" alt=\"\" />";
$site_template->register_vars("iptc_info", "");
}
else {
$media_src = get_file_path($media_file_name, "media", $cat_id, 0, 1);
$file_extension = get_file_extension($media_file_name);
$media_icon = "<img src=\"".ICON_PATH."/".$file_extension.".gif\" border=\"0\" alt=\"".$image_name."\" />";
if ($show_link) {
$media_icon = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : ""))."\">".$media_icon."</a>";
}
$width_height = "";
$width = "";
$height = "";
$iptc_info = "";
$src = (!file_exists($media_src) && file_exists(preg_replace("/\/{2,}/", "/", get_document_root()."/".$media_src))) ? preg_replace("/\/{2,}/", "/", get_document_root()."/".$media_src) : $media_src;
if ($image_info = @getimagesize($src, $info)) {
$width_height = " ".$image_info[3];
$width = $image_info[0];
$height = $image_info[1];
if ($detailed_view && isset($info['APP13'])) {
$iptc_array = get_iptc_info($info['APP13']);
$bgcounter = 0;
foreach ($iptc_array as $key => $val) {
$row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
$site_template->register_vars(array(
"iptc_value" => $val,
"iptc_name" => $lang['iptc_'.$key],
"row_bg_number" => $row_bg_number
));
$iptc_info .= $site_template->parse_template("iptc_bit");
}
}
}
// Hier analysieren wir mp3-Dateien
if ($file_extension == "mp3" && $detailed_view)
{
$mp3info = mp3_getinfo($src,$update=1,$advanced=0);
$site_template->register_vars("simplepic_info", "");
$site_template->register_vars( $mp3info );
//$site_template->register_vars(array(
// "id3_song" => $mp3info['song']
// ));
//var_dump( $mp3info );
//echo "\n<br />";
}
else if ($detailed_view)
{
$site_template->register_vars("mp3_info", "");
$site_template->register_vars("simplepic_info", "yes");
}
$site_template->register_vars(array(
"media_src" => $media_src,
"media_icon" => $media_icon,
"image_name" => $image_name,
"width_height" => $width_height,
"width" => $width,
"height" => $height,
"iptc_info" => $iptc_info
));
$media = $site_template->parse_template("media/".$file_extension);
}
return $media;
}
///////////////////////////////////////////////////////////////////////
////// I D 3 //////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/**
* Genommen aus Code ursprünglich geschrieben von
* Kristof Hamann für sein Programm MusicServer
* www.korelstar.de
*/
// strim trimmt auch binäre 0
function strim($str)
{
$buf=""; $ret="";
$str = trim($str);
for($i=0;$i<strlen($str);$i++)
{
if(ord($str[$i])==0)
{
if(strlen($ret)!=0)
{
$buf .= $str[$i];
}
}
else
{
if($buf)
{
$ret .= $buf;
$buf = "";
}
$ret .= $str[$i];
}
}
return $ret;
}
// liest infos aus MP3
function mp3_getinfo($datei,$update=0,$advanced=1)
{
global $MP3DIR;
$mp3info = array();
$mp3info["size"] = @filesize($MP3DIR.$datei);
$mp3info["datei"] = $datei;
// Sicherheitschecks
if(strtolower(substr($datei,-4))!=".mp3" || strstr($datei,"..") || substr($datei,0,1)=="/" || !is_file($MP3DIR.$datei) || !is_readable($MP3DIR.$datei))
{
if($GLOBALS["DEBUG"]) echo "Keine gültige MP3 gewählt.<br />";
return false;
}
// auslesen der datei
$fp = fopen($MP3DIR.$datei,"r");
if(!$fp)
{
if($GLOBALS["DEBUG"]) echo "Konnte Datei nicht oeffnen.<br />";
return false;
}
fseek($fp,0);
$mp3head_asc = fread($fp,4);
// ID3v2-Tag
if(substr($mp3head_asc,0,3)=="ID3")
{
// lese restlichen IDv2-header aus
$mp3v2head_asc = $mp3head_asc . fread($fp,6);
$mp3v2head = asc2bin($mp3v2head_asc);
if($GLOBALS["DEBUG"]) echo "<b>IDv2-Header:</b> ".chunk_split($mp3v2head,8," ")."<br />";
// Laenge des ID3v2-Headers
$mp3v2headext_len = bindec(substr($mp3v2head,49,7).substr($mp3v2head,57,7).substr($mp3v2head,65,7).substr($mp3v2head,73,7));
if($GLOBALS["DEBUG"]) echo "Laenge des ID3v2-Headers: $mp3v2headext_len<br />";
// checke ob Erweiterten Headers ???? !!!! ????
if($mp3v2head[49])
{
if($GLOBALS["DEBUG"]) echo "Erweiterter Header, noch nicht programmiert.<br />";
}
// Version, kenne nur die 3.
$mp3info["id3v2"] = bindec(substr($mp3v2head,24,8));
if($mp3info["id3v2"]==3)
{
// Lese ID3v2-Informationen aus (alle Frames)
fseek($fp,10);
$mp3v2data = fread($fp,$mp3v2headext_len);
$curpos = 0;
while($curpos < $mp3v2headext_len)
{
$mp3v2frameid = substr($mp3v2data,$curpos + 0,4);
if(!trim($mp3v2frameid)) break;
$mp3v2framesize = bindec(asc2bin(substr($mp3v2data,$curpos + 4,4)));
$mp3v2frameflags = asc2bin(substr($mp3v2data,$curpos + 8,2));
$mp3v2framedata = substr($mp3v2data,$curpos + 10,$mp3v2framesize);
$curpos += 10 + $mp3v2framesize;
if($GLOBALS["DEBUG"]) echo "<b>$mp3v2frameid</b> (Len: $mp3v2framesize, Flags: ".chunk_split($mp3v2frameflags,8," ").") = $mp3v2framedata <small>[".chunk_split(asc2bin($mp3v2framedata),8," ")."]</small><br />";
switch($mp3v2frameid)
{
case "TPE1": $mp3info["artist"] = $mp3v2framedata; break;
case "TIT2": $mp3info["song"] = $mp3v2framedata; break;
case "TRCK": $mp3info["track"] = $mp3v2framedata; break;
case "TYER": $mp3info["year"] = $mp3v2framedata; break;
case "TALB": $mp3info["album"] = $mp3v2framedata; break;
case "COMM": $mp3info["comment"] = substr($mp3v2framedata,4); break;
case "TCON": if(substr($mp3v2framedata,1,1)=="(") $mp3info["genre"] = (int)substr($mp3v2framedata,2,3); break;
}
}
}
elseif($GLOBALS["DEBUG"]) echo "ID3v2-Tag-Version ist nicht 3. Kenne ich leider nicht.<br />";
// Lese MP3-Header fuer Advanced-Mod aus
if($advanced)
{
$mp3v2_startdata = $mp3v2headext_len + 10;
if($GLOBALS["DEBUG"]) echo "MP3 beginnt bei Byte ".$mp3v2_startdata.".<br />";
fseek($fp,$mp3v2_startdata);
$mp3head_asc = fread($fp,4);
}
}
// auslesen erweiterter informationen (bitrate, etc.)
if($advanced)
{
$mp3headinfo = array();
if($GLOBALS["DEBUG"]) echo "<br /><b>Erweiterte Infos zur Datei (DEBUG-Modus):</b><br />";
$mp3head = asc2bin($mp3head_asc);
if($GLOBALS["DEBUG"]) echo "<b>1. Frame-Header:</b> ".chunk_split($mp3head,8," ")."<br /><br />";
// lese techn. infos aus
$mp3headinfo["mpeg"] = $mp3head[12];
$mp3headinfo["layer"] = substr($mp3head, 13, 2);
$mp3headinfo["protect"] = $mp3head[15];
$mp3headinfo["bitrate"] = substr($mp3head, 16, 4);
$mp3headinfo["frequency"] = substr($mp3head, 20, 2);
$mp3headinfo["padding"] = $mp3head[22];
$mp3headinfo["private"] = $mp3head[23];
$mp3headinfo["mode"] = substr($mp3head, 24, 2);
$mp3headinfo["modeext"] = substr($mp3head, 26, 2);
$mp3headinfo["copy"] = $mp3head[28];
$mp3headinfo["home"] = $mp3head[29];
$mp3headinfo["emphasis"] = substr($mp3head, 30, 2);
// wandle infos in mp3info um
switch($mp3headinfo["layer"])
{
case "01" : $mp3info["layer"]=3; break;
case "10" : $mp3info["layer"]=2; break;
case "11" : $mp3info["layer"]=1; break;
default : $mp3info["layer"]="[fehler]"; break;
}
if($mp3headinfo["mpeg"])
{
switch($mp3headinfo["frequency"])
{
case "00" : $mp3info["frequency"]=44100; break;
case "01" : $mp3info["frequency"]=48000; break;
case "10" : $mp3info["frequency"]=32000; break;
default : $mp3info["frequency"]=""; break;
}
}
else
{
switch($mp3headinfo["frequency"])
{
case "00" : $mp3info["frequency"]=22050; break;
case "01" : $mp3info["frequency"]=24000; break;
case "10" : $mp3info["frequency"]=16000; break;
default : $mp3info["frequency"]=""; break;
}
}
switch($mp3headinfo["mode"])
{
case "00" : $mp3info["mode"]="Stereo"; break;
case "01" : $mp3info["mode"]="Joint Stereo"; break;
case "10" : $mp3info["mode"]="Dual Channel"; break;
case "11" : $mp3info["mode"]="Mono"; break;
default : $mp3info["mode"]="[fehler]"; break;
}
switch($mp3headinfo["emphasis"])
{
case "00" : $mp3info["emphasis"]="none"; break;
case "01" : $mp3info["emphasis"]="50/15ms"; break;
case "10" : $mp3info["emphasis"]="not set"; break;
case "11" : $mp3info["emphasis"]="CCITT j.17"; break;
default : $mp3info["emphasis"]="[fehler]"; break;
}
$mp3info["bitrate"] = $GLOBALS["BITRATE"][$mp3headinfo["mpeg"]][$mp3headinfo["layer"]][$mp3headinfo["bitrate"]];
if((int)$mp3info["frequency"]) $mp3info["framesize"] = floor((144 * $mp3info["bitrate"] * 1000 / $mp3info["frequency"]) + $mp3headinfo["padding"]);
if((int)$mp3info["framesize"]) $mp3info["frames"] = floor($mp3info["size"] / $mp3info["framesize"]);
if((int)$mp3info["bitrate"]) $mp3info["length"] = floor($mp3info["size"] / ($mp3info["bitrate"] * 1000 / 8));
$mp3info["mpeg"] = $mp3headinfo["mpeg"] ? 1 : 2;
$mp3info["copyright"] = $mp3headinfo["copy"] ? "yes" : "no";
$mp3info["private"] = $mp3headinfo["private"] ? "yes" : "no";
$mp3info["home"] = $mp3headinfo["home"] ? "yes" : "no";
if($GLOBALS["DEBUG"])
{
echo "<pre>\$mp3headinfo: ";
print_r($mp3headinfo);
echo "<br />\$mp3info: ";
print_r($mp3info);
echo "</pre>";
}
}
// beginn des ID3v1-tags bei 128byte von hinten
fseek($fp,$mp3info["size"]-128);
$ID3 = fread($fp,128);
if(strtoupper(substr($ID3,0,3))=="TAG")
{
$mp3info["id3v1"] = 1;
if($GLOBALS["DEBUG"]) echo "<b>ID3v1-Tag found</b>.<br />";
$mp3info["id3song"] = strim(substr($ID3,3,30));
$mp3info["id3artist"] = strim(substr($ID3,33,30));
$mp3info["id3album"] = strim(substr($ID3,63,30));
$mp3info["id3year"] = strim(substr($ID3,93,4));
$mp3info["id3genre"] = ord($ID3[127]);
// der trick: falls vorletztes comment-char 0 ist,
// und das letzte ungleich 0, so gibt das letzte die
// tracknummer an
if(ord($ID3[125])==0 && ord($ID3[126])!=0)
{
$mp3info["id3comment"] = trim(substr($ID3,97,28));
$mp3info["id3track"] = ord($ID3[126]);
}
else
{
$mp3info["id3comment"] = trim(substr($ID3,97,30));
}
if(empty($mp3info["song"])) $mp3info["song"] = $mp3info["id3song"];
if(empty($mp3info["artist"])) $mp3info["artist"] = $mp3info["id3artist"];
if(empty($mp3info["album"])) $mp3info["album"] = $mp3info["id3album"];
if(empty($mp3info["year"])) $mp3info["year"] = $mp3info["id3year"];
if(empty($mp3info["genre"])) $mp3info["genre"] = $mp3info["id3genre"];
if(empty($mp3info["comment"])) $mp3info["comment"] = $mp3info["id3comment"];
if(empty($mp3info["track"]) && !empty($mp3info["id3track"])) $mp3info["track"] = $mp3info["id3track"];
}
fclose($fp);
return $mp3info;
}