diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eaf25b..751676f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 2.0.0 - 2022-07-22 + +- Craft CMS 4 ready + ## 1.2.3 - 2021-09-16 - Consistent plugin naming in all files diff --git a/composer.json b/composer.json index 3631fda..a084a4f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "homm/hommsocialfeed", "description": "Craft CMS Social Feed Adapter for juicer.io", "type": "craft-plugin", - "version": "1.2.3", + "version": "2.0.0", "keywords": [ "craft", "cms", @@ -24,8 +24,10 @@ } ], "require": { - "craftcms/cms": "^3.0.0", - "ext-json": "*" + "php": "^8.0|^8.1", + "craftcms/cms": "^4.0.0", + "ext-json": "*", + "ext-fileinfo": "*" }, "autoload": { "psr-4": { diff --git a/src/HOMMSocialFeed.php b/src/HOMMSocialFeed.php index e16f173..12a5eaf 100644 --- a/src/HOMMSocialFeed.php +++ b/src/HOMMSocialFeed.php @@ -49,17 +49,17 @@ class HOMMSocialFeed extends Plugin /** * @var string */ - public $schemaVersion = '1.2.0'; + public string $schemaVersion = '1.2.0'; /** * @var bool */ - public $hasCpSettings = true; + public bool $hasCpSettings = true; /** * @var bool */ - public $hasCpSection = true; + public bool $hasCpSection = true; // Public Methods // ========================================================================= @@ -124,7 +124,7 @@ function (Event $event) { /** * @inheritdoc */ - protected function createSettingsModel() + protected function createSettingsModel(): ?\craft\base\Model { return new Settings(); } @@ -132,7 +132,7 @@ protected function createSettingsModel() /** * @inheritdoc */ - protected function settingsHtml(): string + protected function settingsHtml(): ?string { return Craft::$app->view->renderTemplate( 'hommsocialfeed/settings', diff --git a/src/elements/SocialFeed.php b/src/elements/SocialFeed.php index f43e8fc..b4474d3 100644 --- a/src/elements/SocialFeed.php +++ b/src/elements/SocialFeed.php @@ -12,8 +12,10 @@ use Craft; use craft\base\Element; +use craft\elements\actions\Edit; use craft\elements\actions\SetStatus; use craft\elements\db\ElementQueryInterface; +use craft\elements\User; use craft\validators\StringValidator; use craft\web\View; use GuzzleHttp\Client as GuzzleClient; @@ -36,7 +38,7 @@ class SocialFeed extends Element /** * @var int Social Feed ID */ - public $feedId; + public int $feedId; /** * @var \DateTime Social Feed Date Created @@ -46,17 +48,17 @@ class SocialFeed extends Element /** * @var string The URL to the feed */ - public $feedUrl; + public string $feedUrl; /** * @var string|null External URL provided from the feed */ - public $externalUrl = null; + public ?string $externalUrl = null; /** * @var string|null Name of the social media provider */ - public $source = null; + public ?string $source = null; /** * @var string|null Source options @@ -65,47 +67,42 @@ class SocialFeed extends Element * of response you get back they will be included here. * E.g. "retweets". */ - public $sourceOptions = null; + public ?string $sourceOptions = null; /** * @var string Feed text or title (as HTML) */ - public $message; + public string $message; /** - * @var string Like Count + * @var int Like Count */ - public $likeCount = 0; + public int $likeCount = 0; /** * @var string|null Image URL */ - public $image = null; + public ?string $image = null; /** * @var array|null Additional photos URL */ - public $additionalPhotos = null; + public ?array $additionalPhotos = null; /** * @var string|null Video URL */ - public $video = null; + public ?string $video = null; /** * @var bool Hide the image or not */ - public $isMediaHidden = false; + public bool $isMediaHidden = false; /** * @var string|null Color handle */ - public $color = null; - - /** - * @var int|null Pseudo property to count feeds by source - */ - public $socialfeedsCount = null; + public ?string $color = null; /** * @inheritdoc @@ -126,7 +123,7 @@ public static function pluralDisplayName(): string /** * @inheritdoc */ - public static function refHandle() + public static function refHandle(): ?string { return 'socialfeed'; } @@ -139,6 +136,26 @@ public static function hasStatuses(): bool return true; } + /** + * @inheritdoc + */ + public function canView(User $user): bool + { + return false; + } + + /** + * @inheritdoc + */ + public function canSave(User $user): bool + { + if (parent::canSave($user)) { + return true; + } + + return $user->can('hommsocialfeed-saveSocialFeed:' . $this->uid); + } + /** * @inheritdoc */ @@ -183,7 +200,7 @@ protected static function defineSources(string $context = null): array $sources[] = [ 'key' => '*', 'label' => Craft::t('hommsocialfeed', 'All feeds'), - 'badgeCount' => self::find()->anyStatus()->count(), + 'badgeCount' => self::find()->status(null)->count(), 'defaultSort' => ['feedDateCreated', 'desc'], 'criteria' => [], ]; @@ -245,13 +262,11 @@ protected static function defineSearchableAttributes(): array */ protected static function defineActions(string $source = null): array { - $actions = []; - - $actions[] = SetStatus::class; - $actions[] = SetColor::class; - $actions[] = HideMedia::class; - - return $actions; + return [ + SetStatus::class, + SetColor::class, + HideMedia::class, + ]; } /** @@ -310,7 +325,7 @@ public function beforeSave(bool $isNew): bool /** * @inheritdoc */ - public function afterSave(bool $isNew) + public function afterSave(bool $isNew): void { $attributes = [ 'feedId' => $this->feedId, diff --git a/src/elements/actions/HideMedia.php b/src/elements/actions/HideMedia.php index 828f71b..3309244 100644 --- a/src/elements/actions/HideMedia.php +++ b/src/elements/actions/HideMedia.php @@ -31,7 +31,7 @@ class HideMedia extends ElementAction /** * @inheritdoc */ - public function getTriggerHtml() + public function getTriggerHtml(): ?string { \Craft::$app->view->setTemplateMode(\craft\web\View::TEMPLATE_MODE_CP); return \Craft::$app->view->renderTemplate('hommsocialfeed/feeds/_hideMediaTrigger'); @@ -53,7 +53,7 @@ public function performAction(ElementQueryInterface $query): bool } } - $this->setMessage(Craft::t('hommsocialfeed', 'Successfully updated.')); + $this->setMessage(\Craft::t('hommsocialfeed', 'Successfully updated.')); return true; } } diff --git a/src/elements/actions/SetColor.php b/src/elements/actions/SetColor.php index 3428086..616d63f 100644 --- a/src/elements/actions/SetColor.php +++ b/src/elements/actions/SetColor.php @@ -31,7 +31,7 @@ class SetColor extends ElementAction /** * @inheritdoc */ - public function getTriggerHtml() + public function getTriggerHtml(): ?string { // Render the trigger menu template with all the available ingredients $colors = HOMMSocialFeed::$plugin->getSettings()->colors; @@ -56,7 +56,7 @@ public function performAction(ElementQueryInterface $query): bool } } - $this->setMessage(Craft::t('hommsocialfeed', 'Successfully updated.')); + $this->setMessage(\Craft::t('hommsocialfeed', 'Successfully updated.')); return true; } } diff --git a/src/models/Settings.php b/src/models/Settings.php index 7ff3ab4..68cdea3 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -55,7 +55,7 @@ class Settings extends Model /** * @inheritdoc */ - public function rules() + public function rules(): array { return [ [['apiPath', 'numberOfFeeds'], 'required'], diff --git a/src/services/SocialFeedService.php b/src/services/SocialFeedService.php index 28c6ee0..93926da 100644 --- a/src/services/SocialFeedService.php +++ b/src/services/SocialFeedService.php @@ -59,12 +59,12 @@ public function fetch() $posts = json_decode($response->getBody())->posts->items; // TODO: extend the Guzzle ResponseInterface $errors = []; - $socialFeeds = SocialFeed::find()->anyStatus()->where(['feedId' => array_column($posts, 'id')])->all(); + $socialFeeds = SocialFeed::find()->status(null)->where(['feedId' => array_column($posts, 'id')])->all(); $feedIds = array_column($socialFeeds, 'feedId'); foreach ($posts as $post) { $socialFeed = new SocialFeed(); if (in_array($post->id, $feedIds)) { - $socialFeed = SocialFeed::find()->anyStatus()->where(['feedId' => $post->id])->one(); + $socialFeed = SocialFeed::find()->status(null)->where(['feedId' => $post->id])->one(); } $attributes = [