diff --git a/lib/batch.lib.php b/lib/batch.lib.php index ede5e03c..4ee664e3 100644 --- a/lib/batch.lib.php +++ b/lib/batch.lib.php @@ -62,7 +62,7 @@ function get_song_files($media_ids) * @param string $name name of the zip file to be created * @param string $song_files array of full paths to songs to zip create w/ call to get_song_files */ -function send_zip( $name, $song_files ) +function send_zip($name, $song_files) { // Check if they want to save it to a file, if so then make sure they've // got a defined path as well and that it's writable. @@ -75,37 +75,37 @@ function send_zip( $name, $song_files ) $in_memory = '0'; $basedir = AmpConfig::get('tmp_dir_path'); } - } else { $in_memory = '1'; } // if file downloads /* Require needed library */ - require_once AmpConfig::get('prefix') . '/modules/archive/archive.lib.php'; - $arc = new zip_file( $name . ".zip" ); - $options = array( - 'inmemory' => $in_memory, // create archive in memory - 'basedir' => $basedir, - 'storepaths' => 0, // only store file name, not full path - 'level' => 0, // no compression - 'comment' => AmpConfig::get('file_zip_comment') - ); + require_once AmpConfig::get('prefix') . '/modules/archive/archive.lib.php'; + $arc = new zip_file($name . ".zip" ); + $options = array( + 'inmemory' => $in_memory, // create archive in memory + 'basedir' => $basedir, + 'storepaths' => 0, // only store file name, not full path + 'level' => 0, // no compression + 'comment' => AmpConfig::get('file_zip_comment'), + 'type' => "zip" + ); - $arc->set_options( $options ); - foreach ($song_files as $dir => $files) { - $arc->add_files( $files, $dir ); - } + $arc->set_options( $options ); + foreach ($song_files as $dir => $files) { + $arc->add_files($files, $dir); + } if (count($arc->error)) { debug_event('archive',"Error: unable to add songs",'3'); return false; } // if failed to add songs - if (!$arc->create_archive()) { + if (!$arc->create_archive()) { debug_event('archive',"Error: unable to create archive",'3'); return false; } // if failed to create archive - $arc->download_file(); + $arc->download_file(); } // send_zip diff --git a/modules/archive/archive.lib.php b/modules/archive/archive.lib.php index c3d7bf64..6842f782 100644 --- a/modules/archive/archive.lib.php +++ b/modules/archive/archive.lib.php @@ -44,8 +44,11 @@ class archive { public function set_options($options) { - foreach ($options as $key => $value) + foreach ($options as $key => $value) { $this->options[$key] = $value; + debug_event("archive.lib.php", "Setting option ".$key."[".$value."]...", "5"); + } + if (!empty ($this->options['basedir'])) { $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']); @@ -92,8 +95,9 @@ class archive { return 0; } } - else + else { $this->archive = ""; + } switch ($this->options['type']) { @@ -139,8 +143,9 @@ class archive { 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['tmpname'] . ".tmp"); + } } return true; @@ -217,34 +222,39 @@ class archive { foreach ($list as $current) { + debug_event("archive.lib.php", "Listing file {".$current."}...", "5"); + $current = str_replace("\\", "/", $current); $current = preg_replace("/\/+/", "/", $current); $current = preg_replace("/\/$/", "", $current); if (substr($current, 0, 1) == "/" ) { $current = "/" . $current; } - if (strstr($current, "*")) - { + if (strstr($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); } - 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), + 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); @@ -256,33 +266,37 @@ class archive { function parse_dir($dirname) { - if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $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 + } + else { $files = array (); + } + $dir = @opendir($dirname); while ($file = @readdir($dir)) { $fullname = $dirname . "/" . $file; - if ($file == "." || $file == "..") + if ($file == "." || $file == "..") { continue; - else if (@is_dir($fullname)) - { + } + else if (@is_dir($fullname)) { if (empty ($this->options['recurse'])) continue; $temp = $this->parse_dir($fullname); foreach ($temp as $file2) $files[] = $file2; } - else if (@file_exists($fullname)) + 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); @@ -313,25 +327,25 @@ class archive { if ($this->options['inmemory'] == 0) { - $full_arc_name = $this->options['basedir']."/".$this->options['tmpname']; + $full_arc_name = $this->options['basedir']."/".$this->options['tmpname']; if (file_exists($full_arc_name)) { - $fsize = filesize($full_arc_name); + $fsize = filesize($full_arc_name); - //Send some headers which can be useful... - $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: " . $fsize); - 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"); + //Send some headers which can be useful... + $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: " . $fsize); + 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"); - readfile($full_arc_name); + readfile($full_arc_name); - //Now delete tempory file - unlink($full_arc_name); - } + //Now delete tempory file + unlink($full_arc_name); + } else { debug_event('ERROR','Archive does not exist, unable to download','1'); return false; @@ -617,14 +631,19 @@ class zip_file extends archive $offset += strlen($temp); unset ($temp); } - else + else { $this->error[] = "Could not open sfx module from {$this->options['sfx']}."; + } $pwd = getcwd(); chdir($this->options['basedir']); foreach ($this->files as $current) { + foreach ($current as $key => $value) { + debug_event("archive.lib.php", "Processing ".$key."[".$value."]...", "5"); + } + if ($current['name'] == $this->options['name']) continue; @@ -683,8 +702,9 @@ class zip_file extends archive $files++; $offset += (30 + strlen($current['name2']) + $size); } - else + else { $this->error[] = "Could not open file {$current['name']} for reading. It was not added."; + } } $this->add_data($central); diff --git a/templates/show_album.inc.php b/templates/show_album.inc.php index 27b64e75..89a38c51 100644 --- a/templates/show_album.inc.php +++ b/templates/show_album.inc.php @@ -99,13 +99,13 @@ if (AmpConfig::get('show_played_times')) {
  • - - + +
  • - - + +