add_file($item, "${ziptheme['theme_name']}/$file"); } // ... just to get its size ... $zipsize=number_format(strlen($zip->archive())/1024,2,'.',','); // ... then free memory $zip->clear(); print_header("Content of Wordpress Theme archive: ${ziptheme['theme_name']}${suffix}.zip",'table'); // No, I will not use PHP_SELF. $script = substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"],'?')); print "

Content of ${ziptheme['theme_name']}${suffix}.zip ($zipsize kb)

\n"; print << Filename Size Modified Path TABLEHEAD; $style='odd'; $totalsize=0; foreach ($zippit as $k=>$v) { $file = substr($zippit[$k],strlen($ziptheme['rootdir'] . '/' . $ziptheme['theme_name'])+1); $path = ''; if (strpos($file,'/')) { $path = substr($file,0,strrpos($file,'/')).'/'; $file = substr($file,strrpos($file,'/')+1); } $size = $infos[$k]['size']; $totalsize += $size; $umodified = max($infos[$k]['mtime'],$infos[$k]['ctime']); $modified = date('Y/m/d H:i:s', $umodified); $style = ($style == 'odd')?'even':'odd'; if ($ziptheme['enable_file_preview']) { $html="$file"; } else { $html="$file"; } print "$html$size$umodified $modified${ziptheme['theme_name']}/$path\n"; } print ''; print '

Zip file contains '.count($zippit) . ' files ('. number_format($totalsize/1024,2,'.',',')." kb uncompressed → $zipsize kb compressed)

\n"; print '

Zip file last modified on ' . date('Y/m/d H:i:s',$lastmod).''; print_footer(); break; // Display file content case 'view' : $viewfile = @$_GET['view']; print_header("Content: $viewfile « Wordpress Theme: ${ziptheme['theme_name']}",'li'); $lastmod = array_pop($zippit); if ($ziptheme['datesuffix']) $suffix = '-' . date($ziptheme['datesuffix'],$lastmod); $script = substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"],'?')); print "

Content of $viewfile from ${ziptheme['theme_name']}${suffix}.zip

\n"; print 'without / with line numbers'; $found = 0; foreach ($zippit as $item) { $file = substr($item,strlen($ziptheme['rootdir'] . '/' . $ziptheme['theme_name'])+1); if ($file == $viewfile) { $found = print_content($item); break; } } if ($found == 1) { print "

Return to listing of ${ziptheme['theme_name']}${suffix}.zip

"; } else { print "

File $viewfile is not part of ${ziptheme['theme_name']}${suffix}.zip !

"; } print_footer(); break; // Create zip archive and send to browser case 'zip' : $lastmod = array_pop($zippit); if ($ziptheme['datesuffix']) $suffix = '-' . date($ziptheme['datesuffix'],$lastmod); foreach ($zippit as $item) { $file = substr($item,strlen($ziptheme['rootdir'] . '/' . $ziptheme['theme_name'])+1); $zip->add_file($item, "${ziptheme['theme_name']}/$file"); } // Incoming Quadded Zipfile ! Secure Browser & Escort Flag Carrier ! header('Content-Type: application/x-zip'); header("Content-Type: application/force-download"); header("Content-Transfer-Encoding: binary"); // >>> Incoming Low <<< $zip->save($ziptheme['theme_name'].$suffix.'.zip','b'); break; } /**************************** That's it folks. ***************************/ // Functions : // Super neato cool function to go through a dir and subdirs found in comments of php.net/readdir // What is very good about it is that this function makes no recursive call to itself -> $speed++ ! // More info here : http://frenchfragfactory.net/ozh/archives/2005/12/22/php-non-recursive-function-through-directories/ function list_directory($dir) { global $ziptheme; if (substr($dir,strlen($dir)-1,1) == '/') $dir = substr($dir,0,strlen($dir)-1); $file_list = array(); $info_list = array(); $lastmod=0; $stack[] = $dir; while ($stack) { $current_dir = array_pop($stack); if ($dh = opendir($current_dir)) { while (($file = readdir($dh)) !== false) { if ($file !== '.' AND $file !== '..') { $current_file = "{$current_dir}/{$file}"; if (is_file($current_file)) { $file_list[] = "{$current_dir}/{$file}"; //if ($ziptheme['datesuffix'] or $ziptheme['action'] == 'list') { clearstatcache(); $infos=stat("{$current_dir}/{$file}"); $lastmod = max($lastmod, $infos['mtime'],$infos['ctime']); // Ok I admit I just don't understand the difference between these 2 from my tests on a Windows and a Linux platform :) if ($ziptheme['action'] == 'list') $info_list[]=$infos; //} } elseif (is_dir($current_file)) { $stack[] = $current_file; } } } } } if ($ziptheme['action'] == 'list') $file_list[] = $info_list; //if ($ziptheme['datesuffix']) $file_list[] = $lastmod; // So, what do we have now ? // An array with all the file (physical path) // + an entry that contains an array of infos about all these files (used to get size etc...) // + an entry that contains date of last modification return $file_list; } // Print headers and some HTML function print_header($name='',$js='') { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma:no-cache"); // HTTP//1.0 print "\n\n$name\n"; switch ($js) { case 'table': print_js_table(); break; case 'li': print_js_li(); break; } print_css(); print "\n\n\n"; } // Print some HTML for footer // If you find this script useful, please don't remove the credit link so that other people // will try it and hopefully find it cool too. This free script is linkware :) function print_footer() { global $ziptheme; print "
\n"; print "\n"; print "\n\n"; } // Print content of file : as text, as image, or as nothing. function print_content($file) { global $ziptheme; $ext = substr($file,strrpos($file,'.')+1); if (in_array($ext,$ziptheme['textfiles'])) { $content = file($file); $style='odd'; print "
    \n"; foreach($content as $line) { $style = ($style == 'odd')?'even':'odd'; print "
  1. "; highlight_string($line); print "
  2. \n"; } print " 
\n"; } elseif (in_array($ext,$ziptheme['imagefiles'])) { $file = substr($file,strlen($ziptheme['rootdir'] . '/' . $ziptheme['theme_name'])+1); print "

$file

"; } else { print "

Cannot display file content in your web browser

\n"; } return 1; } // Print tiny Javascript code to switch from
    to