From a2984fe4f08e600c2978d639bfc20a8de8c35f7e Mon Sep 17 00:00:00 2001 From: Alix Guillard Date: Wed, 24 Nov 2021 14:38:18 +0100 Subject: [PATCH 1/5] create toggle to replicate Google description all over --- blueprints/seo.yaml | 92 +++++++++++++++++++++++++-------------------- languages/en.yaml | 3 +- languages/nl.yaml | 3 +- languages/ro.yaml | 1 + 4 files changed, 56 insertions(+), 43 deletions(-) diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 899bd0b..745c88f 100644 --- a/blueprints/seo.yaml +++ b/blueprints/seo.yaml @@ -16,7 +16,7 @@ form: fields: googlefields: type: tab - title: Google + title: Google fields: header.googletitle: type: text @@ -26,13 +26,23 @@ form: type: textarea label: PLUGIN_SEO.GOOGLE_DESC id: desc - + header.googledescall: + type: toggle + label: PLUGIN_SEO.GOOGLE_DESC_ALL + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + header.googlepreview: type: google label: PLUGIN_SEO.GOOGLE_PREVIEWDESC twitterfields: type: tab - title: Twitter + title: Twitter fields: columns: type: columns @@ -72,7 +82,7 @@ form: label: PLUGIN_SEO.TWITTER_SHAREIMG preview_images: true id: twittimgselect - + header.twittertitle: type: text label: PLUGIN_SEO.TWITTER_TITLE @@ -82,21 +92,21 @@ form: style: vertical label: PLUGIN_SEO.TWITTER_DESCRIPTION id: twitterdescription - + # .... subfields - + column2: type: column fields: header.twitterlabel: type: section text: PLUGIN_SEO.TWITTER_PREVIEWDESC - + header.twitterpreview: type: twitter # .... other subfields - + jsonfield: type: tab title: Microdata @@ -231,7 +241,7 @@ form: 'http://schema.org/SoldOut': PLUGIN_SEO.SOLDOUT 'http://schema.org/OnlineOnly': PLUGIN_SEO.ONLINEONLY field_classes: togglemusicevent - + .musicevent_offers_url: type: text label: PLUGIN_SEO.TICKET_URL @@ -248,7 +258,7 @@ form: label: PLUGIN_SEO.PRICE_CURRENCY field_classes: togglemusicevent placeholder: USD - + .musicevent_performer: type: list label: PLUGIN_SEO.ADD_PERFORMER @@ -269,7 +279,7 @@ form: type: text label: Same as placeholder: 'http://en.wikipedia.org/wiki/Artist_Page' - .musicevent_startdate: + .musicevent_startdate: type: datetime label: PLUGIN_SEO.MUSICEVENT_DATE_START field_classes: togglemusicevent @@ -357,7 +367,7 @@ form: label: Link to official website of the organization header.orga.logo: type: text - label: Url to Organization Logo + label: Url to Organization Logo placeholder: 'include http://' header.orgaratingenabled: type: toggle @@ -467,7 +477,7 @@ form: type: conditional condition: "config.plugins.seo.event ? 'true' : 'false'" fields: - + header.eventfieldset: type: fieldset title: Event Microdata @@ -498,7 +508,7 @@ form: field_classes: toggleevent .event_description: type: text - label: PLUGIN_SEO.EVENT_DESCRIPTION + label: PLUGIN_SEO.EVENT_DESCRIPTION field_classes: toggleevent .event_startDate: type: datetime @@ -541,7 +551,7 @@ form: fields: header.personfieldset: type: fieldset - title: Person Microdata + title: Person Microdata collapsed: true icon: address-card-o collapsible: true @@ -573,11 +583,11 @@ form: field_classes: toggleperson .person_address_addressLocality: type: text - label: PLUGIN_SEO.PERSON_ADDRESS_LOCALITY + label: PLUGIN_SEO.PERSON_ADDRESS_LOCALITY field_classes: toggleperson .person_address_addressRegion: type: text - label: PLUGIN_SEO.PERSON_ADDRESS_REGION + label: PLUGIN_SEO.PERSON_ADDRESS_REGION field_classes: toggleperson header.musicalbum_condition: type: conditional @@ -585,7 +595,7 @@ form: fields: header.musicalbumfieldset: type: fieldset - title: Music Album Microdata + title: Music Album Microdata icon: headphones collapsed: true collapsible: true @@ -622,9 +632,9 @@ form: field_classes: togglemusicalbum .musicalbum_url: type: text - label: PLUGIN_SEO.MUSICALBUM_URL + label: PLUGIN_SEO.MUSICALBUM_URL field_classes: togglemusicalbum - .musicalbum_genre: + .musicalbum_genre: type: text label: PLUGIN_SEO.MUSICALBUM_GENRE field_classes: togglemusicalbum @@ -633,14 +643,14 @@ form: label: PLUGIN_SEO.MUSICALBUM_TRACK_NUMBER field_classes: togglemusicalbum .musicalbum_track: - type: list + type: list field_classes: togglemusicalbum label: PLUGIN_SEO.MUSICALBUM_ADD_TRACK default: fields: .position: type: text - label: PLUGIN_SEO.MUSICALBUM_TRACK_POSITION + label: PLUGIN_SEO.MUSICALBUM_TRACK_POSITION .name: type: text label: PLUGIN_SEO.MUSICALBUM_TRACK_NAME @@ -657,7 +667,7 @@ form: header.productfieldset: type: fieldset icon: shopping-bag - title: Product Microdata + title: Product Microdata collapsed: true collapsible: true fields: @@ -670,10 +680,10 @@ form: 1: PLUGIN_ADMIN.YES 0: PLUGIN_ADMIN.NO validate: - type: bool + type: bool header.product.name: type: text - label: Name of the Product + label: Name of the Product field_classes: togglerestaurant header.product.category: type: text @@ -732,7 +742,7 @@ form: .offer_price: type: text size: small - label: Price of the product + label: Price of the product placeholder: "e.g: 19.99 (no currency symbol)" .offer_validFrom: type: datetime @@ -740,13 +750,13 @@ form: .offer_validUntil: type: datetime label: Offer is valid until (optional) - + .offer_priceCurrency: label: PLUGIN_SEO.PRICE_CURRENCY type: text placeholder: USD - - + + header.restaurant_condition: type: conditional condition: "config.plugins.seo.restaurant ? 'true' : 'false'" @@ -754,7 +764,7 @@ form: header.restaurantfieldset: type: fieldset icon: cutlery - title: Restaurant Microdata + title: Restaurant Microdata collapsed: true collapsible: true fields: @@ -767,7 +777,7 @@ form: 1: PLUGIN_ADMIN.YES 0: PLUGIN_ADMIN.NO validate: - type: bool + type: bool header.restaurant.name: type: text label: PLUGIN_SEO.RESTAURANT_NAME @@ -831,11 +841,11 @@ form: fields: .custom_json: type: textarea - label: Or paste here your own JSON-ld Microdata - placeholder: (do not include the script tags) + label: Or paste here your own JSON-ld Microdata + placeholder: (do not include the script tags) facebookfields: type: tab - title: Facebook + title: Facebook fields: columns2: type: columns @@ -843,7 +853,7 @@ form: column3: type: column fields: - + header.facebookenable: type: toggle label: PLUGIN_SEO.FACEBOOK_ENABLE @@ -855,13 +865,13 @@ form: 0: PLUGIN_ADMIN.NO validate: type: bool - + header.facebooktitle: type: text label: PLUGIN_SEO.FACEBOOK_TITLE id: facebooktitle placeholder: Will default to page title if left empty - + header.facebookdesc: type: textarea style: vertical @@ -878,7 +888,7 @@ form: id: fbimgselect label: PLUGIN_SEO.FACEBOOK_SHAREIMG # .... subfields - + column4: type: column fields: @@ -887,17 +897,17 @@ form: header.facebookpreview: type: facebook label: PLUGIN_SEO.FACEBOOK_PREVIEWDESC - + # conditional_new_entries: # type: conditional # condition: "header.facebookenable ? 'false' : 'true'" # classes: overlay bottom -# +# # fields: # field-a: # label: New Field A # type: text -# +# # field-b: # label: New Field B # type: text diff --git a/languages/en.yaml b/languages/en.yaml index 6de15ed..bf3cbd1 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -4,6 +4,7 @@ PLUGIN_SEO: PLUGIN_STATUS: "Plugin status" STATUS_HELP: "Set to false to disable this plugin completely." GOOGLE_DESC: "Override Description" + GOOGLE_DESC_ALL: "Override all descriptions with this one" GOOGLE_TITLE: "Override Title" GOOGLE_PREVIEWDESC: "Here is a preview of your page on Google results" TWITTER_ENABLE: "Activate twitter card" @@ -116,4 +117,4 @@ PLUGIN_SEO: RESTAURANT_TELEPHONE: "Telephone" ENABLE_PERSON: "Enable Person Microdata" ENABLEORGA: "Enable Organization Microdata" - MUSICEVENT_URL_PLACEHOLDER: "Url to the official page of this music event" \ No newline at end of file + MUSICEVENT_URL_PLACEHOLDER: "Url to the official page of this music event" diff --git a/languages/nl.yaml b/languages/nl.yaml index 4f5211f..abab5d5 100644 --- a/languages/nl.yaml +++ b/languages/nl.yaml @@ -4,6 +4,7 @@ PLUGIN_SEO: PLUGIN_STATUS: "Plugin status" STATUS_HELP: "Zet op false om deze plugin volledig stop te zetten." GOOGLE_DESC: "Overschrijf omschrijving" + GOOGLE_DESC_ALL: "Overschrijf ale omschrijvings met dese" GOOGLE_TITLE: "Overschrijf titel" GOOGLE_PREVIEWDESC: "Hier is een preview van jouw pagina in de google resultaten." TWITTER_ENABLE: "Activeer twitter kaart" @@ -116,4 +117,4 @@ PLUGIN_SEO: RESTAURANT_TELEPHONE: "Telefoon" ENABLE_PERSON: "Voeg persoon Microdata toe" ENABLEORGA: "Voeg Organisatie Microdata toe" - MUSICEVENT_URL_PLACEHOLDER: "Url naar de officiële pagina van het muziek event" \ No newline at end of file + MUSICEVENT_URL_PLACEHOLDER: "Url naar de officiële pagina van het muziek event" diff --git a/languages/ro.yaml b/languages/ro.yaml index 6b81217..92fafeb 100644 --- a/languages/ro.yaml +++ b/languages/ro.yaml @@ -4,6 +4,7 @@ PLUGIN_SEO: PLUGIN_STATUS: "Status modul" STATUS_HELP: "Setează ”fals” pentru a dezactiva acest modul complet." GOOGLE_DESC: "Adaugă descrierea pentru Google" + GOOGLE_DESC_ALL: "Override all descriptions with this one" GOOGLE_TITLE: "Setează titlul pentru Google" GOOGLE_PREVIEWDESC: "Acesta este previzualizarea paginii așa cum apare în rezultatele Google" TWITTER_ENABLE: "Activează cardul Twitter" From 2e987c0337a48ab8b09fc47c19b1200c33cfc42f Mon Sep 17 00:00:00 2001 From: Alix Guillard Date: Wed, 24 Nov 2021 14:57:54 +0100 Subject: [PATCH 2/5] use google description for twitter and facebook too --- languages/en.yaml | 2 +- languages/nl.yaml | 2 +- languages/ro.yaml | 2 +- seo.php | 187 +++++++++++++++++++++++----------------------- 4 files changed, 95 insertions(+), 98 deletions(-) diff --git a/languages/en.yaml b/languages/en.yaml index bf3cbd1..ed57828 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -4,7 +4,7 @@ PLUGIN_SEO: PLUGIN_STATUS: "Plugin status" STATUS_HELP: "Set to false to disable this plugin completely." GOOGLE_DESC: "Override Description" - GOOGLE_DESC_ALL: "Override all descriptions with this one" + GOOGLE_DESC_ALL: "Override all other empty descriptions with this one" GOOGLE_TITLE: "Override Title" GOOGLE_PREVIEWDESC: "Here is a preview of your page on Google results" TWITTER_ENABLE: "Activate twitter card" diff --git a/languages/nl.yaml b/languages/nl.yaml index abab5d5..9dd0cb5 100644 --- a/languages/nl.yaml +++ b/languages/nl.yaml @@ -4,7 +4,7 @@ PLUGIN_SEO: PLUGIN_STATUS: "Plugin status" STATUS_HELP: "Zet op false om deze plugin volledig stop te zetten." GOOGLE_DESC: "Overschrijf omschrijving" - GOOGLE_DESC_ALL: "Overschrijf ale omschrijvings met dese" + GOOGLE_DESC_ALL: "Overschrijf ale andere lege omschrijvings met dese" GOOGLE_TITLE: "Overschrijf titel" GOOGLE_PREVIEWDESC: "Hier is een preview van jouw pagina in de google resultaten." TWITTER_ENABLE: "Activeer twitter kaart" diff --git a/languages/ro.yaml b/languages/ro.yaml index 92fafeb..5cb0404 100644 --- a/languages/ro.yaml +++ b/languages/ro.yaml @@ -4,7 +4,7 @@ PLUGIN_SEO: PLUGIN_STATUS: "Status modul" STATUS_HELP: "Setează ”fals” pentru a dezactiva acest modul complet." GOOGLE_DESC: "Adaugă descrierea pentru Google" - GOOGLE_DESC_ALL: "Override all descriptions with this one" + GOOGLE_DESC_ALL: "Override all other empty descriptions with this one" GOOGLE_TITLE: "Setează titlul pentru Google" GOOGLE_PREVIEWDESC: "Acesta este previzualizarea paginii așa cum apare în rezultatele Google" TWITTER_ENABLE: "Activează cardul Twitter" diff --git a/seo.php b/seo.php index 75094c6..9984e50 100644 --- a/seo.php +++ b/seo.php @@ -66,7 +66,7 @@ public function array_filter_recursive( array $array, callable $callback = null $value = $this->array_filter_recursive($value); } } - + return $array; } private function seoGetimage($imageurl){ @@ -81,7 +81,7 @@ private function seoGetimage($imageurl){ $keyvalue = $keyimages[$imgkey]; //$imgkey = array_shift($imgarray); $imgobject = $imgarray[$keyvalue]; - + $im = getimagesize($imgobject->path()); $imagedata = [ 'width' => "$im[0]", @@ -110,15 +110,15 @@ private function cleanMarkdown($text){ '/(\*|\+|-)(.*)/' => '\2', // ul lists '/\n[0-9]+\.(.*)/' => '\2', // ol lists '/(>|\>)+(.*)/' => '\2', // blockquotes - - + + ); $text=str_replace(".\n", '.', $text); $text=str_replace("\n", '. ', $text); $text=str_replace('"', '', $text); $text=str_replace('', '', $text); - + foreach ($rules as $regex => $rep) { if (is_callable ( $rep)) { $text = preg_replace_callback ($regex, $rep, $text); @@ -126,12 +126,12 @@ private function cleanMarkdown($text){ $text = preg_replace ($regex, $rep, $text); } } - - + + return substr($text,0,320); // htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); } - + /** * Initialize configuration @@ -156,7 +156,7 @@ public function onPluginsInitialized() } // Register events - + $this->enable($events); } public function onPageInitialized() @@ -175,28 +175,28 @@ public function onPageInitialized() $microdata = []; $meta = $page->metadata(null); $cleanedMarkdown = $this->cleanMarkdown($page->content()); - + if (isset($page->header()->googletitle)) { $page->header()->displaytitle = $page->header()->title; // Keep original title available for template use $page->header()->title = $page->header()->googletitle; }; if (isset($page->header()->googledesc)) { - + $meta['description']['name'] = 'description'; $meta['description']['content'] = $page->header()->googledesc; - + } else { $meta['description']['name'] = 'description'; $meta['description']['content'] = $cleanedMarkdown; }; - + /** * Set Twitter Metatags */ if (property_exists($page->header(),'twitterenable')) { if ($page->header()->twitterenable == 'true') { - + if (isset($config['twitterid'])) { $meta['twitter:site']['name'] = 'twitter:site'; $meta['twitter:site']['property'] = 'twitter:site'; @@ -211,7 +211,7 @@ public function onPageInitialized() $meta['twitter:card']['property'] = 'twitter:card'; $meta['twitter:card']['content'] = 'summary_large_image'; }; - + if (isset($page->header()->twittertitle)) { $meta['twitter:title']['name'] = 'twitter:title'; $meta['twitter:title']['property'] = 'twitter:title'; @@ -225,6 +225,10 @@ public function onPageInitialized() $meta['twitter:description']['name'] = 'twitter:description'; $meta['twitter:description']['property'] = 'twitter:description'; $meta['twitter:description']['content'] = $page->header()->twitterdescription; + } else if ($page->header()->googledescall == 1 && isset($page->header()->googledesc)) { + $meta['twitter:card']['name'] = 'twitter:card'; + $meta['twitter:card']['property'] = 'twitter:card'; + $meta['twitter:card']['content'] = $page->header()->googledesc; } else { $meta['twitter:description']['name'] = 'twitter:description'; $meta['twitter:description']['property'] = 'twitter:description'; @@ -237,7 +241,7 @@ public function onPageInitialized() $imagedata = $this->seoGetimage($twittershareimg); $meta['twitter:image']['content'] = $this->grav['uri']->base() . $imagedata['url']; } elseif(!empty($page->media()->images())) { - + $meta['twitter:image']['name'] = 'twitter:image'; $meta['twitter:image']['property'] = 'twitter:image'; $imgobject = $page->media()->images(); @@ -253,46 +257,39 @@ public function onPageInitialized() } if (property_exists($page->header(),'facebookenable')){ if ($page->header()->facebookenable == 'true') { - - //$meta['og:sitename']['name'] = 'og:sitename'; + $meta['og:site_name']['property'] = 'og:site_name'; $meta['og:site_name']['content'] = $this->config->get('site.title'); if (isset($page->header()->facebooktitle)) { - //$meta['og:title']['name'] = 'og:title'; $meta['og:title']['property'] = 'og:title'; $meta['og:title']['content'] = $page->header()->facebooktitle; } else { - // $meta['og:title']['name'] = 'og:title'; $meta['og:title']['property'] = 'og:title'; $meta['og:title']['content'] = $page->title(); } if (isset($config['facebookid'])) { - //$meta['twitter:site']['name'] = 'twitter:site'; $meta['fb:app_id']['property'] = 'fb:app_id'; $meta['fb:app_id']['content'] = $config->facebookid; }; - //$meta['og:type']['name'] = 'og:type'; $meta['og:type']['property'] = 'og:type'; $meta['og:type']['content'] = 'article'; - // $meta['og:url']['name'] = 'og:url'; $meta['og:url']['property'] = 'og:url'; $meta['og:url']['content'] = $this->grav['page']->canonical(true); if (isset($page->header()->facebookdesc)) { - //$meta['og:description']['name'] = 'og:description'; $meta['og:description']['property'] = 'og:description'; $meta['og:description']['content'] = substr($this->cleanMarkdown($page->header()->facebookdesc),0,320); + } else if ($page->header()->googledescall == 1 && isset($page->header()->googledesc)) { + $meta['og:description']['property'] = 'og:description'; + $meta['og:description']['content'] = $page->header()->googledesc; } else { - // $meta['og:description']['name'] = 'og:description'; $meta['og:description']['property'] = 'og:description'; $meta['og:description']['content'] = $cleanedMarkdown; } if (isset($page->header()->facebookauthor)) { - // $meta['article:author']['name'] = 'article:author'; $meta['article:author']['property'] = 'article:author'; $meta['article:author']['content'] = $page->header()->facebookauthor; } if (isset($page->header()->facebookimg)) { - // $meta['og:image']['name'] = 'og:image'; $meta['og:image']['property'] = 'og:image'; $facebookimg = $page->header()->facebookimg; $imagedata = $this->seoGetimage($facebookimg); @@ -306,9 +303,9 @@ public function onPageInitialized() $meta['twitter:image']['content'] = $this->grav['uri']->base() . $firstimage; $meta['og:image']['content'] = $this->grav['uri']->base() . $firstimage; } - + } - + } // Add metadata $page->metadata($meta); @@ -324,32 +321,32 @@ public function onPageInitialized() $performerarray[] = [ '@type' => @$artist['performer_type'], 'name' => @$artist['name'], - 'sameAs' => @$artist['sameAs'], + 'sameAs' => @$artist['sameAs'], ]; - + }; } if (isset($event['musicevent_workPerformed'])){ foreach ($event['musicevent_workPerformed'] as $work){ $workarray[] = [ 'name' => @$work['name'], - 'sameAs' => @$work['sameAs'], + 'sameAs' => @$work['sameAs'], ]; - + } } if (isset($event['musicevent_image'])){ $imageurl = $event['musicevent_image']; $imagedata = $this->seoGetimage($imageurl); $musiceventimage = [ - + '@type' => 'ImageObject', 'width' => $imagedata['width'], 'height' => $imagedata['height'], 'url' => $this->grav['uri']->base() . $imagedata['url'], - + ]; - + } $microdata[] = [ '@context' => 'http://schema.org', @@ -363,35 +360,35 @@ public function onPageInitialized() 'description' => @$event['musicevent_description'], 'url' => @$event['musicevent_url'], 'performer' => @$performerarray, - 'workPerformed' => @$workarray, + 'workPerformed' => @$workarray, 'image' => @$musiceventimage, 'offers' => [ '@type' => 'Offer', 'price' => @$event['musicevent_offers_price'], 'priceCurrency' => @$event['musicevent_offers_priceCurrency'], - 'url' => @$event['musicevent_offers_url'], + 'url' => @$event['musicevent_offers_url'], ], 'startDate' => @date("c", strtotime($event['musicevent_startdate'])), 'endDate' => @date("c", strtotime($event['musicevent_enddate'])), - + ]; - - + + } } - } + } } if (property_exists($page->header(),'eventenabled')){ if ($page->header()->eventenabled and $this->config['plugins']['seo']['event']) { $eventsarray = @$page->header()->addevent; - + if (count($eventsarray) > 0) { foreach ($eventsarray as $event) { $microdata[] = [ '@context' => 'http://schema.org', '@type' => 'Event', 'name' => @$event['event_name'], - + 'location' => [ '@type' => 'Place', 'name' => @$event['event_location_name'], @@ -408,18 +405,18 @@ public function onPageInitialized() '@type' => 'Offer', 'price' => @$event['event_offers_price'], 'priceCurrency' => @$event['event_offers_currency'], - 'url' => @$event['event_offers_url'], + 'url' => @$event['event_offers_url'], ], 'startDate' => @date("c", strtotime($event['event_startDate'])), 'endDate' => @date("c", strtotime($event['event_endDate'])), 'description' => @$event['event_description'], - + ]; - - + + } } - + } } if (property_exists($page->header(),'personenabled')){ @@ -431,21 +428,21 @@ public function onPageInitialized() '@context' => 'http://schema.org', '@type' => 'Person', 'name' => @$person['person_name'], - + 'address' => [ '@type' => 'PostalAddress', 'addressLocality' => @$person['person_address_addressLocality'], 'addressRegion' => @$person['person_address_addressRegion'], ], 'jobTitle' => @$person['person_jobTitle'], - + ]; - + } - + } - + } } if (property_exists($page->header(),'orgaenabled')){ @@ -455,22 +452,22 @@ public function onPageInitialized() $founderarray[] = [ '@type' => 'Person', 'name' => @$founder['name'], - ]; + ]; } } if (isset($page->header()->orga['similar'])){ foreach ($page->header()->orga['similar'] as $similar){ - $similararray[] = $similar['sameas']; + $similararray[] = $similar['sameas']; } } if (isset($page->header()->orga['areaserved'])){ foreach ($page->header()->orga['areaserved'] as $areaserved){ - $areaservedarray[] = $areaserved['area']; + $areaservedarray[] = $areaserved['area']; } - } + } if (isset($page->header()->orga['openingHours'])){ foreach ($page->header()->orga['openingHours'] as $hours){ - $openingHours[] = $hours['entry']; + $openingHours[] = $hours['entry']; } } if (isset($page->header()->orga['offercatalog'])){ @@ -513,9 +510,9 @@ public function onPageInitialized() 'ratingValue' => @$page->header()->orga['ratingValue'], 'reviewCount' => @$page->header()->orga['reviewCount'], ]; - } + } - } + } $microdata[] = [ '@context' => 'http://schema.org', '@type' => 'Organization', @@ -525,7 +522,7 @@ public function onPageInitialized() 'vatid' => @$page->header()->orga['vatid'], 'areaServed' => @$areaservedarray, 'description' => @$page->header()->orga['description'], - + 'address' => [ '@type' => 'PostalAddress', 'streetAddress' => @$page->header()->orga['streetaddress'], @@ -545,9 +542,9 @@ public function onPageInitialized() 'sameAs' => @$similararray, 'hasOfferCatalog' => @$offerarray ]; - - - + + + } } if (property_exists($page->header(),'restaurantenabled')){ @@ -556,20 +553,20 @@ public function onPageInitialized() $imageurl = $page->header()->restaurant['image']; $imagedata = $this->seoGetimage($imageurl); $restaurantimage = [ - + '@type' => 'ImageObject', 'width' => $imagedata['width'], 'height' => $imagedata['height'], 'url' => $this->grav['uri']->base() . $imagedata['url'], - + ]; - + } $microdata[] = [ '@context' => 'http://schema.org', '@type' => 'Restaurant', 'name' => @$page->header()->restaurant['name'], - + 'address' => [ '@type' => 'PostalAddress', 'addressLocality' => @$page->header()->restaurant['address_addressLocality'], @@ -582,32 +579,32 @@ public function onPageInitialized() 'priceRange' => @$page->header()->restaurant['priceRange'], 'image' => @$restaurantimage, 'telephone' => @$page->header()->restaurant['telephone'], - + ]; - + } } if (property_exists($page->header(),'productenabled')){ if ($page->header()->productenabled and $this->config['plugins']['seo']['product']) { if (isset($page->header()->product['image'])){ - $productimagearray = []; + $productimagearray = []; $productimages = $page->header()->product['image']; - - + + foreach ($productimages as $key => $value){ $imagearray = $productimages[$key]; foreach($imagearray as $newkey => $newvalue){ $imagedata = $this->seoGetimage($imagearray[$newkey]); - $productimage[] = + $productimage[] = $this->grav['uri']->base() . $imagedata['url']; - + }; - + }; } if (isset($page->header()->product['addoffer'])){ - + $offers = $page->header()->product['addoffer']; foreach ($offers as $key => $value){ $offer[$key] = [ @@ -620,8 +617,8 @@ public function onPageInitialized() ]; }; } - else { $offer = ''; } - + else { $offer = ''; } + $microdata[] = [ '@context' => 'http://schema.org', '@type' => 'Product', @@ -638,7 +635,7 @@ public function onPageInitialized() '@type' => 'AggregateRating', 'ratingValue' => @$page->header()->product['ratingValue'], 'reviewCount' => @$page->header()->product['reviewCount'], - + ] ]; } @@ -666,7 +663,7 @@ public function onPageInitialized() $microdata['article']['description'] = $page->header()->article['description']; } else { - $microdata['article']['description'] = substr($content,0,140); + $microdata['article']['description'] = substr($content,0,140); }; if (isset($page->header()->article['author'])) { @@ -683,7 +680,7 @@ public function onPageInitialized() $microdata['article']['publisher']['logo']['url'] = $this->grav['uri']->base() . $imagedata['url']; $microdata['article']['publisher']['logo']['width'] = $imagedata['width']; $microdata['article']['publisher']['logo']['height'] = $imagedata['height']; - + }; if (isset($page->header()->article['image_url'])) { $microdata['article']['image']['@type'] = 'ImageObject'; @@ -692,9 +689,9 @@ public function onPageInitialized() $microdata['article']['image']['url'] = $this->grav['uri']->base() . $imagedata['url']; $microdata['article']['image']['width'] = $imagedata['width']; $microdata['article']['image']['height'] = $imagedata['height']; - + } - } + } }; // Encode to json /*foreach ($microdata as $key => $value){ @@ -706,8 +703,8 @@ public function onPageInitialized() $microdata = $this->array_filter_recursive($microdata); $customjson = @$page->header()->add_json; foreach ($microdata as $key => $value){ - - + + $jsonscript = PHP_EOL . ''; $outputjson = $outputjson . $jsonscript; } @@ -718,8 +715,8 @@ public function onPageInitialized() } $outputjson = $outputjson . $outputcustomjson; } - - + + $outputjson = '' . $outputjson . ' + {% if field.text %} {% endif %} diff --git a/templates/forms/fields/twitter/twitter.html.twig b/templates/forms/fields/twitter/twitter.html.twig index bc47dbf..3f577cc 100644 --- a/templates/forms/fields/twitter/twitter.html.twig +++ b/templates/forms/fields/twitter/twitter.html.twig @@ -7,7 +7,7 @@ {% endif %} {% set context = admin.page(true) %} -
Twitter team
@twitter
- - - - - {% if field.text %} - {% endif %} + + {% if field.text %}{% endif %} {% if field.fields %}
From fba141c98d976ffb98b99f330bc8a3c6f96d63b9 Mon Sep 17 00:00:00 2001 From: Alix Guillard Date: Fri, 26 Nov 2021 08:09:34 +0100 Subject: [PATCH 4/5] display and save only N first chars for twitter and facebook --- seo.php | 6 +++--- templates/forms/fields/facebook/facebook.html.twig | 4 ++-- templates/forms/fields/twitter/twitter.html.twig | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/seo.php b/seo.php index 9984e50..2e97c89 100644 --- a/seo.php +++ b/seo.php @@ -228,7 +228,7 @@ public function onPageInitialized() } else if ($page->header()->googledescall == 1 && isset($page->header()->googledesc)) { $meta['twitter:card']['name'] = 'twitter:card'; $meta['twitter:card']['property'] = 'twitter:card'; - $meta['twitter:card']['content'] = $page->header()->googledesc; + $meta['twitter:card']['content'] = substr($page->header()->googledesc,0,140); } else { $meta['twitter:description']['name'] = 'twitter:description'; $meta['twitter:description']['property'] = 'twitter:description'; @@ -279,8 +279,8 @@ public function onPageInitialized() $meta['og:description']['property'] = 'og:description'; $meta['og:description']['content'] = substr($this->cleanMarkdown($page->header()->facebookdesc),0,320); } else if ($page->header()->googledescall == 1 && isset($page->header()->googledesc)) { - $meta['og:description']['property'] = 'og:description'; - $meta['og:description']['content'] = $page->header()->googledesc; + $meta['og:description']['property'] = 'og:description'; + $meta['og:description']['content'] = substr($page->header()->googledesc,0,320); } else { $meta['og:description']['property'] = 'og:description'; $meta['og:description']['content'] = $cleanedMarkdown; diff --git a/templates/forms/fields/facebook/facebook.html.twig b/templates/forms/fields/facebook/facebook.html.twig index 7532532..527f34e 100644 --- a/templates/forms/fields/facebook/facebook.html.twig +++ b/templates/forms/fields/facebook/facebook.html.twig @@ -24,7 +24,7 @@
{{ context.header.facebooktitle|default(context.header.title ~ " | " ~ site.title )}}
{% if context.header.facebookdesc %}{{ context.header.facebookdesc }} - {% elseif context.header.googledesc and context.header.googledescall == "1" %}{{ context.header.googledesc }} + {% elseif context.header.googledesc and context.header.googledescall == "1" %}{{ context.header.googledesc|truncate(300) }} {% else %}{{ context.summary|striptags|truncate(300) }}{% endif %}
{{uri.host|replace({"http://": "","/":" › " }) }}
@@ -214,7 +214,7 @@ $('#facebookdesc').keyup(function(){ $("#facebooktargdesc").html(keyed); $("#fbcount").text("Characters left: " + (300 - $(this).val().length)); } else { - var defaultDesc = $("#toggle_header\\.googledescall1").is(':checked') ? $("#desc").val() : $("#fbsummary").val(); + var defaultDesc = $("#toggle_header\\.googledescall1").is(':checked') ? $("#desc").val().substring(0,300) : $("#fbsummary").val(); $("#facebooktargdesc").html(defaultDesc); } }); diff --git a/templates/forms/fields/twitter/twitter.html.twig b/templates/forms/fields/twitter/twitter.html.twig index 3f577cc..f979ec1 100644 --- a/templates/forms/fields/twitter/twitter.html.twig +++ b/templates/forms/fields/twitter/twitter.html.twig @@ -17,7 +17,7 @@

