Spade
Mini Shell
vote.xml000064400000002723151170300120006235 0ustar00<?xml
version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="content"
method="upgrade">
<name>plg_content_vote</name>
<author>Joomla! Project</author>
<creationDate>2005-11</creationDate>
<copyright>(C) 2005 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see
LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_VOTE_XML_DESCRIPTION</description>
<namespace
path="src">Joomla\Plugin\Content\Vote</namespace>
<files>
<folder plugin="vote">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<languages>
<language
tag="en-GB">language/en-GB/plg_content_vote.ini</language>
<language
tag="en-GB">language/en-GB/plg_content_vote.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="position"
type="list"
label="PLG_VOTE_POSITION_LABEL"
default="top"
validate="options"
>
<option value="top">PLG_VOTE_TOP</option>
<option value="bottom">PLG_VOTE_BOTTOM</option>
</field>
<field
name="show_total_votes"
type="radio"
label="PLG_VOTE_TOTAL_VOTES_LABEL"
layout="joomla.form.field.radio.switcher"
default="0"
filter="integer"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
</fieldset>
</fields>
</config>
</extension>
services/provider.php000064400000002364151170300120010725 0ustar00<?php
/**
* @package Joomla.Plugin
* @subpackage Content.vote
*
* @copyright (C) 2023 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\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Content\Vote\Extension\Vote;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.4.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new Vote(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('content',
'vote')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};
tmpl/vote.php000064400000003517151170300120007202 0ustar00<?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>
tmpl/rating.php000064400000006203151170300120007504 0ustar00<?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 */
$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" itemscope
itemtype="https://schema.org/Product">
<span itemprop="name"><?php echo $row->title;
?></span>
<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>
<?php if ($this->params->get('show_total_votes',
0)) : ?>
<?php echo Text::sprintf('PLG_VOTE_TOTAL_VOTES',
$rcount); ?>
<?php endif; ?>
</div>
<?php endif; ?>
<ul>
<?php echo $img; ?>
</ul>
</div>
src/Extension/Vote.php000064400000007516151170300120010734 0ustar00<?php
/**
* @package Joomla.Plugin
* @subpackage Content.vote
*
* @copyright (C) 2006 Open Source Matters, Inc.
<https://www.joomla.org>
* @license GNU General Public License version 2 or later; see
LICENSE.txt
*/
namespace Joomla\Plugin\Content\Vote\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Vote plugin.
*
* @since 1.5
*/
final class Vote extends CMSPlugin
{
/**
* @var \Joomla\CMS\Application\CMSApplication
*
* @since 3.7.0
*
* @deprecated 4.4.0 will be removed in 6.0 as it is there only for
layout overrides
* Use getApplication() instead
*/
protected $app;
/**
* Displays the voting area when viewing an article and the voting
section is displayed before the article
*
* @param string $context The context of the content being passed
to the plugin
* @param object &$row The article object
* @param object &$params The article params
* @param integer $page The 'page' number
*
* @return string|boolean HTML string containing code for the votes
if in com_content else boolean false
*
* @since 1.6
*/
public function onContentBeforeDisplay($context, &$row,
&$params, $page = 0)
{
if ($this->params->get('position', 'top')
!== 'top') {
return '';
}
return $this->displayVotingData($context, $row, $params, $page);
}
/**
* Displays the voting area when viewing an article and the voting
section is displayed after the article
*
* @param string $context The context of the content being passed
to the plugin
* @param object &$row The article object
* @param object &$params The article params
* @param integer $page The 'page' number
*
* @return string|boolean HTML string containing code for the votes
if in com_content else boolean false
*
* @since 3.7.0
*/
public function onContentAfterDisplay($context, &$row,
&$params, $page = 0)
{
if ($this->params->get('position', 'top')
!== 'bottom') {
return '';
}
return $this->displayVotingData($context, $row, $params, $page);
}
/**
* Displays the voting area
*
* @param string $context The context of the content being passed
to the plugin
* @param object &$row The article object
* @param object &$params The article params
* @param integer $page The 'page' number
*
* @return string HTML string containing code for the votes if in
com_content else empty string
*
* @since 3.7.0
*/
private function displayVotingData($context, &$row, &$params,
$page)
{
$parts = explode('.', $context);
if ($parts[0] !== 'com_content') {
return '';
}
if (empty($params) || !$params->get('show_vote',
null)) {
return '';
}
// Load plugin language files only when needed (ex: they are not
needed if show_vote is not active).
$this->loadLanguage();
// Get the path for the rating summary layout file
$path = PluginHelper::getLayoutPath('content',
'vote', 'rating');
// Render the layout
ob_start();
include $path;
$html = ob_get_clean();
if
($this->getApplication()->getInput()->getString('view',
'') === 'article' && $row->state == 1) {
// Get the path for the voting form layout file
$path = PluginHelper::getLayoutPath('content',
'vote', 'vote');
// Render the layout
ob_start();
include $path;
$html .= ob_get_clean();
}
return $html;
}
}