As you probably know, PAD files are XML documents describing a shareware or freeware application (PAD stands for Portable Application Descrition). PAD files are great for sharing information about a software tool. You can create a PAD file easily using the freeware tool PADGen.
The annoying thing about PAD files is that the PAD format is constantly being updated and modified. It's a little tiresome to have to update all your PAD files with PADGen every time this happens.
Therefore I created this PHP script that generates dynamic PAD files based on a template. The template is simply an updated PAD file. Now, whenever the PAD file format changes, simply replace the template file with a new-fangled PAD file and everthing else will automatically be up-to-date. It doesn't matter if you have 500 applications! Cool eh?
Hint: Although not required, it's best if you keep your applications together in one folder and use a naming convention for associated graphics etc. For example, my applications are in the "apps" folder of this site. All screenshots are /apps/{appname]_sshot.gif, all icons are /apps/{appname}_icon.gif and all PAD files are /apps/{appname}_pad.xml.
Download the PAD-Script zipped folder. In it you will find three files, place them in the folder where you keep your applications and PAD files. They are:
pad-script.php the PAD generator script
pad-template.xml sample 2.01 PAD file (replace this with any PAD file of your own)
sample_pad.php sample PAD file -- make one for each application Replace the contents of pad-template.xml file with one of your existing PAD files. Now rename sample_pad.php to the desired name of your first dynamic PAD file (such as justzipit_pad.xml). Open it in a text editor and modify the first lines to use your URL and your application folder path.
That's it! Here's the PAD-Script Code so you can see what it's doing:
<?php class pad {
function pad($appName, $filePath, $version, $releaseDate, $fields, $template){
$pad = $template;
// replace initial fields
pad::replaceFields($fields, $pad);
// automatic replacements
$fields[Program_Name] = $appName;
$fields[Program_Version] = $version;
$fields[Program_Release_Month] = date("m", $releaseDate);
$fields[Program_Release_Day] = date("d", $releaseDate);
$fields[Program_Release_Year] = date("Y", $releaseDate);
pad::replaceFields($fields, $pad);
// current filesize
$appSize = fileSize($filePath);
$fields[File_Size_Bytes] = $appSize;
$fields[File_Size_K] = $appSize/1024;
$fields[File_Size_MB] = number_format($appSize/1024/1024, 2, '.', '');
pad::replaceFields($fields, $pad);
// output result and exit
header("content-type: text/xml");
echo($pad);
exit;
}
function replaceFields(&$fields, &$pad){
foreach($fields as $name=>$val) pad::replaceField($name, $val, $pad);
$fields = "";
}
function replaceField($fieldName, $value, &$pad){
$search = "/<{$fieldName}>.*<\/{$fieldName}>/i";
$replace = "<{$fieldName}>{$value}</{$fieldName}>";
$pad = preg_replace($search, $replace, $pad);
}
}
?>
From now on, each of your PAD files will be PHP files like this:
<?php
include_once("pad-script.php");
$template = file_get_contents("pad-template.xml");
$title = "Sample";
$url = "http://free-backup.info/";
$name = strtolower($title);
$app = "{$name}.exe";
$appFolderURL = "{$url}apps/";
// Just modify these two lines whenever you update the app
$version = 130;
$releaseDate = strtotime("20 Jan 2006");
// if your apps use a consistent naming convention,
// these can be assigned automatically
// --------------------------------------------------------
$fields[Application_Info_URL] = "{$url}{$name}.html";
$fields[Application_Order_URL] = "{$url}{$name}.html";
$fields[Application_Screenshot_URL] = "{$appFolderURL}{$name}_sshot.gif";
$fields[Application_Icon_URL] = "{$appFolderURL}{$name}_icon.gif";
$fields[Application_XML_File_URL] = "{$appFolderURL}{$name}_pad.xml";
$fields[Primary_Download_URL] = "{$appFolderURL}{$app}";
//
$fields[Filename_Versioned] = $app;
$fields[Filename_Previous] = $app;
$fields[Filename_Generic] = $app;
$fields[Filename_Long] = $app;
// --------------------------------------------------------
// these ones need to be assigned manually,
// add any others you want to modify here
// (version and date fields are set automatically)
// --------------------------------------------------------
$fields[Program_Categories] = "";
$fields[Program_Specific_Category] = "";
$fields[Program_Category_Class] = "";
$fields[Program_Categories] = "";
$fields[Keywords] = "";
$fields[Char_Desc_45] = "";
$fields[Char_Desc_80] = "";
$fields[Char_Desc_250] = "";
$fields[Char_Desc_450] = "";
$fields[Char_Desc_2000] = "";
// --------------------------------------------------------
new pad($title, $app, $version, $releaseDate, $fields, $template);
?>
Notice how easy it is to make custom dynamic changes to the resulting PAD file. Simply add a value to the "$fields" array to change any PAD field.
If you're running on Apache (you probably are if you're using PHP) then you can take this one step further and use the .xml extension for your new PHP PAD files! Just create an file named .htaccess in your apps folder and add this line:
AddType application/x-httpd-php .xml
Then use the .xml extension on your PAD files (even though they contain PHP code). The XML files will be processed through the PHP engine! Notice that this page you are viewing has a .html extension? It's also PHP -- same trick!
Also, check out our roundup of free backup software.
Or, if it's too late for backup and your data is gone, (sorry!), you might want to check out our roundup of free data recovery software.
© 2005 - 2008 copyright free-backup.info ~ contact us