2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use App\Tag;
|
|
|
|
use App\Note;
|
|
|
|
use Validator;
|
2017-09-11 15:56:11 +01:00
|
|
|
use Illuminate\Http\Request;
|
2017-02-18 12:27:21 +00:00
|
|
|
use Laravel\Dusk\DuskServiceProvider;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bootstrap any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
// Validate photos for a maximum filesize
|
|
|
|
Validator::extend('photosize', function ($attribute, $value, $parameters, $validator) {
|
|
|
|
if ($value[0] !== null) {
|
|
|
|
foreach ($value as $file) {
|
|
|
|
if ($file->getSize() > 5000000) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
//Add tags for notes
|
|
|
|
Note::created(function ($note) {
|
|
|
|
$tagsToAdd = [];
|
2017-05-18 15:15:53 +01:00
|
|
|
preg_match_all('/#([^\s<>]+)\b/', $note->note, $tags);
|
2016-05-29 17:35:39 +01:00
|
|
|
foreach ($tags[1] as $tag) {
|
|
|
|
$tag = Tag::normalizeTag($tag);
|
|
|
|
}
|
|
|
|
$tags = array_unique($tags[1]);
|
|
|
|
foreach ($tags as $tag) {
|
|
|
|
$tag = Tag::firstOrCreate(['tag' => $tag]);
|
2016-05-19 15:01:28 +01:00
|
|
|
$tagsToAdd[] = $tag->id;
|
|
|
|
}
|
2017-09-12 14:39:22 +01:00
|
|
|
if (count($tagsToAdd) > 0) {
|
2016-05-19 15:01:28 +01:00
|
|
|
$note->tags()->attach($tagsToAdd);
|
|
|
|
}
|
|
|
|
});
|
2017-09-11 15:56:11 +01:00
|
|
|
|
|
|
|
// Request AS macro
|
2017-09-13 17:02:31 +00:00
|
|
|
Request::macro('wantsActivityStream', function () {
|
2017-09-11 15:56:11 +01:00
|
|
|
return str_contains(mb_strtolower($this->header('Accept')), 'application/activity+json');
|
|
|
|
});
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2017-02-18 12:27:21 +00:00
|
|
|
if ($this->app->environment('local', 'testing')) {
|
|
|
|
$this->app->register(DuskServiceProvider::class);
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
}
|