Permalink
Browse files

move custom date functions to class file

  • Loading branch information...
rwchhs committed Aug 9, 2014
1 parent 8180168 commit 0f684a0dcaf5f823ff518bfc931372b9c3d56bca
View
@@ -167,12 +167,12 @@
<td class='area_1'><i>".$user["email"]."</i></td>";
echo "
<td class='area_2' style='text-align:center;'>";
if (gmdate('Y-m-d', user_date($user['date_added'])) == gmdate('Y-m-d'))
if (gmdate('Y-m-d', DateCustom::user_date($user['date_added'])) == gmdate('Y-m-d'))
echo '<i>today</i>';
else if (gmdate('Y-m-d', user_date($user['date_added'])) == gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), ((int)gmdate('d') - 1), gmdate('Y'))))
else if (gmdate('Y-m-d', DateCustom::user_date($user['date_added'])) == gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), ((int)gmdate('d') - 1), gmdate('Y'))))
echo "<i>yesterday</i>";
else
echo gmdate("Y-m-d", user_date($user['date_added']))."</td>";
echo gmdate("Y-m-d", DateCustom::user_date($user['date_added']))."</td>";
$sig = str_replace('<br><br>', '',format_text(filterLanguage($user["sig"])));
print "<td class='area_1'><a href='{$user['homepage']}' target='_blank'>{$user['homepage']}</a></td>
<td class='area_2'><i>".substr($sig, 0, (50 - strlen(strip_tags($sig)))).(((50 - strlen(strip_tags($sig))) > 0) ? '': "...")."</i></td>
@@ -346,11 +346,11 @@
else if (gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), ((int)gmdate('d') - 1), gmdate('Y'))))
echo '<i>yesterday</i>';
else
echo gmdate("Y-m-d", user_date($lastvisit));
echo gmdate("Y-m-d", DateCustom::user_date($lastvisit));
echo "</td></tr>
<tr>
<td class='area_1' style='padding:8px;'><strong>Registered Date:</strong></td>
<td class='area_2'>".gmdate("Y-m-d", user_date($rec[0]["date_added"]))."</td>
<td class='area_2'>".gmdate("Y-m-d", DateCustom::user_date($rec[0]["date_added"]))."</td>
</tr>
<tr>
<td class='area_1' style='padding:8px;'><strong>Time zone:</strong></td>
@@ -599,7 +599,7 @@
$status = $status_config['status'];
$statuscolor = $status_config['statuscolor'];
//if(gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d')) $lastvisit =
//(gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d') ? '<i>today</i>' : (gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), ((int)gmdate('d') - 1), gmdate('Y'))) ? '<i>yesterday</i>' : gmdate("Y-m-d", user_date($lastvisit))))
//(gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d') ? '<i>today</i>' : (gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), ((int)gmdate('d') - 1), gmdate('Y'))) ? '<i>yesterday</i>' : gmdate("Y-m-d", DateCustom::user_date($lastvisit))))
//show each user
echo "
<tr>
@@ -620,8 +620,8 @@
else if (gmdate('Y-m-d', $lastvisit) == gmdate('Y-m-d', mktime(0, 0, 0, gmdate('m'), ((int)gmdate('d') - 1), gmdate('Y'))))
echo "<i>yesterday</i>";
else
echo gmdate("Y-m-d", user_date($lastvisit))."</td>";
echo "<td class='area_2' style='text-align:center;'>".gmdate("Y-m-d", user_date($user['date_added']))."</td>";
echo gmdate("Y-m-d", DateCustom::user_date($lastvisit))."</td>";
echo "<td class='area_2' style='text-align:center;'>".gmdate("Y-m-d", DateCustom::user_date($user['date_added']))."</td>";
echo "<td class='area_2' style='text-align:center;'>";
if ($user['level'] != 9)
{
View
@@ -49,7 +49,7 @@
$msg .= "<div id='{$_POST["forumid"]}-{$_POST['threadid']}-{$_POST['postid']}-attach'>".$tdb->getUploads($_POST["forumid"],$_POST['threadid'],$pRec[0]['id'],$pRec[0]['upload_id'],$_CONFIG['fileupload_location'],$pRec[0]['user_id'])."</div>";
$dbmsg = encode_text(stripslashes($attach_msg.$_POST["newedit"]),ENT_NOQUOTES);
$posts_tdb->edit("posts", $_POST["postid"], array("message" => $dbmsg, "edited_by_id" => $_COOKIE["id_env"], "edited_by" => $_COOKIE["user_env"], "edited_date" => mkdate()));
$posts_tdb->edit("posts", $_POST["postid"], array("message" => $dbmsg, "edited_by_id" => $_COOKIE["id_env"], "edited_by" => $_COOKIE["user_env"], "edited_date" => DateCustom::mkdate()));
//clearstatcache();
$posts_tdb->cleanup();
$posts_tdb->setFp("posts", $_POST["forumid"]);
@@ -59,7 +59,7 @@
if(!empty($pRec2[0]['edited_by']) && !empty($pRec2[0]['edited_by_id']) && !empty($pRec2[0]['edited_date']))
$edited = "Last edited by: <a href='profile.php?action=get&id=".$pRec2[0]['edited_by_id']."' target='_new'>".$pRec2[0]['edited_by']."</a> on ".gmdate("M d, Y g:i:s a", user_date($pRec2[0]['edited_date']));
$edited = "Last edited by: <a href='profile.php?action=get&id=".$pRec2[0]['edited_by_id']."' target='_new'>".$pRec2[0]['edited_by']."</a> on ".gmdate("M d, Y g:i:s a", DateCustom::user_date($pRec2[0]['edited_date']));
echo "$msg<!--divider-->$edited";
break 1;
@@ -96,7 +96,7 @@
$p_id = $posts_tdb->add("posts", array(
"icon" => $_POST["icon"],
"user_name" => $_COOKIE["user_env"],
"date" => mkdate(),
"date" => DateCustom::mkdate(),
"message" => $msg,
"user_id" => $_COOKIE["id_env"],
"t_id" => $_POST["t_id"],
@@ -125,7 +125,7 @@
}
$rec = $posts_tdb->get("topics", $_POST["t_id"]);
$posts_tdb->edit("topics", $_POST["t_id"], array("replies" => ((int)$rec[0]["replies"] + 1), "last_post" => mkdate(), "user_name" => $_COOKIE["user_env"], "user_id" => $_COOKIE["id_env"], "p_ids" => $rec[0]["p_ids"].",".$p_id));
$posts_tdb->edit("topics", $_POST["t_id"], array("replies" => ((int)$rec[0]["replies"] + 1), "last_post" => DateCustom::mkdate(), "user_name" => $_COOKIE["user_env"], "user_id" => $_COOKIE["id_env"], "p_ids" => $rec[0]["p_ids"].",".$p_id));
clearstatcache();
$posts_tdb->sort("topics", "last_post", "DESC");
clearstatcache();
@@ -181,7 +181,7 @@
$output .= "<a name='{$pRec['id']}'>
<div name='post{$_GET['id']}-{$_GET['t_id']}-{$pRec['id']}' id='post{$_GET['id']}-{$_GET['t_id']}-{$pRec['id']}'>
<div class='main_cat_wrapper'>
<div class='cat_area_1' style='text-align:center;'>Posted: ".gmdate("M d, Y g:i:s a", user_date($pRec["date"]))."</div>
<div class='cat_area_1' style='text-align:center;'>Posted: ".gmdate("M d, Y g:i:s a", DateCustom::user_date($pRec["date"]))."</div>
<table class='main_table'>";
if ($x == 0)
{
@@ -261,7 +261,7 @@
<br />
<strong>Registered:</strong>
<br />
".gmdate("Y-m-d", user_date($user[0]["date_added"]))."
".gmdate("Y-m-d", DateCustom::user_date($user[0]["date_added"]))."
</div>
<br />
<div class='post_info_extra'>";
@@ -283,7 +283,7 @@
//echo "<div name='edit{$_GET['id']}-{$_GET['t_id']}-{$pRec['id']}' id='edit{$_GET['id']}-{$_GET['t_id']}-{$pRec['id']}' style='float: right;'>";
if (!empty($pRec['edited_by']) && !empty($pRec['edited_by_id']) && !empty($pRec['edited_date']))
$output .= "<div class='post_edited' name='edit{$_POST['id']}-{$_POST['t_id']}-{$pRec['id']}' id='edit{$_POST['id']}-{$_POST['t_id']}-{$pRec['id']}'>Last edited by: <a href='profile.php?action=get&id=".$pRec['edited_by_id']." target='_new'><strong>".$pRec['edited_by']."</strong></a> on ".gmdate("M d, Y g:i:s a", user_date($pRec['edited_date']))."</div>";
$output .= "<div class='post_edited' name='edit{$_POST['id']}-{$_POST['t_id']}-{$pRec['id']}' id='edit{$_POST['id']}-{$_POST['t_id']}-{$pRec['id']}'>Last edited by: <a href='profile.php?action=get&id=".$pRec['edited_by_id']." target='_new'><strong>".$pRec['edited_by']."</strong></a> on ".gmdate("M d, Y g:i:s a", DateCustom::user_date($pRec['edited_date']))."</div>";
else
$output .= "<div name='edit{$_POST['id']}-{$_POST['t_id']}-{$pRec['id']}' id='edit{$_POST['id']}-{$_POST['t_id']}-{$pRec['id']}' class='post_edited'></div>";
if ($pRec['user_id'] != 0)
@@ -606,10 +606,10 @@
$key = array_search($_POST['fileid'],$split);
unset($split[$key]);
$new = implode(',',$split);
$posts_tdb->edit("posts", $_POST["postid"], array("message" => $dbmsg, "edited_by_id" => $_COOKIE["id_env"], "edited_by" => $_COOKIE["user_env"], "edited_date" => mkdate(),'upload_id'=>$new));
$posts_tdb->edit("posts", $_POST["postid"], array("message" => $dbmsg, "edited_by_id" => $_COOKIE["id_env"], "edited_by" => $_COOKIE["user_env"], "edited_date" => DateCustom::mkdate(),'upload_id'=>$new));
$pRec2 = $posts_tdb->get("posts", $_POST["postid"]);
$output .= $tdb->getUploads($_POST['forumid'],$_POST['threadid'],$_POST["postid"],$pRec2[0]['upload_id'],$_CONFIG['fileupload_location'],$_POST['userid']);
$edited = "Last edited by: <a href='profile.php?action=get&id=".$pRec2[0]['edited_by_id']."' target='_new'>".$pRec2[0]['edited_by']."</a> on ".gmdate("M d, Y g:i:s a", user_date($pRec2[0]['edited_date']));
$edited = "Last edited by: <a href='profile.php?action=get&id=".$pRec2[0]['edited_by_id']."' target='_new'>".$pRec2[0]['edited_by']."</a> on ".gmdate("M d, Y g:i:s a", DateCustom::user_date($pRec2[0]['edited_date']));
echo $output."<!--divider-->".$edited;
break;
View
@@ -0,0 +1,123 @@
<?php
/**
*
*/
/**
* Class DateCustom
*/
class DateCustom
{
public static function mkdate()
{
return time();
//return gmmktime()+43200; //GMT time is 12 hours behind
}
public static function user_date($timestamp)
{
return $timestamp + ($_COOKIE['timezone'] * 3600);
}
public static function alterDate($date, $offset, $time_unit, $positive = true)
{
$offset = (int)$offset;
if (!$positive)
$offset = $offset * -1;
if ($offset == 0)
return $date;
switch (substr($time_unit, 0 , 2)) {
case 'se':
return $date + $offset;
case 'mi':
return $date + ($offset * 60);
case 'hr':
case 'ho':
return $date + ($offset * 3600);
case 'da':
return $date + ($offset * 86400);
case 'mo':
$d = (int)date('j', $date);
if ($offset > 0) {
$date += 86400 * (static::findTheDaysOfTheMonth($date) - $d + 1);
for ($i = $offset - 1; $i > 0; $i--)
$date += 86400 * static::findTheDaysOfTheMonth($date);
$date += 86400 * ($d - 1);
} else {
$date -= 86400 * ($d);
for ($i = $offset + 1; $i < 0; $i++)
$date -= 86400 * static::findTheDaysOfTheMonth($date);
$date -= 86400 * (static::findTheDaysOfTheMonth($date) - $d);
}
return $date;
case 'yr':
case 'ye':
$d = (int)date('z', $date);
if ($offset > 0) {
$date += 86400 * (static::howManyDaysInAYear($date) - $d + 1);
for ($i = $offset - 1; $i > 0; $i--)
$date += 86400 * (gmdate('L', $date) ? 366 : 365);
$date += 86400 * ($d - 1);
} else {
$date -= 86400 * $d;
for ($i = $offset + 1; $i < 0; $i++)
$date -= 86400 * (gmdate('L', $date) ? 366 : 365);
$date -= 86400 * (static::howManyDaysInAYear($date) - $d);
}
return $date;
default:
echo 'Time unit not recognized';
return;
}
}
public static function findTheDaysOfTheMonth($timestamp)
{
switch(date('n', $timestamp)) {
case 1:
return 31;
case 2:
return ((date('L', $timestamp)) ? 29 : 28);
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
default:
return false;
}
}
public static function howManyDaysInAYear($date)
{
return (gmdate('L', $date) ? 366 : 365);
}
}
View
@@ -45,15 +45,15 @@ public function login_user($user, $pass, $key, &$error)
return false;
}
$this->edit('users', $rec[0]['id'], array('lastvisit' => mkdate()));
$rec[0]['lastvisit'] = mkdate();
$this->edit('users', $rec[0]['id'], array('lastvisit' => DateCustom::mkdate()));
$rec[0]['lastvisit'] = DateCustom::mkdate();
return $rec[0];
}
} elseif (substr($rec[0]['password'], 1) == stripslashes(t_encrypt(substr($pass, 0, (Encode::HASH_LENGTH - 1)), $key))) {
$rec[0]['password'] = Encode::generateHash($pass);
$this->edit('users', $rec[0]['id'], array('password' => $rec[0]['password']));
$this->edit('users', $rec[0]['id'], array('lastvisit' => mkdate()));
$this->edit('users', $rec[0]['id'], array('lastvisit' => DateCustom::mkdate()));
return $rec[0];
}
View
@@ -21,7 +21,7 @@
if ($pRec[0]["user_id"] != $_COOKIE["id_env"] && $_COOKIE["power_env"] < 2) exitPage("<div class='alert'><div class='alert_text'>
<strong>Caution!</strong></div><div style='padding:4px;'>You do not have the rights to perform this action.</div></div>");
if (isset($_POST["message"])) {
$posts_tdb->edit("posts", $_GET["p_id"], array("message" => encode_text(stripslashes($_POST["message"])), "edited_by_id" => $_COOKIE["id_env"], "edited_by" => $_COOKIE["user_env"], "edited_date" => mkdate()));
$posts_tdb->edit("posts", $_GET["p_id"], array("message" => encode_text(stripslashes($_POST["message"])), "edited_by_id" => $_COOKIE["id_env"], "edited_by" => $_COOKIE["user_env"], "edited_date" => DateCustom::mkdate()));
echo "
<div class='alert_confirm'>
<div class='alert_confirm_text'>
View
@@ -14,15 +14,15 @@
if ($user[0]['id'] != '') {
$results = $tdb->basicQuery("getpass", "user_id", $user[0]['id'], 1, 1);
if ($results[0]['id'] != '') {
$expire = alterDate($results[0]['time'], 2, 'days');
if (mkdate() > $expire) {
$expire = DateCustom::alterDate($results[0]['time'], 2, 'days');
if (DateCustom::mkdate() > $expire) {
$tdb->delete('getpass', $results[0]['id']);
unset($results);
}
}
if ($results[0]['id'] == '') {
$passcode = rand();
$request_ID = $tdb->add("getpass", array("passcode_HASH" => Encode::generateHash($passcode), time => mkdate(), "user_id" => $user[0]['id']));
$request_ID = $tdb->add("getpass", array("passcode_HASH" => Encode::generateHash($passcode), time => DateCustom::mkdate(), "user_id" => $user[0]['id']));
if (FALSE !== ($question_mark_where = strpos($_SERVER['REQUEST_URI'], '?'))) {
$url = substr($_SERVER['REQUEST_URI'], 0, $question_mark_where);
}
@@ -61,8 +61,8 @@
if (isset($_GET['passcode']) && isset($_GET['request_ID'])) {
$_GET['passcode'] = trim($_GET['passcode']);
$results = $tdb->get('getpass', $_GET['request_ID']);
$expire = alterDate($results[0]['time'], 2, 'days');
if (mkdate() < $expire) {
$expire = DateCustom::alterDate($results[0]['time'], 2, 'days');
if (DateCustom::mkdate() < $expire) {
$passcode_HASH = Encode::generateHash($_GET['passcode'], $results[0]['passcode_HASH']);
if ($passcode_HASH == $results[0]['passcode_HASH']) {
$where = "Lost Password ".$_CONFIG["where_sep"]." Create New";
View
@@ -32,8 +32,8 @@
//NEW VERSION
$ses_info = $r['lastvisit'];
if ($ses_info == 0)
$ses_info = mkdate();
$tdb->edit("users",$_COOKIE["id_env"],array('lastvisit'=>mkdate()));
$ses_info = DateCustom::mkdate();
$tdb->edit("users",$_COOKIE["id_env"],array('lastvisit'=>DateCustom::mkdate()));
if (!headers_sent()) {
$uniquekey = generateUniqueKey();
@@ -59,7 +59,7 @@
}
} else {
$default_timezone = '0';
$now = mkdate();
$now = DateCustom::mkdate();
if (!isset($_COOKIE["timezone"]) && !headers_sent()) setcookie("timezone", $default_timezone, (time() + (60 * 60 * 24 * 7)));
if (!isset($_COOKIE["lastvisit"]) && !headers_sent()) setcookie("lastvisit", $now, (time() + (60 * 60 * 24 * 7)));
$_COOKIE['lastvisit'] = $now;
Oops, something went wrong.

0 comments on commit 0f684a0

Please sign in to comment.