-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure introtext and fulltext are valid html
The splitting may caused html to get invalid (missing end tags).
- Loading branch information
1 parent
cdd1adc
commit 196318d
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Part of the Joomla Framework Utilities Package | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE | ||
*/ | ||
|
||
namespace Joomla\Utilities; | ||
|
||
/** | ||
* Dom Helper. | ||
* | ||
* @since 3.8 | ||
*/ | ||
class DomHelper | ||
{ | ||
public static $dom = null; | ||
|
||
private static function getDomInstance() | ||
{ | ||
return self::$dom ? self::$dom : self::$dom = new DOMDocument(); | ||
} | ||
|
||
/** | ||
* Function to fix Html errors like missing end tags. | ||
* | ||
* @param string $html | ||
* | ||
* @return string | ||
*/ | ||
public static function fixHtml($html) | ||
{ | ||
$dom = self::getDomInstance(); | ||
@$dom->loadHTML('<?xml encoding="utf-8" ?>' . $html, LIBXML_HTML_NODEFDTD); | ||
// Fix the html errors | ||
$value = $dom->saveHtml($dom->getElementsByTagName('body')->item(0)); | ||
|
||
// Remove body tag | ||
return mb_strimwidth($value, 6, mb_strwidth($value, 'UTF-8') - 13, '', 'UTF-8'); | ||
} | ||
} |