]> _ Git - psq.git/commitdiff
social articles for subscribers only
authorLouis Jeckel <louis.jeckel@outlook.cm>
Wed, 9 Sep 2020 09:00:39 +0000 (11:00 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Wed, 9 Sep 2020 09:00:39 +0000 (11:00 +0200)
19 files changed:
.idea/lettre-pharma.iml
.idea/php.xml
app/Models/HasSubscriberOnlyContent.php [new file with mode: 0644]
app/Models/SocialArticle.php
app/User.php
composer.json
composer.lock
database/migrations/2020_09_09_080543_add_chapo_col_to_social_articles_table.php [new file with mode: 0644]
database/migrations/2020_09_09_081624_add_subscriber_only_col_to_social_articles_table.php [new file with mode: 0644]
public/admin/css/admin.css
public/admin/js/admin.js
public/css/app.css
public/js/app.js
resources/js/app.js
resources/js/components/Publish/Step2PrepareMail.vue
resources/sass/_articles.scss
resources/sass/app.scss
resources/views/admin/socialArticles/form.blade.php
resources/views/social-articles/show.blade.php

index d6fc662169d7a457c92787ba74eb9fb7cf88e069..a117e04d36b5f250b457e55674724569c17454fe 100644 (file)
@@ -20,6 +20,7 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/http-interop/http-factory-guzzle" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/itsgoingd/clockwork" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/jean85/pretty-package-versions" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/judev/php-htmltruncator" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/justinrainbow/json-schema" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/kriswallsmith/buzz" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/kub-at/php-simple-html-dom-parser" />
@@ -33,6 +34,7 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/mailgun/mailgun-php" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/markbaker/complex" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/markbaker/matrix" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/masterminds/html5" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/moneyphp/money" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/nyholm/psr7" />
index b93a0190827f3cdff8428cef74bfcc0d32a404a9..fdcbde49807dd4f32f68547619adc11537dec384 100644 (file)
       <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
       <path value="$PROJECT_DIR$/vendor/league/mime-type-detection" />
       <path value="$PROJECT_DIR$/vendor/maennchen/zipstream-php" />
+      <path value="$PROJECT_DIR$/vendor/masterminds/html5" />
+      <path value="$PROJECT_DIR$/vendor/judev/php-htmltruncator" />
     </include_path>
   </component>
   <component name="PhpInterpreters">
     <interpreters>
       <interpreter id="8d15c044-128d-49a1-8834-43ff64d38bcb" name="Ubuntu" home="wsl://DATA" debugger_id="php.debugger.XDebug">
-        <remote_data DISTRIBUTION_ID="UBUNTU" INTERPRETER_PATH="/usr/bin/php" HELPERS_PATH="/opt/.phpstorm_helpers" INITIALIZED="false" VALID="true" RUN_AS_ROOT_VIA_SUDO="false" />
+        <remote_data INTERPRETER_PATH="/usr/bin/php" HELPERS_PATH="/opt/.phpstorm_helpers" INITIALIZED="false" VALID="true" RUN_AS_ROOT_VIA_SUDO="false" DISTRIBUTION_ID="UBUNTU" />
       </interpreter>
     </interpreters>
   </component>
diff --git a/app/Models/HasSubscriberOnlyContent.php b/app/Models/HasSubscriberOnlyContent.php
new file mode 100644 (file)
index 0000000..bb8e135
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+
+namespace App\Models;
+
+use App\User;
+use HtmlTruncator\InvalidHtmlException;
+use HtmlTruncator\Truncator;
+
+/**
+ * Trait HasSubscriberOnlyContent
+ * @package App\Models
+ * @property bool $subscriber_only
+ */
+trait HasSubscriberOnlyContent
+{
+
+    /**
+     * @return string
+     * @throws InvalidHtmlException
+     */
+    public function getTruncatedContent(): string
+    {
+        return Truncator::truncate($this->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());
+
+    }
+
+}
index 87cd67947053e679eecce6579669e07d65b5c174..56c66c449bdb10dd58ac4a06673993a49509d9c9 100644 (file)
@@ -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
index 06c48a5e08f20d6cd44195e6a165b95647a23afa..6a5bbb9072f6ad54e76699c8620d7c052bb36ca9 100644 (file)
@@ -212,7 +212,7 @@ class User extends Authenticatable implements MustVerifyEmail
      */
     public function hasValidSubscription(): bool
     {
-        return $this->orgIsSubscribed();
+        return $this->orgIsSubscribed() || $this->subscribed();
     }
 
     /**
index fd5b40582cc10b61e4741d342d004b9e801f0707..a9a07e0159e16366d19235a903e1330bfc43d090 100644 (file)
@@ -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",
         "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",
             "@php artisan key:generate --ansi"
         ]
     }
-}
\ No newline at end of file
+}
index 1ee388ac89b61e745665b358fb9c1e7770821496..a9fbdb35ca1e0827b43dc4c9db04f31b44b0f5c2 100644 (file)
@@ -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",
             "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": ""
             },
                 "laravel",
                 "lpm"
             ],
+            "abandoned": "https://github.com/Laravel-Lang/lang",
             "time": "2020-07-13T14:35:32+00:00"
         },
         {
             ],
             "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",
             ],
             "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 (file)
index 0000000..c2215a3
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddChapoColToSocialArticlesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('social_articles', function (Blueprint $table) {
+            $table->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 (file)
index 0000000..83d2b6c
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddSubscriberOnlyColToSocialArticlesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('social_articles', function (Blueprint $table) {
+            $table->boolean('subscriber_only')->default(0);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('social_articles', function (Blueprint $table) {
+            $table->dropColumn('subscriber_only');
+        });
+    }
+}
index a148c6683d54257030a98c58059a610587e5dcd7..66e07b3a502b6f866b949bad4e218cae029e3282 100644 (file)
   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";
index 9ddc556be86aa507be315adf6b14a0541b0a5ca5..8095af27e742f244b555562b77fa6b0600084038 100644 (file)
@@ -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                <h2>".concat(headline.headline, "</h2>\n                <p>").concat(headline.content, "</p>\n\n                ");
+      }, "<p>A la une aujourd'hui</p>");
+    }
+  },
   watch: {
     email: {
       deep: true,
index 130e5b3c73664fa58890cc67aa91726b5f79e844..765cc0174745424558fd422c3da9877c40e8853c 100644 (file)
@@ -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;
index 198ee3005b1a2ad47208f925f93aa56e6d04fb60..b579f96491385e59e19f259864e8e08700d76772 100644 (file)
@@ -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                <h2>".concat(headline.headline, "</h2>\n                <p>").concat(headline.content, "</p>\n\n                ");
+      }, "<p>A la une aujourd'hui</p>");
+    }
+  },
   watch: {
     email: {
       deep: true,
@@ -96956,7 +96963,8 @@ var app = new Vue({
     publishState: {
       file: {
         title: "",
-        slug: ""
+        slug: "",
+        headlines: []
       },
       email: {
         subject: "",
index c70b81e3a421660c9930e8fbc24683e8247ddd4e..a6fc64120f109b5b3404ecde9fba5c17b662e1ac 100644 (file)
@@ -49,6 +49,7 @@ const app = new Vue({
             file: {
                 title: "",
                 slug: "",
+                headlines: []
 
             },
             email:{
index 6acedaffbae6e8457f7034fe39bb7d76ba4996cc..db5b2fa4f77dfa5ce7d177286f95ae92834114c4 100644 (file)
                 }
             }
         },
+        computed: {
+            headlines: function() {
+                this.$root.publishState.file.headlines.reduce(function(result, headline) {
+                    return `
+                    <h2>${headline.headline}</h2>
+                    <p>${headline.content}</p>
+
+                    `;
+
+                }, "<p>A la une aujourd'hui</p>")
+            }
+
+        },
 
         watch: {
             email: {
index 8c0b4bcc648463ffca12b65f0a4ed52d009c8e34..881487795b99a483877eaaf6ae1bd81d531822e5 100644 (file)
@@ -30,4 +30,9 @@
 
     }
 
+    .chapo {
+        text-transform: uppercase;
+        font-size: large;
+    }
+
 }
index 4055b66cb0b070e6aa1e172f5fb28bfe9e84775e..412f1671c0c9ddefc076a31224099a5c64e3c9ae 100644 (file)
@@ -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 {
index 60a3295e67f22fb267a898e97bb569f16a418951..fc77f121632bc5ddfb09f22babb8272c1457c28c 100644 (file)
@@ -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',
index 1205977b409f25da726a9920b883aa838e347b51..a9399a57aa3fcf6a8532a1ba55ed3ecf9f25fcca 100644 (file)
             </div>
             <div class="col-sm-8">
                 <h2>{{$article->title}}</h2>
+                <div class="chapo">{!! $article->chapo !!}</div>
                 <div class="content ck-content">
-                    {!! $article->content !!}
+
+                    @if($article->isVisibleByUser())
+                        {!! $article->content !!}
+                    @else
+                        <div class="truncated">
+                            {!! $article->getTruncatedContent() !!}
+                        </div>
+                        <div class="alert alert-warning">
+                            Cet article est réservé aux abonnés ! Pour y accéder merci de vous connecter, ou
+                            <a href="{{route('not-registered')}}" >cliquez ici pour découvrir nos formules d'abonnement.</a>
+                        </div>
+                    @endif
+
                 </div>
 
             </div>