diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-08-18 16:49:50 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-08-18 16:49:50 +0000 |
commit | ebd39247d9e7a4eda49ac3410197de1e1a2f2457 (patch) | |
tree | 8cd483816d3fa8d514bc63e618e2073be132365f | |
parent | ccf03a68e2584835fb4d6fe3a6bc2e2cc780ce8c (diff) | |
download | ampache-ebd39247d9e7a4eda49ac3410197de1e1a2f2457.tar.gz ampache-ebd39247d9e7a4eda49ac3410197de1e1a2f2457.tar.bz2 ampache-ebd39247d9e7a4eda49ac3410197de1e1a2f2457.zip |
few mpd style tweaks, new archive lib and a new print_tags
-rw-r--r-- | batch.php | 7 | ||||
-rw-r--r-- | bin/print_tags.php.inc | 38 | ||||
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/batch.lib.php | 17 | ||||
-rw-r--r-- | modules/archive/archive.lib.php | 609 | ||||
-rw-r--r-- | templates/show_mpdpl.inc | 4 | ||||
-rw-r--r-- | templates/show_mpdplay.inc | 61 |
7 files changed, 306 insertions, 431 deletions
@@ -38,7 +38,6 @@ /* Drop the normal Time limit constraints, this can take a while */ set_time_limit(0); - if(batch_ok()) { switch( scrub_in( $_REQUEST['action'] ) ) { case 'download_selected': @@ -51,7 +50,7 @@ } $name = "selected-" . date("m-d-Y",time()); $song_files = get_song_files($song_ids); - set_memory_limit($song_files[1]+16); + set_memory_limit($song_files[1]+32); send_zip($name,$song_files[0]); break; case "pl": @@ -60,7 +59,7 @@ $name = $pl->name; $song_ids = $pl->get_songs(); $song_files = get_song_files( $song_ids ); - set_memory_limit( $song_files[1]+16 ); + set_memory_limit( $song_files[1]+32 ); send_zip( $name, $song_files[0] ); break; case "alb": @@ -69,7 +68,7 @@ $name = $alb->name; $song_ids = $alb->get_song_ids(); $song_files = get_song_files( $song_ids ); - set_memory_limit( $song_files[1]+16 ); + set_memory_limit( $song_files[1]+32 ); send_zip( $name, $song_files[0] ); break; default: diff --git a/bin/print_tags.php.inc b/bin/print_tags.php.inc index 59edc534..d266a000 100644 --- a/bin/print_tags.php.inc +++ b/bin/print_tags.php.inc @@ -1,6 +1,9 @@ <?php /* + Copyright 2001 - 2005 Ampache.org + All Rights Reserved + This program 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 @@ -17,18 +20,41 @@ */ +$no_session = '1'; +require ("../modules/init.php"); -/* Name of the filename who's tags you want to read */ -$filename = "/data/music/video1.avi"; +$filename = usage(); +echo "Reading: $filename\n"; -$no_session = '1'; -require ("../modules/init.php"); -echo "<pre>"; $info = new Audioinfo(); $results = $info->info($filename); +$results['file'] = $filename; +$key = get_tag_type($results); +$ampache_results = clean_tag_info($results,$key,$filename); - +echo "Results Seen by GetID3()\n"; print_r($results); +echo "\n------------------------------------------------------------------\n"; +echo "Results Seen by Ampache using $key\n"; +print_r($ampache_results); + +function usage( ) { + $text = _( "[print_tags.php.inc] +This commandline script will display the tag information for the specified filename as it will +appear to Ampache. + \n" ); + echo $text; + + $text = _( "Filename:" ); + echo $text; + + // grab a character ignoring whitespace + $input = trim(fgets(STDIN)); + + return $input; + +} // usage() + ?> diff --git a/docs/CHANGELOG b/docs/CHANGELOG index d6bbe00c..db384eea 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -7,6 +7,7 @@ - Added 'Simple' Genre Bar (Thx sigger) - Added initial TV page for viewing of nowplaying and additional information (Thx sigger) + - Updated Archive library to 2.1 Released 08/13/2005 diff --git a/lib/batch.lib.php b/lib/batch.lib.php index 3d22a72f..5cb8494f 100644 --- a/lib/batch.lib.php +++ b/lib/batch.lib.php @@ -57,10 +57,23 @@ function send_zip( $name, $song_files ) { 'storepaths' => 0, // only store file name, not full path 'level' => 0 // no compression ); + $arc->set_options( $options ); $arc->add_files( $song_files ); - $arc->create_archive(); - $arc->download_file(); + if (count($arc->error)) { + if (conf('debug')) { + log_event($GLOBALS['user']->username,'archive',"Error: unable to add songs"); + + } + } // if failed to add songs + if (!$arc->create_archive()) { + if (conf('debug')) { + log_event($GLOBALS['user']->username,'archive',"Error: unable to create archive"); + } + } // if failed to create archive + + $arc->download_file(); + } // send_zip ?> diff --git a/modules/archive/archive.lib.php b/modules/archive/archive.lib.php index 1a605f10..2f67af19 100644 --- a/modules/archive/archive.lib.php +++ b/modules/archive/archive.lib.php @@ -1,8 +1,8 @@ <?php
/*--------------------------------------------------
- | TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.0
+ | TAR/GZIP/BZIP2/ZIP ARCHIVE CLASSES 2.1
| By Devin Doucette
- | Copyright (c) 2004 Devin Doucette
+ | Copyright (c) 2005 Devin Doucette
| Email: darksnoopy@shaw.ca
+--------------------------------------------------
| Email bugs/suggestions to darksnoopy@shaw.ca
@@ -16,49 +16,48 @@ class archive {
function archive($name)
{
- $this->options = array(
- 'basedir'=>".",
- 'name'=>$name,
- 'prepend'=>"",
- 'inmemory'=>0,
- 'overwrite'=>0,
- 'recurse'=>1,
- 'storepaths'=>1,
- 'level'=>3,
- 'method'=>1,
- 'sfx'=>"",
- 'type'=>"",
- 'comment'=>""
+ $this->options = array (
+ 'basedir' => ".",
+ 'name' => $name,
+ 'prepend' => "",
+ 'inmemory' => 0,
+ 'overwrite' => 0,
+ 'recurse' => 1,
+ 'storepaths' => 1,
+ 'followlinks' => 0,
+ 'level' => 3,
+ 'method' => 1,
+ 'sfx' => "",
+ 'type' => "",
+ 'comment' => ""
);
- $this->files = array();
- $this->exclude = array();
- $this->storeonly = array();
- $this->error = array();
+ $this->files = array ();
+ $this->exclude = array ();
+ $this->storeonly = array ();
+ $this->error = array ();
}
function set_options($options)
{
- foreach($options as $key => $value)
- {
+ foreach ($options as $key => $value)
$this->options[$key] = $value;
- }
- if(!empty($this->options['basedir']))
+ if (!empty ($this->options['basedir']))
{
- $this->options['basedir'] = str_replace("\\","/",$this->options['basedir']);
- $this->options['basedir'] = preg_replace("/\/+/","/",$this->options['basedir']);
- $this->options['basedir'] = preg_replace("/\/$/","",$this->options['basedir']);
+ $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
+ $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
+ $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
}
- if(!empty($this->options['name']))
+ if (!empty ($this->options['name']))
{
- $this->options['name'] = str_replace("\\","/",$this->options['name']);
- $this->options['name'] = preg_replace("/\/+/","/",$this->options['name']);
+ $this->options['name'] = str_replace("\\", "/", $this->options['name']);
+ $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
}
- if(!empty($this->options['prepend']))
+ if (!empty ($this->options['prepend']))
{
- $this->options['prepend'] = str_replace("\\","/",$this->options['prepend']);
- $this->options['prepend'] = preg_replace("/^(\.*\/+)+/","",$this->options['prepend']);
- $this->options['prepend'] = preg_replace("/\/+/","/",$this->options['prepend']);
- $this->options['prepend'] = preg_replace("/\/$/","",$this->options['prepend']) . "/";
+ $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
+ $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
+ $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
+ $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
}
}
@@ -66,20 +65,18 @@ class archive {
$this->make_list();
- if($this->options['inmemory'] == 0)
+ if ($this->options['inmemory'] == 0)
{
$pwd = getcwd();
chdir($this->options['basedir']);
- if($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip"? ".tmp" : "")))
+ if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
{
$this->error[] = "File {$this->options['name']} already exists.";
chdir($pwd);
return 0;
}
- else if($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip"? ".tmp" : ""),"wb+"))
- {
+ else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
chdir($pwd);
- }
else
{
$this->error[] = "Could not open {$this->options['name']} for writing.";
@@ -88,231 +85,184 @@ class archive }
}
else
- {
$this->archive = "";
- }
- switch($this->options['type'])
+ switch ($this->options['type'])
{
case "zip":
- if(!$this->create_zip())
+ if (!$this->create_zip())
{
$this->error[] = "Could not create zip file.";
return 0;
}
break;
case "bzip":
- if(!$this->create_tar())
+ if (!$this->create_tar())
{
$this->error[] = "Could not create tar file.";
return 0;
}
- if(!$this->create_bzip())
+ if (!$this->create_bzip())
{
$this->error[] = "Could not create bzip2 file.";
return 0;
}
break;
case "gzip":
- if(!$this->create_tar())
+ if (!$this->create_tar())
{
$this->error[] = "Could not create tar file.";
return 0;
}
- if(!$this->create_gzip())
+ if (!$this->create_gzip())
{
$this->error[] = "Could not create gzip file.";
return 0;
}
break;
case "tar":
- if(!$this->create_tar())
+ if (!$this->create_tar())
{
$this->error[] = "Could not create tar file.";
return 0;
}
}
- if($this->options['inmemory'] == 0)
+ if ($this->options['inmemory'] == 0)
{
fclose($this->archive);
- if($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
- {
+ if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
- }
}
}
function add_data($data)
{
- if($this->options['inmemory'] == 0)
- {
- fwrite($this->archive,$data);
- }
+ if ($this->options['inmemory'] == 0)
+ fwrite($this->archive, $data);
else
- {
$this->archive .= $data;
- }
}
function make_list()
{
- if(!empty($this->exclude))
- {
- foreach($this->files as $key => $value)
- {
- foreach($this->exclude as $current)
- {
- if($value['name'] == $current['name'])
- {
- unset($this->files[$key]);
- }
- }
- }
- }
- if(!empty($this->storeonly))
- {
- foreach($this->files as $key => $value)
- {
- foreach($this->storeonly as $current)
- {
- if($value['name'] == $current['name'])
- {
+ if (!empty ($this->exclude))
+ foreach ($this->files as $key => $value)
+ foreach ($this->exclude as $current)
+ if ($value['name'] == $current['name'])
+ unset ($this->files[$key]);
+ if (!empty ($this->storeonly))
+ foreach ($this->files as $key => $value)
+ foreach ($this->storeonly as $current)
+ if ($value['name'] == $current['name'])
$this->files[$key]['method'] = 0;
- }
- }
- }
- }
- unset($this->exclude,$this->storeonly);
+ unset ($this->exclude, $this->storeonly);
}
function add_files($list)
{
$temp = $this->list_files($list);
- foreach($temp as $current)
- {
+ foreach ($temp as $current)
$this->files[] = $current;
- }
}
function exclude_files($list)
{
$temp = $this->list_files($list);
- foreach($temp as $current)
- {
+ foreach ($temp as $current)
$this->exclude[] = $current;
- }
}
function store_files($list)
{
$temp = $this->list_files($list);
- foreach($temp as $current)
- {
+ foreach ($temp as $current)
$this->storeonly[] = $current;
- }
}
function list_files($list)
{
- if(!is_array($list))
+ if (!is_array ($list))
{
$temp = $list;
- $list = array($temp);
- unset($temp);
+ $list = array ($temp);
+ unset ($temp);
}
- $files = array();
+ $files = array ();
$pwd = getcwd();
chdir($this->options['basedir']);
- foreach($list as $current)
+ foreach ($list as $current)
{
- $current = str_replace("\\","/",$current);
- $current = preg_replace("/\/+/","/",$current);
- $current = preg_replace("/\/$/","",$current);
- if(strstr($current,"*"))
+ $current = str_replace("\\", "/", $current);
+ $current = preg_replace("/\/+/", "/", $current);
+ $current = preg_replace("/\/$/", "", $current);
+ if (strstr($current, "*"))
{
- $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/","\\\\\\1",$current);
- $regex = str_replace("*",".*",$regex);
- $dir = strstr($current,"/")? substr($current,0,strrpos($current,"/")) : ".";
+ $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
+ $regex = str_replace("*", ".*", $regex);
+ $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
$temp = $this->parse_dir($dir);
- foreach($temp as $current2)
- {
- if(preg_match("/^{$regex}$/i",$current2['name']))
- {
+ foreach ($temp as $current2)
+ if (preg_match("/^{$regex}$/i", $current2['name']))
$files[] = $current2;
- }
- }
- unset($regex,$dir,$temp,$current);
+ unset ($regex, $dir, $temp, $current);
}
- else if(@is_dir($current))
+ else if (@is_dir($current))
{
$temp = $this->parse_dir($current);
- foreach($temp as $file)
- {
+ foreach ($temp as $file)
$files[] = $file;
- }
- unset($temp,$file);
- }
- else if(@file_exists($current))
- {
- $files[] = array('name'=>$current,'name2'=>$this->options['prepend'] .
- preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($current,"/"))?
- substr($current,strrpos($current,"/") + 1) : $current),'type'=>0,
- 'ext'=>substr($current,strrpos($current,".")),'stat'=>stat($current));
+ unset ($temp, $file);
}
+ else if (@file_exists($current))
+ $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
+ preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
+ substr($current, strrpos($current, "/") + 1) : $current),
+ 'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
+ 'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
}
chdir($pwd);
- unset($current,$pwd);
+ unset ($current, $pwd);
- usort($files,array("archive","sort_files"));
+ usort($files, array ("archive", "sort_files"));
return $files;
}
function parse_dir($dirname)
{
- if($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/",$dirname))
- {
- $files = array(array('name'=>$dirname,'name2'=>$this->options['prepend'] .
- preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($dirname,"/"))?
- substr($dirname,strrpos($dirname,"/") + 1) : $dirname),'type'=>5,'stat'=>stat($dirname)));
- }
+ if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
+ $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
+ preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
+ substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
else
- {
- $files = array();
- }
+ $files = array ();
$dir = @opendir($dirname);
- while($file = @readdir($dir))
+ while ($file = @readdir($dir))
{
- if($file == "." || $file == "..")
- {
+ $fullname = $dirname . "/" . $file;
+ if ($file == "." || $file == "..")
continue;
- }
- else if(@is_dir($dirname."/".$file))
+ else if (@is_dir($fullname))
{
- if(empty($this->options['recurse']))
- {
+ if (empty ($this->options['recurse']))
continue;
- }
- $temp = $this->parse_dir($dirname."/".$file);
- foreach($temp as $file2)
- {
+ $temp = $this->parse_dir($fullname);
+ foreach ($temp as $file2)
$files[] = $file2;
- }
- }
- else if(@file_exists($dirname."/".$file))
- {
- $files[] = array('name'=>$dirname."/".$file,'name2'=>$this->options['prepend'] .
- preg_replace("/(\.+\/+)+/","",($this->options['storepaths'] == 0 && strstr($dirname."/".$file,"/"))?
- substr($dirname."/".$file,strrpos($dirname."/".$file,"/") + 1) : $dirname."/".$file),'type'=>0,
- 'ext'=>substr($file,strrpos($file,".")),'stat'=>stat($dirname."/".$file));
}
+ else if (@file_exists($fullname))
+ $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
+ preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
+ substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
+ 'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
+ 'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
}
@closedir($dir);
@@ -320,63 +270,53 @@ class archive return $files;
}
- function sort_files($a,$b)
+ function sort_files($a, $b)
{
- if($a['type'] != $b['type'])
- {
- return $a['type'] > $b['type']? -1 : 1;
- }
- else if($a['type'] == 5)
- {
- return strcmp(strtolower($a['name']),strtolower($b['name']));
- }
+ if ($a['type'] != $b['type'])
+ if ($a['type'] == 5 || $b['type'] == 2)
+ return -1;
+ else if ($a['type'] == 2 || $b['type'] == 5)
+ return 1;
+ else if ($a['type'] == 5)
+ return strcmp(strtolower($a['name']), strtolower($b['name']));
+ else if ($a['ext'] != $b['ext'])
+ return strcmp($a['ext'], $b['ext']);
+ else if ($a['stat'][7] != $b['stat'][7])
+ return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
else
- {
- if($a['ext'] != $b['ext'])
- {
- return strcmp($a['ext'],$b['ext']);
- }
- else if($a['stat'][7] != $b['stat'][7])
- {
- return $a['stat'][7] > $b['stat'][7]? -1 : 1;
- }
- else
- {
- return strcmp(strtolower($a['name']),strtolower($b['name']));
- }
- }
+ return strcmp(strtolower($a['name']), strtolower($b['name']));
return 0;
}
function download_file()
{
- if($this->options['inmemory'] == 0)
+ if ($this->options['inmemory'] == 0)
{
$this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
return;
}
- switch($this->options['type'])
+ switch ($this->options['type'])
{
case "zip":
- header("Content-type:application/zip");
+ header("Content-Type: application/zip");
break;
case "bzip":
- header("Content-type:application/x-compressed");
+ header("Content-Type: application/x-bzip2");
break;
case "gzip":
- header("Content-type:application/x-compressed");
+ header("Content-Type: application/x-gzip");
break;
case "tar":
- header("Content-type:application/x-tar");
+ header("Content-Type: application/x-tar");
}
- $header = "Content-disposition: attachment; filename=\"";
- $header .= strstr($this->options['name'],"/")? substr($this->options['name'],strrpos($this->options['name'],"/") + 1) : $this->options['name'];
+ $header = "Content-Disposition: attachment; filename=\"";
+ $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
$header .= "\"";
header($header);
- header("Content-length: " . strlen($this->archive));
- header("Content-transfer-encoding: binary");
- header("Pragma: no-cache");
- header("Expires: 0");
+ header("Content-Length: " . strlen($this->archive));
+ header("Content-Transfer-Encoding: binary");
+ header("Cache-Control: no-cache, must-revalidate, max-age=60");
+ header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
print($this->archive);
}
}
@@ -394,64 +334,53 @@ class tar_file extends archive $pwd = getcwd();
chdir($this->options['basedir']);
- foreach($this->files as $current)
+ foreach ($this->files as $current)
{
- if($current['name'] == $this->options['name'])
- {
+ if ($current['name'] == $this->options['name'])
continue;
- }
- if(strlen($current['name2']) > 99)
+ if (strlen($current['name2']) > 99)
{
- $path = substr($current['name2'],0,strpos($current['name2'],"/",strlen($current['name2']) - 100) + 1);
- $current['name2'] = substr($current['name2'],strlen($path));
- if(strlen($path) > 154 || strlen($current['name2']) > 99)
+ $path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
+ $current['name2'] = substr($current['name2'], strlen($path));
+ if (strlen($path) > 154 || strlen($current['name2']) > 99)
{
$this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
continue;
}
}
- $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12",$current['name2'],decoct($current['stat'][2]),
- sprintf("%6s ",decoct($current['stat'][4])),sprintf("%6s ",decoct($current['stat'][5])),
- sprintf("%11s ",decoct($current['stat'][7])),sprintf("%11s ",decoct($current['stat'][9])),
- " ",$current['type'],"","ustar","00","Unknown","Unknown","","",!empty($path)? $path : "","");
+ $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o",
+ $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]),
+ sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]),
+ " ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ",
+ "Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
$checksum = 0;
- for($i = 0; $i < 512; $i++)
- {
- $checksum += ord(substr($block,$i,1));
- }
- $checksum = pack("a8",sprintf("%6s ",decoct($checksum)));
- $block = substr_replace($block,$checksum,148,8);
+ for ($i = 0; $i < 512; $i++)
+ $checksum += ord(substr($block, $i, 1));
+ $checksum = pack("a8", sprintf("%07o", $checksum));
+ $block = substr_replace($block, $checksum, 148, 8);
- if($current['stat'][7] == 0)
- {
+ if ($current['type'] == 2 || $current['stat'][7] == 0)
$this->add_data($block);
- }
- else if($fp = @fopen($current['name'],"rb"))
+ else if ($fp = @fopen($current['name'], "rb"))
{
$this->add_data($block);
- while($temp = fread($fp,1048576))
- {
+ while ($temp = fread($fp, 1048576))
$this->add_data($temp);
- }
- if($current['stat'][7] % 512 > 0)
+ if ($current['stat'][7] % 512 > 0)
{
$temp = "";
- for($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
- {
+ for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
$temp .= "\0";
- }
$this->add_data($temp);
}
fclose($fp);
}
else
- {
$this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
- }
}
- $this->add_data(pack("a512",""));
+ $this->add_data(pack("a1024", ""));
chdir($pwd);
@@ -463,99 +392,90 @@ class tar_file extends archive $pwd = getcwd();
chdir($this->options['basedir']);
- if($fp = $this->open_archive())
+ if ($fp = $this->open_archive())
{
- if($this->options['inmemory'] == 1)
- {
- $this->files = array();
- }
+ if ($this->options['inmemory'] == 1)
+ $this->files = array ();
- while($block = fread($fp,512))
+ while ($block = fread($fp, 512))
{
- $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100temp/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp",$block);
- $file = array(
- 'name'=>$temp['prefix'] . $temp['name'],
- 'stat'=>array(
- 2=>$temp['mode'],
- 4=>octdec($temp['uid']),
- 5=>octdec($temp['gid']),
- 7=>octdec($temp['size']),
- 9=>octdec($temp['mtime']),
+ $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
+ $file = array (
+ 'name' => $temp['prefix'] . $temp['name'],
+ 'stat' => array (
+ 2 => $temp['mode'],
+ 4 => octdec($temp['uid']),
+ 5 => octdec($temp['gid']),
+ 7 => octdec($temp['size']),
+ 9 => octdec($temp['mtime']),
),
- 'checksum'=>octdec($temp['checksum']),
- 'type'=>$temp['type'],
- 'magic'=>$temp['magic'],
+ 'checksum' => octdec($temp['checksum']),
+ 'type' => $temp['type'],
+ 'magic' => $temp['magic'],
);
- if($file['checksum'] == 0x00000000)
- {
+ if ($file['checksum'] == 0x00000000)
break;
- }
- else if($file['magic'] != "ustar")
+ else if (substr($file['magic'], 0, 5) != "ustar")
{
$this->error[] = "This script does not support extracting this type of tar file.";
break;
}
- $block = substr_replace($block," ",148,8);
+ $block = substr_replace($block, " ", 148, 8);
$checksum = 0;
- for($i = 0; $i < 512; $i++)
+ for ($i = 0; $i < 512; $i++)
+ $checksum += ord(substr($block, $i, 1));
+ if ($file['checksum'] != $checksum)
+ $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
+
+ if ($this->options['inmemory'] == 1)
{
- $checksum += ord(substr($block,$i,1));
+ $file['data'] = fread($fp, $file['stat'][7]);
+ fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
+ unset ($file['checksum'], $file['magic']);
+ $this->files[] = $file;
}
- if($file['checksum'] != $checksum)
+ else if ($file['type'] == 5)
{
- $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
+ if (!is_dir($file['name']))
+ mkdir($file['name'], $file['stat'][2]);
}
-
- if($this->options['inmemory'] == 1)
+ else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
{
- $file['data'] = fread($fp,$file['stat'][7]);
- fread($fp,(512 - $file['stat'][7] % 512) == 512? 0 : (512 - $file['stat'][7] % 512));
- unset($file['checksum'],$file['magic']);
- $this->files[] = $file;
+ $this->error[] = "{$file['name']} already exists.";
+ continue;
+ }
+ else if ($file['type'] == 2)
+ {
+ symlink($temp['symlink'], $file['name']);
+ chmod($file['name'], $file['stat'][2]);
+ }
+ else if ($new = @fopen($file['name'], "wb"))
+ {
+ fwrite($new, fread($fp, $file['stat'][7]));
+ fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
+ fclose($new);
+ chmod($file['name'], $file['stat'][2]);
}
else
{
- if($file['type'] == 5)
- {
- if(!is_dir($file['name']))
- {
- mkdir($file['name'],$file['stat'][2]);
- chown($file['name'],$file['stat'][4]);
- chgrp($file['name'],$file['stat'][5]);
- }
- }
- else if($this->options['overwrite'] == 0 && file_exists($file['name']))
- {
- $this->error[] = "{$file['name']} already exists.";
- }
- else if($new = @fopen($file['name'],"wb"))
- {
- fwrite($new,fread($fp,$file['stat'][7]));
- fread($fp,(512 - $file['stat'][7] % 512) == 512? 0 : (512 - $file['stat'][7] % 512));
- fclose($new);
- chmod($file['name'],$file['stat'][2]);
- chown($file['name'],$file['stat'][4]);
- chgrp($file['name'],$file['stat'][5]);
- }
- else
- {
- $this->error[] = "Could not open {$file['name']} for writing.";
- }
+ $this->error[] = "Could not open {$file['name']} for writing.";
+ continue;
}
- unset($file);
+ chown($file['name'], $file['stat'][4]);
+ chgrp($file['name'], $file['stat'][5]);
+ touch($file['name'], $file['stat'][9]);
+ unset ($file);
}
}
else
- {
$this->error[] = "Could not open file {$this->options['name']}";
- }
chdir($pwd);
}
function open_archive()
{
- return @fopen($this->options['name'],"rb");
+ return @fopen($this->options['name'], "rb");
}
}
@@ -569,17 +489,15 @@ class gzip_file extends tar_file function create_gzip()
{
- if($this->options['inmemory'] == 0)
+ if ($this->options['inmemory'] == 0)
{
$pwd = getcwd();
chdir($this->options['basedir']);
- if($fp = gzopen($this->options['name'],"wb{$this->options['level']}"))
+ if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
{
- fseek($this->archive,0);
- while($temp = fread($this->archive,1048576))
- {
- gzwrite($fp,$temp);
- }
+ fseek($this->archive, 0);
+ while ($temp = fread($this->archive, 1048576))
+ gzwrite($fp, $temp);
gzclose($fp);
chdir($pwd);
}
@@ -591,16 +509,14 @@ class gzip_file extends tar_file }
}
else
- {
- $this->archive = gzencode($this->archive,$this->options['level']);
- }
+ $this->archive = gzencode($this->archive, $this->options['level']);
return 1;
}
function open_archive()
{
- return @gzopen($this->options['name'],"rb");
+ return @gzopen($this->options['name'], "rb");
}
}
@@ -614,17 +530,15 @@ class bzip_file extends tar_file function create_bzip()
{
- if($this->options['inmemory'] == 0)
+ if ($this->options['inmemory'] == 0)
{
$pwd = getcwd();
chdir($this->options['basedir']);
- if($fp = bzopen($this->options['name'],"wb"))
+ if ($fp = bzopen($this->options['name'], "wb"))
{
- fseek($this->archive,0);
- while($temp = fread($this->archive,1048576))
- {
- bzwrite($fp,$temp);
- }
+ fseek($this->archive, 0);
+ while ($temp = fread($this->archive, 1048576))
+ bzwrite($fp, $temp);
bzclose($fp);
chdir($pwd);
}
@@ -636,16 +550,14 @@ class bzip_file extends tar_file }
}
else
- {
- $this->archive = bzcompress($this->archive,$this->options['level']);
- }
+ $this->archive = bzcompress($this->archive, $this->options['level']);
return 1;
}
function open_archive()
{
- return @bzopen($this->options['name'],"rb");
+ return @bzopen($this->options['name'], "rb");
}
}
@@ -663,113 +575,92 @@ class zip_file extends archive $offset = 0;
$central = "";
- if(!empty($this->options['sfx']))
- {
- if($fp = @fopen($this->options['sfx'],"rb"))
+ if (!empty ($this->options['sfx']))
+ if ($fp = @fopen($this->options['sfx'], "rb"))
{
- $temp = fread($fp,filesize($this->options['sfx']));
+ $temp = fread($fp, filesize($this->options['sfx']));
fclose($fp);
$this->add_data($temp);
$offset += strlen($temp);
- unset($temp);
+ unset ($temp);
}
else
- {
$this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
- }
- }
$pwd = getcwd();
chdir($this->options['basedir']);
- foreach($this->files as $current)
+ foreach ($this->files as $current)
{
- if($current['name'] == $this->options['name'])
- {
+ if ($current['name'] == $this->options['name'])
continue;
- }
- $translate = array('Ç'=>pack("C",128),'ü'=>pack("C",129),'é'=>pack("C",130),'â'=>pack("C",131),'ä'=>pack("C",132),
- 'à'=>pack("C",133),'å'=>pack("C",134),'ç'=>pack("C",135),'ê'=>pack("C",136),'ë'=>pack("C",137),
- 'è'=>pack("C",138),'ï'=>pack("C",139),'î'=>pack("C",140),'ì'=>pack("C",141),'Ä'=>pack("C",142),
- 'Å'=>pack("C",143),'É'=>pack("C",144),'æ'=>pack("C",145),'Æ'=>pack("C",146),'ô'=>pack("C",147),
- 'ö'=>pack("C",148),'ò'=>pack("C",149),'û'=>pack("C",150),'ù'=>pack("C",151),'Ö'=>pack("C",153),
- 'Ü'=>pack("C",154),'£'=>pack("C",156),'¥'=>pack("C",157),'ƒ'=>pack("C",159),'á'=>pack("C",160),
- 'í'=>pack("C",161),'ó'=>pack("C",162),'ú'=>pack("C",163),'ñ'=>pack("C",164),'Ñ'=>pack("C",165));
- $current['name2'] = strtr($current['name2'],$translate);
-
- $timedate = explode(" ",date("Y n j G i s",$current['stat'][9]));
- $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
+ $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
+ $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
- $block = pack("VvvvV",0x04034b50,0x000A,0x0000,(isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate);
+ $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
- if($current['stat'][7] == 0 && $current['type'] == 5)
+ if ($current['stat'][7] == 0 && $current['type'] == 5)
{
- $block .= pack("VVVvv",0x00000000,0x00000000,0x00000000,strlen($current['name2']) + 1,0x0000);
+ $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
$block .= $current['name2'] . "/";
$this->add_data($block);
- $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000,
- (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate,
- 0x00000000,0x00000000,0x00000000,strlen($current['name2']) + 1,0x0000,0x0000,0x0000,0x0000,$current['type'] == 5? 0x00000010 : 0x00000000,$offset);
+ $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
+ (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
+ 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
$central .= $current['name2'] . "/";
$files++;
$offset += (31 + strlen($current['name2']));
}
- else if($current['stat'][7] == 0)
+ else if ($current['stat'][7] == 0)
{
- $block .= pack("VVVvv",0x00000000,0x00000000,0x00000000,strlen($current['name2']),0x0000);
+ $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
$block .= $current['name2'];
$this->add_data($block);
- $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000,
- (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate,
- 0x00000000,0x00000000,0x00000000,strlen($current['name2']),0x0000,0x0000,0x0000,0x0000,$current['type'] == 5? 0x00000010 : 0x00000000,$offset);
+ $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
+ (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
+ 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
$central .= $current['name2'];
$files++;
$offset += (30 + strlen($current['name2']));
}
- else if($fp = @fopen($current['name'],"rb"))
+ else if ($fp = @fopen($current['name'], "rb"))
{
- $temp = fread($fp,$current['stat'][7]);
+ $temp = fread($fp, $current['stat'][7]);
fclose($fp);
$crc32 = crc32($temp);
- if(!isset($current['method']) && $this->options['method'] == 1)
+ if (!isset($current['method']) && $this->options['method'] == 1)
{
- $temp = gzcompress($temp,$this->options['level']);
+ $temp = gzcompress($temp, $this->options['level']);
$size = strlen($temp) - 6;
- $temp = substr($temp,2,$size);
+ $temp = substr($temp, 2, $size);
}
else
- {
$size = strlen($temp);
- }
- $block .= pack("VVVvv",$crc32,$size,$current['stat'][7],strlen($current['name2']),0x0000);
+ $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
$block .= $current['name2'];
$this->add_data($block);
$this->add_data($temp);
- unset($temp);
- $central .= pack("VvvvvVVVVvvvvvVV",0x02014b50,0x0014,$this->options['method'] == 0? 0x0000 : 0x000A,0x0000,
- (isset($current['method']) || $this->options['method'] == 0)? 0x0000 : 0x0008,$timedate,
- $crc32,$size,$current['stat'][7],strlen($current['name2']),0x0000,0x0000,0x0000,0x0000,0x00000000,$offset);
+ unset ($temp);
+ $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
+ (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
+ $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
$central .= $current['name2'];
$files++;
$offset += (30 + strlen($current['name2']) + $size);
}
else
- {
$this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
- }
}
$this->add_data($central);
- $this->add_data(pack("VvvvvVVv",0x06054b50,0x0000,0x0000,$files,$files,strlen($central),$offset,
- !empty($this->options['comment'])? strlen($this->options['comment']) : 0x0000));
+ $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
+ !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
- if(!empty($this->options['comment']))
- {
+ if (!empty ($this->options['comment']))
$this->add_data($this->options['comment']);
- }
chdir($pwd);
diff --git a/templates/show_mpdpl.inc b/templates/show_mpdpl.inc index a8bdac20..8a2e3f09 100644 --- a/templates/show_mpdpl.inc +++ b/templates/show_mpdpl.inc @@ -99,8 +99,8 @@ $myMpd = init_mpd(); echo "<tr class=\"".flip_class()."\">"; if ($id==$myMpd->current_track_id) { - $tdstyle = "style='padding: 0px 2px 0px 2px; font-weight: bold;' class='error'"; - $linkstyle = "class='error'"; + $tdstyle = "style='padding: 0px 2px 0px 2px; font-weight: bold;' class='npsong'"; + $linkstyle = "class='npsong'"; } else { $tdstyle = $minpad; diff --git a/templates/show_mpdplay.inc b/templates/show_mpdplay.inc index d71ae02b..ed770354 100644 --- a/templates/show_mpdplay.inc +++ b/templates/show_mpdplay.inc @@ -106,10 +106,10 @@ global $condPL; <tr><td> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> - <td><b><?php echo _("Now Playing :")?></b></td> + <td class="npsong"><b><?php echo _("Now Playing :")?></b></td> </tr> <tr> - <td align="center"><?php + <td align="center" class="npsong"><?php if (!$myMpd->playlist[($myMpd->current_track_id)]['Title']) { list($tmp, $id, $tmp) = preg_split("/(song=|&)/", $myMpd->playlist[($myMpd->current_track_id)]['file']); $r = new Song($id); @@ -126,7 +126,7 @@ global $condPL; ?></td> </tr> <tr> - <td align="center"><span id="mpd_cur_track_pos"><?php echo fmt_time($myMpd->current_track_position)?></span> (<?php echo (round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."%) played" ?></td> + <td align="center" class="npsong"><span id="mpd_cur_track_pos"><?php echo fmt_time($myMpd->current_track_position)?></span> (<?php echo (round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."%) played" ?></td> </tr> <tr> @@ -163,59 +163,4 @@ echo '<script language="JavaScript" type="text/javascript"> var mpd_song_length echo '<script language="JavaScript" type="text/javascript"> var mpd_state = "'. $myMpd->state .'" </script>'; ?> -<?php /**************** Comment the playlist out now that the big playlist is done - -<br /> -<table border="0" cellpadding="0" cellspacing="0" WIDTH=<?php echo $PG_WIDTH ?>> - <tr><td align="center"><b><?php echo _("Server Playlist"); ?></b></td></tr> - <tr> - <td align="center"><i><a title="<?php echo _("Refresh the Playlist Window"); ?>" href="<?php echo conf('web_path'); ?>"><?php echo _("[refresh]"); ?></a> -<?php if ( $myMpd->playlist_count > 0 ) { ?> - [<a title="<?php echo _("Click to shuffle (randomize) the playlist"); ?>" href="<?php echo conf('web_path'); ?>/amp-mpd.php?action=shuffle"><?php echo _("shuffle"); ?></a>] - [<a title="<?php echo _("Click to clear the playlist"); ?>" href="<?php echo conf('web_path'); ?>/amp-mpd.php?action=clear"><?php echo _("clear"); ?></a>] - [<a title="<?php echo _("Click the toggle condensed playlist"); ?>" href="<?php echo conf('web_path'); ?>/amp-mpd.php?action=condPL"><?php echo _("condensed"); ?></a>] -<?php } ?> - </i></td> - </tr> - <tr><td align="left"> -<?php -$condPL= conf('condPL'); - if ($condPL) echo " ... Condensed Playlist ... <br/>"; - $pl = $myMpd->playlist; - if ( is_null($pl) ) echo "ERROR: " .$myMpd->errStr."\n"; - else { - $maxlen = strlen(count($pl)); - foreach ($pl as $id => $entry) { - if ( (!$condPL) or (($id >= $myMpd->current_track_id -1) && ($id <= $myMpd->current_track_id + 10)) ) - { - $tblClass = ( $id == $myMpd->current_track_id ? "SongPlaying" : "Song" ); - $track = $id+1; - - // Make all number lengths equal - $len = strlen($track); - - while ($len < $maxlen) { - $track = "0" . $track; - $len++; - } - - $song_name = truncate_with_ellipse($entry['Artist'],conf('ellipse_threshold_artist')-3) . " - " . truncate_with_ellipse($entry['Title'],conf('ellipse_threshold_title')-3) . " - " . $entry['Album'] . " - " . fmt_time($entry['Time']); - - echo "\t"; - if ($myMpd->current_track_id == $id) echo "<b>"; - echo "<a title=\"Click to remove '".$entry['Title']." '\" href=\"".conf('web_path')."/amp-mpd.php?action=rem&id=".$id."\">" . $track . ".</a>"; - echo " <a title=\"Click to jump to '".$entry['Title']."'\" href='".conf('web_path')."/amp-mpd.php?action=skipto&val=".$id."'>$song_name</a>"; - echo " <a title=\"file='".$entry['file']."'\" href=\"".conf('web_path')."\">f</a>"; - if ($myMpd->current_track_id == $id) echo "</b>"; - echo "<br />\n"; - } - } - } - if ( $myMpd->playlist_count == 0 ) { - echo "<i>(Playlist is empty)</i><br />\n"; - } -?> - </td></tr> -</table> -<?php *********************/ ?> </div> |