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

Source for file MetaFragment.php

Documentation is available at MetaFragment.php

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

Documentation generated on Wed, 18 Jun 2008 06:30:00 +0200 by phpDocumentor 1.3.2