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 "
\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 "
\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 "- ";
highlight_string($line);
print "
\n";
}
print "
\n";
} elseif (in_array($ext,$ziptheme['imagefiles'])) {
$file = substr($file,strlen($ziptheme['rootdir'] . '/' . $ziptheme['theme_name'])+1);
print "
";
} else {
print "Cannot display file content in your web browser
\n";
}
return 1;
}
// Print tiny Javascript code to switch from to when
// viewing a file content
function print_js_li() {
print <<//
JSLI;
}
// Print Javascript code to make table sortable
// Can't remember where I got this from. Probably from
// http://www.brainjar.com/dhtml/tablesort/demo.html but I'm not sure.
// Pretty cool anyway :)
function print_js_table() {
print <<// 0) {
minIdx = j;
minVal = testVal;
}
}
// By now, we have the row with the smallest value. Remove it from the
// table and insert it before the current row.
if (minIdx > i) {
tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
tblEl.insertBefore(tmpEl, tblEl.rows[i]);
}
}
// Restore the table's display style.
tblEl.style.display = oldDsply;
// Make it look pretty.
makePretty(tblEl, col);
return false;
}
//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------
// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null) {
document.ELEMENT_NODE = 1;
document.TEXT_NODE = 3;
}
function getTextValue(el) {
var i;
var s;
// Find and concatenate the values of all text nodes contained within the
// element.
s = "";
for (i = 0; i < el.childNodes.length; i++)
if (el.childNodes[i].nodeType == document.TEXT_NODE)
s += el.childNodes[i].nodeValue;
else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
el.childNodes[i].tagName == "BR")
s += " ";
else
// Use recursion to get text within sub-elements.
s += getTextValue(el.childNodes[i]);
return normalizeString(s);
}
function compareValues(v1, v2) {
var f1, f2;
// If the values are numeric, convert them to floats.
f1 = parseFloat(v1);
f2 = parseFloat(v2);
if (!isNaN(f1) && !isNaN(f2)) {
v1 = f1;
v2 = f2;
}
// Compare the two values.
if (v1 == v2)
return 0;
if (v1 > v2)
return 1
return -1;
}
// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\s*|\s*$", "g");
var whtSpMult = new RegExp("\s\s+", "g");
function normalizeString(s) {
s = s.replace(whtSpMult, " "); // Collapse any multiple whites space.
s = s.replace(whtSpEnds, ""); // Remove leading or trailing white space.
return s;
}
// Style class names.
var rowClsNm = "odd";
var colClsNm = "sorted";
// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");
function makePretty(tblEl, col) {
var i, j;
var rowEl, cellEl;
// Set style classes on each row to alternate their appearance.
for (i = 0; i < tblEl.rows.length; i++) {
rowEl = tblEl.rows[i];
rowEl.className = rowEl.className.replace(rowTest, "");
if (i % 2 != 0)
rowEl.className += " " + rowClsNm;
rowEl.className = normalizeString(rowEl.className);
// Set style classes on each column (other than the name column) to
// highlight the one that was sorted.
for (j = 0; j < tblEl.rows[i].cells.length; j++) {
cellEl = rowEl.cells[j];
cellEl.className = cellEl.className.replace(colTest, "");
if (j == col)
cellEl.className += " " + colClsNm;
cellEl.className = normalizeString(cellEl.className);
}
}
// Find the table header and highlight the column that was sorted.
var el = tblEl.parentNode.tHead;
rowEl = el.rows[el.rows.length - 1];
// Set style classes for each column as above.
for (i = 0; i < rowEl.cells.length; i++) {
cellEl = rowEl.cells[i];
cellEl.className = cellEl.className.replace(colTest, "");
// Highlight the header of the sorted column.
if (i == col)
cellEl.className += " " + colClsNm;
cellEl.className = normalizeString(cellEl.className);
}
}
//]]>
JS;
}
// Print some CSS style. Customize this to suit your needs and likes.
function print_css() {
print <<
td,th,body,table,h1 {
whitespace: pre;
font-family:monospace;
font-size:1em;
}
hr {
margin-top:1.5em;
color: #ccc;
background-color: #bbf;
height: 2px;
}
#footer {
margin:0;
font-size:75%;
}
#blog {
float:left;
}
#ozh {
float:right;
}
a, a:visited {
color:#009;
}
a:hover,a:active {
color:#0055ff;
}
tr td a {
text-decoration:none;
}
tr td a:hover {
text-decoration:underline;
}
#zipfile th {
text-align:center;
background-color: #eee;
}
#zipfile td {
padding: 0 1em;
}
td .sorted {
display:none;
color:#088;
font-weight:bold;
}
#zipfile tr.odd, #zipfile tr.odd td.sorted, #zipfile tr th {
background-color: #eee;
margin:20px;
}
.odd {
background-color: #eee;
}
#zipfile tr:hover, #zipfile td:hover {
background: #bbf;
}
#ol2ul {float:right;font-size:75%;background: #eee}
#filecontent {clear:right;}
CSS;
}
?>