You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Return only distinct / unique results, based on a fieldname supplied as &distinct parameter
7
+
* Version: 1.0.1
8
+
* Author: Nick Crossland (ncrossland)
9
+
* Installation: Put file "distinct.extender.inc.php" into /assets/snippets/ditto/extenders
10
+
* Usage: In the Ditto call, add "distinct" to the extenders param, and specify the &distinct parameter with the name(s) of the field which you would like to be unique.
11
+
* If you would like to make the combined values of more than one field unique, separate them with commas
12
+
* e.g. [[Ditto? &tpl=`myTemplate` &extenders=`distinct` &distinct=`pagetitle`]] -- will return only unique page titles.
13
+
* e.g. [[Ditto? &tpl=`myTemplate` &extenders=`distinct` &distinct=`pagetitle,pub_date`]] -- will return only unique page titles for each date.
14
+
*
15
+
* Changelog:
16
+
* 1.0: initial release
17
+
* 1.0.1: Bugfixes only
18
+
*/
19
+
20
+
21
+
$distinct = isset($distinct) ? $distinct : false;
22
+
/*
23
+
Param: distinct
24
+
25
+
Purpose:
26
+
What field should we search for being distinct?
27
+
28
+
Options:
29
+
Fieldname
30
+
31
+
Default:
32
+
"default"
33
+
*/
34
+
35
+
36
+
// If no fieldname value has been supplied, don't do anything else
37
+
if ($distinct === false) {
38
+
returnfalse;
39
+
}
40
+
41
+
// It would be nice if this was class based, so it doesn't pollute the global namespace
42
+
// But - create an array of document values we've seen, and the fieldnames we're making distinct
43
+
global$seen;
44
+
global$distinct_fieldname;
45
+
$distinct_fieldname = explode(',',$distinct);
46
+
47
+
// Remove any extra spaces from the fieldnames (in case they have been supplied with commas and spaces)
// Make a unique string based on the fieldname and value of each field we've been asked to make distinct
59
+
$distinct_string = '';
60
+
foreach ($distinct_fieldnameas$f) {
61
+
$distinct_string .= '~'. $f.'|'.$resource[$f];
62
+
}
63
+
64
+
// Check if this string has been seen yet -- if it has, don't include it in the results
65
+
if (isset($seen[$distinct_string]) && ($seen[$distinct_string])==true ) { // If this value of the fieldname has been seen before, remove it from the list
66
+
returnfalse;
67
+
} else {
68
+
$seen[$distinct_string] = true; // Otherwise, remember the value has been seen, and allow it in the list (this time)
$result = $modx->db->select('uparent, COUNT(*)', $modx->getFullTableName("jot_content"), 'published=1 AND deleted=0 GROUP BY uparent', 'COUNT(*) DESC');
4
+
$counts = $modx->db->makeArray( $result );
5
+
6
+
// ïðèâîäèì ìàññèâ â âèä document_id => comments_count
/* apparently in 0.9.2.1 the getTemplateVarOutput function doesn't work as expected and doesn't return INHERITED value; this is probably to be fixed for next release; see http://modxcms.com/bugs/task/464
<ahref="[+jot.link.delete:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to delete this comment?')" title="Delete Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/delete.gif" width="16" height="16" alt="Delete Comment" border="0" /></a>
31
+
[+comment.published:is=`0`:then=`
32
+
<ahref="[+jot.link.publish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to publish this comment?')" title="Publish Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/publish.png" width="16" height="16" alt="Publish Comment" border="0" /></a>
33
+
`+]
34
+
[+comment.published:is=`1`:then=`
35
+
<ahref="[+jot.link.unpublish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to unpublish this comment?')" title="Unpublish Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/unpublish.png" width="16" height="16" alt="Unpublish Comment" border="0" /></a>
<ahref="[+jot.link.edit:esc+][+jot.querykey.id+]=[+comment.id+]#jf[+jot.link.id+]" onclick="return confirm('Are you sure you wish to edit this comment?')" title="Edit Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/edit.gif" width="16" height="16" alt="Edit Comment" border="0" /></a>
<ahref="[+jot.link.delete:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to delete this comment?')" title="Delete Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/delete.gif" width="16" height="16" alt="Delete Comment" border="0" /></a>
23
+
[+comment.published:is=`0`:then=`
24
+
<ahref="[+jot.link.publish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to publish this comment?')" title="Publish Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/publish.png" width="16" height="16" alt="Publish Comment" border="0" /></a>
25
+
`+]
26
+
[+comment.published:is=`1`:then=`
27
+
<ahref="[+jot.link.unpublish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to unpublish this comment?')" title="Unpublish Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/unpublish.png" width="16" height="16" alt="Unpublish Comment" border="0" /></a>
<ahref="[+jot.link.edit:esc+][+jot.querykey.id+]=[+comment.id+]#jf[+jot.link.id+]" onclick="return confirm('Are you sure you wish to edit this comment?')" title="Edit Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/edit.gif" width="16" height="16" alt="Edit Comment" border="0" /></a>
<ahref="[+jot.link.delete:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to delete this comment?')" title="Delete Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/delete.gif" width="16" height="16" alt="Delete Comment" border="0" /></a>
<ahref="[+jot.link.publish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to publish this comment?')" title="Publish Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/publish.png" width="16" height="16" alt="Publish Comment" border="0" /></a>
24
+
<ahref="[+jot.link.publish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Если разрешить комментарий он будет доступен для просмотра пользователям, уверены, что хотите этого?')" title="Publish Comment"><imgsrc="[(base_url)]manager/media/style/MODxCarbon/images/icons/add.png" width="16" height="16" alt="Опубликовать" border="0" /></a>
25
25
`+]
26
26
[+comment.published:is=`1`:then=`
27
-
<ahref="[+jot.link.unpublish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Are you sure you wish to unpublish this comment?')" title="Unpublish Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/unpublish.png" width="16" height="16" alt="Unpublish Comment" border="0" /></a>
27
+
<ahref="[+jot.link.unpublish:esc+][+jot.querykey.id+]=[+comment.id+]#jotmod[+jot.link.id+]" onclick="return confirm('Если запретить комментарий он не будет доступен для просмотра пользователями, уверены, что хотите этого?')" title="Unpublish Comment"><imgsrc="[(base_url)]manager/media/style/MODxCarbon/images/icons/delete.png" width="16" height="16" alt="Запретить" border="0" /></a>
<ahref="[+jot.link.edit:esc+][+jot.querykey.id+]=[+comment.id+]#jf[+jot.link.id+]" onclick="return confirm('Are you sure you wish to edit this comment?')" title="Edit Comment"><imgsrc="[(base_url)]assets/snippets/jot/templates/edit.gif" width="16" height="16" alt="Edit Comment" border="0" /></a>
<divstyle="width:150px;margin-top: 5px;margin-bottom: 5px;"><ahref="[+jot.link.current:esc+]"><imgsrc="[(base_url)]manager/includes/veriword.php?rand=[+jot.seed+]" width="148" height="60" alt="Если у Вас возникли проблемы с чтением кода, нажмите на картинку с кодом для нового кода." style="border: 1px solid #003399" /></a></div>
79
+
<labelfor="vericode[+jot.id+]">Для защиты от спама - введите код:<br/><inputtype="text" name="vericode" style="width:150px;" size="20" id="vericode[+jot.id+]" /></label>
<divstyle="width:150px;margin-top: 5px;margin-bottom: 5px;"><ahref="[+jot.link.current:esc+]"><imgsrc="[(base_url)]manager/includes/veriword.php?rand=[+jot.seed+]" width="148" height="60" alt="If you have trouble reading the code, click on the code itself to generate a new random code." style="border: 1px solid #003399" /></a></div>
<divstyle="width:150px;margin-top: 5px;margin-bottom: 5px;"><ahref="[+jot.link.current:esc+]"><imgsrc="[(base_url)]manager/includes/veriword.php?rand=[+jot.seed+]" width="148" height="60" alt="If you have trouble reading the code, click on the code itself to generate a new random code." style="border: 1px solid #003399" /></a></div>
<divstyle="width:150px;margin-top: 5px;margin-bottom: 5px;"><ahref="[+jot.link.current:esc+]"><imgsrc="[(base_url)]manager/includes/veriword.php?rand=[+jot.seed+]" width="148" height="60" alt="Если у Вас возникли проблемы с чтением кода, нажмите на картинку с кодом для нового кода." style="border: 1px solid #003399" /></a></div>
72
+
<labelfor="vericode[+jot.id+]">Для защиты от спама - введите код:<br/><inputtype="text" name="vericode" style="width:150px;" size="20" id="vericode[+jot.id+]" /></label>
$output .= ($docPriority) ? ("\t\t".'<priority>'.$docPriority.'</priority>'."\n") : ''; // don't output anything if TV doesn't exist
247
+
$output .= ($docChangefreq) ? ("\t\t".'<changefreq>'.$docChangefreq.'</changefreq>'."\n") : ''; // don't output anything if TV doesn't exist
248
+
$output .= "\t".'</url>'."\n";
249
+
} // end foreach
250
+
$output .= '</urlset>';
251
+
252
+
} // end switch
253
+
254
+
return $output;
255
+
256
+
# functions
257
+
# ---------------------------------------------
258
+
259
+
# gets (inherited) value of template variable
260
+
function getTV($modx,$docid,$doctv)
261
+
{
262
+
/* apparently in 0.9.2.1 the getTemplateVarOutput function doesn't work as expected and doesn't return INHERITED value; this is probably to be fixed for next release; see http://modxcms.com/bugs/task/464
0 commit comments