How can we mark new articles with a "NEW" label?

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

How can we mark new articles with a "NEW" label?

Post by Nik2004 »

Hi.

I would like the system to automatically add a "NEW" (or other customizable) text label or icon, next to ALL newly added or edited articles/categories, for a specified period.

For example, when I add a new article, I want for one week a label "NEW" next to it, so people know that this is new material in the site.

Likewise, when I add a new category, I want for, e.g. a week, a label "NEW" next to the menu line for this category, so that can people can directly recognize new material.

Can this be done somehow and if yes, how??
Pappnase

Post by Pappnase »

Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

About isNew.php

Post by Nik2004 »

Thanks Pappnase for your reply.

I read the thread you sent me. However, I would like to ask:

1. The code posted at that thread is the whole content of a file named isNew.php ?
2. So, I can create a file named isNew.php with that content, but where do I put isNew.php?
3. Do I need to modify any other files of phpwcms?
4. Does it work with phpwcms_1.1-RC4_2004-06-22 ?

Thanks for your help.
jscholtysik

Post by jscholtysik »

Hi Nik2004,


if you want to use the isNew.php file, look into the folder

phpwcms_template/inc_script/frontend_render.

this file is already in there. The only thing is that you have to rename the existing file from isNew.php_ to isNew.php. That's all!


Joachim
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

File is NOT already there!

Post by Nik2004 »

Sorry, folder phpwcms_template/inc_script does not exist in phpwcms_1.1-RC4_2004-06-22.

