primo commit
This commit is contained in:
		
							
								
								
									
										100
									
								
								plugins/content/vote/tmpl/rating.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								plugins/content/vote/tmpl/rating.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,100 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Plugin | ||||
|  * @subpackage  Content.vote | ||||
|  * | ||||
|  * @copyright   (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| use Joomla\CMS\HTML\HTMLHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\Uri\Uri; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * @var Joomla\CMS\WebAsset\WebAssetManager $wa | ||||
|  * @var \Joomla\Plugin\Content\Vote\Extension\Vote $this | ||||
|  */ | ||||
| $wa = $this->getApplication()->getDocument()->getWebAssetManager(); | ||||
| $wa->registerAndUseStyle('plg_content_vote', 'plg_content_vote/rating.css'); | ||||
|  | ||||
| /** | ||||
|  * Layout variables | ||||
|  * ----------------- | ||||
|  * @var   string   $context  The context of the content being passed to the plugin | ||||
|  * @var   object   &$row     The article object | ||||
|  * @var   object   &$params  The article params | ||||
|  * @var   integer  $page     The 'page' number | ||||
|  * @var   array    $parts    The context segments | ||||
|  * @var   string   $path     Path to this file | ||||
|  */ | ||||
|  | ||||
| if ($context === 'com_content.categories') { | ||||
|     return; | ||||
| } | ||||
|  | ||||
| // Get the icons | ||||
| $iconStar     = HTMLHelper::_('image', 'plg_content_vote/vote-star.svg', '', '', true, true); | ||||
| $iconHalfstar = HTMLHelper::_('image', 'plg_content_vote/vote-star-half.svg', '', '', true, true); | ||||
|  | ||||
| // If you can't find the icons then skip it | ||||
| if ($iconStar === null || $iconHalfstar === null) { | ||||
|     return; | ||||
| } | ||||
|  | ||||
| // Get paths to icons | ||||
| $pathStar     = JPATH_ROOT . substr($iconStar, strlen(Uri::root(true))); | ||||
| $pathHalfstar = JPATH_ROOT . substr($iconHalfstar, strlen(Uri::root(true))); | ||||
|  | ||||
| // Write inline '<svg>' elements | ||||
| $star     = file_exists($pathStar) ? file_get_contents($pathStar) : ''; | ||||
| $halfstar = file_exists($pathHalfstar) ? file_get_contents($pathHalfstar) : ''; | ||||
|  | ||||
| // Get rating | ||||
| $rating = (float) $row->rating; | ||||
| $rcount = (int) $row->rating_count; | ||||
|  | ||||
| // Round to 0.5 | ||||
| $rating = round($rating / 0.5) * 0.5; | ||||
|  | ||||
| // Determine number of stars | ||||
| $stars = $rating; | ||||
| $img   = ''; | ||||
|  | ||||
| for ($i = 0; $i < floor($stars); $i++) { | ||||
|     $img .= '<li class="vote-star">' . $star . '</li>'; | ||||
| } | ||||
|  | ||||
| if (($stars - floor($stars)) >= 0.5) { | ||||
|     $img .= '<li class="vote-star-empty">' . $star . '</li>'; | ||||
|     $img .= '<li class="vote-star-half">' . $halfstar . '</li>'; | ||||
|  | ||||
|     ++$stars; | ||||
| } | ||||
|  | ||||
| for ($i = $stars; $i < 5; $i++) { | ||||
|     $img .= '<li class="vote-star-empty">' . $star . '</li>'; | ||||
| } | ||||
|  | ||||
| ?> | ||||
| <div class="content_rating" role="img" aria-label="<?php echo Text::sprintf('PLG_VOTE_STAR_RATING', $rating); ?>"> | ||||
|     <?php if ($rcount) : ?> | ||||
|         <div class="visually-hidden"> | ||||
|             <p 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> | ||||
|         </div> | ||||
|         <?php if ($this->params->get('show_total_votes', 0)) : ?> | ||||
|             <?php echo Text::sprintf('PLG_VOTE_TOTAL_VOTES', $rcount); ?> | ||||
|         <?php endif; ?> | ||||
|     <?php endif; ?> | ||||
|     <ul> | ||||
|         <?php echo $img; ?> | ||||
|     </ul> | ||||
| </div> | ||||
							
								
								
									
										48
									
								
								plugins/content/vote/tmpl/vote.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								plugins/content/vote/tmpl/vote.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * @package     Joomla.Plugin | ||||
|  * @subpackage  Content.vote | ||||
|  * | ||||
|  * @copyright   (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| use Joomla\CMS\HTML\HTMLHelper; | ||||
| use Joomla\CMS\Language\Text; | ||||
| use Joomla\CMS\Uri\Uri; | ||||
|  | ||||
| /** | ||||
|  * Layout variables | ||||
|  * ----------------- | ||||
|  * @var   string   $context  The context of the content being passed to the plugin | ||||
|  * @var   object   &$row     The article object | ||||
|  * @var   object   &$params  The article params | ||||
|  * @var   integer  $page     The 'page' number | ||||
|  * @var   array    $parts    The context segments | ||||
|  * @var   string   $path     Path to this file | ||||
|  */ | ||||
|  | ||||
| $uri = clone Uri::getInstance(); | ||||
|  | ||||
| // Create option list for voting select box | ||||
| $options = []; | ||||
|  | ||||
| for ($i = 1; $i < 6; $i++) { | ||||
|     $options[] = HTMLHelper::_('select.option', $i, Text::sprintf('PLG_VOTE_VOTE', $i)); | ||||
| } | ||||
|  | ||||
| ?> | ||||
| <form method="post" action="<?php echo htmlspecialchars($uri->toString(), ENT_COMPAT, 'UTF-8'); ?>" class="form-inline mb-2"> | ||||
|     <span class="content_vote"> | ||||
|         <label class="visually-hidden" for="content_vote_<?php echo (int) $row->id; ?>"><?php echo Text::_('PLG_VOTE_LABEL'); ?></label> | ||||
|         <?php echo HTMLHelper::_('select.genericlist', $options, 'user_rating', 'class="form-select form-select-sm w-auto"', 'value', 'text', '5', 'content_vote_' . (int) $row->id); ?> | ||||
|         <input class="btn btn-sm btn-primary align-baseline" type="submit" name="submit_vote" value="<?php echo Text::_('PLG_VOTE_RATE'); ?>"> | ||||
|         <input type="hidden" name="task" value="article.vote"> | ||||
|         <input type="hidden" name="hitcount" value="0"> | ||||
|         <input type="hidden" name="url" value="<?php echo htmlspecialchars($uri->toString(), ENT_COMPAT, 'UTF-8'); ?>"> | ||||
|         <?php echo HTMLHelper::_('form.token'); ?> | ||||
|     </span> | ||||
| </form> | ||||
		Reference in New Issue
	
	Block a user