Skip to content

Commit

Permalink
Generate a build timestamp via Git, if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccue committed Dec 12, 2010
1 parent 3d60b8b commit 0b4a875
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions SimplePie/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@

/**
* SimplePie Build
* @todo Hardcode for release (there's no need to have to call SimplePie_Misc::parse_date() only every load of simplepie.inc)
* @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
*/
define('SIMPLEPIE_BUILD', gmdate('YmdHis', filemtime(__FILE__)));
define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build()));

/**
* SimplePie Website URL
Expand Down
34 changes: 34 additions & 0 deletions SimplePie/Misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2248,5 +2248,39 @@ function embed_wmedia(width, height, link) {
}
<?php
}

/**
* Get the SimplePie build timestamp
*
* Uses the git index if it exists, otherwise uses the modification time
* of the newest file.
*/
public static function get_build()
{
$root = dirname(dirname(__FILE__));
if (file_exists($root . '/.git/index'))
{
return filemtime($root . '/.git/index');
}
elseif (file_exists($root . '/SimplePie'))
{
$time = 0;
foreach (glob($root . '/SimplePie/*.php') as $file) {
if (($mtime = filemtime($file)) > $time)
{
$time = $mtime;
}
}
return $time;
}
elseif (file_exists(dirname(__FILE__) . '/Core.php'))
{
return filemtime(dirname(__FILE__) . '/Core.php');
}
else
{
return filemtime(__FILE__);
}
}
}

0 comments on commit 0b4a875

Please sign in to comment.