|
21 | 21 | * &showUnused int optional If 1 is set, Tags that are not assigned to any Resource will be included to the output as well
|
22 | 22 | * &showUnpublished int optional If 1 is set, Tags that are assigned only to unpublished Resources will be included to the output as well
|
23 | 23 | * &showDeleted int optional If 1 is set, Tags that are assigned only to deleted Resources will be included to the output as well
|
| 24 | + * &linkCurrentTags int optional If 1 is set, Current Tags will be included in generated URL, default behavior is to generate links to a single tag |
24 | 25 | * &contexts string optional If set, will display only tags for resources in given contexts. Contexts can be separated by a comma
|
25 | 26 | * &toPlaceholder string optional If set, output will return in placeholder with given name
|
26 | 27 | * &sort string optional Sort options in JSON. Example {"tag": "ASC"} or multiple sort options {"group_id": "ASC", "tag": "ASC"}
|
|
46 | 47 | $showUnused = (int) $modx->getOption('showUnused', $scriptProperties, '0');
|
47 | 48 | $showUnpublished = (int) $modx->getOption('showUnpublished', $scriptProperties, '0');
|
48 | 49 | $showDeleted = (int) $modx->getOption('showDeleted', $scriptProperties, '0');
|
| 50 | +$linkCurrentTags = (int) $modx->getOption('linkCurrentTags', $scriptProperties, '0'); |
49 | 51 | $contexts = $modx->getOption('contexts', $scriptProperties, '');
|
50 | 52 | $translate = (int) $modx->getOption('translate', $scriptProperties, '0');
|
51 | 53 |
|
|
172 | 174 |
|
173 | 175 | $idx = 1;
|
174 | 176 | $currentTags = $tagger->getCurrentTags();
|
| 177 | +$currentTagsLink = array(); |
| 178 | + |
| 179 | +if ($linkCurrentTags == 1) { |
| 180 | + foreach($currentTags as $currentTag) |
| 181 | + { |
| 182 | + $currentTagsLink[$currentTag['alias']] = array_keys($currentTag['tags']); |
| 183 | + } |
| 184 | +} |
175 | 185 |
|
176 | 186 | foreach ($tags as $tag) {
|
177 | 187 | /** @var TaggerTag $tag */
|
178 | 188 | $phs = $tag->toArray();
|
179 | 189 |
|
180 | 190 | $group = $tag->Group;
|
181 | 191 |
|
| 192 | + $linkData = array_merge_recursive($currentTagsLink, array( |
| 193 | + $group->alias => array($tag->alias) |
| 194 | + )); |
| 195 | + $linkData = array_filter(array_map(function($data) { |
| 196 | + return array_filter($data, function($value) use ($data) { |
| 197 | + return !(array_count_values($data)[$value] > 1); |
| 198 | + }); |
| 199 | + }, $linkData)); |
| 200 | + |
182 | 201 | if ($friendlyURL == 1) {
|
183 |
| - $uri = rtrim($modx->makeUrl($target, '', '', $linkTagScheme), '/') . '/' . $group->alias . '/' . $tag->alias . '/'; |
| 202 | + $linkPath = array_reduce(array_keys($linkData), function($carry, $item) use ($linkData) { |
| 203 | + return $carry . $item . '/' . implode('/', array_unique($linkData[$item])) . '/'; |
| 204 | + }, ''); |
| 205 | + $uri = rtrim($modx->makeUrl($target, '', '', $linkTagScheme), '/') . '/' . $linkPath; |
184 | 206 | } else {
|
185 |
| - $uri = $modx->makeUrl($target, '', $group->alias . '=' . $tag->alias, $linkTagScheme); |
| 207 | + $linkPath = http_build_query( |
| 208 | + array_map(function($values) { |
| 209 | + return is_array($values) ? implode(',', array_unique($values)) : $values; |
| 210 | + }, $linkData) |
| 211 | + ); |
| 212 | + $uri = $modx->makeUrl($target, '', $linkPath, $linkTagScheme); |
186 | 213 | }
|
187 | 214 |
|
188 | 215 | $phs['uri'] = $uri;
|
189 | 216 | $phs['idx'] = $idx;
|
190 | 217 | $phs['target'] = $target;
|
191 | 218 | $phs['max_cnt'] = $maxCnt;
|
192 |
| - |
| 219 | + |
193 | 220 | if (isset($currentTags[$group->alias]['tags'][$tag->alias])) {
|
194 |
| - $phs['active'] = 1; |
| 221 | + $phs['active'] = 1; |
195 | 222 | } else {
|
196 | 223 | $phs['active'] = 0;
|
197 | 224 | }
|
|
0 commit comments