Skip to content

Commit

Permalink
Allow the vote plugin's position to be configured. Fixes #11375
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker authored and wilsonge committed Sep 4, 2016
1 parent e2e4b98 commit a6f5e84
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
4 changes: 4 additions & 0 deletions administrator/language/en-GB/en-GB.plg_content_vote.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
; Note : All ini files need to be saved as UTF-8

PLG_CONTENT_VOTE="Content - Vote"
PLG_VOTE_BOTTOM="Bottom"
PLG_VOTE_LABEL="Please Rate"
PLG_VOTE_POSITION_DESC="Set where the voting is displayed."
PLG_VOTE_POSITION_LABEL="Position"
PLG_VOTE_RATE="Rate"
PLG_VOTE_STAR_ACTIVE="Star Active"
PLG_VOTE_STAR_INACTIVE="Star Inactive"
PLG_VOTE_TOP="Top"
PLG_VOTE_USER_RATING="User Rating: %1$s / %2$s"
PLG_VOTE_VOTE="Vote %s"
PLG_VOTE_XML_DESCRIPTION="Add Voting functionality to Articles."
71 changes: 69 additions & 2 deletions plugins/content/vote/vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,30 @@ class PlgContentVote extends JPlugin
protected $app;

/**
* Displays the voting area if in an article
* The position the voting data is displayed in relative to the article.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $votingPosition;

/**
* Constructor.
*
* @param object &$subject The object to observe
* @param array $config An optional associative array of configuration settings.
*
* @since __DEPLOY_VERSION__
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);

$this->votingPosition = $this->params->get('position', 'top');
}

/**
* 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
Expand All @@ -36,7 +59,51 @@ class PlgContentVote extends JPlugin
*
* @since 1.6
*/
public function onContentBeforeDisplay($context, &$row, &$params, $page=0)
public function onContentBeforeDisplay($context, &$row, &$params, $page = 0)
{
if ($this->votingPosition != '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 __DEPLOY_VERSION__
*/
public function onContentAfterDisplay($context, &$row, &$params, $page = 0)
{
if ($this->votingPosition != '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|boolean HTML string containing code for the votes if in com_content else boolean false
*
* @since __DEPLOY_VERSION__
*/
private function displayVotingData($context, &$row, &$params, $page)
{
$parts = explode(".", $context);

Expand Down
12 changes: 12 additions & 0 deletions plugins/content/vote/vote.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="position"
type="list"
default="top"
description="PLG_VOTE_POSITION_DESC"
label="PLG_VOTE_POSITION_LABEL"
>
<option value="top">PLG_VOTE_TOP</option>
<option value="bottom">PLG_VOTE_BOTTOM</option>
</field>
</fieldset>
</fields>
</config>
</extension>

0 comments on commit a6f5e84

Please sign in to comment.