Помогите изменить плагин голосования, чтобы вместо пяти звезд выводилось только один. В данном коде вместо звезд цифра 1, никак не могу убрать остальные четыре единицы. Отблагодарю рублем кто поможет Вот код: PHP: <?php // No direct access defined('_JEXEC') or die; jimport('joomla.plugin.plugin'); class plgContentExtraVote extends JPlugin { protected $article_id; public function __construct(& $subject, $config) { parent::__construct($subject, $config); $this->loadLanguage(); $this->view = JRequest::getCmd('view'); } public function onContentBeforeDisplay($context, &$article, &$params, $limitstart = 1) { if (strpos($context, 'com_content') !== false) { $this->article_id = $article->id; $this->ExtraVotePrepare($article, $params); if ( $this->params->get('display') == 0 ) { $hide = $this->params->get('hide', 1); if ( $hide != 1 || $this->view == 'article' ) { $article->xid = 0; return $this->ContentExtraVote($article, $params); } } } } protected function ContentExtraVote(&$article, &$params) { $rating_count=$rating_sum=0; $html=''; if ($params->get('show_vote')) { $db = JFactory::getDBO(); $query='SELECT * FROM #__content_extravote WHERE content_id='.$this->article_id.' AND extra_id = 0'; $db->setQuery($query); $vote=$db->loadObject(); if($vote) { $rating_sum = $vote->rating_sum; $rating_count = intval($vote->rating_count); } $html .= $this->plgContentExtraVoteStars( $this->article_id, $rating_sum, $rating_count, $article->xid ); } return $html; } protected function plgContentExtraVoteStars( $id, $rating_sum, $rating_count, $xid ) { $document = JFactory::getDocument(); if ( $this->params->get('css', 1) ) : $document->addStyleSheet(JURI::root(true).'/plugins/content/extravote/assets/extravote.css'); endif; $document->addScript(JURI::root(true).'/plugins/content/extravote/assets/extravote.js'); global $plgContentExtraVoteAddScript; $show_counter = $this->params->get('show_counter',1); $show_rating = $this->params->get('show_rating',1); $rating_mode = $this->params->get('rating_mode', 1); $show_unrated = $this->params->get('show_unrated',1); $rating = 0; if(!$plgContentExtraVoteAddScript){ $document->addScriptDeclaration(" var ev_basefolder = '".JURI::base(true)."'; var extravote_text=Array('". JTEXT::_('PLG_CONTENT_EXTRAVOTE_MESSAGE_NO_AJAX')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_MESSAGE_LOADING')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_MESSAGE_THANKS')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_MESSAGE_LOGIN')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_MESSAGE_RATED')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_LABEL_VOTES')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_LABEL_VOTE')."','". JTEXT::_('PLG_CONTENT_EXTRAVOTE_LABEL_RATING'). "'); "); $plgContentExtraVoteAddScript = 1; } if( $rating_count!=0 ) { $rating = ($rating_sum / intval( $rating_count )); } elseif( $show_unrated == 0 ) { $show_counter = -1; $show_rating = -1; } $container = 'div'; $class = 'extravote'; if( (int)$xid ) { if ( $show_counter == 2 ) $show_counter = 0; if ( $show_rating == 2 ) $show_rating = 0; $container = 'span'; $class = 'extravote-small'; } else { if ( $show_counter == 3 ) $show_counter = 0; if ( $show_rating == 3 ) $show_rating = 0; } $stars = $this->params->get('stars',2); $spans = ''; for ($i=0,$j=5/$stars; $i<$stars; $i++,$j+=5/$stars) : $spans .= " <span class=\"extravote-star\"><a href=\"javascript:void(null)\" onclick=\"javascript:JVXVote(".$id.",".$j.",".$rating_sum.",".$rating_count.",'".$xid."',".$show_counter.",".$show_rating.",".$rating_mode.");\" title=\"".JTEXT::_('PLG_CONTENT_EXTRAVOTE_RATING_'.($j*10).'_OUT_OF_5')."\" class=\"ev-".($j*10)."-stars\">1</a></span>"; endfor; $html = " <".$container." class=\"".$class."\"> <span class=\"extravote-stars\"> <span id=\"rating_".$id."_".$xid."\" class=\"current-rating\" style=\"width:".round($rating*20)."%;\"></span>" .$spans." </span> <span class=\"extravote-info\" id=\"extravote_".$id."_".$xid."\">"; if ( $show_rating > 0 ) { if ( $rating_mode == 0 ) { $rating = round($rating*20) . '%'; } else { $rating = number_format($rating,2); } $html .= JTEXT::sprintf('PLG_CONTENT_EXTRAVOTE_LABEL_RATING', $rating); } if ( $show_counter > 0 ) { if($rating_count!=1) { $html .= JTEXT::sprintf('PLG_CONTENT_EXTRAVOTE_LABEL_VOTES', $rating_count); } else { $html .= JTEXT::sprintf('PLG_CONTENT_EXTRAVOTE_LABEL_VOTE', $rating_count); } } $html .="</span>"; $html .=" </".$container.">"; return $html; } protected function ExtraVotePrepare( $article, &$params ) { if (isset($this->article_id)) { $extra = $this->params->get('extra', 1); $main = $this->params->get('main', 1); if ( $extra != 0 ) { $regex = "#{extravote\s*([0-9]+)}#s"; if ( $this->view != 'article' ) { if ( $extra == 2 ) { $article->introtext = preg_replace( $regex, '', $article->introtext ); } else { $article->introtext = preg_replace_callback( $regex, array($this,'plgContentExtraVoteReplacer'), $article->introtext ); } } else { // $this->article_id = $article->id; $article->text = preg_replace_callback( $regex, array($this,'plgContentExtraVoteReplacer'), $article->text ); } } if ( $main != 0 ) { if ( $main == 2 && $this->view != 'article') { $article->introtext = preg_replace( '#{mainvote}#', '', $article->introtext ); } else { $this->article_id = $article->id; if ( $this->view == 'article' ) { $article->text = preg_replace_callback( '#{mainvote}#', array($this,'plgContentExtraVoteReplacer'), $article->text ); } else { $article->introtext = preg_replace_callback( '#{mainvote}#', array($this,'plgContentExtraVoteReplacer'), $article->introtext ); } } } if ( $this->params->get('display') == 1 ) { $article->xid = 0; if ( $this->view == 'article' ) { $article->text .= $this->ContentExtraVote($article, $params); } elseif ( $this->params->get('hide') == 0 ) { $article->introtext .= $this->ContentExtraVote($article, $params); } } } } protected function plgContentExtraVoteReplacer(&$matches ) { $db = JFactory::getDBO(); $xid = 0; if (isset($matches[1])) { $xid = (int)$matches[1]; } $cid = 0; if ( $this->params->get('article_id') || $xid == 0 ) { $cid = $this->article_id; } $rating_sum = 0; $rating_count = 0; $db->setQuery('SELECT * FROM #__content_extravote WHERE content_id='.(int)$cid.' AND extra_id='.(int)$xid); $vote = $db->loadObject(); if($vote) { if($vote->rating_count!=0) $rating_sum = $vote->rating_sum; $rating_count = intval($vote->rating_count); } if ( $xid == 0 ) : global $extravote_mainvote; $extravote_mainvote .= 'x'; $xid = $extravote_mainvote; endif; return $this->plgContentExtraVoteStars( $cid, $rating_sum, $rating_count, $xid ); } }
debug http://phpfaq.ru/debug https://netbeans.org/kb/docs/php/debugging_ru.html https://php.ru/forum/threads/howto-...i-po-shagam-i-s-kartinkami.58974/#post-474550 --- Добавлено --- @Shuhra попробуй ещё посмотреть на окружающий код этих "единиц", и потом посмотреть где этот html формируется, может в другом файле.
Все формируется в этом файле, так-как все его касающиеся файлы тупо удалял и все оставалось также - пять едениц (1 1 1 1 1 1 (черная единица количество проголосовавших) ) Вот кусок кода, где можно заменить однерку допустим на ПРИВЕТ - соответственно выйдет так - ПРИВЕТ ПРИВЕТ ПРИВЕТ ПРИВЕТ ПРИВЕТ 1 $stars = $this->params->get('stars',2); $spans = ''; for ($i=0,$j=5/$stars; $i<$stars; $i++,$j+=5/$stars) : $spans .= " <span class=\"extravote-star\"><a href=\"javascript:void(null)\" onclick=\"javascript:JVXVote(".$id.",".$j.",".$rating_sum.",".$rating_count.",'".$xid."',".$show_counter.",".$show_rating.",".$rating_mode.");\" title=\"".JTEXT::_('PLG_CONTENT_EXTRAVOTE_RATING_'.($j*10).'_OUT_OF_5')."\" class=\"ev-".($j*10)."-stars\">1</a></span>";
Тебе надо вместо пяти повторений было одно? В коде что я процитировал замечаешь ответ на свой вопрос?
Пробовал менять неоднократно. Делал так for ($i=0,$j=1/$stars; $i<$stars; $i++,$j+=1/$stars) и ничего не меняется
Тогда удали цикл полностью с его содержимым и посмотри если пропадёт вывод рейтинга. Так можешь методом тыка удалять по частям и смотреть что за что отвечает.
@Shuhra Могу перенести тему в раздел free-lance, вот за деньги человеку будет проще зайти на твой сервер и быстро по своему опыту на живой системе всё сделать как тебе надо. Вместо того чтобы мы тут гадали.
@Shuhra в google chrome можно делать отладку html, css, js. Но PHP работает на севере и нужен например xdebug и ide для удобства. В моём первом сообщении посмотри три ссылки, там всё про отладку, вручную и с помощью IDE.
@mr.akv Разрешите я бесплатно помогу? Все же там совсем совсем чуть-чуть поправить. Не стал писать решение, т.к. Вы уже предложили свои услуги.
Внимательнее! Вы делаете не то, что нужно. И так смотря по вашему коду я его и взял. Если запустить пример мы увидим PHP: $stars = 5; // количество выбранных звезд for($i = 0, $j = 5 / $stars; $i < $stars; $i++, $j+=5 / $stars) { echo nl2br($i . ' - ' . $j * 10 . ' '); } Вывод: 0 - 10 1 - 20 2 - 30 3 - 40 4 - 50 Следовательно $j рейтинг. Собственно загвостка тут $i < $stars; за место $stars нужно поставить 1 еденицу, так как 0 < 1 выведит одну звезду, даже если выбрано 5 каким-то странным образом
@rodent90 جزاك الله خير , что значит - Да воздаст тебе Аллах только благое! Получилось - 1 1 (голоса тоже считаются исправно) Только вот друг еще одна загвоздка появилась, может поможешь: Включаю стили и появляются 5 звезд ( ну вместо тех однерок). Только теперь вместо 5 активных звезд - активная только 1. Как убрать остальные четыре неактивные звезды? P.S. Закрепляю изображение звезды - изображение одно. Режима три - без голоса, при наведении, проголосовали. Одно изображение - получается оно двигается вверх вниз, как-то так наверно.
<span class="extravote-stars"> <span id="rating_5_0" class="current-rating" style="width:20%;"></span> <span class="extravote-star"><a href="javascript:void(null)" onclick="javascript:JVXVote(5,1,3,3,'0',1,0,1);" title="1 из 5" class="ev-10-stars">1</a></span> </span>
Картинка одна, только она размножается в 5 .extravote-stars, .extravote-star a:hover, .extravote-stars .current-rating { background-image: url(../images/star.png)!important; background-color: transparent!important; background-repeat: repeat-x!important; } .extravote-stars { font-size: 1em; overflow: hidden; width: 125px; } .extravote-stars, .extravote-star a, .extravote-info, .extravote-stars .current-rating { height: 25px; line-height: 25px; } .extravote-stars, .extravote-info { display: inline-block; margin: 0!important; padding: 0!important; position: relative; vertical-align: middle; --- Добавлено --- Сейчас показывает так * * * * * 3