<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Aukyla PHP Framework</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="StyleSheet" href="auton.css" type="text/css" media="screen">
</head>
<body>
<div id="mainmenu">
<a href="http://www.auton.nl/" class="home">Home</a>
</div>
<div id="submenu">
<a class="logo" href="http://www.auton.nl/"></a>
<div class="head">Ads</div>
<a href="http://sourceforge.net/"><img src="http://sourceforge.net/sflogo.php?group_id=116358&type=1" alt="SourceForge.net Logo" style="padding: 2px 4px; width: 88px; height: 31px; border: 0px"></a>
<a href="http://getfirefox.com/" title="Get Firefox - The Browser, Reloaded."><img src="http://www.mozilla.org/products/firefox/buttons/getfirefox_small.png" alt="Get Firefox" style="width: 110px; height: 32px; border: 0px"></a>
</div>
<div id="main">
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">base</a></div>
<h1>OpenDocument.php</h1><div class="fragment"><pre class="fragment">00001 <?php
00002 <span class="comment">/*</span>
00003 <span class="comment"> OpenDocument.php, utility functions for working with OpenDocument files and</span>
00004 <span class="comment"> converting them to XHTML.</span>
00005 <span class="comment"> Copyright (C) 2003-2005 Arend van Beelen, Auton Rijnsburg</span>
00006 <span class="comment"></span>
00007 <span class="comment"> This program is free software; you can redistribute it and/or modify it</span>
00008 <span class="comment"> under the terms of the GNU General Public License as published by the Free</span>
00009 <span class="comment"> Software Foundation; either version 2 of the License, or (at your option)</span>
00010 <span class="comment"> any later version.</span>
00011 <span class="comment"></span>
00012 <span class="comment"> This program is distributed in the hope that it will be useful, but WITHOUT</span>
00013 <span class="comment"> ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span>
00014 <span class="comment"> FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for</span>
00015 <span class="comment"> more details.</span>
00016 <span class="comment"></span>
00017 <span class="comment"> You should have received a copy of the GNU General Public License along</span>
00018 <span class="comment"> with this program; if not, write to the Free Software Foundation, Inc.,</span>
00019 <span class="comment"> 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00020 <span class="comment"></span>
00021 <span class="comment"> For any questions, comments or whatever, you may mail me at: hide@address.com</span>
00022 <span class="comment">*/</span>
00023
00024 require_once('<a class="code" href="a00092.html">Config</a>.php');
00025 require_once('<a class="code" href="a00163.html">URI</a>.php');
00026
<a name="l00030"></a><a class="code" href="a00132.html">00030</a> <span class="keyword">class </span><a class="code" href="a00132.html">OpenDocument</a>
00031 {
<a name="l00037"></a><a class="code" href="a00132.html#a0">00037</a> <span class="keyword">public</span> function __destruct()
00038 {
00039 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">true</span>)
00040 {
00041 $this->close();
00042 }
00043 }
00044
<a name="l00059"></a><a class="code" href="a00132.html#a1">00059</a> <span class="keyword">public</span> function load($openDocument)
00060 {
00061 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">true</span>)
00062 {
00063 $this->close();
00064 }
00065
00066 <span class="keywordflow">if</span>((<a class="code" href="a00163.html#e15">URI::permissions</a>($openDocument) & PERMISSION_READ) == 0)
00067 {
00068 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00069 }
00070
00071 $simplifiedFilename = <a class="code" href="a00153.html#e6">String::simplifyPath</a>($openDocument);
00072 <span class="keywordflow">if</span>(isset(self::$openedDocuments[$simplifiedFilename]))
00073 {
00074 $this->fileOpened = <span class="keyword">true</span>;
00075 $this->document = $openDocument;
00076 $this->tmpdir = self::$openedDocuments[$simplifiedFilename]->tmpdir;
00077 $this->metaDoc = self::$openedDocuments[$simplifiedFilename]->metaDoc;
00078 $this->metaNodes = self::$openedDocuments[$simplifiedFilename]->metaNodes;
00079 $this->changed = self::$openedDocuments[$simplifiedFilename]->changed;
00080 $this->cached = <span class="keyword">true</span>;
00081 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00082 }
00083
00084 <span class="comment">// create a temporary directory and extract the document to it</span>
00085 $this->tmpdir = tempnam('/tmp', '<a class="code" href="a00132.html">OpenDocument</a>');
00086 unlink($this->tmpdir);
00087 <span class="keywordflow">if</span>(mkdir($this->tmpdir) == <span class="keyword">false</span>)
00088 {
00089 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00090 }
00091 <span class="keywordflow">if</span>(copy($openDocument, <span class="stringliteral">"{$this->tmpdir}/document.od"</span>) == <span class="keyword">false</span>)
00092 {
00093 exec(<span class="stringliteral">"rm -R {$this->tmpdir}"</span>);
00094 trigger_error('Could not copy <a class="code" href="a00132.html">OpenDocument</a> file');
00095 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00096 }
00097 exec(<span class="stringliteral">"unzip {$this->tmpdir}/document.od -d {$this->tmpdir}"</span>, $output, $<span class="keywordflow">return</span>);
00098 <span class="keywordflow">if</span>($return != 0)
00099 {
00100 exec(<span class="stringliteral">"rm -R {$this->tmpdir}"</span>);
00101 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00102 }
00103
00104 $this->loadMeta();
00105
00106 $this->fileOpened = <span class="keyword">true</span>;
00107 $this->document = $openDocument;
00108 $this->cached = <span class="keyword">false</span>;
00109 self::$openedDocuments[$simplifiedFilename] = $this;
00110
00111 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00112 }
00113
<a name="l00120"></a><a class="code" href="a00132.html#a2">00120</a> <span class="keyword">public</span> function unload()
00121 {
00122 $simplifiedFilename = <a class="code" href="a00153.html#e6">String::simplifyPath</a>($this->document);
00123 <span class="keywordflow">if</span>(isset(self::$openedDocuments[$simplifiedFilename]))
00124 {
00125 unset(self::$openedDocuments[$simplifiedFilename]);
00126 }
00127 <span class="keywordflow">else</span>
00128 {
00129 trigger_error('<a class="code" href="a00100.html">Document</a> was never loaded');
00130 }
00131 }
00132
<a name="l00140"></a><a class="code" href="a00132.html#a3">00140</a> <span class="keyword">public</span> function title()
00141 {
00142 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00143 {
00144 trigger_error('Trying to get title when no document is loaded');
00145 <span class="keywordflow">return</span> '';
00146 }
00147
00148 <span class="keywordflow">return</span> $this->metaNodes['title']->nodeValue;
00149 }
00150
<a name="l00158"></a><a class="code" href="a00132.html#a4">00158</a> <span class="keyword">public</span> function setTitle($title)
00159 {
00160 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00161 {
00162 trigger_error('Cannot set title when no document is loaded');
00163 <span class="keywordflow">return</span>;
00164 }
00165
00166 $this->metaNodes['title']->nodeValue = $title;
00167
00168 $this->setChanged();
00169 }
00170
<a name="l00178"></a><a class="code" href="a00132.html#a5">00178</a> <span class="keyword">public</span> function subject()
00179 {
00180 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00181 {
00182 trigger_error('Trying to get subject when no document is loaded');
00183 <span class="keywordflow">return</span> '';
00184 }
00185
00186 <span class="keywordflow">return</span> $this->metaNodes['subject']->nodeValue;
00187 }
00188
<a name="l00196"></a><a class="code" href="a00132.html#a6">00196</a> <span class="keyword">public</span> function setSubject($subject)
00197 {
00198 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00199 {
00200 trigger_error('Cannot set subject when no document is loaded');
00201 <span class="keywordflow">return</span>;
00202 }
00203
00204 $this->metaNodes['subject']->nodeValue = $subject;
00205
00206 $this->setChanged();
00207 }
00208
<a name="l00216"></a><a class="code" href="a00132.html#a7">00216</a> <span class="keyword">public</span> function keywords()
00217 {
00218 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00219 {
00220 trigger_error('Trying to get keywords when no document is loaded');
00221 <span class="keywordflow">return</span> '';
00222 }
00223
00224 <span class="keywordflow">return</span> $this->metaNodes['keywords']->nodeValue;
00225 }
00226
<a name="l00234"></a><a class="code" href="a00132.html#a8">00234</a> <span class="keyword">public</span> function setKeywords($keywords)
00235 {
00236 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00237 {
00238 trigger_error('Cannot set keywords when no document is loaded');
00239 <span class="keywordflow">return</span>;
00240 }
00241
00242 $this->metaNodes['keywords']->nodeValue = $keywords;
00243
00244 $this->setChanged();
00245 }
00246
<a name="l00254"></a><a class="code" href="a00132.html#a9">00254</a> <span class="keyword">public</span> function comments()
00255 {
00256 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00257 {
00258 trigger_error('Trying to get comments when no document is loaded');
00259 <span class="keywordflow">return</span> '';
00260 }
00261
00262 <span class="keywordflow">return</span> $this->metaNodes['comments']->nodeValue;
00263 }
00264
<a name="l00272"></a><a class="code" href="a00132.html#a10">00272</a> <span class="keyword">public</span> function setComments($comments)
00273 {
00274 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00275 {
00276 trigger_error('Cannot set comments when no document is loaded');
00277 <span class="keywordflow">return</span>;
00278 }
00279
00280 $this->metaNodes['comments']->nodeValue = $comments;
00281
00282 $this->setChanged();
00283 }
00284
<a name="l00292"></a><a class="code" href="a00132.html#a11">00292</a> <span class="keyword">public</span> function author()
00293 {
00294 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00295 {
00296 trigger_error('Trying to get author when no document is loaded');
00297 <span class="keywordflow">return</span> '';
00298 }
00299
00300 <span class="keywordflow">return</span> $this->metaNodes['author']->nodeValue;
00301 }
00302
<a name="l00310"></a><a class="code" href="a00132.html#a12">00310</a> <span class="keyword">public</span> function setAuthor($author)
00311 {
00312 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00313 {
00314 trigger_error('Cannot set author when no document is loaded');
00315 <span class="keywordflow">return</span>;
00316 }
00317
00318 $this->metaNodes['author']->nodeValue = $author;
00319
00320 $this->setChanged();
00321 }
00322
<a name="l00333"></a><a class="code" href="a00132.html#a13">00333</a> <span class="keyword">public</span> function convertToXHTML($xhtmlDocument)
00334 {
00335 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00336 {
00337 trigger_error('No document was loaded <span class="keywordflow">for</span> conversion to <a class="code" href="a00169.html">XHTML</a>');
00338 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00339 }
00340
00341 <span class="keywordflow">if</span>(((<a class="code" href="a00163.html#e15">URI::permissions</a>(dirname($xhtmlDocument)) & PERMISSION_APPEND) &&
00342 (<a class="code" href="a00163.html#e29">URI::fileExists</a>($xhtmlDocument) == <span class="keyword">false</span> ||
00343 <a class="code" href="a00163.html#e15">URI::permissions</a>($xhtmlDocument) & PERMISSION_MODIFY)) == <span class="keyword">false</span>)
00344 {
00345 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00346 }
00347
00348 <span class="comment">// copy images</span>
00349 $images = glob(<span class="stringliteral">"{$this->tmpdir}/Pictures/*"</span>);
00350 <span class="keywordflow">if</span>($images !== <span class="keyword">false</span>)
00351 {
00352 $picturesDir = dirname($xhtmlDocument).'/Pictures';
00353 <span class="keywordflow">if</span>(<a class="code" href="a00163.html#e29">URI::fileExists</a>($picturesDir) == <span class="keyword">false</span>)
00354 {
00355 <a class="code" href="a00163.html#e18">URI::mkdir</a>($picturesDir);
00356 }
00357
00358 foreach($images as $image)
00359 {
00360 $basename = basename($image);
00361 <span class="keywordflow">if</span>($basename == <span class="charliteral">'.'</span> || $basename == '..')
00362 {
00363 <span class="keywordflow">continue</span>;
00364 }
00365 copy($image, <span class="stringliteral">"$picturesDir/$basename"</span>);
00366 }
00367 }
00368
00369 <span class="comment">// convert the OpenDocument XML file using the XSL stylesheets into an XHTML file</span>
00370 OpenDocument2XHTML::reset();
00371
00372 $stylesDoc = <span class="keyword">new</span> DOMDocument();
00373 $contentDoc = <span class="keyword">new</span> DOMDocument();
00374 <span class="keywordflow">if</span>($stylesDoc->load(<span class="stringliteral">"{$this->tmpdir}/styles.xml"</span>) == <span class="keyword">false</span> ||
00375 $contentDoc->load(<span class="stringliteral">"{$this->tmpdir}/content.xml"</span>) == <span class="keyword">false</span>)
00376 {
00377 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00378 }
00379
00380 $stylesXSL = <span class="keyword">new</span> DOMDocument();
00381 $stylesXSL->load(AUKYLA_DIR.'/data/base/<a class="code" href="a00132.html">OpenDocument</a>/Styles.xsl');
00382 $contentXSL = <span class="keyword">new</span> DOMDocument();
00383 $contentXSL->load(AUKYLA_DIR.'/data/base/OpenDocument/Content2XHTML.xsl');
00384
00385 $xsltProcessor = <span class="keyword">new</span> XSLTProcessor();
00386 <span class="keywordflow">if</span>($xsltProcessor->hasExsltSupport() == <span class="keyword">false</span>)
00387 {
00388 die('EXSLT support in PHP is required <span class="keywordflow">for</span> converting OpenDocument files!');
00389 }
00390
00391 $xsltProcessor->registerPHPFunctions();
00392 $xsltProcessor->importStyleSheet($stylesXSL);
00393 $xsltProcessor->transformToXML($stylesDoc);
00394
00395 $xsltProcessor = <span class="keyword">new</span> XSLTProcessor();
00396 $xsltProcessor->registerPHPFunctions();
00397 $xsltProcessor->importStyleSheet($contentXSL);
00398 $xsltProcessor->setParameter('', 'imagePrefix', Config::globals('downloadURL').'?file='.dirname($xhtmlDocument).'/Pictures/');
00399 $xsltProcessor->setParameter('', 'title', $this->title());
00400 <span class="keywordflow">if</span>($xsltProcessor->transformToURI($contentDoc, $xhtmlDocument) == <span class="keyword">false</span>)
00401 {
00402 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00403 }
00404
00405 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00406 }
00407
<a name="l00419"></a><a class="code" href="a00132.html#a14">00419</a> <span class="keyword">public</span> function scaleImages($maxWidth, $maxHeight)
00420 {
00421 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00422 {
00423 trigger_error('No document was loaded <span class="keywordflow">for</span> scaling images');
00424 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00425 }
00426
00427 <span class="keywordflow">if</span>((<a class="code" href="a00163.html#e15">URI::permissions</a>($this->document) & PERMISSION_MODIFY) == 0)
00428 {
00429 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00430 }
00431
00432 $images = glob(<span class="stringliteral">"{$this->tmpdir}/Pictures/*"</span>);
00433 <span class="keywordflow">if</span>($images !== <span class="keyword">false</span> && <span class="keyword">sizeof</span>($images) > 0)
00434 {
00435 foreach($images as $image)
00436 {
00437 unset($output);
00438 exec(<span class="stringliteral">"identify $image"</span>, $output, $<span class="keywordflow">return</span>);
00439 <span class="keywordflow">if</span>($return != 0)
00440 {
00441 trigger_error(<span class="stringliteral">"Failed to run 'identify', is ImageMagick installed?"</span>);
00442 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00443 }
00444
00445 $properties = explode(<span class="charliteral">' '</span>, $output[0]);
00446 $geometry = $properties[2];
00447 list($width, $height) = explode(<span class="charliteral">'x'</span>, $geometry);
00448 <span class="keywordflow">if</span>($width > $maxWidth || $height > $maxHeight)
00449 {
00450 exec(<span class="stringliteral">"convert -size {$maxWidth}x{$maxHeight} $image -scale {$maxWidth}x{$maxHeight} $image"</span>, $output, $<span class="keywordflow">return</span>);
00451 <span class="keywordflow">if</span>($return != 0)
00452 {
00453 trigger_error(<span class="stringliteral">"Failed to run 'convert', is ImageMagick installed?"</span>);
00454 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00455 }
00456 }
00457 }
00458
00459 $this->setChanged();
00460 }
00461
00462 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00463 }
00464
<a name="l00478"></a><a class="code" href="a00132.html#a15">00478</a> <span class="keyword">public</span> function temporaryDirectory()
00479 {
00480 <span class="keywordflow">if</span>($this->fileOpened == <span class="keyword">false</span>)
00481 {
00482 trigger_error('Requesting temporary directory with no document loaded');
00483 <span class="keywordflow">return</span> '';
00484 }
00485
00486 <span class="keywordflow">return</span> $this->tmpdir;
00487 }
00488
00489 <span class="keyword">private</span> function loadMeta()
00490 {
00491 $this->metaNodes = array('title' => <span class="keyword">false</span>,
00492 'subject' => <span class="keyword">false</span>,
00493 'keywords' => <span class="keyword">false</span>,
00494 'comments' => <span class="keyword">false</span>,
00495 'author' => <span class="keyword">false</span>);
00496
00497 $this->metaDoc = <span class="keyword">new</span> DOMDocument();
00498 <span class="keywordflow">if</span>($this->metaDoc->load(<span class="stringliteral">"{$this->tmpdir}/meta.xml"</span>) == <span class="keyword">false</span>)
00499 {
00500 <span class="keywordflow">return</span> <span class="keyword">false</span>;
00501 }
00502
00503 $dcNS = 'http:<span class="comment">//purl.org/dc/elements/1.1/';</span>
00504 $metaNS = 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0';
00505 $officeNS = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0';
00506
00507 $xpath = <span class="keyword">new</span> DOMXPath($this->metaDoc);
00508 $xpath->registerNamespace('dc', $dcNS);
00509 $xpath->registerNamespace('meta', $metaNS);
00510 $xpath->registerNamespace('office', $officeNS);
00511
00512 $metaNodes = $xpath->query('<span class="comment">//office:document-meta/office:meta/*');</span>
00513 foreach($metaNodes as $metaNode)
00514 {
00515 <span class="keywordflow">if</span>($metaNode->namespaceURI == $dcNS)
00516 {
00517 <span class="keywordflow">if</span>($metaNode->localName == 'title')
00518 {
00519 $this->metaNodes['title'] = $metaNode;
00520 }
00521 <span class="keywordflow">if</span>($metaNode->localName == 'subject')
00522 {
00523 $this->metaNodes['subject'] = $metaNode;
00524 }
00525 <span class="keywordflow">if</span>($metaNode->localName == 'description')
00526 {
00527 $this->metaNodes['comments'] = $metaNode;
00528 }
00529 <span class="keywordflow">if</span>($metaNode->localName == 'author')
00530 {
00531 $this->metaNodes['creator'] = $metaNode;
00532 }
00533 }
00534 elseif($metaNode->namespaceURI == $metaNS)
00535 {
00536 <span class="keywordflow">if</span>($metaNode->localName == 'keyword')
00537 {
00538 $this->metaNodes['keywords'] = $metaNode;
00539 }
00540 }
00541 }
00542
00543 $officeMetaNode = $xpath->query('<span class="comment">//office:document-meta/office:meta')->item(0);</span>
00544 foreach(array('title',
00545 'subject',
00546 'keywords',
00547 'comments',
00548 'author') as $key)
00549 {
00550 <span class="keywordflow">if</span>($this->metaNodes[$key] === <span class="keyword">false</span>)
00551 {
00552 <span class="keywordflow">if</span>($key == 'keywords')
00553 {
00554 $ns = $metaNS;
00555 }
00556 <span class="keywordflow">else</span>
00557 {
00558 $ns = $dcNS;
00559 }
00560
00561 $node = $this->metaDoc->createElementNS($ns, $key, '');
00562 $officeMetaNode->appendChild($node);
00563 $this->metaNodes[$key] = $node;
00564 }
00565 }
00566 }
00567
<a name="l00574"></a><a class="code" href="a00132.html#a16">00574</a> <span class="keyword">public</span> function setChanged()
00575 {
00576 <span class="keywordflow">if</span>($this->cached == <span class="keyword">true</span>)
00577 {
00578 $simplifiedFilename = <a class="code" href="a00153.html#e6">String::simplifyPath</a>($this->document);
00579 self::$openedDocuments[$simplifiedFilename]->changed = <span class="keyword">true</span>;
00580 }
00581 $this->changed = <span class="keyword">true</span>;
00582 }
00583
00589 <span class="keyword">private</span> function close()
00590 {
00591 <span class="keywordflow">if</span>($this->cached == <span class="keyword">false</span>)
00592 {
00593 <span class="keywordflow">if</span>($this->changed == <span class="keyword">true</span>)
00594 {
00595 $this->metaDoc->save(<span class="stringliteral">"{$this->tmpdir}/meta.xml"</span>);
00596
00597 <span class="keywordflow">if</span>(<a class="code" href="a00163.html#e15">URI::permissions</a>($this->document) & PERMISSION_MODIFY)
00598 {
00599 exec(<span class="stringliteral">"cd {$this->tmpdir}; rm document.od; zip -r - * > document.od"</span>, $output, $<span class="keywordflow">return</span>);
00600 <span class="keywordflow">if</span>($return == 0)
00601 {
00602 copy(<span class="stringliteral">"{$this->tmpdir}/document.od"</span>, $this->document);
00603 }
00604 }
00605 <span class="keywordflow">else</span>
00606 {
00607 trigger_error(<span class="stringliteral">"Not allowed to save {$this->document}"</span>);
00608 }
00609 }
00610
00611 <span class="comment">// clean up</span>
00612 exec(<span class="stringliteral">"rm -R {$this->tmpdir}"</span>);
00613
00614 $this->fileOpened = <span class="keyword">false</span>;
00615 $this->document = '';
00616 unset($this->meta);
00617 }
00618 }
00619
00620 <span class="keyword">private</span> <span class="keyword">static</span> $openedDocuments = array();
00621 <span class="keyword">private</span> $fileOpened = <span class="keyword">false</span>;
00622 <span class="keyword">private</span> $document = '';
00623 <span class="keyword">private</span> $tmpdir = '';
00624 <span class="keyword">private</span> $metaDoc;
00625 <span class="keyword">private</span> $metaNodes;
00626 <span class="keyword">private</span> $changed = <span class="keyword">false</span>;
00627 <span class="keyword">private</span> $cached = <span class="keyword">false</span>;
00628 }
00629
00633 <span class="keyword">class </span>OpenDocument2XHTML
00634 {
00635 <span class="keyword">public</span> <span class="keyword">static</span> function reset()
00636 {
00637 self::$styles = array();
00638 self::$fontFaces = array();
00639 self::$listStyles = array();
00640 }
00641
00645 <span class="keyword">public</span> <span class="keyword">static</span> function setFontFace($name, $family)
00646 {
00647 self::$fontFaces[$name] = $family;
00648
00649 <span class="keywordflow">return</span> '';
00650 }
00651
00655 <span class="keyword">public</span> <span class="keyword">static</span> function fontFaceFamily($name)
00656 {
00657 <span class="keywordflow">return</span> (isset(self::$fontFaces[$name]) ? self::$fontFaces[$name] : '');
00658 }
00659
00663 <span class="keyword">public</span> <span class="keyword">static</span> function createStyle($family, $styleName, $parentStyleName = '')
00664 {
00665 <span class="keywordflow">if</span>(isset(self::$styles[$family]) == <span class="keyword">false</span>)
00666 {
00667 self::$styles[$family] = array();
00668 }
00669 <span class="keywordflow">if</span>(isset(self::$styles[$family][$styleName]) == <span class="keyword">false</span>)
00670 {
00671 <span class="keywordflow">if</span>(isset(self::$styles[$family][$parentStyleName]))
00672 {
00673 self::$styles[$family][$styleName] = self::$styles[$family][$parentStyleName];
00674 }
00675 <span class="keywordflow">else</span>
00676 {
00677 self::$styles[$family][$styleName] = array();
00678 <span class="keywordflow">if</span>($family == 'paragraph')
00679 {
00680 self::$styles[$family][$styleName]['margin-top'] = '0cm';
00681 self::$styles[$family][$styleName]['margin-bottom'] = '0cm';
00682 }
00683 elseif($family == 'paragraph')
00684 {
00685 self::$styles[$family][$styleName]['margin'] = '0cm';
00686 self::$styles[$family][$styleName]['padding'] = '0cm';
00687 }
00688 }
00689 }
00690
00691 <span class="keywordflow">return</span> '';
00692 }
00693
00697 <span class="keyword">public</span> <span class="keyword">static</span> function createListStyle($styleName)
00698 {
00699 <span class="keywordflow">if</span>(isset(self::$listStyles[$styleName]) == <span class="keyword">false</span>)
00700 {
00701 self::$listStyles[$styleName] = array();
00702 }
00703
00704 <span class="keywordflow">return</span> '';
00705 }
00706
00710 <span class="keyword">public</span> <span class="keyword">static</span> function setStyleTextProperties($family,
00711 $styleName,
00712 $fontName,
00713 $fontSize,
00714 $fontStyle,
00715 $fontWeight,
00716 $textUnderlineStyle,
00717 $color,
00718 $backgroundColor)
00719 {
00720 self::createStyle($family, $styleName);
00721
00722 self::$styles[$family][$styleName] = array_merge(self::$styles[$family][$styleName],
00723 self::cssStyleTextProperties($fontName,
00724 $fontSize,
00725 $fontStyle,
00726 $fontWeight,
00727 $textUnderlineStyle,
00728 $color,
00729 $backgroundColor));
00730
00731 <span class="keywordflow">return</span> '';
00732 }
00733
00737 <span class="keyword">public</span> <span class="keyword">static</span> function setStyleParagraphProperties($family,
00738 $styleName,
00739 $marginTop,
00740 $marginBottom,
00741 $textAlign)
00742 {
00743 self::createStyle($family, $styleName);
00744
00745 self::$styles[$family][$styleName] = array_merge(self::$styles[$family][$styleName],
00746 self::cssStyleParagraphProperties($marginTop,
00747 $marginBottom,
00748 $textAlign));
00749
00750 <span class="keywordflow">return</span> '';
00751 }
00752
00756 <span class="keyword">public</span> <span class="keyword">static</span> function setStyleTableProperties($family,
00757 $styleName,
00758 $width)
00759 {
00760 self::createStyle($family, $styleName);
00761
00762 self::$styles[$family][$styleName] = array_merge(self::$styles[$family][$styleName],
00763 self::cssStyleTableProperties($width));
00764
00765 <span class="keywordflow">return</span> '';
00766 }
00767
00771 <span class="keyword">public</span> <span class="keyword">static</span> function setStyleTableCellProperties($family,
00772 $styleName,
00773 $border,
00774 $borderTop,
00775 $borderRight,
00776 $borderBottom,
00777 $borderLeft,
00778 $backgroundColor,
00779 $padding)
00780 {
00781 self::createStyle($family, $styleName);
00782
00783 self::$styles[$family][$styleName] = array_merge(self::$styles[$family][$styleName],
00784 self::cssStyleTableCellProperties($border,
00785 $borderTop,
00786 $borderRight,
00787 $borderBottom,
00788 $borderLeft,
00789 $backgroundColor,
00790 $padding));
00791
00792 <span class="keywordflow">return</span> '';
00793 }
00794
00798 <span class="keyword">public</span> <span class="keyword">static</span> function setStyleListProperties($styleName,
00799 $listLevel,
00800 $bulletChar,
00801 $numFormat)
00802 {
00803 self::createListStyle($styleName);
00804
00805 self::$listStyles[$styleName][$listLevel] = self::cssStyleListProperties($bulletChar,
00806 $numFormat);
00807
00808 <span class="keywordflow">return</span> '';
00809 }
00810
00814 <span class="keyword">public</span> <span class="keyword">static</span> function style($family, $styleName)
00815 {
00816 $styleArray = (isset(self::$styles[$family][$styleName]) ? self::$styles[$family][$styleName] :
00817 (isset(self::$styles[$family]['']) ? self::$styles[$family][''] : array()));
00818
00819 $style = '';
00820 foreach($styleArray as $key => $value)
00821 {
00822 <span class="keywordflow">if</span>($style != '')
00823 {
00824 $style .= '; ';
00825 }
00826 $style .= <span class="stringliteral">"$key: $value"</span>;
00827 }
00828
00829 <span class="keywordflow">return</span> $style;
00830 }
00831
00835 <span class="keyword">public</span> <span class="keyword">static</span> function listStyle($styleName, $listLevel)
00836 {
00837 $styleArray = (isset(self::$listStyles[$styleName][$listLevel]) ?
00838 self::$listStyles[$styleName][$listLevel] : array());
00839
00840 $style = '';
00841 foreach($styleArray as $key => $value)
00842 {
00843 <span class="keywordflow">if</span>($style != '')
00844 {
00845 $style .= '; ';
00846 }
00847 $style .= <span class="stringliteral">"$key: $value"</span>;
00848 }
00849
00850 <span class="keywordflow">return</span> $style;
00851 }
00852
00856 <span class="keyword">private</span> <span class="keyword">static</span> function cssStyleTextProperties($fontName,
00857 $fontSize,
00858 $fontStyle,
00859 $fontWeight,
00860 $textUnderlineStyle,
00861 $color,
00862 $backgroundColor)
00863 {
00864 $style = array();
00865
00866 <span class="keywordflow">if</span>($fontName != '')
00867 {
00868 <span class="comment">// fonts families are ignored purposefully, with the exception of</span>
00869 <span class="comment">// seperating monospace/non-monospace</span>
00870 <span class="comment">//$style['font-family'] = self::fontFaceFamily($fontName);</span>
00871 $font = self::fontFaceFamily($fontName);
00872 <span class="keywordflow">if</span>(strstr($font, 'Courier') !== <span class="keyword">false</span> ||
00873 strstr($font, 'Cumberland') !== <span class="keyword">false</span>)
00874 {
00875 $style['font-family'] = 'Courier New';
00876 }
00877 }
00878 <span class="keywordflow">if</span>($fontSize != '')
00879 {
00880 <span class="comment">// font sizes are ignored purposefully</span>
00881 <span class="comment">//$style['font-size'] = $fontSize;</span>
00882 }
00883 <span class="keywordflow">if</span>($fontStyle != '')
00884 {
00885 $style['font-style'] = $fontStyle;
00886 }
00887 <span class="keywordflow">if</span>($fontWeight != '')
00888 {
00889 $style['font-weight'] = $fontWeight;
00890 }
00891 <span class="keywordflow">if</span>($textUnderlineStyle != '')
00892 {
00893 $style['text-decoration'] = 'underline';
00894 }
00895 <span class="keywordflow">if</span>($color != '')
00896 {
00897 $style['color'] = $color;
00898 }
00899 <span class="keywordflow">if</span>($backgroundColor != '')
00900 {
00901 $style['background-color'] = $backgroundColor;
00902 }
00903
00904 <span class="keywordflow">return</span> $style;
00905 }
00906
00910 <span class="keyword">private</span> <span class="keyword">static</span> function cssStyleParagraphProperties($marginTop,
00911 $marginBottom,
00912 $textAlign)
00913 {
00914 $style = array();
00915
00916 <span class="keywordflow">if</span>($marginTop != '')
00917 {
00918 $style['margin-top'] = $marginTop;
00919 }
00920 <span class="keywordflow">if</span>($marginBottom != '')
00921 {
00922 $style['margin-bottom'] = $marginBottom;
00923 }
00924 <span class="keywordflow">if</span>($textAlign != '')
00925 {
00926 $style['text-align'] = $textAlign;
00927 }
00928
00929 <span class="keywordflow">return</span> $style;
00930 }
00931
00935 <span class="keyword">private</span> <span class="keyword">static</span> function cssStyleTableProperties($width)
00936 {
00937 $style = array();
00938
00939 <span class="keywordflow">if</span>($width != '')
00940 {
00941 $style['width'] = $width;
00942 }
00943
00944 <span class="keywordflow">return</span> $style;
00945 }
00946
00950 <span class="keyword">private</span> <span class="keyword">static</span> function cssStyleTableCellProperties($border,
00951 $borderTop,
00952 $borderRight,
00953 $borderBottom,
00954 $borderLeft,
00955 $backgroundColor,
00956 $padding)
00957 {
00958 $style = array();
00959
00960 <span class="keywordflow">if</span>($border != '')
00961 {
00962 $style['border'] = $border;
00963 }
00964 <span class="keywordflow">if</span>($borderTop != '')
00965 {
00966 $style['border-top'] = $borderTop;
00967 }
00968 <span class="keywordflow">if</span>($borderRight != '')
00969 {
00970 $style['border-right'] = $borderRight;
00971 }
00972 <span class="keywordflow">if</span>($borderBottom != '')
00973 {
00974 $style['border-bottom'] = $borderBottom;
00975 }
00976 <span class="keywordflow">if</span>($borderLeft != '')
00977 {
00978 $style['border-left'] = $borderLeft;
00979 }
00980 <span class="keywordflow">if</span>($backgroundColor != '')
00981 {
00982 $style['background-color'] = $backgroundColor;
00983 }
00984 <span class="keywordflow">if</span>($padding != '')
00985 {
00986 $style['padding'] = $padding;
00987 }
00988
00989 <span class="keywordflow">return</span> $style;
00990 }
00991
00995 <span class="keyword">private</span> <span class="keyword">static</span> function cssStyleListProperties($bulletChar,
00996 $numFormat)
00997 {
00998 $style = array();
00999
01000 <span class="keywordflow">if</span>($bulletChar != '')
01001 {
01002 <span class="keywordflow">if</span>($bulletChar == 'â¢')
01003 {
01004 $style['list-style'] = 'disc';
01005 }
01006 elseif($bulletChar == 'î')
01007 {
01008 $style['list-style'] = 'square';
01009 }
01010 }
01011 <span class="keywordflow">else</span>
01012 {
01013 <span class="keywordflow">if</span>($numFormat == <span class="charliteral">'1'</span>)
01014 {
01015 $style['list-style'] = 'decimal';
01016 }
01017 elseif($numFormat == <span class="charliteral">'a'</span>)
01018 {
01019 $style['list-style'] = 'lower-latin';
01020 }
01021 elseif($numFormat == <span class="charliteral">'A'</span>)
01022 {
01023 $style['list-style'] = 'upper-latin';
01024 }
01025 elseif($numFormat == <span class="charliteral">'i'</span>)
01026 {
01027 $style['list-style'] = 'lower-roman';
01028 }
01029 elseif($numFormat == <span class="charliteral">'I'</span>)
01030 {
01031 $style['list-style'] = 'upper-roman';
01032 }
01033 }
01034
01035 <span class="keywordflow">return</span> $style;
01036 }
01037
01038 <span class="keyword">private</span> <span class="keyword">static</span> $styles;
01039 <span class="keyword">private</span> <span class="keyword">static</span> $fontFaces;
01040 <span class="keyword">private</span> <span class="keyword">static</span> $listStyles;
01041 }
01042
01043 ?>
</pre></div> </div>
</body>
</html>