Advertisement
shairva

joomla plugin

Feb 12th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. <?php
  2. /**
  3. * @version $Id: usratevote.php 12228 2009-06-21 02:01:44Z ian $
  4. * @package Joomla
  5. * @copyright Copyright (C) 2009 - 2010 uniquescience. All rights reserved.
  6. * @license GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13.  
  14. // no direct access
  15. defined( '_JEXEC' ) or die( 'Restricted access' );
  16.  
  17. //global $mainframe;
  18. //$mainframe->registerEvent( 'onAfterDisplayTitle', 'plgContentusratevote' );
  19. //$mainframe->registerEvent( 'onPrepareContent', 'plgContentusratevote' );
  20.  
  21. /**
  22. * Tech Rating plugin
  23. * <b>Usage:</b>
  24. * <span class="system-usrate">{uniquescience-ratevote:rateVal}</span>
  25. */
  26.  
  27. class plgContentUsratevote extends JPlugin
  28. {
  29. /**
  30. * Constructor
  31. *
  32. * @access protected
  33. * @param object $subject The object to observe
  34. * @param array $config An array that holds the plugin configuration
  35. * @since 1.5
  36. */
  37. public function __construct(& $subject, $config)
  38. {
  39. parent::__construct($subject, $config);
  40. $this->loadLanguage();
  41. }
  42.  
  43. function onContentBeforeDisplay($context, &$row, &$params, $page=0 )
  44. {
  45. global $document, $path;
  46. // expression to search for
  47. $regex = "#<span([^>]*?)class=(\"|')system-usrate(\"|\')([^>]*?)>.*?</span>#iU";
  48.  
  49. // Get Plugin info
  50. //$plugin =& JPluginHelper::getPlugin('content', 'usratevote');
  51. //$pluginParams = new JParameter( $plugin->params );
  52. $frontpageflag = trim($this->params->get('frontpageflag'));
  53. $ussitename = trim($this->params->get('ussitename'));
  54. $usratelink = trim($this->params->get('usratelink'));
  55. $innovaPermission = trim($this->params->get('usratevote')); // title
  56. $textcolor = trim($this->params->get('textcolor'));
  57. $bordercolor = trim($this->params->get('bordercolor'));
  58. $bgcolor = trim($this->params->get('bgcolor'));
  59. $usvotingcount = trim($this->params->get('usvotingcount'));
  60. $votetitle = trim($this->params->get('votetitle'));
  61. $allflag = trim($this->params->get('allflag'));
  62. $defaultrate = trim($this->params->get('defaultrate'));
  63.  
  64. $textcolor = ($textcolor!="")?$textcolor:"#666666";
  65. $bordercolor = ($bordercolor!="")?$bordercolor:"#ccc";
  66. $bgcolor = ($bgcolor!="")?$bgcolor:"#ffffff";
  67. //JPlugin::loadLanguage( 'plg_content_usratevote' );
  68.  
  69. //simple performance check to determine whether bot should process further
  70. if ( preg_match( "!class=(\"|')system-usrate!", $row->text ) === false ) {
  71. return true;
  72. }
  73. $db =& JFactory::getDBO();
  74. $view = JRequest::getCmd('view');
  75.  
  76. if(!$page) {
  77. $page = 0;
  78. }
  79. $userLoginObj =& JFactory::getUser();
  80. $allow_vote_permission = false;
  81. if($innovaPermission == 'allow_all'){
  82. $allow_vote_permission = true;
  83. } elseif($innovaPermission == 'disallow_all') {
  84. $allow_vote_permission = false;
  85. } else {
  86. $innovagroupArray = array('Registered', 'Author', 'Editor', 'Publisher', 'Manager', 'Administrator', 'Super Administrator');
  87. $db_key = array_search($innovaPermission, $innovagroupArray);
  88. $sess_key = array_search(trim($userLoginObj->usertype), $innovagroupArray);
  89. if($db_key <= $sess_key) {
  90. $allow_vote_permission = true;
  91. }
  92. }
  93. // check whether plugin has been unpublished
  94. //if (!JPluginHelper::isEnabled('content', 'usratevote') || $params->get( 'intro_only' )|| $params->get( 'popup' ) || $view != 'article') {
  95. if (!JPluginHelper::isEnabled('content', 'usratevote') || ($frontpageflag=="no" && $view == "frontpage") ) {
  96. $row->text = preg_replace( $regex, '', $row->text );
  97. return;
  98. }
  99. $patternExtractVal = "#<span([^>]*?)class=(\"|')system-usrate(\"|')([^>]*?)>.*?:(.*?)\}</span>#iU";
  100. if(preg_match($patternExtractVal, $row->text, $matches)) {
  101. $ratingVal = $matches[5];
  102. $replaceStatus = true;
  103. } else {
  104. $ratingVal = $defaultrate;
  105. $replaceStatus = false;
  106. }
  107. $id = $row->id;
  108.  
  109. $query = 'SELECT rating_sum, rating_count' .
  110. ' FROM #__content_rating' .
  111. ' WHERE content_id='.$id;
  112. $rating_sum = $ratingVal;
  113. $rating_count = 1;
  114. $db->setQuery($query);
  115. $result = $db->loadRowList();
  116. if(isset($result[0])) {
  117. $rating_row = $result[0];
  118. $rating_sum += (isset($rating_row[0]))?$rating_row[0]:0;
  119. $rating_count += (isset($rating_row[1]))?$rating_row[1]:0;
  120. }
  121. if($rating_count>0) {
  122. $ratingVal = round((($rating_sum/$rating_count)), 1);
  123. } else {
  124. $ratingVal = 0;
  125. }
  126.  
  127. $linkratingText = (trim($usratelink) != "")?'<a href="'.$usratelink.'" class="usratevote">'.$ratingVal.'</a>':'<span class="usratevote_rt">'.$ratingVal.'</span>';
  128.  
  129. $voteDivWidth = ($usvotingcount == 5)?"310px":"480px";
  130. $html = '';
  131. $html .= '
  132. <style>
  133. 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.';}
  134. table.usratevote td { padding: 2px 5px 2px 5px; background-color:'.$bgcolor.'; }
  135. td.usratevote_td { border-bottom: 1px solid '.$bordercolor.'; color: '.$textcolor.'; background-color:'.$bgcolor.'; }
  136. div.usratevote { font-size: 10px; text-align: center; font-weight: normal; padding: 1px 0px 1px 0px; background-color:'.$bgcolor.'; }
  137. a.usratevote { font-size: 28px; font-weight: bold; color: '.$textcolor.'; }
  138. .usratevote_rt { font-size: 28px; font-weight: bold; color: '.$textcolor.'; }
  139. a.usratevote_sm { font-size: 12px; font-weight: normal; color: '.$textcolor.'; }
  140. .usratevote_vote { display: none; border: 1px solid '.$bordercolor.'; margin: 0px 5px 5px 5px; padding: 5px 5px 5px 5px; width:'.$voteDivWidth.'; background-color:'.$bgcolor.'; }
  141. .usratevote_form { margin: 0px; }
  142. </style>
  143. <script>
  144. function show_usratevote_vote_'.$id.'() {
  145. if(document.getElementById("usratevote_vote_'.$id.'")) {
  146. document.getElementById("usratevote_vote_'.$id.'").style.display = "block";
  147. }
  148. }
  149. function hideRate_'.$id.'(){
  150. if(document.getElementById("usratevote_vote_'.$id.'")) {
  151. document.getElementById("usratevote_vote_'.$id.'").style.display = "none";
  152. }
  153. }
  154. </script>
  155. <div id="mainContainer">
  156. <div>
  157. <table cellpadding="0" cellspacing="0" class="usratevote">
  158. <tr><td align="center" class="usratevote_td"><b>'.$ussitename.'</b></td></tr>
  159. <tr><td><span align="center" class="usratevote">'.$usratevote_title.'</span></td></tr>
  160. <tr><td><span align="center" class="usratevote">'.$linkratingText.'</span></td></tr>
  161. ';
  162. if($allow_vote_permission) {
  163. $uri = JFactory::getURI();
  164. $html .= '
  165. <tr><td>
  166. <div style="position:relative;">
  167. <div align="center" class="usratevote">
  168. <a href="javascript:void(0);" style="margin-left:12px;" onclick="return show_usratevote_vote_'.$id.'();" class="usratevote_sm">'.$votetitle.'</a>
  169. </div>
  170. <div id="subContainer" style="position:absolute; top:21px; right:-10px;">
  171. <form class="usratevote_form" id="frmRatevote" name="frmRatevote" method="post" action="'.$uri->toString().'">
  172. <div class="usratevote_vote" id="usratevote_vote_'.$id.'">
  173. <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>
  174. ';
  175. $headText = "<tr><td>&nbsp;</td>";
  176. $optionText = "<tr><td>".JText::_( 'Poor' )."</td>";
  177. if(isset($usvotingcount) && $usvotingcount>0) {
  178. for($i=1;$i<=$usvotingcount;$i++) {
  179. $headText .= "<td align='center'>".$i."</td>";
  180. $optionText .= "<td align='center'>".'<input type="radio" alt="vote '.$i.' star" name="user_rating" value="'.$i.'" />'."</td>";
  181. }
  182. }
  183. $headText .= "<td>&nbsp;</td><td>&nbsp;</td></tr>";
  184. $optionText .= "<td>".JText::_( 'Best' )."</td><td><input type='submit' name='submit_vote' value='". JText::_('Rate')."' /></td></tr>";
  185. $html .= '<table cellpadding="2px" border="0">'.$headText.$optionText.'</table>';
  186. $html .= '<input type="hidden" name="task" value="article.vote" />';
  187. $html .= '<input type="hidden" name="view" value="article" />';
  188. $html .= '<input type="hidden" name="option" value="com_content" />';
  189. $html .= '<input type="hidden" name="cid" value="'. $id .'" />';
  190. $html .= '<input type="hidden" name="id" value="'. $id .'" />';
  191. $html .= '<input type="hidden" name="url" value="'. $uri->toString( ) .'" />';
  192. $html .= JHtml::_('form.token');
  193. $html .= '
  194. </div>
  195. </form>
  196. </div>
  197. </div>
  198. </td></tr>';
  199. }
  200. $html .= '
  201. </table>
  202. </div>
  203. </div>
  204.  
  205. ';
  206.  
  207.  
  208. // look for images in template if available
  209. $starImageOn = JHTML::_('image.site', 'rating_star.png', '/images/M_images/' );
  210. $starImageOff = JHTML::_('image.site', 'rating_star_blank.png', '/images/M_images/' );
  211.  
  212. // find all instances of plugin and put in $matches
  213. $matches = array();
  214. if($replaceStatus) {
  215. $row->text = preg_replace( $regex, $html, $row->text, 1);
  216. } elseif($allflag == "yes") {
  217. $row->text = preg_replace( $regex, "", $row->text, 1);
  218. $row->text = $html.$row->text;
  219. }
  220.  
  221. return $html;
  222. }
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement