Bonjour,
Je ne m’explique pas ce probleme:
- Sous la version precedente de modx ca fct mais la 0.9.6.3 je n’arrive pas a recuperer la variable du tag.
Le snippet
<?php
/****************************************************
* Name: TvTagCloud
* Version: 2.1.4
* Desc: Displays the tags from a documents tvar in a "tag cloud"
* Credits:
* Created by Kyle Jaebker and optimized by Mark Kaplan
* Style code added by Garry Nutting
* Large parts refactored and features added by Nick Crossland
* dittoID added by Jens Weintraut
* numeric sorting and limit (top) code by BBloke
* 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. Can take a comma separated list of parents
* depth: the number of levels down we should search for child documents
* days: the number of days to look back over to find tags. Leave as 0 for all time
* min: minimum number of tag occurances for tag to show, 0 for all
* sort: how should the results be ordered? By default they will be sorted by document ID. Values can be:
asc - tag alphabetical
dec - tag reverse alpgabetical
numasc - tag count ascending
numdesc - tag count descending
random - random order
* 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
* steps: comma separated list of the numeric intervals to determine the size of the tag class
* styles: comma separated list of class names that will be applied to each of the size intervals in "steps"
* tooltip: Template for the tooltip that will appear as the title attribute for each tag link. Takes placeholders [+count+] and
* [+tag+] which will be replaced with appropriate values
* dittoID: Id of the Ditto instance which should display the selected tag
* limit: restrict the number of tags to display
*
*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";
$depth = isset ($depth) ? $depth : 10;
$days = isset ($days) ? $days : 0;
$min = isset ($min) ? $min : "0";
$sort = isset ($sort) ? strtolower($sort) : false; // asc, desc, or random
$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;
$steps = isset($steps) ? $steps : '14,25,34,51,100';
$styles = isset($styles) ? $styles : 's5,s4,s3,s2,s1';
$tooltip = isset($tooltip) ? $tooltip : 'Click for stories about "[+tag+]" ([+count+])';
$dittoID = isset($dittoID) ? $dittoID . '_' : '';
$limit = isset ($limit) ? $limit : 0;
//-- styles for different sizes in the tag cloud (smallest to largest)
$steps = explode(',', $steps);
$styles = explode(',', $styles);
/* -------------------------------- Functions -------------------------------- */
/* ---------------- getTags ---------------- */
if (!function_exists('getTags')) {
function getTags($cIDs, $tvTags, $days) {
global $modx, $parent;
$docTags = array ();
$baspath= $modx->config["base_path"] . "manager/includes";
include_once $baspath . "/tmplvars.format.inc.php";
include_once $baspath . "/tmplvars.commands.inc.php";
if ($days > 0) {
$pub_date = mktime() - $days*24*60*60;
} else {
$pub_date = 0;
}
$tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
$tb2 = $modx->getFullTableName("site_tmplvars");
$tb_content = $modx->getFullTableName("site_content");
$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 .= " LEFT JOIN $tb_content tb_content ON stc.contentid=tb_content.id ";
$query .= " WHERE stv.name='".$tvTags."' AND stc.contentid IN (".implode($cIDs,",").") ";
$query .= " AND tb_content.pub_date >= '$pub_date' ";
$query .= " AND tb_content.published = 1 ";
$query .= " 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;
}
}
}
return $docTags;
}
}
/* -------------------------------- Main section -------------------------------- */
// Get the subentities of the supplied parent
$parents = explode(',',$parent);
$subEntities = $parents;
foreach ($parents as $parentDoc) {
$subDocs = $modx->getChildIds($parentDoc, $depth);
$subEntities = array_merge($subDocs,$subEntities);
}
$docTags = getTags(array_unique($subEntities), $tvTags, $days);
// docTags now contains an array indexed by docId, with each value containing an array of tags, e.g.:
// go through each document, split the works into an array, and add them to a
// master array with the word as the key, and a value containing an array consisting of count and style name
$tags = array();
$tag_count = 0;
foreach ($docTags as $n => $v) {
if (is_array($v)){ // We should have an array containing only one key (tags)
$this_tags = explode($tagDelim,$v['tags']); // Split it by the tag delimiter
foreach ($this_tags as $tag) { // Each of the new found tags
$tag = trim($tag); // Remove any whitespace
$tag = ($caseSensitive) ? $tag : strtolower($tag); // If not case sensitive, lower-case it
if ($tag != '') { // if its not empty after all this
$tag_count++;
if (isset($tags[$tag]['count'])) { // if we've already met this tag, increment its counter
$tags[$tag]['count']++;
} else { // Otherwise create a counter for it
$tags[$tag]['count'] = 1;
}
}
}
}
}
// Now we've totalled up how often each word appears, determine what style we should apply
foreach ($tags as $tag => $data) {
// if this tag has less than the minimum required count, remove it
if ($min > 0 && $data['count'] < $min) {
unset($tags[$tag]);
break;
}
$chosen_style = 0; // a default style
$step = (100 / $data['count']); // get percentage
for ($i=0;$i<count($steps);$i++) {
if ($step <= $steps[$i]) {
$tags[$tag]['style'] = $styles[$i];
break;
}
}
// Left in for debugging
/* echo "-------------- $tag \n";
echo "total tag_count: $tag_count \n";
echo "this tag count: ".$data['count']." \n";
echo "step: $step \n";
echo "chosen_style: ".$tags[$tag]['style']." \n";*/
}
// How do we want the words sorted?
switch ($sort) {
case 'asc':
ksort($tags); //sort them alphabetically
break;
case 'desc':
krsort($tags); //sort them reverse alphabetically
break;
case 'numasc':
asort($tags); // sort by value asc
break;
case 'numdesc':
arsort($tags); // sort by value desc
break;
case 'random': // Sort them randomly
$keys = array_keys($tags);
shuffle($keys);
$random_words = array();
foreach ($keys as $key) {
$random_words[$key] = $tags[$key];
}
$tags = $random_words;
break;
default:
break;
}
/* ------------- Output ------------- */
// Begin the output
if ($displayType == 'cloud') {
$output = '<div class="tagcloud">';
} else {
$output .= '<ul>';
$output .= "\r\n";
}
// How many tags should we display?
if ($limit == 0 ) {
$tags_still_to_show = count($tags);
}
else {
$tags_still_to_show = $limit;
}
// Go through each of the tags
foreach ($tags as $tag => $value) {
if ($tags_still_to_show == 0) {
break;
}
$count = $value['count'];
$this_style = $value['style'];
$tag = trim($tag);
// Prepare the tooltip
$this_tooltip = str_replace('[+count+]',$count,$tooltip);
$this_tooltip = str_replace('[+tag+]',$tag,$this_tooltip);
$this_tooltip = htmlentities($this_tooltip,ENT_QUOTES,$modx->config['modx_charset']);
if ($showCount) {
$countvalues = '(' . $count . ')';
}
// Choose the correct string seperator depending on whether we are using friendly URLs, and XHTML URLs
$url_amp = $modx->config['xhtml_urls']?'&':'&';
$query_string_seperator = ($modx->config['friendly_urls'])?'?':$url_amp;
if ($displayType == 'cloud') {
$output .= '<span><a class="' . $this_style . '" href="[~' . $landing . '~]'.$query_string_seperator.$dittoID . 'tags=' . urlencode($tag) . '" title="'.$this_tooltip.'">' . $tag . $countvalues . '</a></span>';
$output .= "\r\n";
} else {
$output .= '<li><a class="' . $this_style . '" href="[~' . $landing . '~]'.$query_string_seperator.$dittoID . 'tags=' . urlencode($tag) . '" title="'.$this_tooltip.'">' . $tag . ' ' . $countvalues . '</a></li>';
$output .= "\r\n";
}
$tags_still_to_show--;
}
// Finish the output
if ($displayType == 'cloud') {
$output .= '</div>';
} else {
$output .= '</ul>';
$output .= "\r\n";
}
return $output;
?>
J’ai cree une variable docTag pour implemente sur ma page des tags que j’appelle comme ceci:
[!TvTagCloud? &parent=`[*id*]` &displayType=`cloud` &tagDelim=`, ` &landing=`24` &tvTags=`docTags` &showCount=`0` &styles=`s5,s4,s3,s2,s1` &tooltip=`[+tag+]` !]
Sur ma page landing 24:
Pages relatives au tag: "[+tag+]"
[!Ditto? &startID=`2` &tagData=`docTags` &tagDelimiter=`,` &tagMode=`onlyTags` &tpl=`tagtpl`!]
La requete passe:
Tags.html?tags=accords
J’ai les reponses mais Pages relatives au tag: "
[+tag+]" [+tag+]= impossible d’arriver a l’afficher je comprends pas alors que la valeur passe dans la requete.
Si quelqu’un a une idee merci par avance