PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Reader / Xlsx / Hyperlinks.php

Hyperlinks.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php

71 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Reader\Xlsx;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Cell\Coordinate;
6 use TablePress\PhpOffice\PhpSpreadsheet\Reader\Xlsx;
7 use TablePress\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
8 use SimpleXMLElement;
9
10 class Hyperlinks
11 {
12 private Worksheet $worksheet;
13
14 /** @var string[] */
15 private array $hyperlinks = [];
16
17 public function __construct(Worksheet $workSheet)
18 {
19 $this->worksheet = $workSheet;
20 }
21
22 public function readHyperlinks(SimpleXMLElement $relsWorksheet): void
23 {
24 foreach ($relsWorksheet->children(Namespaces::RELATIONSHIPS)->Relationship as $elementx) {
25 $element = Xlsx::getAttributes($elementx);
26 if ($element->Type == Namespaces::HYPERLINK) {
27 $this->hyperlinks[(string) $element->Id] = (string) $element->Target;
28 }
29 }
30 }
31
32 public function setHyperlinks(SimpleXMLElement $worksheetXml): void
33 {
34 foreach ($worksheetXml->children(Namespaces::MAIN)->hyperlink as $hyperlink) {
35 $this->setHyperlink($hyperlink, $this->worksheet);
36 }
37 }
38
39 private function setHyperlink(SimpleXMLElement $hyperlink, Worksheet $worksheet): void
40 {
41 // Link url
42 $linkRel = Xlsx::getAttributes($hyperlink, Namespaces::SCHEMA_OFFICE_DOCUMENT);
43
44 $attributes = Xlsx::getAttributes($hyperlink);
45 foreach (Coordinate::extractAllCellReferencesInRange($attributes->ref) as $cellReference) {
46 $cell = $worksheet->getCell($cellReference);
47
48 $hyperlinkUrl = '';
49 if (isset($linkRel['id'])) {
50 $hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']] ?? '';
51 }
52 if (isset($attributes['location'])) {
53 if ($hyperlinkUrl === '') {
54 $hyperlinkUrl = 'sheet://' . (string) $attributes['location'];
55 } else {
56 $hyperlinkUrl .= '#' . (string) $attributes['location'];
57 }
58 }
59 $cell->getHyperlink()->setUrl($hyperlinkUrl);
60 // Tooltip
61 if (isset($attributes['tooltip'])) {
62 $cell->getHyperlink()->setTooltip((string) $attributes['tooltip']);
63 }
64
65 if (isset($attributes['display'])) {
66 $cell->getHyperlink()->setDisplay((string) $attributes['display']);
67 }
68 }
69 }
70 }
71