Skip to content

Commit

Permalink
Better handling of furls for tags with modBlog
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun McCormick committed Nov 15, 2011
1 parent e619ff7 commit c133f92
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/components/taglister/elements/chunks/tag.chunk.tpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<li class="[[+cls]]"><a href="[[~[[+target]]? &[[+tagVar]]=`[[+tag]]` &[[+tagKeyVar]]=`[[+tagKey]]`]]">[[+tag]]</a> ([[+count]])</li>
<li class="[[+cls]]"><a href="[[+url]]">[[+tag]]</a> ([[+count]])</li>
30 changes: 27 additions & 3 deletions core/components/taglister/elements/snippets/taglister.snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
/**
* tagLister snippet
*
* @var modX
* @var TagLister $tagLister
* @var array $scriptProperties
*
* @package taglister
*/
$tagLister = $modx->getService('taglister','TagLister',$modx->getOption('taglister.core_path',null,$modx->getOption('core_path').'components/taglister/').'model/taglister/',$scriptProperties);
Expand Down Expand Up @@ -53,6 +57,7 @@
$toLower = $modx->getOption('toLower',$scriptProperties,false);
$weights = $modx->getOption('weights',$scriptProperties,0);
$weightCls = $modx->getOption('weightCls',$scriptProperties,'');
$useTagFurl = $modx->getOption('useTagFurl',$scriptProperties,false);

/* parents support */
$parents = isset($parents) ? explode(',', $parents) : array();
Expand All @@ -78,8 +83,16 @@
$c->where(array('TemplateVar.name' => $tv));
}
if (!empty($parents)) {
$children = array();
foreach ($parents as $parent) {
$kids = $modx->getChildIds($parent);
foreach ($kids as $kid) {
$children[] = $kid;
}
}
$children = array_unique($children);
$c->where(array(
'Resource.parent:IN' => $parents,
'Resource.id:IN' => $children,
));
}
if (!$modx->getOption('includeDeleted',$scriptProperties,false)) {
Expand Down Expand Up @@ -147,7 +160,7 @@
/* handle weighting for css */
if (!empty($weights) && !empty($weightCls)) $tagCls .= ' '.$weightCls.ceil($count / (max($tagList) / $weights));

$output[] = $tagLister->getChunk($tpl,array(
$tagArray = array(
'tag' => $tag,
'tagVar' => $tagVar,
'tagKey' => $tv,
Expand All @@ -156,7 +169,18 @@
'target' => $target,
'cls' => $tagCls,
'idx' => $i,
));
);
$tagParams = array();
if (empty($useTagFurl)) {
$tagParams[$tagVar] = $tag;
$tagParams[$tagKeyVar] = $tv;
}
$tagArray['url'] = $modx->makeUrl($target,'',$tagParams);
if (!empty($useTagFurl)) {
$tagArray['url'] = rtrim($tagArray['url'],'/').'/tags/'.str_replace(' ','+',$tag);
}

$output[] = $tagLister->getChunk($tpl,$tagArray);
$totalTags += $count;
$i++;
}
Expand Down
20 changes: 16 additions & 4 deletions core/components/taglister/elements/snippets/tolinks.snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
/**
* tolinks snippet. Creates links out of tags.
*
* @var modX $modx
* @var tagLister $tagLister
* @var array $scriptProperties
*
* @package taglister
*/
$tagLister = $modx->getService('taglister','TagLister',$modx->getOption('taglister.core_path',null,$modx->getOption('core_path').'components/taglister/').'model/taglister/',$scriptProperties);
Expand All @@ -40,6 +44,7 @@
$target = !empty($scriptProperties['target']) ? $scriptProperties['target'] : $modx->resource->get('id');
$tpl = $modx->getOption('tpl',$scriptProperties,'link');
$cls = $modx->getOption('cls',$scriptProperties,'tl-tag');
$useTagsFurl = $modx->getOption('useTagsFurl',$scriptProperties,false);

/* get items */
$items = $modx->getOption('items',$scriptProperties,'');
Expand All @@ -65,14 +70,21 @@
foreach ($items as $item) {
$itemArray = array();
$itemArray['item'] = trim($item);
$params = array(
$tagRequestParam => $itemArray['item'],
$tagKeyVar => $tagKey,
);
$params = array();
if (empty($useTagsFurl)) {
$params = array(
$tagRequestParam => $itemArray['item'],
$tagKeyVar => $tagKey,
);
}

if (!empty($extraParams)) {
$params = array_merge($extraParams,$params);
}
$itemArray['url'] = $modx->makeUrl($target,'',$params);
if (!empty($useTagsFurl)) {
$itemArray['url'] = rtrim($itemArray['url'],'/').'/tags/'.$itemArray['item'];
}
$itemArray['url'] = str_replace(' ','+',$itemArray['url']);
$itemArray['cls'] = $cls;
$tags[] = $tagLister->getChunk($tpl,$itemArray);
Expand Down

0 comments on commit c133f92

Please sign in to comment.