Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-16 12:14:39

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Expired Articles: Finetuning

Handling of expired articles is very well since 4.0.7.
I mostly set “Publish expired articles?” Yes and handle visibility or design of expired articles by txp:if_expired.

But now I had some tasks where some more finetuning is needed:

Within my site expired articles are hidden on the frontpage but visible on subpages/archives. So far everything ok.

But on some pages I’d like to place a recent-articles-list (only titles) or an article-summary-list (title with additional elements) with a numerical limit.
The current behaviour includes expired articles within the limit if publish_expired_articles is ‘yes’.
Thus – if expired articles are sequently hidden – the number of visible articles is less than the limit.
(e.g. Label: “10 recent articles:” Article-Limit: 10, 6/10 articles live, 4/10 articles live but expired and not output. Output: 6 Articles.)

So – obviously – I will need an article/recent_articles tag/query which treats expired articles as not be published (only in this case, not as a preference).
Sidefeature: Also sometimes it even could be a useful feature to list only expired articles, without counting the other ones.

New Attribute
Instead of making a plugin and using a different tag for article/recent_articles in this case
I’d like to propose an attribute for txp:article, txp:recent_articles and txp:related_articles:

Attribute name: “selectexpired” Attribute values:
  • “ignore”: Will exclude expired articles (alternative term “skip”?)
  • “only”: Will return only expired articles.
    Relation to Expired-Preference:
    Both attribute values only have an effect, if publish_expired_articles is ‘yes’.
    If publish_expired_articles is ‘no’ expired articles are completely excluded.
  • (It could be discussed if there should be an analogous attribute-value which generates an exception to the No-Preference: e.g. selectexpired=“include” – but at the moment I think “No” should be “No”. If needed, the preference has to be changed to yes and subsequent tags adapted. … On the other hand: It would be easier to place a selectexpired=“include” attribute once, if you’ll need a single exception in a later step of site development. Thoughts?).

Working code so far:
changes in textpattern/publish.php (rev3050/4.0.8):

line 580

'time'      => 'past',

new:

'time'      => 'past',
'selectexpired'   => '',

line 683-685

if (!$publish_expired_articles) {
$time .= " and (now() <= Expires or Expires = ".NULLDATETIME.")";
}

new:

if (!$publish_expired_articles or $selectexpired=='ignore') {
$time .= " and (now() <= Expires or Expires = ".NULLDATETIME.")";
}
if ($publish_expired_articles and $selectexpired=='only') {
$time .= " and (now() > Expires and Expires != ".NULLDATETIME.")";
}

changes in publish/taghandlers.php (rev3078/4.0.8)
line 591

'limit'    => 10,

new:

'limit'    => 10,
'selectexpired'   => '',

line 620

$expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= Expires or Expires = '.NULLDATETIME.') ';

new:

$expired = (!$prefs['publish_expired_articles'] or $selectexpired=='ignore') ? ' and (now() <= Expires or Expires = '.NULLDATETIME.') ' : '';
$expired = ($prefs['publish_expired_articles'] and $selectexpired=='only') ? ' and (now() > Expires and Expires != '.NULLDATETIME.') ' : $expired;

line 728

'limit'    => 10,

new:

'limit'    => 10,
'selectexpired'   => '',

line 780

$expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= Expires or Expires = '.NULLDATETIME.') ';

new:

$expired = (!$prefs['publish_expired_articles'] or $selectexpired=='ignore') ? ' and (now() <= Expires or Expires = '.NULLDATETIME.') ' : '';
$expired = ($prefs['publish_expired_articles'] and $selectexpired=='only') ? ' and (now() > Expires and Expires != '.NULLDATETIME.') ' : $expired;

In my installs this is working so far.
But I may have missed something important.
Any comments and thoughts?

Last edited by saccade (2009-05-16 16:29:24)

Offline

#2 2009-05-16 14:54:37

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Expired Articles: Finetuning

+1.
I was thinking about this a few days ago, although not as deep and with such technical details as you did, saccade.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2009-05-16 15:29:32

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Expired Articles: Finetuning

saccade wrote:

(Help needed: How do I get those nice broken lines around the code?)

Start the first line of code with bc. (plus a space) or bc.. for extended code blocks (with blank lines in it). An extended code block needs to be escaped by starting the next paragraph with p. .

