We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26085
    • 494 Posts
    $key - это слово. Вместо русских букв выводиться белеберда "ББББББББББББББ". Кодировка у меня UTF8. хотя поиск по этой белеберде работает правильно. Как лечить?


    <?php
    
    /****************************************************
    * Name: TvTagCloud
    * Version: 2.0
    * Desc: Displays the tags from a documents tvar in a "tag cloud"
    * Created by Kyle Jaebker and optimized by Mark Kaplan
    * style code added by Garry Nutting
    * Based of code by Marc Hinse, [email protected], www.modxcms.de (original TagCloud creator)
    *
    * Usage: [!TvTagCloud? &parent=`1` &landing=`22` &tvTags=`docTags` &showCount=`1`!]
    *
    * Parameters:
    * 	parent: folder that conatins the documents which are to be counted
    *   min: minimum number of tag occurances for tag to show, 0 for all
    *   landing: id of document to display ditto listings
    *   tvTags: the template variable that has the tags
    *   tagDelim: delimiter between tags in tvar
    *   displayType: [cloud | list] output as a tag cloud or an unordered list
    *   showCount: if you want the number of occurances to be displayed set to 1
    *   caseSensitive: if you want tag duplicate removal to be case sensitive set to 1
    *
    *Landing Page setup:
    *   the landing page should have a call to ditto (the latest version) with at
    *   minimum the following tagging parameters set:
    *
    *   [!ditto? &startID=`1` &tagData=`tvdocTags` &tagDelimiter=`,`!]
    *
    * ***************************************************/
    
    $parent = isset ($parent) ? $parent : "0";
    $min = isset ($min) ? $min : "0";
    $landing = isset ($landing) ? $landing : "[~[*id*]~]";
    $tvTags = isset ($tvTags) ? $tvTags : 'repo_tags';
    $tagDelim = isset ($tagDelim) ? $tagDelim : ',';
    $displayType = isset ($displayType) ? $displayType : 'cloud';
    $showCount = isset ($showCount) ? $showCount : 0;
    $caseSensitive = isset ($caseSensitive) ? $caseSensitive : 0;
    
    //-- styles for different sizes in the tag cloud (smallest to largest)
    $styles = array (
    	's1',
    	's2',
    	's3',
    	's4',
    	's5'
    );
    
    $subEntities = $modx->getDocumentChildren($parent); //,1,0,"id,pagetitle");
    
    global $docTags;
    $docTags = array ();
    
    if (!function_exists('getTags')) {
    	function getTags($resource, $tvTags) {
    		global $modx, $docTags, $parent;
    
    		$baspath= $modx->config["base_path"] . "manager/includes";
    	    include_once $baspath . "/tmplvars.format.inc.php";
    	    include_once $baspath . "/tmplvars.commands.inc.php";
    
    		$cIDs = array();
    		foreach ($resource as $doc => $values) {
    			$cIDs[] = $values['id'];
    		}
    
    		$tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
    		$tb2 = $modx->getFullTableName("site_tmplvars");
    		$query = "SELECT stv.name,stc.tmplvarid,stc.contentid,stv.type,stv.display,stv.display_params,stc.value";
    		$query .= " FROM ".$tb1." stc LEFT JOIN ".$tb2." stv ON stv.id=stc.tmplvarid ";
    		$query .= " WHERE stv.name='".$tvTags."' AND stc.contentid IN (".implode($cIDs,",").") ORDER BY stc.contentid ASC;";
    		$rs = $modx->db->query($query);
    		$tot = $modx->db->getRecordCount($rs);
    		$resourceArray = array();
    		for($i=0;$i<$tot;$i++)  {
    			$row = @$modx->fetchRow($rs);
    			$docTags[$row['contentid']]['tags'] = getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
    		}
    		if ($tot != count($cIDs)) {
    			$query = "SELECT name,type,display,display_params,default_text";
    			$query .= " FROM $tb2";
    			$query .= " WHERE name='".$tvTags."' LIMIT 1";
    			$rs = $modx->db->query($query);
    			$row = @$modx->fetchRow($rs);
    			$defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
    			foreach ($cIDs as $id) {
    				if (!isset($docTags[$id]['tags'])) {
    					$docTags[$id]['tags'] = $defaultOutput;
    				}
    			}
    		}
    	}
    }
    
    getTags($subEntities, $tvTags);
    
    if (!function_exists('getSizeStyle')) {
        function getSizeStyle($value) {
        	$step = (100 / $value); // get percentage
    
        	//-- reverse logic (smaller number = higher frequency)
        	if ($step < 20) {
        		$style = 4;
        	} else
        		if ($step >= 20 && $step < 40) {
        			$style = 3;
        		} else
        			if ($step >= 40 && $step < 60) {
        				$style = 2;
        			} else
        				if ($step >= 60 && $step < 80) {
        					$style = 1;
        				} else
        					if ($step >= 80) {
        						$style = 0;
        					}
        	return $style;
        }
    }
    
    $content = '';
    
    $firstDoc = 1;
    
    foreach ($docTags as $n => $v) {
    	if ($firstDoc) {
    		$content = $v['tags'];
    		$firstDoc = 0;
    	} else {
    		$content .= $tagDelim . $v['tags'];
    	}
    }
    
    if ($displayType == 'cloud') {
      $output = '<div class="tagcloud">';
    }
    $array_content = explode($tagDelim, $content); //split them in separate words
    
    foreach ($array_content as $tag) {
    	$tags[] = ($caseSensitive) ? $tag : strtolower($tag);
    }
    
    $wordCount = array_count_values($tags); //count the words
    
    $words = array ();
    foreach ($wordCount as $key => $value) {
    	if ($value >= $min) {
    		$words[$key] = $value; //put them in a new array
    	}
    }
    
    $wordStyles = array_map("getSizeStyle", $wordCount);
    
    ksort($words); //sort them alphabetically (just comment that out, then they will be unsortet
    
    if ($displayType !== 'cloud') {
    	$output .= '<ul>';
    	$output .= "\r\n";
    }
    
    foreach ($words as $key => $value) {
    	if ($showCount) {
    		$countvalues = '(' . $value . ')';
    	}
    	if ($displayType == 'cloud') {
    		$output .= '<span><a class="' . $styles[$wordStyles[$key]] . '" href="[~' . $landing . '~]&tags=' . urlencode(trim($key)) . '">' . trim($key) . $countvalues . '</a></span>';
    		$output .= "\r\n";
    	} else {
    		$output .= '<li><a href="[~' . $landing . '~]&tags=' . urlencode(trim($key)) . '">' . trim($key) . ' ' . $countvalues . '</a></li>';
    		$output .= "\r\n";
    	}
    }
    
    if ($displayType !== 'cloud') {
    	$output .= '</ul>';
    	$output .= "\r\n";
    }
    
    if ($displayType == 'cloud') {
      $output .= '</div>';
    }
    return $output;
    ?>
    
      • 897
      • 1,620 Posts
      давай плясать от обратного, ты 100% уверен что в базе лежит правильно?
        "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

        Не используйте Revo для "просто сайтов". Используйте Evo

        Who can defeat the Russian bear?
        • 26085
        • 494 Posts
        Quote from: aleksey.stepanov at May 22, 2007, 12:53 PM

        давай плясать от обратного, ты 100% уверен что в базе лежит правильно?
        Ну дак во всех остальных местах всё нормально на русском. В базе всё в UTF8 проверял через PSPAD.
        URI кодировке поиск работает незовисимо от "козябликов". Пробовал экспериментировать с php iconv() utf8_decode() Ничего вразумительного не получил. А по поводу ста процентов как это ещё проверить можно?
          • 897
          • 1,620 Posts
          ну phpMyAdmin посмотреть в таблице с TV.
            "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

            Не используйте Revo для "просто сайтов". Используйте Evo

            Who can defeat the Russian bear?
            • 26085
            • 494 Posts
            Quote from: aleksey.stepanov at May 23, 2007, 01:38 AM

            ну phpMyAdmin посмотреть в таблице с TV.

            Ну я уж не такой тупой laugh
            Всё в UTF8. Кстати чере дитту tagging тоже та же тема.
              • 26085
              • 494 Posts
              Так и не понял где собака зарыта. В win-1251 всё ок. Так что решил перейти на неё.
                • 897
                • 1,620 Posts
                видимо проблема была (и остается) в базе, по-моему сотни раз мы это обсуждали, сейчас не вспомню, но там что-то о кодировке сравнения у таблиц в мускуле надо курить
                  "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

                  Не используйте Revo для "просто сайтов". Используйте Evo

                  Who can defeat the Russian bear?
                  • 16876
                  • 8 Posts
                  Òîæå ïðîáëåìà, òîëüêî â îáëàêå òåãîâ çíàêè âîïðîñà. Â ðåçóëüòàòàõ (landing) âñå âïîðÿäêå. Â áàçå âñå êîððåêòíî îòîáðàæàåòñÿ. Íèêòî íå íàøåë ðåøåíèÿ?
                    • 26085
                    • 494 Posts
                    Quote from: leeroy at Nov 14, 2007, 09:09 AM

                    Òîæå ïðîáëåìà, òîëüêî â îáëàêå òåãîâ çíàêè âîïðîñà. Â ðåçóëüòàòàõ (landing) âñå âïîðÿäêå. Â áàçå âñå êîððåêòíî îòîáðàæàåòñÿ. Íèêòî íå íàøåë ðåøåíèÿ?
                    я вроде нашёл и забыл smiley
                      • 16876
                      • 8 Posts
                      Ñîáñòâåííî ó ìåíÿ ïðîáëåìà áûëà â Äåíâåðå, íà õîñòèíãå âñå â ïîðÿäêå. 3-é Äåíâåð, êñòàòè âûøåë, âîçìîæíî òàêîãî íåò.