[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage Content.vote 6 * 7 * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 defined('_JEXEC') or die; 12 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\Uri\Uri; 16 17 /** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ 18 $wa = $this->app->getDocument()->getWebAssetManager(); 19 $wa->registerAndUseStyle('plg_content_vote', 'plg_content_vote/rating.css'); 20 21 /** 22 * Layout variables 23 * ----------------- 24 * @var string $context The context of the content being passed to the plugin 25 * @var object &$row The article object 26 * @var object &$params The article params 27 * @var integer $page The 'page' number 28 * @var array $parts The context segments 29 * @var string $path Path to this file 30 */ 31 32 if ($context === 'com_content.categories') { 33 return; 34 } 35 36 // Get the icons 37 $iconStar = HTMLHelper::_('image', 'plg_content_vote/vote-star.svg', '', '', true, true); 38 $iconHalfstar = HTMLHelper::_('image', 'plg_content_vote/vote-star-half.svg', '', '', true, true); 39 40 // If you can't find the icons then skip it 41 if ($iconStar === null || $iconHalfstar === null) { 42 return; 43 } 44 45 // Get paths to icons 46 $pathStar = JPATH_ROOT . substr($iconStar, strlen(Uri::root(true))); 47 $pathHalfstar = JPATH_ROOT . substr($iconHalfstar, strlen(Uri::root(true))); 48 49 // Write inline '<svg>' elements 50 $star = file_exists($pathStar) ? file_get_contents($pathStar) : ''; 51 $halfstar = file_exists($pathHalfstar) ? file_get_contents($pathHalfstar) : ''; 52 53 // Get rating 54 $rating = (float) $row->rating; 55 $rcount = (int) $row->rating_count; 56 57 // Round to 0.5 58 $rating = round($rating / 0.5) * 0.5; 59 60 // Determine number of stars 61 $stars = $rating; 62 $img = ''; 63 64 for ($i = 0; $i < floor($stars); $i++) { 65 $img .= '<li class="vote-star">' . $star . '</li>'; 66 } 67 68 if (($stars - floor($stars)) >= 0.5) { 69 $img .= '<li class="vote-star-empty">' . $star . '</li>'; 70 $img .= '<li class="vote-star-half">' . $halfstar . '</li>'; 71 72 ++$stars; 73 } 74 75 for ($i = $stars; $i < 5; $i++) { 76 $img .= '<li class="vote-star-empty">' . $star . '</li>'; 77 } 78 79 ?> 80 <div class="content_rating" role="img" aria-label="<?php echo Text::sprintf('PLG_VOTE_STAR_RATING', $rating); ?>"> 81 <?php if ($rcount) : ?> 82 <p class="visually-hidden" itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating"> 83 <?php echo Text::sprintf('PLG_VOTE_USER_RATING', '<span itemprop="ratingValue">' . $rating . '</span>', '<span itemprop="bestRating">5</span>'); ?> 84 <meta itemprop="ratingCount" content="<?php echo $rcount; ?>"> 85 <meta itemprop="worstRating" content="1"> 86 </p> 87 <?php if ($this->params->get('show_total_votes', 0)) : ?> 88 <?php echo Text::sprintf('PLG_VOTE_TOTAL_VOTES', $rcount); ?> 89 <?php endif; ?> 90 <?php endif; ?> 91 <ul> 92 <?php echo $img; ?> 93 </ul> 94 </div>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |