Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Make recent_articles context aware (exclude self)
When using txp:recent_articles in an article context it also list itself.
It could be really nice if txp:recent_articles was made context aware so that txp:recent_articles would exclude itself form it’s list.
Perhaps something like:
txp:recent_articles excludeself=1
Testcase:
Lets say you have the following articles:
test1
test2
test3
So if I’m in the article “test1” and use txp:recent_articles excludeself=1 I would get the following list:
test2
test3
So if I’m in the article “test2” and use txp:recent_articles excludeself=1 I would get the following list:
test1
test3
etc
Offline
Re: Make recent_articles context aware (exclude self)
gemal wrote:
When using txp:recent_articles in an article context it also list itself.
If I produce a patch will someone look at it?
Offline
Re: Make recent_articles context aware (exclude self)
I think there may be a plugin that does that.
We can’t suddenly change behaviour for backwards-comaptibility. Especially when it is basically a matter of taste, whether the tag should out put all articles, omit the current one, or show the current one as plain-text in the same position in the list.
I think this fits really well into plugin territory.
Offline
Re: Make recent_articles context aware (exclude self)
Sencer wrote:
I think there may be a plugin that does that.
We can’t suddenly change behaviour for backwards-comaptibility. Especially when it is basically a matter of taste, whether the tag should out put all articles, omit the current one, or show the current one as plain-text in the same position in the list.
I wouldn’t change default behavior. I would add a optional noself parameter that would exclude the article itself from the list. Calling the tag without this parameter would return the list as it is today.
Offline
Re: Make recent_articles context aware (exclude self)
svn diff
Index: taghandlers.php
===================================================================
--- taghandlers.php (revision 2503)
+++ taghandlers.php (working copy)
@@ -585,6 +585,7 @@
'label' => gTxt('recent_articles'),
'labeltag' => '',
'limit' => 10,
+ 'no_self' => '',
'section' => '',
'sort' => 'Posted desc',
'sortby' => '',
@@ -613,7 +614,11 @@
$categories = ($category) ? "and (Category1 = '".doSlash($category)."' or Category2 = '".doSlash($category)."')" : '
';
$section = ($section) ? " and Section = '".doSlash($section)."'" : '';
- $rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern',
+ if ($no_self)
+ {
+ $limit++;
+ }
+ $rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern',
"Status = 4 $section $categories and Posted <= now() order by ".doSlash($sort).' limit 0,'.intval($limit));
if ($rs)
@@ -622,12 +627,19 @@
while ($a = nextRow($rs))
{
- $a['Title'] = ($no_widow) ? noWidow(escape_title($a['Title'])) : escape_title($a['Title']);
- $out[] = href($a['Title'], permlinkurl($a));
+ if (!($no_self && ($thisarticle['thisid'] == $a['ID'])))
+ {
+ $a['Title'] = ($no_widow) ? noWidow(escape_title($a['Title'])) : escape_title($a['Title']);
+ $out[] = href($a['Title'], permlinkurl($a));
+ }
}
if ($out)
{
+ if ($no_self && count($out) > $limit)
+ {
+ array_splice($out, -1);
+ }
return doLabel($label, $labeltag).doWrap($out, $wraptag, $break, $class);
}
Last edited by gemal (2007-07-24 19:17:51)
Offline
Re: Make recent_articles context aware (exclude self)
That can be done much shorter by excluding the current article ID in the SQL query when no_self is set.
Offline
Re: Make recent_articles context aware (exclude self)
ruud wrote:
That can be done much shorter by excluding the current article ID in the SQL query when no_self is set.
Index: taghandlers.php
===================================================================
--- taghandlers.php (revision 2503)
+++ taghandlers.php (working copy)
@@ -585,6 +585,7 @@
'label' => gTxt('recent_articles'),
'labeltag' => '',
'limit' => 10,
+ 'no_self' => '',
'section' => '',
'sort' => 'Posted desc',
'sortby' => '',
@@ -613,8 +614,13 @@
$categories = ($category) ? "and (Category1 = '".doSlash($category)."' or Category2 = '".doSlash($category)."')" : '';
$section = ($section) ? " and Section = '".doSlash($section)."'" : '';
+ $exclude = '';
+ if ($no_self)
+ {
+ $exclude = ' and id != ' . $thisarticle['thisid'];
+ }
$rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern',
- "Status = 4 $section $categories and Posted <= now() order by ".doSlash($sort).' limit 0,'.intval($limit));
+ "Status = 4 $section $categories and Posted <= now() $exclude order by ".doSlash($sort).' limit 0,'.intval($limit));
if ($rs)
{
Last edited by gemal (2007-07-24 20:18:51)
Offline
Re: Make recent_articles context aware (exclude self)
Complete patch. Will someone please look at it?
Index: lang/en-gb.txt
===================================================================
--- lang/en-gb.txt (revision 2503)
+++ lang/en-gb.txt (working copy)
@@ -897,6 +897,7 @@
decimals => Display # numbers after the decimal point
default_title => Text to use for default section link
exclude => Exclude
+exclude_self => Exclude current article?
filename => Name
file_download_tags => File Downloads
flavor => Syndication format
Index: include/txp_tag.php
===================================================================
--- include/txp_tag.php (revision 2503)
+++ include/txp_tag.php (working copy)
@@ -940,6 +940,7 @@
'label',
'labeltag',
'limit',
+ 'exclude_self',
'section',
'sort',
'wraptag',
@@ -968,6 +969,9 @@
tagRow('limit',
fInput('text', 'limit', $limit, 'edit', '', '', 2)).
+ tagRow('exclude_self',
+ yesno_pop('exclude_self', $exclude_self)).
+
tagRow('label',
fInput('text', 'label', ($label ? $label : gTxt('recent_articles')), 'edit', '', '', 20)).
@@ -1072,6 +1076,7 @@
'label',
'labeltag',
'limit',
+ 'exclude_self',
'sort',
'wraptag',
));
@@ -1093,6 +1098,9 @@
tagRow('limit',
fInput('text', 'limit', $limit, 'edit', '', '', 2)).
+ tagRow('exclude_self',
+ yesno_pop('exclude_self', $exclude_self)).
+
tagRow('label',
fInput('text', 'label', ($label ? $label : gTxt('recent_comments')), 'edit', '', '', 20)).
Index: setup/en-gb.php
===================================================================
--- setup/en-gb.php (revision 2503)
+++ setup/en-gb.php (working copy)
@@ -903,6 +903,7 @@
'decimals' => 'Display # numbers after the decimal point',
'default_title' => 'Text to use for default section link',
'exclude' => 'Exclude',
+ 'exclude_self' => 'Exclude current article',
'filename' => 'Name',
'file_download_tags' => 'File Downloads',
'flavor' => 'Syndication format',
Index: publish/taghandlers.php
===================================================================
--- publish/taghandlers.php (revision 2503)
+++ publish/taghandlers.php (working copy)
@@ -577,7 +577,7 @@
function recent_articles($atts)
{
- global $prefs;
+ global $prefs, $thisarticle;
extract(lAtts(array(
'break' => br,
'category' => '',
@@ -585,6 +585,7 @@
'label' => gTxt('recent_articles'),
'labeltag' => '',
'limit' => 10,
+ 'exclude_self' => '',
'section' => '',
'sort' => 'Posted desc',
'sortby' => '',
@@ -613,8 +614,13 @@
$categories = ($category) ? "and (Category1 = '".doSlash($category)."' or Category2 = '".doSlash($category)."')" : '';
$section = ($section) ? " and Section = '".doSlash($section)."'" : '';
+ $exclude = '';
+ if ($exclude_self)
+ {
+ $exclude = 'and id != ' . $thisarticle['thisid'];
+ }
$rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern',
- "Status = 4 $section $categories and Posted <= now() order by ".doSlash($sort).' limit 0,'.intval($limit));
+ "Status = 4 $section $categories and Posted <= now() $exclude order by ".doSlash($sort).' limit 0,'.intval($limit));
if ($rs)
{
@@ -639,18 +645,25 @@
function recent_comments($atts)
{
+ global $thisarticle;
extract(lAtts(array(
'break' => br,
'class' => __FUNCTION__,
'label' => '',
'labeltag' => '',
'limit' => 10,
+ 'exclude_self' => '',
'sort' => 'posted desc',
'wraptag' => '',
), $atts));
+ $exclude = '';
+ if ($exclude_self)
+ {
+ $exclude = 'and parentid != ' . $thisarticle['thisid'];
+ }
$rs = safe_rows_start('parentid, name, discussid', 'txp_discuss',
- 'visible = '.VISIBLE.' order by '.doSlash($sort).' limit 0,'.intval($limit));
+ 'visible = '.VISIBLE." $exclude order by ".doSlash($sort).' limit 0,'.intval($limit));
if ($rs)
{
Offline
Re: Make recent_articles context aware (exclude self)
What happens when $thisarticle[‘thisid’] is not set (when you’re not on an individual article page)?
Offline
Re: Make recent_articles context aware (exclude self)
ruud wrote:
What happens when $thisarticle[‘thisid’] is not set (when you’re not on an individual article page)?
Fail :(
I’ll rewrite when I get home and have access to svn
Offline
Re: Make recent_articles context aware (exclude self)
gemal wrote:
Fail :( I’ll rewrite when I get home and have access to svn
What is needed for this to be checked in?
Index: lang/en-gb.txt
===================================================================
--- lang/en-gb.txt (revision 2503)
+++ lang/en-gb.txt (working copy)
@@ -897,6 +897,7 @@
decimals => Display # numbers after the decimal point
default_title => Text to use for default section link
exclude => Exclude
+exclude_self => Exclude current article?
filename => Name
file_download_tags => File Downloads
flavor => Syndication format
Index: include/txp_tag.php
===================================================================
--- include/txp_tag.php (revision 2503)
+++ include/txp_tag.php (working copy)
@@ -940,6 +940,7 @@
'label',
'labeltag',
'limit',
+ 'exclude_self',
'section',
'sort',
'wraptag',
@@ -968,6 +969,9 @@
tagRow('limit',
fInput('text', 'limit', $limit, 'edit', '', '', 2)).
+ tagRow('exclude_self',
+ yesno_pop('exclude_self', $exclude_self)).
+
tagRow('label',
fInput('text', 'label', ($label ? $label : gTxt('recent_articles')), 'edit', '', '', 20)).
@@ -1072,6 +1076,7 @@
'label',
'labeltag',
'limit',
+ 'exclude_self',
'sort',
'wraptag',
));
@@ -1093,6 +1098,9 @@
tagRow('limit',
fInput('text', 'limit', $limit, 'edit', '', '', 2)).
+ tagRow('exclude_self',
+ yesno_pop('exclude_self', $exclude_self)).
+
tagRow('label',
fInput('text', 'label', ($label ? $label : gTxt('recent_comments')), 'edit', '', '', 20)).
Index: setup/en-gb.php
===================================================================
--- setup/en-gb.php (revision 2503)
+++ setup/en-gb.php (working copy)
@@ -903,6 +903,7 @@
'decimals' => 'Display # numbers after the decimal point',
'default_title' => 'Text to use for default section link',
'exclude' => 'Exclude',
+ 'exclude_self' => 'Exclude current article',
'filename' => 'Name',
'file_download_tags' => 'File Downloads',
'flavor' => 'Syndication format',
Index: publish/taghandlers.php
===================================================================
--- publish/taghandlers.php (revision 2503)
+++ publish/taghandlers.php (working copy)
@@ -577,7 +577,7 @@
function recent_articles($atts)
{
- global $prefs;
+ global $prefs, $thisarticle;
extract(lAtts(array(
'break' => br,
'category' => '',
@@ -585,6 +585,7 @@
'label' => gTxt('recent_articles'),
'labeltag' => '',
'limit' => 10,
+ 'exclude_self' => '',
'section' => '',
'sort' => 'Posted desc',
'sortby' => '',
@@ -613,8 +614,13 @@
$categories = ($category) ? "and (Category1 = '".doSlash($category)."' or Category2 = '".doSlash($category)."')" : '';
$section = ($section) ? " and Section = '".doSlash($section)."'" : '';
+ $exclude = '';
+ if ($exclude_self && $thisarticle['thisid'])
+ {
+ $exclude = 'and id != ' . $thisarticle['thisid'];
+ }
$rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern',
- "Status = 4 $section $categories and Posted <= now() order by ".doSlash($sort).' limit 0,'.intval($limit));
+ "Status = 4 $section $categories and Posted <= now() $exclude order by ".doSlash($sort).' limit 0,'.intval($limit));
if ($rs)
{
@@ -639,18 +645,25 @@
function recent_comments($atts)
{
+ global $thisarticle;
extract(lAtts(array(
'break' => br,
'class' => __FUNCTION__,
'label' => '',
'labeltag' => '',
'limit' => 10,
+ 'exclude_self' => '',
'sort' => 'posted desc',
'wraptag' => '',
), $atts));
+ $exclude = '';
+ if ($exclude_self && $thisarticle['thisid'])
+ {
+ $exclude = 'and parentid != ' . $thisarticle['thisid'];
+ }
$rs = safe_rows_start('parentid, name, discussid', 'txp_discuss',
- 'visible = '.VISIBLE.' order by '.doSlash($sort).' limit 0,'.intval($limit));
+ 'visible = '.VISIBLE." $exclude order by ".doSlash($sort).' limit 0,'.intval($limit));
if ($rs)
{
Last edited by gemal (2007-07-25 13:50:24)
Offline
Re: Make recent_articles context aware (exclude self)
Some discussion between the developers, tonight :)
Offline
Re: Make recent_articles context aware (exclude self)
ruud wrote:
Some discussion between the developers, tonight :)
Any update?
Offline
Re: Make recent_articles context aware (exclude self)
ruud wrote:
Some discussion between the developers, tonight :)
Still waiting for an update :)
Offline
Re: Make recent_articles context aware (exclude self)
Sorry for the delay.
So far it looks like this won’t be accepted into the stable 4.0.x branch (no new features or attributes, just bugfixes), so it’ll have to wait for the 4.1 release. It’s not the final answer, but that’s all I can tell you right now.
Offline