Skip to content

Commit

Permalink
Merge pull request #1867 from bolt/fix/ensure-not-found-config-is-array
Browse files Browse the repository at this point in the history
Ensure config for `not_found` etc. are arrays. (and some cleanup of old, deprecrated stuff)
  • Loading branch information
I-Valchev authored Sep 16, 2020
2 parents d8da8bb + c198a01 commit 4c289d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 124 deletions.
6 changes: 0 additions & 6 deletions config/bolt/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ theme: skeleton
# format settings, see: https://www.php.net/manual/en/function.date.php
date_format: 'F j, Y H:i'

# The hour of the day for the internal cron task scheduler to run daily, weekly,
# monthly and yearly jobs.
#
# Default: 3 (3 am)
cron_hour: 3

# You can set a preference to omit background images on the login screen.
omit_backgrounds: true

Expand Down
96 changes: 18 additions & 78 deletions src/Configuration/Parser/GeneralParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Bolt\Configuration\Parser;

use Bolt\Common\Arr;
use Bolt\Common\Str;
use Bolt\Utils\Html;
use Tightenco\Collect\Support\Collection;
use Webmozart\PathUtil\Path;

Expand All @@ -27,22 +25,6 @@ public function parse(): Collection
$tempconfiglocal = $this->parseConfigYaml($this->getFilenameLocalOverrides(), true);
$general = Arr::replaceRecursive($defaultconfig, Arr::replaceRecursive($tempconfig, $tempconfiglocal));

// Make sure Bolt's mount point is OK:
$path = $general['branding']['path'];
if (is_string($path)) {
$path = '/' . Str::makeSafe($path);
} else {
$path = '/';
}
$general['branding']['path'] = $path;

// Set the link in branding, if provided_by is set.
$general['branding']['provided_link'] = Html::providerLink(
$general['branding']['provided_by']
);

$general['database'] = $this->parseDatabase($general['database']);

if (! isset($general['date_format'])) {
$general['date_format'] = 'F j, Y H:i';
}
Expand All @@ -57,6 +39,19 @@ public function parse(): Collection
$general['query_search'] = true;
}

if (! is_array($general['notfound'])) {
$general['notfound'] = [$general['notfound']];
}
if (! is_array($general['maintenance'])) {
$general['maintenance'] = [$general['maintenance']];
}
if (! is_array($general['forbidden'])) {
$general['forbidden'] = [$general['forbidden']];
}
if (! is_array($general['internal_server_error'])) {
$general['internal_server_error'] = [$general['internal_server_error']];
}

return new Collection($general);
}

Expand All @@ -66,59 +61,13 @@ public function parse(): Collection
protected function getDefaultConfig(): array
{
return [
'database' => [
'driver' => 'sqlite',
'host' => 'localhost',
'slaves' => [],
'dbname' => 'bolt',
'prefix' => 'bolt_',
'charset' => 'utf8',
'collate' => 'utf8_unicode_ci',
'randomfunction' => '',
],
'sitename' => 'Default Bolt site',
'locale' => null,
'records_per_page' => 10,
'records_on_dashboard' => 5,
'debug' => null,
'debug_show_loggedoff' => false,
'debug_error_level' => null,
'production_error_level' => null,
'strict_variables' => null,
'theme' => 'base-2019',
'listing_template' => 'listing.html.twig',
'listing_records' => '5',
'listing_sort' => 'datepublish DESC',
'caching' => [
'config' => true,
'templates' => true,
'request' => false,
'duration' => 10,
],
'wysiwyg' => [
'images' => false,
'tables' => false,
'fontcolor' => false,
'align' => false,
'subsuper' => false,
'embed' => false,
'anchor' => false,
'underline' => false,
'strike' => false,
'blockquote' => false,
'codesnippet' => false,
'specialchar' => false,
'styles' => false,
'ck' => [
'autoParagraph' => true,
'contentsCss' => [
['css/ckeditor-contents.css', 'bolt'],
['css/ckeditor.css', 'bolt'],
],
'filebrowserWindowWidth' => 640,
'filebrowserWindowHeight' => 480,
],
],
'enforce_ssl' => false,
'thumbnails' => [
'default_thumbnail' => [160, 120],
Expand All @@ -133,11 +82,6 @@ protected function getDefaultConfig(): array
'accept_media_types' => explode(',', 'gif,jpg,jpeg,png,svg,pdf,mp3,tiff'),
'accept_upload_size' => '8M',
'upload_location' => '{contenttype}/{year}/{month}/',
'branding' => [
'name' => 'Bolt',
'path' => '/bolt',
'provided_by' => [],
],
'maintenance_mode' => false,
'headers' => [
'x_frame_options' => true,
Expand All @@ -147,15 +91,11 @@ protected function getDefaultConfig(): array
'allowed_attributes' => explode(',', 'id,class,style,name,value,href,Bolt,alt,title,width,height,frameborder,allowfullscreen,scrolling'),
'allowed_frame_targets' => explode(',', '_blank,_self,_parent,_top'),
],
'performance' => [
'http_cache' => [
'options' => [],
],
'timed_records' => [
'interval' => 3600,
'use_cron' => false,
],
],
'notfound' => 'helpers/page_404.html.twig',
'maintenance' => 'helpers/page_503.html.twig',
'forbidden' => 'helpers/page_403.html.twig',
'internal_server_error' => 'helpers/page_500.html.twig',
'omit_backgrounds' => false,
];
}

Expand Down
40 changes: 0 additions & 40 deletions src/Utils/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,6 @@ public static function addScheme($url, $scheme = 'http://'): string
return parse_url($url, PHP_URL_SCHEME) === null ? $scheme . $url : $url;
}

/**
* Create 'provider' link, as used in the footer, to link to either an
* email address or website URL.
*
* @param array $providedby
*/
public static function providerLink($providedby): string
{
// If nothing is provided, we don't make a link.
if (empty($providedby) || ! is_array($providedby)) {
return '';
}

// If we forgot the second element in the array, substitute the first for it.
if (empty($providedby[1]) || empty(strip_tags($providedby[1]))) {
$providedby[1] = $providedby[0];
}

$scheme = parse_url($providedby[0], PHP_URL_SCHEME);

if ($scheme === 'http' || $scheme === 'https') {
// Link is OK, just add a target
$link = sprintf('<a href="%s" target="_blank">', $providedby[0]);
} elseif ($scheme === 'mailto') {
// Already a `mailto:` include.
$link = sprintf('<a href="%s">', $providedby[0]);
} elseif (self::isURL($providedby[0])) {
// An URL, without a scheme
$link = sprintf('<a href="http://%s" target="_blank">', $providedby[0]);
} else {
// Fall back to old behaviour, assume an e-mail address
$link = sprintf('<a href="mailto:%s">', $providedby[0]);
}

// Add the label and closing tag.
$link .= strip_tags($providedby[1]) . '</a>';

return $link;
}

public static function makeAbsoluteLink(string $link): string
{
if (mb_strpos($link, '://') !== false || mb_substr($link, 0, 2) === '//') {
Expand Down

0 comments on commit 4c289d4

Please sign in to comment.