2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
use App\Tag;
|
|
|
|
use App\Note;
|
|
|
|
use Validator;
|
|
|
|
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 = [];
|
2016-05-29 17:35:39 +01:00
|
|
|
preg_match_all('/#([^\s<>]+)\b/', $note, $tags);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
if (count($tagsToAdd > 0)) {
|
|
|
|
$note->tags()->attach($tagsToAdd);
|
|
|
|
}
|
|
|
|
});
|
2016-10-03 16:26:07 +01:00
|
|
|
|
|
|
|
//allow micropub use in development
|
|
|
|
if (env('APP_DEBUG') == true) {
|
|
|
|
$tokenService = new \App\Services\TokenService();
|
|
|
|
$token = $tokenService->getNewToken([
|
|
|
|
'me' => 'https://jonnybarnes.localhost',
|
|
|
|
'client_id' => 'https://jonnybarnes.localhost/notes/new',
|
|
|
|
'scope' => 'post'
|
|
|
|
]);
|
|
|
|
session(['me' => 'https://jonnybarnes.localhost']);
|
|
|
|
session(['token' => 'abc123']);
|
|
|
|
}
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any application services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|