1<?php 2/** 3 * DokuWiki Plugin gtime (Renderer Component) 4 * 5 * @license Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 6 * @author Michael Kirchner <michael.kirchner@uni-due.de> 7 */ 8/* 9 * Copyright (C) Michael Kirchner <michael.kirchner@uni-due.de> 10 * 11 * This file is part of the GuardTime dokuwiki plugin. 12 * 13 * Licensed under the Apache License, Version 2.0 (the "License"); 14 * you may not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * 19 * Unless required by applicable law or agreed to in writing, software 20 * distributed under the License is distributed on an "AS IS" BASIS, 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the License for the specific language governing permissions and 23 * limitations under the License. 24 */ 25 26 27// must be run within Dokuwiki 28if (!defined('DOKU_INC')) die(); 29 30if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 31if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 32require_once DOKU_INC.'inc/parser/renderer.php'; 33require_once(DOKU_INC.'inc/pluginutils.php'); 34 35class renderer_plugin_gtime extends Doku_Renderer { 36 37 /** 38 * The format this renderer produces 39 */ 40 public function getFormat(){ 41 return 'gtime'; 42 } 43 44 45 /** 46 * This function exports page and timestamp and makes it available as ZIP download. 47 * 48 * @return void 49 */ 50 function document_start() { 51 global $ID; 52 global $INFO; 53 global $conf; 54 global $ACT; 55 global $lang; 56 57 $this->setupLocale(); 58 59 // Hoping to get at the caching problem 60 $this->info['cache'] = false; 61 p_set_metadata($ID, array('cache' => 'expire'), false, false); 62 63 64 65 $pagefile = $INFO['filepath']; 66 $filerev = basename($INFO['filepath']); 67 68$GT_README= <<<EOT 69{$this->getLang('README')} 70gtime -xv -f {$filerev} -i {$filerev}.gtts 71 72EOT; 73 74 75 76 $filename = "GuardTime_Timestamp_Attic_{$filerev}.zip"; 77 $filetemp = tempnam(DOKU_INC.'data/tmp/', "GUARDTIME"); 78 79 $zip = new ZipArchive(); 80 81 $result = $zip->open($filetemp, ZipArchive::CREATE); 82 83 if ($result !== true) { 84 die("Unable to create zip file: {$filetemp}, error code: {$result}"); 85 } 86 87 $zip->addFile($pagefile,$filerev); 88 $zip->addFile($pagefile.".gtts",$filerev.".gtts"); 89 $zip->addfromString("README.txt",$GT_README); 90 $zip->close(); 91 92 $fp = fopen($filetemp, 'r'); 93 94 if (!$fp) { 95 die("Unable to open ZIP file: {$filetemp}"); 96 } 97 98 header("Content-Type: archive/zip"); 99 header("Content-Disposition: attachment; filename={$filename}"); 100 101 $headers = array( 102 'Content-Type' => 'archive/zip', 103 'Content-Disposition' => "attachment; filename={$filename}.zip" 104 ); 105 p_set_metadata($ID,array('format' => array('zip' => $headers) )); 106 107 fpassthru($fp); 108 fclose($fp); 109 unlink($filetemp); 110 111 } 112} 113 114// vim:ts=4:sw=4:et: 115