{% if context.header.twitterdescription %}{{ context.header.twitterdescription }} - {% elseif context.header.googledesc and context.header.googledescall == "1" %}{{ context.header.googledesc }} + {% elseif context.header.googledesc and context.header.googledescall == "1" %}{{ context.header.googledesc|truncate(140) }} {% else %}{{ context.summary|striptags|truncate(140) }}{% endif %}

@@ -38,7 +38,7 @@ $("#twittdesc").html(keyed); $("#twittcount").text("Characters left: " + (140 - $(this).val().length)); } else { - var defaultDesc = $("#toggle_header\\.googledescall1").is(':checked') ? $("#desc").val() : $("#summary").val(); + var defaultDesc = $("#toggle_header\\.googledescall1").is(':checked') ? $("#desc").val().substring(0,140) : $("#summary").val(); $("#twittdesc").html(defaultDesc); } }); From 704a683bcfbaf6af685bab440065f417e464ea8c Mon Sep 17 00:00:00 2001 From: aloxe Date: Fri, 10 Dec 2021 10:44:37 +0100 Subject: [PATCH 5/5] fix problem with google desc toggled not known --- seo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seo.php b/seo.php index 2e97c89..b771636 100644 --- a/seo.php +++ b/seo.php @@ -225,7 +225,7 @@ public function onPageInitialized() $meta['twitter:description']['name'] = 'twitter:description'; $meta['twitter:description']['property'] = 'twitter:description'; $meta['twitter:description']['content'] = $page->header()->twitterdescription; - } else if ($page->header()->googledescall == 1 && isset($page->header()->googledesc)) { + } else if (isset($page->header()->googledescall) && $page->header()->googledescall == 1 && isset($page->header()->googledesc)) { $meta['twitter:card']['name'] = 'twitter:card'; $meta['twitter:card']['property'] = 'twitter:card'; $meta['twitter:card']['content'] = substr($page->header()->googledesc,0,140); @@ -278,7 +278,7 @@ public function onPageInitialized() if (isset($page->header()->facebookdesc)) { $meta['og:description']['property'] = 'og:description'; $meta['og:description']['content'] = substr($this->cleanMarkdown($page->header()->facebookdesc),0,320); - } else if ($page->header()->googledescall == 1 && isset($page->header()->googledesc)) { + } else if (isset($page->header()->googledescall) && $page->header()->googledescall == 1 && isset($page->header()->googledesc)) { $meta['og:description']['property'] = 'og:description'; $meta['og:description']['content'] = substr($page->header()->googledesc,0,320); } else {