Page 1 of 1

Pull request (here, because I don't have Github account)

Posted: Sun Mar 09, 2025 10:51 pm
by JerryWham
Hello everyone !
I am a French user, so sorry for my english.

I don't have Github account since Microsoft buy it and introduice IA in it.
So I post a pull request if it can help....

Issue : when a file is not found, a warning is raised because of file_get_contents function in pagex.class.php

So, I propose to split this warning with catching error.

In bl-kernel/helpers/filesystem.class.php, I add this static function :

Code: Select all

	public static function fileGetContents($filePath)
	{
		set_error_handler(
		    function ($severity, $message, $file, $line) {
		        throw new ErrorException($message, $severity, $severity, $file, $line);
		    }
		);
		try {
		    $contentRaw = file_get_contents($filePath);
		}
		catch (Exception $e) {
			header("HTTP/1.0 404 Not Found");
		    echo 'File not found';
			exit();
		}
		restore_error_handler();

		return $contentRaw;

	}
and I remplace the contentRaw function of bl-kernel/pagex.class.php by this code :

Code: Select all


	// Returns the raw content
	// This content is not markdown parser
	// (boolean) $sanitize, TRUE returns the content sanitized
	public function contentRaw($sanitize = false)
	{
		$key = $this->key();
		$filePath = PATH_PAGES . $key . DS . FILENAME;

		$contentRaw = Filesystem::fileGetContents($filePath);

		if ($sanitize) {
			return Sanitize::html($contentRaw);
		}
		return $contentRaw;
	}

After that, when a file is not found, instead of a warning with the file path, the message "File not found" is displayed and the header status of the page is 404.

I hope this can help.

Best regards

Re: Pull request (here, because I don't have Github account)

Posted: Mon Sep 08, 2025 11:16 pm
by JerryWham
On bl-kernel/helpers/theme.class.php, I add integrity param to css files and javascript files.

I replace css and javascript functions, by these:

Code: Select all


	public static function css($files, $base = DOMAIN_THEME)
	{
		global $site;
		if (!is_array($files)) {
			$files = array($files);
		}

		$links = '';
		foreach ($files as $file) {
			$links .= '<link rel="stylesheet" type="text/css" href="' . $base . $file . '?version=' . BLUDIT_VERSION . ' " integrity="sha384-'. base64_encode(hash('sha384', file_get_contents( str_replace(DOMAIN_BASE, '', $base) . '/' . $file,'css'), true)) .'" >' . PHP_EOL;
		}

		return $links;
	}

	public static function javascript($files, $base = DOMAIN_THEME, $attributes = '')
	{
		global $site;
		if (!is_array($files)) {
			$files = array($files);
		}

		$scripts = '';
		foreach ($files as $file) {
			$scripts .= '<script ' . $attributes . ' src="' . $base . $file . '?version=' . BLUDIT_VERSION . '" integrity="sha384-'. base64_encode(hash('sha384', file_get_contents( str_replace(DOMAIN_BASE, '', $base) . '/' . $file,'js'), true)) .'" ></script>' . PHP_EOL;
		}

		return $scripts;
	}

I hope it can help.