Skip to content

Commit b394247

Browse files
authored
Merge branch 'develop' into feature-add-table-indent-option
2 parents 081c672 + dd27f66 commit b394247

File tree

8 files changed

+33
-9
lines changed

8 files changed

+33
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ v0.15.0 (?? ??? 2018)
2020
- Added support for Image text wrapping distance @troosan #1310
2121
- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
2222
- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
23-
- Add support for table indent (tblInd) @Trainmaster
23+
- Add support for table indent (tblInd) @Trainmaster #1343
24+
- Added parsing of internal links in HTML reader @lalop #1336
2425

2526
### Fixed
2627
- Fix reading of docx default style - @troosan #1238
@@ -36,6 +37,7 @@ v0.15.0 (?? ??? 2018)
3637

3738
### Changed
3839
- Remove zend-stdlib dependency @Trainmaster #1284
40+
- The default unit for `\PhpOffice\PhpWord\Style\Image` changed from `px` to `pt`.
3941

4042

4143
v0.14.0 (29 Dec 2017)

docs/elements.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ To add an image, use the ``addImage`` method to sections, headers, footers, text
242242
243243
$section->addImage($src, [$style]);
244244
245-
- ``$src``. String path to a local image, URL of a remote image or the image data, as a string.
245+
- ``$src``. String path to a local image, URL of a remote image or the image data, as a string. Warning: Do not pass user-generated strings here, as that would allow an attacker to read arbitrary files or perform server-side request forgery by passing file paths or URLs instead of image data.
246246
- ``$style``. See :ref:`image-style`.
247247

248248
Examples:
@@ -435,8 +435,8 @@ Available line style attributes:
435435
- ``dash``. Line types: dash, rounddot, squaredot, dashdot, longdash, longdashdot, longdashdotdot.
436436
- ``beginArrow``. Start type of arrow: block, open, classic, diamond, oval.
437437
- ``endArrow``. End type of arrow: block, open, classic, diamond, oval.
438-
- ``width``. Line-object width in pt.
439-
- ``height``. Line-object height in pt.
438+
- ``width``. Line-object width in *pt*.
439+
- ``height``. Line-object height in *pt*.
440440
- ``flip``. Flip the line element: true, false.
441441

442442
Chart

docs/styles.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ Image
150150
Available Image style options:
151151

152152
- ``alignment``. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
153-
- ``height``. Height in pixels.
153+
- ``height``. Height in *pt*.
154154
- ``marginLeft``. Left margin in inches, can be negative.
155155
- ``marginTop``. Top margin in inches, can be negative.
156-
- ``width``. Width in pixels.
156+
- ``width``. Width in *pt*.
157157
- ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*.
158158
- ``wrapDistanceTop``. Top text wrapping in pixels.
159159
- ``wrapDistanceBottom``. Bottom text wrapping in pixels.

samples/Sample_Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function write($phpWord, $filename, $writers)
9292
* Get ending notes
9393
*
9494
* @param array $writers
95-
*
95+
* @param mixed $filename
9696
* @return string
9797
*/
9898
function getEndingNotes($writers, $filename)

src/PhpWord/Shared/Html.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Html
3737
* Add HTML parts.
3838
*
3939
* Note: $stylesheet parameter is removed to avoid PHPMD error for unused parameter
40+
* Warning: Do not pass user-generated HTML here, as that would allow an attacker to read arbitrary
41+
* files or perform server-side request forgery by passing local file paths or URLs in <img>.
4042
*
4143
* @param \PhpOffice\PhpWord\Element\AbstractContainer $element Where the parts need to be added
4244
* @param string $html The code to parse
@@ -721,6 +723,10 @@ private static function parseLink($node, $element, &$styles)
721723
}
722724
self::parseInlineStyle($node, $styles['font']);
723725

726+
if (strpos($target, '#') === 0) {
727+
return $element->addLink(substr($target, 1), $node->textContent, $styles['font'], $styles['paragraph'], true);
728+
}
729+
724730
return $element->addLink($target, $node->textContent, $styles['font'], $styles['paragraph']);
725731
}
726732
}

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function testParseLineHeight()
125125
$section = $phpWord->addSection();
126126
Html::addHtml($section, '<p style="line-height: 1.5;">test</p>');
127127
Html::addHtml($section, '<p style="line-height: 15pt;">test</p>');
128+
Html::addHtml($section, '<p style="line-height: 120%;">test</p>');
128129

129130
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
130131
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:pPr/w:spacing'));
@@ -134,6 +135,10 @@ public function testParseLineHeight()
134135
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[2]/w:pPr/w:spacing'));
135136
$this->assertEquals(300, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:spacing', 'w:line'));
136137
$this->assertEquals(LineSpacingRule::EXACT, $doc->getElementAttribute('/w:document/w:body/w:p[2]/w:pPr/w:spacing', 'w:lineRule'));
138+
139+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[3]/w:pPr/w:spacing'));
140+
$this->assertEquals(Paragraph::LINE_HEIGHT * 1.2, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:line'));
141+
$this->assertEquals(LineSpacingRule::AUTO, $doc->getElementAttribute('/w:document/w:body/w:p[3]/w:pPr/w:spacing', 'w:lineRule'));
137142
}
138143

139144
/**
@@ -453,6 +458,17 @@ public function testParseLink()
453458

454459
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
455460
$this->assertEquals('link text', $doc->getElement('/w:document/w:body/w:p/w:hyperlink/w:r/w:t')->nodeValue);
461+
462+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
463+
$section = $phpWord->addSection();
464+
$section->addBookmark('bookmark');
465+
$html = '<p><a href="#bookmark">internal link text</a></p>';
466+
Html::addHtml($section, $html);
467+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
468+
469+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p/w:hyperlink'));
470+
$this->assertTrue($doc->getElement('/w:document/w:body/w:p/w:hyperlink')->hasAttribute('w:anchor'));
471+
$this->assertEquals('bookmark', $doc->getElement('/w:document/w:body/w:p/w:hyperlink')->getAttribute('w:anchor'));
456472
}
457473

458474
public function testParseMalformedStyleIsIgnored()

tests/PhpWord/Writer/Word2007/ElementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function testChartElements()
256256
{
257257
$phpWord = new PhpWord();
258258
$section = $phpWord->addSection();
259-
$style = array('width' => 1000000, 'height' => 1000000);
259+
$style = array('width' => 1000000, 'height' => 1000000, 'showAxisLabels' => true, 'showGridX' => true, 'showGridY' => true);
260260

261261
$chartTypes = array('pie', 'doughnut', 'bar', 'line', 'area', 'scatter', 'radar');
262262
$categories = array('A', 'B', 'C', 'D', 'E');

tests/PhpWord/Writer/Word2007/Style/FontTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testFontRTL()
4343
$phpWord = new \PhpOffice\PhpWord\PhpWord();
4444
$section = $phpWord->addSection();
4545
$textrun = $section->addTextRun();
46-
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
46+
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true, 'lang' => 'ar-DZ'));
4747
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
4848

4949
$file = 'word/document.xml';

0 commit comments

Comments
 (0)