Source for file generate_offline.php
Documentation is available at generate_offline.php
* Command line offline page generation script.
* This is a command line script which generates day and week files for offline
* This file is part of HRDIODB.
* HRDIODB is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* HRDIODB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with HRDIODB; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** Configuration file */
require_once("conf.php");
/** HRDI database class */
require_once("hrdi_db_class.php");
require_once("download_class.php");
// Make sure the script doesn't time out
// HRDI database class instance
// Get a list of all UARS days
$days = $hdb->get_column($sql);
// Do a very simple check to see if week files already exist
if (is_file("$offline_prefix/week_0.html")) {
print "Error! Please delete all week HTML files first\n";
print "There are ". count($days). " days to process\n";
// Try to create the offline directory if it doesn't already exist
if (!is_dir($offline_prefix)) {
print "Trying to make the directory $offline_prefix... ";
// This will fail if the process doesn't have the right permissions
if (@mkdir($offline_prefix)) {
print "error!\nPlease create $offline_prefix by hand and run this script again\n";
// For each day, create the offline day file and the week file for the day
foreach ($days as $day) {
print "Generating day $day\n";
/* Run the day script in offline mode. Redirect output to a file called
day_X.html, where X is the UARS day number. */
exec("php day.php $day > $offline_prefix/day_$day.html");
// Figure out the week number that the UARS day is a part of
$week = floor(($day + 3) / 7);
/* If the week file already exists, don't create it. This is just a simple
way to try and increase the speed of this whole process */
if (!is_file("$offline_prefix/week_$week.html")) {
print "Generating week ". ($week + 1). "\n";
/* Run the week script in offline mode. Redirect the output to a file
called week_X.html, where X is the week number. */
exec("php week.php $day > $offline_prefix/week_$week.html");
// Generate an index page
<head><meta http-equiv=\"refresh\" content=\"1;url=week_$week.html\"></head>
If the page doesn't refresh, click <a href=\"week_$week.html\">here</a>.
print "Generating index page... ";
$fp = fopen("$offline_prefix/index.html", 'w');
// Array of extra files we need for offline mode
$extra = array("hrdi.css", "print.css", "hrdi.js");
print "Copying CSS and JavaScript files... ";
// Try to copy each extra file to the offline directory
if (!copy($e, "$offline_prefix/$e")) {
print "error!\nPlease copy $e to $offline_prefix\n";
print "Copying domTT directory... ";
// Lastly, try to copy the DOM Tooltip JavaScript library to the offline directory
system("cp -R domTT $offline_prefix", $status);
print "error!\nPlease copy the domTT directory to $offline_prefix\n";
|