cvs: pear /OpenDocument/OpenDocument Bookmark.php Element.php ElementStyle.php Exception.php Heading.php Hyperlink.php Paragraph.php Span.php
Style.php StyledElement.php TextElement.php ZipWrapper.php

From: Date: Wed, 30 Aug 2006 18:16:04 +0000
Subject: cvs: pear /OpenDocument/OpenDocument Bookmark.php Element.php ElementStyle.php Exception.php Heading.php Hyperlink.php Paragraph.php Span.php
Style.php StyledElement.php TextElement.php ZipWrapper.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-41928@lists.php.net to get a copy of this message
irokez Wed Aug 30 18:16:04 2006 UTC Added files: /pear/OpenDocument/OpenDocument Bookmark.php Element.php ElementStyle.php Exception.php Heading.php Hyperlink.php Paragraph.php Span.php Style.php StyledElement.php TextElement.php ZipWrapper.php Log:

http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Bookmark.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Bookmark.php +++ pear/OpenDocument/OpenDocument/Bookmark.php <?php require_once 'Element.php'; class OpenDocument_Bookmark extends OpenDocument_Element { private $name; public function __constructor($node, $document, $name) { parent::__constructor($node, $document); $this->name = $name; } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Element.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Element.php +++ pear/OpenDocument/OpenDocument/Element.php <?php /** * OpenDocument_Element abstract class * * OpenDocument_Element absract class - all other elements inherit from this one * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ /** * OpenDocument_Element abstract class * * OpenDocument_Element absract class - all other elements inherit from this one * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ abstract class OpenDocument_Element { /** * Element DOMNode * * @var DOMNode */ protected $node; /** * Element OpenDocument * * @var OpenDocument */ protected $document; /** * Array of allowed documents * * @var array */ protected $allowedElements; /** * ArrayObject of children elements * * @var ArrayObject */ protected $children; /** * Constructor * * @param DOMNode $node * @param OpenDocument $document */ public function __construct(DOMNode $node, OpenDocument $document) { $this->node = $node; $this->document = $document; $this->allowedElements = array(); } /** * Get element DOMNode * * @return DOMNode */ public function getNode() { return $this->node; } /** * Get element document * * @return OpenDocument */ public function getDocument() { return $this->document; } /** * Delete element * */ public function delete() { $this->document->deleteElement($this); } /** * Get element children * * @return ArrayIterator */ public function getChildren() { $this->listChildren(); return $this->children->getIterator(); } /** * Prepare element children * */ protected function listChildren() { $this->children = new ArrayObject; if ($this->node instanceof DOMNode) { $childrenNodes = $this->node->childNodes; foreach ($childrenNodes as $child) { if ($child instanceof DOMText) { $element = new OpenDocument_TextElement($child, $this->document); $this->children->append($element); } else { foreach ($this->allowedElements as $class) { $ReflectionClass = new ReflectionClass($class); $tag = $ReflectionClass->getConstant('nodePrefix') . ':' . $ReflectionClass->getConstant('nodeName'); if ($child->nodeName == $tag) { $element = new $class($child, $this->document); $this->children->append($element); break; } } } } } } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/ElementStyle.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/ElementStyle.php +++ pear/OpenDocument/OpenDocument/ElementStyle.php <?php /** * OpenDocument_ElementStyle class * * OpenDocument_ElementStyle concretes element style object * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'Style.php'; /** * OpenDocument_ElementStyle class * * OpenDocument_ElementStyle concretes element style object * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_ElementStyle extends OpenDocument_Style { /** * Possible properties values * */ const FONT_WEIGHT_BOLD = 'bold', FONT_WEIGHT_NORMAL = 'normal', FONT_STYLE_ITALIC = 'italic', FONT_STYLE_NORMAL = 'normal', UNDERLINE_STYLE_SOLID = 'solid'; /** * List of properties * */ protected $fontWeight, $fontStyle, $fontName, $fontSize, $backgroundColor, $color, $lineHeight, $underlineStyle, $underlineWidth, $underlineColor; /** * Constructor * * @param OpenDocument_StyledElement $element */ public function __construct($element) { $this->map = array( 'fontWeight' => 'fo:font-weight', 'fontStyle' => 'fo:font-style', 'fontName' => 'style:font-name', 'fontSize' => 'fo:font-size', 'backgroundColor' => 'fo:background-color', 'color' => 'fo:color', 'lineHeight' => 'style:line-height', 'underlineStyle' => 'style:text-underline-style', 'underlineWidth' => 'style:text-underline-width', 'underlineColor' => 'style:text-underline-color', ); parent::__construct($element); } /** * Set style value * * @param string $name * @param mixed $value */ protected function __set($name, $value) { if ($name == 'fontName') { $this->element->getDocument()->addFont($value); } parent::__set($name, $value); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Exception.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Exception.php +++ pear/OpenDocument/OpenDocument/Exception.php <?php /** * OpenDocument_Exception class * * OpenDocument_Exception class extends PEAR_Exception * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'PEAR/Exception.php'; /** * OpenDocument_Exception class * * OpenDocument_Exception class extends PEAR_Exception * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_Exception extends PEAR_Exception { /** * Error while accessing OpenDocument file */ const ACCESS_FILE_ERR = 1; /** * Error while loading mimetype file */ const LOAD_MIMETYPE_ERR = 2; /** * Error while loading content file */ const LOAD_CONTENT_ERR = 3; /** * Error while loading meta file */ const LOAD_META_ERR = 4; /** * Error while loading settings file */ const LOAD_SETTINGS_ERR = 5; /** * Error while loading styles file */ const LOAD_STYLES_ERR = 6; /** * Error while loading manifest file */ const LOAD_MANIFEST_ERR = 7; /** * Error while writing mimetype file */ const WRITE_MIMETYPE_ERR = 8; /** * Error while writing content file */ const WRITE_CONTENT_ERR = 9; /** * Error while writing meta file */ const WRITE_META_ERR = 10; /** * Error while writing settings file */ const WRITE_SETTINGS_ERR = 11; /** * Error while writing styles file */ const WRITE_STYLES_ERR = 12; /** * Error while writing manifest file */ const WRITE_MANIFEST_ERR = 13; /** * OpenDocument_Element or OpenDocument expected * */ const ELEM_OR_DOC_EXPECTED = 14; } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Heading.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Heading.php +++ pear/OpenDocument/OpenDocument/Heading.php <?php /** * OpenDocument_Heading class * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'StyledElement.php'; /** * OpenDocument_Heading element * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_Heading extends OpenDocument_StyledElement { /** * Heading level * * @var integer */ private $level; /** * Node namespace */ const nodeNS = OpenDocument::NS_TEXT; /** * Node namespace */ const nodePrefix = 'text'; /** * Node name */ const nodeName = 'h'; /** * Element style name prefix */ const styleNamePrefix = 'H'; /** * Constructor * * @param DOMNode $node * @param OpenDocument $document */ public function __construct(DOMNode $node, OpenDocument $document) { parent::__construct($node, $document); $this->level = $node->getAttributeNS(OpenDocument::NS_TEXT, 'outline-level'); $this->allowedElements = array( 'OpenDocument_Span', 'OpenDocument_Hyperlink', ); } /** * Create OpenDocument_Heading element * * @param mixed $object * @param mixed $content * @param integer $level optional * @return OpenDocument_Heading */ public static function instance($object, $content, $level = 1) { if ($object instanceof OpenDocument) { $document = $object; $node = $object->cursor; } else if ($object instanceof OpenDocument_Element) { $document = $object->getDocument(); $node = $object->getNode(); } else { throw new OpenDocument_Exception(OpenDocument_Exception::ELEM_OR_DOC_EXPECTED); } $element = new OpenDocument_Heading($node->ownerDocument->createElementNS(self::nodeNS, self::nodeName), $document); $node->appendChild($element->node); if (is_scalar($content)) { $element->createTextElement($content); } $element->__set('level', $level); return $element; } /** * Set element properties * * @param string $name * @param mixed $value */ public function __set($name, $value) { switch ($name) { case 'level': if (!is_int($value) && !ctype_digit($value)) { $value = 1; } $this->type = $value; $this->node->setAttributeNS(OpenDocument::NS_TEXT, 'outline-level', $value); break; default: } } /** * Get element properties * * @param string $name * @return mixed */ protected function __get($name) { if ($value = parent::__get($name)) { return $value; } if (isset($this->$name)) { return $this->$name; } } /** * Generate element new style name * * @return string */ public function generateStyleName() { self::$styleNameMaxNumber ++; return self::styleNamePrefix . self::$styleNameMaxNumber; } /************** Elements ***********************/ /** * Create OpenDocument_TextElement * * @param string $text * @return OpenDocument_TextElement */ public function createTextElement($text) { return OpenDocument_TextElement::instance($this, $text); } /** * Create OpenDocument_Hyperlink * * @param string $text * @param string $location * @param string $type optional * @param string $target optional * @param string $name optional * @return OpenDocument_Hyperlink */ public function createHyperlink($text, $location, $type = 'simple', $target = '', $name = '') { return OpenDocument_Hyperlink::instance($this, $text, $location, $type, $target, $name); } /** * Create OpenDocument_Span element * * @param string $text * @return OpenDocument_Span */ public function createSpan($text) { return OpenDocument_Span::instance($this, $text); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Hyperlink.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Hyperlink.php +++ pear/OpenDocument/OpenDocument/Hyperlink.php <?php /** * OpenDocument_Hyperlink class * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'StyledElement.php'; /** * OpenDocument_Hyperlink element * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_Hyperlink extends OpenDocument_StyledElement { /** * Link location * * @var string */ private $location; /** * Link type * * @var string */ private $type; /** * Link target * * @var string */ private $target; /** * Link name * * @var string */ private $name; /** * Node namespace */ const nodeNS = OpenDocument::NS_TEXT; /** * Node namespace */ const nodePrefix = 'text'; /** * Node name */ const nodeName = 'a'; /** * Element style name prefix */ const styleNamePrefix = 'A'; /** * Constructor * * @param DOMNode $node * @param OpenDocument $document */ public function __construct(DOMNode $node, OpenDocument $document) { parent::__construct($node, $document); $this->location = $node->getAttributeNS(OpenDocument::NS_XLINK, 'href'); $this->type = $node->getAttributeNS(OpenDocument::NS_XLINK, 'type'); $this->target = $node->getAttributeNS(OpenDocument::NS_OFFICE, 'target'); $this->name = $node->getAttributeNS(OpenDocument::NS_OFFICE, 'name'); $this->allowedElements = array( 'OpenDocument_Span', ); } /** * Create OpenDocument_Hyperlink instance * * @param mixed $object * @param mixed $content * @param string $location * @param string $type optional * @param string $target optional * @param string $name optional * @return OpenDocument_Hyperlink */ public static function instance($object, $content, $location, $type = 'simple', $target = '', $name = '') { if ($object instanceof OpenDocument) { $document = $object; $node = $object->cursor; } else if ($object instanceof OpenDocument_Element) { $document = $object->getDocument(); $node = $object->getNode(); } else { throw new Exception('Object must be OpenDocument or OpenDocument_Element'); } $element = new OpenDocument_Hyperlink($node->ownerDocument->createElementNS(self::nodeNS, self::nodeName), $document); $node->appendChild($element->node); $element->__set('location', $location); $element->__set('type', $type); $element->__set('target', $target); $element->__set('name', $name); if (is_scalar($content)) { $element->createTextElement($content); } return $element; } /** * Set element property * * @param string $name * @param mixed $value */ public function __set($name, $value) { switch ($name) { case 'location': $this->location = $value; $this->node->setAttributeNS(OpenDocument::NS_XLINK, 'href', $value); break; case 'type': if (!in_array($value, array('simple'))) { $value = 'simple'; } $this->type = $value; $this->node->setAttributeNS(OpenDocument::NS_XLINK, 'type', $value); break; case 'target': $this->target = $value; $this->node->setAttributeNS(OpenDocument::NS_OFFICE, 'target-frame-name', $value); break; case 'name': $this->name = $value; $this->node->setAttributeNS(OpenDocument::NS_OFFICE, 'name', $value); break; default: } } /** * Get element property * * @param string $name * @return mixed */ protected function __get($name) { /*if ($value = parent::__get($name)) { return $value; }*/ if (isset($this->$name)) { return $this->$name; } } /** * Generate element new style name * * @return string */ public function generateStyleName() { self::$styleNameMaxNumber ++; return self::styleNamePrefix . self::$styleNameMaxNumber; } /************** Elements ***********************/ /** * Create OpenDocument_TextElement * * @param string $text * @return OpenDocument_TextElement */ public function createTextElement($text) { return OpenDocument_TextElement::instance($this, $text); } /** * Create OpenDocument_Span element * * @param string $text * @return OpenDocument_Span */ public function createSpan($text) { return OpenDocument_Span::instance($this, $text); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Paragraph.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Paragraph.php +++ pear/OpenDocument/OpenDocument/Paragraph.php <?php /** * OpenDocument_Paragraph class * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'StyledElement.php'; /** * OpenDocument_Paragraph element * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_Paragraph extends OpenDocument_StyledElement { /** * Node namespace */ const nodeNS = OpenDocument::NS_TEXT; /** * Node namespace */ const nodePrefix = 'text'; /** * Node name */ const nodeName = 'p'; /** * Element style name prefix * */ const styleNamePrefix = 'P'; /** * Constructor * * @param DOMNode $node * @param OpenDocument $document */ public function __construct(DOMNode $node, OpenDocument $document) { parent::__construct($node, $document); $this->allowedElements = array( 'OpenDocument_Span', 'OpenDocument_Hyperlink', ); } /** * Create element instance * * @param mixed $object * @param mixed $content * @return OpenDocument_Paragraph * @throws OpenDocument_Exception */ public static function instance($object, $content) { if ($object instanceof OpenDocument) { $document = $object; $node = $object->cursor; } else if ($object instanceof OpenDocument_Element) { $document = $object->getDocument(); $node = $object->getNode(); } else { throw new OpenDocument_Exception(OpenDocument_Exception::ELEM_OR_DOC_EXPECTED); } $element = new OpenDocument_Paragraph($node->ownerDocument->createElementNS(self::nodeNS, self::nodeName), $document); $node->appendChild($element->node); if (is_scalar($content)) { $element->createTextElement($content); } return $element; } /** * Generate element new style name * * @return string */ public function generateStyleName() { self::$styleNameMaxNumber ++; return self::styleNamePrefix . self::$styleNameMaxNumber; } /************** Elements ****************/ /** * Create OpenDocument_TextElement * * @param string $text * @return OpenDocument_TextElement */ public function createTextElement($text) { return OpenDocument_TextElement::instance($this, $text); } /** * Create OpenDocument_Hyperlink * * @param string $text * @param string $location * @param string $type optional * @param string $target optional * @param string $name optional * @return OpenDocument_Hyperlink */ public function createHyperlink($text, $location, $type = 'simple', $target = '', $name = '') { return OpenDocument_Hyperlink::instance($this, $text, $location, $type, $target, $name); } /** * Create OpenDocument_Span element * * @param string $text * @return OpenDocument_Span */ public function createSpan($text) { return OpenDocument_Span::instance($this, $text); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Span.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Span.php +++ pear/OpenDocument/OpenDocument/Span.php <?php /** * OpenDocument_Span class * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'StyledElement.php'; /** * OpenDocument_Span element * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_Span extends OpenDocument_StyledElement { /** * Node namespace */ const nodeNS = OpenDocument::NS_TEXT; /** * Node amespace */ const nodePrefix = 'text'; /** * Node name */ const nodeName = 'span'; /** * Element style name prefix */ const styleNamePrefix = 'T'; /** * Create element instance * * @param mixed $object * @param mixed $content * @return OpenDocument_Span * @throws OpenDocument_Exception */ public static function instance($object, $content) { if ($object instanceof OpenDocument) { $document = $object; $node = $object->cursor; } else if ($object instanceof OpenDocument_Element) { $document = $object->getDocument(); $node = $object->getNode(); } else { throw new OpenDocument_Exception(OpenDocument_Exception::ELEM_OR_DOC_EXPECTED); } $element = new OpenDocument_Span($node->ownerDocument->createElementNS(self::nodeNS, self::nodeName), $document); $node->appendChild($element->node); if (is_scalar($content)) { $element->createTextElement($content); } return $element; } /** * Generate new style name * * @return string $stylename */ public function generateStyleName() { self::$styleNameMaxNumber ++; return self::styleNamePrefix . self::$styleNameMaxNumber; } /************** Elements ****************/ /** * Create OpenDocument_TextElement * * @param string $text * @return OpenDocument_TextElement */ public function createTextElement($text) { return OpenDocument_TextElement::instance($this, $text); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/Style.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/Style.php +++ pear/OpenDocument/OpenDocument/Style.php <?php /** * OpenDocument_Style abstract class * * OpenDocument_Style absract class - handles element style * all other elements inherit from this one * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ /** * OpenDocument_Style abstract class * * OpenDocument_Style absract class - handles element style * all other elements inherit from this one * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ abstract class OpenDocument_Style { /** * OpenDocument Element * * @var OpenDocument_StyledElement */ protected $element; /** * Style map of properties * * @var array */ protected $map; /** * Constructor * * @param OpenDocument_StyledElement $element */ public function __construct(OpenDocument_StyledElement $element) { $this->element = $element; $this->loadStyle(); } /** * Load element style information * */ private function loadStyle() { $map = array_flip($this->map); $style = $this->element->getStyle(array_keys($map)); foreach ($style as $name => $value) { if (isset($map[$name])) { $this->$map[$name] = $value; } } } /** * Magic method * Set property value * * @param string $name * @param mixed $value */ protected function __set($name, $value) { if (isset($this->map[$name])) { $this->element->applyStyle($this->map[$name], $value); $this->$name = $value; } } /** * Magic method * Get property value * * @param string $name * @return mixed */ protected function __get($name) { if (isset($this->$name)) { return $this->$name; } else { return null; } } /** * Export style information * * @return array */ public function export() { $style = array(); foreach ($this->map as $name => $value) { $style[$name] = $this->__get($name); } return $style; } /** * Import style information * * @param array $style */ public function import($style) { foreach ($style as $name => $value) { if (isset($this->map[$name])) { $this->__set($name, $value); } } } /** * Copy style from another element * * @param OpenDocument_Style $styleObject */ public function copy(OpenDocument_Style $styleObject) { $style = $styleObject->export(); $this->import($style); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/StyledElement.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/StyledElement.php +++ pear/OpenDocument/OpenDocument/StyledElement.php <?php /** * OpenDocument_StyledElement abstract class * * OpenDocument_StyledElement absract class - all elements that have styles inherit from this one * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'Element.php'; require_once 'ElementStyle.php'; /** * OpenDocument_StyledElement abstract class * * OpenDocument_StyledElement absract class - all elements that have styles inherit from this one * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ abstract class OpenDocument_StyledElement extends OpenDocument_Element { /** * Style information * * @var array */ protected $style; /** * Style name suffix max value * * @var integer */ protected static $styleNameMaxNumber = 0; /** * Style name prefix * */ const styleNamePrefix = 'E'; /** * Generate new style name * */ abstract public function generateStyleName(); /** * Constructor * * @param DOMNode $node * @param OpenDocument $document */ public function __construct(DOMNode $node, OpenDocument $document) { parent::__construct($node, $document); $this->style = new OpenDocument_ElementStyle($this); } /** * Magic method * Get property value * * @param string $name * @return mixed */ protected function __get($name) { if ($name == 'style') { return $this->style; } } /** * Get style information * * @param array $properties * @return array */ public function getStyle($properties) { return $this->document->getStyle($this->getStyleName(), $properties); } /** * Get style name * * @return string */ public function getStyleName() { return $this->node->getAttributeNS(OpenDocument::NS_TEXT, 'style-name'); } /** * Get style name prefix * * @return string */ public function getStyleNamePrefix() { return $this->styleNamePrefix; } /** * Get style name suffix max value * * @return integer */ public static function getStyleNameMaxNumber() { return self::$styleNameMaxNumber; } /** * Set style name suxxif max value * * @param integer $number */ public static function setStyleNameMaxNumber($number) { self::$styleNameMaxNumber = $number; } /** * Apply style information * * @param string $name * @param mixed $value */ public function applyStyle($name, $value) { $style_name = $this->node->getAttributeNS(OpenDocument::NS_TEXT, 'style-name'); $style_name = $this->document->applyStyle($style_name, $name, $value, $this); $this->node->setAttributeNS(OpenDocument::NS_TEXT, 'style-name', $style_name); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/TextElement.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/TextElement.php +++ pear/OpenDocument/OpenDocument/TextElement.php <?php /** * OpenDocument_TextElement class * * OpenDocument_TextElement represents text in OpenDocument * * PHP version 5 * * LICENSE: This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ require_once 'Element.php'; /** * OpenDocument_TextElement class * * OpenDocument_TextElement represents text in OpenDocument * * @category File Formats * @package OpenDocument * @author Alexander Pak <irokez@gmail.com> * @license http://www.gnu.org/copyleft/lesser.html Lesser General Public License 2.1 * @version 0.1.0 * @link http://pear.php.net/package/OpenDocument * @since File available since Release 0.1.0 */ class OpenDocument_TextElement extends OpenDocument_Element { /** * Element text * * @var string */ private $text; /** * Constructor * * @param DOMNode $node * @param OpenDocument $document */ public function __construct(DOMNode $node, OpenDocument $document) { parent::__construct($node, $document); $this->text = $node->wholeText; } /** * Create object instance * * @param mixed $object * @param string $text * @return OpenDocument_TextElement */ public static function instance($object, $text) { if ($object instanceof OpenDocument) { $document = $object; $node = $object->cursor; } else if ($object instanceof OpenDocument_Element) { $document = $object->getDocument(); $node = $object->getNode(); } else { throw new Exception('Object must be OpenDocument or OpenDocument_Element'); } $element = new OpenDocument_TextElement($node->ownerDocument->createTextNode($text), $document); $node->appendChild($element->node); $element->text = $text; return $element; } /** * Magic method * Set property value * * @param string $name * @param mixed $value */ protected function __set($name, $value) { switch ($name) { case 'text': $this->text = $value; $this->setText($value); break; default: } } /** * Magic method * Get property value * * @param string $name * @return mixed */ protected function __get($name) { if (isset($this->$name)) { return $this->$name; } } /** * Set element text * * @param string $text */ private function setText($text) { $node = $this->node->ownerDocument->createTextNode($text); $this->node->parentNode->replaceChild($node, $this->node); } } ?> http://cvs.php.net/viewvc.cgi/pear/OpenDocument/OpenDocument/ZipWrapper.php?view=markup&rev=1.1 Index: pear/OpenDocument/OpenDocument/ZipWrapper.php +++ pear/OpenDocument/OpenDocument/ZipWrapper.php <?php class ZipWrapper { public static function read($archive, $filename) { $zip = new ZipArchive; if (file_exists($archive)) { if ($zip->open(realpath($archive))) { if ($zip->locateName($filename) !== false) { return $zip->getFromName($filename); } } } return false; } public static function write($archive, $filename, $content) { $zip = new ZipArchive; if (file_exists($archive)) { $zip->open(realpath($archive)); } else { $zip->open(getcwd() . '/' . $archive, ZipArchive::CREATE); } if ($zip->locateName($filename) !== false) { $zip->deleteName($filename); } $error = $zip->addFromString($filename, $content); return $error; } } ?>
« previous php.pear.cvs (#41928) next »