Article summary list filtered by date

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
johan_further
Posts: 13
Joined: Thu 3. Jul 2008, 16:41

Article summary list filtered by date

Post by johan_further »

I've been asked to produce an event calendar to be displayed in a simple left hand pane on the front page of a client web site. The calendar must be easy to manage and should preferably blend in with the rest of the CMS.

My solution is to create a replacement tag that mimics the appearance of an article list but that filters the articles based on a date flag in the title of the article.

As snipped from the comments in the below code block:
"The function uses the TITLE of the article to filter the list. The first part
of the article name must be the date (Ymd) followed by the actual title. Date
and title must be delimited with a blank space " ".

Only articles with a title date higher than the one specified in the parameter
will be displayed. By setting the $date to "NOW" the **** will be done
using todays date as set on the server."

By implementing a replacement tag like this it is my intention to use the normal article functionality to provide what the users perceive as an event calendar. The only caveat I can see in this is to ensure that the users make sure to set the title of the article correctly, as there is nothing to enforce this by default in PHPWCMS.

To implement this feature, copy the below code to a file that you name something like rt_ARTICLE_LIST_BY_DATE.php and place it in the template/inc_script/frontend_renderer folder.

Invoke the functionality by placing the following replacement tag in your template or content part:
{ARTICLE_LIST_BY_DATE:id to page:date to filter by ('NOW' for todays date):class of the container div:the number of articles to display:a message to show when the list is empty}

Code: Select all

<?php
/* ======================================================================
A date based article summary display tag. Only shows articles with a title that
is more "recent" than the given date.

Replacement tag by Johan Strömquist, Further AB, 2008-07-08

========================================================================= */
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------

if(strpos($content["all"],'{ARTICLE_LIST_BY_DATE') !== false) { // TAG in use ?
	$content["all"] = preg_replace('/\{ARTICLE_LIST_BY_DATE:(.*?):(.*?):(.*?):(.*?)\}/ie', 'article_list_by_date("$1","$2","$3","$4")', $content["all"]);
}
// ----------------------------------------------------------------

function article_list_by_date($cat_id, $date, $class="", $limit="", $empty="") {
/* ======================================================================
Parameters:
	$cat_id		The id of the page from which articles are fetched
	$date		Only articles "newer" than this date are showed
	$class		The class for the container div
	$limit		An integer to limit the number of displayed articles
	$empty		A string to display in case the list is empty
	
	The function uses the TITLE of the article to filter the list. The first part
	of the article name must be the date (Ymd) followed by the actual title. Date
	and title must be delimited with a blank space " ".
	
	Only articles with a title date higher than the one specified in the parameter
	will be displayed. By setting the $date to "NOW" the **** will be done
	using todays date as set on the server.
========================================================================= */
	global $content;
	
	$empty = htmlentities($empty);
	if ($date == "NOW") $date = date("Ymd", time());

	$x_class_01 = '<div class="' . $class . '">';
	$x_class_02   = '</div>';
	$articleInfo = get_actcat_articles_data($cat_id);

	foreach ($articleInfo as $id => $article) {
		$title = explode(" ", $article["article_title"]);
		if (is_numeric($art_date = array_shift($title)) && $art_date > $date) {
			$title = implode(" ", $title);
			
			$replace .= "<div class = 'calDate'>" . $art_date . "</div>" .
						"<a href = '?aid=" . $id . "'>" .
						$title . 
						"</a><br />";
			if ($article["article_summary"]) $replace .= $article["article_summary"];
		}
		$counter ++;
		if ($counter > $limit - 1) break;
	}

	if (!$replace) $replace = $empty;
	
	$replace = $header . $x_class_01 . $replace . $x_class_02;
	
	return $replace;
}
?>
If this functionality is available elsewhere and with less fiddling, I am eager to know!

(Thanks to DF6IH for providing me with a working regexp! :D)
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Article summary list filtered by date

Post by Oliver Georgi »

