diff --git a/Dockerfile b/Dockerfile
index f507b09..c0d8a24 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
# Stage 0: Base
-FROM php:8.3-fpm AS base
+FROM php:8.4-fpm AS base
# Install dependencies and extensions
RUN apt-get update && apt-get install -y \
diff --git a/README.en.md b/README.en.md
index 6d5449a..77dbfcf 100644
--- a/README.en.md
+++ b/README.en.md
@@ -3,6 +3,7 @@
[](https://github.com/manualdousuario/marreta/blob/master/README.md)
[](https://github.com/manualdousuario/marreta/blob/master/README.en.md)
+[](https://www.php.net/)
[](https://github.com/manualdousuario/marreta/network/members)
[](https://github.com/manualdousuario/marreta/stargazers)
[](https://github.com/manualdousuario/marreta/issues)
diff --git a/README.md b/README.md
index 1f2beb3..8846612 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,7 @@
[](https://github.com/manualdousuario/marreta/blob/master/README.en.md)
[](https://github.com/manualdousuario/marreta/blob/master/README.md)
+[](https://www.php.net/)
[](https://github.com/manualdousuario/marreta/network/members)
[](https://github.com/manualdousuario/marreta/stargazers)
[](https://github.com/manualdousuario/marreta/issues)
diff --git a/app/inc/URLAnalyzer/URLAnalyzerProcess.php b/app/inc/URLAnalyzer/URLAnalyzerProcess.php
index ae1434d..1a78475 100644
--- a/app/inc/URLAnalyzer/URLAnalyzerProcess.php
+++ b/app/inc/URLAnalyzer/URLAnalyzerProcess.php
@@ -7,9 +7,9 @@
namespace Inc\URLAnalyzer;
-use DOMDocument;
-use DOMXPath;
-use DOMElement;
+use Dom\HTMLDocument;
+use Dom\XPath;
+use Dom\Element;
class URLAnalyzerProcess extends URLAnalyzerBase
{
@@ -22,17 +22,6 @@ class URLAnalyzerProcess extends URLAnalyzerBase
$this->error = new URLAnalyzerError();
}
- /** Creates DOM from HTML content */
- private function createDOM($content)
- {
- $dom = new DOMDocument();
- $dom->preserveWhiteSpace = true;
- libxml_use_internal_errors(true);
- @$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
- libxml_clear_errors();
- return $dom;
- }
-
/**
* Processes and modifies HTML content
* Applies rules and fixes URLs
@@ -43,8 +32,8 @@ class URLAnalyzerProcess extends URLAnalyzerBase
$this->error->throwError(self::ERROR_CONTENT_ERROR);
}
- $dom = $this->createDOM($content);
- $xpath = new DOMXPath($dom);
+ $dom = HTMLDocument::createFromString($content, LIBXML_NOERROR);
+ $xpath = new XPath($dom);
// Process all modifications in real-time
$this->processCanonicalLinks($dom, $xpath, $url);
@@ -222,7 +211,7 @@ class URLAnalyzerProcess extends URLAnalyzerBase
$elements = $xpath->query("//*[@style]");
if ($elements !== false) {
foreach ($elements as $element) {
- if ($element instanceof DOMElement) {
+ if ($element instanceof Element) {
$style = $element->getAttribute('style');
$style = preg_replace('/(max-height|height|overflow|position|display|visibility)\s*:\s*[^;]+;?/', '', $style);
$element->setAttribute('style', $style);
@@ -234,15 +223,13 @@ class URLAnalyzerProcess extends URLAnalyzerBase
/** Adds branded bar to page */
private function addBrandBar($dom, $xpath, $url)
{
- $body = $xpath->query('//body')->item(0);
+ $body = $dom->getElementsByTagName('body')[0];
if ($body) {
$brandDiv = $dom->createElement('div');
- $brandDiv->setAttribute('style', 'z-index: 9999; position: fixed; top: 0; right: 1rem; display: flex; gap: 8px;');
- $brandHtml = $dom->createDocumentFragment();
- $brandHtml->appendXML('');
- $brandDiv->appendChild($brandHtml);
- $brandHtml->appendXML('');
- $brandDiv->appendChild($brandHtml);
+ $brandDiv->setAttribute('style', 'z-index: 2147483647; position: fixed; top: 0; right: 1rem; display: flex; gap: 8px;');
+ $linkHtml = '';
+ $siteHtml = '';
+ $brandDiv->innerHTML = $linkHtml . $siteHtml;
$body->appendChild($brandDiv);
}
}
@@ -251,10 +238,10 @@ class URLAnalyzerProcess extends URLAnalyzerBase
private function addDebugBar($dom, $xpath)
{
if (defined('LOG_LEVEL') && LOG_LEVEL === 'DEBUG') {
- $body = $xpath->query('//body')->item(0);
+ $body = $dom->getElementsByTagName('body')[0];
if ($body) {
$debugDiv = $dom->createElement('div');
- $debugDiv->setAttribute('style', 'position: fixed; bottom: 1rem; right: 1rem; max-width: 400px; padding: 1rem; color: #000; background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(8px); border: 1px solid #e5e7eb; border-radius: 0.5rem; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); overflow: auto; max-height: 80vh; z-index: 9999; font-family: monospace; font-size: 13px; line-height: 1.4;');
+ $debugDiv->setAttribute('style', 'z-index: 2147483647; position: fixed; bottom: 1rem; right: 1rem; max-width: 400px; padding: 1rem; color: #000; background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(8px); border: 1px solid #e5e7eb; border-radius: 0.5rem; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); overflow: auto; max-height: 80vh; z-index: 2147483647; font-family: monospace; font-size: 13px; line-height: 1.4;');
if (empty($this->activatedRules)) {
$ruleElement = $dom->createElement('div');
@@ -301,7 +288,7 @@ class URLAnalyzerProcess extends URLAnalyzerBase
$elements = $xpath->query("//*[@src]");
if ($elements !== false) {
foreach ($elements as $element) {
- if ($element instanceof DOMElement) {
+ if ($element instanceof Element) {
$src = $element->getAttribute('src');
if (strpos($src, 'base64') !== false) {
continue;
@@ -317,7 +304,7 @@ class URLAnalyzerProcess extends URLAnalyzerBase
$elements = $xpath->query("//*[@href]");
if ($elements !== false) {
foreach ($elements as $element) {
- if ($element instanceof DOMElement) {
+ if ($element instanceof Element) {
$href = $element->getAttribute('href');
if (
strpos($href, 'mailto:') === 0 ||
@@ -336,3 +323,4 @@ class URLAnalyzerProcess extends URLAnalyzerBase
}
}
}
+