<?php
//
// ObsidianMusic
// a.k.a. amaroK Web Frontend 2.0
//
// Created 11/24/05
// Copyright (C) Ryan Loebs (ObsidianX) 2005/2006
// See LICENSE for GPL
//
// miscfuncs.php - Miscelaneous Functions
//
///////////////////////////////////////
if(eregi("miscfuncs.php", $_SERVER['PHP_SELF'])){
die("Cannot access directly.");
}
// Takes the seconds format amaroK uses in its database
// and converts it to human readable hh:mm:ss format
function sec2min($seconds){
$seconds = intval($seconds/1000);
$mins = intval($seconds/60);
$secs = $seconds%60;
$hrs = intval($mins/60);
if($secs < 10){
$secs = "0$secs";
}
if($hrs > 0){
$mins = $mins%60;
if($mins < 10){
$mins = "0$mins";
}
return "$hrs:$mins:$secs";
}else{
return "$mins:$secs";
}
}
// Takes the human readable format (hh:mm:ss) and converts
// it to seconds format for the playlists
function min2sec($in){
$time = explode(":", $in);
if(count($time) == 3){
$hrs = $time[0]*3600;
$mins = $time[1]*60;
}else{
$hrs = 0;
$mins = $time[0]*60;
}
$secs = end($time);
return $hrs+$mins+$secs;
}
// Reads the themes directory and produces an array filled with the names of the themes
// (based on the file name minus .css)
function getThemes(){
if($dir = opendir("themes")){
while(false !== ($file = readdir($dir))){
if($file != '.' && $file != '..'){
$ext = explode('.', $file);
$name = "";
foreach($ext as $key=>$value){
if($value != end($ext)){
if($value != $ext[0]){
$name .= ".";
}
$name .= $value;
}
}
$ext = end($ext);
$outa[] = array('theme' => $name);
}
}
}
return $outa;
}
// Creates the array for populating the song table
function getSongArray($q){
global $extrainfo;
$i = 0;
$rows = array();
while($row = fetch_assoc($q)){
if($extrainfo){
$format = explode('.', $row['url']);
$format = strtoupper($format[count($format)-1]);
$bitrate = "<td class='bitrate'>{$row['bitrate']}</td>";
$format = "<td class='format'>$format</td>";
}
$row['artistN'] = $row['artistN'] ? htmlentities($row['artistN'], ENT_QUOTES, 'UTF-8') : '<i>'._UNKNOWN.'</i>';
$row['title'] = $row['title'] ? htmlentities($row['title'], ENT_QUOTES, 'UTF-8') : '<i>'._UNKNOWN.'</i>';
$rows[] = array(
'song' => $row['artistN']." - ".$row['title'],
'album' => htmlentities($row['albumN'], ENT_QUOTES, 'UTF-8'),
'track' => $row['tracknumber'] > 0 ? $row['tracknumber'] : '',
'songid' => (int)$row['id'],
'length' => sec2min($row['length']),
'albumid' => $row['album'],
'num' => $i,
'bitrate' => isset($bitrate) ? $bitrate : '',
'format' => isset($format) ? $format : '',
);
$i++;
}
return $rows;
}