We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16238
    • 47 Posts
    Подскажите пожалуйста, как можно сделать так: http://modx.ru/ - в правой колонке - Лучшие 20 из 200 сайтов на MODx: ... TotalJapan: [b]3.11[/b]. Чтоб выводилось именно число оценки.

    У меня получилось лишь вот так: http://utekaj.ru/ - 10 лучших: ... Страсть [b]23:5[/b] (Вывела так: <a href="[(base_url)][~[+id+]~]">[+pagetitle+] </a> <b> [+star_rating+]</b>, где [+star_rating+] - TV, в которую CSS Star Rating записывает результаты оценки)

    Спасибо заранее.
      Download MODx Templates free
      • 29688
      • 40 Posts
      Хех, этот вопрос хитрый… был не так давно демо-доступ к админской части сайта modx.ru перелопатил его весь, но осталось много неизученного. Так вот этот сниппет был насколько я понял немного перелопачен администраторами этого сайта, был добален еще один TV параметр который отвечает именно за цифру рейтинга.
        www.lipdesign.ru
        [url=http://www.happylipetsk.ru/]Праздник в Липецке
        • 16238
        • 47 Posts
        Quote from: thefate at Jun 30, 2008, 01:07 AM

        Хех, этот вопрос хитрый… был не так давно демо-доступ к админской части сайта modx.ru перелопатил его весь, но осталось много неизученного. Так вот этот сниппет был насколько я понял немного перелопачен администраторами этого сайта, был добален еще один TV параметр который отвечает именно за цифру рейтинга.

        Да, жалко что закрыли, надо было тогда все себе скопировать что можно, когда возможность была smiley
        А на счет этого TV я пробовала, но мои познания PHP оставляют желать лучшего, поэтому ничего не получилось.
        Как сделать этот TV? Помогите плиз, всю голову сломала... :’(

          Download MODx Templates free
          • 29688
          • 40 Posts
          Я думаю автор не обидится и не сдержит зла smiley все лежало на всеобщем обозрении.

          Создай дополнительный TV параметр с именнем rating_number
          Там и будет содержаться твой рейтинг документа.

          Готовый сниппет ниже.

          <?php
          /**
           * Created on 30-May-2006
           *
           * Snippet: CSS Star Rating
           * Author: Garry Nutting
           * For: MODx 0.9.2.1 and above
           *
           * Modified:
           *  06/26/2006 - Added output template support - kylej
           *  06/29/2006 - Added language variables
           * 
           * Placeholder Values
           * ------------------
           *
           * [+starRating+] - output of the <ul> list for the star rating
           * [+totalVotes+] - output the total number of votes
           *  
           */
           
          //-- start session
          session_start();
          
          //-- snippet parameters
          $tvName = (isset ($tvName)) ? $tvName : 'star_rating'; // TV name where data will be stored
          $tvName2 = (isset ($tvName2)) ? $tvName2 : 'rating_number'; 
          $useSession = (isset ($useSession)) ? true : false; // Whether to only one vote per session
          $docID = (isset ($docID)) ? $docID : $modx->documentObject['id']; //see if document is set
          $pid = (isset ($_GET['pid'])) ? $_GET['pid'] : ''; //see if pid has been passed back
          $viewOnly = (isset ($viewOnly)) ? true : false; //disable voting
          $cssFile = (isset ($cssFile)) ? $cssFile : 1; //see if alternate css should be used
          $imgWidth = (isset ($imgWidth)) ? $imgWidth : 25; //get the image width, used when displaying current rating
          $onevote = (isset ($onevote)) ? $onevote : false; //use cookie restrictions to only allow one vote
          $ovtime = (isset ($ovtime)) ? $ovtime : 608400; //expire in one week
          
          //-- language variables
          $_lang['no_display'] = 'Невозможно отобразить рейтинг';
          $_lang['current_1'] = 'Сейчас';
          $_lang['current_2'] = '/5 звезд';
          $_lang['one_star'] = '1 звезда из 5';
          $_lang['two_stars'] = '2 звезды из 5';
          $_lang['three_stars'] = '3 звезды из 5';
          $_lang['four_stars'] = '4 звезды из 5';
          $_lang['five_stars'] = '5 звезд из 5';
          $_lang['no_vote'] = 'Голосовать можно один раз';
          
          $cssFiles = array (
          	'1' => 'assets/snippets/star_rating/star.css'
          );
          
          $starTpl = isset ($starTpl) ? $modx->getChunk($starTpl) : '[+starRating+]<span class="totalvotes">Голосов: [+totalVotes+]</span>';
          
          if (array_key_exists($cssFile, $cssFiles)) {
          	$cssFile = $cssFiles[$cssFile];
          }
          
          //-- check if visitor is logged in
          session_start();
          
          //-- cookie check - if $onevote, check if visitor is allowed to vote
          if (!$viewOnly && $onevote == true) {
          	if (isset ($_COOKIE['cssStarRating' . $docID])) {
          		$viewOnly = true;
          	}
          	elseif (isset ($_GET['starvote'])) {
          		//-- set cookie
          		setcookie('cssStarRating' . $docID, 'novote', time() + $ovtime);
          	}
          }
          
          if (!function_exists('setTemplateVar')) {
          	function setTemplateVar($value, $docID, $tplVarName) {
          		global $modx;
          
          		//-- get tmplvar id
          		$tplName = $modx->getFullTableName('site_tmplvars');
          		$tplRS = $modx->db->select('id', $tplName, 'name="' . $tplVarName . '"');
          		$tplRow = $modx->db->getRow($tplRS);
          
          		$tblName = $modx->getFullTableName('site_tmplvar_contentvalues');
          
          		$selectQuery = $modx->db->select('*', $tblName, 'contentid=' . $docID . ' AND tmplvarid=' . $tplRow['id']);
          
          		$updFields = array (
          			'value' => $value
          		);
          		$insFields = array (
          			'tmplvarid' => $tplRow['id'],
          			'contentid' => $docID,
          			'value' => $value
          		);
          
          		if ($modx->db->getRecordCount($selectQuery) < 1) {
          			$modx->db->insert($insFields, $tblName);
          		} else {
          			$modx->db->update($updFields, $tblName, 'contentid=' . $docID . ' AND tmplvarid=' . $tplRow['id']);
          		}
          	}
          }
          
          //-- get TV value
          $tvValue = $modx->getTemplateVar($tvName, '*', $docID);
          
          //-- check session variable to see if already voted
          $novote = ($useSession == true && isset ($_SESSION['starRating']['voted' . $docID])) ? true : false;
          
          //-- exit if no TV found
          if (!$tvValue)
          	return $_lang['no_display'];
          
          //-- split out TV values and calculate current Rating
          $splitVals = explode(':', $tvValue['value']);
          
          //-- check to ensure that a vote can be cast
          if ($pid <> '' && isset ($_GET['starvote']) && $novote == false && is_numeric($_GET['starvote']) && $_GET['starvote'] >= 0 && $_GET['starvote'] <= 5) {
          
          	//-- get TV value
          	$tvValue = $modx->getTemplateVar($tvName, '*', $pid);
          
          	//-- split out TV values and calculate current Rating
          	$splitVals = explode(':', $tvValue['value']);
          
          	$newCount = $splitVals[0] + $_GET['starvote'];
          	$newVoteNumber = $splitVals[1] + 1;
          
          	@ setTemplateVar("$newCount:$newVoteNumber", $pid, $tvName);
                  @ setTemplateVar(round($newCount/$newVoteNumber, 2), $pid, $tvName2);
          	//-- as this code is run for each instance of the Star Rating,
          	//-- the $_GET variable is unset so the update is only run once
          	//-- useful for when star rating multiple times on same page ;)
          	unset ($_GET);
          
          	if ($useSession == true) {
          		$_SESSION['starRating']['voted' . $pid] = true;
          	}
          
          	//-- refresh page to show correct ratings
          	$curURL = $modx->makeUrl($modx->documentObject['id']);
          	$modx->sendRedirect($curURL);
          }
          
          if ($splitVals[1] > 0) {
          	$currentStarValue = $splitVals[0] / $splitVals[1];
          	$totalVotes = $splitVals[1];
          } else {
          	$currentStarValue = 0;
          	$totalVotes = '0';
          }
          
          $starPhArray = array ();
          
          $output = '';
          $width = $currentStarValue * $imgWidth;
          
          if (!$viewOnly) {
          	$starPhArray['starRating'] = "<ul class='star-rating'>
          		<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
          		<li><a href='[~[*id*]~]?starvote=1&pid=[*id*]' title='" . $_lang['one_star'] . "' class='one-star'>1</a></li>
          		<li><a href='[~[*id*]~]?starvote=2&pid=[*id*]' title='" . $_lang['two_stars'] . "' class='two-stars'>2</a></li>
          		<li><a href='[~[*id*]~]?starvote=3&pid=[*id*]' title='" . $_lang['three_stars'] . "' class='three-stars'>3</a></li>
          		<li><a href='[~[*id*]~]?starvote=4&pid=[*id*]' title='" . $_lang['four_stars'] . "' class='four-stars'>4</a></li>
          		<li><a href='[~[*id*]~]?starvote=5&pid=[*id*]' title='" . $_lang['five_stars'] . "' class='five-stars'>5</a></li>
          	</ul>";
          } else {
          	$starPhArray['starRating'] = "<ul class='star-rating'>
          	<li class='current-rating' style='width:" . $width . "px;'>" . $_lang['current_1'] . $currentStarValue . $_lang['current_2'] . "</li>
          		<li class='one-star'>1</li>
          		<li class='two-stars'>2</li>
          		<li class='three-stars'>3</li>
          		<li class='four-stars'>4</li>
          		<li class='five-stars'>5</li>
          	</ul>";
          }
          
          $starPhArray['totalVotes'] = $totalVotes;
          
          foreach ($starPhArray as $n => $v) {
          	$starTpl = str_replace('[+' . $n . '+]', $v, $starTpl);
          }
          
          if ($novote) {
          	$output .= '<div class="star-rating-warning">' . $_lang['no_vote'] . '</div>';
          } else {
          	$output .= $starTpl;
          }
          
          return $output;
          ?>
          


            www.lipdesign.ru
            [url=http://www.happylipetsk.ru/]Праздник в Липецке
            • 16238
            • 47 Posts
            thefate, спасибо Вам ОГРОМНОЕ! Все получилось! kiss
              Download MODx Templates free