Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
2047969
[5.1]Vote : aggregateRating error in Google Rich Results
Mar 1, 2024
f2f2565
Update rating.php
Mar 1, 2024
2110d3b
[5.1] Add aggregateRating
Mar 3, 2024
6eec765
Merge branch '5.1-dev' into 5.1-dev
Mar 3, 2024
ee326b9
Update libraries/src/Schemaorg/SchemaorgPrepareProductAggregateRating…
Mar 3, 2024
b0ca4a4
Update libraries/src/Schemaorg/SchemaorgPrepareProductAggregateRating…
Mar 3, 2024
d04ab02
Update administrator/language/en-GB/plg_schemaorg_aggregaterating.ini
Mar 3, 2024
18329b8
Update libraries/src/Schemaorg/SchemaorgPrepareRecipeAggregateRating.php
Mar 3, 2024
c89a71a
Update libraries/src/Schemaorg/SchemaorgPrepareRecipeAggregateRating.php
Mar 3, 2024
6a2a3b3
Update plugins/schemaorg/aggregaterating/aggregaterating.xml
Mar 3, 2024
eb87e70
Update plugins/schemaorg/aggregaterating/services/provider.php
Mar 3, 2024
bc4a773
Update plugins/schemaorg/aggregaterating/aggregaterating.xml
Mar 3, 2024
079b53c
Update plugins/schemaorg/aggregaterating/services/provider.php
Mar 3, 2024
f9dad77
Update plugins/schemaorg/aggregaterating/src/Extension/AggregateRatin…
Mar 3, 2024
1c7ae08
Update plugins/schemaorg/aggregaterating/src/Extension/AggregateRatin…
Mar 3, 2024
5906495
Update plugins/schemaorg/aggregaterating/src/Extension/AggregateRatin…
Mar 3, 2024
06361f7
Update plugins/schemaorg/aggregaterating/aggregaterating.xml
Mar 3, 2024
6a2ef72
Update plugins/schemaorg/aggregaterating/src/Extension/AggregateRatin…
Mar 3, 2024
51055ae
Update plugins/schemaorg/aggregaterating/src/Extension/AggregateRatin…
Mar 3, 2024
7bad455
Update plugins/schemaorg/aggregaterating/src/Extension/AggregateRatin…
Mar 3, 2024
c2d6ab7
Update SchemaorgPrepareProductAggregateRating.php
Mar 3, 2024
dcc65f3
Update SchemaorgPrepareRecipeAggregateRating.php
Mar 3, 2024
b007a9c
5.1 : AggregateRating
Mar 3, 2024
ea09697
5.1 : aggregaterating
Mar 3, 2024
ad65284
Update rating.php
Mar 3, 2024
5f84ef9
5.1 aggregateRating
Mar 3, 2024
881b8db
Update Vote.php
Mar 3, 2024
3671034
Merge branch '5.1-dev' into 5.1-dev
Mar 3, 2024
da2242f
5.1 : aggregatrating
Mar 3, 2024
556e59e
Merge branch '5.1-dev' of https://github.com/conseilgouz/joomla-cms i…
Mar 3, 2024
c89fdee
5.1 : aggregaterating
Mar 3, 2024
e4e206b
5.1 : aggregaterating
Mar 3, 2024
250efa5
Merge branch '5.1-dev' into 5.1-dev
Mar 3, 2024
50aa1c5
5.1 : aggregaterating
Mar 3, 2024
73bec50
Merge branch '5.1-dev' of https://github.com/conseilgouz/joomla-cms i…
Mar 3, 2024
e6c7e8a
Update Vote.php
Mar 3, 2024
62c2fdd
5.1 : aggregaterating
Mar 3, 2024
b8ea2bf
Update SchemaorgPrepareRecipeAggregateRating.php
Mar 3, 2024
2e5aa50
Update rating.php
Mar 3, 2024
d5b4970
Update libraries/src/Schemaorg/SchemaorgPrepareProductAggregateRating…
Mar 3, 2024
209236c
Update plugins/content/vote/src/Extension/Vote.php
Mar 3, 2024
ff5cf0d
5.1 : aggregaterating
Mar 3, 2024
393ff14
Merge branch '5.1-dev' of https://github.com/conseilgouz/joomla-cms i…
Mar 3, 2024
ae60130
5.1 : aggregaterating
Mar 4, 2024
70cfee2
Merge branch '5.1-dev' into 5.1-dev
Mar 4, 2024
33a6dea
5.1 : aggregaterating
Mar 4, 2024
78bcf77
Merge branch '5.1-dev' of https://github.com/conseilgouz/joomla-cms i…
Mar 4, 2024
659ddfc
Update Vote.php
Mar 4, 2024
b8bb9f1
5.1 : aggregaterating
Mar 4, 2024
ff2555e
Update Vote.php
Mar 4, 2024
297c185
5.1 : aggregaterating
Mar 4, 2024
c0d0bd8
Update Vote.php
Mar 4, 2024
9af6bce
Update Vote.php
Mar 4, 2024
ba432f6
5.1 aggregaterating
Mar 4, 2024
9ffa36c
5.1 : aggregaterating for Article
Mar 4, 2024
0c286f7
Merge branch '5.1-dev' into 5.1-dev
Mar 4, 2024
514e2cf
Merge branch '5.1-dev' into 5.1-dev
Mar 4, 2024
5cf1222
Update libraries/src/Schemaorg/SchemaorgPrepareAggregateRating.php
Mar 4, 2024
d96cf41
Update plugins/content/vote/src/Extension/Vote.php
Mar 4, 2024
7d252e6
Merge branch '5.1-dev' into 5.1-dev
Mar 4, 2024
ce0ca5d
5.1 : aggregaterating
Mar 4, 2024
61c2ae5
Merge branch '5.1-dev' of https://github.com/conseilgouz/joomla-cms i…
Mar 4, 2024
54855a2
Update Vote.php
Mar 4, 2024
70a3661
No vote
Mar 4, 2024
704d2e5
Update Vote.php
Mar 4, 2024
928f354
Update Vote.php
Mar 4, 2024
8e26131
Merge branch '5.1-dev' into 5.1-dev
Mar 5, 2024
54f871f
Merge branch '5.1-dev' into 5.1-dev
Mar 5, 2024
7bebf3a
Merge branch '5.1-dev' into 5.1-dev
Mar 6, 2024
3bb1ba4
Merge branch 'joomla:5.1-dev' into 5.1-dev
Apr 6, 2024
61a5519
Update Update.php
Apr 6, 2024
c124cb9
Update UpdateModel.php
Apr 6, 2024
eca2730
restore Update.php
Apr 6, 2024
de21fd4
restore UpdateModel.php
Apr 6, 2024
8fe4f00
Merge branch 'joomla:5.1-dev' into 5.1-dev
Apr 7, 2024
2637ad9
Merge branch '5.2-dev' into 5.1-dev
pe7er Apr 26, 2024
777c85f
Merge branch '5.2-dev' into 5.1-dev
pe7er Apr 30, 2024
a9a2f86
Merge branch '5.2-dev' into 5.1-dev
pe7er Apr 30, 2024
483d536
Merge branch '5.2-dev' into 5.1-dev
QuyTon Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions plugins/content/vote/src/Extension/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Uri\Uri;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -123,4 +124,110 @@ private function displayVotingData($context, &$row, &$params, $page)

