6
6
*
7
7
*
8
8
* PROPERTIES:
9
- *
10
- * &tagTpl string optional Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered
11
- * &groupTpl string optional Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered
12
- * &tagSeparator string optional String separator, that will be used for separating Tags
13
- * &groupSeparator string optional String separator, that will be used for separating Groups
9
+ *
10
+ * &tagTpl string optional Name of a chunk that will be used for each Tag. If no chunk is given, array with available placeholders will be rendered
11
+ * &groupTpl string optional Name of a chunk that will be used for each Group. If no chunk is given, array with available placeholders will be rendered
12
+ * &outTpl string optional Name of a chunk that will be used for wrapping all groups. If no chunk is given, tags will be rendered without a wrapper
13
+ * &tagSeparator string optional String separator, that will be used for separating Tags
14
+ * &groupSeparator string optional String separator, that will be used for separating Groups
15
+ * &target int optional An ID of a resource that will be used for generating URI for a Tag. If no ID is given, current Resource ID will be used
16
+ * &friendlyURL int optional If set, will be used instead of friendly_urls system setting to generate URL
17
+ * &linkTagScheme int|string optional Strategy to generate URLs, available values: -1, 0, 1, full, abs, http, https; Default: link_tag_scheme system setting
14
18
*
15
19
* USAGE:
16
20
*
25
29
if (!($ tagger instanceof Tagger))
26
30
return '' ;
27
31
32
+ $ target = (int ) $ modx ->getOption ('target ' , $ scriptProperties , $ modx ->resource ->id , true );
28
33
$ tagTpl = $ modx ->getOption ('tagTpl ' , $ scriptProperties , '' );
29
34
$ groupTpl = $ modx ->getOption ('groupTpl ' , $ scriptProperties , '' );
35
+ $ outTpl = $ modx ->getOption ('outTpl ' , $ scriptProperties , '' );
30
36
$ tagSeparator = $ modx ->getOption ('tagSeparator ' , $ scriptProperties , '' );
31
37
$ groupSeparator = $ modx ->getOption ('groupSeparator ' , $ scriptProperties , '' );
32
38
39
+ $ friendlyURL = (int ) $ modx ->getOption ('friendlyURL ' , $ scriptProperties , $ modx ->getOption ('friendly_urls ' , null , 0 ));
40
+ $ linkTagScheme = $ modx ->getOption ('linkTagScheme ' , $ scriptProperties , $ modx ->getOption ('link_tag_scheme ' , null , -1 ));
41
+
33
42
$ currentTags = $ tagger ->getCurrentTags ();
43
+ $ currentTagsLink = array ();
44
+
45
+ foreach ($ currentTags as $ currentTag ) {
46
+ $ currentTagsLink [$ currentTag ['alias ' ]] = array_keys ($ currentTag ['tags ' ]);
47
+ }
34
48
35
49
$ output = array ();
36
50
37
51
foreach ($ currentTags as $ currentTag ) {
38
52
if (!isset ($ currentTag ['tags ' ])) continue ;
39
53
40
54
$ tags = array ();
55
+
41
56
foreach ($ currentTag ['tags ' ] as $ tag ) {
57
+ $ linkData = $ currentTags ;
58
+ unset($ linkData [$ currentTag ['alias ' ]]['tags ' ][$ tag ['alias ' ]]);
59
+ if (count ($ linkData [$ currentTag ['alias ' ]]['tags ' ]) === 0 ) {
60
+ unset($ linkData [$ currentTag ['alias ' ]]);
61
+ }
62
+
63
+ if ($ friendlyURL === 1 ) {
64
+ $ linkPath = array_reduce (array_keys ($ linkData ), function ($ carry , $ item ) use ($ linkData ) {
65
+ return $ carry . $ item . '/ ' . implode ('/ ' , array_unique (array_keys ($ linkData [$ item ]['tags ' ]))) . '/ ' ;
66
+ }, '' );
67
+
68
+ $ uri = rtrim ($ modx ->makeUrl ($ target , '' , '' , $ linkTagScheme ), '/ ' ) . '/ ' . $ linkPath ;
69
+ } else {
70
+ $ args = [];
71
+ foreach ($ linkData as $ group ) {
72
+ $ args [$ group ['alias ' ]] = implode (', ' , array_keys ($ group ['tags ' ]));
73
+ }
74
+
75
+ $ uri = $ modx ->makeUrl ($ target , '' , $ args , $ linkTagScheme );
76
+ }
77
+
42
78
$ phs = array (
43
79
'tag ' => $ tag ['tag ' ],
44
80
'alias ' => $ tag ['alias ' ],
81
+ 'uri ' => $ uri ,
45
82
'group_name ' => $ currentTag ['group ' ],
46
83
'group_alias ' => $ currentTag ['alias ' ],
47
84
);
52
89
$ tags [] = $ tagger ->getChunk ($ tagTpl , $ phs );
53
90
}
54
91
}
55
-
92
+
56
93
$ groupPhs = array (
57
94
'name ' => $ currentTag ['group ' ],
58
95
'alias ' => $ currentTag ['alias ' ],
67
104
}
68
105
}
69
106
70
- return implode ($ groupSeparator , $ output );
107
+ if (!empty ($ outTpl ) && !empty ($ output )) {
108
+ return $ tagger ->getChunk ($ outTpl , array (
109
+ 'groups ' => implode ($ groupSeparator , $ output )
110
+ ));
111
+ }
112
+
113
+ return implode ($ groupSeparator , $ output );
0 commit comments