Is there a way I can use the script in my version and how ? (It's too difficult to upgrade in my case.)

Thanks for your reply, anyway.
jscholtysik

Post by jscholtysik »

Hi Nik2004,


unfortunately not, I think, the frontend_render and frontend_init folders have been introduced after the 1.1-RC4 release... :-(

Upgrading to the lastest version 1.2.6 is not that diffcult, why not trying it? What are the problems?


Joachim
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

Upgrade dificult!

Post by Nik2004 »

Due to many modified pieces of code for better support of greek and many other changes which I don't know if the new version supports them! See my thread: http://www.phpwcms.de/forum/viewtopic.php?t=10582

Thanks for your interest.
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

To support using the replacement tag ...just add *another* modification to your list...

In "content.func.inc.php" choose a similar and easy to FIND place such as:

Code: Select all

// include external HTML page but only part between <body></body>
$content["all"] = preg_replace('/\{URL:(.*?)\}/ie', 'include_url("$1");', $content["all"]);

// -------------------------------------------------------------
REPLACE with:

Code: Select all

// include external HTML page but only part between <body></body>
$content["all"] = preg_replace('/\{URL:(.*?)\}/ie', 'include_url("$1");', $content["all"]);

// -------------------------------------------------------------

// include isNew image at location of replacement tag with format {D:startdate,duration,imagename}
$content["all"] = preg_replace('/\{D:(.*?)\}/ie', 'myRT1("$1")', $content["all"]);

// -------------------------------------------------------------
AND in "front.func.inc.php" FIND:

Code: Select all

// -------------------------------------------------------------

function include_url($url) {
	// include given URL but only take content between <body></body>
	
	$k = '';
	$url = trim($url);
	if($url && function_exists('file_get_contents')) {
		$GLOBALS['include_urlparts'] = parse_url($url);
		if(isset($GLOBALS['include_urlparts']['path']) && $GLOBALS['include_urlparts']['path']) {
			$GLOBALS['include_urlparts']['path'] = dirname($GLOBALS['include_urlparts']['path']);
			$GLOBALS['include_urlparts']['path'] = str_replace("\\", '/', $GLOBALS['include_urlparts']['path']);
		}
		$k = @file_get_contents($url);
		$k = preg_replace("/.*<body[^>]*?".">(.*?)<\/body>.*/si", "$1", $k);
		$k = str_replace('<?', '<?', $k);
		$k = str_replace('?>', '?>', $k);
		$k = str_replace('<%', '<%', $k);
		$k = str_replace('%>', '%>', $k);
		//$k = preg_replace_callback('/(href|src|action)=[\'|"](.*?)[\'|"]/i', 'make_absoluteURL', $k);
		$k = preg_replace_callback('/(href|src|action)=[\'|"]{0,1}(.*?)[\'|"]{0,1}( .*?){0,1}>/i', 'make_absoluteURL', $k);
		$GLOBALS['include_urlparts'] = '';
	}
	return $k;
}

// -------------------------------------------------------------
and REPLACE with:

Code: Select all

// -------------------------------------------------------------

function include_url($url) {
	// include given URL but only take content between <body></body>
	
	$k = '';
	$url = trim($url);
	if($url && function_exists('file_get_contents')) {
		$GLOBALS['include_urlparts'] = parse_url($url);
		if(isset($GLOBALS['include_urlparts']['path']) && $GLOBALS['include_urlparts']['path']) {
			$GLOBALS['include_urlparts']['path'] = dirname($GLOBALS['include_urlparts']['path']);
			$GLOBALS['include_urlparts']['path'] = str_replace("\\", '/', $GLOBALS['include_urlparts']['path']);
		}
		$k = @file_get_contents($url);
		$k = preg_replace("/.*<body[^>]*?".">(.*?)<\/body>.*/si", "$1", $k);
		$k = str_replace('<?', '<?', $k);
		$k = str_replace('?>', '?>', $k);
		$k = str_replace('<%', '<%', $k);
		$k = str_replace('%>', '%>', $k);
		//$k = preg_replace_callback('/(href|src|action)=[\'|"](.*?)[\'|"]/i', 'make_absoluteURL', $k);
		$k = preg_replace_callback('/(href|src|action)=[\'|"]{0,1}(.*?)[\'|"]{0,1}( .*?){0,1}>/i', 'make_absoluteURL', $k);
		$GLOBALS['include_urlparts'] = '';
	}
	return $k;
}

// -------------------------------------------------------------

function myRT1($rtinfo) { 

   $dateImage = ''; 
   $rtinfo = explode(',', $rtinfo); 
   $startDate = strtotime($rtinfo[0]); 
   $timeout = isset($rtinfo[1]) ? intval($rtinfo[1]) : 0; 
   $timeout = $timeout * 24 * 3600; 

   if(time() - $timeout < $startDate) { 
      $dateImage = '<img src="picture/myRT1/'.$rtinfo[2].'" alt="'.$rtinfo[0].'" border="0">'; 
   } 

   return $dateImage; 
}

// -------------------------------------------------------------
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

How we use the tag with articles?

Post by Nik2004 »

Thank you all guys for your prompt reply and for all the support.

I have done these changes, then placed the tag in the category title, and it works! Great.

Yet, how I can use the tag (or modify something) so that the "NEW" icon is automatically placed next to ALL articles (that satisfy a date condition of course) included in a category WITHOUT having to modify the title of each?

In essence, what I would like to do is to automatically make all articles include in their title the {D:...} tag with start date the last_edit_date of each article. What should I do???

I would like to have the icon displayed next to article title in the category list of articles (which is always displayed when a visitor goes to the category page and also in artlicle lists produced by the following tag: {NEWCATID:X:X}.
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Do you mean like was suggested by OliverG for applying GT Mod to all article titles??

http://www.phpwcms.de/forum/viewtopic.php?p=23450#23450
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

{D:...} In all article titles

Post by Nik2004 »

Thanks Dexxus,

I see that I can use tags in article templates. Unfortunately, I am using many templates, so I have to modify things in many, I guess. But this is the solution, thanks.

I hope I'll have things working soon.
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

Can a date parameter be used in {D:...} tag?

Post by Nik2004 »

Please, would someone know: In the {D} tag, for example in {D:2005/9/4,30,newR.gif}, can I use a variable/parameter instead of a particular date?

In particular:
If I use the {D} tag in an article template (in the title) or in:

Code: Select all

$template_default["article"]["title_before"]		= '<span class="articleHead">';
$template_default["article"]["title_after"]			= ' {D:start_date,30,newR.gif} </span>';
...Can I somehow reference the article date as a start_date in the {D} tag, so that periods of displaying the NEW icon count automatically from the date each article was last edited?

Otherwise, if I use the same hard-coded date in an article template, all articles would appear new for the same period, which is not true.

Thanks for all the help.
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Just a WILD guess.
I wonder if you could get by with using {DATE_ARTICLE} embedded in your other Rep Tag somehow? Like:

Code: Select all

$template_default["article"]["title_before"]      = '<span class="articleHead">'; 
$template_default["article"]["title_after"]         = ' {D:{DATE_ARTICLE},30,newR.gif} </span>'; 
You would UNDO and REDO like this: ( moves {D:startdate,duration,imagename} Rep Tag "parsing" to right after {DATE_ARTICLE} "parsing" ):
In "content.func.inc.php"
REPLACE:

Code: Select all

// date replacement
if( ! ( strpos($content["all"],'{DATE_')===false ) ) {
	$content["all"] = str_replace('{DATE_LONG}',    international_date_format($template_default["date"]["language"], $template_default["date"]["long"]),   $content["all"]);
	$content["all"] = str_replace('{DATE_MEDIUM}',  international_date_format($template_default["date"]["language"], $template_default["date"]["medium"]), $content["all"]);
	$content["all"] = str_replace('{DATE_SHORT}',   international_date_format($template_default["date"]["language"], $template_default["date"]["short"]),  $content["all"]);
	$content["all"] = str_replace('{DATE_ARTICLE}', international_date_format($template_default["date"]["language"], $template_default["date"]["article"],   $content["article_date"]),  $content["all"]);
}

// -------------------------------------------------------------
WITH:

Code: Select all

// date replacement
if( ! ( strpos($content["all"],'{DATE_')===false ) ) {
	$content["all"] = str_replace('{DATE_LONG}',    international_date_format($template_default["date"]["language"], $template_default["date"]["long"]),   $content["all"]);
	$content["all"] = str_replace('{DATE_MEDIUM}',  international_date_format($template_default["date"]["language"], $template_default["date"]["medium"]), $content["all"]);
	$content["all"] = str_replace('{DATE_SHORT}',   international_date_format($template_default["date"]["language"], $template_default["date"]["short"]),  $content["all"]);
	$content["all"] = str_replace('{DATE_ARTICLE}', international_date_format($template_default["date"]["language"], $template_default["date"]["article"],   $content["article_date"]),  $content["all"]);
}

// -------------------------------------------------------------

// include isNew image at location of replacement tag with format {D:startdate,duration,imagename}
$content["all"] = preg_replace('/\{D:(.*?)\}/ie', 'myRT1("$1")', $content["all"]);

// -------------------------------------------------------------
NOTE: Even just moving to anywhere after the {DATE_ARTICLE} code in "content.func.inc.php" would suffice.
Nik2004
Posts: 132
Joined: Mon 9. Aug 2004, 14:31
Location: Athens,Greece

{DATE_ARTICLE} nested in {D:start_date,duration,image}

Post by Nik2004 »

Thanks DeXXus,

Your trick worked! I did in:

Code: Select all

$template_default["article"]["title_after"]			= ' {D:{DATE_ARTICLE},30,new_icon1.gif} </span>';
But the NEW icon appears only in the full article listing and nowhere else. For example see (I know you cannot read greek, but you'll see what I mean): http://www.unborn.gr/unborn1/unborn/ind ... 93,0,0,1,0
(the NEW icon appears next to the title).

However the NEW icon does not appear next to the article title in the category: http://www.unborn.gr/unborn1/unborn/ind ... rentevents (it is the first article, the only one which appears with a summary)

What should I change so that the NEW icon is displayed in the article title when the category is displayed (both when the article is displayed with a summary and when it is displayed only in the list)?

Additionally, the NEW icon is not displayed when a list is displayed using the {NEWCATID:X:X}. See: http://www.unborn.gr/unborn1/unborn/index.php (it is the article with this title: "8.3.2006 - Ίδρυση του Συλλόγου Προστασίας Αγέννητου Παιδιού Πτολεμαΐδος" (it appears without a NEW icon).

What should I change to make the icon appear here as well?

Also, one question: what is exactly the DATE_ARTICLE? The article_creation_date or the Last_Edit_date?
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Post by pepe »

Have you tried, to put that code:

{D:{DATE_ARTICLE},30,new_icon1.gif}

into the article.tmpl ? Don't now, if it works, but would give it a chance.
Post Reply