|
From: <yaw...@us...> - 2006-03-11 18:21:05
|
Revision: 16 Author: yawnster Date: 2006-03-11 10:20:53 -0800 (Sat, 11 Mar 2006) ViewCVS: http://svn.sourceforge.net/opendocumentphp/?rev=16&view=rev Log Message: ----------- - Revised TestOutput to include in main package, please see inbox for more details. - Added in Content Translation support, now adding in new editors is as simple as writing new Regular Expressions. TODO: Actually write some regular expressions that do the job, nothing is broken as such but it needs more work. Modified Paths: -------------- poc/src/samples/TestInput.php Added Paths: ----------- poc/src/OpenDocumentOutput.php poc/src/samples/TestTranslate.php Removed Paths: ------------- poc/src/samples/TestOutput.php Added: poc/src/OpenDocumentOutput.php =================================================================== --- poc/src/OpenDocumentOutput.php (rev 0) +++ poc/src/OpenDocumentOutput.php 2006-03-11 18:20:53 UTC (rev 16) @@ -0,0 +1,195 @@ +<?php +/** + * SampleClass produces a little OpenDocument and send it to the client + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @author Alex Latchford <yaw...@us...> + * @version $Revision$ + * @package OpenDocument + * @since 0.4.2 + * + * $Id$ + */ + +ini_set( "include_path", ini_get( "include_path" ). ";..\\" ); + +require_once( "OpenDocumentFactory.php" ); +require_once( "Log/observer.php" ); +require_once( "input/TestTranslate.php" ); + +class OpenDocumentOutput { + + const DocumentName = "test.odt"; + + const PathToDocument = "D:/PHP/OpenDocument/"; + + private $logger; + private $content_matches = array(); + + function __construct() { + $conf = array( "mode" => 0600 ); + $this->logger = &Log::factory( "file", "D:/PHP/OpenDocument.log", "OpenDocument", $conf ); + $this->logger = &Log::factory( "console", "", "OpenDocument" ); + + $this->testtranslate = new TestTranslate; + } + + function makeMeta( $meta, $creator="Norman Markgraf", $title="This is a test!", $language="en-EN" ) { + $meta->addDublinCore( "title", $title ); + $meta->addDublinCore( "creator", $creator ); + $meta->addDublinCore( "language", "en-EN" ); + $meta->addDublinCore( "date", date("Y-m-d\TH:i:s") ); + $meta->addGenerator( "" ); + $meta->addInitialCreator( $creator ); + $meta->addCreationDate(); + } + + function makeContent( $content, $document_content ) { + $content->addNoScript(); + + $content->addFontFace( "Test", "Tahoma" ); + + $content->addNoAutomaticStyles(); + + $text = $content->getBody()->getText(); + + $text->addNoForms(); + + $content_matches['paragraphs'] = $this->testtranslate->getParagraphs($document_content); + $content_matches['headings'] = $this->testtranslate->getHeadings($document_content); + //print_r($content_matches['headings']); + + foreach($content_matches['paragraphs'] as $paragraph) { + $text->addToText( $text->getTextParagraph( "Paragraph", $paragraph ) ); + } + + foreach($content_matches['headings'] as $heading) { + $text->addToText( $text->getTextHeading( "Heading", $heading ) ); + } + } + + function makeStyle( $style ) { + $NS_STYLE = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; + $NS_FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compartible:1.0"; + + $style->addFontFace( "Test", "Tahoma" ); + + // Set default style + $defStyle = $style->getDefaultStyle( "paragraph" ); + + $defProp = $style->getDom()->createElementNS( $NS_STYLE, "style:paragraph-properties" ); + $defProp->setAttributeNS( $NS_FO, "fo:hypenation-ladder-count", "no-limit" ); + $defProp->setAttributeNS( $NS_STYLE, "style:text-autospace", "ideograph-alpha" ); + $defProp->setAttributeNS( $NS_STYLE, "style:punctuation-wrap", "hanging" ); + $defProp->setAttributeNS( $NS_STYLE, "style:line-break", "strict" ); + $defProp->setAttributeNS( $NS_STYLE, "style:tab-stop-distance", "1.251cm" ); + $defProp->setAttributeNS( $NS_STYLE, "style:writeing-mode", "page" ); + $defStyle->appendChild( $defProp ); + + $defProp = $style->getDom()->createElementNS( $NS_STYLE, "style:text-properties" ); + $defProp->setAttributeNS( $NS_FO, "fo:font-size", "12pt" ); + $defProp->setAttributeNS( $NS_FO, "fo:language", "de" ); + $defProp->setAttributeNS( $NS_FO, "fo:country", "DE" ); + $defProp->setAttributeNS( $NS_FO, "fo:hyphenate", "false" ); + $defProp->setAttributeNS( $NS_FO, "fo:hypenation-remain-char-count", "2" ); + $defProp->setAttributeNS( $NS_FO, "fo:hypenation-push-char-count", "2" ); + $defProp->setAttributeNS( $NS_STYLE, "style:use-window-font-color", "true" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-name", "Times New Roman" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-name-asian", "Arial Unicode MS" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-size-asian", "12pt" ); + $defProp->setAttributeNS( $NS_STYLE, "style:language-asian", "none" ); + $defProp->setAttributeNS( $NS_STYLE, "style:country-asian", "none" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-name-complex", "Tahoma" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-site-complex", "12pt" ); + $defProp->setAttributeNS( $NS_STYLE, "style:language-complex", "none" ); + $defProp->setAttributeNS( $NS_STYLE, "style:country-complex", "none" ); + $defStyle->appendChild( $defProp ); + + $style->addDefaultStyle( $defStyle ); + + //Set a style + $aStyle = $style->getStyle( "Paragraph" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:family", "paragraph" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:class", "text" ); + + $style->addStyle( $aStyle, "Paragraph" ); + + //Set a style + $aStyle = $style->getStyle( "Heading" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:family", "paragraph" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:class", "text" ); + + $aStyleProp = $style->getDom()->createElementNS( $NS_STYLE, "style:paragraph-properties" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:margin-top", "0.423cm" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:margin-bottom", "0.212cm" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:keep-with-next", "always" ); + $aStyle->appendChild( $aStyleProp ); + + $aStyleProp = $style->getDom()->createElementNS( $NS_STYLE, "style:text-properties" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:font-size", "20pt" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name", "Arial" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name-asian", "MS Mincho" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-size-asian", "20pt" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name-complex", "Tahoma1" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-size-complex", "20pt" ); + $aStyle->appendChild( $aStyleProp ); + + $style->addStyle( $aStyle, "Paragraph" ); + } + + function run($post) { + if (!function_exists('gzencode')) { + $out = "<p>You have to enable zlib at compile time of your PHP! "; + $out .= "use <emph>--with-zlib=[DIR]</emph> at the <emph>configure</emph> "; + $out .= "procedure</p>"; + echo $out; + return; + } + + $SingleDocument = ($post["SingleDocument"] == "true"); + $creator = $post["Creator"]; + $title = $post["Title"]; + $document_content = $post["Content"]; + + header( "Content-type: application/odt" ); + header( "Content-Disposition: attachment; filename=".self::DocumentName ); + header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 + header( "Cache-Control: post-check=0, pre-check=0", false ); + header( "Pragma: no-cache" ); + + // Get a OpenDocument object from the factory: + + if(isset($SingleDocument)) + { + $TestDoc = OpenDocumentFactory::createOpenDocument( + self::DocumentName, + self::PathToDocument, + $SingleDocument + ); + + /* + $TestDoc->attachObserverToLogger( $this->logger ); + */ + + $this->makeMeta( $TestDoc->getMeta(), $creator, $title, "en-EN" ); + $this->makeStyle( $TestDoc->getStyle() ); + $this->makeContent( $TestDoc->getContent(), $document_content ); + + echo $TestDoc->get(); + + //$TestDoc->save(); + } + + + } +} + +if(isset($_POST['SingleDocument'])) +{ + $TestOutput = new OpenDocumentOutput(); + $TestOutput->run($_POST); +} + +// Do TestInput again ... +?> Property changes on: poc/src/OpenDocumentOutput.php ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Modified: poc/src/samples/TestInput.php =================================================================== --- poc/src/samples/TestInput.php 2006-03-11 00:11:52 UTC (rev 15) +++ poc/src/samples/TestInput.php 2006-03-11 18:20:53 UTC (rev 16) @@ -6,7 +6,7 @@ * @author Norman Markgraf <nma...@us...> * @author Alex Latchford <yaw...@us...> * @version $Revision$ - * @package OpenDocument/Samples + * @package OpenDocument/input * @since 0.4.2 * * $Id$ @@ -17,7 +17,7 @@ <title>TestOutput File!</title> </head> <body> - <form method="POST" action="TestOutput.php"> + <form method="POST" action="./../OpenDocumentOutput.php"> <fieldset> <legend>Generate a sample OpenDocument:</legend> <fieldset> @@ -40,6 +40,7 @@ </fieldset> <fieldset> <legend>Document Content:</legend> + <p>Please input your content with HTML formatting.</p> <textarea rows="10" cols="50" id="content" name="Content"></textarea> </fieldset> <legend>Try it:</legend> Deleted: poc/src/samples/TestOutput.php =================================================================== --- poc/src/samples/TestOutput.php 2006-03-11 00:11:52 UTC (rev 15) +++ poc/src/samples/TestOutput.php 2006-03-11 18:20:53 UTC (rev 16) @@ -1,183 +0,0 @@ -<?php -/** - * SampleClass produces a little OpenDocument and send it to the client - * - * @copyright GNU General Public License - * @author Norman Markgraf <nma...@us...> - * @author Alex Latchford <yaw...@us...> - * @version $Revision$ - * @package OpenDocument/Samples - * @since 0.4.2 - * - * $Id$ - */ - -ini_set( "include_path", ini_get( "include_path" ). ";..\\" ); - -require_once( "OpenDocumentFactory.php" ); -require_once( "Log/observer.php" ); - -class TestOutput { - - const DocumentName = "test.odt"; - - const PathToDocument = "D:/PHP/OpenDocument/"; - - private $logger; - - function __construct() { - $conf = array( "mode" => 0600 ); - $this->logger = &Log::factory( "file", "D:/PHP/OpenDocument.log", "OpenDocument", $conf ); - $this->logger = &Log::factory( "console", "", "OpenDocument" ); - } - - function makeMeta( $meta, $creator="Norman Markgraf", $title="This is a test!", $language="en-EN" ) { - $meta->addDublinCore( "title", $title ); - $meta->addDublinCore( "creator", $creator ); - $meta->addDublinCore( "language", "en-EN" ); - $meta->addDublinCore( "date", date("Y-m-d\TH:i:s") ); - $meta->addGenerator( "" ); - $meta->addInitialCreator( $creator ); - $meta->addCreationDate(); - } - - function makeContent( $content ) { - $content->addNoScript(); - - $content->addFontFace( "Test", "Tahoma" ); - - $content->addNoAutomaticStyles(); - - $text = $content->getBody()->getText(); - - $text->addNoForms(); - - $text->addToText( $text->getTextHeading( "Heading", "The first step" ) ); - $text->addToText( $text->getTextParagraph( "Paragraph", "This is a little test!" ) ); - } - - function makeStyle( $style ) { - $NS_STYLE = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; - $NS_FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compartible:1.0"; - - $style->addFontFace( "Test", "Tahoma" ); - - // Set default style - $defStyle = $style->getDefaultStyle( "paragraph" ); - - $defProp = $style->getDom()->createElementNS( $NS_STYLE, "style:paragraph-properties" ); - $defProp->setAttributeNS( $NS_FO, "fo:hypenation-ladder-count", "no-limit" ); - $defProp->setAttributeNS( $NS_STYLE, "style:text-autospace", "ideograph-alpha" ); - $defProp->setAttributeNS( $NS_STYLE, "style:punctuation-wrap", "hanging" ); - $defProp->setAttributeNS( $NS_STYLE, "style:line-break", "strict" ); - $defProp->setAttributeNS( $NS_STYLE, "style:tab-stop-distance", "1.251cm" ); - $defProp->setAttributeNS( $NS_STYLE, "style:writeing-mode", "page" ); - $defStyle->appendChild( $defProp ); - - $defProp = $style->getDom()->createElementNS( $NS_STYLE, "style:text-properties" ); - $defProp->setAttributeNS( $NS_FO, "fo:font-size", "12pt" ); - $defProp->setAttributeNS( $NS_FO, "fo:language", "de" ); - $defProp->setAttributeNS( $NS_FO, "fo:country", "DE" ); - $defProp->setAttributeNS( $NS_FO, "fo:hyphenate", "false" ); - $defProp->setAttributeNS( $NS_FO, "fo:hypenation-remain-char-count", "2" ); - $defProp->setAttributeNS( $NS_FO, "fo:hypenation-push-char-count", "2" ); - $defProp->setAttributeNS( $NS_STYLE, "style:use-window-font-color", "true" ); - $defProp->setAttributeNS( $NS_STYLE, "style:font-name", "Times New Roman" ); - $defProp->setAttributeNS( $NS_STYLE, "style:font-name-asian", "Arial Unicode MS" ); - $defProp->setAttributeNS( $NS_STYLE, "style:font-size-asian", "12pt" ); - $defProp->setAttributeNS( $NS_STYLE, "style:language-asian", "none" ); - $defProp->setAttributeNS( $NS_STYLE, "style:country-asian", "none" ); - $defProp->setAttributeNS( $NS_STYLE, "style:font-name-complex", "Tahoma" ); - $defProp->setAttributeNS( $NS_STYLE, "style:font-site-complex", "12pt" ); - $defProp->setAttributeNS( $NS_STYLE, "style:language-complex", "none" ); - $defProp->setAttributeNS( $NS_STYLE, "style:country-complex", "none" ); - $defStyle->appendChild( $defProp ); - - $style->addDefaultStyle( $defStyle ); - - //Set a style - $aStyle = $style->getStyle( "Paragraph" ); - $aStyle->setAttributeNS ( $NS_STYLE, "style:family", "paragraph" ); - $aStyle->setAttributeNS ( $NS_STYLE, "style:class", "text" ); - - $style->addStyle( $aStyle, "Paragraph" ); - - //Set a style - $aStyle = $style->getStyle( "Heading" ); - $aStyle->setAttributeNS ( $NS_STYLE, "style:family", "paragraph" ); - $aStyle->setAttributeNS ( $NS_STYLE, "style:class", "text" ); - - $aStyleProp = $style->getDom()->createElementNS( $NS_STYLE, "style:paragraph-properties" ); - $aStyleProp->setAttributeNS ( $NS_FO, "fo:margin-top", "0.423cm" ); - $aStyleProp->setAttributeNS ( $NS_FO, "fo:margin-bottom", "0.212cm" ); - $aStyleProp->setAttributeNS ( $NS_FO, "fo:keep-with-next", "always" ); - $aStyle->appendChild( $aStyleProp ); - - $aStyleProp = $style->getDom()->createElementNS( $NS_STYLE, "style:text-properties" ); - $aStyleProp->setAttributeNS ( $NS_FO, "fo:font-size", "20pt" ); - $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name", "Arial" ); - $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name-asian", "MS Mincho" ); - $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-size-asian", "20pt" ); - $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name-complex", "Tahoma1" ); - $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-size-complex", "20pt" ); - $aStyle->appendChild( $aStyleProp ); - - $style->addStyle( $aStyle, "Paragraph" ); - } - - function run($post) { - if (!function_exists('gzencode')) { - $out = "<p>You have to enable zlib at compile time of your PHP! "; - $out .= "use <emph>--with-zlib=[DIR]</emph> at the <emph>configure</emph> "; - $out .= "procedure</p>"; - echo $out; - return; - } - - $SingleDocument = ($post["SingleDocument"] == "true"); - $creator = $post["Creator"]; - $title = $post["Title"]; - - - - header( "Content-type: application/odt" ); - header( "Content-Disposition: attachment; filename=".self::DocumentName ); - header( "Cache-Control: no-store, no-cache, must-revalidate" ); // HTTP/1.1 - header( "Cache-Control: post-check=0, pre-check=0", false ); - header( "Pragma: no-cache" ); - - // Get a OpenDocument object from the factory: - - if(isset($SingleDocument)) - { - $TestDoc = OpenDocumentFactory::createOpenDocument( - self::DocumentName, - self::PathToDocument, - $SingleDocument - ); - - /* - $TestDoc->attachObserverToLogger( $this->logger ); - */ - - $this->makeMeta( $TestDoc->getMeta(), $creator, $title, "en-EN" ); - $this->makeStyle( $TestDoc->getStyle() ); - $this->makeContent( $TestDoc->getContent() ); - - echo $TestDoc->get(); - - //$TestDoc->save(); - } - - - } -} - -if(isset($_POST['SingleDocument'])) -{ - $TestOutput = new TestOutput(); - $TestOutput->run($_POST); -} - -// Do TestInput again ... -?> Added: poc/src/samples/TestTranslate.php =================================================================== --- poc/src/samples/TestTranslate.php (rev 0) +++ poc/src/samples/TestTranslate.php 2006-03-11 18:20:53 UTC (rev 16) @@ -0,0 +1,46 @@ +<?php +/** + * TestTranslate class that will translate a given formatting style to ODF formatting. + * + * @copyright GNU General Public License + * @author Alex Latchford <yaw...@us...> + * @version $Revision$ + * @package OpenDocument/input + * @since 0.4.2 + * + * $Id$ + */ + +require_once( "Log/observer.php" ); + +class TestTranslate { + + private $expression; + private $logger; + private $matches = array(); + + public function __construct() { + $this->logger = &Log::factory( "null", "", "OpenDocument" ); + $this->logger->debug( "Constructing TestTranslate." ); + } + + public function __destruct() { + $this->logger->debug( "Destructing TestTranslate." ); + } + + public function getParagraphs($document_content) { + + $matches = preg_split( "/\n/", $document_content, 0, PREG_SPLIT_NO_EMPTY); + + return $matches; + } + + public function getHeadings($document_content) { + + $matches = preg_split( "/(<h[1-6])+\w.+(<\/h[1-6]>)+/", $document_content, 0, PREG_SPLIT_NO_EMPTY); + + return $matches; + } + +} + ?> \ No newline at end of file Property changes on: poc/src/samples/TestTranslate.php ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |