Compare commits

..
536 changed files with 24043 additions and 18221 deletions

View file

@ -1,21 +1,18 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true root = true
# Unix-style newlines with a newline ending every file
[*] [*]
charset = utf-8
end_of_line = lf end_of_line = lf
indent_size = 4 charset = utf-8
indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
indent_style = space
[*.{js,css}]
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
[docker-compose.yml]
indent_size = 4 indent_size = 4
# Tab indentation
[Makefile]
indent_style = tab
tab_width = 4

View file

@ -1,69 +1,45 @@
APP_NAME=Laravel APP_NAME=Laravel
APP_ENV=local APP_ENV=production
APP_KEY= APP_KEY=SomeRandomString # Leave this
APP_DEBUG=true APP_DEBUG=false
APP_TIMEZONE=UTC APP_LOG_LEVEL=warning
APP_URL=https://example.com
APP_LONGURL=example.com
APP_SHORTURL=examp.le
APP_LOCALE=en DB_CONNECTION=pgsql
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US
APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database
BCRYPT_ROUNDS=12
LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=3306 DB_PORT=5432
DB_DATABASE=laravel DB_DATABASE=
DB_USERNAME=root DB_USERNAME=
DB_PASSWORD= DB_PASSWORD=
SESSION_DRIVER=database BROADCAST_DRIVER=log
SESSION_LIFETIME=120 CACHE_DRIVER=file
SESSION_ENCRYPT=false SESSION_DRIVER=file
SESSION_PATH=/ QUEUE_DRIVER=sync
SESSION_DOMAIN=null
BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database
CACHE_STORE=database
CACHE_PREFIX=
MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1 REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null REDIS_PASSWORD=null
REDIS_PORT=6379 REDIS_PORT=6379
MAIL_MAILER=log MAIL_DRIVER=smtp
MAIL_HOST=127.0.0.1 MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525 MAIL_PORT=2525
MAIL_USERNAME=null MAIL_USERNAME=null
MAIL_PASSWORD=null MAIL_PASSWORD=null
MAIL_ENCRYPTION=null MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID= PUSHER_APP_ID=
AWS_SECRET_ACCESS_KEY= PUSHER_APP_KEY=
AWS_DEFAULT_REGION=us-east-1 PUSHER_APP_SECRET=
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
VITE_APP_NAME="${APP_NAME}" AWS_S3_KEY=your-key
AWS_S3_SECRET=your-secret
AWS_S3_REGION=region
AWS_S3_BUCKET=your-bucket
AWS_S3_URL=https://xxxxxxx.s3-region.amazonaws.com
APP_URL=https://example.com # This one is necessary
APP_LONGURL=example.com
APP_SHORTURL=examp.le
ADMIN_USER=admin # pick something better, this is used for `/admin` ADMIN_USER=admin # pick something better, this is used for `/admin`
ADMIN_PASS=password ADMIN_PASS=password
@ -74,16 +50,19 @@ TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN= TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET= TWITTER_ACCESS_TOKEN_SECRET=
SCOUT_DRIVER=database SCOUT_DRIVER=pgsql
SCOUT_QUEUE=false
SESSION_SECURE_COOKIE=true PIWIK=false
SESSION_SAME_SITE=strict PIWIK_ID=1
PIWIK_URL=https://analytics.jmb.lv/piwik.php
FATHOM_ID=
APP_TIMEZONE=UTC
APP_LANG=en
APP_LOG=daily
SECURE_SESSION_COOKIE=true
LOG_SLACK_WEBHOOK_URL= LOG_SLACK_WEBHOOK_URL=
FLARE_KEY= FONT_LINK=
IGNITION_OPEN_AI_KEY=
BRIDGY_MASTODON_TOKEN=

View file

@ -7,7 +7,7 @@ APP_LOG_LEVEL=warning
DB_CONNECTION=pgsql DB_CONNECTION=pgsql
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=5432 DB_PORT=5432
DB_DATABASE=jbukdev_testing DB_DATABASE=jbuktest
DB_USERNAME=postgres DB_USERNAME=postgres
DB_PASSWORD=postgres DB_PASSWORD=postgres
@ -50,8 +50,7 @@ TWITTER_CONSUMER_SECRET=
TWITTER_ACCESS_TOKEN= TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET= TWITTER_ACCESS_TOKEN_SECRET=
SCOUT_DRIVER=database SCOUT_DRIVER=pgsql
SCOUT_QUEUE=false
PIWIK=false PIWIK=false
@ -63,8 +62,5 @@ APP_LOG=daily
SECURE_SESSION_COOKIE=true SECURE_SESSION_COOKIE=true
LOG_SLACK_WEBHOOK_URL= LOG_SLACK_WEBHOOK_URL=
FLARE_KEY=
FONT_LINK= FONT_LINK=
BRIDGY_MASTODON_TOKEN=

17
.env.travis Normal file
View file

@ -0,0 +1,17 @@
APP_ENV=testing
APP_DEBUG=true
APP_KEY=base64:6DJhvZLVjE6dD4Cqrteh+6Z5vZlG+v/soCKcDHLOAH0=
APP_URL=http://jonnybarnes.localhost
APP_LONGURL=jonnybarnes.localhost
APP_SHORTURL=jmb.localhost
DB_CONNECTION=travis
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync
SCOUT_DRIVER=pgsql
DISPLAY_NAME='Travis Test'
USER_NAME=travis

24
.eslintrc.yml Normal file
View file

@ -0,0 +1,24 @@
parserOptions:
sourceType: 'module'
extends: 'eslint:recommended'
env:
browser: true
es6: true
rules:
indent:
- error
- 4
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- always
no-console:
- error
- allow:
- warn
- error

14
.gitattributes vendored
View file

@ -1,11 +1,5 @@
* text=auto eol=lf * text=auto
*.css linguist-vendored
*.blade.php diff=html *.scss linguist-vendored
*.css diff=css *.js linguist-vendored
*.html diff=html
*.md diff=markdown
*.php diff=php
/.github export-ignore
CHANGELOG.md export-ignore CHANGELOG.md export-ignore
.styleci.yml export-ignore

View file

@ -1,17 +0,0 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

View file

@ -1,144 +0,0 @@
name: Deploy
on:
workflow_dispatch:
release:
types: [published]
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: Hetzner
env:
repository: 'jonnybarnes/jonnybarnes.uk'
newReleaseName: '${{ github.run_id }}'
steps:
- name: 🌍 Set Environment Variables
run: |
echo "releasesDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/releases" >> $GITHUB_ENV
echo "persistentDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent" >> $GITHUB_ENV
echo "currentDir=${{ secrets.DEPLOYMENT_BASE_DIR }}/current" >> $GITHUB_ENV
- name: 🌎 Set Environment Variables Part 2
run: |
echo "newReleaseDir=${{ env.releasesDir }}/${{ env.newReleaseName }}" >> $GITHUB_ENV
- name: 🔄 Clone Repository
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
[ -d ${{ env.releasesDir }} ] || mkdir ${{ env.releasesDir }}
[ -d ${{ env.persistentDir }} ] || mkdir ${{ env.persistentDir }}
[ -d ${{ env.persistentDir }}/storage ] || mkdir ${{ env.persistentDir }}/storage
cd ${{ env.releasesDir }}
# Create new release directory
mkdir ${{ env.newReleaseDir }}
# Clone app
git clone --depth 1 --branch ${{ github.ref_name }} https://github.com/${{ env.repository }} ${{ env.newReleaseName }}
# Mark release
cd ${{ env.newReleaseDir }}
echo "${{ env.newReleaseName }}" > public/release-name.txt
# Fix cache directory permissions
sudo chown -R ${{ secrets.HTTP_USER }}:${{ secrets.HTTP_USER }} bootstrap/cache
- name: 🎵 Run Composer
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
cd ${{ env.newReleaseDir }}
composer install --prefer-dist --no-scripts --no-dev --no-progress --optimize-autoloader --quiet --no-interaction
- name: 🔗 Update Symlinks
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
# Import the environment config
cd ${{ env.newReleaseDir }};
ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/.env .env;
# Remove the storage directory and replace with persistent data
rm -rf ${{ env.newReleaseDir }}/storage;
cd ${{ env.newReleaseDir }};
ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/storage storage;
# Remove the public/profile-images directory and replace with persistent data
rm -rf ${{ env.newReleaseDir }}/public/assets/profile-images;
cd ${{ env.newReleaseDir }};
ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/profile-images public/assets/profile-images;
# Add the persistent files data
cd ${{ env.newReleaseDir }};
ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/files public/files;
# Add the persistent fonts data
cd ${{ env.newReleaseDir }};
ln -nfs ${{ secrets.DEPLOYMENT_BASE_DIR }}/persistent/fonts public/fonts;
- name: ✨ Optimize Installation
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
cd ${{ env.newReleaseDir }};
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan clear-compiled;
- name: 🙈 Migrate database
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
cd ${{ env.newReleaseDir }}
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan migrate --force
- name: 🙏 Bless release
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
ln -nfs ${{ env.newReleaseDir }} ${{ env.currentDir }};
cd ${{ env.newReleaseDir }}
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan horizon:terminate
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan config:cache
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan event:cache
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan route:cache
sudo runuser -u ${{ secrets.HTTP_USER }} -- php artisan view:cache
sudo systemctl restart php-fpm.service
sudo systemctl restart jbuk-horizon.service
- name: 🚾 Clean up old releases
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOYMENT_HOST }}
port: ${{ secrets.DEPLOYMENT_PORT }}
username: ${{ secrets.DEPLOYMENT_USER }}
key: ${{ secrets.DEPLOYMENT_KEY }}
script: |
fd '.+' ${{ env.releasesDir }} -d 1 | head -n -3 | xargs -d "\n" -I'{}' sudo chown -R ${{ secrets.DEPLOYMENT_USER }}:${{ secrets.DEPLOYMENT_USER }} {}
fd '.+' ${{ env.releasesDir }} -d 1 | head -n -3 | xargs -d "\n" -I'{}' rm -rf {}

View file

@ -1,65 +0,0 @@
name: PHP Unit
on:
pull_request:
jobs:
phpunit:
runs-on: ubuntu-latest
name: PHPUnit test suite
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: jbukdev_testing
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, intl, phpredis, imagick
coverage: xdebug
tools: phpunit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.github', '.env');"
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-php-8.3-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-8.3-composer-
- name: Install Composer Dependencies
run: composer install --quiet --no-ansi --no-interaction --no-progress
- name: Generate Key
run: php artisan key:generate
- name: Setup Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Setup Database
run: php artisan migrate
- name: Execute PHPUnit Tests
run: vendor/bin/phpunit

View file

@ -1,38 +0,0 @@
name: Laravel Pint
on:
pull_request:
jobs:
pint:
runs-on: ubuntu-latest
name: Laravel Pint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP with pecl extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: composer install --quiet --no-ansi --no-interaction --no-progress
- name: Check Files with Laravel Pint
run: vendor/bin/pint --test

56
.github/workflows/run-tests.yml vendored Normal file
View file

@ -0,0 +1,56 @@
name: Run Tests
on:
pull_request:
jobs:
phpunit:
runs-on: ubuntu-20.04
name: PHPUnit test suite
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: jbuktest
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
- name: Install npm dependencies
run: npm install
- name: Install ImageMagick
run: sudo apt install imagemagick
- name: Setup PHP with pecl extension
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: pecl, phpcs
extensions: imagick
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.github', '.env');"
- name: Install dependencies
run: composer install -q --no-ansi --no-interaction --no-progress
- name: Generate key
run: php artisan key:generate
- name: Setup directory permissions
run: chmod -R 777 storage bootstrap/cache
- name: Setup test database
run: |
php artisan migrate
php artisan db:seed
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
- name: Run phpcs
run: phpcs
- name: Check for security vulnerabilities
run: php vendor/bin/security-checker security:check

23
.gitignore vendored
View file

@ -1,23 +1,20 @@
/.phpunit.cache
/node_modules /node_modules
/public/build
/public/coverage
/public/hot
/public/files
/public/fonts
/public/storage
/storage/*.key /storage/*.key
/vendor /vendor
.env .env
.env.backup
.env.production
.phpunit.result.cache .phpunit.result.cache
Homestead.json Homestead.json
Homestead.yaml Homestead.yaml
auth.json
npm-debug.log npm-debug.log
yarn-error.log yarn-error.log
/.fleet
/.idea /.idea
/.vscode /lsp
ray.php .phpstorm.meta.php
_ide_helper.php
# Custom paths in /public
/public/coverage
/public/hot
/public/storage
/public/fonts
/public/files
/public/keybase.txt

View file

@ -1,9 +1,8 @@
php:
preset: laravel preset: laravel
disabled: disabled:
- no_unused_imports - concat_without_spaces
- single_import_per_statement
finder: finder:
not-name: path: app/
- index.php
js: true
css: true

View file

@ -1,3 +1,6 @@
{ {
"extends": ["stylelint-config-standard"] "extends": ["stylelint-config-standard", "stylelint-a11y/recommended"],
"rules": {
"indentation": 4
}
} }

View file

@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
namespace App\CommonMark\Generators;
use League\CommonMark\Extension\Mention\Generator\MentionGeneratorInterface;
use League\CommonMark\Extension\Mention\Mention;
use League\CommonMark\Node\Inline\AbstractInline;
class MentionGenerator implements MentionGeneratorInterface
{
public function generateMention(Mention $mention): ?AbstractInline
{
return $mention;
}
}

View file

@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace App\CommonMark\Renderers;
use App\Models\Contact;
use League\CommonMark\Node\Node;
use League\CommonMark\Renderer\ChildNodeRendererInterface;
use League\CommonMark\Renderer\NodeRendererInterface;
use League\CommonMark\Util\HtmlElement;
class MentionRenderer implements NodeRendererInterface
{
public function render(Node $node, ChildNodeRendererInterface $childRenderer): HtmlElement|string
{
$contact = Contact::where('nick', $node->getIdentifier())->first();
// If we have a contact, render a mini-hcard
if ($contact) {
// rendering a blade template to a string, so can’t be an HtmlElement
return trim(view('templates.mini-hcard', ['contact' => $contact])->render());
}
// Otherwise, check the link is to the Mastodon profile
$mentionText = $node->getIdentifier();
$parts = explode('@', $mentionText);
// This is not [@]handle@instance, so return a Twitter link
if (count($parts) === 1) {
return new HtmlElement('a', ['href' => 'https://twitter.com/' . $parts[0]], '@' . $mentionText);
}
// Render the Mastodon profile link
return new HtmlElement('a', ['href' => 'https://' . $parts[1] . '/@' . $parts[0]], '@' . $mentionText);
}
}

View file

@ -6,11 +6,6 @@ use App\Models\Place;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
/**
* @codeCoverageIgnore
*
* @psalm-suppress UnusedClass
*/
class MigratePlaceDataFromPostgis extends Command class MigratePlaceDataFromPostgis extends Command
{ {
/** /**
@ -28,9 +23,21 @@ class MigratePlaceDataFromPostgis extends Command
protected $description = 'Copy Postgis data to normal latitude longitude fields'; protected $description = 'Copy Postgis data to normal latitude longitude fields';
/** /**
* Execute the console command. * Create a new command instance.
*
* @return void
*/ */
public function handle(): int public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{ {
$locationColumn = DB::selectOne(DB::raw(" $locationColumn = DB::selectOne(DB::raw("
SELECT EXISTS ( SELECT EXISTS (

View file

@ -6,12 +6,8 @@ namespace App\Console\Commands;
use App\Models\WebMention; use App\Models\WebMention;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\FileSystem\FileSystem; use Illuminate\FileSystem\FileSystem;
/**
* @psalm-suppress UnusedClass
*/
class ParseCachedWebMentions extends Command class ParseCachedWebMentions extends Command
{ {
/** /**
@ -28,22 +24,32 @@ class ParseCachedWebMentions extends Command
*/ */
protected $description = 'Re-parse the webmention’s cached HTML'; protected $description = 'Re-parse the webmention’s cached HTML';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/** /**
* Execute the console command. * Execute the console command.
* *
* @throws FileNotFoundException * @return mixed
*/ */
public function handle(FileSystem $filesystem): void public function handle(FileSystem $filesystem)
{ {
$htmlFiles = $filesystem->allFiles(storage_path() . '/HTML'); $HTMLfiles = $filesystem->allFiles(storage_path() . '/HTML');
foreach ($htmlFiles as $file) { foreach ($HTMLfiles as $file) {
if ($file->getExtension() !== 'backup') { //we don’t want to parse `.backup` files if ($file->getExtension() != 'backup') { //we don’t want to parse.backup files
$filepath = $file->getPathname(); $filepath = $file->getPathname();
$this->info('Loading HTML from: ' . $filepath); $this->info('Loading HTML from: ' . $filepath);
$html = $filesystem->get($filepath); $html = $filesystem->get($filepath);
$url = $this->urlFromFilename($filepath); $url = $this->URLFromFilename($filepath);
$webmention = WebMention::where('source', $url)->firstOrFail();
$microformats = \Mf2\parse($html, $url); $microformats = \Mf2\parse($html, $url);
$webmention = WebMention::where('source', $url)->firstOrFail();
$webmention->mf2 = json_encode($microformats); $webmention->mf2 = json_encode($microformats);
$webmention->save(); $webmention->save();
$this->info('Saved the microformats to the database.'); $this->info('Saved the microformats to the database.');
@ -53,13 +59,16 @@ class ParseCachedWebMentions extends Command
/** /**
* Determine the source URL from a filename. * Determine the source URL from a filename.
*
* @param string
* @return string
*/ */
private function urlFromFilename(string $filepath): string private function URLFromFilename(string $filepath): string
{ {
$dir = mb_substr($filepath, mb_strlen(storage_path() . '/HTML/')); $dir = mb_substr($filepath, mb_strlen(storage_path() . '/HTML/'));
$url = str_replace(['http/', 'https/'], ['http://', 'https://'], $dir); $url = str_replace(['http/', 'https/'], ['http://', 'https://'], $dir);
if (mb_substr($url, -10) === 'index.html') { if (mb_substr($url, -10) == 'index.html') {
$url = mb_substr($url, 0, -10); $url = mb_substr($url, 0, mb_strlen($url) - 10);
} }
return $url; return $url;

View file

@ -8,9 +8,6 @@ use App\Jobs\DownloadWebMention;
use App\Models\WebMention; use App\Models\WebMention;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/**
* @psalm-suppress UnusedClass
*/
class ReDownloadWebMentions extends Command class ReDownloadWebMentions extends Command
{ {
/** /**
@ -28,9 +25,21 @@ class ReDownloadWebMentions extends Command
protected $description = 'Redownload the HTML content of webmentions'; protected $description = 'Redownload the HTML content of webmentions';
/** /**
* Execute the console command. * Create a new command instance.
*
* @return void
*/ */
public function handle(): void public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{ {
$webmentions = WebMention::all(); $webmentions = WebMention::all();
foreach ($webmentions as $webmention) { foreach ($webmentions as $webmention) {

View file

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use Illuminate\Console\Command;
use SensioLabs\Security\SecurityChecker;
/**
* @codeCoverageIgnore
*/
class SecurityCheck extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'security:check';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run the SensioLab’s Security Check tool';
/**
* The Security Checker intergation service.
*
* @var SecurityChecker
*/
protected $securityChecker;
/**
* Create a new command instance.
*
* @param SecurityChecker $SecurityChecker
* @return void
*/
public function __construct(SecurityChecker $securityChecker)
{
parent::__construct();
$this->securityChecker = $securityChecker;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle(): int
{
$alerts = $this->securityChecker->check(base_path() . '/composer.lock');
if (count($alerts) === 0) {
$this->info('No security vulnerabilities found.');
return 0;
}
$this->error('vulnerabilities found');
return 1;
}
}

Some files were not shown because too many files have changed in this diff Show more