use DOMDocument;
use DOMXPath;
+use Friendica\Protocol\HTTP\MediaType;
use Friendica\Content\Widget\ContactBlock;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
self::tagToBBCode($doc, 'div', [], "\r", "\r");
self::tagToBBCode($doc, 'p', [], "\n", "\n");
- self::tagToBBCode($doc, 'ul', [], "[list]", "[/list]");
- self::tagToBBCode($doc, 'ol', [], "[list=1]", "[/list]");
- self::tagToBBCode($doc, 'li', [], "[*]", "");
+ self::tagToBBCode($doc, 'ul', [], "[ul]", "\n[/ul]");
+ self::tagToBBCode($doc, 'ol', [], "[ol]", "\n[/ol]");
+ self::tagToBBCode($doc, 'li', [], "\n[li]", "[/li]");
self::tagToBBCode($doc, 'hr', [], "[hr]", "");
$message = str_replace("\n\n\n", "\n\n", $message);
} while ($oldmessage != $message);
- do {
- $oldmessage = $message;
- $message = str_replace(
- [
- "[/size]\n\n",
- "\n[hr]",
- "[hr]\n",
- "\n[list",
- "[/list]\n",
- "\n[/",
- "[list]\n",
- "[list=1]\n",
- "\n[*]"],
- [
- "[/size]\n",
- "[hr]",
- "[hr]",
- "[list",
- "[/list]",
- "[/",
- "[list]",
- "[list=1]",
- "[*]"],
- $message
- );
- } while ($message != $oldmessage);
-
$message = str_replace(
['[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'],
['[b]', '[/b]', '[i]', '[/i]'],
// the quotes, e.g.:
//
// concat("'foo'", '"', "bar")
- return 'concat(' . implode(', \'"\', ', array_map(['self', 'xpathQuote'], explode('"', $value))) . ')';
+ return 'concat(' . implode(', \'"\', ', array_map([self::class, 'xpathQuote'], explode('"', $value))) . ')';
}
/**
return $result !== false && $result->length > 0;
}
+
+ /**
+ * @param DOMDocument $doc
+ * @return string|null Lowercase charset
+ */
+ public static function extractCharset(DOMDocument $doc): ?string
+ {
+ $xpath = new DOMXPath($doc);
+
+ $expression = "string(//meta[@charset]/@charset)";
+ if ($charset = $xpath->evaluate($expression)) {
+ return strtolower($charset);
+ }
+
+ try {
+ // This expression looks for a meta tag with the http-equiv attribute set to "content-type" ignoring case
+ // whose content attribute contains a "charset" string and returns its value
+ $expression = "string(//meta[@http-equiv][translate(@http-equiv, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'content-type'][contains(translate(@content, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'charset')]/@content)";
+ $mediaType = MediaType::fromContentType($xpath->evaluate($expression));
+ if (isset($mediaType->parameters['charset'])) {
+ return strtolower($mediaType->parameters['charset']);
+ }
+ } catch(\InvalidArgumentException $e) {}
+
+ return null;
+ }
}