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

Source for file Rels.php

Documentation is available at Rels.php

  1. <?php
  2. /**
  3.  * PHPPowerPoint
  4.  *
  5.  * Copyright (c) 2009 - 2010 PHPPowerPoint
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPPowerPoint
  22.  * @package    PHPPowerPoint_Writer_PowerPoint2007
  23.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    0.1.0, 2009-04-27
  26.  */
  27.  
  28.  
  29. /** PHPPowerPoint */
  30. require_once 'PHPPowerPoint.php';
  31.  
  32. /** PHPPowerPoint_Slide */
  33. require_once 'PHPPowerPoint/Slide.php';
  34.  
  35. /** PHPPowerPoint_Writer_PowerPoint2007 */
  36. require_once 'PHPPowerPoint/Writer/PowerPoint2007.php';
  37.  
  38. /** PHPPowerPoint_Writer_PowerPoint2007_WriterPart */
  39. require_once 'PHPPowerPoint/Writer/PowerPoint2007/WriterPart.php';
  40.  
  41. /** PHPPowerPoint_Shared_XMLWriter */
  42. require_once 'PHPPowerPoint/Shared/XMLWriter.php';
  43.  
  44.  
  45. /**
  46.  * PHPPowerPoint_Writer_PowerPoint2007_Rels
  47.  *
  48.  * @category   PHPPowerPoint
  49.  * @package    PHPPowerPoint_Writer_PowerPoint2007
  50.  * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
  51.  */
  52. {
  53.     /**
  54.      * Write relationships to XML format
  55.      *
  56.      * @param     PHPPowerPoint    $pPHPPowerPoint 
  57.      * @return     string         XML Output
  58.      * @throws     Exception
  59.      */
  60.     public function writeRelationships(PHPPowerPoint $pPHPPowerPoint null)
  61.     {
  62.         // Create XML writer
  63.         $objWriter null;
  64.         if ($this->getParentWriter()->getUseDiskCaching()) {
  65.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  66.         else {
  67.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
  68.         }
  69.  
  70.         // XML header
  71.         $objWriter->startDocument('1.0','UTF-8','yes');
  72.  
  73.         // Relationships
  74.         $objWriter->startElement('Relationships');
  75.         $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/package/2006/relationships');
  76.  
  77.             // Relationship docProps/app.xml
  78.             $this->_writeRelationship(
  79.                 $objWriter,
  80.                 3,
  81.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
  82.                 'docProps/app.xml'
  83.             );
  84.  
  85.             // Relationship docProps/core.xml
  86.             $this->_writeRelationship(
  87.                 $objWriter,
  88.                 2,
  89.                 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
  90.                 'docProps/core.xml'
  91.             );
  92.  
  93.             // Relationship ppt/presentation.xml
  94.             $this->_writeRelationship(
  95.                 $objWriter,
  96.                 1,
  97.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
  98.                 'ppt/presentation.xml'
  99.             );
  100.  
  101.         $objWriter->endElement();
  102.  
  103.         // Return
  104.         return $objWriter->getData();
  105.     }
  106.  
  107.     /**
  108.      * Write presentation relationships to XML format
  109.      *
  110.      * @param     PHPPowerPoint    $pPHPPowerPoint 
  111.      * @return     string         XML Output
  112.      * @throws     Exception
  113.      */
  114.     public function writePresentationRelationships(PHPPowerPoint $pPHPPowerPoint null)
  115.     {
  116.         // Create XML writer
  117.         $objWriter null;
  118.         if ($this->getParentWriter()->getUseDiskCaching()) {
  119.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  120.         else {
  121.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
  122.         }
  123.  
  124.         // XML header
  125.         $objWriter->startDocument('1.0','UTF-8','yes');
  126.  
  127.         // Relationships
  128.         $objWriter->startElement('Relationships');
  129.         $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/package/2006/relationships');
  130.  
  131.             // Relationship slideMasters/slideMaster1.xml
  132.             $this->_writeRelationship(
  133.                 $objWriter,
  134.                 1,
  135.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster',
  136.                 'slideMasters/slideMaster1.xml'
  137.             );
  138.             
  139.             // Relationship theme/theme1.xml
  140.             $this->_writeRelationship(
  141.                 $objWriter,
  142.                 2,
  143.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
  144.                 'theme/theme1.xml'
  145.             );
  146.  
  147.             // Relationships with slides
  148.             $slideCount $pPHPPowerPoint->getSlideCount();
  149.             for ($i 0$i $slideCount++$i{
  150.                 $this->_writeRelationship(
  151.                     $objWriter,
  152.                     ($i 2),
  153.                     'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide',
  154.                     'slides/slide' ($i 1'.xml'
  155.                 );
  156.             }
  157.  
  158.         $objWriter->endElement();
  159.  
  160.         // Return
  161.         return $objWriter->getData();
  162.     }
  163.     
  164.     /**
  165.      * Write slide master relationships to XML format
  166.      *
  167.      * @return     string             XML Output
  168.      * @throws     Exception
  169.      */
  170.     public function writeSlideMasterRelationships()
  171.     {
  172.         // Create XML writer
  173.         $objWriter null;
  174.         if ($this->getParentWriter()->getUseDiskCaching()) {
  175.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  176.         else {
  177.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
  178.         }
  179.  
  180.         // XML header
  181.         $objWriter->startDocument('1.0','UTF-8','yes');
  182.  
  183.         // Relationships
  184.         $objWriter->startElement('Relationships');
  185.         $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/package/2006/relationships');
  186.  
  187.             // Write slideLayout relationships
  188.             $layoutPack        $this->getParentWriter()->getLayoutPack();
  189.             for ($i 0$i count($layoutPack->getLayouts())++$i{
  190.                 $this->_writeRelationship(
  191.                     $objWriter,
  192.                     $i 1,
  193.                     'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout',
  194.                     '../slideLayouts/slideLayout' ($i 1'.xml'
  195.                 );
  196.             }
  197.  
  198.             // Relationship theme/theme1.xml
  199.             $this->_writeRelationship(
  200.                 $objWriter,
  201.                 count($layoutPack->getLayouts()) 1,
  202.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
  203.                 '../theme/theme1.xml'
  204.             );
  205.  
  206.         $objWriter->endElement();
  207.  
  208.         // Return
  209.         return $objWriter->getData();
  210.     }
  211.     
  212.     /**
  213.      * Write slide layout relationships to XML format
  214.      *
  215.      * @return     string             XML Output
  216.      * @throws     Exception
  217.      */
  218.     public function writeSlideLayoutRelationships()
  219.     {
  220.         // Create XML writer
  221.         $objWriter null;
  222.         if ($this->getParentWriter()->getUseDiskCaching()) {
  223.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  224.         else {
  225.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
  226.         }
  227.  
  228.         // XML header
  229.         $objWriter->startDocument('1.0','UTF-8','yes');
  230.  
  231.         // Relationships
  232.         $objWriter->startElement('Relationships');
  233.         $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/package/2006/relationships');
  234.  
  235.             // Write slideMaster relationship
  236.             $this->_writeRelationship(
  237.                 $objWriter,
  238.                 1,
  239.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster',
  240.                 '../slideMasters/slideMaster1.xml'
  241.             );
  242.  
  243.         $objWriter->endElement();
  244.  
  245.         // Return
  246.         return $objWriter->getData();
  247.     }
  248.  
  249.     /**
  250.      * Write slide relationships to XML format
  251.      *
  252.      * Numbering is as follows:
  253.      *     rId1                 - Drawings
  254.      *
  255.      * @param     PHPPowerPoint_Slide        $pSlide 
  256.      * @param     int                        $pSlideId 
  257.      * @return     string                     XML Output
  258.      * @throws     Exception
  259.      */
  260.     public function writeSlideRelationships(PHPPowerPoint_Slide $pSlide null$pSlideId 1)
  261.     {
  262.         // Create XML writer
  263.         $objWriter null;
  264.         if ($this->getParentWriter()->getUseDiskCaching()) {
  265.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  266.         else {
  267.             $objWriter new PHPPowerPoint_Shared_XMLWriter(PHPPowerPoint_Shared_XMLWriter::STORAGE_MEMORY);
  268.         }
  269.  
  270.         // XML header
  271.         $objWriter->startDocument('1.0','UTF-8','yes');
  272.  
  273.         // Relationships
  274.         $objWriter->startElement('Relationships');
  275.         $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/package/2006/relationships');
  276.             
  277.             // Starting relation id
  278.             $relId 1;
  279.             
  280.             // Write slideLayout relationship
  281.             $layoutPack        $this->getParentWriter()->getLayoutPack();
  282.             $layoutIndex    $layoutPack->findlayoutIndex$pSlide->getSlideLayout() );
  283.  
  284.             $this->_writeRelationship(
  285.                 $objWriter,
  286.                 $relId++,
  287.                 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout',
  288.                 '../slideLayouts/slideLayout' ($layoutIndex 1'.xml'
  289.             );
  290.                         
  291.             // Write drawing relationships?
  292.             if ($pSlide->getShapeCollection()->count(0{
  293.                 // Loop trough images and write relationships
  294.                 $iterator $pSlide->getShapeCollection()->getIterator();
  295.                 while ($iterator->valid()) {
  296.                     if ($iterator->current(instanceof PHPPowerPoint_Shape_Drawing
  297.                         || $iterator->current(instanceof PHPPowerPoint_Shape_MemoryDrawing{
  298.                         // Write relationship for image drawing
  299.                         $this->_writeRelationship(
  300.                             $objWriter,
  301.                             $relId,
  302.                             'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
  303.                             '../media/' str_replace(' '''$iterator->current()->getIndexedFilename())
  304.                         );
  305.                     }
  306.     
  307.                     $iterator->next();
  308.                     ++$relId;
  309.                 }
  310.             }
  311.  
  312.         $objWriter->endElement();
  313.  
  314.         // Return
  315.         return $objWriter->getData();
  316.     }
  317.  
  318.     /**
  319.      * Write Override content type
  320.      *
  321.      * @param     PHPPowerPoint_Shared_XMLWriter     $objWriter         XML Writer
  322.      * @param     int                            $pId            Relationship ID. rId will be prepended!
  323.      * @param     string                        $pType            Relationship type
  324.      * @param     string                         $pTarget        Relationship target
  325.      * @param     string                         $pTargetMode    Relationship target mode
  326.      * @throws     Exception
  327.      */
  328.     private function _writeRelationship(PHPPowerPoint_Shared_XMLWriter $objWriter null$pId 1$pType ''$pTarget ''$pTargetMode '')
  329.     {
  330.         if ($pType != '' && $pTarget != ''{
  331.             // Write relationship
  332.             $objWriter->startElement('Relationship');
  333.             $objWriter->writeAttribute('Id',         'rId' $pId);
  334.             $objWriter->writeAttribute('Type',         $pType);
  335.             $objWriter->writeAttribute('Target',    $pTarget);
  336.  
  337.             if ($pTargetMode != ''{
  338.                 $objWriter->writeAttribute('TargetMode',    $pTargetMode);
  339.             }
  340.  
  341.             $objWriter->endElement();
  342.         else {
  343.             throw new Exception("Invalid parameters passed.");
  344.         }
  345.     }
  346. }

Documentation generated on Sat, 25 Apr 2009 11:37:50 +0200 by phpDocumentor 1.4.1