1<?php
2
3//this script may only be included - so its better to die if called directly.
4if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
5  header("location: index.php");
6  exit;
7}
8
9
10/*
11This file is part of J4PHP - Ensembles de propriétés et méthodes permettant le developpment rapide d'application web modulaire
12Copyright (c) 2002-2004 @PICNet
13
14This program is free software; you can redistribute it and/or
15modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
16as published by the Free Software Foundation.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21GNU LESSER GENERAL PUBLIC LICENSE for more details.
22
23You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26*/
27
28APIC::import("org.apicnet.io.OOo.absOOo");
29APIC::import("org.apicnet.io.cdir");
30
31class OOoManifest extends absOOo {
32
33	function __construct($dir){
34		parent::__construct();
35
36		$this->DIRXML   = $dir;
37		$this->FILENAME = "META-INF/manifest.xml";
38		$this->xml      = new DOMIT_Document();
39		$this->xml->setDocType("<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">");
40	}
41
42	function create($type){
43		$docManifestNode =& $this->xml->createElement("manifest:manifest");
44		$docManifestNode->setAttribute("xmlns:manifest", "http://openoffice.org/2001/manifest");
45
46
47		$fileEntryNode = &$this->xml->createElement("manifest:file-entry");
48		if (in_array($type, $this->XMLTYPE)) {
49		    $fileEntryNode->setAttribute("manifest:media-type", "application/".$this->MIME[$type]);
50		} else {
51			$this -> ErrorTracker(4, 'Le type '.$type." est inconnu", 'create', __FILE__, __LINE__);
52		}
53		$fileEntryNode->setAttribute("manifest:full-path", "/");
54		$docManifestNode->appendChild($fileEntryNode);
55
56		$cdir = new CDir();
57		$cdir->Read( $this->DIRXML."/", "", true, 5 , true, true);
58		$allFiles = array();
59
60		$sortFiles = $cdir->sort("'Path'", false, 4, "'File'", true, 0);
61		reset( $sortFiles );
62
63		foreach ($sortFiles as $aFile) {
64			$sFileName     = $cdir->FileName($aFile);
65			$sFilePath     = $cdir->GetPath($aFile);
66			$mediaType     = "";
67			$sExtension    = "";
68			$fileEntryNode = &$this->xml->createElement("manifest:file-entry");
69
70
71			$i = strrpos( $sFileName, "." ) + 1;
72			if ( substr( $sFileName, $i - 1, 1 ) == "." ) {
73				$sExtension = substr( $sFileName, $i );
74			}
75
76			switch($sExtension){
77				case "":
78					$mediaType = "";
79					break;
80				case "png":
81				case "gif":
82				case "jpeg":
83					$mediaType = "image/".$sExtension;
84					break;
85				default:
86					$mediaType = "text/xml";
87			} // switch
88
89			$dirname  = dirname($this->DIRXML."/".$sFilePath.$sFileName);
90			$filename = basename($this->DIRXML."/".$sFilePath.$sFileName);
91			if ($dirname != $this->DIRXML) {
92				$filename = str_replace($this->DIRXML."/", "", $dirname)."/".$filename;
93			} else {
94				if ($cdir->GetIsDirectory( $aFile )) $filename = $filename."/";
95			}
96
97
98			$fileEntryNode->setAttribute("manifest:media-type", $mediaType);
99			$fileEntryNode->setAttribute("manifest:full-path", $filename);
100			$docManifestNode->appendChild($fileEntryNode);
101		}
102
103		$this->xml->setDocumentElement($docManifestNode);
104
105		$this->xml->setXMLDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
106	}
107
108
109	function Main(){
110		$this->create("Writer");
111		mkdir (CACHE_PATH."/OOotmp");
112		mkdir (CACHE_PATH."/OOotmp/META-INF");
113		$this->save(CACHE_PATH."/OOotmp");
114	}
115
116
117}
118