Skip to content

Commit

Permalink
added ratings and opening hours to organization microdata
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmassen committed Dec 20, 2017
1 parent fbcf726 commit 9b093f3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
40 changes: 40 additions & 0 deletions blueprints/seo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,49 @@ form:
type: text
label: Url to Organization Logo
placeholder: 'include http://'
header.orgaratingenabled:
type: toggle
highlight: 1
label: Add rating to this organization
default: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
header.orga.ratingValue:
type: range
label: Star Rating
help: Choose a value between 0 and 5 which should be the average ratings for your product. Make sure the value is consistent with your actual reviews.
validate:
min: 0
max: 5
step: 0.1
header.orga.reviewCount:
type: number
label: Number of reviews you used for calculating your rating.
header.orga.openingHours:
type: list
label: Opening Hours
fields:
.entry:
type: text
style: vertical
label: Opening hours - Please write the day or a range of day (mon-fri) followed by a space and the opening hours"
placeholder: "Exemple: Mon-Fri 09:00-18:00 or Saturday 09:00-15:00"
header.orga.foundingDate:
type: text
label: Founding year
header.orga.email:
type: email
label: Official Email for this Organization
header.orga.paymentaccepted:
type: selectize
label: Accepted Payments
placeholder: Visa, Cash, Credit Card, Amex, etc.
validate:
type: commalist

header.orga.founders:
type: list
label: Founders
Expand Down
33 changes: 31 additions & 2 deletions seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public static function getSubscribedEvents()
// 'onBlueprintCreated' => ['onBlueprintCreated', 0]
];
}
public function array_filter_recursive( array $array, callable $callback = null ) {
$array = is_callable( $callback ) ? array_filter( $array, $callback ) : array_filter( $array );
foreach ( $array as &$value ) {
if ( is_array( $value ) ) {
$myfunc = '$this->' . __FUNCTION__;
$value = $this->array_filter_recursive($value);
}
}

return $array;
}
private function seoGetimage($imageurl){

$imagedata = [];
Expand Down Expand Up @@ -379,6 +390,18 @@ public function onPageInitialized()
$similararray[] = $similar['sameas'];
}
}
if (isset($page->header()->orga['openingHours'])){
foreach ($page->header()->orga['openingHours'] as $hours){
$openingHours[] = $hours['entry'];
}
}
if ($page->header()->orgaratingenabled){
$orgarating = [
'@type' => 'AggregateRating',
'ratingValue' => @$page->header()->orga['ratingValue'],
'reviewCount' => @$page->header()->orga['reviewCount'],
];
}
$microdata[] = [
'@context' => 'http://schema.org',
'@type' => 'Organization',
Expand All @@ -394,7 +417,11 @@ public function onPageInitialized()
'telephone' => @$page->header()->orga['phone'],
'logo' => @$page->header()->orga['logo'],
'url' => @$page->header()->orga['url'],
'openingHours' => @$openingHours,
'email' => @$page->header()->orga['email'],
'foundingDate' => @$page->header()->orga['foundingDate'],
'aggregateRating' => @$orgarating,
'paymentAccepted' => @$page->header()->orga['paymentAccepted'],
'founders' => @$founderarray,
'sameAs' => @$similararray
];
Expand Down Expand Up @@ -553,8 +580,8 @@ public function onPageInitialized()
unset($microdata[$key]);
}
}*/
$microdata = array_map('array_filter', $microdata);
$microdata = array_filter( $microdata );
// $microdata = array_map('array_filter', $microdata);
$microdata = $this->array_filter_recursive($microdata);
foreach ($microdata as $key => $value){


Expand Down Expand Up @@ -604,6 +631,8 @@ public function onTwigTemplatePaths()
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}



private function cleanMarkdown($text){
$rules = array (
'/(#+)(.*)/' => '\2', // headers
Expand Down

0 comments on commit 9b093f3

Please sign in to comment.