From 638b9a9a055f32c17f1546968f134de854f7f2c2 Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Wed, 9 Sep 2020 11:00:39 +0200 Subject: [PATCH] social articles for subscribers only --- .idea/lettre-pharma.iml | 2 + .idea/php.xml | 4 +- app/Models/HasSubscriberOnlyContent.php | 40 ++++++ app/Models/SocialArticle.php | 16 ++- app/User.php | 2 +- composer.json | 8 +- composer.lock | 124 +++++++++++++++++- ...add_chapo_col_to_social_articles_table.php | 32 +++++ ...iber_only_col_to_social_articles_table.php | 32 +++++ public/admin/css/admin.css | 4 + public/admin/js/admin.js | 7 + public/css/app.css | 26 +++- public/js/app.js | 10 +- resources/js/app.js | 1 + .../components/Publish/Step2PrepareMail.vue | 13 ++ resources/sass/_articles.scss | 5 + resources/sass/app.scss | 11 +- .../views/admin/socialArticles/form.blade.php | 20 +++ .../views/social-articles/show.blade.php | 15 ++- 19 files changed, 350 insertions(+), 22 deletions(-) create mode 100644 app/Models/HasSubscriberOnlyContent.php create mode 100644 database/migrations/2020_09_09_080543_add_chapo_col_to_social_articles_table.php create mode 100644 database/migrations/2020_09_09_081624_add_subscriber_only_col_to_social_articles_table.php diff --git a/.idea/lettre-pharma.iml b/.idea/lettre-pharma.iml index d6fc662..a117e04 100644 --- a/.idea/lettre-pharma.iml +++ b/.idea/lettre-pharma.iml @@ -20,6 +20,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index b93a019..fdcbde4 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -206,12 +206,14 @@ + + - + diff --git a/app/Models/HasSubscriberOnlyContent.php b/app/Models/HasSubscriberOnlyContent.php new file mode 100644 index 0000000..bb8e135 --- /dev/null +++ b/app/Models/HasSubscriberOnlyContent.php @@ -0,0 +1,40 @@ +content, 100); + } + + /** + * @param User|null $user + * @return bool + */ + public function isVisibleByUser(User $user = null) + { + $user ??= \Auth::user(); + + return !$this->subscriber_only || + ($user !== null && $user->hasValidSubscription()); + + } + +} diff --git a/app/Models/SocialArticle.php b/app/Models/SocialArticle.php index 87cd679..56c66c4 100644 --- a/app/Models/SocialArticle.php +++ b/app/Models/SocialArticle.php @@ -12,14 +12,24 @@ use A17\Twill\Models\Behaviors\HasPosition; use A17\Twill\Models\Behaviors\Sortable; use A17\Twill\Models\Model; +/** + * Class SocialArticle + * @package App\Models + * @property string $content + * @property string $title + * @property string $chapo + * @property int $count + */ class SocialArticle extends Model { - use HasSlug, HasMedias; + use HasSlug, HasMedias, HasSubscriberOnlyContent; protected $fillable = [ 'published', 'content', + 'chapo', 'title', + 'subscriber_only' ]; @@ -27,6 +37,10 @@ class SocialArticle extends Model 'title', ]; + public $casts = [ + 'subscriber_only' => 'bool' + ]; + /** * Increments view count diff --git a/app/User.php b/app/User.php index 06c48a5..6a5bbb9 100644 --- a/app/User.php +++ b/app/User.php @@ -212,7 +212,7 @@ class User extends Authenticatable implements MustVerifyEmail */ public function hasValidSubscription(): bool { - return $this->orgIsSubscribed(); + return $this->orgIsSubscribed() || $this->subscribed(); } /** diff --git a/composer.json b/composer.json index fd5b405..a9a07e0 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^6.3", "itsgoingd/clockwork": "^4.1", + "judev/php-htmltruncator": "^1.2", "kriswallsmith/buzz": "^1.1", "kub-at/php-simple-html-dom-parser": "^1.9", "laravel/cashier": "^11.2", @@ -33,13 +34,14 @@ "league/glide-laravel": "^1.0", "league/html-to-markdown": "^4.9", "mailgun/mailgun-php": "^3.0", + "masterminds/html5": "^2.7", "nyholm/psr7": "^1.2", + "psq/psq-theme": "*", "pusher/pusher-php-server": "~4.0", "sentry/sentry-laravel": "1.7.1", "spatie/pdf-to-image": "^2.0", "spatie/pdf-to-text": "^1.3", - "vaites/php-apache-tika": "^0.9.1", - "psq/psq-theme": "*" + "vaites/php-apache-tika": "^0.9.1" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.2", @@ -98,4 +100,4 @@ "@php artisan key:generate --ansi" ] } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 1ee388a..a9fbdb3 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": "8acd1f5a7163e1ac73fdd7ea056333ab", + "content-hash": "247a233609ac91be13638bd635f24b12", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -666,12 +666,12 @@ "version": "6.1.4", "source": { "type": "git", - "url": "https://github.com/caouecs/Laravel-lang.git", + "url": "https://github.com/caouecs/lang.git", "reference": "18a7845e813e737a56a7f164301d5014b536950c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/caouecs/Laravel-lang/zipball/18a7845e813e737a56a7f164301d5014b536950c", + "url": "https://api.github.com/repos/caouecs/lang/zipball/18a7845e813e737a56a7f164301d5014b536950c", "reference": "18a7845e813e737a56a7f164301d5014b536950c", "shasum": "" }, @@ -701,6 +701,7 @@ "laravel", "lpm" ], + "abandoned": "https://github.com/Laravel-Lang/lang", "time": "2020-07-13T14:35:32+00:00" }, { @@ -2339,6 +2340,56 @@ ], "time": "2020-06-23T06:23:06+00:00" }, + { + "name": "judev/php-htmltruncator", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/judev/php-htmltruncator.git", + "reference": "92121c36dc0fc44f3b6932344fae1d7a0abb0b76" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/judev/php-htmltruncator/zipball/92121c36dc0fc44f3b6932344fae1d7a0abb0b76", + "reference": "92121c36dc0fc44f3b6932344fae1d7a0abb0b76", + "shasum": "" + }, + "require": { + "masterminds/html5": "^2.0", + "php": ">=5.6.0" + }, + "require-dev": { + "phpunit/phpunit": "4.4.*" + }, + "suggest": { + "ext-intl": "*", + "ext-mbstring": "*" + }, + "type": "library", + "autoload": { + "psr-0": { + "HtmlTruncator": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jude Venn", + "homepage": "https://github.com/judev", + "role": "Developer" + } + ], + "description": "HTML Truncation library, ported from the html_truncator rubygem", + "homepage": "https://github.com/judev/php-htmltruncator", + "keywords": [ + "html", + "php" + ], + "time": "2019-11-19T10:31:52+00:00" + }, { "name": "kriswallsmith/buzz", "version": "1.1.0", @@ -3982,6 +4033,73 @@ ], "time": "2020-08-28T19:41:55+00:00" }, + { + "name": "masterminds/html5", + "version": "2.7.3", + "source": { + "type": "git", + "url": "https://github.com/Masterminds/html5-php.git", + "reference": "aad73dbfefd71d46072138109ce1288d96c329cc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/aad73dbfefd71d46072138109ce1288d96c329cc", + "reference": "aad73dbfefd71d46072138109ce1288d96c329cc", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-dom": "*", + "ext-libxml": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35", + "sami/sami": "~2.0", + "satooshi/php-coveralls": "1.0.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Masterminds\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Butcher", + "email": "technosophos@gmail.com" + }, + { + "name": "Matt Farina", + "email": "matt@mattfarina.com" + }, + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" + } + ], + "description": "An HTML5 parser and serializer.", + "homepage": "http://masterminds.github.io/html5-php", + "keywords": [ + "HTML5", + "dom", + "html", + "parser", + "querypath", + "serializer", + "xml" + ], + "time": "2020-07-05T07:53:37+00:00" + }, { "name": "matthewbdaly/laravel-azure-storage", "version": "1.3.8", diff --git a/database/migrations/2020_09_09_080543_add_chapo_col_to_social_articles_table.php b/database/migrations/2020_09_09_080543_add_chapo_col_to_social_articles_table.php new file mode 100644 index 0000000..c2215a3 --- /dev/null +++ b/database/migrations/2020_09_09_080543_add_chapo_col_to_social_articles_table.php @@ -0,0 +1,32 @@ +text('chapo')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('social_articles', function (Blueprint $table) { + $table->dropColumn('chapo'); + }); + } +} diff --git a/database/migrations/2020_09_09_081624_add_subscriber_only_col_to_social_articles_table.php b/database/migrations/2020_09_09_081624_add_subscriber_only_col_to_social_articles_table.php new file mode 100644 index 0000000..83d2b6c --- /dev/null +++ b/database/migrations/2020_09_09_081624_add_subscriber_only_col_to_social_articles_table.php @@ -0,0 +1,32 @@ +boolean('subscriber_only')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('social_articles', function (Blueprint $table) { + $table->dropColumn('subscriber_only'); + }); + } +} diff --git a/public/admin/css/admin.css b/public/admin/css/admin.css index a148c66..66e07b3 100644 --- a/public/admin/css/admin.css +++ b/public/admin/css/admin.css @@ -22,6 +22,10 @@ font-size: 17px; line-height: 1.6; } +.ck-content-custom .chapo, .ck-content .chapo, .ck-editor .chapo { + text-transform: uppercase; + font-size: large; +} @font-face { font-family: "Avenir Next"; diff --git a/public/admin/js/admin.js b/public/admin/js/admin.js index 9ddc556..8095af2 100644 --- a/public/admin/js/admin.js +++ b/public/admin/js/admin.js @@ -3387,6 +3387,13 @@ __webpack_require__.r(__webpack_exports__); editorConfig: {} }; }, + computed: { + headlines: function headlines() { + this.$root.publishState.file.headlines.reduce(function (result, headline) { + return "\n

".concat(headline.headline, "

\n

").concat(headline.content, "

\n\n "); + }, "

A la une aujourd'hui

"); + } + }, watch: { email: { deep: true, diff --git a/public/css/app.css b/public/css/app.css index 130e5b3..765cc01 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -43,6 +43,14 @@ article p, line-height: 1.6; } +.ck-content-custom .chapo, +.ck-content .chapo, +article .chapo, +.ck-editor .chapo { + text-transform: uppercase; + font-size: large; +} + /*! * Bootstrap v4.4.1 (https://getbootstrap.com/) * Copyright 2011-2019 The Bootstrap Authors @@ -11600,6 +11608,14 @@ article p, line-height: 1.6; } +.ck-content-custom .chapo, +.ck-content .chapo, +article .chapo, +.ck-editor .chapo { + text-transform: uppercase; + font-size: large; +} + body { margin-bottom: 4rem; } @@ -11660,11 +11676,6 @@ div.pill-box div > a.bottom-right { font-size: small; } -.chapo { - font-style: italic; - font-size: large; -} - .simple-preview .chapo { font-size: small; } @@ -11682,6 +11693,11 @@ article p { margin-bottom: 0; } +article .truncated { + mask-image: linear-gradient(to bottom, black 75%, transparent 99%); + -webkit-mask-image: linear-gradient(to bottom, black 75%, transparent 99%); +} + article h2 { font-size: 22px; text-align: center; diff --git a/public/js/app.js b/public/js/app.js index 198ee30..b579f96 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -8582,6 +8582,13 @@ __webpack_require__.r(__webpack_exports__); editorConfig: {} }; }, + computed: { + headlines: function headlines() { + this.$root.publishState.file.headlines.reduce(function (result, headline) { + return "\n

".concat(headline.headline, "

\n

").concat(headline.content, "

\n\n "); + }, "

A la une aujourd'hui

"); + } + }, watch: { email: { deep: true, @@ -96956,7 +96963,8 @@ var app = new Vue({ publishState: { file: { title: "", - slug: "" + slug: "", + headlines: [] }, email: { subject: "", diff --git a/resources/js/app.js b/resources/js/app.js index c70b81e..a6fc641 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -49,6 +49,7 @@ const app = new Vue({ file: { title: "", slug: "", + headlines: [] }, email:{ diff --git a/resources/js/components/Publish/Step2PrepareMail.vue b/resources/js/components/Publish/Step2PrepareMail.vue index 6acedaf..db5b2fa 100644 --- a/resources/js/components/Publish/Step2PrepareMail.vue +++ b/resources/js/components/Publish/Step2PrepareMail.vue @@ -80,6 +80,19 @@ } } }, + computed: { + headlines: function() { + this.$root.publishState.file.headlines.reduce(function(result, headline) { + return ` +

${headline.headline}

+

${headline.content}

+ + `; + + }, "

A la une aujourd'hui

") + } + + }, watch: { email: { diff --git a/resources/sass/_articles.scss b/resources/sass/_articles.scss index 8c0b4bc..8814877 100644 --- a/resources/sass/_articles.scss +++ b/resources/sass/_articles.scss @@ -30,4 +30,9 @@ } + .chapo { + text-transform: uppercase; + font-size: large; + } + } diff --git a/resources/sass/app.scss b/resources/sass/app.scss index 4055b66..412f167 100644 --- a/resources/sass/app.scss +++ b/resources/sass/app.scss @@ -85,11 +85,6 @@ a { } -.chapo { - font-style: italic; - font-size: large; -} - .simple-preview{ .chapo { font-size: small; @@ -114,6 +109,11 @@ a { article { + .truncated { + mask-image: linear-gradient(to bottom, black 75%, transparent 99%); + -webkit-mask-image: linear-gradient(to bottom, black 75%, transparent 99%); + } + @extend .ck-content; h2 { font-size: 22px; @@ -142,7 +142,6 @@ article { font-size: 18px; color: #074e9c; text-transform: uppercase; - } } .error-403 { diff --git a/resources/views/admin/socialArticles/form.blade.php b/resources/views/admin/socialArticles/form.blade.php index 60a3295..fc77f12 100644 --- a/resources/views/admin/socialArticles/form.blade.php +++ b/resources/views/admin/socialArticles/form.blade.php @@ -1,6 +1,26 @@ @extends('twill::layouts.form') @section('contentFields') + @formField('wysiwyg', [ + 'name' => 'chapo', + 'label' => 'Chapô', + ]) + @formField('radios', [ + 'name' => 'subscriber_only', + 'label' => 'Article réservé aux abonnés', + 'default' => false, + 'inline' => true, + 'options' => [ + [ + 'value' => false, + 'label' => 'Non' + ], + [ + 'value' => true, + 'label' => 'Oui' + ], + ] + ]) @formField('ckeditor', [ 'name' => 'content', 'label' => 'Article complet', diff --git a/resources/views/social-articles/show.blade.php b/resources/views/social-articles/show.blade.php index 1205977..a9399a5 100644 --- a/resources/views/social-articles/show.blade.php +++ b/resources/views/social-articles/show.blade.php @@ -10,8 +10,21 @@

{{$article->title}}

+
{!! $article->chapo !!}
- {!! $article->content !!} + + @if($article->isVisibleByUser()) + {!! $article->content !!} + @else +
+ {!! $article->getTruncatedContent() !!} +
+
+ Cet article est réservé aux abonnés ! Pour y accéder merci de vous connecter, ou + cliquez ici pour découvrir nos formules d'abonnement. +
+ @endif +
-- 2.39.5