58 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
2014-05-04 21:03:28 +04:00
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
2014-04-26 11:14:27 +07:00
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
/**
* Link element writer
*
* @since 0.10.0
*/
class Link extends Element
{
/**
* Write link element
*/
public function write()
{
$rId = $this->element->getRelationId() + ($this->element->isInSection() ? 6 : 0);
$fontStyle = $this->element->getFontStyle();
$paragraphStyle = $this->element->getParagraphStyle();
if (!$this->withoutP) {
$styleWriter = new ParagraphStyleWriter($this->xmlWriter, $paragraphStyle);
2014-04-26 11:14:27 +07:00
$styleWriter->setIsInline(true);
$this->xmlWriter->startElement('w:p');
2014-04-26 11:14:27 +07:00
$styleWriter->write();
}
2014-04-26 11:14:27 +07:00
$styleWriter = new FontStyleWriter($this->xmlWriter, $fontStyle);
2014-04-26 11:14:27 +07:00
$styleWriter->setIsInline(true);
$this->xmlWriter->startElement('w:hyperlink');
$this->xmlWriter->writeAttribute('r:id', 'rId' . $rId);
$this->xmlWriter->writeAttribute('w:history', '1');
$this->xmlWriter->startElement('w:r');
2014-04-26 11:14:27 +07:00
$styleWriter->write();
$this->xmlWriter->startElement('w:t');
$this->xmlWriter->writeAttribute('xml:space', 'preserve');
2014-04-26 16:05:29 +07:00
$this->xmlWriter->writeRaw($this->element->getText());
$this->xmlWriter->endElement(); // w:t
$this->xmlWriter->endElement(); // w:r
$this->xmlWriter->endElement(); // w:hyperlink
if (!$this->withoutP) {
$this->xmlWriter->endElement(); // w:p
}
}
}