ryxeo-glpi-git / htdocs / epack / lib / tests / simplecheck.php @ 1c14bcc4
Historique | Voir | Annoter | Télécharger (3,5 ko)
1 | 1c14bcc4 | Eric Seigne | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * Simple Check file : checking your system about php-zip module
|
||
4 | * The output file checkresult.odt must be readable by an oasis document application as openoffice.org
|
||
5 | * You need PHP 5.2 at least
|
||
6 | * You need Zip Xml Extensions (or PclZip library instead if Zip extension)
|
||
7 | * Encoding : ISO-8859-1
|
||
8 | *
|
||
9 | * @copyright GPL License 2008 - Julien Pauli - Cyril PIERRE de GEYER - Anaska (http://www.anaska.com)
|
||
10 | * @license http://www.gnu.org/copyleft/gpl.html GPL License
|
||
11 | * SVN Revision - $Rev: 36 $
|
||
12 | * Last commit by $Author: neveldo $
|
||
13 | * Date - $Date: 2009-06-04 15:45:12 +0200 (jeu., 04 juin 2009) $
|
||
14 | * SVN Revision - $Rev: 36 $
|
||
15 | * Id : $Id: simplecheck.php 36 2009-06-04 13:45:12Z neveldo $
|
||
16 | */
|
||
17 | |||
18 | // instantiate the Exception class
|
||
19 | class OdfException extends Exception{} |
||
20 | |||
21 | // checking php-zip module
|
||
22 | |||
23 | if ( !class_exists('ZipArchive') ) |
||
24 | { |
||
25 | throw new OdfException('ZipArchive extension not loaded - check your php settings, PHP5.2 minimum with php-zip extension is required'); |
||
26 | } |
||
27 | |||
28 | // checking php-xml module
|
||
29 | |||
30 | if ( !class_exists('DOMDocument') ) |
||
31 | { |
||
32 | throw new OdfException('DOMDocument extension not loaded - check your php settings, PHP5.2 minimum with php-xml extension is required'); |
||
33 | } |
||
34 | |||
35 | // start code ...
|
||
36 | |||
37 | $filename = "simplecheck.odt"; // must exist in same path as this script |
||
38 | |||
39 | // load the oasis document via php-lib library
|
||
40 | |||
41 | $file = new ZipArchive(); |
||
42 | if ( $file->open($filename) !== true ) |
||
43 | { |
||
44 | throw new OdfException("Error while Opening the file '$filename' - Check your odt file"); |
||
45 | } |
||
46 | |||
47 | // read content.xml from the oasis document
|
||
48 | |||
49 | if (($contentXml = $file->getFromName('content.xml')) === false) |
||
50 | { |
||
51 | throw new OdfException("Nothing to parse - check that the content.xml file is correctly formed"); |
||
52 | } |
||
53 | |||
54 | // close the original oasis document
|
||
55 | |||
56 | $file->close();
|
||
57 | |||
58 | // for futur use, with load content.xml via DOMDocument library :
|
||
59 | |||
60 | $odt_content = new DOMDocument('1.0', 'utf-8'); |
||
61 | if ($odt_content->loadXML( $contentXml ) == FALSE) |
||
62 | { |
||
63 | throw new OdfException('Unable to load content.xml by DOMDocument library ', __METHOD__); |
||
64 | } |
||
65 | |||
66 | // here, we dont use the temp function but local temporary file
|
||
67 | |||
68 | $tmpfile = md5(uniqid()).'.odt'; |
||
69 | if( !@copy($filename, $tmpfile) ); |
||
70 | { |
||
71 | // we do not test, because sometime it return false anyway !!
|
||
72 | // $errors = error_get_last();
|
||
73 | // throw new OdfException("Can not copy the tempfile in $tmpfile :[".$errors['message'] ."]/[".$errors['type']."]");
|
||
74 | } |
||
75 | |||
76 | // futur use here : $odt_content modifications ...
|
||
77 | |||
78 | |||
79 | |||
80 | |||
81 | // open the temporary zipfile
|
||
82 | |||
83 | if( $file->open($tmpfile, ZIPARCHIVE::CREATE) != TRUE ) |
||
84 | { |
||
85 | @unlink($tmpfile); // erase temporary file |
||
86 | throw new OdfException("Error while Opening the tempfile '$tmpfile' - Check your odt file"); |
||
87 | } |
||
88 | |||
89 | // for futur use here : with overwrite content.xml in zip file via DOMDocument library :
|
||
90 | |||
91 | if (! $file->addFromString('content.xml', $odt_content->saveXML()) ) |
||
92 | { |
||
93 | @unlink($tmpfile); // erase temporary file |
||
94 | throw new OdfException('Error during file export'); |
||
95 | } |
||
96 | |||
97 | // close the temporary zipfile
|
||
98 | |||
99 | $file->close();
|
||
100 | |||
101 | // send the new checkresult.odt file via http :
|
||
102 | |||
103 | $name = "checkresult.odt"; |
||
104 | $size = filesize($tmpfile); |
||
105 | header('Content-type: application/vnd.oasis.opendocument.text'); |
||
106 | header('Content-Disposition: attachment; filename="'.$name.'"'); |
||
107 | header("Content-Length: ".$size); |
||
108 | readfile($tmpfile); // output |
||
109 | @unlink($tmpfile); // erase temporary file |
||
110 | exit; // be sure nothing else is write after |
||
111 | |||
112 | ?> |