diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 899bd0b..09234cf 100644 --- a/blueprints/seo.yaml +++ b/blueprints/seo.yaml @@ -16,23 +16,27 @@ form: fields: googlefields: type: tab - title: Google + title: Google fields: header.googletitle: type: text label: PLUGIN_SEO.GOOGLE_TITLE - id: text + id: title header.googledesc: type: textarea label: PLUGIN_SEO.GOOGLE_DESC id: desc - + header.googlekeywords: + type: text + label: PLUGIN_SEO.GOOGLE_KEYWORDS + id: keywords + header.googlepreview: type: google label: PLUGIN_SEO.GOOGLE_PREVIEWDESC twitterfields: type: tab - title: Twitter + title: Twitter fields: columns: type: columns @@ -72,7 +76,7 @@ form: label: PLUGIN_SEO.TWITTER_SHAREIMG preview_images: true id: twittimgselect - + header.twittertitle: type: text label: PLUGIN_SEO.TWITTER_TITLE @@ -82,21 +86,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 +235,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 +252,7 @@ form: label: PLUGIN_SEO.PRICE_CURRENCY field_classes: togglemusicevent placeholder: USD - + .musicevent_performer: type: list label: PLUGIN_SEO.ADD_PERFORMER @@ -269,7 +273,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 +361,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 +471,7 @@ form: type: conditional condition: "config.plugins.seo.event ? 'true' : 'false'" fields: - + header.eventfieldset: type: fieldset title: Event Microdata @@ -498,7 +502,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 +545,7 @@ form: fields: header.personfieldset: type: fieldset - title: Person Microdata + title: Person Microdata collapsed: true icon: address-card-o collapsible: true @@ -573,11 +577,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 +589,7 @@ form: fields: header.musicalbumfieldset: type: fieldset - title: Music Album Microdata + title: Music Album Microdata icon: headphones collapsed: true collapsible: true @@ -622,9 +626,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 +637,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 +661,7 @@ form: header.productfieldset: type: fieldset icon: shopping-bag - title: Product Microdata + title: Product Microdata collapsed: true collapsible: true fields: @@ -670,10 +674,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 +736,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 +744,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 +758,7 @@ form: header.restaurantfieldset: type: fieldset icon: cutlery - title: Restaurant Microdata + title: Restaurant Microdata collapsed: true collapsible: true fields: @@ -767,7 +771,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 +835,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 +847,7 @@ form: column3: type: column fields: - + header.facebookenable: type: toggle label: PLUGIN_SEO.FACEBOOK_ENABLE @@ -855,13 +859,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 +882,7 @@ form: id: fbimgselect label: PLUGIN_SEO.FACEBOOK_SHAREIMG # .... subfields - + column4: type: column fields: @@ -887,17 +891,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..c59a710 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -3,8 +3,9 @@ PLUGIN_SEO: CANONICAL_URL: "Canonical URL" PLUGIN_STATUS: "Plugin status" STATUS_HELP: "Set to false to disable this plugin completely." - GOOGLE_DESC: "Override Description" - GOOGLE_TITLE: "Override Title" + GOOGLE_DESC: "Description" + GOOGLE_KEYWORDS: "Meta Keywords, coma separated" + GOOGLE_TITLE: "Override Page Title" GOOGLE_PREVIEWDESC: "Here is a preview of your page on Google results" TWITTER_ENABLE: "Activate twitter card" TWITTER_CARD_SELECT: "Select twitter card type" @@ -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..4aef9e4 100644 --- a/languages/nl.yaml +++ b/languages/nl.yaml @@ -3,8 +3,9 @@ PLUGIN_SEO: CANONICAL_URL: "Canonical URL" PLUGIN_STATUS: "Plugin status" STATUS_HELP: "Zet op false om deze plugin volledig stop te zetten." - GOOGLE_DESC: "Overschrijf omschrijving" - GOOGLE_TITLE: "Overschrijf titel" + GOOGLE_DESC: "Omschrijving" + GOOGLE_KEYWORDS: "Meta sleutelwoord, Kommagescheiden" + GOOGLE_TITLE: "Overschrijf titel van de pagina" GOOGLE_PREVIEWDESC: "Hier is een preview van jouw pagina in de google resultaten." TWITTER_ENABLE: "Activeer twitter kaart" TWITTER_CARD_SELECT: "Selecteer twitter kaart type" @@ -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/seo.php b/seo.php index 75094c6..9d53ed9 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,29 @@ 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()->googlekeywords)) { + $meta['keywords']['name'] = 'keywords'; + $meta['keywords']['content'] = $page->header()->googlekeywords; + } + $meta['description']['name'] = 'description'; 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 +212,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'; @@ -237,7 +238,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,7 +254,7 @@ 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'); @@ -306,9 +307,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 +325,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 +364,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 +409,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 +432,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 +456,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 +514,9 @@ public function onPageInitialized() 'ratingValue' => @$page->header()->orga['ratingValue'], 'reviewCount' => @$page->header()->orga['reviewCount'], ]; - } + } - } + } $microdata[] = [ '@context' => 'http://schema.org', '@type' => 'Organization', @@ -525,7 +526,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 +546,9 @@ public function onPageInitialized() 'sameAs' => @$similararray, 'hasOfferCatalog' => @$offerarray ]; - - - + + + } } if (property_exists($page->header(),'restaurantenabled')){ @@ -556,20 +557,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 +583,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 +621,8 @@ public function onPageInitialized() ]; }; } - else { $offer = ''; } - + else { $offer = ''; } + $microdata[] = [ '@context' => 'http://schema.org', '@type' => 'Product', @@ -638,7 +639,7 @@ public function onPageInitialized() '@type' => 'AggregateRating', 'ratingValue' => @$page->header()->product['ratingValue'], 'reviewCount' => @$page->header()->product['reviewCount'], - + ] ]; } @@ -666,7 +667,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 +684,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 +693,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 +707,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 +719,8 @@ public function onPageInitialized() } $outputjson = $outputjson . $outputcustomjson; } - - + + $outputjson = '' . $outputjson . '