PEAK XOOPS - Re: About "new" in englishin japanese

Re: About "new"

List posts in the topic

normal Re: About "new"

msg# 1.1.1.1.2.1.1
depth:
6
Previous post - Next post | Parent - No child | Posted on 2005/4/10 5:31
GIJOE  ÀèǤ·³Áâ   Posts: 4110
hi efla.

This is a hacked version which has adaptation to both Y-m-d and d-m-Y.
(Of course, Y-n-j, Y/n/j, j-n-Y, j/n/Y are all OK).

But, short year (2 digits) and m-d-Y is no good.
That's because the script can't judge which field is year or month or date.


<?php
// $Id: modifier.ryus_date.php,v 1.1 2003/12/06 08:20:49 Ryuji Exp $
// FILE		::	modifier.ryus_date.php
// AUTHOR	::	Ryuji AMANO <info@joetsu.info>
// WEB		::	Ryu's Planning <http://ryus.joetsu.info/>
//

function smarty_modifier_ryus_date($string, $format="", $withNew = true)
{
	if($format != ""){
		switch($format){
		  case "M":
			$format = "n/j H:i";
			break;
		  case "S":
			$format = "n/j";
			break;
		  default:
		}
	}

	//global $xoopsUser;
	$now = xoops_getUserTimestamp(time(), "");

	if($string != '') {
		if( preg_match( '/^([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})(.*)$/' , $string , $matches ) ) {
			$time = strtotime( "{$matches[3]}-{$matches[2]}-{$matches[1]} {$matches[4]}" ) ;
		} else {
			$time = strtotime($string);
		}
	}else{
		return;
	}
	if($withNew){
		$NewMarks = array(
			1*60*60*24 => ' <span class="new1">New!</span>',
			7*60*60*24 => ' <span class="new2">New</span>'
			);

		$erapse = $now - $time;
		$new = "";
		foreach ($NewMarks as $limit=>$tag) {
			if ($erapse <= $limit){
				$new .= $tag;
				break;
			}
		}
	}else{
		$new = "";
	}
	if($format == ""){
		$retvar = $string . $new;
	}elseif(strtolower($format) == "new"){
		$retvar = $new;
	}else{
		$retvar = date($format, $time) . $new;
	}

	return $retvar;
}

?>
Votes:0 Average:0.00

Posts tree

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!