cvs: pear /OpenDocument/examples create.php html.php read.php test.odt
| From: | Alexander Pak | Date: | Wed, 30 Aug 2006 18:19:27 +0000 |
| Subject: | cvs: pear /OpenDocument/examples create.php html.php read.php test.odt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-41929@lists.php.net to get a copy of this message | ||
irokez Wed Aug 30 18:19:27 2006 UTC
Added files:
/pear/OpenDocument/examples create.php html.php read.php test.odt
Log:
Commit missing examples
http://cvs.php.net/viewvc.cgi/pear/OpenDocument/examples/create.php?view=markup&rev=1.1
Index: pear/OpenDocument/examples/create.php
+++ pear/OpenDocument/examples/create.php
<?php
require_once 'OpenDocument.php'; // open document class
//create a new OpenDocument Text file
$odt = new OpenDocument;
//add heading
$h = $odt->createHeading('Heading', 1);
//create paragraph
$p1 = $odt->createParagraph('Paragraph 1');
//set paragraph styles
$p1->style->fontSize = '12pt';
$p1->style->fontName = 'Times New Roman';
$p1->style->color = '#009900';
$p1->style->underlineStyle = 'dotted';
$p1->style->underlineColor = '#009999';
$p1->style->underlineWidth = '2pt';
//create second paragraph
$p2 = $odt->createParagraph('Paragraph 2');
//copy styles from first one
$p2->style->copy($p1->style);
//insert space into paragraph
$p1->createTextElement(' ');
//create a link inside a paragraph
$a1 = $p1->createHyperlink('', 'http://ya.ru', 'simple', '_self',
'link');
//insert text in link
$span = $a1->createSpan('Ya.ru');
//apply color to text
$span->style->color = '#000099';
//insert space to heading
$h->createTextElement(' ');
//create link in heading
$a2 = $h->createHyperlink('Ya.ru', 'http://ya.ru');
//apply underline color to link
$a2->style->underlineColor = '#990000';
//save as test.odt
$odt->save('test.odt');
echo 'saved as test.odt';
?>
http://cvs.php.net/viewvc.cgi/pear/OpenDocument/examples/html.php?view=markup&rev=1.1
Index: pear/OpenDocument/examples/html.php
+++ pear/OpenDocument/examples/html.php
<?php
require_once 'OpenDocument.php'; // open document class
//open test.odt
$odt = new OpenDocument('test.odt');
//output content as html
echo toHTML($odt);
function toHTML($obj)
{
$html = '';
foreach ($obj->getChildren() as $child) {
switch (get_class($child)) {
case 'OpenDocument_TextElement':
$html .= $child->text;
break;
case 'OpenDocument_Paragraph':
$html .= '<p>';
$html .= toHTML($child);
$html .= '</p>';
break;
case 'OpenDocument_Span':
$html .= '<span>';
$html .= toHTML($child);
$html .= '</span>';
break;
case 'OpenDocument_Heading':
$html .= '<h' . $child->level . '>';
$html .= toHTML($child);
$html .= '</h' . $child->level . '>';
break;
case 'OpenDocument_Hyperlink':
$html .= '<a href="' . $child->location . '"
target="' . $child->target . '">';
$html .= toHTML($child);
$html .= '</a>';
break;
default:
$html .= '<del>unknown element</del>';
}
}
return $html;
}
?>
http://cvs.php.net/viewvc.cgi/pear/OpenDocument/examples/read.php?view=markup&rev=1.1
Index: pear/OpenDocument/examples/read.php
+++ pear/OpenDocument/examples/read.php
<?php
require_once 'OpenDocument.php'; // open document class
//open test.odt
$odt = new OpenDocument('test.odt');
//loop throught document children
foreach ($odt->getChildren() as $child) {
//strip headings
if ($child instanceof OpenDocument_Heading) {
$child->delete();
}
}
//save as no_headings.pdt
$odt->save('no_headings.odt');
echo 'saved as no-headings.odt';
?>
http://cvs.php.net/viewvc.cgi/pear/OpenDocument/examples/test.odt?view=markup&rev=1.1
Index: pear/OpenDocument/examples/test.odt
+++ pear/OpenDocument/examples/test.odt
PK