Changeset 27507
- Timestamp:
- 2013-05-29T12:47:32+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentation/trunk/php/gs-manual-export.php
r25026 r27507 19 19 20 20 // 0. Initialization 21 $xml_source_path = '/research/jmt12/gsdl-docs/temp'; 21 22 22 // - we have a counter to assign identifiers to text blocks etc without ids 23 23 $text_id_counter = 1; … … 44 44 { 45 45 $_REQUEST['a'] = 'store'; // Try to store the file to disk 46 } 47 48 $var_path = filecat(array($base_path, 'var')); 49 $timestamp = time(); 50 //$xml_source_path = '**PATH TO GSDL MANUALS**' 51 $xml_source_path = '/tmp'; 52 if ($_REQUEST['a'] == 'download') 53 { 54 // Clear out previous exports 55 recursiveRemove($var_path, '/greenstone/greenstone-documentation/php/var'); 56 // New export 57 $xml_source_path = fileCat(array($var_path, $timestamp)); 46 58 } 47 59 … … 66 78 echo '<p><b>Manual:</b> ' . $_REQUEST['m'] . ' <b>Language:</b> ' . $_REQUEST['l'] . "</p>\n<hr/>\n"; 67 79 // 1. Create the XML output file handle 68 $xml_file_path = ''; 69 if ($_REQUEST['a'] == 'download') 70 { 71 $xml_file_path = fileCat(array($base_path, 'var', ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml')); 72 } 73 else 74 { 75 // - construct the path using the information we've been provided as arguments 76 $xml_file_dir = $xml_source_path . '/' . $_REQUEST['l']; 77 mkAllDir($xml_file_dir, 0755); 78 $xml_file_path = $xml_file_dir . '/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml'; 79 // - backup any existing file 80 if (file_exists($xml_file_path)) 81 { 82 $xml_backup_file_path = $xml_file_path . '.bak'; 83 if (!rename($xml_file_path, $xml_backup_file_path)) 84 { 85 printError('Failed to rename existing manual file for backup'); 86 } 87 } 88 } 80 // - construct the path using the information we've been provided as arguments 81 $xml_file_dir = $xml_source_path . '/' . $_REQUEST['l']; 82 mkAllDir($xml_file_dir); 83 $xml_file_path = $xml_file_dir . '/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml'; 84 // - backup any existing file 85 if (file_exists($xml_file_path)) 86 { 87 $xml_backup_file_path = $xml_file_path . '.bak'; 88 if (!rename($xml_file_path, $xml_backup_file_path)) 89 { 90 printError('Failed to rename existing manual file for backup'); 91 } 92 } 93 89 94 // - and create a handle to the new file 90 95 $xml_out = fopen($xml_file_path, 'w'); … … 226 231 fwrite($xml_out, '</Manual>' . "\n"); 227 232 fclose($xml_out); 233 chmod($xml_file_path, 0664); 228 234 229 235 // 6. Complete! … … 231 237 if ($_REQUEST['a'] == 'download') 232 238 { 233 echo '<p>Click <a href="var/' . ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.xml">here</a> to download XML file</p>' . "\n"; 239 // Zip up the manual files 240 $zip_file = ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.zip'; 241 $zip_path = fileCat(array($xml_source_path, $zip_file)); 242 $zip_command = 'zip -r "' . $zip_path . '" . > /dev/null 2>&1'; 243 //cho '<p><b>[DEBUG]</b> zip_command:' . $zip_command . '</p>'; 244 $tgz_file = ucfirst($_REQUEST['m']) . '_' . $_REQUEST['l'] . '.tgz'; 245 $tgz_path = fileCat(array($xml_source_path, $tgz_file)); 246 $tgz_command = 'tar -czf "' . $tgz_path . '" * > /dev/null 2>&1'; 247 //cho '<p><b>[DEBUG]</b> tgz_command:' . $tgz_command . '</p>'; 248 // We need to move to the document folder so that archives have sensible paths 249 $original_cwd = getcwd(); 250 chdir($xml_file_dir); 251 system($zip_command); 252 system($tgz_command); 253 // Go back 254 chdir($original_cwd); 255 // Links are ready 256 echo '<p>Download XML file plus images as: <a href="var/' . $timestamp . '/' . $zip_file . '">ZIP</a> or <a href="var/' . $timestamp . '/' . $tgz_file . '">TGZ</a></p>' . "\n"; 234 257 } 235 258 echo '<p>Click <a href="' . $dokuwiki_url . '/doku.php?id=' . $_REQUEST['l'] . ':manuals:' . $_REQUEST['m'] . '">here</a> to return to dokuwiki</p>' . "\n"; … … 1205 1228 $image_source_path = $dokuwiki_path . '/data/media/' . $_REQUEST['l'] . '/manuals/images/' . strtolower($filename); 1206 1229 $image_destination_dir = $xml_source_path . '/' . $_REQUEST['l'] . '/images'; 1207 mkAllDir($image_destination_dir , 0755);1230 mkAllDir($image_destination_dir); 1208 1231 $image_destination_path = $image_destination_dir . '/' . $filename; 1209 1232 if (copy($image_source_path, $image_destination_path)) 1210 1233 { 1211 1234 echo '[copying file: ' . $filename . "] \n"; 1235 chmod($image_destination_path, 0664); 1212 1236 } 1213 1237 else
Note:
See TracChangeset
for help on using the changeset viewer.