diff --git a/app/Http/Controllers/SandboxController.php b/app/Http/Controllers/SandboxController.php deleted file mode 100644 index 590bf67..0000000 --- a/app/Http/Controllers/SandboxController.php +++ /dev/null @@ -1,107 +0,0 @@ - $this->getDefcode() - ]); - } - - private function evaluateCode($code) - { - ini_set('display_errors', true); - ini_set('display_startup_errors', true); - ini_set('display_not_found_reason', true); - ini_set('display_exceptions', true); - ini_set('html_errors', false); - - error_reporting(E_ALL | E_STRICT); - - ob_start(); - $memBefore = memory_get_usage(true); - $startTime = microtime(true); - - // Remove the validate($request, [ - 'code' => 'required' - ]); - - $out = $this->evaluateCode($request->code); - - if ($request->wantsJson()) { - - $resp = Response::json([ - 'output' => $out['output'] . "\n#end-php-console-output#", - 'memory' => sprintf('%.3f', $out['memory']), - 'duration' => sprintf('%.3f', $out['duration']) - ], 200); - - return $resp; - - } else { - - // Full HTML page - return view('debug.sandbox', [ - 'code' => $request->code, - 'defcode' => $this->getDefcode(), - 'output' => $out['output'] - ]); - - } - } - - private function getDefcode() - { - return <<notificationsAbout()->delete(); - }); - } - - /** - * Notifications having this model as a context - * - * @return MorphMany - */ - public function notificationsAbout() - { - return $this->morphMany(Notification::class, 'context'); - } -} diff --git a/app/Models/Concerns/Reportable.php b/app/Models/Concerns/Reportable.php index 4ec845c..5ced1b1 100644 --- a/app/Models/Concerns/Reportable.php +++ b/app/Models/Concerns/Reportable.php @@ -7,6 +7,9 @@ namespace App\Models\Concerns; use App\Models\ContentReport; use Illuminate\Database\Eloquent\Relations\MorphMany; +/** + * @property ContentReport $reportsOf + */ trait Reportable { public function bootReportable() diff --git a/app/Models/Proposal.php b/app/Models/Proposal.php index 67027b5..b9e09c3 100644 --- a/app/Models/Proposal.php +++ b/app/Models/Proposal.php @@ -16,7 +16,6 @@ use Illuminate\Database\Eloquent\Model; class Proposal extends Model { use Reportable; - use NotificationContext; /** Authoring user */ public function author() diff --git a/app/Models/Table.php b/app/Models/Table.php index 9d14e38..aa44cd8 100644 --- a/app/Models/Table.php +++ b/app/Models/Table.php @@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model; class Table extends Model { use Reportable; - use NotificationContext; protected static function boot() { diff --git a/app/Models/TableComment.php b/app/Models/TableComment.php index e5c3d16..19bcfbb 100644 --- a/app/Models/TableComment.php +++ b/app/Models/TableComment.php @@ -12,7 +12,6 @@ use Illuminate\Database\Eloquent\Model; class TableComment extends Model { use Reportable; - use NotificationContext; /** Context data table */ public function table() diff --git a/app/Models/User.php b/app/Models/User.php index bf1d838..bab1ae6 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,16 +4,29 @@ namespace App\Models; use AdamWathan\EloquentOAuth\OAuthIdentity; use App\Models\Concerns\Reportable; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; /** * A user in the application * + * @property Carbon $created_at + * @property Carbon $updated_at + * @property string $name - unique, for vanity URL + * @property string $email - unique, for login and social auth chaining + * @property string $password - hashed pw * @property Proposal[]|Collection $proposals + * @property Table[]|Collection $tables + * @property OAuthIdentity[]|Collection $socialIdentities + * @property TableComment[]|Collection $tableComments + * @property Table[]|Collection $favouriteTables + * @property Table[]|Collection $followedDiscussions + * @property ContentReport[]|Collection $authoredReports + * @property Notification[]|Collection $notifications + * @property Notification[]|Collection $readNotifications + * @property Notification[]|Collection $unreadNotifications */ class User extends Authenticatable { @@ -47,13 +60,11 @@ class User extends Authenticatable foreach ($self->proposals as $proposal) { $proposal->delete(); } - - $self->notificationsCaused()->delete(); }); } /** Owned tables */ - public function dataTables() + public function tables() { return $this->hasMany(Table::class, 'owner_id'); } @@ -94,22 +105,6 @@ class User extends Authenticatable return $this->hasMany(ContentReport::class, 'author_id'); } - /** Notifications for this user */ - public function notifications() - { - return $this->hasMany(Notification::class); - } - - /** - * Notifications caused by this user - * - * @return HasMany - */ - public function notificationsCaused() - { - return $this->hasMany(Notification::class, 'actor_id'); - } - // --------- Relation Helpers --------- public function addFavourite(Table $table) diff --git a/composer.json b/composer.json index 9da249e..1a53884 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ "laravel/framework": "5.6.*", "laravel/socialite": "^3.0", "laravel/tinker": "^1.0", + "mightypork/php-sandbox": "^1.0", "phpoffice/phpspreadsheet": "^1.3", "riesjart/relaquent": "^0.1" }, diff --git a/composer.lock b/composer.lock index bba5768..b147615 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7c2b00ef303415cdc522f82578d90676", + "content-hash": "60a096ac38f47f94abc0e1c82f548194", "packages": [ { "name": "barryvdh/laravel-ide-helper", @@ -161,74 +161,6 @@ "description": "implementation of xdg base directory specification for php", "time": "2014-10-24T07:27:01+00:00" }, - { - "name": "doctrine/annotations", - "version": "v1.6.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", - "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", - "reference": "c7f2050c68a9ab0bdb0f98567ec08d80ea7d24d5", - "shasum": "" - }, - "require": { - "doctrine/lexer": "1.*", - "php": "^7.1" - }, - "require-dev": { - "doctrine/cache": "1.*", - "phpunit/phpunit": "^6.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Docblock Annotations Parser", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "docblock", - "parser" - ], - "time": "2017-12-06T07:11:42+00:00" - }, { "name": "doctrine/cache", "version": "v1.7.1", @@ -304,35 +236,50 @@ "time": "2017-08-25T07:02:50+00:00" }, { - "name": "doctrine/collections", - "version": "v1.5.0", + "name": "doctrine/dbal", + "version": "v2.8.0", "source": { "type": "git", - "url": "https://github.com/doctrine/collections.git", - "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf" + "url": "https://github.com/doctrine/dbal.git", + "reference": "5140a64c08b4b607b9bedaae0cedd26f04a0e621" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/collections/zipball/a01ee38fcd999f34d9bfbcee59dbda5105449cbf", - "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/5140a64c08b4b607b9bedaae0cedd26f04a0e621", + "reference": "5140a64c08b4b607b9bedaae0cedd26f04a0e621", "shasum": "" }, "require": { + "doctrine/cache": "^1.0", + "doctrine/event-manager": "^1.0", + "ext-pdo": "*", "php": "^7.1" }, "require-dev": { - "doctrine/coding-standard": "~0.1@dev", - "phpunit/phpunit": "^5.7" + "doctrine/coding-standard": "^4.0", + "jetbrains/phpstorm-stubs": "^2018.1.2", + "phpstan/phpstan": "^0.10.1", + "phpunit/phpunit": "^7.1.2", + "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", + "symfony/console": "^2.0.5|^3.0|^4.0", + "symfony/phpunit-bridge": "^3.4.5|^4.0.5" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." }, + "bin": [ + "bin/doctrine-dbal" + ], "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.8.x-dev", + "dev-develop": "3.0.x-dev" } }, "autoload": { "psr-0": { - "Doctrine\\Common\\Collections\\": "lib/" + "Doctrine\\DBAL\\": "lib/" } }, "notification-url": "https://packagist.org/downloads/", @@ -355,50 +302,46 @@ { "name": "Jonathan Wage", "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" } ], - "description": "Collections Abstraction library", + "description": "Database Abstraction Layer", "homepage": "http://www.doctrine-project.org", "keywords": [ - "array", - "collections", - "iterator" + "database", + "dbal", + "persistence", + "queryobject" ], - "time": "2017-07-22T10:37:32+00:00" + "time": "2018-07-13T03:16:35+00:00" }, { - "name": "doctrine/common", - "version": "v2.8.1", + "name": "doctrine/event-manager", + "version": "v1.0.0", "source": { "type": "git", - "url": "https://github.com/doctrine/common.git", - "reference": "f68c297ce6455e8fd794aa8ffaf9fa458f6ade66" + "url": "https://github.com/doctrine/event-manager.git", + "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/common/zipball/f68c297ce6455e8fd794aa8ffaf9fa458f6ade66", - "reference": "f68c297ce6455e8fd794aa8ffaf9fa458f6ade66", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/a520bc093a0170feeb6b14e9d83f3a14452e64b3", + "reference": "a520bc093a0170feeb6b14e9d83f3a14452e64b3", "shasum": "" }, "require": { - "doctrine/annotations": "1.*", - "doctrine/cache": "1.*", - "doctrine/collections": "1.*", - "doctrine/inflector": "1.*", - "doctrine/lexer": "1.*", - "php": "~7.1" + "php": "^7.1" + }, + "conflict": { + "doctrine/common": "<2.9@dev" }, "require-dev": { - "phpunit/phpunit": "^5.7" + "doctrine/coding-standard": "^4.0", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { @@ -430,93 +373,20 @@ { "name": "Johannes Schmitt", "email": "schmittjoh@gmail.com" - } - ], - "description": "Common Library for Doctrine projects", - "homepage": "http://www.doctrine-project.org", - "keywords": [ - "annotations", - "collections", - "eventmanager", - "persistence", - "spl" - ], - "time": "2017-08-31T08:43:38+00:00" - }, - { - "name": "doctrine/dbal", - "version": "v2.7.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/dbal.git", - "reference": "11037b4352c008373561dc6fc836834eed80c3b5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/11037b4352c008373561dc6fc836834eed80c3b5", - "reference": "11037b4352c008373561dc6fc836834eed80c3b5", - "shasum": "" - }, - "require": { - "doctrine/common": "^2.7.1", - "ext-pdo": "*", - "php": "^7.1" - }, - "require-dev": { - "doctrine/coding-standard": "^4.0", - "phpunit/phpunit": "^7.0", - "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", - "symfony/console": "^2.0.5||^3.0", - "symfony/phpunit-bridge": "^3.4.5|^4.0.5" - }, - "suggest": { - "symfony/console": "For helpful console commands such as SQL execution and import of files." - }, - "bin": [ - "bin/doctrine-dbal" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\DBAL\\": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" }, { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" } ], - "description": "Database Abstraction Layer", - "homepage": "http://www.doctrine-project.org", + "description": "Doctrine Event Manager component", + "homepage": "https://www.doctrine-project.org/projects/event-manager.html", "keywords": [ - "database", - "dbal", - "persistence", - "queryobject" + "event", + "eventdispatcher", + "eventmanager" ], - "time": "2018-04-07T18:44:18+00:00" + "time": "2018-06-11T11:59:03+00:00" }, { "name": "doctrine/inflector", @@ -1524,6 +1394,37 @@ ], "time": "2016-08-17T00:36:58+00:00" }, + { + "name": "mightypork/php-sandbox", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://git.ondrovo.com/packages/php-sandbox.git", + "reference": "2d0cab061148cfd8b53e38e2b9043a56270c520b" + }, + "require": { + "laravel/framework": "~5.5", + "php": ">=5.6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "MightyPork\\PhpSandbox\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Ondřej Hruška", + "email": "ondra@ondrovo.com" + } + ], + "description": "Web interface for testing PHP code (Laravel package)", + "time": "2018-07-14T15:20:40+00:00" + }, { "name": "monolog/monolog", "version": "1.23.0", @@ -2246,16 +2147,16 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v6.1.1", + "version": "v6.1.2", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "aa899fef280b1c1aec8d5d4ac069af7f80c89a23" + "reference": "7d760881d266d63c5e7a1155cbcf2ac656a31ca8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/aa899fef280b1c1aec8d5d4ac069af7f80c89a23", - "reference": "aa899fef280b1c1aec8d5d4ac069af7f80c89a23", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/7d760881d266d63c5e7a1155cbcf2ac656a31ca8", + "reference": "7d760881d266d63c5e7a1155cbcf2ac656a31ca8", "shasum": "" }, "require": { @@ -2301,7 +2202,7 @@ "mail", "mailer" ], - "time": "2018-07-04T11:12:44+00:00" + "time": "2018-07-13T07:04:35+00:00" }, { "name": "symfony/class-loader", @@ -3444,16 +3345,16 @@ }, { "name": "fzaninotto/faker", - "version": "v1.7.1", + "version": "v1.8.0", "source": { "type": "git", "url": "https://github.com/fzaninotto/Faker.git", - "reference": "d3ed4cc37051c1ca52d22d76b437d14809fc7e0d" + "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/d3ed4cc37051c1ca52d22d76b437d14809fc7e0d", - "reference": "d3ed4cc37051c1ca52d22d76b437d14809fc7e0d", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/f72816b43e74063c8b10357394b6bba8cb1c10de", + "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de", "shasum": "" }, "require": { @@ -3461,7 +3362,7 @@ }, "require-dev": { "ext-intl": "*", - "phpunit/phpunit": "^4.0 || ^5.0", + "phpunit/phpunit": "^4.8.35 || ^5.7", "squizlabs/php_codesniffer": "^1.5" }, "type": "library", @@ -3490,7 +3391,7 @@ "faker", "fixtures" ], - "time": "2017-08-15T16:48:10+00:00" + "time": "2018-07-12T10:23:15+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -4414,16 +4315,16 @@ }, { "name": "sebastian/comparator", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "591a30922f54656695e59b1f39501aec513403da" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/591a30922f54656695e59b1f39501aec513403da", - "reference": "591a30922f54656695e59b1f39501aec513403da", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { @@ -4474,7 +4375,7 @@ "compare", "equality" ], - "time": "2018-06-14T15:05:28+00:00" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", diff --git a/config/app.php b/config/app.php index ed47faa..c517402 100644 --- a/config/app.php +++ b/config/app.php @@ -165,6 +165,7 @@ return [ // sideload AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider::class, + MightyPork\PhpSandbox\PhpSandboxServiceProvider::class, ], /* diff --git a/config/php-sandbox.php b/config/php-sandbox.php index b8943d1..defb02c 100644 --- a/config/php-sandbox.php +++ b/config/php-sandbox.php @@ -2,4 +2,19 @@ return [ 'enable' => env('ENABLE_PHP_SANDBOX', false), + + 'route' => 'sandbox', + + 'route_middleware' => ['web'], + + 'default_code' => <<increments('id'); - $table->timestamps(); - $table->boolean('seen'); - $table->unsignedInteger('user_id')->index(); - $table->unsignedInteger('actor_id')->index()->nullable(); // who did it - $table->string('action'); // what happened, e.g.: favourited, mentioned, forked, commented - $table->nullableMorphs('context'); // the action target or context - - $table->foreign('actor_id')->references('id')->on('users') - ->onDelete('cascade'); - - $table->foreign('user_id')->references('id')->on('users') - ->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists('notifications'); - } -} diff --git a/database/migrations/2018_07_14_133644_create_notifications_table.php b/database/migrations/2018_07_14_133644_create_notifications_table.php new file mode 100644 index 0000000..fb16d5b --- /dev/null +++ b/database/migrations/2018_07_14_133644_create_notifications_table.php @@ -0,0 +1,35 @@ +uuid('id')->primary(); + $table->string('type'); + $table->morphs('notifiable'); + $table->text('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/public/sandbox-assets/ace/ace.js b/public/vendor/php-sandbox/ace/ace.js similarity index 100% rename from public/sandbox-assets/ace/ace.js rename to public/vendor/php-sandbox/ace/ace.js diff --git a/public/sandbox-assets/ace/ext-language_tools.js b/public/vendor/php-sandbox/ace/ext-language_tools.js similarity index 100% rename from public/sandbox-assets/ace/ext-language_tools.js rename to public/vendor/php-sandbox/ace/ext-language_tools.js diff --git a/public/sandbox-assets/ace/mode-php.js b/public/vendor/php-sandbox/ace/mode-php.js similarity index 100% rename from public/sandbox-assets/ace/mode-php.js rename to public/vendor/php-sandbox/ace/mode-php.js diff --git a/public/sandbox-assets/ace/theme-monokai.js b/public/vendor/php-sandbox/ace/theme-monokai.js similarity index 100% rename from public/sandbox-assets/ace/theme-monokai.js rename to public/vendor/php-sandbox/ace/theme-monokai.js diff --git a/public/sandbox-assets/ace/worker-php.js b/public/vendor/php-sandbox/ace/worker-php.js similarity index 100% rename from public/sandbox-assets/ace/worker-php.js rename to public/vendor/php-sandbox/ace/worker-php.js diff --git a/public/sandbox-assets/jquery-1.9.1.min.js b/public/vendor/php-sandbox/jquery-1.9.1.min.js similarity index 100% rename from public/sandbox-assets/jquery-1.9.1.min.js rename to public/vendor/php-sandbox/jquery-1.9.1.min.js diff --git a/public/sandbox-assets/moment.min.js b/public/vendor/php-sandbox/moment.min.js similarity index 100% rename from public/sandbox-assets/moment.min.js rename to public/vendor/php-sandbox/moment.min.js diff --git a/public/sandbox-assets/php-console.js b/public/vendor/php-sandbox/php-console.js similarity index 100% rename from public/sandbox-assets/php-console.js rename to public/vendor/php-sandbox/php-console.js diff --git a/public/sandbox-assets/styles.css b/public/vendor/php-sandbox/styles.css similarity index 100% rename from public/sandbox-assets/styles.css rename to public/vendor/php-sandbox/styles.css diff --git a/resources/views/debug/sandbox.blade.php b/resources/views/debug/sandbox.blade.php deleted file mode 100644 index c9a64ad..0000000 --- a/resources/views/debug/sandbox.blade.php +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - PHP debug sandbox - - - - - - - - - - - - - - -
-
-
-
- -
-
-   - new - ren - del -  |  - Line: 1, Column: 1 - - -
-
-
-
-
{{ $output or '' }}
-
-
- - diff --git a/routes/web.php b/routes/web.php index fdf09f4..1a41dff 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,13 +16,6 @@ use SocialNorm\ProviderUser; Auth::routes(); -// sandbox -if (config('php-sandbox.enable')) { - Route::get('sandbox', 'SandboxController@index')->name('sandbox'); - Route::post('sandbox', 'SandboxController@run'); // ajax -} - - Route::get('/about/terms', function () { return view('terms'); });