$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;
?>