Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
please do something with it...
I’ve tried to make a plugin that make’s your site static and then you can download it in zip format or upload it to a server with ftp for servers without php/mysql shit…
But no time more for that but i’ve started with copiing some code from other sites that might be useful for u…
it’s a mess, but yeah what the hack…
code:
// ——————————————————————————
// Class definition found at http://www.zend.com/zend/spotlight/creating-zip-files3.php
// Some alterations to the original posted code were made in order to get everything working properly
class zipfile
{
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = “\x50\x4b\x05\x06\x00\x00\x00\x00”;
var $old_offset = 0;
function add_dir($name) { $fr = “\x50\x4b\x03\x04”; $fr .= “\x0a\x00”; $fr .= “\x00\x00”; $fr .= “\x00\x00”; $fr .= “\x00\x00\x00\x00”;
$fr .= pack(“V”,0); $fr .= pack(“V”,0); $fr .= pack(“V”,0); $fr .= pack(“v”, strlen($name) ); $fr .= pack(“v”, 0 ); $fr .= $name; $fr .= pack(“V”, 0); $fr .= pack(“V”, 0); $fr .= pack(“V”, 0);
$this -> datasec[] = $fr; $new_offset = strlen(implode(“”, $this->datasec));
$cdrec = “\x50\x4b\x01\x02”; $cdrec .=”\x00\x00”; $cdrec .=”\x0a\x00”; $cdrec .=”\x00\x00”; $cdrec .=”\x00\x00”; $cdrec .=”\x00\x00\x00\x00”; $cdrec .= pack(“V”,0); $cdrec .= pack(“V”,0); $cdrec .= pack(“V”,0); $cdrec .= pack(“v”, strlen($name) ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“v”, 0 );
$ext = “\x00\x00\x10\x00”; $ext = “\xff\xff\xff\xff”;
$cdrec .= pack(“V”, 16 ); $cdrec .= pack(“V”, $this -> old_offset ); $cdrec .= $name;
$this -> ctrl_dir[] = $cdrec; $this -> old_offset = $new_offset; return; }
function add_file($data, $name) { $fp = fopen($data,“r”); $data = fread($fp,filesize($data)); fclose($fp); $name = str_replace(“\\”, “/”, $name); $unc_len = strlen($data); $crc = crc32($data); $zdata = gzcompress($data); $zdata = substr ($zdata, 2, -4); $c_len = strlen($zdata); $fr = “\x50\x4b\x03\x04”; $fr .= “\x14\x00”; $fr .= “\x00\x00”; $fr .= “\x08\x00”; $fr .= “\x00\x00\x00\x00”; $fr .= pack(“V”,$crc); $fr .= pack(“V”,$c_len); $fr .= pack(“V”,$unc_len); $fr .= pack(“v”, strlen($name) ); $fr .= pack(“v”, 0 ); $fr .= $name; $fr .= $zdata; $fr .= pack(“V”,$crc); $fr .= pack(“V”,$c_len); $fr .= pack(“V”,$unc_len);
$this -> datasec[] = $fr; $new_offset = strlen(implode(“”, $this->datasec));
$cdrec = “\x50\x4b\x01\x02”; $cdrec .=”\x00\x00”; $cdrec .=”\x14\x00”; $cdrec .=”\x00\x00”; $cdrec .=”\x08\x00”; $cdrec .=”\x00\x00\x00\x00”; $cdrec .= pack(“V”,$crc); $cdrec .= pack(“V”,$c_len); $cdrec .= pack(“V”,$unc_len); $cdrec .= pack(“v”, strlen($name) ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“v”, 0 ); $cdrec .= pack(“V”, 32 ); $cdrec .= pack(“V”, $this -> old_offset );
$this -> old_offset = $new_offset;
$cdrec .= $name; $this -> ctrl_dir[] = $cdrec; }
function file() { $data = implode(“”, $this -> datasec); $ctrldir = implode(“”, $this -> ctrl_dir);
return
$data .
$ctrldir .
$this -> eof_ctrl_dir .
pack(“v”, sizeof($this -> ctrl_dir)) .
pack(“v”, sizeof($this -> ctrl_dir)) .
pack(“V”, strlen($ctrldir)) .
pack(“V”, strlen($data)) .
“\x00\x00”;
}
}
// ——————————————————————————
// function for making the zip file
function create_zip_file_tmp(){
$oZipfile = new zipfile();
$oZipfile->add_dir(‘sql/’);
exec(‘mysqldump —opt ‘ . $sDatabase . ‘ —user=’ . $sUsername . ‘ —password=’ . $sPassword . ‘ > ‘. $sDocumentRoot . ‘backup/backup.sql’); // controleer of de dump gelukt is if (file_exists($sDocumentRoot . ‘backup/backup.sql’)){ $oZipfile->add_file($sDocumentRoot . ‘backup/backup.sql’, ‘sql/backup.sql’); unlink($sDocumentRoot . ‘backup/backup.sql’); }
foreach ($aBackupFolders as $sFolder){
$oZipfile->add_dir($sFolder); // haal alle bestanden op uit de map: if ($handle = opendir($sDocumentRoot . $sFolder)) { while (false !== ($sFile = readdir($handle))) { if ($sFile != ‘.’ && $sFile != ‘..’) { // voeg bestand toe aan zip $oZipfile->add_file($sDocumentRoot . $sFolder . $sFile, $sFolder . $sFile); } } closedir($handle); } }
$fp = fopen ($sDocumentRoot . ‘backup/’ . $sBackupFileName, ‘wb’);
$out = fwrite ($fp, $oZipfile->file());
fclose ($fp);
}
// ——————————————————————————
// admin side plugin
// Add a new tab to the Content area. // “test” is the name of the associated event; “testing” is the displayed title if (@txpinterface == ‘admin’) {
$myevent = ‘static’; $mytab = ‘static’;
// Set the privilege levels for our new event add_privs($myevent, ’1,2’);
// Add a new tab under ‘extensions’ associated with our event register_tab(“extensions”, $myevent, $mytab); // ‘zem_admin_test’ will be called to handle the new event register_callback(“ptb_test_case”, $myevent); } function ptb_test_case($event, $step) { pagetop(“Testing”);
echo “<div>”; echo tag(“Vars”, “p”); echo “</div>”;
ptb_generate_html_page(); $rs = safe_rows_start( “*, unix_timestamp(Posted) as uPosted”, “textpattern”,“Status=4”);
if ($rs) {
while ($a = nextRow($rs)) {
extract($a);
echo $ID.’-’.$Title.br.n;
ptb_generate_html_page($ID);
}
}
create_zip_file();
}
function ptb_generate_html_page($id=‘0’){ $cache_folder = “/home/pietertj/public_html/hsstl/static/”; $cache_file = “page_”.$id.”.html”; $maker_URL = “http://www.pietertje.nl/hsstl/index.php?id=”.$id;
if($id==‘0’){ $cache_file = “index.html”; $maker_URL = “http://www.pietertje.nl/hsstl/index.php”; }
$read = fopen ( $maker_URL , “r” ); if ( !$read ) { echo ( “Could not open $maker_URL” ); exit; }
$HTML_output = “”;
// read the HTML output while displaying it
while ($line = fgets ( $read , 256 )) { $HTML_output.= $line; //echo $line; } fclose ( $read );
$write = fopen ( $cache_folder . $cache_file , “w” );
if ( !$write ) {
echo ( “could not open $writefile for writing” ); exit; }
// lock the write file and // write all the HTML into it
if ( !flock ( $write , LOCK_EX + LOCK_NB )) { echo ( “could not lock $writefile” ); exit; }
fwrite ( $write , $HTML_output , strlen ( $HTML_output ) );
flock ( $write , LOCK_UN );
fclose ( $write );
}
// ——————————————————————————
// function for making the zip file
function create_zip_file(){
// The eInput/sInput part of the form is important, setting the event and step respectively // root path naar de mappen die je wilt backuppen $sDocumentRoot = ‘/home/pietertj/public_html/hsstl/’;
// zet de mappen die gebackupped moeten worden in deze array
$aBackupFolders = array();
$aBackupFolders[] = ‘textpattern/’;
$aBackupFolders[] = ‘textpattern/dev/’;
$aBackupFolders2 = array();
$tmpBackupFolders = recur_dir($sDocumentRoot);
// de bestandsnaam van de backup: $sBackupFileName = ‘backup_’ . date(‘dmY’) . ‘.zip’; // deze bestandsnaam is zeker niet uniek. Verzin iets anders als je een unieke naam wilt
$oZipfile = new zipfile(); $oZipfile->add_dir(‘sql/’);
foreach ($aBackupFolders as $sFolder){ $oZipfile->add_dir($sFolder); // haal alle bestanden op uit de map: if ($handle = opendir($sDocumentRoot . $sFolder)) { while (false !== ($sFile = readdir($handle))) { if ($sFile != ‘.’ && $sFile != ‘..’ && !is_dir($sDocumentRoot . $sFolder . $sFile)) { // voeg bestand toe aan zip $oZipfile->add_file($sDocumentRoot . $sFolder . $sFile, $sFolder . $sFile); } } closedir($handle); } }
$fp = fopen ($sDocumentRoot . ‘static/’ . $sBackupFileName, ‘wb’);
$out = fwrite ($fp, $oZipfile->file());
fclose ($fp);
}
function recur_dir($dir)
{
global $aBackupFolders2;
$mod_array = array();
$dirlist = opendir($dir);
while ($file = readdir ($dirlist))
{
if ($file != ‘.’ && $file != ‘..’)
{
$newpath = $dir.’/’.$file;
$level = explode(‘/’,$newpath);
if (is_dir($newpath))
{
$aBackupFolders2[] = $newpath;
$mod_array[] = array(
‘level’=>count($level)-1,
‘path’=>$newpath,
‘name’=>end($level),
‘kind’=>‘dir’,
‘mod_time’=>filemtime($newpath),
‘content’=>recur_dir($newpath));
}
}
}
closedir($dirlist);
return $mod_array;
}
function ptb_site_static($event, $step) { // ps() returns the contents of POST vars, if any $something = ps(“something”); $something2 = ps(“something2”); $something3 = ps(“something3”);
// The eInput/sInput part of the form is important, setting the event and step respectively // root path naar de mappen die je wilt backuppen $sDocumentRoot = ‘/home/pietertj/public_html/backup/’;
// zet de mappen die gebackupped moeten worden in deze array $aBackupFolders = array(); $aBackupFolders[] = ‘afbeeldingen/’; $aBackupFolders[] = ‘uploads/’; $aBackupFolders[] = ‘docs/’;
// de bestandsnaam van de backup: $sBackupFileName = ‘backup_’ . date(‘dmY’) . ‘.zip’; // deze bestandsnaam is zeker niet uniek. Verzin iets anders als je een unieke naam wilt
/*
choose temp url handle rule, replace existing, put back after finishing
generate pages by following urls or by calling id’s from database, i prefer last option
*/
pagetop(“Testing”, (ps(“do_something”) ? “you typed: $something” : “”));
echo “<div align=\“center\” style=\“margin-top:3em\”>”; echo form( tag(“Vars”, “h3”). graf(“backup dir”. fInput(“text”, “something3”, $something3, “edit”, “”, “”, “20”, “1”).br. “filename”. fInput(“text”, “something3”, $something3, “edit”, “”, “”, “20”, “1”).br. fInput(“submit”, “do_something”, “Go”, “smallerbox”). eInput(“static”).sInput(“step_a”) ,” style=\”\”“) ); echo “</div>”; }
Offline
#2 2005-10-17 12:21:27
- Anark
- Member
- Registered: 2004-08-14
- Posts: 101
Re: please do something with it...
Unix boxes, including Macs, come with a command-line utility called wget that lets you easily mirror whole sites, no matter if they’re dynamically generated — wget will fetch the directories and the flat files right to your doorstep.
Windows versions seem to be available too.
Offline
Re: please do something with it...
is there somewhere a tutorial on that?
Offline
Pages: 1