return $html;
}

/**
* Create SchemaOrg AggregateRating
*
* @param object $schema The schema of the content being passed to the plugin
* @param string $context The context of the content being passed to the plugin
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onSchemaBeforeCompileHead($schema, $context): void
{
$graph = $schema->get('@graph');
$baseId = Uri::root() . '#/schema/';
$schemaId = $baseId . str_replace('.', '/', $context);

foreach ($graph as &$entry) {
if (!isset($entry['@type']) || !isset($entry['@id'])) {
continue;
}
if ($entry['@id'] !== $schemaId) {
continue;
}

switch ($entry['@type']) {
case 'Book':
case 'Brand':
case 'CreativeWork':
case 'Event':
case 'Offer':
case 'Organization':
case 'Place':
case 'Product':
case 'Recipe':
case 'Service':
$rating = $this->prepareAggregateRating($context);
break;
case 'Article':
case 'BlogPosting':
$rating = $this->prepareProductAggregateRating($context);
break;
}
}

if (isset($rating) && $rating) {
$graph[] = $rating;
$schema->set('@graph', $graph);
}
}

/**
* Prepare AggregateRating
*
* @param string $context
*
* @return ?string
*
* @since __DEPLOY_VERSION__
*/
protected function prepareAggregateRating($context)
{
[$extension, $view, $id] = explode('.', $context);

if ($view === 'article') {
$baseId = Uri::root() . '#/schema/';
$schemaId = $baseId . str_replace('.', '/', $context);

$component = $this->getApplication()->bootComponent('com_content')->getMVCFactory();
$model = $component->createModel('Article', 'Site');
$article = $model->getItem($id);
if ($article->rating_count > 0) {
return ['@isPartOf' => ['@id' => $schemaId, 'aggregateRating' => ['@type' => 'AggregateRating','ratingCount' => (string) $article->rating_count,'ratingValue' => (string) $article->rating]]];
}
}

return false;
}

/**
* Prepare Product AggregateRating
*
* @param string $context
*
* @return ?string
*
* @since __DEPLOY_VERSION__
*/
protected function prepareProductAggregateRating($context)
{
[$extension, $view, $id] = explode('.', $context);

if ($view === 'article') {
$baseId = Uri::root() . '#/schema/';
$schemaId = $baseId . str_replace('.', '/', $context);

$component = $this->getApplication()->bootComponent('com_content')->getMVCFactory();
$model = $component->createModel('Article', 'Site');
$article = $model->getItem($id);
if ($article->rating_count > 0) {
return ['@isPartOf' => ['@id' => $schemaId, '@type' => 'Product', 'name' => $article->title, 'aggregateRating' => ['@type' => 'AggregateRating', 'ratingCount' => (string) $article->rating_count, 'ratingValue' => (string) $article->rating]]];
}
}

return false;
}
}
6 changes: 2 additions & 4 deletions plugins/content/vote/tmpl/rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@
?>
<div class="content_rating" role="img" aria-label="<?php echo Text::sprintf('PLG_VOTE_STAR_RATING', $rating); ?>">
<?php if ($rcount) : ?>
<p class="visually-hidden" itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
<?php echo Text::sprintf('PLG_VOTE_USER_RATING', '<span itemprop="ratingValue">' . $rating . '</span>', '<span itemprop="bestRating">5</span>'); ?>
<meta itemprop="ratingCount" content="<?php echo $rcount; ?>">
<meta itemprop="worstRating" content="1">
<p class="visually-hidden">
<?php echo Text::sprintf('PLG_VOTE_USER_RATING', $rating, 5); ?>
</p>
<?php if ($this->params->get('show_total_votes', 0)) : ?>
<?php echo Text::sprintf('PLG_VOTE_TOTAL_VOTES', $rcount); ?>
Expand Down