diff --git a/app/Follower.php b/app/Follower.php index 118495fe2..54eddd358 100644 --- a/app/Follower.php +++ b/app/Follower.php @@ -21,6 +21,12 @@ class Follower extends Model return $this->belongsTo(Profile::class, 'following_id', 'id'); } + public function permalink() + { + $path = $this->actor->permalink("/follow/{$this->id}"); + return url($path); + } + public function toText() { $actorName = $this->actor->username; diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index f7af111cf..2090f599e 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -64,12 +64,12 @@ class AccountController extends Controller ]); $profile = Auth::user()->profile; $action = $request->input('a'); - $timeago = Carbon::now()->subMonths(1); + $timeago = Carbon::now()->subMonths(3); $following = $profile->following->pluck('id'); $notifications = Notification::whereIn('actor_id', $following) ->where('profile_id', '!=', $profile->id) ->whereDate('created_at', '>', $timeago) - ->orderBy('notifications.id', 'desc') + ->orderBy('notifications.created_at', 'desc') ->simplePaginate(30); return view('account.following', compact('profile', 'notifications')); diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 04c42747e..77962b1be 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -22,6 +22,7 @@ class StatusController extends Controller $user = Profile::whereUsername($username)->firstOrFail(); $status = Status::whereProfileId($user->id) + ->where('visibility', '!=', 'draft') ->withCount(['likes', 'comments', 'media']) ->findOrFail($id); @@ -41,7 +42,7 @@ class StatusController extends Controller $template = $this->detectTemplate($status); - $replies = Status::whereInReplyToId($status->id)->simplePaginate(30); + $replies = Status::whereInReplyToId($status->id)->orderBy('created_at', 'desc')->simplePaginate(30); return view($template, compact('user', 'status', 'replies')); } @@ -59,6 +60,9 @@ class StatusController extends Controller if ($status->viewType() == 'video') { $template = 'status.show.video'; } + if ($status->viewType() == 'video-album') { + $template = 'status.show.video-album'; + } return $template; }); @@ -85,13 +89,7 @@ class StatusController extends Controller } $this->validate($request, [ - 'photo.*' => function() { - return [ - 'required', - 'mimes:' . config('pixelfed.media_types'), - 'max:' . config('pixelfed.max_photo_size'), - ]; - }, + 'photo.*' => 'required|mimetypes:' . config('pixelfed.media_types').'|max:' . config('pixelfed.max_photo_size'), 'caption' => 'string|max:'.config('pixelfed.max_caption_length'), 'cw' => 'nullable|string', 'filter_class' => 'nullable|string', diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php index 58665fb0a..39094c033 100644 --- a/app/Http/Controllers/TimelineController.php +++ b/app/Http/Controllers/TimelineController.php @@ -29,6 +29,7 @@ class TimelineController extends Controller ->pluck('filterable_id'); $timeline = Status::whereIn('profile_id', $following) ->whereNotIn('profile_id', $filtered) + ->whereVisibility('public') ->orderBy('created_at', 'desc') ->withCount(['comments', 'likes']) ->simplePaginate(20); diff --git a/app/Media.php b/app/Media.php index c1d36e558..55cdd854f 100644 --- a/app/Media.php +++ b/app/Media.php @@ -32,4 +32,32 @@ class Media extends Model return url($url); } + + public function mimeType() + { + return explode('/', $this->mime)[0]; + } + + public function activityVerb() + { + $verb = 'Image'; + switch ($this->mimeType()) { + case 'image': + break; + + case 'video': + $verb = 'Video'; + break; + + default: + $verb = 'Document'; + break; + } + return $verb; + } + + public function getMetadata() + { + return json_decode($this->metadata, true, 3); + } } diff --git a/app/Profile.php b/app/Profile.php index b69bf74b9..4fe81c033 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -23,7 +23,7 @@ class Profile extends Model 'private_key', ]; - protected $visible = ['id', 'username', 'name']; + protected $visible = ['username', 'name']; public function user() { @@ -51,6 +51,10 @@ class Profile extends Model public function emailUrl() { + if($this->domain) { + return $this->username; + } + $domain = parse_url(config('app.url'), PHP_URL_HOST); return $this->username.'@'.$domain; @@ -137,7 +141,7 @@ class Profile extends Model { $url = Cache::remember("avatar:{$this->id}", 1440, function () { $path = optional($this->avatar)->media_path; - $version = hash('sha1', $this->avatar->created_at); + $version = hash('sha1', $this->avatar->updated_at); $path = "{$path}?v={$version}"; return url(Storage::url($path)); diff --git a/app/Status.php b/app/Status.php index bfbdeb4e6..70095d3f6 100644 --- a/app/Status.php +++ b/app/Status.php @@ -18,6 +18,8 @@ class Status extends Model */ protected $dates = ['deleted_at']; + protected $fillable = ['profile_id', 'visibility']; + public function profile() { return $this->belongsTo(Profile::class); @@ -36,16 +38,21 @@ class Status extends Model public function viewType() { $media = $this->firstMedia(); - $type = explode('/', $media->mime); + $mime = explode('/', $media->mime)[0]; + $count = $this->media()->count(); + $type = ($mime == 'image') ? 'image' : 'video'; + if($count > 1) { + $type = ($type == 'image') ? 'album' : 'video-album'; + } - return $type[0]; + return $type; } public function thumb($showNsfw = false) { $type = $this->viewType(); $is_nsfw = !$showNsfw ? $this->is_nsfw : false; - if ($this->media->count() == 0 || $is_nsfw || $type != 'image') { + if ($this->media->count() == 0 || $is_nsfw || !in_array($type,['image', 'album'])) { return 'data:image/gif;base64,R0lGODlhAQABAIAAAMLCwgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=='; } diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 5af4dfd62..45ff02564 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -23,8 +23,8 @@ class AccountTransformer extends Fractal\TransformerAbstract 'url' => $profile->url(), 'avatar' => $profile->avatarUrl(), 'avatar_static' => $profile->avatarUrl(), - 'header' => '', - 'header_static' => '', + 'header' => null, + 'header_static' => null, 'moved' => null, 'fields' => null, 'bot' => null, diff --git a/app/Transformer/Api/MediaTransformer.php b/app/Transformer/Api/MediaTransformer.php index 81f49d6af..23c65fe81 100644 --- a/app/Transformer/Api/MediaTransformer.php +++ b/app/Transformer/Api/MediaTransformer.php @@ -11,7 +11,7 @@ class MediaTransformer extends Fractal\TransformerAbstract { return [ 'id' => $media->id, - 'type' => 'image', + 'type' => $media->activityVerb(), 'url' => $media->url(), 'remote_url' => null, 'preview_url' => $media->thumbnailUrl(), diff --git a/app/User.php b/app/User.php index 7fba2c170..16d1b3078 100644 --- a/app/User.php +++ b/app/User.php @@ -35,7 +35,8 @@ class User extends Authenticatable protected $hidden = [ 'email', 'password', 'is_admin', 'remember_token', 'email_verified_at', '2fa_enabled', '2fa_secret', - '2fa_backup_codes', '2fa_setup_at', + '2fa_backup_codes', '2fa_setup_at', 'deleted_at', + 'updated_at' ]; public function profile() @@ -52,4 +53,9 @@ class User extends Authenticatable { return $this->hasOne(UserSetting::class); } + + public function receivesBroadcastNotificationsOn() + { + return 'App.User.'.$this->id; + } } diff --git a/app/Util/Media/Image.php b/app/Util/Media/Image.php index a0a16f522..0c382258b 100644 --- a/app/Util/Media/Image.php +++ b/app/Util/Media/Image.php @@ -13,6 +13,10 @@ class Image public $portrait; public $thumbnail; public $orientation; + public $acceptedMimes = [ + 'image/png', + 'image/jpeg', + ]; public function __construct() { @@ -22,27 +26,27 @@ class Image $this->landscape = $this->orientations()['landscape']; $this->portrait = $this->orientations()['portrait']; $this->thumbnail = [ - 'width' => 293, - 'height' => 293, - ]; + 'width' => 640, + 'height' => 640, + ]; $this->orientation = null; } public function orientations() { return [ - 'square' => [ - 'width' => 1080, - 'height' => 1080, - ], - 'landscape' => [ - 'width' => 1920, - 'height' => 1080, - ], - 'portrait' => [ - 'width' => 1080, - 'height' => 1350, - ], + 'square' => [ + 'width' => 1080, + 'height' => 1080, + ], + 'landscape' => [ + 'width' => 1920, + 'height' => 1080, + ], + 'portrait' => [ + 'width' => 1080, + 'height' => 1350, + ], ]; } @@ -53,9 +57,9 @@ class Image } if ($thumbnail) { return [ - 'dimensions' => $this->thumbnail, - 'orientation' => 'thumbnail', - ]; + 'dimensions' => $this->thumbnail, + 'orientation' => 'thumbnail', + ]; } list($width, $height) = getimagesize($mediaPath); @@ -98,18 +102,22 @@ class Image { $path = $media->media_path; $file = storage_path('app/'.$path); + if (!in_array($media->mime, $this->acceptedMimes)) { + return; + } $ratio = $this->getAspectRatio($file, $thumbnail); $aspect = $ratio['dimensions']; $orientation = $ratio['orientation']; - if ($media->mime === 'image/gif' && !$thumbnail) { - return; - } try { $img = Intervention::make($file)->orientate(); - $img->resize($aspect['width'], $aspect['height'], function ($constraint) { - $constraint->aspectRatio(); - }); + if($thumbnail) { + $img->crop($aspect['width'], $aspect['height']); + } else { + $img->resize($aspect['width'], $aspect['height'], function ($constraint) { + $constraint->aspectRatio(); + }); + } $converted = $this->setBaseName($path, $thumbnail, $img->extension); $newPath = storage_path('app/'.$converted['path']); diff --git a/config/database.php b/config/database.php index 1b88fbad3..fb8136b3e 100644 --- a/config/database.php +++ b/config/database.php @@ -50,7 +50,7 @@ return [ 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', - 'strict' => true, + 'strict' => false, 'engine' => null, ], diff --git a/contrib/docker/start.sh b/contrib/docker/start.sh index be374a914..59c54b978 100755 --- a/contrib/docker/start.sh +++ b/contrib/docker/start.sh @@ -9,7 +9,7 @@ php artisan storage:link php artisan migrate --force # Run a worker if it is set as embedded -if [ HORIZON_EMBED = true ]; then +if [ $HORIZON_EMBED = true ]; then php artisan horizon & fi diff --git a/database/migrations/2018_09_19_060554_create_stories_table.php b/database/migrations/2018_09_19_060554_create_stories_table.php new file mode 100644 index 000000000..5f204ea11 --- /dev/null +++ b/database/migrations/2018_09_19_060554_create_stories_table.php @@ -0,0 +1,34 @@ +increments('bigIncrements'); + $table->bigInteger('profile_id')->unsigned(); + $table->timestamp('published_at')->nullable(); + $table->timestamp('expires_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('stories'); + } +} diff --git a/database/migrations/2018_09_19_060611_create_story_reactions_table.php b/database/migrations/2018_09_19_060611_create_story_reactions_table.php new file mode 100644 index 000000000..eb1d71782 --- /dev/null +++ b/database/migrations/2018_09_19_060611_create_story_reactions_table.php @@ -0,0 +1,33 @@ +bigIncrements('id'); + $table->bigInteger('profile_id')->unsigned()->nullable(); + $table->string('reaction')->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('story_reactions'); + } +} diff --git a/database/migrations/2018_09_27_040314_create_collections_table.php b/database/migrations/2018_09_27_040314_create_collections_table.php new file mode 100644 index 000000000..580d993c3 --- /dev/null +++ b/database/migrations/2018_09_27_040314_create_collections_table.php @@ -0,0 +1,37 @@ +bigIncrements('id'); + $table->bigInteger('profile_id')->unsigned()->nullable(); + $table->string('title')->nullable(); + $table->text('description')->nullable(); + $table->boolean('is_nsfw')->default(false); + $table->string('visibility')->default('public')->index(); + $table->timestamp('published_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('collections'); + } +} diff --git a/database/migrations/2018_09_30_051108_create_direct_messages_table.php b/database/migrations/2018_09_30_051108_create_direct_messages_table.php new file mode 100644 index 000000000..63b305f4d --- /dev/null +++ b/database/migrations/2018_09_30_051108_create_direct_messages_table.php @@ -0,0 +1,38 @@ +bigIncrements('id'); + $table->bigInteger('to_id')->unsigned()->index(); + $table->bigInteger('from_id')->unsigned()->index(); + $table->string('from_profile_ids')->nullable(); + $table->boolean('group_message')->default(false); + $table->bigInteger('status_id')->unsigned()->integer(); + $table->unique(['to_id', 'from_id', 'status_id']); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('direct_messages'); + } +} diff --git a/database/migrations/2018_10_02_040917_create_collection_items_table.php b/database/migrations/2018_10_02_040917_create_collection_items_table.php new file mode 100644 index 000000000..fba5ced78 --- /dev/null +++ b/database/migrations/2018_10_02_040917_create_collection_items_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->bigInteger('collection_id')->unsigned()->index(); + $table->unsignedInteger('order')->nullable(); + $table->string('object_type')->default('post')->index(); + $table->bigInteger('object_id')->unsigned()->index(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('collection_items'); + } +} diff --git a/database/migrations/2018_10_09_043717_update_status_visibility_defaults.php b/database/migrations/2018_10_09_043717_update_status_visibility_defaults.php new file mode 100644 index 000000000..9c0dc3375 --- /dev/null +++ b/database/migrations/2018_10_09_043717_update_status_visibility_defaults.php @@ -0,0 +1,28 @@ + 'About', + 'help' => 'Help', + 'language' => 'Language', + 'fediverse' => 'Fediverse', + 'opensource' => 'Open Source', + 'terms' => 'Terms', + 'privacy' => 'Privacy', + 'l10nWip' => 'We’re still working on localization support', + 'currentLocale' => 'Current locale', + 'selectLocale' => 'Select from one of the supported languages', + +]; \ No newline at end of file diff --git a/resources/lang/fr/site.php b/resources/lang/fr/site.php new file mode 100644 index 000000000..4514e3321 --- /dev/null +++ b/resources/lang/fr/site.php @@ -0,0 +1,16 @@ + 'Environ', + 'help' => 'Aidez-moi', + 'language' => 'La langue', + 'fediverse' => 'Fediverse', + 'opensource' => 'Open Source', + 'terms' => 'Termes', + 'privacy' => 'Intimité', + 'l10nWip' => 'Nous travaillons toujours sur le support de la localisation', + 'currentLocale' => 'Locale actuelle', + 'selectLocale' => 'Sélectionnez l\'une des langues prises en charge', + +]; \ No newline at end of file diff --git a/resources/views/admin/home.blade.php b/resources/views/admin/home.blade.php index 5cc59d605..c8cf6e620 100644 --- a/resources/views/admin/home.blade.php +++ b/resources/views/admin/home.blade.php @@ -30,30 +30,33 @@ + @php($reports = App\Report::whereNull('admin_seen')->count())
-

{{App\Util\Lexer\PrettyNumber::convert(App\Report::whereNull('admin_seen')->count())}}

+

{{App\Util\Lexer\PrettyNumber::convert($reports)}}

Reports

+ @php($statuses = App\Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count())
-

{{App\Util\Lexer\PrettyNumber::convert(App\Status::whereNull('in_reply_to_id')->whereNull('reblog_of_id')->count())}}

+

{{App\Util\Lexer\PrettyNumber::convert($statuses)}}

Statuses

+ @php($replies = App\Status::whereNotNull('in_reply_to_id')->count())
-

{{App\Util\Lexer\PrettyNumber::convert(App\Status::whereNotNull('in_reply_to_id')->count())}}

+

{{App\Util\Lexer\PrettyNumber::convert($replies)}}

Replies

diff --git a/resources/views/errors/500.blade.php b/resources/views/errors/500.blade.php index 0e134790a..b163d53c9 100644 --- a/resources/views/errors/500.blade.php +++ b/resources/views/errors/500.blade.php @@ -6,7 +6,7 @@

Whoops! Something went wrong.

-

Please try again, if this error keeps happening please contact an admin.

+

If you keep seeing this message, please contact an admin.

diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php new file mode 100644 index 000000000..c2e54df94 --- /dev/null +++ b/tests/Feature/LoginTest.php @@ -0,0 +1,31 @@ +get('login'); + + $response->assertSuccessful() + ->assertSee('Forgot Your Password?'); + } + + /** @test */ + public function view_register_page() + { + if(true === config('pixelfed.open_registration')) { + $response = $this->get('register'); + + $response->assertSuccessful() + ->assertSee('Register a new account'); + } else { + $this->assertTrue(true); + } + } +} \ No newline at end of file