Permalink
Browse files

Work item 1196 - Add a hyperlink to an image or textbox

git-svn-id: https://phppowerpoint.svn.codeplex.com/svn/trunk@52160 ffd33b8c-2492-42e0-bdc5-587b920b7d6d
  • Loading branch information...
1 parent df76f08 commit f737fa68abac3ec76e12a30724c7e53a6852b666 @maartenba maartenba committed Oct 11, 2010
@@ -97,6 +97,13 @@
* @var PHPPowerPoint_Shape_Shadow
*/
protected $_shadow;
+
+ /**
+ * Hyperlink
+ *
+ * @var PHPPowerPoint_Shape_Hyperlink
+ */
+ protected $_hyperlink;
/**
* Create a new PHPPowerPoint_Shape
@@ -313,6 +320,42 @@ public function setShadow(PHPPowerPoint_Shape_Shadow $pValue = null) {
$this->_shadow = $pValue;
return $this;
}
+
+ /**
+ * Has Hyperlink?
+ *
+ * @return boolean
+ */
+ public function hasHyperlink()
+ {
+ return !is_null($this->_hyperlink);
+ }
+
+ /**
+ * Get Hyperlink
+ *
+ * @return PHPPowerPoint_Shape_Hyperlink
+ */
+ public function getHyperlink()
+ {
+ if (is_null($this->_hyperlink)) {
+ $this->_hyperlink = new PHPPowerPoint_Shape_Hyperlink();
+ }
+ return $this->_hyperlink;
+ }
+
+ /**
+ * Set Hyperlink
+ *
+ * @param PHPPowerPoint_Shape_Hyperlink $pHyperlink
+ * @throws Exception
+ * @return PHPPowerPoint_Shape
+ */
+ public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = null)
+ {
+ $this->_hyperlink = $pHyperlink;
+ return $this;
+ }
/**
* Get hash code
@@ -329,6 +372,7 @@ public function getHashCode() {
. $this->_rotation
. $this->getFill()->getHashCode()
. $this->_shadow->getHashCode()
+ . (is_null($this->_hyperlink) ? '' : $this->_hyperlink->getHashCode())
. __CLASS__
);
}
@@ -39,6 +39,13 @@ class PHPPowerPoint_Shape_RichText_TextElement implements PHPPowerPoint_Shape_Ri
* @var string
*/
private $_text;
+
+ /**
+ * Hyperlink
+ *
+ * @var PHPPowerPoint_Shape_Hyperlink
+ */
+ protected $_hyperlink;
/**
* Create a new PHPPowerPoint_Shape_RichText_TextElement instance
@@ -79,6 +86,42 @@ public function setText($pText = '') {
public function getFont() {
return null;
}
+
+ /**
+ * Has Hyperlink?
+ *
+ * @return boolean
+ */
+ public function hasHyperlink()
+ {
+ return !is_null($this->_hyperlink);
+ }
+
+ /**
+ * Get Hyperlink
+ *
+ * @return PHPPowerPoint_Shape_Hyperlink
+ */
+ public function getHyperlink()
+ {
+ if (is_null($this->_hyperlink)) {
+ $this->_hyperlink = new PHPPowerPoint_Shape_Hyperlink();
+ }
+ return $this->_hyperlink;
+ }
+
+ /**
+ * Set Hyperlink
+ *
+ * @param PHPPowerPoint_Shape_Hyperlink $pHyperlink
+ * @throws Exception
+ * @return PHPPowerPoint_Shape
+ */
+ public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = null)
+ {
+ $this->_hyperlink = $pHyperlink;
+ return $this;
+ }
/**
* Get hash code
@@ -88,6 +131,7 @@ public function getFont() {
public function getHashCode() {
return md5(
$this->_text
+ . (is_null($this->_hyperlink) ? '' : $this->_hyperlink->getHashCode())
. __CLASS__
);
}
@@ -222,16 +222,11 @@ public function save($pFilename = null)
// Add presentation to ZIP file
$objZip->addFromString('ppt/presentation.xml', $this->getWriterPart('Presentation')->writePresentation($this->_presentation));
- // Add slides (drawings, ...)
+ // Add slides (drawings, ...) and slide relationships (drawings, ...)
for ($i = 0; $i < $this->_presentation->getSlideCount(); ++$i) {
// Add slide
- $objZip->addFromString('ppt/slides/slide' . ($i + 1) . '.xml', $this->getWriterPart('Slide')->writeSlide($this->_presentation->getSlide($i)));
- }
-
- // Add slide relationships (drawings, ...)
- for ($i = 0; $i < $this->_presentation->getSlideCount(); ++$i) {
- // Add relationships
$objZip->addFromString('ppt/slides/_rels/slide' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeSlideRelationships($this->_presentation->getSlide($i), ($i + 1)));
+ $objZip->addFromString('ppt/slides/slide' . ($i + 1) . '.xml', $this->getWriterPart('Slide')->writeSlide($this->_presentation->getSlide($i)));
}
// Add media
@@ -844,7 +844,7 @@ public function __construct() {
);
// Layouts - PHPPowerPoint_Slide_Layout::TITLE_SLIDE
- $this->_layouts[] = array(
+ $this->_layouts[1] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::TITLE_SLIDE,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -1084,7 +1084,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::TITLE_AND_CONTENT
- $this->_layouts[] = array(
+ $this->_layouts[2] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::TITLE_AND_CONTENT,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -1252,7 +1252,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::SECTION_HEADER
- $this->_layouts[] = array(
+ $this->_layouts[3] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::SECTION_HEADER,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -1496,7 +1496,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::TWO_CONTENT
- $this->_layouts[] = array(
+ $this->_layouts[4] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::TWO_CONTENT,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -1782,7 +1782,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::COMPARISON
- $this->_layouts[] = array(
+ $this->_layouts[5] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::COMPARISON,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -2202,7 +2202,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::TITLE_ONLY
- $this->_layouts[] = array(
+ $this->_layouts[6] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::TITLE_ONLY,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -2318,7 +2318,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::BLANK
- $this->_layouts[] = array(
+ $this->_layouts[7] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::BLANK,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -2411,7 +2411,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::CONTENT_WITH_CAPTION
- $this->_layouts[] = array(
+ $this->_layouts[8] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::CONTENT_WITH_CAPTION,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -2686,7 +2686,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::PICTURE_WITH_CAPTION
- $this->_layouts[] = array(
+ $this->_layouts[9] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::PICTURE_WITH_CAPTION,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -2937,7 +2937,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::TITLE_AND_VERTICAL_TEXT
- $this->_layouts[] = array(
+ $this->_layouts[10] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::TITLE_AND_VERTICAL_TEXT,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -3105,7 +3105,7 @@ public function __construct() {
</p:sldLayout>');
// Layouts - PHPPowerPoint_Slide_Layout::VERTICAL_TITLE_AND_TEXT
- $this->_layouts[] = array(
+ $this->_layouts[11] = array(
'masterid' => 1,
'name' => PHPPowerPoint_Slide_Layout::VERTICAL_TITLE_AND_TEXT,
'body' => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
@@ -334,9 +334,6 @@ public function writeThemeRelationships($masterId = 1)
/**
* Write slide relationships to XML format
*
- * Numbering is as follows:
- * rId1 - Drawings
- *
* @param PHPPowerPoint_Slide $pSlide
* @param int $pSlideId
* @return string XML Output
@@ -394,6 +391,77 @@ public function writeSlideRelationships(PHPPowerPoint_Slide $pSlide = null, $pSl
$iterator->next();
}
}
+
+ // Write hyperlink relationships?
+ if ($pSlide->getShapeCollection()->count() > 0) {
+ // Loop trough hyperlinks and write relationships
+ $iterator = $pSlide->getShapeCollection()->getIterator();
+ while ($iterator->valid()) {
+ // Hyperlink on shape
+ if ($iterator->current()->hasHyperlink()) {
+ // Write relationship for hyperlink
+ $hyperlink = $iterator->current()->getHyperlink();
+ $hyperlink->__relationId = 'rId' . $relId;
+
+ if (!$hyperlink->isInternal()) {
+ $this->_writeRelationship(
+ $objWriter,
+ $relId,
+ 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
+ $hyperlink->getUrl(),
+ 'External'
+ );
+ } else {
+ $this->_writeRelationship(
+ $objWriter,
+ $relId,
+ 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide',
+ 'slide' . $hyperlink->getSlideNumber() . '.xml'
+ );
+ }
+
+ ++$relId;
+ }
+
+ // Hyperlink on rich text run
+ if ($iterator->current() instanceof PHPPowerPoint_Shape_RichText) {
+ foreach ($iterator->current()->getParagraphs() as $paragraph) {
+ foreach ($paragraph->getRichTextElements() as $element) {
+ if ($element instanceof PHPPowerPoint_Shape_RichText_Run
+ || $element instanceof PHPPowerPoint_Shape_RichText_TextElement)
+ {
+ if ($element->hasHyperlink()) {
+ // Write relationship for hyperlink
+ $hyperlink = $element->getHyperlink();
+ $hyperlink->__relationId = 'rId' . $relId;
+
+ if (!$hyperlink->isInternal()) {
+ $this->_writeRelationship(
+ $objWriter,
+ $relId,
+ 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
+ $hyperlink->getUrl(),
+ 'External'
+ );
+ } else {
+ $this->_writeRelationship(
+ $objWriter,
+ $relId,
+ 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide',
+ 'slide' . $hyperlink->getSlideNumber() . '.xml'
+ );
+ }
+
+ ++$relId;
+ }
+ }
+ }
+ }
+ }
+
+ $iterator->next();
+ }
+ }
$objWriter->endElement();
Oops, something went wrong.

0 comments on commit f737fa6

Please sign in to comment.