Good idea, I will enhance teaser for filter option.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
yoshi001
Posts: 22
Joined: Sun 25. May 2008, 23:32
Location: Bodensee / Lake of Constance

Re: Article summary list filtered by date

Post by yoshi001 »

mit meinen bescheidenen, bzw. eher nicht vorhandenen php-kenntnissen stellt sich mir folgende frage:

lässt sich der im artikeltitel vorangestellte datumsschnipsel
für die ausgabe im frontend zu einem 'richtigen' datum à la 'd.m.Y' umformen,

oder aber das skript dahingehend anpassen, dass es artikel mit
einem datumsschnipsel à la 'd.m.Y' sortiert?

...

i apologize for having no php-skills (and bad english as well :roll: ):

is there a way to transform '$art_date' to a format like 'd.m.Y.'
or either a way to change the script to work with titles like 'd.m.Y.'?

...

es dankt im voraus..
thanks in advance..

yoshi
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Article summary list filtered by date

Post by Oliver Georgi »

1) ja, ohne Codeänderung: {DATE:d.m.Y lang=DE} - d.m.Y siehe http://php.net/date

2) Artikel im Listingmodus ja, Teaser ja

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
yoshi001
Posts: 22
Joined: Sun 25. May 2008, 23:32
Location: Bodensee / Lake of Constance

Re: Article summary list filtered by date

Post by yoshi001 »

danke oliver,
dass du dich meiner angenommen hast; noch dazu wegen fremder erweiterungen -
wenngleich ich dir teilweise nicht folgen kann..


1) es klappt für mich so (zeile 52):

Code: Select all

 $replace .= "<div class=\"calDate\">" .date("d.m.Y", strtotime($art_date)). "</div>" .
jetzt spuckt {ARTICLE_LIST_BY_DATE} das manuell dem titel vorangestellte datum im format 'd.m.Y' aus.
das datums-format weiter oben im skript (zeile 41) zu ändern, brachte keine änderung - deswegen mein post.
aber egal - jetzt tut's ja, was ich möchte.. :)

