HRDIODB
[ class tree: HRDIODB ] [ index: HRDIODB ] [ all elements ]

Source for file generate_offline.php

Documentation is available at generate_offline.php

  1. <?php
  2. /**
  3.  * Command line offline page generation script.
  4.  * This is a command line script which generates day and week files for offline
  5.  * browsing.
  6.  * @package HRDIODB
  7.  */
  8.  
  9. /**
  10.  * This file is part of HRDIODB.
  11.  *
  12.  * HRDIODB is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * HRDIODB is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with HRDIODB; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25.  */
  26.  
  27. /** Configuration file */
  28. require_once("conf.php");
  29. /** HRDI database class */
  30. require_once("hrdi_db_class.php");
  31. /** Download class */
  32. require_once("download_class.php");
  33.  
  34. // Make sure the script doesn't time out
  35.  
  36. // HRDI database class instance
  37. $hdb new hrdi_db ($dsn);
  38.  
  39. // Get a list of all UARS days
  40. $sql "SELECT UARS_Day
  41.         FROM HRDI_Days
  42.         ORDER BY UARS_Day";
  43.  
  44. $days $hdb->get_column($sql);
  45.  
  46. // Do a very simple check to see if week files already exist
  47. if (is_file("$offline_prefix/week_0.html")) {
  48.   print "Error! Please delete all week HTML files first\n";
  49.   exit(0);
  50. }
  51.  
  52. print "There are ".count($days)." days to process\n";
  53.  
  54. // Try to create the offline directory if it doesn't already exist
  55. if (!is_dir($offline_prefix)) {
  56.   print "Trying to make the directory $offline_prefix... ";
  57.  
  58.   // This will fail if the process doesn't have the right permissions
  59.     if (@mkdir($offline_prefix)) {
  60.     print "done\n";
  61.   else {
  62.     print "error!\nPlease create $offline_prefix by hand and run this script again\n";
  63.     exit(0);
  64.   }
  65. }
  66.  
  67. // For each day, create the offline day file and the week file for the day
  68. foreach ($days as $day{
  69.   print "Generating day $day\n";
  70.  
  71.   /* Run the day script in offline mode. Redirect output to a file called
  72.      day_X.html, where X is the UARS day number. */ 
  73.   exec("php day.php $day > $offline_prefix/day_$day.html");
  74.               
  75.   // Figure out the week number that the UARS day is a part of
  76.     $week floor(($day 37);
  77.  
  78.   /* If the week file already exists, don't create it. This is just a simple
  79.      way to try and increase the speed of this whole process */
  80.   if (!is_file("$offline_prefix/week_$week.html")) {
  81.     print "Generating week ".($week 1)."\n";
  82.  
  83.     /* Run the week script in offline mode. Redirect the output to a file
  84.        called week_X.html, where X is the week number. */
  85.     exec("php week.php $day > $offline_prefix/week_$week.html");
  86.   }
  87. }
  88.  
  89. // Generate an index page
  90. $index "<html>
  91.             <head><meta http-equiv=\"refresh\" content=\"1;url=week_$week.html\"></head>
  92.             <body>
  93.               If the page doesn't refreshclick <a href=\"week_$week.html\">here</a>.
  94.             </body>
  95.           <html>";
  96.  
  97. print "Generating index page... ";
  98.  
  99. $fp fopen("$offline_prefix/index.html"'w');
  100. fwrite($fp$index);
  101. fclose($fp);
  102.  
  103. print "done.\n";
  104.  
  105. // Array of extra files we need for offline mode
  106. $extra array("hrdi.css""print.css""hrdi.js");
  107.  
  108. print "Copying CSS and JavaScript files... ";
  109.  
  110. // Try to copy each extra file to the offline directory
  111. foreach ($extra as $e{
  112.   if (!copy($e"$offline_prefix/$e")) {
  113.     print "error!\nPlease copy $e to $offline_prefix\n";
  114.   }
  115. }
  116.  
  117. print "done.\n";
  118.  
  119. print "Copying domTT directory... ";
  120.  
  121. // Lastly, try to copy the DOM Tooltip JavaScript library to the offline directory
  122. system("cp -R domTT $offline_prefix"$status);
  123.  
  124. if ($status{
  125.   print "error!\nPlease copy the domTT directory to $offline_prefix\n";
  126. else {
  127.   print "done\n";
  128. }
  129.  
  130. print "All finished!\n";
  131. ?>

Documentation generated on Tue, 23 Jan 2007 22:57:48 -0500 by phpDocumentor 1.3.0RC6