{LAST UPDATED} Site/Section

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

{LAST UPDATED} Site/Section

Post by jsw_nz »

Had a requirement to display info on the home page for last site wide update and last update for several sections. So I took existing code and tweaked it little. Placing get_last_update.php in frontend_render directory allows following tags to work:

Code: Select all

<?php
// {LAST UPDATED} Returns the last time site was updated
// {LAST UPDATED:categoryID}  Returns the last time section was updated

function get_newest_update($template_default, $cat, $dbcon) {
	$cat = intval($cat);
	if($cat){
		$appendString="Section Last Updated: ";
	}else{
		$appendString="Site Last Updated: ";
	}
	$cat = ($cat) ? 'article_cid='.intval($cat).' AND ' : '';
	$sql = "SELECT article_id, article_title, article_cid, UNIX_TIMESTAMP(article_tstamp) AS article_date ".
			"FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat.
			"article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ".
			"article_begin < NOW() AND article_end > NOW() ".
			"ORDER BY article_tstamp DESC LIMIT 1";
	$updated = "";
	if($result = mysql_query($sql, $dbcon)) {
		while ($row = mysql_fetch_row($result)) {
			$update_date = html_specialchars(international_date_format
        ($template_default["date_language"], "j F Y", $row[3]));
			$updated .= $appendString.$update_date;
		}
		mysql_free_result($result);
	}
	return $updated;
}
if(!( strpos($content["all"],'{LAST UPDATED:')===false ) ) {
	$content["all"] = preg_replace('/\{LAST UPDATED:{0,1}(\d*)\}/e','get_newest_update($template_default["news"],"$1",$db);',$content["all"]);
}
?>
returns strings looking like these:

Site Last Updated: 15 April 2005
Section Last Updated: 11 April 2005
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

Very cool. thank you
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Cheers Isac,

Basically the code is a simplified derivation of the get_new_articles() in front.func.inc.php. Unfortunately the $appendString needs to be hard-coded to your language requirement, which I think is Portuguese - :D ). Ideally this string could reside in the inc_lang/backend folder, but for purposes of declaring the entire tag inside the frontend_render folder, this may be more work than it is worth. The date returned is also hard coded "j F Y", although is does use the "date_language" parameter.

Real thanks goes to OliG...again...for providing the frontend_render scheme, making such additions very easy.
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Hi jsw_nz
please post your REPTAG on the dev forum on the following area
--...--/index.php/board,1.0.html

please note the formatting of finished REPTAGS for easy info for other users...
see this for an example
--...--/index.php/topic,95.0.html

regards
TriP
brans

Post by brans »

I have added the tag to our list
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Post by pepe »

Hallo jsw_nz,

ich habe den code nach der Vorgabe eingebunden, aber ohne Erfolg.
Es wird kein Datum angezeigt und alle Umlaute ( ä ü ö Ä Ö Ü ) sind verschwunden?

Was kann ich tun?

I have put in the code following the example, but without success.
No date is announced and all "Umlaute" vowel mutations? ( ä ö ü Ä Ö Ü ) have disappeared?

What can I do?
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Pepe,

Not sure why it is not returning German results?
I changed language settings in both
conf.inc.php & conf.template_default.inc.php myself
and had same issue

So while you hard code
Site last updated:
Section last updated:

to german equivalents....

might want to change:

Code: Select all

$update_date = html_specialchars(international_date_format
($template_default["date_language"], "j F Y", $row[3]));
to:

Code: Select all

$update_date = html_specialchars(international_date_format("DE", "j F Y", $row[3]));
...got to be a reason for this 'date_language' parameter quirk....will get back....I might have stripped out a necessary parameter. Just sent Oliver an email, since this code draws on his get_new_articles () method.

:o
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

That date parameter comes from line 209 of conf.template_default.inc.php:

Code: Select all

$template_default["news"]["date_language"]
so I changed the date parameter to the global setting for language,
which will require no edits (conf.inc.php)

Code: Select all

$phpwcms["default_lang"]
This should be the easiest way to implement on single language site. Thinking about impementing a language parameter for multi-language sites. Will run this idea past Pappnase. Thanks to some help from Cyrano, I was able to locate a bug in the code, so I am posting this modification.

To get "Site Last Updated" info now use {LAST UPDATED:0}
instead of {LAST UPDATED}

So here is the newly edited snippet:

