OpenDocumentPHP
[ class tree: OpenDocumentPHP ] [ index: OpenDocumentPHP ] [ all elements ]

Source for file MetaFragment.php

Documentation is available at MetaFragment.php

  1. <?php
  2. /*
  3.  * Created on 10.01.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the GPL. For more information please see
  19.  * <http://opendocumentphp.org>.
  20.  * 
  21.  * $Id: MetaFragment.php 183 2007-06-12 07:58:41Z nmarkgraf $
  22.  */
  23. require_once 'OpenDocumentPHP/util/Fragment.php';
  24. /**
  25.  * MetaFragment class.
  26.  *  
  27.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  28.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  29.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  30.  * @version        $Revision: 183 $
  31.  * @package        OpenDocumentPHP
  32.  * @subpackage    meta
  33.  * @since         0.5.0 - 08.02.2007
  34.  */
  35. class MetaFragment extends Fragment {
  36.     /**
  37.      * @var         DOMElement 
  38.      * @access        private
  39.      * @since         0.5.0 - 08.02.2007
  40.      */
  41.     private $generator null;
  42.     /**
  43.      * @var         DOMElement 
  44.      * @access        private
  45.      * @since         0.5.0 - 08.02.2007
  46.      */
  47.     private $initialCreator null;
  48.     /**
  49.      * @var         DOMElement 
  50.      * @access        private
  51.      * @since         0.5.0 - 08.02.2007
  52.      */
  53.     private $creationDate null;
  54.     /**
  55.      * @var         DOMElement 
  56.      * @access        private
  57.      * @since         0.5.0 - 08.02.2007
  58.      */
  59.     private $printedBy null;
  60.     /**
  61.      * @var         DOMElement 
  62.      * @access        private
  63.      * @since         0.5.0 - 08.02.2007
  64.      */
  65.     private $printDate null;
  66.     /**
  67.      * @var         DOMElement 
  68.      * @access        private
  69.      * @since         0.5.0 - 08.02.2007
  70.      */
  71.     private $editDuration null;
  72.     /**
  73.      * @var            array ...
  74.      * @access        private
  75.      * @since         0.5.0 - 08.02.2007
  76.          */
  77.     private $keywords null;
  78.     /**
  79.      * @var            array ...
  80.      * @access        private
  81.      * @since         0.5.0 - 08.02.2007
  82.      */
  83.     private $userDefineds null;
  84.     /**
  85.      * Constructor method.
  86.      * 
  87.      * @since         0.5.0 - 08.02.2007
  88.      */
  89.     function __construct($domFragment$root{
  90.         parent :: __construct($domFragment$root);
  91.         $this->keywords array ();
  92.         $this->userDefineds array (
  93.             'Info 1' => '',
  94.             'Info 2' => '',
  95.             'Info 3' => '',
  96.             'Info 4' => ''
  97.         );
  98.         $this->root = $root;
  99.         $this->initXpath();
  100.         //setlocale(LC_TIME, 'de_DE');
  101.         $this->setGenerator();
  102.         $this->setCreationDate();
  103.         //        $this->setUserDefinedArray($this->userDefineds);
  104.     }
  105.     /**
  106.      *
  107.      * 
  108.      * @access        public
  109.      * @since         0.5.0 - 08.02.2007
  110.      */
  111.     protected function getTag($tag$defaultValue{
  112.         return parent :: getTag('//*/office:meta/' $tagself :: META$tag$defaultValue);
  113.     }
  114.     /**
  115.      * 
  116.      * @deprecated  0.5.1 - 09.02.2007
  117.      * @access        public
  118.      * @since         0.5.0 - 08.02.2007
  119.      */
  120.     function getDocumentFragment({
  121.         return null;
  122.     }
  123.     /**
  124.      * Retrieve the so called initial-creator. This should be the first author of this document.
  125.      * 
  126.      * In a meta document, if there is a tag like this one
  127.      * <code>
  128.      * <meta:initial-creator>Alex Latchford</meta:initial-creator>
  129.      * <code>
  130.      * this method will return "Alex Latchford" as a string.
  131.      * 
  132.      * @return        String The initial creator of this document.
  133.      * @access        public
  134.      * @since         0.5.0 - 08.02.2007
  135.      */
  136.     function getInitialCreator({
  137.         if (!isset ($this->initialCreator)) {
  138.             $this->initialCreator $this->getTag('meta:initial-creator''');
  139.         }
  140.         return $this->initialCreator->nodeValue;
  141.     }
  142.     /**
  143.      * Put the so called initial-creator into the current meta document. The initial creator should be the first
  144.      * author of an OpenDocument and should allways be put in.
  145.      * 
  146.      * If you write something like:
  147.      * <code>
  148.      *     $metaDoc->setInitialCreator('Norman Markgraf');
  149.      * </code>
  150.      * to a MetaDocument $metaDoc, the initial creator is set to the string 'Norman Markgraf'.
  151.      * 
  152.      * @param        String    $creator The new initial creator of this OpenDocument.
  153.      * @access        public
  154.      * @since         0.5.0 - 08.02.2007
  155.      */
  156.     function setInitialCreator($creator{
  157.         if ($this->getInitialCreator(!= $creator{
  158.             $newNode $this->domFragment->createElementNS(self :: META'meta:initial-creator'$creator);
  159.             $this->setTag($this->initialCreator$newNode);
  160.             $this->initialCreator $newNode;
  161.         }
  162.     }
  163.     /**
  164.      * Retrieve the generator tag. The generator is the name of the programm on which the current OpenDocument was
  165.      * generated.
  166.      * 
  167.      * 
  168.      * @return        String The generator tag.
  169.      * @access        public
  170.      * @since         0.5.0 - 08.02.2007
  171.      */
  172.     function getGenerator({
  173.         if (!isset ($this->generator)) {
  174.             $this->generator $this->getTag('meta:generator''');
  175.         }
  176.         return $this->generator->nodeValue;
  177.     }
  178.     /**
  179.      * Put the generator tag into the meta document. If called with no parameter the generator tag will be set to:
  180.      * 'OpenDocumentPHP/$Revision: 183 $', as this is the default value
  181.      * 
  182.      * @param        String The new generator tag.
  183.      * @access        public
  184.      * @since         0.5.0 - 08.02.2007
  185.      */
  186.     function setGenerator($generator 'OpenDocumentPHP/$Revision: 183 $'{
  187.         if ($this->getGenerator(!= $generator{
  188.             $newNode $this->domFragment->createElementNS(self :: META'meta:generator'$generator);
  189.             $this->setTag($this->generator$newNode);
  190.             $this->generator $newNode;
  191.         }
  192.     }
  193.     /**
  194.      *
  195.      * 
  196.      * @access        public
  197.      * @since         0.5.0 - 08.02.2007
  198.      */
  199.     protected function makeCreationDate($s null{
  200.         $ret $s;
  201.         if (is_null($s)) {
  202.             $ret date('c');
  203.         else {
  204.             if (is_string($s)) {
  205.                 if (($time strtotime($s)) === -1{
  206.                     // *** FIX ME ***
  207.                     echo "**FIX ME**";    
  208.                 }else {
  209.                 $ret date('c'strtotime($s));
  210.                 }    
  211.             else {
  212.                 $ret date('c'$s);
  213.             }
  214.         }
  215.         return $ret;
  216.     }
  217.     /**
  218.      * Retrieve the creation date of this document.
  219.      * 
  220.      * @return 
  221.      * @access        public
  222.      * @since         0.5.0 - 08.02.2007
  223.      */
  224.     function getCreationDate({
  225.         if (!isset ($this->creationDate)) {
  226.             $this->creationDate $this->getTag('meta:creation-date'$this->makeCreationDate());
  227.         }
  228.         return $this->creationDate->nodeValue;
  229.     }
  230.     /**
  231.      * Put the creation date into the meta document. If no date parameter where given, the current date
  232.      * will be used.
  233.      * 
  234.      * @param 
  235.      * @access        public
  236.      * @since         0.5.0 - 08.02.2007
  237.      */
  238.     function setCreationDate($date null{
  239.         $tmpdate $this->makeCreationDate($date);
  240.         if ($this->getCreationDate(!= $tmpdate{
  241.             $newNode $this->domFragment->createElementNS(self :: META'meta:creation-date'$tmpdate);
  242.             $this->setTag($this->creationDate$newNode);
  243.             $this->creationDate $newNode;
  244.         }
  245.     }
  246.     /**
  247.      * 
  248.      * 
  249.      * @access        public
  250.      * @since         0.5.0 - 08.02.2007
  251.      */
  252.     function getPrintDate({
  253.         if (!isset ($this->printDate)) {
  254.             $this->printDate $this->getTag('meta:print-date''');
  255.         }
  256.         return $this->printDate->nodeValue;
  257.     }
  258.     /**
  259.      * 
  260.      * 
  261.      * @access        public
  262.      * @since         0.5.0 - 08.02.2007
  263.      */
  264.     function setPrintDate($date null{
  265.         $tmpdate $this->makeCreationDate($date);
  266.         if ($this->getPrintDate(!= $tmpdate{
  267.             $newNode $this->domFragment->createElementNS(self :: META'meta:print-date'$date);
  268.             $this->setTag($this->printDate$newNode);
  269.             $this->printDate $newNode;
  270.         }
  271.     }
  272.     /**
  273.      * 
  274.      * @param          array $userDefined 
  275.      * @access        public
  276.      * @since         0.5.2 - 03.03.2007
  277.      */
  278.     function setUserDefinedArray(array $userDefined{
  279.         foreach ($userDefined as $name => $value{
  280.             $this->setUserDefined($name$value);
  281.         }
  282.     }
  283.     /**
  284.      *
  285.      * @param        string $name 
  286.      * @param         string $value 
  287.      * @access        public
  288.      * @since         0.5.2 - 03.03.2007
  289.      */
  290.     function setUserDefined($name$value{
  291.         $oldNode $this->getTag('meta:user-defined/[meta:name="' $name '"]'$value);
  292.         $newNode $this->domFragment->createElementNS(self :: META'meta:user-defined');
  293.         $newNode->setAttributeNS(self :: META'meta:name'$value);
  294.         $this->setTag($oldNode$newNode);
  295.     }
  296. }
  297. ?>

Documentation generated on Tue, 12 Jun 2007 10:00:13 +0200 by phpDocumentor 1.3.2