Various fixes for the blog and editor. As well as finally adding in the carousel!
🚀 Deploy website on push / 🎉 Deploy (push) Successful in 24s
🚀 Deploy website on push / 🎉 Deploy (push) Successful in 24s
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+35
-4
@@ -673,9 +673,17 @@ EOD;
|
||||
*/
|
||||
public function changeHTMLSrc(string $body, string $to, string $from): string
|
||||
{
|
||||
// $body = preg_replace_callback('/>([^<]+)</', function($matches) {
|
||||
// // Convert special characters to HTML entities
|
||||
// return '>' . htmlentities(trim($matches[1]), ENT_QUOTES | ENT_HTML5, 'UTF-8') . '<';
|
||||
// }, $body);
|
||||
|
||||
$htmlDoc = new DOMDocument();
|
||||
$body = mb_convert_encoding($body, "HTML-ENTITIES", "UTF-8");
|
||||
$htmlDoc->loadHTML($body, LIBXML_NOERROR);
|
||||
|
||||
// Load the raw HTML content into DOMDocument
|
||||
@$htmlDoc->loadHTML($body, LIBXML_NOERROR);
|
||||
|
||||
// Get the body and process images
|
||||
$doc = $htmlDoc->getElementsByTagName('body')->item(0);
|
||||
$imgs = $doc->getElementsByTagName('img');
|
||||
|
||||
@@ -688,9 +696,11 @@ EOD;
|
||||
$srcList[] = $src;
|
||||
$fileName = basename($src);
|
||||
|
||||
// Update the src attribute to the new location
|
||||
$img->setAttribute("src", substr($to, 2) . $fileName);
|
||||
}
|
||||
|
||||
// Rename files and clean up old ones
|
||||
$files = scandir($from);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
@@ -706,15 +716,36 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
// Process the HTML content for output
|
||||
$newBody = '';
|
||||
foreach ($doc->childNodes as $node)
|
||||
{
|
||||
$newHTML = $htmlDoc->saveHTML($node);
|
||||
$newBody .= mb_convert_encoding($newHTML, "UTF-8", mb_detect_encoding($newHTML));
|
||||
// Only convert text nodes to HTML entities
|
||||
if ($node->nodeType === XML_TEXT_NODE)
|
||||
{
|
||||
$newBody .= $this->convertToHtmlEntities($node->nodeValue); // Convert text nodes
|
||||
}
|
||||
else
|
||||
{
|
||||
$newBody .= $htmlDoc->saveHTML($node); // Keep HTML tags intact
|
||||
}
|
||||
}
|
||||
|
||||
return $newBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all characters in a string to HTML entities while leaving HTML tags intact.
|
||||
* @param string $text - The text to convert
|
||||
* @return string - The converted text with HTML entities
|
||||
*/
|
||||
private function convertToHtmlEntities(string $text): string
|
||||
{
|
||||
// Convert characters to HTML entities using mb_encode_numericentity
|
||||
return htmlentities($text, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all posts with the given category
|
||||
* @param string $category - Category of the post
|
||||
|
||||
Vendored
+1
-1
@@ -181,7 +181,7 @@ class userRoutes implements routesInterface
|
||||
$inactive = 60 * 60 * 48; // 2 days
|
||||
$_SESSION["timeout"] = time() + $inactive;
|
||||
|
||||
return $response->withHeader("Location", "https://rohitpai.co.uk/editor/")->withStatus(302);
|
||||
return $response->withHeader("Location", "https://rohitpai.co.uk/editor/")->withStatus(302);
|
||||
}
|
||||
|
||||
$response->getBody()->write(json_encode(array("error" => "Unauthorised")));
|
||||
|
||||
Reference in New Issue
Block a user