Skip to content

Commit

Permalink
add reminder to admins that CDC is old; refactor date diff stringifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargaj committed Dec 28, 2021
1 parent 7da1dcb commit 94812c6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
35 changes: 22 additions & 13 deletions include_generic/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,40 @@ function toObject($array) {
return $obj;
}

function secToReadable($dif, $toDays)
{
$s = "";
if ($toDays)
{
$dif = $dif / (60 * 60 * 24);
$s = ($dif % 30) . "d" ; $dif = (int)($dif / 30); if (!$dif) return $s;
$s = ($dif % 12) . "m " . $s; $dif = (int)($dif / 12); if (!$dif) return $s;
$s = $dif . "y " . $s;
}
else
{
$s = ($dif % 60) . "s" ; $dif = (int)($dif / 60); if (!$dif) return $s;
$s = ($dif % 60) . "m " . $s; $dif = (int)($dif / 60); if (!$dif) return $s;
$s = ($dif % 24) . "h " . $s; $dif = (int)($dif / 24); if (!$dif) return $s;
$s = $dif . "d " . $s;
}
return $s;
}

function dateDiffReadable( $a, $b )
{
if (is_string($a)) $a = strtotime($a);
if (is_string($b)) $b = strtotime($b);

$dif = $a - $b;

$s = ($dif % 60) . "s" ; $dif = (int)($dif / 60); if (!$dif) return $s;
$s = ($dif % 60) . "m " . $s; $dif = (int)($dif / 60); if (!$dif) return $s;
$s = ($dif % 24) . "h " . $s; $dif = (int)($dif / 24); if (!$dif) return $s;
$s = $dif . "d " . $s;
return $s;
return secToReadable($a - $b, false);
}

function dateDiffReadableDays( $a, $b )
{
if (is_string($a)) $a = strtotime($a);
if (is_string($b)) $b = strtotime($b);

$dif = ($a - $b) / (60 * 60 * 24);

$s = ($dif % 30) . "d" ; $dif = (int)($dif / 30); if (!$dif) return $s;
$s = ($dif % 12) . "m " . $s; $dif = (int)($dif / 12); if (!$dif) return $s;
$s = $dif . "y " . $s;
return $s;
return secToReadable($a - $b, true);
}

function cdcstack($n) { // by ryg
Expand Down
31 changes: 24 additions & 7 deletions include_pouet_index/box-index-cdc.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
<?php
class PouetBoxIndexCDC extends PouetBoxCachable {
class PouetBoxIndexCDC extends PouetBoxCachable
{
var $data;
var $prod;
function __construct() {
function __construct()
{
parent::__construct();
$this->uniqueID = "pouetbox_cdc";
$this->title = "coup de coeur";
}

function LoadFromCachedData($data) {
function LoadFromCachedData($data)
{
$this->data = unserialize($data);
}

function GetCacheableData() {
function GetCacheableData()
{
return serialize($this->data);
}

function LoadFromDB() {
function LoadFromDB()
{
$s = new BM_Query();
$s->AddTable("cdc");
$s->AddField("cdc.addedDate");
$s->attach(array("cdc"=>"which"),array("prods as prod"=>"id"));
$s->AddOrder("cdc.addedDate desc");
$s->SetLimit(1);
Expand All @@ -28,12 +34,23 @@ function LoadFromDB() {
PouetCollectPlatforms($a);
}

function RenderContent() {
function RenderContent()
{
//return $this->prod->RenderLink() . " $ " . $this->prod->RenderGroupsShort();
if ($this->data && $this->data->prod)
$this->data->prod->RenderAsEntry();
}
function RenderFooter() {
function RenderFooter()
{
global $currentUser;
if ($currentUser && $currentUser->IsModerator())
{
$dif = time() - strtotime($this->data->addedDate);
if ($dif > 60 * 60 * 24 * 30)
{
echo "<div class='content notifications'>this current cdc is ".secToReadable($dif,true)." old</div>\n";
}
}
echo " <div class='foot'><a href='awards.php'>awards</a> :: <a href='cdc.php'>more</a>...</div>\n";
echo "</div>\n";
return $s;
Expand Down

0 comments on commit 94812c6

Please sign in to comment.