(How do I post tags and code on the forum?)

Offline

#4 2009-07-07 09:40:20

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Expired Articles: Finetuning

If you want to have a symmetrical function (see note above) that can include “expireds” when publish_expired_articles is off or excludes if it is on and also makes an only -list the following patch (based on r3239) should work:

Usage:
An additional attribute, named “selectexpired” with four values:

  1. empty: don’t modify the preference setting
  2. “include”: includes expireds, even if “publish_expired_articles” is off.
  3. “ignore”: ignores expired articles – even if you publish them otherwise
  4. “only”: selects only expired articles, ignores preference

It is important that these attributes are to be used as exceptions. You should first choose the appropriate preference for the main handling of expired articles on your site – also according to what you want the feeds to publish.
Normally you can filter out expired articles by the if_expired-tags.
But when it comes to correct calculation of article-limits this attribute will help.

--- D:\werkstatt\Webdesign\Textpattern\Releases\3239\textpattern\publish.php 
+++ D:\werkstatt\Webdesign\Textpattern\Releases\3239-sac2\textpattern\publish.php 
@@ -581,6 +581,7 @@
 			'frontpage' => '',
 			'id'        => '',
 			'time'      => 'past',
+			'selectexpired' => '',
 			'status'    => '4',
 			'pgonly'    => 0,
 			'searchall' => 1,
@@ -683,8 +684,11 @@
 			default:
 				$time = " and Posted <= now()";
 		}
-		if (!$publish_expired_articles) {
+		if ((!$selectexpired and !$publish_expired_articles) or $selectexpired=='ignore') {
 			$time .= " and (now() <= Expires or Expires = ".NULLDATETIME.")";
+		}
+		if ($selectexpired=='only') {
+			$time .= " and (now() > Expires and Expires != ".NULLDATETIME.")";
 		}

 		$custom = '';


--- D:\werkstatt\webdesign\textpattern\Releases\3239\textpattern\publish\taghandlers.php 
+++ D:\werkstatt\webdesign\textpattern\Releases\3239-sac2\textpattern\publish\taghandlers.php 
@@ -603,6 +603,7 @@
 			'label'    => gTxt('recent_articles'),
 			'labeltag' => '',
 			'limit'    => 10,
+			'selectexpired' => '',
 			'section'  => '',
 			'sort'     => 'Posted desc',
 			'sortby'   => '',
@@ -631,7 +632,8 @@
 		$category   = join("','", doSlash(do_list($category)));
 		$categories = ($category) ? "and (Category1 IN ('".$category."') or Category2 IN ('".$category."'))" : '';
 		$section = ($section) ? " and Section IN ('".join("','", doSlash(do_list($section)))."')" : '';
-		$expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= Expires or Expires = '.NULLDATETIME.') ';
+		$expired = ((!$prefs['publish_expired_articles'] and !$selectexpired) or $selectexpired=='ignore') ? ' and (now() <= Expires or Expires = '.NULLDATETIME.') ' : '';
+		$expired = ($selectexpired=='only') ? ' and (now() > Expires and Expires != '.NULLDATETIME.') ' : $expired;

 		$rs = safe_rows_start('*, id as thisid, unix_timestamp(Posted) as posted', 'textpattern',
 			"Status = 4 $section $categories and Posted <= now()$expired order by ".doSlash($sort).' limit 0,'.intval($limit));
@@ -740,6 +742,7 @@
 			'label'    => '',
 			'labeltag' => '',
 			'limit'    => 10,
+			'selectexpired' => '',
 			'match'    => 'Category1,Category2',
 			'no_widow' => @$prefs['title_no_widow'],
 			'section'  => '',
@@ -791,7 +794,8 @@

 		$section = ($section) ? " and Section IN ('".join("','", doSlash(do_list($section)))."')" : '';

-		$expired = ($prefs['publish_expired_articles']) ? '' : ' and (now() <= Expires or Expires = '.NULLDATETIME.') ';
+		$expired = ((!$prefs['publish_expired_articles'] and !$selectexpired) or $selectexpired=='ignore') ? ' and (now() <= Expires or Expires = '.NULLDATETIME.') ' : '';
+		$expired = ($selectexpired=='only') ? ' and (now() > Expires and Expires != '.NULLDATETIME.') ' : $expired;
 		$rs = safe_rows_start('*, unix_timestamp(Posted) as posted, unix_timestamp(LastMod) as uLastMod, unix_timestamp(Expires) as uExpires', 'textpattern',
 			'ID != '.intval($id)." and Status = 4 $expired  and Posted <= now() $categories $section order by ".doSlash($sort).' limit 0,'.intval($limit));