2) ich habe nach deinem posting nochmal genauer in teaser und listing hineingesehen.
allerdings will mir nicht eingehen wie ich das umsetzen könnte, dass ich artikel via listing und/oder teaser sortieren und ansteuern kann, wie mit diesem skript.. als - zwar rudimentär, aber doch terminbasiertes - listing mit voller phpwcms-funktionalität (also alle cp's und dateizentrale).

'vom rücken durch die brust ins auge' sozusagen - bis der kalender fertig ist.. :wink:


ich spiele hier mit der r248 auf MAMP /php 5.2.5 / mysql 5.0.41,
sämtliche datumsformate in 'conf.inc.php' und 'conf.template_default.inc.php' sind DE-konform.


gruss,
yoshi
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: Article summary list filtered by date

Post by flip-flop »

Aus meiner Sicht braucht es diesen RT nicht unbedingt.

Oliver meint mit dem Hinweise auf die Datumsformatierung die Möglichkeit, dass du auch in der Artikelbasisinformation direkt diesen Tag setzen kannst.
Z.B. {KILLDATE:d.m.Y lang=DE}
So würde das Verfallsdatum des Artikel ausgegeben und der Artikel wird ausgeblendet, wenn das Verfallsdatum erreicht ist.

Eine andere Möglichkeit bietet die Bearbeitung des Templates für die Artikellistenausgabe.
Hier kann der Tag {KILLDATE:d.m.Y lang=DE} auch direkt gesetzt werden ohne das der User ihn separat eingeben muss.

Allerdings ist in beiden Fällen darauf zu achten, dass der User diese Angaben in "Artikel von: [ ] bis: [ ] auch korrekt setzt (Das versteht sich eigentlich von selbst).
Und die Sortierung nach Enddatum eingestellt ist.
Um die anzeige ab einem bestimmten Datum zu erreichen muss das LIVEDATE (Anzeige von:) entsprechend gesetzt werden.

Im Teaser Template können LIVE/KILLDATE auch verwendet werden.

Wenn du den RT verwendest, ist deine Änderung schon richtig. (Wobei ch bei dem RT mit "global $content;" sicherheitstechnisch sehr hadere).

Der große Unterschied ist also die Art der Eingabe.

Knut
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
yoshi001
Posts: 22
Joined: Sun 25. May 2008, 23:32
Location: Bodensee / Lake of Constance

Re: Article summary list filtered by date

Post by yoshi001 »

vielen dank für deine ausführungen flip-flop - jetzt wird auch mir klar,
wie das gemeint und auch phpwcms-bordmitteln möglich ist.

spitzfindig darüber zu spekulieren, wozu der 'faule user' sich eher bewegen lässt:
den titel nach einer konvention zu vergeben oder artikel-basisdaten proper zu setzen.

weitergedacht sehe ich den vorteil mit diesem RT darin:

dass artikel ab eingabe/veröffentlichung sichtbar sind im frontend dynamisch mit '$date' und '$limit'
einem kalender gleich sortiert werden können.
also als eine art eventkalender die anzeige aller/einer anzhal termine im september oder oktober, etc.
auseinanderdividiert werden kann.


eher ein umweg - aber für mich die möglichkeit, endlich ein, zwei alte 1.2.6.'er installationen in die gegenwart zu portieren.
sollte das kalender-modul fertig werden, wird das dann sicherlich das mittel zum zweck sein. bis dahin sehe ich das hier als einzige alternative, möglichst komfortabel einen 'wysiwyg-eventkalender' direkt in/mit phpwcms zu verwenden.

oder ist mir entgangen, wie der 'ionrock-calendar' in 1.3.9. zum laufen gebracht werden kann?

dank & gruss,
yoshi
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: Article summary list filtered by date

Post by flip-flop »

Abgrenzen kannst du den Teaser z.B. mit:

Artikel:
-------------------------------------------------------
Artikel Basisinformation -> Schlüsselwört.: Jan
Artikel Basisinformation -> Schlüsselwört.: Feb
Artikel Basisinformation -> Schlüsselwört.: März
....

Teaser: (Sortierung Startdatum) (Enddatum (Killdate) wäre der Termin)
-------------------------------------------------------
Tag/Schlagwort: Jan (UND)
Tag/Schlagwort: Feb (UND)
Tag/Schlagwort: März (UND)
....

Es müssen natürlich 12 Teaser CPs erstellt werden.

Knut
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
yoshi001
Posts: 22
Joined: Sun 25. May 2008, 23:32
Location: Bodensee / Lake of Constance

Re: Article summary list filtered by date

Post by yoshi001 »

aha!?

12 hielten sich noch in grenzen - aber ich müsste niemanden belangen, der mir die skripterei dieses RT's zurechtbiegt.

bei der gelegenheit stellt sich mir gerade noch die frage, ob in in der ausgabe von '{KILLDATE:d.m.Y lang=DE}' jeweils 'tag', 'monat' und 'jahr' einzeln abfangen kann - um das ein bisschen übersichtlicher zu gestalten (neudeutsch: um das datum zu stylen)?

ich fürchte eher nicht.. das wäre zuviel hin- und hergebogen..


--
yoshi
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Article summary list filtered by date

Post by Oliver Georgi »

{KILLDATE:d lang=DE} {KILLDATE:m lang=DE} {KILLDATE:Y lang=DE}
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
yoshi001
Posts: 22
Joined: Sun 25. May 2008, 23:32
Location: Bodensee / Lake of Constance

Re: Article summary list filtered by date

Post by yoshi001 »

ausgezeichnet.. ich bin entzückt!

tausend dank euch beiden.

--
yoshi
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Article summary list filtered by date

Post by Oliver Georgi »

das lang=DE macht nur Sinn, wenn Du zum Beispiel mit dem Parameter F arbeitest: {KILLDATE:d. F Y lang=DE}

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Post Reply