Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Giraffaman committed Jan 2, 2024
2 parents 6575137 + 47c9289 commit e1a5274
Show file tree
Hide file tree
Showing 189 changed files with 2,697 additions and 2,779 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Publish
on:
workflow_run:
workflows: Tests
branches: main
branches:
- main
- master
types: completed
workflow_dispatch:
push:
Expand All @@ -16,7 +18,18 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
steps:
- uses: actions/checkout@master
- name: Checkout triggering commit
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/checkout@master
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: Checkout main commit
if: ${{ github.event_name != 'workflow_run' }}
uses: actions/checkout@master
- name: Set build vars
run: |
echo "BUILD_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV
echo "BUILD_HASH=$GITHUB_SHA" >> $GITHUB_ENV
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@main
with:
Expand All @@ -25,4 +38,5 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}
cache: ${{ github.event_name != 'schedule' }}
buildoptions: "--build-arg RUN_TESTS=false"
buildargs: BUILD_TIME,BUILD_HASH
tag_semver: true
15 changes: 11 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Tests

on:
push:
branches:
- main
- master
pull_request:
schedule:
- cron: '0 2 * * 0' # Weekly on Sundays at 02:00
Expand All @@ -26,7 +29,7 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@master
with:
php-version: 8.1
php-version: 8.3
- name: Format
run: ./vendor/bin/php-cs-fixer fix && git diff --exit-code

Expand Down Expand Up @@ -57,7 +60,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
php: ['8.1', '8.2', '8.3']
database: ['pgsql', 'mysql', 'sqlite']

runs-on: ubuntu-latest
Expand Down Expand Up @@ -122,9 +125,13 @@ jobs:
if [[ "${{ matrix.database }}" == "sqlite" ]]; then
export TEST_DSN="sqlite:data/shimmie.sqlite"
fi
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
if [[ "${{ matrix.php }}" == "8.3" ]]; then
vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover=data/coverage.clover
else
vendor/bin/phpunit --configuration tests/phpunit.xml
fi
- name: Upload coverage
if: matrix.php == '8.1'
if: matrix.php == '8.3'
run: |
vendor/bin/ocular code-coverage:upload --format=php-clover data/coverage.clover
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
backup
data
images
thumbs
*.phar
*.sqlite
*.cache
.devcontainer
trace.json
.docker/entrypoint.d/config.json

#Composer
composer.phar
composer.lock
/vendor/

# Created by http://www.gitignore.io
Expand Down
3 changes: 2 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($_phpcs_finder)
;
->setCacheFile("data/php-cs-fixer.cache")
;
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ To Dos:

# Shimmie

