Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @version $Id: usratevote.php 12228 2009-06-21 02:01:44Z ian $
- * @package Joomla
- * @copyright Copyright (C) 2009 - 2010 uniquescience. All rights reserved.
- * @license GNU/GPL, see LICENSE.php
- * Joomla! is free software. This version may have been modified pursuant
- * to the GNU General Public License, and as distributed it includes or
- * is derivative of works licensed under the GNU General Public License or
- * other free or open source software licenses.
- * See COPYRIGHT.php for copyright notices and details.
- */
- // no direct access
- defined( '_JEXEC' ) or die( 'Restricted access' );
- //global $mainframe;
- //$mainframe->registerEvent( 'onAfterDisplayTitle', 'plgContentusratevote' );
- //$mainframe->registerEvent( 'onPrepareContent', 'plgContentusratevote' );
- /**
- * Tech Rating plugin
- * <b>Usage:</b>
- * <span class="system-usrate">{uniquescience-ratevote:rateVal}</span>
- */
- class plgContentUsratevote extends JPlugin
- {
- /**
- * Constructor
- *
- * @access protected
- * @param object $subject The object to observe
- * @param array $config An array that holds the plugin configuration
- * @since 1.5
- */
- public function __construct(& $subject, $config)
- {
- parent::__construct($subject, $config);
- $this->loadLanguage();
- }
- function onContentBeforeDisplay($context, &$row, &$params, $page=0 )
- {
- global $document, $path;
- // expression to search for
- $regex = "#<span([^>]*?)class=(\"|')system-usrate(\"|\')([^>]*?)>.*?</span>#iU";
- // Get Plugin info
- //$plugin =& JPluginHelper::getPlugin('content', 'usratevote');
- //$pluginParams = new JParameter( $plugin->params );
- $frontpageflag = trim($this->params->get('frontpageflag'));
- $ussitename = trim($this->params->get('ussitename'));
- $usratelink = trim($this->params->get('usratelink'));
- $innovaPermission = trim($this->params->get('usratevote')); // title
- $textcolor = trim($this->params->get('textcolor'));
- $bordercolor = trim($this->params->get('bordercolor'));
- $bgcolor = trim($this->params->get('bgcolor'));
- $usvotingcount = trim($this->params->get('usvotingcount'));
- $votetitle = trim($this->params->get('votetitle'));
- $allflag = trim($this->params->get('allflag'));
- $defaultrate = trim($this->params->get('defaultrate'));
- $textcolor = ($textcolor!="")?$textcolor:"#666666";
- $bordercolor = ($bordercolor!="")?$bordercolor:"#ccc";
- $bgcolor = ($bgcolor!="")?$bgcolor:"#ffffff";
- //JPlugin::loadLanguage( 'plg_content_usratevote' );
- //simple performance check to determine whether bot should process further
- if ( preg_match( "!class=(\"|')system-usrate!", $row->text ) === false ) {
- return true;
- }
- $db =& JFactory::getDBO();
- $view = JRequest::getCmd('view');
- if(!$page) {
- $page = 0;
- }
- $userLoginObj =& JFactory::getUser();
- $allow_vote_permission = false;
- if($innovaPermission == 'allow_all'){
- $allow_vote_permission = true;
- } elseif($innovaPermission == 'disallow_all') {
- $allow_vote_permission = false;
- } else {
- $innovagroupArray = array('Registered', 'Author', 'Editor', 'Publisher', 'Manager', 'Administrator', 'Super Administrator');
- $db_key = array_search($innovaPermission, $innovagroupArray);
- $sess_key = array_search(trim($userLoginObj->usertype), $innovagroupArray);
- if($db_key <= $sess_key) {
- $allow_vote_permission = true;
- }
- }
- // check whether plugin has been unpublished
- //if (!JPluginHelper::isEnabled('content', 'usratevote') || $params->get( 'intro_only' )|| $params->get( 'popup' ) || $view != 'article') {
- if (!JPluginHelper::isEnabled('content', 'usratevote') || ($frontpageflag=="no" && $view == "frontpage") ) {
- $row->text = preg_replace( $regex, '', $row->text );
- return;
- }
- $patternExtractVal = "#<span([^>]*?)class=(\"|')system-usrate(\"|')([^>]*?)>.*?:(.*?)\}</span>#iU";
- if(preg_match($patternExtractVal, $row->text, $matches)) {
- $ratingVal = $matches[5];
- $replaceStatus = true;
- } else {
- $ratingVal = $defaultrate;
- $replaceStatus = false;
- }
- $id = $row->id;
- $query = 'SELECT rating_sum, rating_count' .
- ' FROM #__content_rating' .
- ' WHERE content_id='.$id;
- $rating_sum = $ratingVal;
- $rating_count = 1;
- $db->setQuery($query);
- $result = $db->loadRowList();
- if(isset($result[0])) {
- $rating_row = $result[0];
- $rating_sum += (isset($rating_row[0]))?$rating_row[0]:0;
- $rating_count += (isset($rating_row[1]))?$rating_row[1]:0;
- }
- if($rating_count>0) {
- $ratingVal = round((($rating_sum/$rating_count)), 1);
- } else {
- $ratingVal = 0;
- }
- $linkratingText = (trim($usratelink) != "")?'<a href="'.$usratelink.'" class="usratevote">'.$ratingVal.'</a>':'<span class="usratevote_rt">'.$ratingVal.'</span>';
- $voteDivWidth = ($usvotingcount == 5)?"310px":"480px";
- $html = '';
- $html .= '
- <style>
- table.usratevote { margin: 5px 5px 0px 5px; border: 1px solid '.$bordercolor.'; width: 85px; text-align: center; color: '.$textcolor.'; position: relative;float:right;clear:left; background-color:'.$bgcolor.';}
- table.usratevote td { padding: 2px 5px 2px 5px; background-color:'.$bgcolor.'; }
- td.usratevote_td { border-bottom: 1px solid '.$bordercolor.'; color: '.$textcolor.'; background-color:'.$bgcolor.'; }
- div.usratevote { font-size: 10px; text-align: center; font-weight: normal; padding: 1px 0px 1px 0px; background-color:'.$bgcolor.'; }
- a.usratevote { font-size: 28px; font-weight: bold; color: '.$textcolor.'; }
- .usratevote_rt { font-size: 28px; font-weight: bold; color: '.$textcolor.'; }
- a.usratevote_sm { font-size: 12px; font-weight: normal; color: '.$textcolor.'; }
- .usratevote_vote { display: none; border: 1px solid '.$bordercolor.'; margin: 0px 5px 5px 5px; padding: 5px 5px 5px 5px; width:'.$voteDivWidth.'; background-color:'.$bgcolor.'; }
- .usratevote_form { margin: 0px; }
- </style>
- <script>
- function show_usratevote_vote_'.$id.'() {
- if(document.getElementById("usratevote_vote_'.$id.'")) {
- document.getElementById("usratevote_vote_'.$id.'").style.display = "block";
- }
- }
- function hideRate_'.$id.'(){
- if(document.getElementById("usratevote_vote_'.$id.'")) {
- document.getElementById("usratevote_vote_'.$id.'").style.display = "none";
- }
- }
- </script>
- <div id="mainContainer">
- <div>
- <table cellpadding="0" cellspacing="0" class="usratevote">
- <tr><td align="center" class="usratevote_td"><b>'.$ussitename.'</b></td></tr>
- <tr><td><span align="center" class="usratevote">'.$usratevote_title.'</span></td></tr>
- <tr><td><span align="center" class="usratevote">'.$linkratingText.'</span></td></tr>
- ';
- if($allow_vote_permission) {
- $uri = JFactory::getURI();
- $html .= '
- <tr><td>
- <div style="position:relative;">
- <div align="center" class="usratevote">
- <a href="javascript:void(0);" style="margin-left:12px;" onclick="return show_usratevote_vote_'.$id.'();" class="usratevote_sm">'.$votetitle.'</a>
- </div>
- <div id="subContainer" style="position:absolute; top:21px; right:-10px;">
- <form class="usratevote_form" id="frmRatevote" name="frmRatevote" method="post" action="'.$uri->toString().'">
- <div class="usratevote_vote" id="usratevote_vote_'.$id.'">
- <div><div style="position:absolute; right:10px; z-index:1000; top:2px;"><a href="javascript:void(0);" onClick="hideRate_'.$id.'();" class="usratevote_sm">Close</a></div></div>
- ';
- $headText = "<tr><td> </td>";
- $optionText = "<tr><td>".JText::_( 'Poor' )."</td>";
- if(isset($usvotingcount) && $usvotingcount>0) {
- for($i=1;$i<=$usvotingcount;$i++) {
- $headText .= "<td align='center'>".$i."</td>";
- $optionText .= "<td align='center'>".'<input type="radio" alt="vote '.$i.' star" name="user_rating" value="'.$i.'" />'."</td>";
- }
- }
- $headText .= "<td> </td><td> </td></tr>";
- $optionText .= "<td>".JText::_( 'Best' )."</td><td><input type='submit' name='submit_vote' value='". JText::_('Rate')."' /></td></tr>";
- $html .= '<table cellpadding="2px" border="0">'.$headText.$optionText.'</table>';
- $html .= '<input type="hidden" name="task" value="article.vote" />';
- $html .= '<input type="hidden" name="view" value="article" />';
- $html .= '<input type="hidden" name="option" value="com_content" />';
- $html .= '<input type="hidden" name="cid" value="'. $id .'" />';
- $html .= '<input type="hidden" name="id" value="'. $id .'" />';
- $html .= '<input type="hidden" name="url" value="'. $uri->toString( ) .'" />';
- $html .= JHtml::_('form.token');
- $html .= '
- </div>
- </form>
- </div>
- </div>
- </td></tr>';
- }
- $html .= '
- </table>
- </div>
- </div>
- ';
- // look for images in template if available
- $starImageOn = JHTML::_('image.site', 'rating_star.png', '/images/M_images/' );
- $starImageOff = JHTML::_('image.site', 'rating_star_blank.png', '/images/M_images/' );
- // find all instances of plugin and put in $matches
- $matches = array();
- if($replaceStatus) {
- $row->text = preg_replace( $regex, $html, $row->text, 1);
- } elseif($allflag == "yes") {
- $row->text = preg_replace( $regex, "", $row->text, 1);
- $row->text = $html.$row->text;
- }
- return $html;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement