Sat Oct 30, 2004
Textpattern Upgrade
I linked up to the textpattern subversion repository and grabbed the latest code. I then proceeded to spend about an hour merging it with my modded version. All went well, and I am now running live with the (to be) rc2 code.
I added a few new mods beyond what was merged from my older files. I improved the stock txp:recent_comments tag to support forms and added a slew of useful comment and article tags. You’ll may notice that my recent comments list now links to each comment and each article. I also made the query a lot more effecient because it no longer returns every field of both the textpattern and the txp_discuss tables.
Here is the code that makes it possible. A new helper function “doCommentHref” and the modified recent_comments function. If anyone wants this as a plugin, just send me an email (I like getting email). BTW, the code below is meant to be used in a cut & paste situation since it is too wide for the article area. ;)
function recent_comments($atts)
{
extract(lAtts(array(
'label' => 'recent_comments_link',
'break' => br,
'wraptag' => '',
'limit' => 10,
'form' => '',
),$atts));
if ($form) $Form = fetch('Form','txp_form','name',$form);
$q = "select ".PFX."txp_discuss.*,".PFX."textpattern.custom_1,".PFX."textpattern.Title,
".PFX."textpattern.ID,".PFX."textpattern.url_title,".PFX."textpattern.Section
from ".PFX."txp_discuss left join ".PFX."textpattern on ".PFX."textpattern.ID = ".PFX."txp_discuss.parentid
order by ".PFX."txp_discuss.posted desc limit 0,$limit";
$rs = getRows($q);
if ($rs) {
if ($label) $out[] = $label;
foreach($rs as $a) {
extract($a);
if ($Form) {
$tmp = $Form;
$tmp = str_replace("<txp:article_id />", $ID, $tmp);
$tmp = str_replace("<txp:article_title />", $Title, $tmp);
$tmp = str_replace("<txp:article_url_title />", $url_title, $tmp);
$tmp = str_replace("<txp:article_section />", $Section, $tmp);
$tmp = str_replace("<txp:article_permalink />", doArticleHref($ID, $Title, $url_title, $Section), $tmp);
$tmp = preg_replace('/<(txp:article_permlink)>(.*)<\/\\1>/U', doArticleHref($ID, '$2', $url_title, $Section), $tmp);
$tmp = str_replace("<txp:comment_name />", $name, $tmp);
$tmp = str_replace("<txp:comment_email />", $email, $tmp);
$tmp = str_replace("<txp:comment_time />", $posted, $tmp);
$tmp = str_replace("<txp:comment_ip />", $ip, $tmp);
$tmp = str_replace("<txp:comment_id />", $discussid, $tmp);
$tmp = str_replace("<txp:message />", $message, $tmp);
$tmp = str_replace("<txp:comment_permalink />", doCommentHref($ID, $name, $url_title, $Section,$discussid), $tmp);
$tmp = preg_replace('/<(txp:comment_permlink)>(.*)<\/\\1>/U', doCommentHref($ID, '$2', $url_title, $Section,$discussid), $tmp);
$out[] = $tmp;
} else {
$out[] = doArticleHref($ID, $name.' ('.$Title.')', $url_title, $Section);
}
}
if (is_array($out)) {
return doWrap($out, $wraptag, $break);
}
}
return '';
}
function doCommentHref($ID,$Title,$url_title,$Section,$discussid)
{
$conTitle = ($url_title) ? $url_title : stripSpace($Title);
return ($GLOBALS['url_mode'])
? tag($Title,'a',' href="'.hu.$Section.'/'.$ID.'/'.$conTitle.(($conTitle)?'/#c':'#c').$discussid.'"')
: tag($Title,'a',' href="'.hu.'index.php?id='.$ID.'#c'.$discussid.'"');
}
Comment
I created a plugin to accomplish this using built-in txp functionality. Feel free to check it out at asv_recent_comments




