2014-04-25 10:33:45 +07:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* PHPWord
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/PHPOffice/PHPWord
|
|
|
|
|
* @copyright 2014 PHPWord
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2014-04-25 10:33:45 +07:00
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
$linkName = $this->element->getLinkName();
|
|
|
|
|
if (is_null($linkName)) {
|
|
|
|
|
$linkName = $this->element->getLinkSrc();
|
|
|
|
|
}
|
|
|
|
|
$fStyle = $this->element->getFontStyle();
|
|
|
|
|
$pStyle = $this->element->getParagraphStyle();
|
|
|
|
|
|
|
|
|
|
if (!$this->withoutP) {
|
2014-04-26 11:14:27 +07:00
|
|
|
$styleWriter = new ParagraphStyleWriter($this->xmlWriter, $pStyle);
|
|
|
|
|
$styleWriter->setIsInline(true);
|
|
|
|
|
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->startElement('w:p');
|
2014-04-26 11:14:27 +07:00
|
|
|
$styleWriter->write();
|
2014-04-25 10:33:45 +07:00
|
|
|
}
|
2014-04-26 11:14:27 +07:00
|
|
|
|
|
|
|
|
$styleWriter = new FontStyleWriter($this->xmlWriter, $fStyle);
|
|
|
|
|
$styleWriter->setIsInline(true);
|
|
|
|
|
|
2014-04-25 10:33:45 +07:00
|
|
|
$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();
|
2014-04-25 10:33:45 +07:00
|
|
|
$this->xmlWriter->startElement('w:t');
|
|
|
|
|
$this->xmlWriter->writeAttribute('xml:space', 'preserve');
|
|
|
|
|
$this->xmlWriter->writeRaw($linkName);
|
|
|
|
|
$this->xmlWriter->endElement(); // w:t
|
|
|
|
|
$this->xmlWriter->endElement(); // w:r
|
|
|
|
|
$this->xmlWriter->endElement(); // w:hyperlink
|
|
|
|
|
if (!$this->withoutP) {
|
|
|
|
|
$this->xmlWriter->endElement(); // w:p
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|