Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
<?php

namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
> use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
> use SimpleXMLElement;
class Hyperlinks {
> /** @var Worksheet */
private $worksheet;
> /** @var array */
private $hyperlinks = []; public function __construct(Worksheet $workSheet) { $this->worksheet = $workSheet; }
< public function readHyperlinks(\SimpleXMLElement $relsWorksheet)
> public function readHyperlinks(SimpleXMLElement $relsWorksheet): void
{
< foreach ($relsWorksheet->Relationship as $element) { < if ($element['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') { < $this->hyperlinks[(string) $element['Id']] = (string) $element['Target'];
> foreach ($relsWorksheet->children(Namespaces::RELATIONSHIPS)->Relationship as $elementx) { > $element = Xlsx::getAttributes($elementx); > if ($element->Type == Namespaces::HYPERLINK) { > $this->hyperlinks[(string) $element->Id] = (string) $element->Target;
} } }
< public function setHyperlinks(\SimpleXMLElement $worksheetXml)
> public function setHyperlinks(SimpleXMLElement $worksheetXml): void
{
< foreach ($worksheetXml->hyperlink as $hyperlink) {
> foreach ($worksheetXml->children(Namespaces::MAIN)->hyperlink as $hyperlink) { > if ($hyperlink !== null) {
$this->setHyperlink($hyperlink, $this->worksheet); } }
> }
< private function setHyperlink(\SimpleXMLElement $hyperlink, Worksheet $worksheet)
> private function setHyperlink(SimpleXMLElement $hyperlink, Worksheet $worksheet): void
{ // Link url
< $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
> $linkRel = Xlsx::getAttributes($hyperlink, Namespaces::SCHEMA_OFFICE_DOCUMENT);
< foreach (Coordinate::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) {
> $attributes = Xlsx::getAttributes($hyperlink); > foreach (Coordinate::extractAllCellReferencesInRange($attributes->ref) as $cellReference) {
$cell = $worksheet->getCell($cellReference); if (isset($linkRel['id'])) {
< $hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']]; < if (isset($hyperlink['location'])) { < $hyperlinkUrl .= '#' . (string) $hyperlink['location'];
> $hyperlinkUrl = $this->hyperlinks[(string) $linkRel['id']] ?? null; > if (isset($attributes['location'])) { > $hyperlinkUrl .= '#' . (string) $attributes['location'];
} $cell->getHyperlink()->setUrl($hyperlinkUrl);
< } elseif (isset($hyperlink['location'])) { < $cell->getHyperlink()->setUrl('sheet://' . (string) $hyperlink['location']);
> } elseif (isset($attributes['location'])) { > $cell->getHyperlink()->setUrl('sheet://' . (string) $attributes['location']);
} // Tooltip
< if (isset($hyperlink['tooltip'])) { < $cell->getHyperlink()->setTooltip((string) $hyperlink['tooltip']);
> if (isset($attributes['tooltip'])) { > $cell->getHyperlink()->setTooltip((string) $attributes['tooltip']);
} } } }