I'm developing a small script for a game I play occasionally and I've got a link to the development version of the script up in their forum for people to upload test data. I wanted to add a little marker on the bottom of the script that tells them how long ago the script was modified so I don't have to keep updating the forum thread with bug updates except for when something major has changed.
This is what I came up with. I know the get_included_files function includes the name of the files included/required as well as the file that did all of that including.
Anyone see any problems ?
$oldest_include = 0;
foreach(get_included_files() as $key => $val)
{
$oldest_include = max($oldest_include, filemtime($val));
}
printf('<p class="info">beta code last modified: %1$s ago.</p>', new rough_age(time() - $oldest_include));
- $oldest_include = 0;
- foreach(get_included_files() as $key => $val)
- {
- $oldest_include = max($oldest_include, filemtime($val));
- }
- printf('<p class="info">beta code last modified: %1$s ago.</p>', new rough_age(time() - $oldest_include));
Here's the source for that
rough_age class.
class rough_age
{
public $size;
protected static $suffixes = array(
'Years' => '31536000',
'Months' => '2592000',
'Weeks' => '604800',
'Days' => '86400',
'Hours' => '3600',
'Minutes' => '60',
'Seconds' => '1'
);
public function __construct($size = '0')
{
$this->size = (string)$size;
return $this;
}
public function __toString()
{
$str = '';
foreach(self::$suffixes as $suffix => $divisor)
{
if(bccomp($this->size, $divisor) > -1)
{
$num = bcdiv($this->size, $divisor, 0);
$this->size = bcsub($this->size, bcmul($num, $divisor));
$str .= "$num $suffix ";
}
}
return strlen($str) ? $str : 'None';
}
}
- class rough_age
- {
- public $size;
- protected static $suffixes = array(
- 'Years' => '31536000',
- 'Months' => '2592000',
- 'Weeks' => '604800',
- 'Days' => '86400',
- 'Hours' => '3600',
- 'Minutes' => '60',
- 'Seconds' => '1'
- );
-
- public function __construct($size = '0')
- {
- $this->size = (string)$size;
- return $this;
- }
-
-
- public function __toString()
- {
- $str = '';
- foreach(self::$suffixes as $suffix => $divisor)
- {
- if(bccomp($this->size, $divisor) > -1)
- {
- $num = bcdiv($this->size, $divisor, 0);
- $this->size = bcsub($this->size, bcmul($num, $divisor));
- $str .= "$num $suffix ";
- }
- }
- return strlen($str) ? $str : 'None';
- }
- }
Strong with this one, the sudo is.