diff --git a/public/include/classes/notification.class.php b/public/include/classes/notification.class.php index d4376005..bb7506f3 100644 --- a/public/include/classes/notification.class.php +++ b/public/include/classes/notification.class.php @@ -58,10 +58,10 @@ class Notification extends Mail { * @param id int Account ID * @return array Notification data **/ - public function getNofifications($account_id) { + public function getNofifications($account_id,$limit=50) { $this->debug->append("STA " . __METHOD__, 4); - $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE account_id = ? ORDER BY time DESC"); - if ($stmt && $stmt->bind_param('i', $account_id) && $stmt->execute() && $result = $stmt->get_result()) + $stmt = $this->mysqli->prepare("SELECT * FROM $this->table WHERE account_id = ? ORDER BY time DESC LIMIT ?"); + if ($stmt && $stmt->bind_param('ii', $account_id, $limit) && $stmt->execute() && $result = $stmt->get_result()) return $result->fetch_all(MYSQLI_ASSOC); return $this->getError(); } diff --git a/public/include/smarty/libs/plugins/modifier.relative_date.php b/public/include/smarty/libs/plugins/modifier.relative_date.php new file mode 100644 index 00000000..96186266 --- /dev/null +++ b/public/include/smarty/libs/plugins/modifier.relative_date.php @@ -0,0 +1,79 @@ + +* Purpose: Output dates relative to the current time +* Input: timestamp = UNIX timestamp or a date which can be converted by strtotime() +* days = use date only and ignore the time +* format = (optional) a php date format (for dates over 1 year) +* ------------------------------------------------------------- +*/ + +function smarty_modifier_relative_date($timestamp, $days = false, $format = "M j, Y") { + + if (!is_numeric($timestamp)) { + // It's not a time stamp, so try to convert it... + $timestamp = strtotime($timestamp); + } + + if (!is_numeric($timestamp)) { + // If its still not numeric, the format is not valid + return false; + } + + // Calculate the difference in seconds + $difference = time() - $timestamp; + + // Check if we only want to calculate based on the day + if ($days && $difference < (60*60*24)) { + return "Today"; + } + if ($difference < 3) { + return "Just now"; + } + if ($difference < 60) { + return $difference . " seconds ago"; + } + if ($difference < (60*2)) { + return "1 minute ago"; + } + if ($difference < (60*60)) { + return intval($difference / 60) . " minutes ago"; + } + if ($difference < (60*60*2)) { + return "1 hour ago"; + } + if ($difference < (60*60*24)) { + return intval($difference / (60*60)) . " hours ago"; + } + if ($difference < (60*60*24*2)) { + return "1 day ago"; + } + if ($difference < (60*60*24*7)) { + return intval($difference / (60*60*24)) . " days ago"; + } + if ($difference < (60*60*24*7*2)) { + return "1 week ago"; + } + if ($difference < (60*60*24*7*(52/12))) { + return intval($difference / (60*60*24*7)) . " weeks ago"; + } + if ($difference < (60*60*24*7*(52/12)*2)) { + return "1 month ago"; + } + if ($difference < (60*60*24*364)) { + return intval($difference / (60*60*24*7*(52/12))) . " months ago"; + } + + // More than a year ago, just return the formatted date + return @date($format, $timestamp); + +} + +?> \ No newline at end of file diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index 1b401ef7..c9438a00 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -42,6 +42,9 @@ $iCurrentPoolShareRate = $statistics->getCurrentShareRate(); // Active workers if (!$iCurrentActiveWorkers = $worker->getCountAllActiveWorkers()) $iCurrentActiveWorkers = 0; +// Fetch Last 5 notifications +$iLastNotifications = $notification->getNofifications($_SESSION['USERDATA']['id'], 5); + // Some settings to propagate to template if (! $statistics_ajax_refresh_interval = $setting->getValue('statistics_ajax_refresh_interval')) $statistics_ajax_refresh_interval = 10; if (! $statistics_ajax_long_refresh_interval = $setting->getValue('statistics_ajax_long_refresh_interval')) $statistics_ajax_long_refresh_interval = 10; @@ -56,6 +59,7 @@ $aGlobal = array( 'hashrate' => $iCurrentPoolHashrate, 'nethashrate' => $dNetworkHashrate, 'sharerate' => $iCurrentPoolShareRate, + 'lastnotifications' => $iLastNotifications, 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, 'fees' => $config['fees'], diff --git a/public/templates/bootstrap/account/notifications/default.tpl b/public/templates/bootstrap/account/notifications/default.tpl index 1bf1d73b..b304c69f 100755 --- a/public/templates/bootstrap/account/notifications/default.tpl +++ b/public/templates/bootstrap/account/notifications/default.tpl @@ -96,7 +96,7 @@ {/if}