From abbba84999434719fe5f107ceee57381e3ef559e Mon Sep 17 00:00:00 2001 From: chescos Date: Wed, 26 Apr 2023 20:28:33 +0200 Subject: [PATCH 1/4] updated phpdoc methods of facades --- src/SEOTools/Contracts/MetaTags.php | 2 +- src/SEOTools/Contracts/OpenGraph.php | 4 ++-- src/SEOTools/Facades/JsonLd.php | 8 ++++---- src/SEOTools/Facades/JsonLdMulti.php | 6 +++--- src/SEOTools/Facades/OpenGraph.php | 2 +- src/SEOTools/Facades/SEOMeta.php | 6 +++--- src/SEOTools/Facades/SEOTools.php | 2 +- src/SEOTools/Facades/TwitterCard.php | 5 +++-- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/SEOTools/Contracts/MetaTags.php b/src/SEOTools/Contracts/MetaTags.php index 0785603..97a2856 100644 --- a/src/SEOTools/Contracts/MetaTags.php +++ b/src/SEOTools/Contracts/MetaTags.php @@ -134,7 +134,7 @@ public function removeMeta($key); * Add a custom meta tag. * * @param string|array $meta - * @param string $value + * @param string|null $value * @param string $name * * @return static diff --git a/src/SEOTools/Contracts/OpenGraph.php b/src/SEOTools/Contracts/OpenGraph.php index 1474e76..93a2025 100644 --- a/src/SEOTools/Contracts/OpenGraph.php +++ b/src/SEOTools/Contracts/OpenGraph.php @@ -259,7 +259,7 @@ public function setBook($attributes = []); /** * Add Video properties. * - * @param string $source + * @param string|null $source * @param array $attributes * * @return static @@ -269,7 +269,7 @@ public function addVideo($source = null, $attributes = []); /** * Add audio properties. * - * @param string $source + * @param string|null $source * @param array $attributes * * @return static diff --git a/src/SEOTools/Facades/JsonLd.php b/src/SEOTools/Facades/JsonLd.php index 11c1cd8..dcaf94b 100644 --- a/src/SEOTools/Facades/JsonLd.php +++ b/src/SEOTools/Facades/JsonLd.php @@ -10,15 +10,15 @@ * @see \Artesaos\SEOTools\Contracts\JsonLd * @method static string generate(bool $minify = false) * @method static bool isEmpty() - * @method static \Artesaos\SEOTools\Contracts\JsonLd addValue(string $key, array|string $value) + * @method static \Artesaos\SEOTools\Contracts\JsonLd addValue(string $key, string|array $value) * @method static \Artesaos\SEOTools\Contracts\JsonLd addValues(array $values) * @method static \Artesaos\SEOTools\Contracts\JsonLd setType(string $type) * @method static \Artesaos\SEOTools\Contracts\JsonLd setTitle(string $title) * @method static \Artesaos\SEOTools\Contracts\JsonLd setSite(string $site) * @method static \Artesaos\SEOTools\Contracts\JsonLd setDescription(string $description) - * @method static \Artesaos\SEOTools\Contracts\JsonLd setUrl(string $url) - * @method static \Artesaos\SEOTools\Contracts\JsonLd addImage(array|string $image) - * @method static \Artesaos\SEOTools\Contracts\JsonLd setImages(array $images) + * @method static \Artesaos\SEOTools\Contracts\JsonLd setUrl(string|null|bool $url) + * @method static \Artesaos\SEOTools\Contracts\JsonLd addImage(string|array $image) + * @method static \Artesaos\SEOTools\Contracts\JsonLd setImages(string|array $images) */ class JsonLd extends Facade { diff --git a/src/SEOTools/Facades/JsonLdMulti.php b/src/SEOTools/Facades/JsonLdMulti.php index ede9460..ea9ae53 100644 --- a/src/SEOTools/Facades/JsonLdMulti.php +++ b/src/SEOTools/Facades/JsonLdMulti.php @@ -12,15 +12,15 @@ * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti newJsonLd() * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti isEmpty() * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti select(int $index) - * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addValue(string $key, array|string $value) + * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addValue(string $key, string|array $value) * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addValues(array $values) * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setType(string $type) * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setTitle(string $title) * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setSite(string $site) * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setDescription(string $description) - * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setUrl(string $url) + * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setUrl(string|null|bool $url) * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti addImage(array|string $image) - * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setImages(array $images) + * @method static \Artesaos\SEOTools\Contracts\JsonLdMulti setImages(string|array $images) */ class JsonLdMulti extends Facade { diff --git a/src/SEOTools/Facades/OpenGraph.php b/src/SEOTools/Facades/OpenGraph.php index 5400983..a5c7762 100644 --- a/src/SEOTools/Facades/OpenGraph.php +++ b/src/SEOTools/Facades/OpenGraph.php @@ -10,7 +10,7 @@ * @see \Artesaos\SEOTools\Contracts\OpenGraph * * @method static string generate(bool $minify = false) - * @method static \Artesaos\SEOTools\Contracts\OpenGraph addProperty(string $key, array|string $value) + * @method static \Artesaos\SEOTools\Contracts\OpenGraph addProperty(string $key, string|array $value) * @method static \Artesaos\SEOTools\Contracts\OpenGraph removeProperty(string $key) * @method static \Artesaos\SEOTools\Contracts\OpenGraph addImage(string $url, array $attributes = []) * @method static \Artesaos\SEOTools\Contracts\OpenGraph addImages(array $urls) diff --git a/src/SEOTools/Facades/SEOMeta.php b/src/SEOTools/Facades/SEOMeta.php index 051be56..8136770 100644 --- a/src/SEOTools/Facades/SEOMeta.php +++ b/src/SEOTools/Facades/SEOMeta.php @@ -14,10 +14,10 @@ * @method static \Artesaos\SEOTools\Contracts\MetaTags setTitleDefault(string $default) * @method static \Artesaos\SEOTools\Contracts\MetaTags setTitleSeparator(string $separator) * @method static \Artesaos\SEOTools\Contracts\MetaTags setDescription(string $description) - * @method static \Artesaos\SEOTools\Contracts\MetaTags setKeywords(array|string $keywords) - * @method static \Artesaos\SEOTools\Contracts\MetaTags addKeyword(string $keyword) + * @method static \Artesaos\SEOTools\Contracts\MetaTags setKeywords(string|array $keywords) + * @method static \Artesaos\SEOTools\Contracts\MetaTags addKeyword(string|array $keyword) * @method static \Artesaos\SEOTools\Contracts\MetaTags removeMeta(string $key) - * @method static \Artesaos\SEOTools\Contracts\MetaTags addMeta(array|string $meta, string|null $value = null, string $name = 'name') + * @method static \Artesaos\SEOTools\Contracts\MetaTags addMeta(string|array $meta, string|null $value = null, string $name = 'name') * @method static \Artesaos\SEOTools\Contracts\MetaTags setCanonical(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags setPrev(string $url) * @method static \Artesaos\SEOTools\Contracts\MetaTags setNext(string $url) diff --git a/src/SEOTools/Facades/SEOTools.php b/src/SEOTools/Facades/SEOTools.php index 465b358..e453c66 100644 --- a/src/SEOTools/Facades/SEOTools.php +++ b/src/SEOTools/Facades/SEOTools.php @@ -18,7 +18,7 @@ * @method static \Artesaos\SEOTools\Contracts\SEOTools setTitle(string $title, bool $appendDefault = true) * @method static \Artesaos\SEOTools\Contracts\SEOTools setDescription(string $description) * @method static \Artesaos\SEOTools\Contracts\SEOTools setCanonical(string $url) - * @method static \Artesaos\SEOTools\Contracts\SEOTools addImages(array $urls) + * @method static \Artesaos\SEOTools\Contracts\SEOTools addImages(array|string $urls) * @method static string getTitle(bool $session = false) */ class SEOTools extends Facade diff --git a/src/SEOTools/Facades/TwitterCard.php b/src/SEOTools/Facades/TwitterCard.php index a096870..82e74d8 100644 --- a/src/SEOTools/Facades/TwitterCard.php +++ b/src/SEOTools/Facades/TwitterCard.php @@ -10,14 +10,15 @@ * @see \Artesaos\SEOTools\Contracts\TwitterCards * * @method static string generate(bool $minify = false) - * @method static \Artesaos\SEOTools\Contracts\TwitterCards addValue(string $key, array|string $value) + * @method static \Artesaos\SEOTools\Contracts\TwitterCards addValue(string $key, string|array $value) * @method static \Artesaos\SEOTools\Contracts\TwitterCards setType(string $type) * @method static \Artesaos\SEOTools\Contracts\TwitterCards setTitle(string $title) * @method static \Artesaos\SEOTools\Contracts\TwitterCards setSite(string $site) * @method static \Artesaos\SEOTools\Contracts\TwitterCards setDescription(string $description) * @method static \Artesaos\SEOTools\Contracts\TwitterCards setUrl(string $url) * @method static \Artesaos\SEOTools\Contracts\TwitterCards addImage(string|array $image) - * @method static \Artesaos\SEOTools\Contracts\TwitterCards setImages(array $images) + * @method static \Artesaos\SEOTools\Contracts\TwitterCards setImages(string|array $images) + * @method static \Artesaos\SEOTools\Contracts\TwitterCards setImage(string|array $images) */ class TwitterCard extends Facade { From 97d95f6062430dae3e5dfb160a61f548fe96415c Mon Sep 17 00:00:00 2001 From: J-Brk Date: Fri, 28 Apr 2023 15:57:28 +0200 Subject: [PATCH 2/4] Update composer.json - PHPUnit 9 --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9901b2d..b24a4a6 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ }, "require-dev": { "orchestra/testbench": "~3.8.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0", - "phpspec/phpspec": "~5.1.1 || ^6.0 || ^7.0" + "phpspec/phpspec": "~5.1.1 || ^6.0 || ^7.0", + "phpunit/phpunit": "^9.0" }, "autoload": { "psr-4": { From 40068ef5ed566643c39e55f6da14fd6e04d39619 Mon Sep 17 00:00:00 2001 From: Omar Herri Date: Tue, 9 May 2023 15:19:07 +0100 Subject: [PATCH 3/4] Add support to macro (#301) * Add support to macro * Update README.md --- README.md | 21 +++++++++++++++++++++ src/SEOTools/SEOTools.php | 3 +++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index 22d6608..890929c 100644 --- a/README.md +++ b/README.md @@ -520,6 +520,27 @@ class CommomController extends Controller ``` +#### Using Macro +Using the same code in multiple places can be tedious, which is why this package includes a Macroable trait. This trait allows additional functionality to be added to a class that was not defined in the class definition, using a simple trait. + +For example, imagine that you need to add meta titles and descriptions for your pages. You can add your Macroable functions in the AppServiceProvider or create a dedicated file for this purpose, and define your function as shown in the code snippet: +```php + SEOTools::macro('webPage', function (string $title, string $description) { + SEOMeta::setTitle($title); + SEOMeta::setDescription($description); + SEOMeta::setCanonical('http://current.url.com'); + OpenGraph::setDescription($description); + OpenGraph::setTitle($title); + OpenGraph::setUrl('http://current.url.com'); + OpenGraph::addProperty('type', 'webpage'); + }); +``` + +In your controller, you can use the following code to utilize the function: +```php + SEOTools::webPage('Page title', 'Page description'); +``` + #### API (SEOMeta) ```php diff --git a/src/SEOTools/SEOTools.php b/src/SEOTools/SEOTools.php index 27945a9..86890bf 100644 --- a/src/SEOTools/SEOTools.php +++ b/src/SEOTools/SEOTools.php @@ -3,6 +3,7 @@ namespace Artesaos\SEOTools; use Artesaos\SEOTools\Contracts\SEOTools as SEOContract; +use Illuminate\Support\Traits\Macroable; /** * SEOTools provides implementation for `SEOTools` contract. @@ -11,6 +12,8 @@ */ class SEOTools implements SEOContract { + use Macroable; + /** * {@inheritdoc} */ From 99744eaa8c3e21a2121914d8a7ca61284e5497a4 Mon Sep 17 00:00:00 2001 From: J-Brk Date: Tue, 9 May 2023 16:20:42 +0200 Subject: [PATCH 4/4] #297 Updated OpenGraph Product attributes (#299) --- src/SEOTools/OpenGraph.php | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/SEOTools/OpenGraph.php b/src/SEOTools/OpenGraph.php index dd5ac4d..99fe5af 100644 --- a/src/SEOTools/OpenGraph.php +++ b/src/SEOTools/OpenGraph.php @@ -644,6 +644,7 @@ public function setPlace($attributes = []) /** * Set product properties. + * Reference: https://developers.facebook.com/docs/marketing-api/catalog/reference/#example-feeds * * @param array $attributes opengraph product attributes * @@ -652,25 +653,57 @@ public function setPlace($attributes = []) public function setProduct($attributes = []) { $validkeys = [ + // Required + 'brand', + 'availability', + 'condition', + + // Conditionally required + 'locale', + 'plural_title', + + // Conditionally required: https://developers.facebook.com/docs/payments/product/ + 'price:amount', // Required if Static Pricing & not Dynamic Pricing + 'price:currency', // Required if Static Pricing & not Dynamic Pricing + + // Optional + 'catalog_id', + 'item_group_id', + 'category', + 'gender', + 'gtin', + 'isbn', + 'mfr_part_no', + + 'sale_price:amount', + 'sale_price:currency', + 'sale_price_dates:start', + 'sale_price_dates:end', + + + // Optional - extra + 'custom_label_0', + 'custom_label_1', + 'custom_label_2', + 'custom_label_3', + 'custom_label_4', + + + // Deprecated 'original_price:amount', 'original_price:currency', 'pretax_price:amount', 'pretax_price:currency', - 'price:amount', - 'price:currency', 'shipping_cost:amount', 'shipping_cost:currency', 'weight:value', 'weight:units', 'shipping_weight:value', 'shipping_weight:units', - 'sale_price:amount', - 'sale_price:currency', - 'sale_price_dates:start', - 'sale_price_dates:end' ]; $this->setProperties('product', 'productProperties', $attributes, $validkeys); + return $this; }