Dismiss Notice
ВАШИ ПРАВА ОГРАНИЧЕНЫ!

Зарегистрируйтесь на форуме, чтобы стать полноценным участником сообщества!

Вопрос? 10 звёзд dle 12.0 в чём может быть проблема?

Discussion in 'Вопросы- ответы' started by axiles, Oct 14, 2017.

14.10.17 в 20:35
15.10.17 в 14:17
5
1,331
0
  1. TopicStarter Overlay
    axiles

    axiles Посетитель

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Приветствую жителей форума зерокулпро, решил поставить себе рейтинг из 10 звёзд, но столкнулся с проблемой, рейтинг после нажатия на звезду остаётся в активном состоянии (можно ещё нажимать, хотя больше и не засчитывается), отображается не всегда корректно, например при рейтинге = 7 закрашиваются не все 7 звёзд. Может кто подскажет в чём проблема? Код такой:
    Code:
    function ShowRating($id, $rating, $vote_num, $allow = true) {
        global $lang, $config;
    
        if( !$config['rating_type'] ) {
            
            if( $rating AND $vote_num ) $rating = round( ($rating / $vote_num), 1 );
        else $rating = 0;
        $rating1 = str_replace( ".", " , ", $rating );
        $rating2 = str_replace( ",", "", $rating );
        
            if( ! $allow ) {
            
            $rated = <<<HTML
    <div class="rating" style="float:left;">
            <ul class="unit-rating">
            <li class="current-rating" style="width:{$rating2}%;">{$rating2}</li>
            </ul>
            </div>
    <td class="ratestats"><div itemprop="aggregateRating" itemscope="" itemtype="http://schema.org/AggregateRating">
                                                            Рейтинг аниме: <b itemprop="ratingValue">{$rating1}</b>
                                                            <br>
                                                            <small>Голосовало {$vote_num} отаку</small>
                                                            <span itemprop="ratingCount" style="display: none;">{$vote_num}</span>
                                                            <span itemprop="bestRating" style="display: none;">10</span>
                                                            <br>
                                                        </div></td>
    HTML;
            
            return $rated;
        }
        
            $rated .= <<<HTML
    <div class="rating" style="float:left;">
            <ul class="unit-rating">
            <li class="current-rating" style="width:{$rating2}%;">{$rating2}</li>
            <li><a href="#" title="1" class="r1-unit" onclick="doRate('1', '{$id}'); return false;">1</a></li>
            <li><a href="#" title="2" class="r2-unit" onclick="doRate('2', '{$id}'); return false;">2</a></li>
            <li><a href="#" title="3" class="r3-unit" onclick="doRate('3', '{$id}'); return false;">3</a></li>
            <li><a href="#" title="4" class="r4-unit" onclick="doRate('4', '{$id}'); return false;">4</a></li>
            <li><a href="#" title="5" class="r5-unit" onclick="doRate('5', '{$id}'); return false;">5</a></li>
            <li><a href="#" title="6" class="r6-unit" onclick="doRate('6', '{$id}'); return false;">6</a></li>
            <li><a href="#" title="7" class="r7-unit" onclick="doRate('7', '{$id}'); return false;">7</a></li>
            <li><a href="#" title="8" class="r8-unit" onclick="doRate('8', '{$id}'); return false;">8</a></li>
            <li><a href="#" title="9" class="r9-unit" onclick="doRate('9', '{$id}'); return false;">9</a></li>
            <li><a href="#" title="10" class="r10-unit" onclick="doRate('10', '{$id}'); return false;">10</a></li>
            </ul>
            </div></div>
    <td class="ratestats"><div itemprop="aggregateRating" itemscope="" itemtype="http://schema.org/AggregateRating">
                                                            Рейтинг аниме: <b itemprop="ratingValue">{$rating1}</b>
                                                            <br>
                                                            <small>Голосовало {$vote_num} отаку</small>
                                                            <span itemprop="ratingCount" style="display: none;">{$vote_num}</span>
                                                            <span itemprop="bestRating" style="display: none;">10</span>
                                                            <br>
                                                        </div></td>
    HTML;
        
            return $rated;
    
        } elseif ($config['rating_type'] == "1") {
            
            if( $rating < 0 ) $rating = 0;
            
            if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplus ignore-select\" >{$rating}</span></span>";
            else $rated = "<span class=\"ratingtypeplus ignore-select\" >{$rating}</span>";
            
            return $rated;
        
        } elseif ($config['rating_type'] == "2") {
            
            $extraclass = "ratingzero";
            
            if( $rating < 0 ) {
                $extraclass = "ratingminus";
            }
            
            if( $rating > 0 ) {
                $extraclass = "ratingplus";
                $rating = "+".$rating;
            }
            
            if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span></span>";
            else $rated = "<span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span>";
            
            return $rated;
            
        }
        
    } 
     
  2. ettochno

    ettochno PRO Users

    Messages:
    370
    Likes Received:
    49
    Best Answers:
    1
    Votes: 1
    • Нравится Нравится x 1
  3. byroot

    byroot Забанен

    Messages:
    12,295
    Likes Received:
    4,495
    Best Answers:
    54
    axiles скорее всего проблема в стилях, надо увидеть пациента чтобы понять что может быть виной неверному отображению рейтинга.
     
  4. TopicStarter Overlay
    axiles

    axiles Посетитель

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Видимо проблема была в этой строчке

    Code:
    $rating2 = str_replace( ",", "", $rating );
    Заменил на:

    Code:
    $rating2 = str_replace( ",", "", $rating * 10 );
    Проблема решилась.

    А кто-нибудь знает как это сделать на ajax, чтобы страницу не перезагружать? И опять же звёздочки постоянно в активном состоянии после выставления рейтинга.
     
  5. TopicStarter Overlay
    axiles

    axiles Посетитель

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Короче почти всё решил. Значит для для того, чтобы рейтинг 10 звёзд на DLE 12.0 обновлялся в реальном времени я (хер знает насколько всё правильно или неправильно, но всё работает) сделал так:

    В файле \engine\ajax\rating.php находим:

    Code:
    if( $go_rate > 5 or $go_rate < 1 ) $go_rate = false;
    меняем цифру 5 на 10

    В файле /engine/modules/functions.php находим:

    Code:
    function ShowRating($id, $rating, $vote_num, $allow = true) {
        global $lang, $config;
    
        if( !$config['rating_type'] ) {
           
            if( $rating AND $vote_num ) $rating = round( ($rating / $vote_num), 0 );
            else $rating = 0;
           
            if ($rating < 0 ) $rating = 0;
    
            $rating = $rating * 20;
       
            if( !$allow ) {
           
                $rated = <<<HTML
    <div class="rating">
            <ul class="unit-rating">
            <li class="current-rating" style="width:{$rating}%;">{$rating}</li>
            </ul>
    </div>
    HTML;
           
                return $rated;
            }
       
            $rated = <<<HTML
    <div id='ratig-layer-{$id}'><div class="rating">
            <ul class="unit-rating">
            <li class="current-rating" style="width:{$rating}%;">{$rating}</li>
            <li><a href="#" title="{$lang['useless']}" class="r1-unit" onclick="doRate('1', '{$id}'); return false;">1</a></li>
            <li><a href="#" title="{$lang['poor']}" class="r2-unit" onclick="doRate('2', '{$id}'); return false;">2</a></li>
            <li><a href="#" title="{$lang['fair']}" class="r3-unit" onclick="doRate('3', '{$id}'); return false;">3</a></li>
            <li><a href="#" title="{$lang['good']}" class="r4-unit" onclick="doRate('4', '{$id}'); return false;">4</a></li>
            <li><a href="#" title="{$lang['excellent']}" class="r5-unit" onclick="doRate('5', '{$id}'); return false;">5</a></li>
            </ul>
    </div></div>
    HTML;
       
            return $rated;
    
        } elseif ($config['rating_type'] == "1") {
           
            if( $rating < 0 ) $rating = 0;
           
            if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplus ignore-select\" >{$rating}</span></span>";
            else $rated = "<span class=\"ratingtypeplus ignore-select\" >{$rating}</span>";
           
            return $rated;
       
        } elseif ($config['rating_type'] == "2") {
           
            $extraclass = "ratingzero";
           
            if( $rating < 0 ) {
                $extraclass = "ratingminus";
            }
           
            if( $rating > 0 ) {
                $extraclass = "ratingplus";
                $rating = "+".$rating;
            }
           
            if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span></span>";
            else $rated = "<span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span>";
           
            return $rated;
           
        }
       
    }
    Меняем на:

    Code:
    function ShowRating($id, $rating, $vote_num, $allow = true) {
        global $lang, $config;
    
        if( !$config['rating_type'] ) {
           
        if( $rating AND $vote_num ) $rating = round( ($rating / $vote_num), 1 );
        else $rating = 0;
        $rating1 = str_replace( ".", " , ", $rating );
        $rating2 = str_replace( ",", "", $rating * 10 );
       
            if( ! $allow ) {
           
            $rated = <<<HTML
            <ul class="unit-rating">
            <li class="current-rating" style="width:{$rating2}%;">{$rating2}</li>
            </ul>
    HTML;
           
            return $rated;
        }
       
            $rated .= <<<HTML
    <div class="ratestats" id='ratig-layer-{$id}'>
            <ul class="unit-rating">
            <li class="current-rating" style="width:{$rating2}%;">{$rating2}</li>
            <li><a href="#" title="1" class="r1-unit" onclick="doRate('1', '{$id}'); return false;">1</a></li>
            <li><a href="#" title="2" class="r2-unit" onclick="doRate('2', '{$id}'); return false;">2</a></li>
            <li><a href="#" title="3" class="r3-unit" onclick="doRate('3', '{$id}'); return false;">3</a></li>
            <li><a href="#" title="4" class="r4-unit" onclick="doRate('4', '{$id}'); return false;">4</a></li>
            <li><a href="#" title="5" class="r5-unit" onclick="doRate('5', '{$id}'); return false;">5</a></li>
            <li><a href="#" title="6" class="r6-unit" onclick="doRate('6', '{$id}'); return false;">6</a></li>
            <li><a href="#" title="7" class="r7-unit" onclick="doRate('7', '{$id}'); return false;">7</a></li>
            <li><a href="#" title="8" class="r8-unit" onclick="doRate('8', '{$id}'); return false;">8</a></li>
            <li><a href="#" title="9" class="r9-unit" onclick="doRate('9', '{$id}'); return false;">9</a></li>
            <li><a href="#" title="10" class="r10-unit" onclick="doRate('10', '{$id}'); return false;">10</a></li>
            </ul>
    <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"><div class="reiting">
                                                            Рейтинг аниме: <b itemprop="ratingValue">{$rating1}</b>
                                                            <br>
                                                            <small>Голосовало {$vote_num} отаку</small>
                                                            <span itemprop="ratingCount" style="display: none;">{$vote_num}</span>
                                                            <span itemprop="bestRating" style="display: none;">10</span>
                                                            <br>
                                                        </div></div></div>
    HTML;
       
            return $rated;
       
        } elseif ($config['rating_type'] == "2") {
           
            $extraclass = "ratingzero";
           
            if( $rating < 0 ) {
                $extraclass = "ratingminus";
            }
           
            if( $rating > 0 ) {
                $extraclass = "ratingplus";
                $rating = "+".$rating;
            }
           
            if( $allow ) $rated = "<span id=\"ratig-layer-{$id}\" class=\"ignore-select\"><span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span></span>";
            else $rated = "<span class=\"ratingtypeplusminus ignore-select {$extraclass}\" >{$rating}</span>";
           
            return $rated;
           
        }
       
    }
    Файл engine.css:

    Code:
    /*--- RATING ---*/
    .ratestats { color: rgb(94, 94, 94); font-size: 18px; vertical-align: top;}
    .ratestats small { font-size: 10px; }
    .ratebar { width: 580px; }
    .reiting { float: left; margin: -32px; margin-left: 390px;}
    .fullrating b { color: rgb(108, 27, 109); }
    .fullrating { font-family: Verdana,Arial,Helvetica,sans-serif; margin-top: 8px; box-shadow: 3px 3px 3px 0 rgba(0,0,0,0.1); font-size: 100%; line-height: 1em; color: rgb(57, 57, 57); background: rgb(253, 253, 253) none repeat scroll 0% 0%; border-width: 1px; border-style: solid; border-color: rgb(233, 232, 232) rgb(233, 232, 232) rgb(241, 240, 240); -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none; -moz-border-left-colors: none; border-image: none; padding: 5px; }
    
    .rating {
    color: black;
    display: block;
    font-size: 10px;
    font-family: tahoma;
    height: 36px;
    margin: 0;
    font-weight: bold;
    }
    .unit-rating { list-style: outside none none; margin: 0px; padding: 0px; width: 380px; height: 38px; position: relative; background: rgba(0, 0, 0, 0) url(../dleimages/ratingv.png) repeat-x scroll 0px -1px; }
    .unit-rating li { text-indent: -90000px; padding: 0px; margin: 0px; float: left; }
    .unit-rating li a { display: block; width: 38px; height: 39px; text-decoration: none; text-indent: -9000px; z-index: 39; position: absolute; padding: 0px; }
    .unit-rating li a:hover { background: rgba(0, 0, 0, 0) url(../dleimages/ratingv.png) repeat scroll 0px -39px; z-index: 2; left: 0px; }
    .unit-rating li.current-rating { background: rgba(0, 0, 0, 0) url(../dleimages/ratingv.png) repeat scroll 0px -78px; position: absolute; height: 39px; display: block; text-indent: -9000px; z-index: 1; }
    
    .unit-rating a.r1-unit { left: 0px; }
    .unit-rating a.r1-unit:hover { width: 38px; }
    .unit-rating a.r2-unit { left: 38px; }
    .unit-rating a.r2-unit:hover { width: 76px; }
    .unit-rating a.r3-unit { left: 76px; }
    .unit-rating a.r3-unit:hover { width: 114px; }
    .unit-rating a.r4-unit { left: 114px; }
    .unit-rating a.r4-unit:hover { width: 152px; }
    .unit-rating a.r5-unit { left: 152px; }
    .unit-rating a.r5-unit:hover { width: 190px; }
    .unit-rating a.r6-unit { left: 190px; }
    .unit-rating a.r6-unit:hover { width: 228px; }
    .unit-rating a.r7-unit { left: 228px; }
    .unit-rating a.r7-unit:hover { width: 266px; }
    .unit-rating a.r8-unit { left: 266px; }
    .unit-rating a.r8-unit:hover { width: 304px; }
    .unit-rating a.r9-unit { left: 304px; }
    .unit-rating a.r9-unit:hover { width: 342px; }
    .unit-rating a.r10-unit { left: 342px; }
    .unit-rating a.r10-unit:hover { width: 380px; }
    
    В /fullstory.tpl в нужное место вставляем:

    Code:
    [rating-type-1]
    <div class="fullrating">
    <div class="ratebar">
    {rating}
    </div>[not-group=5]<div class="mov-compl ic-l">[complaint]<span class="fa fa-exclamation"></span>Сообщить об ошибке[/complaint]</div>[/not-group]</div>
    [/rating-type-1]
    Чтобы рейтинг отображался в любом месте шаблона:

    Выводим рейтинг в полной новости:
    В файле: engine/modules/show.full.php найти строку:

    Code:
    $tpl->set( '{vote-num}', $row['vote_num'] );
    или
    $tpl->set( '{vote-num}', "<span id=\"vote-num-id-".$row['id']."\">".$row['vote_num']."</span>" );
    Ниже вставить:

    Code:
    $tpl->set( '{rate}', str_replace(",",".",round($row['rating']/max(1,$row['vote_num']),1)));
    В шаблоне использовать тег:
    {rate}

    Звёзды загрузить в /dleimages
     

    Attached Files:

    Last edited: Oct 15, 2017
  6. TopicStarter Overlay
    axiles

    axiles Посетитель

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Теперь, кто знает как сделать звёзды не активными после клика?