neooleg, большое спасибо за сниппет
http://modxcms.com/forums/index.php/topic,17843.msg255208.html#msg255208 !
Недавно мне потребовался вывод последних комментариев со всего сайта. Я попробовал вариант от
lossendae http://modxcms.com/forums/index.php/topic,15746.msg199855.html#msg199855. В 1.0.2 (Jot 1.1.4) все работает, но с моим детсадовским PHP мне так и не удалось вывести pagetitle страницы с комментарием, при этом немыслимо выросло количество запросов к БД. И тут как раз ваше решение.
На то, чтобы успешно «допилить» ваш код, меня хватило

.
Синтаксис запроса к БД подсмотрел в сниппете showMembers. Теперь выводится еще имя веб-пользователя, кроме того, регулируется кол-во выводимых знаков заголовка и содержимого, выводимый пункт является ссылкой на сам коммент.
Ну, и написал комментарии к сниппету с примерами, так как полагаю, что найдется кто-то, кто соображает в разработке еще меньше меня.
<?php
/*
* snippet name: getComments
* written by neooleg, 23.11.2009
* modified by jen, 30.11.2009
*
* Parameters:
* tplComments - chunk to display comments output. Required.
* ** below parameters are optional **
* &limit - qty of comments in output. All published comments in DB by default. :)
* &trunkPgtitle - number of characters to show of pagetitle. Any nonnegative integer. 60 by default.
* &truncComment - number of characters to show of text of comment. Any nonnegative integer. 200 by default.
* &dateFormat - formats date output. See strftime() function for details. See snippet call example. "%d.%m.%Y, %H:%M" by default.
*
* Placeholders:
* id - id of resource where comment placed.
* comment_id - id of comment.
* pagetitle - pagetitle of resource where comment placed.
* comment_text
* comment_author- web-user username (login).
* comment_date - comment creation date.
*
* Snippet call example: [!getComments? &tplComments=`getCommentsTpl` &trunkPgtitle=`30` &truncComment=`100` &dateFormat=`%Y-%m-%d, %H:%M` &limitComments=`10`!]
* Chunk example: <li><a href="[~[+id+]~]#comment.[+comment_id+]"><strong>[+pagetitle+] • </strong>[+comment_text+]…<strong> – <i>[+comment_author+],</i></strong> <small><i>[+comment_date+]</i></small></a></li>
* To make the above link operable add two pieces of code to assets/snippets/jot/templates/chunk.comment.inc.html
* e.g., <div class="jot-comment" id="comment.[+comment.id+]">
* and <a href="[~[+jot.docid+]~]#comment.[+comment.id+]" title="Link to this comment">#[+comment.postnumber+]</a>
* instead of <a href="[~[+jot.docid+]~]#jc[+jot.link.id+][+comment.id+]"...
*/
// date_default_timezone_set('Europe/Helsinki');
mb_internal_encoding("UTF-8");
global $modx;
$tpl = isset($tplComments) ? $tplComments : null;
$limit = isset($limitComments) ? $limitComments : null;
$pgtLength = isset($trunkPgtitle) ? $trunkPgtitle : 60;
$length = isset($truncComment) ? $truncComment : 200;
$date = isset($dateFormat) ? $dateFormat : "%d.%m.%Y, %H:%M";
if ($tpl)
{
$jc = $modx->getFullTableName('jot_content');
$wu = $modx->getFullTableName('web_users');
$sql = "SELECT jc.id, jc.uparent, jc.content, jc.createdon, wu.username FROM {$jc} jc JOIN {$wu} wu ON wu.id = -jc.createdby AND jc.published = 1 AND jc.deleted = 0 ORDER BY jc.createdon DESC" . ($limit != null ? " LIMIT $limit;" : ';');
$output = '';
$result = $modx->db->query($sql);
$hashRes = null;
while(($hashRes = mysql_fetch_assoc($result)) != null)
{
$hashPlaceholders = $modx->getTemplateVarOutput(array('pagetitle'), $hashRes['uparent']);
$chunkArr = array(
'id' => $hashRes['uparent'],
'comment_id' => $hashRes['id'],
'pagetitle' => mb_substr($hashPlaceholders['pagetitle'], 0, $pgtLength),
'comment_text' => mb_substr($hashRes['content'], 0, $length),
'comment_author' => $hashRes['username'],
'comment_date' => strftime($date, $hashRes['createdon'])
);
$output .= $modx->parseChunk($tpl, $chunkArr, '[+', '+]');
}
echo $output;
}
?>
К сожалению, проблема, описанная в
http://modxcms.com/forums/index.php/topic,17843.msg188967.html#msg188967 никуда не делась. Видимо, дело не столько в UTF-8, сколько в парсере Jot. Если уж умные дядьки не могут ее решить, то я просто смирился

.
Знатоки, поправьте, если что!
Может быть, можно оптимизировать запросы к БД. При подключении сниппета (6 выводимых комментов с заголовком страницы и веб-юзером) число запросов выросло на 13.
Если кому-то нужно выводить админские комменты — пилите дальше

.
P.S. Добавил дату создания коммента. В комментариях и примерах тоже прописал.