Source for file vote.php

Documentation is available at vote.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Plugin
  4.  * @subpackage  Content.vote
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Vote plugin.
  14.  *
  15.  * @package     Joomla.Plugin
  16.  * @subpackage  Content.vote
  17.  * @since       1.5
  18.  */
  19. class PlgContentVote extends JPlugin
  20. {
  21.     /**
  22.      * Load the language file on instantiation.
  23.      *
  24.      * @var    boolean 
  25.      * @since  3.1
  26.      */
  27.     protected $autoloadLanguage = true;
  28.  
  29.     /**
  30.      * Displays the voting area if in an article
  31.      *
  32.      * @param   string   $context  The context of the content being passed to the plugin
  33.      * @param   object   &$row     The article object
  34.      * @param   object   &$params  The article params
  35.      * @param   integer  $page     The 'page' number
  36.      *
  37.      * @return  mixed  html string containing code for the votes if in com_content else boolean false
  38.      *
  39.      * @since   1.6
  40.      */
  41.     public function onContentBeforeDisplay($context&$row&$params$page=0)
  42.     {
  43.         $parts explode(" "$context);
  44.         if ($parts[0!= 'com_content')
  45.         {
  46.             return false;
  47.         }
  48.  
  49.         $html '';
  50.  
  51.         if (!empty($params&& $params->get('show_vote'null))
  52.         {
  53.             $rating = (int) @$row->rating;
  54.  
  55.             $view JFactory::getApplication()->input->getString('view''');
  56.             $img '';
  57.  
  58.             // Look for images in template if available
  59.             $starImageOn JHtml::_('image''system/rating_star.png'JText::_('PLG_VOTE_STAR_ACTIVE')nulltrue);
  60.             $starImageOff JHtml::_('image''system/rating_star_blank.png'JText::_('PLG_VOTE_STAR_INACTIVE')nulltrue);
  61.  
  62.             for ($i 0$i $rating$i++)
  63.             {
  64.                 $img .= $starImageOn;
  65.             }
  66.  
  67.             for ($i $rating$i 5$i++)
  68.             {
  69.                 $img .= $starImageOff;
  70.             }
  71.  
  72.             $html .= '<div class="content_rating">';
  73.             $html .= '<p class="unseen element-invisible">' JText::sprintf('PLG_VOTE_USER_RATING'$rating'5''</p>';
  74.             $html .= $img;
  75.             $html .= '</div>';
  76.  
  77.             if ($view == 'article' && $row->state == 1)
  78.             {
  79.                 $uri JUri::getInstance();
  80.                 $uri->setQuery($uri->getQuery('&hitcount=0');
  81.  
  82.                 // Create option list for voting select box
  83.                 $options array();
  84.  
  85.                 for ($i 1$i 6$i++)
  86.                 {
  87.                     $options[JHtml::_('select.option'$iJText::sprintf('PLG_VOTE_VOTE'$i));
  88.                 }
  89.  
  90.                 // Generate voting form
  91.                 $html .= '<form method="post" action="' htmlspecialchars($uri->toString()) '" class="form-inline">';
  92.                 $html .= '<span class="content_vote">';
  93.                 $html .= '<label class="unseen element-invisible" for="content_vote_' $row->id '">' JText::_('PLG_VOTE_LABEL''</label>';
  94.                 $html .= JHtml::_('select.genericlist'$options'user_rating'null'value''text''5''content_vote_' $row->id);
  95.                 $html .= '&#160;<input class="btn btn-mini" type="submit" name="submit_vote" value="' JText::_('PLG_VOTE_RATE''" />';
  96.                 $html .= '<input type="hidden" name="task" value="article.vote" />';
  97.                 $html .= '<input type="hidden" name="hitcount" value="0" />';
  98.                 $html .= '<input type="hidden" name="url" value="' htmlspecialchars($uri->toString()) '" />';
  99.                 $html .= JHtml::_('form.token');
  100.                 $html .= '</span>';
  101.                 $html .= '</form>';
  102.             }
  103.         }
  104.  
  105.         return $html;
  106.     }
  107. }

Documentation generated on Tue, 19 Nov 2013 15:18:18 +0100 by phpDocumentor 1.4.3