Code: Select all

<?php 
// {LAST UPDATED:0} Returns the last time site was updated
// {LAST UPDATED:X}  Returns the last time section X was updated 
// Where X is = PhpWcms Category ID Integer
// SAMPLE USAGE: 
// {LAST UPDATED:0} >> Site Last Updated: 12 April 2005
// {LAST UPDATED:4} >> Section Last Updated: 10 April 2005

function get_newest_update($language, $cat, $dbcon) { 
   $cat = intval($cat); 
   if($cat!=0){ 
      $appendString="Section Last Updated: "; 
   }else{ 
      $appendString="Site Last Updated: "; 
   } 
   $cat = ($cat!=0) ? 'article_cid='.intval($cat).' AND ' : ''; 
   $sql =   "SELECT article_id, article_title, article_cid, UNIX_TIMESTAMP(article_tstamp) AS article_date ". 
         "FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat. 
         "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ". 
         "article_begin < NOW() AND article_end > NOW() ". 
         "ORDER BY article_tstamp DESC LIMIT 1"; 
   $updated = ""; 
   if($result = mysql_query($sql, $dbcon)) { 
      while ($row = mysql_fetch_row($result)) { 
         $update_date =    html_specialchars(international_date_format($language, "j F Y", $row[3])); 
         $updated .= $appendString.$update_date; 
      } 
      mysql_free_result($result); 
   } 
   return $updated; 
} 
if(!( strpos($content["all"],'{LAST UPDATED:')===false ) ) { 
   $content["all"] = preg_replace('/\{LAST UPDATED:{0,1}(\d*)\}/e','get_newest_update($phpwcms["default_lang"],"$1",$db);',$content["all"]); 
} 
?>
Brans, Trip I have updated dev listing as well.

Cheers, :)
Last edited by jsw_nz on Fri 29. Apr 2005, 23:36, edited 2 times in total.
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

:D
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Hi John,

I added your new script,
{LAST UPDATED:0}works, {LAST UPDATED:categoryID} shown as Tag is.

hmm, will try and play a little bit.
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Cyrano,

The CategoryID should end up being an integer in your final implementation, so for example:

//for last update site wide, code would be
{LAST UPDATED:0}

//last update for category ID 4, code would be
{LAST UPDATED:4}

I ran these on my localhost and they returned these strings, respectively:

Site Last Updated: Friday 29 April 2005
Section Last Updated: Friday 15 April 2005

So give this a go.....all best :D

Great set of new Italian pix
cyrano
Posts: 1598
Joined: Sat 31. Jan 2004, 18:33
Location: Stuttgart
Contact:

Post by cyrano »

Cheers John,

ah OK, I thought the script will find by itselfs the category ID and changes/display last edited entry.

Ok, so then it will work :-)

New italian photos? haven't updated them since i went back from italy.

Love the blue boat pix.

All the best
Gruß/ regards cyrano
--------------------------------------------------------
templates -> http://www.128.weitzelmedia.de
planepix -> http://www.planepix.de
XING -> https://www.xing.com/profile/Thomas_Weitzel3
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Cyrano,
I updated the comments inside the code to make it a little clearer.

Code: Select all

// {LAST UPDATED:X}  Returns the last time section X was updated 
// Where X is = PhpWcms Category ID Integer
Can understand your confusion.
My apologies.

With regards to pix, yes I was referring to those you did a few months back at that lake resort. Very nice....also the Venice photos are really awesome. Looking forward to your next batch. All best.... :D
Tooms
Posts: 12
Joined: Sat 16. Jul 2005, 20:04

Post by Tooms »

Okay, with this mod it's possible to show the date of the last updated section and the whole website. Is it also possible to show the last update of a specific article? For example:

Last Changes: 2005/07/09

The documentation http://www.phpwcms-docu.de uses this RT at the right side of the bottom. How can I realize this?
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Tooms,

Welcome to the forums:

With regards to providing the last update of an article use:
{DATE_ARTICLE}
To display dates in other languages you must edit: config/phpwcms/conf.template_default.inc.php
$template_default["date"]["language"]="EN"; default
http://www.phpwcms-docu.de/index.php?article_tags


With regards to providing the date when article was created use:
{WAK_ARTICLE_CREATED}
(custom_rep_tag): for instructions see:
--...--/index.php/topic,74.0.html

hope this helps :D
Post Reply