Offline

#5 2009-07-07 14:27:29

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Expired Articles: Finetuning

Great, now we have to put this thread on wet’s radar. Maybe reporting an enhancement issue?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2009-07-07 15:32:59

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: Expired Articles: Finetuning

A solution for now, until (if?) this becomes a core feature, is to use my soo_article_filter plugin.


Code is topiary

Offline

#7 2009-07-09 07:40:19

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: Expired Articles: Finetuning

The idea is compelling.

Onto the details, therefore:

Looking at jsoo’s plugin, the attribute values used there (expired="none"|"any"|"past"|"future"|""|"solely") sound more “Textpatternish”. The implied semantics match with the desired behaviour, and even extend it. Opinions?

Offline

#8 2009-07-09 08:31:26

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Expired Articles: Finetuning

Thanks!

“None”, “any” and “solely” is ok in my point of view. And “expired” of course.

The only thing I think about is marking the relation to the overall setting publish_expired_articles.
I chose the term “selectexpired” to mark a somewhat special behaviour and leave the priority to the preference setting.

We still have to mark that there is a relation to the preference (because of the feeds).
I’m afraid a little if the attribute is “expired” a lot of people might only see this attribute-way of dealing with expired’s as the only way and miss the preference – and run into questions if looking closer at the feeds.
But that just are thoughts of interface.

I have to take a closer look to “past” and “future” first. Not yet didn’t grasp the function. (And at my first attempt didn’t want to make the attribute and additional code too complicated.)
Will report later – but have some business to do first.

Offline

#9 2009-07-09 09:44:37

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Expired Articles: Finetuning

Ok, what I understand so far:
My attempt dealt with “expireD” and jsoo’s with “expireS” (where “past” is the expireD subset of expiring articles).
A combination would be comprehensive.

What we have so far (not yet mixed):

1. (sac) “include” = include expireD articles within the given query (whether expires defined or not).
2. (sac) “ignore” = ignore expireD articles, but include the rest (with or without expiration).
3. (sac) “only” = only expireD articles within the given query
4. (sac) empty = do what publish_expired_articles says.

5. (jsoo) “any” = only articles with an expireS-value, regardless if expireD
6. (jsoo) “past” = only expireD articles
7. (jsoo) “future” = only articles with an expireS-value not yet expireD
8. (jsoo) “0” = only articles which don’t have an expiration-date
9. (jsoo) empty = do what publish_expired_articles says.

Only 3. and 6. (and 4./9.) are really the same.

I hope I did understand the behaviour of jsoo’s plugin right. If not, please help.

Last edited by saccade (2009-07-09 09:56:58)

Offline

#10 2009-07-09 09:47:32

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Expired Articles: Finetuning

@wet:
“None” and “solely” is what you would rename the options “ignore” and “only”?
I didn’t find them in jsoo’s plugin – or did you use another version?

Offline

#11 2009-07-09 10:06:01

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: Expired Articles: Finetuning

I’ve expanded the set, and I’m thinking of a consolidation of both proposed semantics like so:

  • “any”: Display all articles which match the other criteria (section etc.) regardless of the state of the publish_expired_articles prefs and which expiry datestamp is assigned to the article, even if it isn’t assigned any expiry date at all.
  • “past”: Display all articles which match the other criteria regardless of the state of the publish_exirepd_articles prefs and which are expired.
  • “future”: Display all articles which match the other criteria regardless of the state of the publish_expired_articles prefs and which are not expired.
  • “solely”: Display all articles which match the other criteria regardless of the state of the publish_expired_articles prefs and have an expiry datestamp.
  • “none”: Display all articles which match the other criteria regardless of the state of the publish_expired_articles prefs and do not have an expiry datestamp.
  • “”: Default behaviour as in TXP 4.0.7/4.0.8.

Offline

#12 2009-07-09 10:20:05

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Expired Articles: Finetuning

Perfectly!! Very reasonable! Thanks!

Offline

Board footer

Powered by FluxBB