[![Test & Publish](https://github.com/shish/shimmie2/workflows/Test%20&%20Publish/badge.svg)](https://github.com/shish/shimmie2/actions)
[![Tests](https://github.com/shish/shimmie2/workflows/Tests/badge.svg?branch=main)](https://github.com/shish/shimmie2/actions)
[![Code Quality](https://scrutinizer-ci.com/g/shish/shimmie2/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/shish/shimmie2/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/shish/shimmie2/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/shish/shimmie2/?branch=master)
[![Matrix](https://matrix.to/img/matrix-badge.svg)](https://matrix.to/#/#shimmie:matrix.org)


# Documentation
Expand All @@ -35,13 +36,6 @@ To Dos:
* [High-performance notes](https://github.com/shish/shimmie2/wiki/Performance)


# Contact

Email: webmaster at shishnet.org

Issue/Bug tracker: https://github.com/shish/shimmie2/issues


# Licence

All code is released under the [GNU GPL Version 2](https://www.gnu.org/licenses/gpl-2.0.html) unless mentioned otherwise.
Expand Down
79 changes: 44 additions & 35 deletions core/basepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace Shimmie2;

use MicroHTML\HTMLElement;
use TBela\CSS\Parser;
use TBela\CSS\Renderer;

require_once "core/event.php";

Expand Down Expand Up @@ -113,6 +111,7 @@ public function set_redirect(string $redirect): void
public string $title = "";
public string $heading = "";
public string $subheading = "";
public bool $left_enabled = true;

/** @var string[] */
public array $html_headers = [];
Expand Down Expand Up @@ -157,6 +156,11 @@ public function flash(string $message): void
$this->flash[] = $message;
}

public function disable_left()
{
$this->left_enabled = false;
}

/**
* Add a line to the HTML head section.
*/
Expand Down Expand Up @@ -376,6 +380,9 @@ public function add_auto_html_headers(): void
$css_cache_file = $this->get_css_cache_file($theme_name, $config_latest);
$this->add_html_header("<link rel='stylesheet' href='$data_href/$css_cache_file' type='text/css'>", 43);

$initjs_cache_file = $this->get_initjs_cache_file($theme_name, $config_latest);
$this->add_html_header("<script src='$data_href/$initjs_cache_file' type='text/javascript'></script>", 44);

$js_cache_file = $this->get_js_cache_file($theme_name, $config_latest);
$this->add_html_header("<script defer src='$data_href/$js_cache_file' type='text/javascript'></script>", 44);
}
Expand All @@ -393,31 +400,39 @@ private function get_css_cache_file(string $theme_name, int $config_latest): str
$css_md5 = md5(serialize($css_files));
$css_cache_file = data_path("cache/style/{$theme_name}.{$css_latest}.{$css_md5}.css");
if (!file_exists($css_cache_file)) {
// the CSS minifier causes a bunch of deprecation warnings,
// so we turn off error reporting while it runs
$old_error_level = error_reporting(error_reporting(null) & ~E_DEPRECATED);
$parser = new Parser();
foreach($css_files as $file) {
$parser->append($file);
$mcss = new \MicroBundler\MicroBundler();

Check failure on line 403 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Instantiated class MicroBundler\MicroBundler not found.
foreach($css_files as $css) {
$mcss->addSource($css, file_get_contents($css));

Check failure on line 405 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to method addSource() on an unknown class MicroBundler\MicroBundler.
}
$element = $parser->parse();

// minified output
$renderer = new Renderer([
'compress' => true,
'convert_color' => 'hex',
'css_level' => 3,
'sourcemap' => true,
'allow_duplicate_declarations' => false,
'legacy_rendering' => true, // turn nested CSS into regular
]);
$renderer->save($element, $css_cache_file);
error_reporting($old_error_level);
$mcss->save($css_cache_file);

Check failure on line 407 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to method save() on an unknown class MicroBundler\MicroBundler.
}

return $css_cache_file;
}

private function get_initjs_cache_file(string $theme_name, int $config_latest): string
{
$js_latest = $config_latest;
$js_files = array_merge(
zglob("ext/{" . Extension::get_enabled_extensions_as_string() . "}/init.js"),
zglob("themes/$theme_name/init.js")
);
foreach ($js_files as $js) {
$js_latest = max($js_latest, filemtime($js));
}
$js_md5 = md5(serialize($js_files));
$js_cache_file = data_path("cache/initscript/{$theme_name}.{$js_latest}.{$js_md5}.js");
if (!file_exists($js_cache_file)) {
$mcss = new \MicroBundler\MicroBundler();

Check failure on line 426 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Instantiated class MicroBundler\MicroBundler not found.
foreach($js_files as $js) {
$mcss->addSource($js, file_get_contents($js));

Check failure on line 428 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to method addSource() on an unknown class MicroBundler\MicroBundler.
}
$mcss->save($js_cache_file);

Check failure on line 430 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to method save() on an unknown class MicroBundler\MicroBundler.
}

return $js_cache_file;
}

private function get_js_cache_file(string $theme_name, int $config_latest): string
{
$js_latest = $config_latest;
Expand All @@ -426,7 +441,6 @@ private function get_js_cache_file(string $theme_name, int $config_latest): stri
"vendor/bower-asset/jquery/dist/jquery.min.js",
"vendor/bower-asset/jquery-timeago/jquery.timeago.js",
"vendor/bower-asset/js-cookie/src/js.cookie.js",
"ext/static_files/modernizr-3.3.1.custom.js",
],
zglob("ext/{" . Extension::get_enabled_extensions_as_string() . "}/script.js"),
zglob("themes/$theme_name/{" . implode(",", $this->get_theme_scripts()) . "}")
Expand All @@ -437,17 +451,16 @@ private function get_js_cache_file(string $theme_name, int $config_latest): stri
$js_md5 = md5(serialize($js_files));
$js_cache_file = data_path("cache/script/{$theme_name}.{$js_latest}.{$js_md5}.js");
if (!file_exists($js_cache_file)) {
$js_data = "";
foreach ($js_files as $file) {
$js_data .= file_get_contents($file) . "\n";
$mcss = new \MicroBundler\MicroBundler();

Check failure on line 454 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Instantiated class MicroBundler\MicroBundler not found.
foreach($js_files as $js) {
$mcss->addSource($js, file_get_contents($js));

Check failure on line 456 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to method addSource() on an unknown class MicroBundler\MicroBundler.
}
file_put_contents($js_cache_file, $js_data);
$mcss->save($js_cache_file);

Check failure on line 458 in core/basepage.php

View workflow job for this annotation

GitHub Actions / Static Analysis

Call to method save() on an unknown class MicroBundler\MicroBundler.
}

return $js_cache_file;
}


/**
* @return array A list of stylesheets relative to the theme root.
*/
Expand Down Expand Up @@ -505,8 +518,9 @@ protected function get_nav_links(): array
}

$sub_links = $sub_links ?? [];
usort($nav_links, "Shimmie2\sort_nav_links");
usort($sub_links, "Shimmie2\sort_nav_links");

usort($nav_links, fn (NavLink $a, NavLink $b) => $a->order - $b->order);
usort($sub_links, fn (NavLink $a, NavLink $b) => $a->order - $b->order);

return [$nav_links, $sub_links];
}
Expand All @@ -521,7 +535,7 @@ public function render()

print <<<EOD
<!doctype html>
<html class="no-js" lang="en">
<html lang="en">
$head_html
$body_html
</html>
Expand Down Expand Up @@ -699,8 +713,3 @@ public static function is_active(array $pages_matched, string $url = null): bool
return false;
}
}

function sort_nav_links(NavLink $a, NavLink $b): int
{
return $a->order - $b->order;
}
32 changes: 16 additions & 16 deletions core/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,27 +278,27 @@ public function __construct(
$this->table_name = $table_name;
$this->sub_value = $sub_value;
$this->sub_column = $sub_column;
$this->cache_name = empty($sub_value) ? "config" : "config_{$sub_value}";
$this->cache_name = empty($sub_value) ? "config" : "config_{$sub_column}_{$sub_value}";
$this->values = cache_get_or_set($this->cache_name, fn () => $this->get_values());
}

$cached = $cache->get($this->cache_name);
if (!is_null($cached)) {
$this->values = $cached;
} else {
$this->values = [];
private function get_values(): mixed
{
$values = [];

$query = "SELECT name, value FROM {$this->table_name}";
$args = [];
$query = "SELECT name, value FROM {$this->table_name}";
$args = [];

if (!empty($sub_column) && !empty($sub_value)) {
$query .= " WHERE $sub_column = :sub_value";
$args["sub_value"] = $sub_value;
}
if (!empty($this->sub_column) && !empty($this->sub_value)) {
$query .= " WHERE {$this->sub_column} = :sub_value";
$args["sub_value"] = $this->sub_value;
}

foreach ($this->database->get_all($query, $args) as $row) {
$this->values[$row["name"]] = $row["value"];
}
$cache->set($this->cache_name, $this->values);
foreach ($this->database->get_all($query, $args) as $row) {
$values[$row["name"]] = $row["value"];
}

return $values;
}

public function save(string $name = null): void
Expand Down
Loading

0 comments on commit e1a5274

Please sign in to comment.