From 6c29d57a4c8e42c53e8d9c7ae947a1b0cdf43a70 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sun, 10 Mar 2024 13:40:50 +1100 Subject: [PATCH] refactor datetime part1 --- Code/Daemon/Cache_embeds.php | 4 +- Code/Daemon/Checksites.php | 4 +- Code/Daemon/Cron.php | 11 +-- Code/Daemon/Cron_daily.php | 9 +- Code/Daemon/Cron_weekly.php | 3 +- Code/Daemon/Cronhooks.php | 3 +- Code/Daemon/Directory.php | 3 +- Code/Daemon/Notifier.php | 5 +- Code/Daemon/Onepoll.php | 11 +-- Code/Daemon/Poller.php | 23 ++--- Code/Daemon/Xchan_photo.php | 5 +- Code/Import/Friendica.php | 13 +-- Code/Lib/Account.php | 6 +- Code/Lib/Activity.php | 100 ++++++++++----------- Code/Lib/ActivityPub.php | 6 +- Code/Lib/Apps.php | 4 +- Code/Lib/Cache.php | 6 +- Code/Lib/Channel.php | 38 ++++---- Code/Lib/Chatroom.php | 8 +- Code/Lib/Connect.php | 4 +- Code/Lib/DReport.php | 6 +- Code/Lib/Enotify.php | 6 +- Code/Lib/Libprofile.php | 4 +- Code/Lib/Libsync.php | 26 +++--- Code/Lib/Libzot.php | 46 +++++----- Code/Lib/Libzotdir.php | 8 +- Code/Lib/Markdown.php | 2 +- Code/Lib/MastAPI.php | 4 +- Code/Lib/Menu.php | 8 +- Code/Lib/MenuItem.php | 6 +- Code/Lib/Navbar.php | 4 +- Code/Lib/Queue.php | 44 +++++----- Code/Lib/Socgraph.php | 12 +-- Code/Lib/ThreadItem.php | 12 +-- Code/Lib/Tombstone.php | 2 +- Code/Lib/Url.php | 2 +- Code/Lib/Verify.php | 2 +- Code/Lib/Xprof.php | 2 +- Code/Module/Admin/Account_edit.php | 3 +- Code/Module/Admin/Accounts.php | 7 +- Code/Module/Admin/Queue.php | 3 +- Code/Module/Admin/Site.php | 3 +- Code/Module/Apporder.php | 5 +- Code/Module/Cal.php | 47 +++++----- Code/Module/Calendar.php | 25 +++--- Code/Module/Cdav.php | 21 ++--- Code/Module/Changeaddr.php | 3 +- Code/Module/Channel.php | 9 +- Code/Module/Chatsvc.php | 11 +-- Code/Module/Connections.php | 3 +- Code/Module/Cover_photo.php | 5 +- Code/Module/Dirsearch.php | 9 +- Code/Module/Display.php | 7 +- Code/Module/Dreport.php | 3 +- Code/Module/Events.php | 61 ++++++------- Code/Module/Fhublocs.php | 5 +- Code/Module/Home.php | 3 +- Code/Module/Impel.php | 11 +-- Code/Module/Import.php | 17 ++-- Code/Module/Inbox.php | 3 +- Code/Module/Invite.php | 3 +- Code/Module/Item.php | 29 +++--- Code/Module/Like.php | 3 +- Code/Module/Manage.php | 9 +- Code/Module/Photos.php | 9 +- Code/Module/Ping.php | 41 ++++----- Code/Module/Profile_photo.php | 5 +- Code/Module/Pubstream.php | 5 +- Code/Module/Removeaccount.php | 3 +- Code/Module/Removeme.php | 3 +- Code/Module/Search.php | 3 +- Code/Module/Settings/Account.php | 3 +- Code/Module/Settings/Channel.php | 3 +- Code/Module/Settings/Profile_edit.php | 9 +- Code/Module/Settings/Tokens.php | 9 +- Code/Module/Stream.php | 9 +- Code/Module/Tasks.php | 9 +- Code/Module/Thing.php | 5 +- Code/Module/Uexport.php | 3 +- Code/Module/Webpages.php | 5 +- Code/Photo/PhotoDriver.php | 3 +- Code/Storage/Browser.php | 3 +- Code/Storage/Directory.php | 5 +- Code/Storage/File.php | 5 +- Code/Update/_1252.php | 5 +- Code/Web/HTTPSig.php | 5 +- Code/Widget/Archive.php | 3 +- boot.php | 17 ++-- include/api.php | 3 +- include/api_zot.php | 13 +-- include/attach.php | 17 ++-- include/auth.php | 15 ++-- include/bbcode.php | 3 +- include/connections.php | 5 +- include/conversation.php | 21 ++--- include/datetime.php | 31 +++---- include/dba/dba_pdo.php | 6 +- include/event.php | 121 +++++++++++++------------- include/feedutils.php | 11 +-- include/hubloc.php | 7 +- include/import.php | 31 +++---- include/items.php | 109 +++++++++++------------ include/misc.php | 13 +-- include/network.php | 3 +- include/photos.php | 9 +- include/security.php | 11 +-- include/taxonomy.php | 3 +- include/xchan.php | 27 +++--- 108 files changed, 742 insertions(+), 657 deletions(-) diff --git a/Code/Daemon/Cache_embeds.php b/Code/Daemon/Cache_embeds.php index f7209fcd5..123cb97f3 100644 --- a/Code/Daemon/Cache_embeds.php +++ b/Code/Daemon/Cache_embeds.php @@ -2,6 +2,8 @@ namespace Code\Daemon; +use Code\Lib\Time; + class Cache_embeds implements DaemonInterface { @@ -31,7 +33,7 @@ class Cache_embeds implements DaemonInterface if ($cache_expire <= 0) { $cache_expire = 60; } - $cache_enable = !(($cache_expire) && ($item['created'] < datetime_convert('UTC', 'UTC', 'now - ' . $cache_expire . ' days'))); + $cache_enable = !(($cache_expire) && ($item['created'] < Time::convert('UTC', 'UTC', 'now - ' . $cache_expire . ' days'))); $s = bbcode($item['body']); sslify($s, $cache_enable); diff --git a/Code/Daemon/Checksites.php b/Code/Daemon/Checksites.php index 3b9da80af..537b4276e 100644 --- a/Code/Daemon/Checksites.php +++ b/Code/Daemon/Checksites.php @@ -4,6 +4,8 @@ namespace Code\Daemon; +use Code\Lib\Time; + require_once('include/hubloc.php'); @@ -51,7 +53,7 @@ class Checksites implements DaemonInterface logger('checksites: ' . $rr['site_url']); q( "update site set site_update = '%s' where site_url = '%s' ", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($rr['site_url']) ); } else { diff --git a/Code/Daemon/Cron.php b/Code/Daemon/Cron.php index 6bf148ab5..a01786fb2 100644 --- a/Code/Daemon/Cron.php +++ b/Code/Daemon/Cron.php @@ -7,6 +7,7 @@ namespace Code\Daemon; use Code\Lib\Config; use Code\Lib\Libsync; use Code\Lib\Addon; +use Code\Lib\Time; class Cron implements DaemonInterface { @@ -111,7 +112,7 @@ class Cron implements DaemonInterface $r = q( "select id from item where item_delayed = 1 and created <= %s and created > '%s' ", db_utcnow(), - dbesc(datetime_convert('UTC', 'UTC', 'now - 2 days')) + dbesc(Time::convert('UTC', 'UTC', 'now - 2 days')) ); if ($r) { foreach ($r as $rr) { @@ -154,13 +155,13 @@ class Cron implements DaemonInterface // by directory servers $d1 = intval(get_config('system', 'last_expire_day')); - $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd')); + $d2 = intval(Time::convert('UTC', 'UTC', 'now', 'd')); // Allow somebody to staggger daily activities if they have more than one site on their server, // or if it happens at an inconvenient (busy) hour. $h1 = intval(get_config('system', 'cron_hour')); - $h2 = intval(datetime_convert('UTC', 'UTC', 'now', 'G')); + $h2 = intval(Time::convert('UTC', 'UTC', 'now', 'G')); if (($d2 != $d1) && ($h1 == $h2)) { @@ -208,7 +209,7 @@ class Cron implements DaemonInterface Addon::reload_all(); - $d = datetime_convert(); + $d = Time::convert(); // TODO check to see if there are any cronhooks before wasting a process @@ -216,7 +217,7 @@ class Cron implements DaemonInterface Run::Summon([ 'Cronhooks' ]); } - set_config('system', 'lastcron', datetime_convert()); + set_config('system', 'lastcron', Time::convert()); //All done - clear the lockfile @unlink($lockfile); diff --git a/Code/Daemon/Cron_daily.php b/Code/Daemon/Cron_daily.php index 67bd66e87..b426b8adb 100644 --- a/Code/Daemon/Cron_daily.php +++ b/Code/Daemon/Cron_daily.php @@ -5,7 +5,8 @@ namespace Code\Daemon; use Code\Lib\ServiceClass; use Code\Lib\Libzot; use Code\Extend\Hook; - +use Code\Lib\Time; + class Cron_daily implements DaemonInterface { @@ -26,7 +27,7 @@ class Cron_daily implements DaemonInterface // Fire off the Cron_weekly process if it's the correct day. - $d3 = intval(datetime_convert('UTC', 'UTC', 'now', 'N')); + $d3 = intval(Time::convert('UTC', 'UTC', 'now', 'N')); if ($d3 == 7) { Run::Summon([ 'Cron_weekly' ]); } @@ -94,10 +95,10 @@ class Cron_daily implements DaemonInterface Run::Summon([ 'Expire' ]); remove_obsolete_hublocs(); - $data = datetime_convert(); + $data = Time::convert(); Hook::call('cron_daily', $data); - set_config('system', 'last_expire_day', intval(datetime_convert('UTC', 'UTC', 'now', 'd'))); + set_config('system', 'last_expire_day', intval(Time::convert('UTC', 'UTC', 'now', 'd'))); /** * End Cron Daily diff --git a/Code/Daemon/Cron_weekly.php b/Code/Daemon/Cron_weekly.php index e6462129a..dcd2a46b1 100644 --- a/Code/Daemon/Cron_weekly.php +++ b/Code/Daemon/Cron_weekly.php @@ -4,6 +4,7 @@ namespace Code\Daemon; use Code\Lib\Channel; use Code\Extend\Hook; +use Code\Lib\Time; class Cron_weekly implements DaemonInterface { @@ -18,7 +19,7 @@ class Cron_weekly implements DaemonInterface * */ - $data = datetime_convert(); + $data = Time::convert(); Hook::call('cron_weekly', $data); z_check_cert(); diff --git a/Code/Daemon/Cronhooks.php b/Code/Daemon/Cronhooks.php index c2474e219..141954ed7 100644 --- a/Code/Daemon/Cronhooks.php +++ b/Code/Daemon/Cronhooks.php @@ -4,6 +4,7 @@ namespace Code\Daemon; use Code\Extend\Hook; +use Code\Lib\Time; class Cronhooks implements DaemonInterface { @@ -13,7 +14,7 @@ class Cronhooks implements DaemonInterface logger('cronhooks: start'); - $d = datetime_convert(); + $d = Time::convert(); Hook::call('cron', $d); } diff --git a/Code/Daemon/Directory.php b/Code/Daemon/Directory.php index 83d2b6d72..be5351dc5 100644 --- a/Code/Daemon/Directory.php +++ b/Code/Daemon/Directory.php @@ -4,6 +4,7 @@ namespace Code\Daemon; use Code\Lib\Libzotdir; use Code\Lib\Channel; +use Code\Lib\Time; class Directory implements DaemonInterface { @@ -40,7 +41,7 @@ class Directory implements DaemonInterface q( "update channel set channel_dirdate = '%s' where channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($channel['channel_id']) ); diff --git a/Code/Daemon/Notifier.php b/Code/Daemon/Notifier.php index b64bc61e8..b54e8661c 100644 --- a/Code/Daemon/Notifier.php +++ b/Code/Daemon/Notifier.php @@ -13,6 +13,7 @@ use Code\Lib\ActivityStreams; use Code\Lib\ActivityPub; use Code\Lib\Channel; use Code\Extend\Hook; +use Code\Lib\Time; require_once('include/html2plain.php'); @@ -784,7 +785,7 @@ class Notifier implements DaemonInterface dbesc($hub['hubloc_host']), dbesc($hub['hubloc_host']), dbesc('queued'), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(self::$channel['channel_hash']), dbesc($hash), dbesc(EMPTY_STR) @@ -817,7 +818,7 @@ class Notifier implements DaemonInterface dbesc($deceased['hubloc_host']), dbesc($deceased['hubloc_host']), dbesc('undeliverable/unresponsive site'), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(self::$channel['channel_hash']), dbesc(new_uuid()), dbesc(EMPTY_STR) diff --git a/Code/Daemon/Onepoll.php b/Code/Daemon/Onepoll.php index 931ec1085..cc8c14043 100644 --- a/Code/Daemon/Onepoll.php +++ b/Code/Daemon/Onepoll.php @@ -10,6 +10,7 @@ use Code\Lib\Activity; use Code\Lib\ASCollection; use Code\Lib\Socgraph; use Code\Lib\PConfig; +use Code\Lib\Time; class Onepoll implements DaemonInterface { @@ -62,8 +63,8 @@ class Onepoll implements DaemonInterface logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['xchan_name']}, CONTACT: {$contact['xchan_name']}"); $last_update = ((($contact['abook_updated'] === $contact['abook_created']) || ($contact['abook_updated'] <= NULL_DATE)) - ? datetime_convert('UTC', 'UTC', 'now - 7 days') - : datetime_convert('UTC', 'UTC', $contact['abook_updated'] . ' - 2 days') + ? Time::convert('UTC', 'UTC', 'now - 7 days') + : Time::convert('UTC', 'UTC', $contact['abook_updated'] . ' - 2 days') ); if (in_array($contact['xchan_network'],['nomad','zot6'])) { @@ -72,8 +73,8 @@ class Onepoll implements DaemonInterface $x = Libzot::refresh($contact, $importer); $responded = false; - $updated = datetime_convert(); - $connected = datetime_convert(); + $updated = Time::convert(); + $connected = Time::convert(); if (! $x) { // mark for death by not updating abook_connected, this is caught in include/poller.php q( @@ -115,7 +116,7 @@ class Onepoll implements DaemonInterface $fetch_feed = false; } - if ($contact['abook_created'] < datetime_convert('UTC', 'UTC', 'now - 1 week')) { + if ($contact['abook_created'] < Time::convert('UTC', 'UTC', 'now - 1 week')) { $fetch_feed = false; } diff --git a/Code/Daemon/Poller.php b/Code/Daemon/Poller.php index 4dbbd1aef..88c52ab07 100644 --- a/Code/Daemon/Poller.php +++ b/Code/Daemon/Poller.php @@ -6,7 +6,8 @@ namespace Code\Daemon; use Code\Lib\ServiceClass; use Code\Lib\Addon; - +use Code\Lib\Time; + class Poller implements DaemonInterface { @@ -72,7 +73,7 @@ class Poller implements DaemonInterface Addon::reload_all(); - $d = datetime_convert(); + $d = Time::convert(); // Only poll from those with suitable relationships @@ -115,7 +116,7 @@ class Poller implements DaemonInterface if (! $min) { $min = 60; } - $x = datetime_convert('UTC', 'UTC', "now - $min minutes"); + $x = Time::convert('UTC', 'UTC', "now - $min minutes"); if ($c < $x) { Run::Summon([ 'Onepoll', $contact['abook_id'] ]); if ($interval) { @@ -130,7 +131,7 @@ class Poller implements DaemonInterface } if ($c == $t) { - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { + if (Time::convert('UTC', 'UTC', 'now') > Time::convert('UTC', 'UTC', $t . " + 1 day")) { $update = true; } } else { @@ -139,16 +140,16 @@ class Poller implements DaemonInterface if ($c <= NULL_DATE) { $r = q( "update abook set abook_connected = '%s' where abook_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($contact['abook_id']) ); - $c = datetime_convert(); + $c = Time::convert(); $update = true; } // He's dead, Jim - if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 30 day")) > 0) { + if (strcmp(Time::convert('UTC', 'UTC', 'now'), Time::convert('UTC', 'UTC', $c . " + 30 day")) > 0) { $r = q( "update abook set abook_archived = 1 where abook_id = %d", intval($contact['abook_id']) @@ -167,15 +168,15 @@ class Poller implements DaemonInterface // recently deceased, so keep up the regular schedule for 3 days if ( - (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $c . " + 3 day")) > 0) - && (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 1 day")) > 0) + (strcmp(Time::convert('UTC', 'UTC', 'now'), Time::convert('UTC', 'UTC', $c . " + 3 day")) > 0) + && (strcmp(Time::convert('UTC', 'UTC', 'now'), Time::convert('UTC', 'UTC', $t . " + 1 day")) > 0) ) { $update = true; } // After that back off and put them on a morphine drip - if (strcmp(datetime_convert('UTC', 'UTC', 'now'), datetime_convert('UTC', 'UTC', $t . " + 2 day")) > 0) { + if (strcmp(Time::convert('UTC', 'UTC', 'now'), Time::convert('UTC', 'UTC', $t . " + 2 day")) > 0) { $update = true; } } @@ -195,7 +196,7 @@ class Poller implements DaemonInterface } } - set_config('system', 'lastpoll', datetime_convert()); + set_config('system', 'lastpoll', Time::convert()); //All done - clear the lockfile @unlink($lockfile); diff --git a/Code/Daemon/Xchan_photo.php b/Code/Daemon/Xchan_photo.php index 99d20b6ca..9d94455f9 100644 --- a/Code/Daemon/Xchan_photo.php +++ b/Code/Daemon/Xchan_photo.php @@ -5,6 +5,7 @@ namespace Code\Daemon; use Code\Lib\Channel; +use Code\Lib\Time; class Xchan_photo implements DaemonInterface { @@ -28,7 +29,7 @@ class Xchan_photo implements DaemonInterface if ($xchans && (int)$xchans[0]['xchan_censored'] === 2) { $result = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", - dbescdate(datetime_convert()), + dbescdate(Time::convert()), dbesc(z_root() . '/' . Channel::get_default_profile_photo()), dbesc(z_root() . '/' . Channel::get_default_profile_photo(80)), dbesc(z_root() . '/' . Channel::get_default_profile_photo(48)), @@ -45,7 +46,7 @@ class Xchan_photo implements DaemonInterface if ($photos) { $result = q( "update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", - dbescdate(datetime_convert()), + dbescdate(Time::convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/Code/Import/Friendica.php b/Code/Import/Friendica.php index 3e13294eb..f12d006fd 100644 --- a/Code/Import/Friendica.php +++ b/Code/Import/Friendica.php @@ -10,6 +10,7 @@ use Code\Lib\Channel; use Code\Lib\Multibase; use Code\Lib\ServiceClass; use Code\Lib\AccessList; +use Code\Lib\Time; use Code\Lib\Url; use Code\Access\PermissionLimits; use Code\Access\PermissionRoles; @@ -145,7 +146,7 @@ class Friendica 'hubloc_callback' => z_root() . '/nomad', 'hubloc_sitekey' => get_config('system', 'pubkey'), 'hubloc_network' => 'nomad', - 'hubloc_updated' => datetime_convert() + 'hubloc_updated' => Time::convert() ] ); if (!$r) { @@ -189,9 +190,9 @@ class Friendica 'xchan_connurl' => z_root() . '/poco/' . $channel['channel_address'], 'xchan_name' => $channel['channel_name'], 'xchan_network' => 'nomad', - 'xchan_updated' => datetime_convert(), - 'xchan_photo_date' => datetime_convert(), - 'xchan_name_date' => datetime_convert(), + 'xchan_updated' => Time::convert(), + 'xchan_photo_date' => Time::convert(), + 'xchan_name_date' => Time::convert(), 'xchan_system' => 0 ]); @@ -220,8 +221,8 @@ class Friendica 'abook_channel' => intval($newuid), 'abook_xchan' => $channel['channel_hash'], 'abook_closeness' => 0, - 'abook_created' => datetime_convert(), - 'abook_updated' => datetime_convert(), + 'abook_created' => Time::convert(), + 'abook_updated' => Time::convert(), 'abook_self' => 1 ]); diff --git a/Code/Lib/Account.php b/Code/Lib/Account.php index 6fa46cfa8..d1989778f 100644 --- a/Code/Lib/Account.php +++ b/Code/Lib/Account.php @@ -214,7 +214,7 @@ class Account { 'account_password' => $password_encoded, 'account_email' => $email, 'account_language' => get_best_language(), - 'account_created' => datetime_convert(), + 'account_created' => Time::convert(), 'account_flags' => intval($flags), 'account_roles' => intval($roles), 'account_expires' => $expires, @@ -289,7 +289,7 @@ class Account { $r = q( "INSERT INTO register ( hash, created, uid, password, lang ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ", dbesc($hash), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($arr['account']['account_id']), dbesc('verify'), dbesc($arr['account']['account_language']) @@ -357,7 +357,7 @@ class Account { $r = q( "INSERT INTO register ( hash, created, uid, password, lang ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ", dbesc($hash), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($arr['account']['account_id']), dbesc(''), dbesc($arr['account']['account_language']) diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 68d3f2b52..0be40cf66 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -162,7 +162,7 @@ class Activity $headers = [ 'Accept' => $accept_header, 'Host' => $parsed['host'], - 'Date' => datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'), + 'Date' => Time::convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'), '(request-target)' => 'get ' . get_request_string($url) ]; @@ -179,7 +179,7 @@ class Activity $site_url = unparse_url(['scheme' => $parsed['scheme'], 'host' => $parsed['host'], 'port' => ((array_key_exists('port', $parsed) && intval($parsed['port'])) ? $parsed['port'] : 0)]); q( "update site set site_update = '%s' where site_url = '%s' and site_update < %s - INTERVAL %s", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($site_url), db_utcnow(), db_quoteinterval('1 DAY') @@ -857,9 +857,9 @@ class Activity } } - $activity['published'] = datetime_convert('UTC', 'UTC', $item['created'], ISO8601); + $activity['published'] = Time::convert('UTC', 'UTC', $item['created'], ISO8601); if ($item['created'] !== $item['edited']) { - $activity['updated'] = datetime_convert('UTC', 'UTC', $item['edited'], ISO8601); + $activity['updated'] = Time::convert('UTC', 'UTC', $item['edited'], ISO8601); if ($activity['type'] === 'Create') { $activity['type'] = 'Update'; } @@ -1193,12 +1193,12 @@ class Activity $activity['id'] = $item['mid']; - $activity['published'] = datetime_convert('UTC', 'UTC', $item['created'], ISO8601); + $activity['published'] = Time::convert('UTC', 'UTC', $item['created'], ISO8601); if ($item['created'] !== $item['edited']) { - $activity['updated'] = datetime_convert('UTC', 'UTC', $item['edited'], ISO8601); + $activity['updated'] = Time::convert('UTC', 'UTC', $item['edited'], ISO8601); } if ($item['expires'] > NULL_DATE) { - $activity['expires'] = datetime_convert('UTC', 'UTC', $item['expires'], ISO8601); + $activity['expires'] = Time::convert('UTC', 'UTC', $item['expires'], ISO8601); } if ($item['app']) { $activity['generator'] = ['type' => 'Application', 'name' => $item['app']]; @@ -1216,8 +1216,8 @@ class Activity } if (!isset($activity['startTime'])) { - if ($item['comments_closed'] && datetime_convert(datetime: $item['comments_closed']) > NULL_DATE) { - $activity['endTime'] = datetime_convert(datetime: $item['comments_closed'], format: ISO8601); + if ($item['comments_closed'] && Time::convert(datetime: $item['comments_closed']) > NULL_DATE) { + $activity['endTime'] = Time::convert(datetime: $item['comments_closed'], format: ISO8601); } } @@ -1228,7 +1228,7 @@ class Activity $activity['canReply'] = ACTIVITY_PUBLIC_INBOX; } elseif (in_array($item['comment_policy'], ['contacts', 'specific'])) { $activity['canReply'] = z_root() . '/followers/' . substr($item['author']['xchan_addr'], 0, strpos($item['author']['xchan_addr'], '@')); - } elseif (in_array($item['comment_policy'], ['self', 'none']) || $item['item_nocomment'] || datetime_convert('UTC', 'UTC', $item['comments_closed']) <= datetime_convert()) { + } elseif (in_array($item['comment_policy'], ['self', 'none']) || $item['item_nocomment'] || Time::convert('UTC', 'UTC', $item['comments_closed']) <= Time::convert()) { $activity['canReply'] = []; } } @@ -1654,12 +1654,12 @@ class Activity $actor->setPreferredUsername(substr($p['xchan_addr'], 0, strpos($p['xchan_addr'], '@'))); } $actor->setName($p['xchan_name']); - $actor->setPublished(datetime_convert('UTC','UTC', $p['xchan_created'], ISO8601)); - $actor->setUpdated(datetime_convert('UTC', 'UTC', $p['xchan_name_date'], ISO8601)); + $actor->setPublished(Time::convert('UTC','UTC', $p['xchan_created'], ISO8601)); + $actor->setUpdated(Time::convert('UTC', 'UTC', $p['xchan_name_date'], ISO8601)); $actor->setIcon([ 'type' => 'Image', 'mediaType' => (($p['xchan_photo_mimetype']) ?: 'image/png'), - 'updated' => datetime_convert('UTC', 'UTC', $p['xchan_photo_date'], ISO8601), + 'updated' => Time::convert('UTC', 'UTC', $p['xchan_photo_date'], ISO8601), 'url' => $p['xchan_photo_l'], 'height' => 300, 'width' => 300, @@ -2160,9 +2160,9 @@ class Activity 'abook_channel' => intval($channel['channel_id']), 'abook_xchan' => $ret['xchan_hash'], 'abook_closeness' => intval($closeness), - 'abook_created' => datetime_convert(), - 'abook_updated' => datetime_convert(), - 'abook_connected' => datetime_convert(), + 'abook_created' => Time::convert(), + 'abook_updated' => Time::convert(), + 'abook_connected' => Time::convert(), 'abook_dob' => NULL_DATE, 'abook_pending' => intval(($automatic) ? 0 : 1), 'abook_instance' => z_root() @@ -2297,7 +2297,7 @@ class Activity if ($ap_hubloc) { // we already have a stored record. Determine if it needs updating. - if ($ap_hubloc['hubloc_updated'] < datetime_convert('UTC', 'UTC', ' now - ' . self::ACTOR_CACHE_DAYS . ' days') || $force) { + if ($ap_hubloc['hubloc_updated'] < Time::convert('UTC', 'UTC', ' now - ' . self::ACTOR_CACHE_DAYS . ' days') || $force) { $person_obj = self::fetch($url); // ensure we received something if (!is_array($person_obj)) { @@ -2498,11 +2498,11 @@ class Activity 'xchan_url' => $profile, 'xchan_name' => $name, 'xchan_hidden' => intval($hidden), - 'xchan_updated' => datetime_convert(), - 'xchan_name_date' => datetime_convert(), + 'xchan_updated' => Time::convert(), + 'xchan_name_date' => Time::convert(), 'xchan_network' => 'activitypub', 'xchan_type' => $xchan_type, - 'xchan_photo_date' => datetime_convert('UTC', 'UTC', '1968-01-01'), + 'xchan_photo_date' => Time::convert('UTC', 'UTC', '1968-01-01'), 'xchan_photo_l' => z_root() . '/' . Channel::get_default_profile_photo(), 'xchan_photo_m' => z_root() . '/' . Channel::get_default_profile_photo(80), 'xchan_photo_s' => z_root() . '/' . Channel::get_default_profile_photo(48), @@ -2515,19 +2515,19 @@ class Activity // Record exists. Cache existing records for a set number of days // then refetch to catch updated profile photos, names, etc. - if ($r[0]['xchan_name_date'] >= datetime_convert('UTC', 'UTC', 'now - ' . self::ACTOR_CACHE_DAYS . ' days') && (!$force)) { + if ($r[0]['xchan_name_date'] >= Time::convert('UTC', 'UTC', 'now - ' . self::ACTOR_CACHE_DAYS . ' days') && (!$force)) { return; } // update existing record q( "update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_pubkey = '%s', xchan_epubkey = '%s', xchan_network = '%s', xchan_name_date = '%s', xchan_hidden = %d, xchan_type = %d, xchan_censored = %d where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($name), dbesc($pubkey), dbesc($epubkey), dbesc('activitypub'), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($hidden), intval($xchan_type), intval($r[0]['xchan_censored'] ?: $censored), @@ -2582,7 +2582,7 @@ class Activity q( "update site set site_project = '%s', site_update = '%s', site_version = '%s' where site_url = '%s'", dbesc($software), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($version), dbesc($site_url) ); @@ -2598,7 +2598,7 @@ class Activity site_store_lowlevel( [ 'site_url' => $site_url, - 'site_update' => datetime_convert(), + 'site_update' => Time::convert(), 'site_dead' => 0, 'site_type' => SITE_TYPE_NOTZOT, 'site_project' => $software, @@ -2640,7 +2640,7 @@ class Activity 'hubloc_url' => $baseurl, 'hubloc_host' => $hostname, 'hubloc_callback' => $inbox, - 'hubloc_updated' => datetime_convert(), + 'hubloc_updated' => Time::convert(), 'hubloc_primary' => 1 ]); } @@ -2668,7 +2668,7 @@ class Activity } q( "update hubloc set hubloc_updated = '%s' where hubloc_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($url) ); } @@ -2900,8 +2900,8 @@ class Activity } } if ($pollItem['comments_closed'] > NULL_DATE) { - if ($pollItem['comments_closed'] > datetime_convert()) { - $o['closed'] = datetime_convert('UTC', 'UTC', $pollItem['comments_closed'], ISO8601); + if ($pollItem['comments_closed'] > Time::convert()) { + $o['closed'] = Time::convert('UTC', 'UTC', $pollItem['comments_closed'], ISO8601); // set this to force an update $answer_found = true; } @@ -2914,7 +2914,7 @@ class Activity q( "update item set obj = '%s', edited = '%s', item_blocked = 0 where id = %d", dbesc(json_encode($o)), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($pollItem['id']) ); } @@ -2936,7 +2936,7 @@ class Activity $newObj['proof'] = (new JcsEddsa2022())->sign($newObj, $channel); $r = q("update item set obj = '%s', edited = '%s' where id = %d", dbesc(json_encode($newObj)), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($related['id']) ); Run::Summon(['Notifier', 'edit_post', $related['id']]); @@ -3063,30 +3063,30 @@ class Activity */ if (array_key_exists('published', $act->data) && $act->data['published']) { - $item['created'] = datetime_convert('UTC', 'UTC', $act->data['published']); + $item['created'] = Time::convert('UTC', 'UTC', $act->data['published']); } elseif ($act->objprop('published')) { - $item['created'] = datetime_convert('UTC', 'UTC', $act->obj['published']); + $item['created'] = Time::convert('UTC', 'UTC', $act->obj['published']); } if (array_key_exists('updated', $act->data) && $act->data['updated']) { - $item['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']); + $item['edited'] = Time::convert('UTC', 'UTC', $act->data['updated']); } elseif ($act->objprop('updated')) { - $item['edited'] = datetime_convert('UTC', 'UTC', $act->obj['updated']); + $item['edited'] = Time::convert('UTC', 'UTC', $act->obj['updated']); } // Hubzilla, streams if (array_key_exists('expires', $act->data) && $act->data['expires']) { - $item['expires'] = datetime_convert('UTC', 'UTC', $act->data['expires']); + $item['expires'] = Time::convert('UTC', 'UTC', $act->data['expires']); } elseif ($act->objprop('expires')) { - $item['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']); + $item['expires'] = Time::convert('UTC', 'UTC', $act->obj['expires']); } // pixelfed stories if (array_key_exists('expiresAt', $act->data) && $act->data['expiresAt']) { - $item['expires'] = datetime_convert('UTC', 'UTC', $act->data['expiresAt']); + $item['expires'] = Time::convert('UTC', 'UTC', $act->data['expiresAt']); } elseif ($act->objprop('expiresAt')) { - $item['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expiresAt']); + $item['expires'] = Time::convert('UTC', 'UTC', $act->obj['expiresAt']); } // this will prevent peertube View activities which only exist for 2 minutes, but are like // scrobblers and seem to only put noise into your stream and then vanish abruptly. - if ($item['expires'] > NULL_DATE && $item['expires'] < datetime_convert(datetime: 'now + 15 minutes')) { + if ($item['expires'] > NULL_DATE && $item['expires'] < Time::convert(datetime: 'now + 15 minutes')) { // We shouldn't even be seeing this activity. return false; } @@ -3151,12 +3151,12 @@ class Activity // over-ride the object timestamp with the activity if (isset($act->data['published']) && $act->data['published']) { - $item['created'] = datetime_convert('UTC', 'UTC', $act->data['published']); + $item['created'] = Time::convert('UTC', 'UTC', $act->data['published']); unset($item['edited']); } if (isset($act->data['updated']) && $act->data['updated']) { - $item['edited'] = datetime_convert('UTC', 'UTC', $act->data['updated']); + $item['edited'] = Time::convert('UTC', 'UTC', $act->data['updated']); } $obj_actor = ($act->objprop('actor')) ? $act->obj['actor'] : $act->get_actor('attributedTo', $act->obj); @@ -3282,7 +3282,7 @@ class Activity // Set default date and time if no date fields were found (including within response activities). if (!(array_key_exists('created', $item) && $item['created'])) { - $item['created'] = datetime_convert(); + $item['created'] = Time::convert(); } if (!(array_key_exists('edited', $item) && $item['edited'])) { $item['edited'] = $item['created']; @@ -3295,8 +3295,8 @@ class Activity if ($act->objprop('commentPolicy')) { $until = strpos($act->obj['commentPolicy'], 'until='); if ($until !== false) { - $item['comments_closed'] = datetime_convert('UTC', 'UTC', substr($act->obj['commentPolicy'], $until + 6)); - if ($item['comments_closed'] < datetime_convert()) { + $item['comments_closed'] = Time::convert('UTC', 'UTC', substr($act->obj['commentPolicy'], $until + 6)); + if ($item['comments_closed'] < Time::convert()) { $item['item_nocomment'] = true; } } @@ -3393,7 +3393,7 @@ class Activity // Mastodon does not provide update timestamps when updating poll tallies which means race conditions may occur here. if (in_array($act->type,['Create','Update']) && $act->objprop('type') === 'Question' && $item['edited'] === $item['created']) { if (intval($act->objprop('votersCount'))) { - $item['edited'] = datetime_convert(); + $item['edited'] = Time::convert(); } } @@ -3506,12 +3506,12 @@ class Activity if ($act->objprop('type') === 'Question' && in_array($act->type, ['Create', 'Update'])) { if ($act->objprop['endTime']) { - $item['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['endTime']); + $item['comments_closed'] = Time::convert('UTC', 'UTC', $act->obj['endTime']); } } if ($act->objprop('closed')) { - $item['comments_closed'] = datetime_convert('UTC', 'UTC', $act->obj['closed']); + $item['comments_closed'] = Time::convert('UTC', 'UTC', $act->obj['closed']); } // we will need a hook here to extract magnet links e.g. peertube @@ -4741,10 +4741,10 @@ class Activity if (array_key_exists('startTime', $act) && str_ends_with($act['startTime'], 'Z')) { $adjust = true; $event['adjust'] = 1; - $event['dtstart'] = datetime_convert('UTC', 'UTC', $event['startTime']); + $event['dtstart'] = Time::convert('UTC', 'UTC', $event['startTime']); } if (array_key_exists('endTime', $act)) { - $event['dtend'] = datetime_convert('UTC', 'UTC', $event['endTime'] . (($adjust) ? '' : 'Z')); + $event['dtend'] = Time::convert('UTC', 'UTC', $event['endTime'] . (($adjust) ? '' : 'Z')); } else { $event['nofinish'] = true; } diff --git a/Code/Lib/ActivityPub.php b/Code/Lib/ActivityPub.php index c43a86005..59993f5e9 100644 --- a/Code/Lib/ActivityPub.php +++ b/Code/Lib/ActivityPub.php @@ -213,7 +213,7 @@ class ActivityPub dbesc($dest_url), dbesc($dest_url), dbesc('queued'), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($sender['channel_hash']), dbesc($hash), dbesc(EMPTY_STR) @@ -372,7 +372,7 @@ class ActivityPub [ 'id' => z_root() . '/channel/' . $x['sender']['channel_address'] . '#update', 'type' => 'Update', - 'updated' => datetime_convert(format: ISO8601), + 'updated' => Time::convert(format: ISO8601), 'actor' => $p, 'object' => z_root() . '/channel/' . $x['sender']['channel_address'], 'to' => [z_root() . '/followers/' . $x['sender']['channel_address']], @@ -595,7 +595,7 @@ class ActivityPub $ab = array_shift($ab); unset($ab['abook_id']); $ab['abook_xchan'] = $dst_xchan; - $ab['abook_created'] = $ab['abook_updated'] = $ab['abook_connected'] = datetime_convert(); + $ab['abook_created'] = $ab['abook_updated'] = $ab['abook_connected'] = Time::convert(); abook_store_lowlevel($ab); } diff --git a/Code/Lib/Apps.php b/Code/Lib/Apps.php index ec50e33a7..ca4549d69 100644 --- a/Code/Lib/Apps.php +++ b/Code/Lib/Apps.php @@ -1271,7 +1271,7 @@ class Apps $darray['app_deleted'] = ((x($arr, 'deleted')) ? intval($arr['deleted']) : 0); $darray['app_options'] = ((x($arr, 'options')) ? intval($arr['options']) : 0); - $created = datetime_convert(); + $created = Time::convert(); $r = q( "insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_plugin, app_deleted, app_options ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d )", @@ -1362,7 +1362,7 @@ class Apps $darray['app_deleted'] = ((x($arr, 'deleted')) ? intval($arr['deleted']) : 0); $darray['app_options'] = ((x($arr, 'options')) ? intval($arr['options']) : 0); - $edited = datetime_convert(); + $edited = Time::convert(); $r = q( "update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_plugin = '%s', app_deleted = %d, app_options = %d where app_id = '%s' and app_channel = %d", diff --git a/Code/Lib/Cache.php b/Code/Lib/Cache.php index fb35158f3..e7f616aae 100644 --- a/Code/Lib/Cache.php +++ b/Code/Lib/Cache.php @@ -39,7 +39,7 @@ class Cache q( "UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'", dbesc($value), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($hash) ); } else { @@ -47,7 +47,7 @@ class Cache "INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')", dbesc($hash), dbesc($value), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); } } @@ -57,7 +57,7 @@ class Cache { q( "DELETE FROM cache WHERE updated < '%s'", - dbesc(datetime_convert('UTC', 'UTC', "now - 30 days")) + dbesc(Time::convert('UTC', 'UTC', "now - 30 days")) ); } } diff --git a/Code/Lib/Channel.php b/Code/Lib/Channel.php index 2bb6b5c79..54cfa4734 100644 --- a/Code/Lib/Channel.php +++ b/Code/Lib/Channel.php @@ -458,7 +458,7 @@ class Channel 'hubloc_callback' => z_root() . '/nomad', 'hubloc_sitekey' => get_config('system', 'pubkey'), 'hubloc_network' => 'nomad', - 'hubloc_updated' => datetime_convert() + 'hubloc_updated' => Time::convert() ] ); if (! $r) { @@ -485,9 +485,9 @@ class Channel 'xchan_name' => $ret['channel']['channel_name'], 'xchan_network' => 'nomad', 'xchan_type' => $xchannel_type, - 'xchan_updated' => datetime_convert(), - 'xchan_photo_date' => datetime_convert(), - 'xchan_name_date' => datetime_convert(), + 'xchan_updated' => Time::convert(), + 'xchan_photo_date' => Time::convert(), + 'xchan_name_date' => Time::convert(), 'xchan_system' => $system ] ); @@ -522,8 +522,8 @@ class Channel 'abook_channel' => intval($newuid), 'abook_xchan' => $hash, 'abook_closeness' => 0, - 'abook_created' => datetime_convert(), - 'abook_updated' => datetime_convert(), + 'abook_created' => Time::convert(), + 'abook_updated' => Time::convert(), 'abook_self' => 1 ] ); @@ -738,7 +738,7 @@ class Channel $xv['xchan_guid_sig'] = $sig; $xv['xchan_hash'] = $hash; $xv['xchan_pubkey'] = $key['pubkey']; - $xv['xchan_updated'] = datetime_convert(); + $xv['xchan_updated'] = Time::convert(); xchan_store_lowlevel($xv); $newxchan = $xv; } @@ -1238,11 +1238,11 @@ class Channel $target_month = '01'; } - $mindate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month . '-01 00:00:00'); + $mindate = Time::convert('UTC', 'UTC', $year . '-' . $target_month . '-01 00:00:00'); if ($month && $month < 12) { - $maxdate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month_plus . '-01 00:00:00'); + $maxdate = Time::convert('UTC', 'UTC', $year . '-' . $target_month_plus . '-01 00:00:00'); } else { - $maxdate = datetime_convert('UTC', 'UTC', $year + 1 . '-01-01 00:00:00'); + $maxdate = Time::convert('UTC', 'UTC', $year + 1 . '-01-01 00:00:00'); } return self::export_items_date($channel_id, $mindate, $maxdate); @@ -1265,10 +1265,10 @@ class Channel if (! $start) { return []; } else { - $start = datetime_convert('UTC', 'UTC', $start); + $start = Time::convert('UTC', 'UTC', $start); } - $finish = datetime_convert('UTC', 'UTC', (($finish) ? $finish : 'now')); + $finish = Time::convert('UTC', 'UTC', (($finish) ? $finish : 'now')); if ($finish < $start) { return []; } @@ -1333,10 +1333,10 @@ class Channel if (! $start) { $start = NULL_DATE; } else { - $start = datetime_convert('UTC', 'UTC', $start); + $start = Time::convert('UTC', 'UTC', $start); } - $finish = datetime_convert('UTC', 'UTC', (($finish) ? $finish : 'now')); + $finish = Time::convert('UTC', 'UTC', (($finish) ? $finish : 'now')); if ($finish < $start) { return []; } @@ -2359,7 +2359,7 @@ class Channel $r = q( "update channel set channel_deleted = '%s', channel_removed = 1 where channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($channel_id) ); @@ -2529,8 +2529,8 @@ class Channel 'xchan_name' => $anon_name, 'xchan_url' => $anon_url, 'xchan_network' => 'anon', - 'xchan_updated' => datetime_convert(), - 'xchan_name_date' => datetime_convert() + 'xchan_updated' => Time::convert(), + 'xchan_name_date' => Time::convert() ]); @@ -2545,8 +2545,8 @@ class Channel if ($photos) { $r = q( "update xchan set xchan_updated = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_guid = '%s' and xchan_hash = '%s' and xchan_network = 'anon' ", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/Code/Lib/Chatroom.php b/Code/Lib/Chatroom.php index 3d1524e3a..fcb8ab56e 100644 --- a/Code/Lib/Chatroom.php +++ b/Code/Lib/Chatroom.php @@ -56,7 +56,7 @@ class Chatroom $arr['expire'] = 120; // minutes, e.g. 2 hours } - $created = datetime_convert(); + $created = Time::convert(); $x = q( "insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid ) @@ -183,7 +183,7 @@ class Chatroom if ($r) { q( "update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['cp_id']), dbesc($client) ); @@ -195,7 +195,7 @@ class Chatroom values ( %d, '%s', '%s', '%s', '%s' )", intval($room_id), dbesc($observer_xchan), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($status), dbesc($client) ); @@ -303,7 +303,7 @@ class Chatroom values( %d, '%s', '%s', '%s' )", intval($room_id), dbesc($xchan), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(str_rot47(base64url_encode($arr['chat_text']))) ); diff --git a/Code/Lib/Connect.php b/Code/Lib/Connect.php index 1781123e4..aabafacca 100644 --- a/Code/Lib/Connect.php +++ b/Code/Lib/Connect.php @@ -261,8 +261,8 @@ class Connect 'abook_xchan' => $xchan_hash, 'abook_profile' => $profile_assign, 'abook_feed' => intval(($xchan['xchan_network'] === 'rss') ? 1 : 0), - 'abook_created' => datetime_convert(), - 'abook_updated' => datetime_convert(), + 'abook_created' => Time::convert(), + 'abook_updated' => Time::convert(), 'abook_instance' => (($singleton) ? z_root() : '') ] ); diff --git a/Code/Lib/DReport.php b/Code/Lib/DReport.php index 8e34dfb3e..5f406a39b 100644 --- a/Code/Lib/DReport.php +++ b/Code/Lib/DReport.php @@ -23,13 +23,13 @@ class DReport $this->name = EMPTY_STR; $this->message_id = $message_id; $this->status = $status; - $this->date = datetime_convert(); + $this->date = Time::convert(); } public function update($status) { $this->status = $status; - $this->date = datetime_convert(); + $this->date = Time::convert(); } public function set_name($name) @@ -71,7 +71,7 @@ class DReport if ($expire_days === 0) { $expire_days = self::EXPIRE_DAYS; } - if (strcmp(datetime_convert(datetime: $item['created']), datetime_convert(datetime: "now - $expire_days days")) > 0) { + if (strcmp(Time::convert(datetime: $item['created']), Time::convert(datetime: "now - $expire_days days")) > 0) { return false; } return true; diff --git a/Code/Lib/Enotify.php b/Code/Lib/Enotify.php index a26270573..dc5cb0faf 100644 --- a/Code/Lib/Enotify.php +++ b/Code/Lib/Enotify.php @@ -121,7 +121,7 @@ class Enotify $title = $params['item']['title']; $body = $params['item']['body']; } - if ($params['item']['created'] < datetime_convert('UTC', 'UTC', 'now - 1 month')) { + if ($params['item']['created'] < Time::convert('UTC', 'UTC', 'now - 1 month')) { logger('notification invoked for an old item which may have been refetched.', LOGGER_DEBUG, LOG_INFO); return; } @@ -564,7 +564,7 @@ class Enotify $datarray['xname'] = $sender['xchan_name']; $datarray['url'] = $sender['xchan_url']; $datarray['photo'] = $sender['xchan_photo_s']; - $datarray['created'] = datetime_convert(); + $datarray['created'] = Time::convert(); $datarray['aid'] = $recip['channel_account_id']; $datarray['uid'] = $recip['channel_id']; $datarray['link'] = $itemlink; @@ -839,7 +839,7 @@ class Enotify $ret = ''; $expire = intval(get_config('system', 'default_expire_days')); - $expire_date = (($expire) ? datetime_convert('UTC', 'UTC', 'now - ' . $expire . ' days') : NULL_DATE); + $expire_date = (($expire) ? Time::convert('UTC', 'UTC', 'now - ' . $expire . ' days') : NULL_DATE); require_once('include/conversation.php'); diff --git a/Code/Lib/Libprofile.php b/Code/Lib/Libprofile.php index 628e12367..95abf2f8e 100644 --- a/Code/Lib/Libprofile.php +++ b/Code/Lib/Libprofile.php @@ -618,8 +618,8 @@ class Libprofile if (!$val) { $val = ((intval(App::$profile['dob'])) - ? day_translate(datetime_convert('UTC', 'UTC', App::$profile['dob'] . ' 00:00 +00:00', $year_bd_format)) - : day_translate(datetime_convert('UTC', 'UTC', '2001-' . substr(App::$profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format))); + ? day_translate(Time::convert('UTC', 'UTC', App::$profile['dob'] . ' 00:00 +00:00', $year_bd_format)) + : day_translate(Time::convert('UTC', 'UTC', '2001-' . substr(App::$profile['dob'], 5) . ' 00:00 +00:00', $short_bd_format))); } $profile['birthday'] = [t('Birthday:'), $val]; } diff --git a/Code/Lib/Libsync.php b/Code/Lib/Libsync.php index 63f146503..0fe5f37e0 100644 --- a/Code/Lib/Libsync.php +++ b/Code/Lib/Libsync.php @@ -348,10 +348,10 @@ class Libsync // if the clone is active, so are we - if (substr($channel['channel_active'], 0, 10) !== substr(datetime_convert(), 0, 10)) { + if (substr($channel['channel_active'], 0, 10) !== substr(Time::convert(), 0, 10)) { q( "UPDATE channel set channel_active = '%s' where channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($channel['channel_id']) ); } @@ -930,7 +930,7 @@ class Libsync if (isset($arr['deleted_locally']) && intval($arr['deleted_locally'])) { q( "UPDATE hubloc SET hubloc_deleted = 1, hubloc_updated = '%s' WHERE hubloc_hash = '%s' AND hubloc_url = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($sender['hash']), dbesc($sender['site']['url']) ); @@ -1035,7 +1035,7 @@ class Libsync $current_site = false; - $t = datetime_convert('UTC', 'UTC', 'now - 15 minutes'); + $t = Time::convert('UTC', 'UTC', 'now - 15 minutes'); if (isset($location['driver']) && $location['driver'] === 'nomad' && $location['driver'] !== $r[0]['hubloc_network']) { q("update hubloc set hubloc_network = '%s' where hubloc_id = %d", @@ -1054,8 +1054,8 @@ class Libsync if (array_key_exists('site', $arr) && $location['url'] == $arr['site']['url']) { q( "update hubloc set hubloc_connected = '%s', hubloc_updated = '%s' where hubloc_id = %d and hubloc_updated < '%s'", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), intval($r[0]['hubloc_id']), dbesc($t) ); @@ -1094,7 +1094,7 @@ class Libsync if (intval($r[0]['hubloc_primary']) && (!$location['primary'])) { $m = q( "update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['hubloc_id']) ); $r[0]['hubloc_primary'] = intval($location['primary']); @@ -1104,7 +1104,7 @@ class Libsync } elseif ((!intval($r[0]['hubloc_primary'])) && ($location['primary'])) { $m = q( "update hubloc set hubloc_primary = 1, hubloc_updated = '%s' where hubloc_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['hubloc_id']) ); // make sure hubloc_change_primary() has current data @@ -1123,7 +1123,7 @@ class Libsync if (intval($r[0]['hubloc_deleted']) && (!intval($location['deleted']))) { $n = q( "update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['hubloc_id']) ); $what .= 'undelete_hub '; @@ -1143,7 +1143,7 @@ class Libsync if (intval($location['primary'])) { $r = q( "update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_hash = '%s' and hubloc_primary = 1", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($sender['hash']) ); } @@ -1165,8 +1165,8 @@ class Libsync 'hubloc_host' => $location['host'], 'hubloc_callback' => $location['callback'], 'hubloc_sitekey' => $location['sitekey'], - 'hubloc_updated' => datetime_convert(), - 'hubloc_connected' => datetime_convert() + 'hubloc_updated' => Time::convert(), + 'hubloc_connected' => Time::convert() ] ); @@ -1278,7 +1278,7 @@ class Libsync $xv['xchan_guid_sig'] = $sig; $xv['xchan_hash'] = $hash; $xv['xchan_pubkey'] = $channel['channel_pubkey']; - $xv['xchan_updated'] = datetime_convert(); + $xv['xchan_updated'] = Time::convert(); xchan_store_lowlevel($xv); $newxchan = $xv; } diff --git a/Code/Lib/Libzot.php b/Code/Lib/Libzot.php index a463f1cd3..29ee9119e 100644 --- a/Code/Lib/Libzot.php +++ b/Code/Lib/Libzot.php @@ -394,7 +394,7 @@ class Libzot set_abconfig($channel['channel_id'], $x['hash'], 'system', 'their_perms', $record['data']['permissions']); if (array_key_exists('profile', $record['data']) && array_key_exists('next_birthday', $record['data']['profile'])) { - $next_birthday = datetime_convert('UTC', 'UTC', $record['data']['profile']['next_birthday']); + $next_birthday = Time::convert('UTC', 'UTC', $record['data']['profile']['next_birthday']); } else { $next_birthday = NULL_DATE; } @@ -444,7 +444,7 @@ class Libzot $n = q( "select count(abook_id) as total from abook where abook_channel = %d and abook_created > '%s'", intval($channel['channel_id']), - dbesc(datetime_convert('UTC', 'UTC', 'now - 24 hours')) + dbesc(Time::convert('UTC', 'UTC', 'now - 24 hours')) ); if ($n && intval($n['total']) > $lim) { logger('channel: ' . $channel['channel_id'] . ' too many new connections per day. This one from ' . $hsig['signer'], LOGGER_NORMAL, LOG_WARNING); @@ -504,8 +504,8 @@ class Libzot 'abook_closeness' => intval($closeness), 'abook_xchan' => $x['hash'], 'abook_profile' => $profile_assign, - 'abook_created' => datetime_convert(), - 'abook_updated' => datetime_convert(), + 'abook_created' => Time::convert(), + 'abook_updated' => Time::convert(), 'abook_dob' => $next_birthday, 'abook_pending' => intval(($automatic) ? 0 : 1) ] @@ -863,14 +863,14 @@ class Libzot || ($r[0]['xchan_connpage'] !== $arr['connect_url']) || ($r[0]['xchan_url'] !== $arr['primary_location']['url']) || ($r[0]['xchan_network'] !== $network) - || ($r[0]['xchan_updated'] < datetime_convert('UTC', 'UTC', 'now - 7 days')) + || ($r[0]['xchan_updated'] < Time::convert('UTC', 'UTC', 'now - 7 days')) || $hidden_changed || $adult_changed || $deleted_changed || $type_changed ) { $rup = q( "update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_name_date = '%s', xchan_connurl = '%s', xchan_follow = '%s', xchan_connpage = '%s', xchan_hidden = %d, xchan_selfcensored = %d, xchan_deleted = %d, xchan_type = %d, xchan_addr = '%s', xchan_url = '%s', xchan_network = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(($arr['name']) ? unicode_trim(escape_tags($arr['name'])) : '-'), dbesc($arr['name_updated']), dbesc($arr['primary_location']['connections_url']), @@ -923,7 +923,7 @@ class Libzot 'xchan_connpage' => $arr['connect_url'], 'xchan_name' => (($arr['name']) ? unicode_trim(escape_tags($arr['name'])) : '-'), 'xchan_network' => $network, - 'xchan_updated' => datetime_convert(), + 'xchan_updated' => Time::convert(), 'xchan_photo_date' => $arr['photo']['updated'], 'xchan_name_date' => $arr['name_updated'], 'xchan_hidden' => intval(1 - intval($arr['searchable'])), @@ -959,7 +959,7 @@ class Libzot $r = q( "update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -970,8 +970,8 @@ class Libzot $r = q( "update xchan set xchan_updated = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), - dbesc(datetime_convert('UTC', 'UTC', ((isset($arr['photo_updated'])) ? $arr['photo_updated'] : 'now'))), + dbesc(Time::convert()), + dbesc(Time::convert('UTC', 'UTC', ((isset($arr['photo_updated'])) ? $arr['photo_updated'] : 'now'))), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -1104,7 +1104,7 @@ class Libzot $b = q( "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'", dbesc(($x['message']) ? $x['message'] : 'unknown delivery error'), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($outq['outq_hash']) ); } @@ -1120,7 +1120,7 @@ class Libzot dbesc($xx['recipient']), dbesc($xx['name']), dbesc($xx['status']), - dbesc(datetime_convert(datetime: $xx['date'])), + dbesc(Time::convert(datetime: $xx['date'])), dbesc($xx['sender']), dbesc(EMPTY_STR) ); @@ -1139,7 +1139,7 @@ class Libzot // update the timestamp for this site q( "update site set site_dead = 0, site_update = '%s' where site_url = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(dirname($hub)) ); @@ -1373,7 +1373,7 @@ class Libzot // as comments were already closed before the post was even sent. if ($p !== false) { - $comments_closed_at = datetime_convert('UTC', 'UTC', substr($p, 6)); + $comments_closed_at = Time::convert('UTC', 'UTC', substr($p, 6)); if ($comments_closed_at === $arr['created']) { $arr['item_nocomment'] = 1; } else { @@ -2457,8 +2457,8 @@ class Libzot if ($stored['id'] !== $stored['parent']) { q( "update item set commented = '%s', changed = '%s' where id = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), intval($stored['parent']) ); } @@ -2702,7 +2702,7 @@ class Libzot intval($site_flags), intval($access_policy), intval($register_policy), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($sellpage), intval(SITE_TYPE_ZOT), dbesc($site_project), @@ -2717,7 +2717,7 @@ class Libzot // update the timestamp to indicate we communicated with this site q( "update site set site_dead = 0, site_update = '%s' where site_url = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($url) ); } @@ -2730,7 +2730,7 @@ class Libzot 'site_url' => $url, 'site_access' => intval($access_policy), 'site_flags' => 0, - 'site_update' => datetime_convert(), + 'site_update' => Time::convert(), 'site_register' => intval($register_policy), 'site_sellpage' => $sellpage, 'site_type' => intval(SITE_TYPE_ZOT), @@ -2818,7 +2818,7 @@ class Libzot // We have valid and somewhat fresh information. Always true if it is our own site. - if ($r1 && $r2 && ($r1[0]['hubloc_updated'] > datetime_convert('UTC', 'UTC', 'now - 1 week') || $r1[0]['hubloc_url'] === z_root())) { + if ($r1 && $r2 && ($r1[0]['hubloc_updated'] > Time::convert('UTC', 'UTC', 'now - 1 week') || $r1[0]['hubloc_url'] === z_root())) { logger('in cache', LOGGER_DEBUG); return $hash; } @@ -3232,11 +3232,11 @@ class Libzot // Update our DB to show when we last communicated successfully with this hub // This will allow us to prune dead hubs from using up resources - $t = datetime_convert('UTC', 'UTC', 'now - 15 minutes'); + $t = Time::convert('UTC', 'UTC', 'now - 15 minutes'); $r = q( "update hubloc set hubloc_connected = '%s' where hubloc_id = %d and hubloc_site_id = '%s' and hubloc_connected < '%s' ", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($hub['hubloc_id']), dbesc($site_id), dbesc($t) @@ -3340,7 +3340,7 @@ class Libzot public static function update_cached_hubloc($hubloc) { - if ($hubloc['hubloc_updated'] > datetime_convert('UTC', 'UTC', 'now - 1 week') || $hubloc['hubloc_url'] === z_root()) { + if ($hubloc['hubloc_updated'] > Time::convert('UTC', 'UTC', 'now - 1 week') || $hubloc['hubloc_url'] === z_root()) { return; } self::refresh(['hubloc_id_url' => $hubloc['hubloc_id_url']]); diff --git a/Code/Lib/Libzotdir.php b/Code/Lib/Libzotdir.php index 237382d6e..277fd97a4 100644 --- a/Code/Lib/Libzotdir.php +++ b/Code/Lib/Libzotdir.php @@ -129,7 +129,7 @@ class Libzotdir } else { q( "update updates set ud_last = '%s' where ud_addr = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($ud['ud_addr']) ); } @@ -274,7 +274,7 @@ class Libzotdir if (isset($profile['birthday'])) { $arr['xprof_dob'] = (($profile['birthday'] === '0000-00-00') ? $profile['birthday'] - : datetime_convert('', '', $profile['birthday'], 'Y-m-d')); // !!!! check this for 0000 year + : Time::convert('', '', $profile['birthday'], 'Y-m-d')); // !!!! check this for 0000 year } $arr['xprof_age'] = (isset($profile['age']) ? intval($profile['age']) : 0); $arr['xprof_desc'] = ((isset($profile['description']) && $profile['description']) ? htmlspecialchars($profile['description'], ENT_COMPAT, 'UTF-8', false) : ''); @@ -365,7 +365,7 @@ class Libzotdir q( "update xchan set xchan_updated = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($arr['xprof_hash']) ); @@ -445,7 +445,7 @@ class Libzotdir "insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' )", dbesc($hash), dbesc($guid), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($flags), dbesc($addr) ); diff --git a/Code/Lib/Markdown.php b/Code/Lib/Markdown.php index e494d0242..7d0f7a4a2 100644 --- a/Code/Lib/Markdown.php +++ b/Code/Lib/Markdown.php @@ -204,7 +204,7 @@ class Markdown } - $reldate = datetime_convert('UTC', date_default_timezone_get(), $posted, 'r'); + $reldate = Time::convert('UTC', date_default_timezone_get(), $posted, 'r'); $headline = ''; diff --git a/Code/Lib/MastAPI.php b/Code/Lib/MastAPI.php index f21d1ad17..047058929 100644 --- a/Code/Lib/MastAPI.php +++ b/Code/Lib/MastAPI.php @@ -52,7 +52,7 @@ class MastAPI $ret['display_name'] = $channel['channel_name']; $ret['locked'] = !intval(PConfig::Get($channel['channel_id'], 'system', 'autoperms')); $ret['discoverable'] = (bool)((1 - intval($channel['xchan_hidden']))); - $ret['created_at'] = datetime_convert('UTC', 'UTC', $a[0]['account_created'], ISO8601); + $ret['created_at'] = Time::convert('UTC', 'UTC', $a[0]['account_created'], ISO8601); $ret['note'] = bbcode($p[0]['about'], ['export' => true]); $ret['url'] = Channel::url($channel); $ret['avatar'] = $channel['xchan_photo_l']; @@ -64,7 +64,7 @@ class MastAPI $ret['followers_count'] = intval($followers[0]['total']); $ret['following_count'] = intval($following[0]['total']); $ret['statuses_count'] = intval($statuses[0]['total']); - $ret['last_status_at'] = datetime_convert('UTC', 'UTC', $channel['lastpost'], ISO8601); + $ret['last_status_at'] = Time::convert('UTC', 'UTC', $channel['lastpost'], ISO8601); return $ret; diff --git a/Code/Lib/Menu.php b/Code/Lib/Menu.php index 70e4ea6b0..c904dbc0b 100644 --- a/Code/Lib/Menu.php +++ b/Code/Lib/Menu.php @@ -195,7 +195,7 @@ class Menu return false; } - $t = datetime_convert(); + $t = Time::convert(); $r = q( "insert into menu ( menu_name, menu_desc, menu_flags, menu_channel_id, menu_created, menu_edited ) @@ -204,8 +204,8 @@ class Menu dbesc($menu_desc), intval($menu_flags), intval($menu_channel_id), - dbesc(datetime_convert('UTC', 'UTC', (($arr['menu_created']) ?: $t))), - dbesc(datetime_convert('UTC', 'UTC', (($arr['menu_edited']) ?: $t))) + dbesc(Time::convert('UTC', 'UTC', (($arr['menu_created']) ?: $t))), + dbesc(Time::convert('UTC', 'UTC', (($arr['menu_edited']) ?: $t))) ); if (! $r) { return false; @@ -306,7 +306,7 @@ class Menu dbesc($menu_name), dbesc($menu_desc), intval($menu_flags), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($menu_id), intval($menu_channel_id) ); diff --git a/Code/Lib/MenuItem.php b/Code/Lib/MenuItem.php index 876b479cb..1a6068df5 100644 --- a/Code/Lib/MenuItem.php +++ b/Code/Lib/MenuItem.php @@ -43,7 +43,7 @@ class MenuItem $x = q( "update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($menu_id), intval($uid) ); @@ -88,7 +88,7 @@ class MenuItem $x = q( "update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($menu_id), intval($uid) ); @@ -110,7 +110,7 @@ class MenuItem $x = q( "update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($menu_id), intval($uid) ); diff --git a/Code/Lib/Navbar.php b/Code/Lib/Navbar.php index 088dc03b9..736b4cd61 100644 --- a/Code/Lib/Navbar.php +++ b/Code/Lib/Navbar.php @@ -196,9 +196,9 @@ class Navbar { //app bin if ($is_owner) { - if (get_pconfig(local_channel(), 'system', 'import_system_apps') !== datetime_convert('UTC', 'UTC', 'now', 'Y-m-d')) { + if (get_pconfig(local_channel(), 'system', 'import_system_apps') !== Time::convert('UTC', 'UTC', 'now', 'Y-m-d')) { Apps::import_system_apps(); - set_pconfig(local_channel(), 'system', 'import_system_apps', datetime_convert('UTC', 'UTC', 'now', 'Y-m-d')); + set_pconfig(local_channel(), 'system', 'import_system_apps', Time::convert('UTC', 'UTC', 'now', 'Y-m-d')); } $list = Apps::app_list(local_channel(), false, [ 'nav_pinned_app' ]); diff --git a/Code/Lib/Queue.php b/Code/Lib/Queue.php index 3ff227c61..cb7d2a0bb 100644 --- a/Code/Lib/Queue.php +++ b/Code/Lib/Queue.php @@ -19,7 +19,7 @@ class Queue // Log the current error message to the current delivery. q("update outq set outq_log = CONCAT(outq_log, '%s') where outq_hash = '%s'", - dbesc(datetime_convert() . EOL . $msg . EOL), + dbesc(Time::convert() . EOL . $msg . EOL), dbesc($id) ); @@ -66,7 +66,7 @@ class Queue $might_be_down = false; if ($y) { - $might_be_down = datetime_convert('UTC', 'UTC', $y[0]['earliest']) < datetime_convert('UTC', 'UTC', 'now - 2 days'); + $might_be_down = Time::convert('UTC', 'UTC', $y[0]['earliest']) < Time::convert('UTC', 'UTC', 'now - 2 days'); } @@ -80,17 +80,17 @@ class Queue $r = q( "UPDATE outq SET outq_scheduled = '%s' WHERE outq_posturl = '%s' and outq_driver = '%s'", - dbesc(datetime_convert('UTC', 'UTC', 'now + 5 days')), + dbesc(Time::convert('UTC', 'UTC', 'now + 5 days')), dbesc($x[0]['outq_posturl']), dbesc($x[0]['outq_driver']) ); - $since = datetime_convert('UTC', 'UTC', $y[0]['earliest']); + $since = Time::convert('UTC', 'UTC', $y[0]['earliest']); - if (($might_be_down) || ($since < datetime_convert('UTC', 'UTC', 'now - 12 hour'))) { - $next = datetime_convert('UTC', 'UTC', 'now + 1 hour'); + if (($might_be_down) || ($since < Time::convert('UTC', 'UTC', 'now - 12 hour'))) { + $next = Time::convert('UTC', 'UTC', 'now + 1 hour'); } else { - $next = datetime_convert('UTC', 'UTC', 'now + ' . (($add_priority) ? intval($add_priority) : 5) . ' minutes'); + $next = Time::convert('UTC', 'UTC', 'now + ' . (($add_priority) ? intval($add_priority) : 5) . ' minutes'); } q( @@ -98,7 +98,7 @@ class Queue outq_priority = outq_priority + %d, outq_scheduled = '%s' WHERE outq_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($add_priority), dbesc($next), dbesc($x[0]['outq_hash']) @@ -133,7 +133,7 @@ class Queue if ($forThisUrl) { q("update outq set outq_scheduled = '%s' where outq_hash = '%s' and outq_delivered = 0", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($forThisUrl[0]['outq_hash']) ); } @@ -161,8 +161,8 @@ class Queue q( "update outq set outq_delivered = 1, outq_updated = '%s', outq_scheduled = '%s' where outq_hash = '%s' $sql_extra ", - dbesc(datetime_convert()), - dbesc(datetime_convert('UTC', 'UTC', 'now + 5 days')), + dbesc(Time::convert()), + dbesc(Time::convert('UTC', 'UTC', 'now + 5 days')), dbesc($id) ); } @@ -193,9 +193,9 @@ class Queue dbesc($arr['posturl']), intval(1), intval((isset($arr['priority'])) ? $arr['priority'] : 0), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc((isset($arr['scheduled'])) ? $arr['scheduled'] : datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), + dbesc((isset($arr['scheduled'])) ? $arr['scheduled'] : Time::convert()), dbesc($arr['notify']), dbesc(($arr['msg']) ?: '') ); @@ -220,7 +220,7 @@ class Queue if ($y) { // Don't bother delivering if the site is dead. // And if we haven't heard from the site in over a month - let them through but 3 strikes you're out. - if (intval($y[0]['site_dead']) || ($y[0]['site_update'] < datetime_convert('UTC', 'UTC', 'now - 1 month') + if (intval($y[0]['site_dead']) || ($y[0]['site_update'] < Time::convert('UTC', 'UTC', 'now - 1 month') && $outq['outq_priority'] > 20 )) { q( "update dreport set dreport_result = '%s' where dreport_queue = '%s'", @@ -240,7 +240,7 @@ class Queue site_store_lowlevel( [ 'site_url' => $base, - 'site_update' => datetime_convert(), + 'site_update' => Time::convert(), 'site_dead' => 0, 'site_type' => ((in_array($outq['outq_driver'], ['post', 'activitypub'])) ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN), 'site_crypto' => '' @@ -264,14 +264,14 @@ class Queue if ($base) { q( "update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($base) ); } q( "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'", dbesc('accepted for delivery'), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($outq['outq_hash']) ); self::remove($outq['outq_hash']); @@ -379,7 +379,7 @@ class Queue $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; $ret = $outq['outq_msg']; logger('ActivityPub send: ' . jindent($ret), LOGGER_DATA); - $headers['Date'] = datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); + $headers['Date'] = Time::convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); $headers['Digest'] = HTTPSig::generate_digest_header($ret); $headers['Host'] = $m['host']; $headers['(request-target)'] = 'post ' . get_request_string($outq['outq_posturl']); @@ -397,14 +397,14 @@ class Queue if ($base) { q( "update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($base) ); } q( "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'", dbesc('accepted for delivery'), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($outq['outq_hash']) ); self::remove($outq['outq_hash']); @@ -434,7 +434,7 @@ class Queue q( "update dreport set dreport_result = '%s', dreport_time = '%s' where dreport_queue = '%s'", dbesc('delivery rejected' . ' ' . $result['return_code']), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($outq['outq_hash']) ); self::remove($outq['outq_hash']); diff --git a/Code/Lib/Socgraph.php b/Code/Lib/Socgraph.php index 5df44dcec..021facf10 100644 --- a/Code/Lib/Socgraph.php +++ b/Code/Lib/Socgraph.php @@ -102,7 +102,7 @@ class Socgraph { if ($r) { q( "update xchat set xchat_edited = '%s' where xchat_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['xchat_id']) ); } else { @@ -112,7 +112,7 @@ class Socgraph { dbesc(escape_tags($room['url'])), dbesc(escape_tags($room['desc'])), dbesc($xchan), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); } } @@ -223,12 +223,12 @@ class Socgraph { intval(0), dbesc(''), dbesc(''), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); } else { q( "update xlink set xlink_updated = '%s' where xlink_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['xlink_id']) ); } @@ -330,12 +330,12 @@ class Socgraph { intval(0), dbesc(''), dbesc(''), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); } else { q( "update xlink set xlink_updated = '%s' where xlink_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['xlink_id']) ); } diff --git a/Code/Lib/ThreadItem.php b/Code/Lib/ThreadItem.php index 08a0e612c..18872a9bc 100644 --- a/Code/Lib/ThreadItem.php +++ b/Code/Lib/ThreadItem.php @@ -339,13 +339,13 @@ class ThreadItem $keep_reports = 10; } - if ((! get_config('system', 'disable_dreport')) && strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', "now - $keep_reports days")) > 0) { + if ((! get_config('system', 'disable_dreport')) && strcmp(Time::convert('UTC', 'UTC', $item['created']), Time::convert('UTC', 'UTC', "now - $keep_reports days")) > 0) { $dreport = t('Delivery report'); $dreport_link = gen_link_id($item['mid']); } $is_new = false; - if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) { + if (strcmp(Time::convert('UTC', 'UTC', $item['created']), Time::convert('UTC', 'UTC', 'now - 12 hours')) > 0) { $is_new = true; } @@ -440,10 +440,10 @@ class ThreadItem 'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf(t('from %s'), $item['app']), - 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), - 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), - 'editedtime' => (($item['edited'] != $item['created']) ? sprintf(t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), - 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf(t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : ''), + 'isotime' => Time::convert('UTC', date_default_timezone_get(), $item['created'], 'c'), + 'localtime' => Time::convert('UTC', date_default_timezone_get(), $item['created'], 'r'), + 'editedtime' => (($item['edited'] != $item['created']) ? sprintf(t('last edited: %s'), Time::convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), + 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf(t('Expires: %s'), Time::convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : ''), 'lock' => $lock, 'locktype' => $locktype, 'delayed' => $item['item_delayed'], diff --git a/Code/Lib/Tombstone.php b/Code/Lib/Tombstone.php index b2113940a..2afd34d03 100644 --- a/Code/Lib/Tombstone.php +++ b/Code/Lib/Tombstone.php @@ -19,7 +19,7 @@ class Tombstone $r = q("insert into tombstone (id_hash, id_channel, deleted_at) values ('%s', %d, '%s')", dbesc(hash('sha256',$url)), intval($channel_id), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); return $r; } diff --git a/Code/Lib/Url.php b/Code/Lib/Url.php index 277d9c62d..7e8b224c3 100644 --- a/Code/Lib/Url.php +++ b/Code/Lib/Url.php @@ -476,7 +476,7 @@ class Url { { $output = EMPTY_STR; if (isset($ret['debug'])) { - $output .= datetime_convert() . EOL; + $output .= Time::convert() . EOL; $output .= t('url: ') . $ret['debug']['url'] . EOL; $output .= t('http_code: ') . ((isset($ret['debug']['http_code'])) ? $ret['debug']['http_code'] : 0) . EOL; $output .= t('error_code: ') . $ret['debug']['error_code'] . EOL; diff --git a/Code/Lib/Verify.php b/Code/Lib/Verify.php index 78f3d8428..fc70d3271 100644 --- a/Code/Lib/Verify.php +++ b/Code/Lib/Verify.php @@ -20,7 +20,7 @@ class Verify intval($channel_id), dbesc($token), dbesc($meta), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); } diff --git a/Code/Lib/Xprof.php b/Code/Lib/Xprof.php index d69206c8f..7050a97aa 100644 --- a/Code/Lib/Xprof.php +++ b/Code/Lib/Xprof.php @@ -12,7 +12,7 @@ class Xprof { $store = [ 'xprof_hash' => $profile['xprof_hash'], - 'xprof_dob' => (($profile['birthday'] === '0000-00-00') ? $profile['birthday'] : datetime_convert('', '', $profile['birthday'], 'Y-m-d')), + 'xprof_dob' => (($profile['birthday'] === '0000-00-00') ? $profile['birthday'] : Time::convert('', '', $profile['birthday'], 'Y-m-d')), 'xprof_age' => (($profile['age']) ? intval($profile['age']) : 0), 'xprof_desc' => (($profile['description']) ? htmlspecialchars($profile['description'], ENT_COMPAT, 'UTF-8', false) : ''), 'xprof_gender' => (($profile['gender']) ? htmlspecialchars($profile['gender'], ENT_COMPAT, 'UTF-8', false) : ''), diff --git a/Code/Module/Admin/Account_edit.php b/Code/Module/Admin/Account_edit.php index 9d941d630..147313f96 100644 --- a/Code/Module/Admin/Account_edit.php +++ b/Code/Module/Admin/Account_edit.php @@ -2,6 +2,7 @@ namespace Code\Module\Admin; +use Code\Lib\Time; use Code\Render\Theme; @@ -27,7 +28,7 @@ class Account_edit account_password_changed = '%s' where account_id = %d", dbesc($salt), dbesc($password_encoded), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($account_id) ); if ($r) { diff --git a/Code/Module/Admin/Accounts.php b/Code/Module/Admin/Accounts.php index cf03d70fb..9b64fddc8 100644 --- a/Code/Module/Admin/Accounts.php +++ b/Code/Module/Admin/Accounts.php @@ -5,6 +5,7 @@ namespace Code\Module\Admin; use App; use Code\Lib\Account; use Code\Lib\Channel; +use Code\Lib\Time; use Code\Render\Theme; @@ -163,9 +164,9 @@ class Accounts if ($users) { for ($x = 0; $x < count($users); $x++) { - $users[$x]['account_lastlog'] = datetime_convert(to: date_default_timezone_get(), datetime: $users[$x]['account_lastlog']); - $users[$x]['account_created'] = datetime_convert(to: date_default_timezone_get(), datetime: $users[$x]['account_created']); - $users[$x]['account_expires'] = datetime_convert(to: date_default_timezone_get(), datetime: $users[$x]['account_expires']); + $users[$x]['account_lastlog'] = Time::convert(to: date_default_timezone_get(), datetime: $users[$x]['account_lastlog']); + $users[$x]['account_created'] = Time::convert(to: date_default_timezone_get(), datetime: $users[$x]['account_created']); + $users[$x]['account_expires'] = Time::convert(to: date_default_timezone_get(), datetime: $users[$x]['account_expires']); $channel_arr = explode(' ', $users[$x]['channels']); if ($channel_arr) { diff --git a/Code/Module/Admin/Queue.php b/Code/Module/Admin/Queue.php index 5e43bf2f2..f493fcf1e 100644 --- a/Code/Module/Admin/Queue.php +++ b/Code/Module/Admin/Queue.php @@ -4,6 +4,7 @@ namespace Code\Module\Admin; use Code\Lib\Queue as ZQueue; +use Code\Lib\Time; use Code\Render\Theme; @@ -45,7 +46,7 @@ class Queue for ($x = 0; $x < count($r); $x++) { $r[$x]['eurl'] = urlencode($r[$x]['outq_posturl']); - $r[$x]['connected'] = datetime_convert('UTC', date_default_timezone_get(), $r[$x]['connected'], 'Y-m-d'); + $r[$x]['connected'] = Time::convert('UTC', date_default_timezone_get(), $r[$x]['connected'], 'Y-m-d'); } $o = replace_macros(Theme::get_template('admin_queue.tpl'), array( diff --git a/Code/Module/Admin/Site.php b/Code/Module/Admin/Site.php index e5aec37c2..a702d3c7a 100644 --- a/Code/Module/Admin/Site.php +++ b/Code/Module/Admin/Site.php @@ -7,6 +7,7 @@ use Code\Lib\System; use Code\Lib\PConfig; use Code\Access\PermissionRoles; use Code\Lib\Channel; +use Code\Lib\Time; use Code\Render\Theme; use Code\Lib\Addon; use Code\Module\Legal; @@ -146,7 +147,7 @@ class Site q( "update xchan set xchan_name = '%s' , xchan_name_date = '%s' where xchan_hash = '%s'", dbesc($sitename), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($sys['channel_hash']) ); diff --git a/Code/Module/Apporder.php b/Code/Module/Apporder.php index 03f042f09..ecc47a300 100644 --- a/Code/Module/Apporder.php +++ b/Code/Module/Apporder.php @@ -2,6 +2,7 @@ namespace Code\Module; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Apps; use Code\Lib\Navbar; @@ -18,9 +19,9 @@ class Apporder extends Controller return ''; } - if (get_pconfig(local_channel(), 'system', 'import_system_apps') !== datetime_convert('UTC', 'UTC', 'now', 'Y-m-d')) { + if (get_pconfig(local_channel(), 'system', 'import_system_apps') !== Time::convert('UTC', 'UTC', 'now', 'Y-m-d')) { Apps::import_system_apps(); - set_pconfig(local_channel(), 'system', 'import_system_apps', datetime_convert('UTC', 'UTC', 'now', 'Y-m-d')); + set_pconfig(local_channel(), 'system', 'import_system_apps', Time::convert('UTC', 'UTC', 'now', 'Y-m-d')); } Navbar::set_selected('Order Apps'); diff --git a/Code/Module/Cal.php b/Code/Module/Cal.php index a09fdffb1..e67ed2fcf 100644 --- a/Code/Module/Cal.php +++ b/Code/Module/Cal.php @@ -8,6 +8,7 @@ use Code\Lib\Libprofile; use Code\Lib\Apps; use Code\Lib\Channel; use Code\Lib\Navbar; +use Code\Lib\Time; use Code\Render\Theme; @@ -130,22 +131,22 @@ class Cal extends Controller $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); } - $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); - $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); - $sday = datetime_convert('UTC', $tz, $sdt, 'd'); - $shour = datetime_convert('UTC', $tz, $sdt, 'H'); - $sminute = datetime_convert('UTC', $tz, $sdt, 'i'); + $syear = Time::convert('UTC', $tz, $sdt, 'Y'); + $smonth = Time::convert('UTC', $tz, $sdt, 'm'); + $sday = Time::convert('UTC', $tz, $sdt, 'd'); + $shour = Time::convert('UTC', $tz, $sdt, 'H'); + $sminute = Time::convert('UTC', $tz, $sdt, 'i'); - $stext = datetime_convert('UTC', $tz, $sdt); + $stext = Time::convert('UTC', $tz, $sdt); $stext = substr($stext, 0, 14) . "00:00"; - $fyear = datetime_convert('UTC', $tz, $fdt, 'Y'); - $fmonth = datetime_convert('UTC', $tz, $fdt, 'm'); - $fday = datetime_convert('UTC', $tz, $fdt, 'd'); - $fhour = datetime_convert('UTC', $tz, $fdt, 'H'); - $fminute = datetime_convert('UTC', $tz, $fdt, 'i'); + $fyear = Time::convert('UTC', $tz, $fdt, 'Y'); + $fmonth = Time::convert('UTC', $tz, $fdt, 'm'); + $fday = Time::convert('UTC', $tz, $fdt, 'd'); + $fhour = Time::convert('UTC', $tz, $fdt, 'H'); + $fminute = Time::convert('UTC', $tz, $fdt, 'i'); - $ftext = datetime_convert('UTC', $tz, $fdt); + $ftext = Time::convert('UTC', $tz, $fdt); $ftext = substr($ftext, 0, 14) . "00:00"; $type = ((x($orig_event)) ? $orig_event['etype'] : 'event'); @@ -166,8 +167,8 @@ class Cal extends Controller $category = ''; - $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y'); - $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm'); + $thisyear = Time::convert('UTC', date_default_timezone_get(), 'now', 'Y'); + $thismonth = Time::convert('UTC', date_default_timezone_get(), 'now', 'm'); if (!$y) { $y = intval($thisyear); } @@ -214,11 +215,11 @@ class Cal extends Controller } } - $start = datetime_convert('UTC', 'UTC', $start); - $finish = datetime_convert('UTC', 'UTC', $finish); + $start = Time::convert('UTC', 'UTC', $start); + $finish = Time::convert('UTC', 'UTC', $finish); - $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); - $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); + $adjust_start = Time::convert('UTC', date_default_timezone_get(), $start); + $adjust_finish = Time::convert('UTC', date_default_timezone_get(), $finish); if (!perm_is_allowed(App::$profile['uid'], get_observer_hash(), 'view_contacts')) { @@ -263,7 +264,7 @@ class Cal extends Controller if ($r) { foreach ($r as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j')); + $j = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'j')); if (!x($links, $j)) { $links[$j] = z_root() . '/' . App::$cmd . '#link-' . $j; } @@ -277,15 +278,15 @@ class Cal extends Controller if ($r) { foreach ($r as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j')); - $d = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt)); + $j = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'j')); + $d = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : Time::convert('UTC', 'UTC', $rr['dtstart'], $fmt)); $d = day_translate($d); - $start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c')); + $start = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'c')); if ($rr['nofinish']) { $end = null; } else { - $end = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c')); + $end = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : Time::convert('UTC', 'UTC', $rr['dtend'], 'c')); } diff --git a/Code/Module/Calendar.php b/Code/Module/Calendar.php index 215ccf58e..a15b045de 100644 --- a/Code/Module/Calendar.php +++ b/Code/Module/Calendar.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Libsync; use Code\Access\AccessControl; @@ -67,14 +68,14 @@ class Calendar extends Controller } if ($adjust) { - $start = datetime_convert($tz, 'UTC', $start); + $start = Time::convert($tz, 'UTC', $start); if (!$nofinish) { - $finish = datetime_convert($tz, 'UTC', $finish); + $finish = Time::convert($tz, 'UTC', $finish); } } else { - $start = datetime_convert('UTC', 'UTC', $start); + $start = Time::convert('UTC', 'UTC', $start); if (!$nofinish) { - $finish = datetime_convert('UTC', 'UTC', $finish); + $finish = Time::convert('UTC', 'UTC', $finish); } } @@ -122,9 +123,9 @@ class Calendar extends Controller $acl->set($x[0]); $created = $x[0]['created']; - $edited = datetime_convert(); + $edited = Time::convert(); } else { - $created = $edited = datetime_convert(); + $created = $edited = Time::convert(); $acl->set_from_array($_POST); } @@ -321,11 +322,11 @@ class Calendar extends Controller } } - $start = datetime_convert('UTC', 'UTC', $start); - $finish = datetime_convert('UTC', 'UTC', $finish); + $start = Time::convert('UTC', 'UTC', $start); + $finish = Time::convert('UTC', 'UTC', $finish); - $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); - $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); + $adjust_start = Time::convert('UTC', date_default_timezone_get(), $start); + $adjust_finish = Time::convert('UTC', date_default_timezone_get(), $finish); if (x($_GET, 'id')) { $r = q( @@ -371,11 +372,11 @@ class Calendar extends Controller if ($r) { foreach ($r as $rr) { - $start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c')); + $start = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'c')); if ($rr['nofinish']) { $end = null; } else { - $end = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c')); + $end = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : Time::convert('UTC', 'UTC', $rr['dtend'], 'c')); // give a fake end to birthdays so they get crammed into a // single day on the calendar diff --git a/Code/Module/Cdav.php b/Code/Module/Cdav.php index 96b795fe4..fa4ea3f58 100644 --- a/Code/Module/Cdav.php +++ b/Code/Module/Cdav.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\HTTPHeaders; use DBA; use DateTime; @@ -320,10 +321,10 @@ class Cdav extends Controller } $title = $_REQUEST['title']; - $start = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtstart']); + $start = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtstart']); $dtstart = new DateTime($start); if ($_REQUEST['dtend']) { - $end = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtend']); + $end = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtend']); $dtend = new DateTime($end); } $description = $_REQUEST['description']; @@ -401,10 +402,10 @@ class Cdav extends Controller $uri = $_REQUEST['uri']; $title = $_REQUEST['title']; - $start = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtstart']); + $start = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtstart']); $dtstart = new DateTime($start); if ($_REQUEST['dtend']) { - $end = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtend']); + $end = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtend']); $dtend = new DateTime($end); } $description = $_REQUEST['description']; @@ -461,10 +462,10 @@ class Cdav extends Controller } $uri = $_REQUEST['uri']; - $start = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtstart']); + $start = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtstart']); $dtstart = new DateTime($start); if ($_REQUEST['dtend']) { - $end = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtend']); + $end = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['dtend']); $dtend = new DateTime($end); } @@ -967,8 +968,8 @@ class Cdav extends Controller xchan_query($r); $r = fetch_post_tags($r); - $r[0]['dtstart'] = (($r[0]['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $r[0]['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $r[0]['dtstart'], 'c')); - $r[0]['dtend'] = (($r[0]['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $r[0]['dtend'], 'c') : datetime_convert('UTC', 'UTC', $r[0]['dtend'], 'c')); + $r[0]['dtstart'] = (($r[0]['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $r[0]['dtstart'], 'c') : Time::convert('UTC', 'UTC', $r[0]['dtstart'], 'c')); + $r[0]['dtend'] = (($r[0]['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $r[0]['dtend'], 'c') : Time::convert('UTC', 'UTC', $r[0]['dtend'], 'c')); $r[0]['plink'] = [$r[0]['plink'], t('Link to source')]; @@ -1163,8 +1164,8 @@ class Cdav extends Controller 'calendar_id' => $id, 'uri' => $object['uri'], 'title' => $title, - 'start' => datetime_convert($timezone, $timezone, $dtstart, 'c'), - 'end' => (($dtend) ? datetime_convert($timezone, $timezone, $dtend, 'c') : ''), + 'start' => Time::convert($timezone, $timezone, $dtstart, 'c'), + 'end' => (($dtend) ? Time::convert($timezone, $timezone, $dtend, 'c') : ''), 'description' => $description, 'location' => $location, 'allDay' => $allDay, diff --git a/Code/Module/Changeaddr.php b/Code/Module/Changeaddr.php index edb170c60..0e58750cf 100644 --- a/Code/Module/Changeaddr.php +++ b/Code/Module/Changeaddr.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Channel; use Code\Render\Theme; @@ -55,7 +56,7 @@ class Changeaddr extends Controller } if ($account['account_password_changed'] > NULL_DATE) { - $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours'); + $d1 = Time::convert('UTC', 'UTC', 'now - 48 hours'); if ($account['account_password_changed'] > $d1) { notice(t('Channel name changes are not allowed within 48 hours of changing the account password.') . EOL); return; diff --git a/Code/Module/Channel.php b/Code/Module/Channel.php index 31d608293..05e6ee4eb 100644 --- a/Code/Module/Channel.php +++ b/Code/Module/Channel.php @@ -11,6 +11,7 @@ use Code\Lib\ActivityStreams; use Code\Lib\Crypto; use Code\Lib\PConfig; use Code\Lib as Zlib; +use Code\Lib\Time; use Code\Web\HTTPSig; use App; use Code\Web\Controller; @@ -264,7 +265,7 @@ class Channel extends Controller if ($this->loading && !$mid) { - $_SESSION['loadtime_channel'] = datetime_convert(); + $_SESSION['loadtime_channel'] = Time::convert(); if ($is_owner) { PConfig::Set(local_channel(), 'system', 'loadtime_channel', $_SESSION['loadtime_channel']); } @@ -386,7 +387,7 @@ class Channel extends Controller ]); if ($this->updating && isset($_SESSION['loadtime_channel'])) { - $simple_update = " AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime_channel']) . "' "; + $simple_update = " AND item.changed > '" . Time::convert('UTC', 'UTC', $_SESSION['loadtime_channel']) . "' "; } if ($this->loading) { $simple_update = ''; @@ -425,11 +426,11 @@ class Channel extends Controller } if ($datequery) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery)))); + $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(Time::convert(date_default_timezone_get(), '', $datequery)))); $order = 'post'; } if ($datequery2) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2)))); + $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(Time::convert(date_default_timezone_get(), '', $datequery2)))); } if ($datequery || $datequery2) { diff --git a/Code/Module/Chatsvc.php b/Code/Module/Chatsvc.php index 80146ca55..e935ad1e1 100644 --- a/Code/Module/Chatsvc.php +++ b/Code/Module/Chatsvc.php @@ -7,6 +7,7 @@ namespace Code\Module; use App; use Code\Lib as Zlib; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Channel; use Code\Extend\Hook; @@ -74,7 +75,7 @@ class Chatsvc extends Controller values( %d, '%s', '%s', '%s' )", intval(App::$data['chat']['room_id']), dbesc(get_observer_hash()), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(str_rot47(base64url_encode($arr['chat_text']))) ); @@ -98,7 +99,7 @@ class Chatsvc extends Controller $r = q( "update chatpresence set cp_status = '%s', cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s'", dbesc($status), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($room_id), dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']) @@ -174,8 +175,8 @@ class Chatsvc extends Controller 'img' => zid($rr['xchan_photo_m']), 'img_type' => $rr['xchan_photo_mimetype'], 'name' => $rr['xchan_name'], - 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'c'), - 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'r'), + 'isotime' => Time::convert('UTC', date_default_timezone_get(), $rr['created'], 'c'), + 'localtime' => Time::convert('UTC', date_default_timezone_get(), $rr['created'], 'r'), 'text' => zidify_links(smilies(bbcode(base64url_decode(str_rot47($rr['chat_text']))))), 'self' => ((get_observer_hash() == $rr['chat_xchan']) ? 'self' : '') ]; @@ -185,7 +186,7 @@ class Chatsvc extends Controller $r = q( "update chatpresence set cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval(App::$data['chat']['room_id']), dbesc(get_observer_hash()), dbesc($_SERVER['REMOTE_ADDR']) diff --git a/Code/Module/Connections.php b/Code/Module/Connections.php index e9517e32c..9ca026005 100644 --- a/Code/Module/Connections.php +++ b/Code/Module/Connections.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Lib\XConfig; use Code\Web\Controller; use Code\Lib\LibBlock; @@ -359,7 +360,7 @@ class Connections extends Controller 'status_label' => t('Status'), 'status' => $status_str, 'connected_label' => t('Connected'), - 'connected' => datetime_convert('UTC', date_default_timezone_get(), $rr['abook_created'], 'c'), + 'connected' => Time::convert('UTC', date_default_timezone_get(), $rr['abook_created'], 'c'), 'approve_hover' => t('Approve connection'), 'approve' => (($rr['abook_pending']) ? t('Approve') : false), 'ignore_hover' => t('Ignore connection'), diff --git a/Code/Module/Cover_photo.php b/Code/Module/Cover_photo.php index c43220135..db556456f 100644 --- a/Code/Module/Cover_photo.php +++ b/Code/Module/Cover_photo.php @@ -6,6 +6,7 @@ use App; use Code\Lib\Activity; use Code\Lib\Libprofile; use Code\Access\AccessControl; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Channel; use Code\Extend\Hook; @@ -294,8 +295,8 @@ class Cover_photo extends Controller $arr['obj'] = [ 'type' => ACTIVITY_OBJ_NOTE, - 'published' => datetime_convert('UTC', 'UTC', 'now', ISO8601), - 'updated' => datetime_convert('UTC', 'UTC', 'now', ISO8601), + 'published' => Time::convert('UTC', 'UTC', 'now', ISO8601), + 'updated' => Time::convert('UTC', 'UTC', 'now', ISO8601), 'id' => $arr['mid'], 'url' => ['type' => 'Link', 'mediaType' => $photo['mimetype'], 'href' => z_root() . '/photo/' . $photo['resource_id'] . '-7'], 'source' => ['content' => $arr['body'], 'mediaType' => 'text/x-multicode'], diff --git a/Code/Module/Dirsearch.php b/Code/Module/Dirsearch.php index d9a14d5d1..700e684cb 100644 --- a/Code/Module/Dirsearch.php +++ b/Code/Module/Dirsearch.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; // This is the primary endpoint for communicating with Zot directory services. @@ -94,9 +95,9 @@ class Dirsearch extends Controller if (array_key_exists('sync', $_REQUEST)) { if ($_REQUEST['sync']) { - $sync = datetime_convert('UTC', 'UTC', $_REQUEST['sync']); + $sync = Time::convert('UTC', 'UTC', $_REQUEST['sync']); } else { - $sync = datetime_convert('UTC', 'UTC', '2010-01-01 01:01:00'); + $sync = Time::convert('UTC', 'UTC', '2010-01-01 01:01:00'); } } else { $sync = false; @@ -179,7 +180,7 @@ class Dirsearch extends Controller // mtime is not currently working - $mtime = ((x($_REQUEST, 'mtime')) ? datetime_convert('UTC', 'UTC', $_REQUEST['mtime']) : ''); + $mtime = ((x($_REQUEST, 'mtime')) ? Time::convert('UTC', 'UTC', $_REQUEST['mtime']) : ''); // merge them into xprof @@ -207,7 +208,7 @@ class Dirsearch extends Controller $activesql = EMPTY_STR; if ($active) { - $activesql = "and xchan_updated > '" . datetime_convert(date_default_timezone_get(), 'UTC', 'now - 60 days') . "' "; + $activesql = "and xchan_updated > '" . Time::convert(date_default_timezone_get(), 'UTC', 'now - 60 days') . "' "; } if ($limit) { diff --git a/Code/Module/Display.php b/Code/Module/Display.php index cd84972d2..5c79030c9 100644 --- a/Code/Module/Display.php +++ b/Code/Module/Display.php @@ -6,6 +6,7 @@ use App; use Code\Lib\PermissionDescription; use Code\Lib\System; use Code\Lib\PConfig; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Channel; use Code\Lib\Libacl; @@ -42,7 +43,7 @@ class Display extends Controller } if ($this->loading) { - $_SESSION['loadtime_display'] = datetime_convert(); + $_SESSION['loadtime_display'] = Time::convert(); } if (argc() > 1) { @@ -200,7 +201,7 @@ class Display extends Controller $simple_update = (($this->updating) ? " AND item_unseen = 1 " : ''); if ($this->updating && $_SESSION['loadtime_display']) { - $simple_update = " AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime_display']) . "' "; + $simple_update = " AND item.changed > '" . Time::convert('UTC', 'UTC', $_SESSION['loadtime_display']) . "' "; } if ($this->loading) { $simple_update = ''; @@ -452,7 +453,7 @@ class Display extends Controller '$generator_uri' => z_root(), '$feed_id' => xmlify(App::$cmd), '$feed_title' => xmlify(t('Article')), - '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ISO8601)), + '$feed_updated' => xmlify(Time::convert('UTC', 'UTC', 'now', ISO8601)), '$author' => '', '$owner' => '', '$profile_page' => xmlify(z_root() . '/display/?mid=' . $target_item['mid']), diff --git a/Code/Module/Dreport.php b/Code/Module/Dreport.php index 3e6945e3e..ac45a986a 100644 --- a/Code/Module/Dreport.php +++ b/Code/Module/Dreport.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Daemon\Run; use Code\Render\Theme; @@ -166,7 +167,7 @@ class Dreport extends Controller $entries[] = [ 'name' => escape_tags($rr['dreport_name'] ?: $rr['dreport_recip']), 'result' => $rr['dreport_result'], - 'time' => escape_tags(datetime_convert('UTC', date_default_timezone_get(), $rr['dreport_time'])) + 'time' => escape_tags(Time::convert('UTC', date_default_timezone_get(), $rr['dreport_time'])) ]; } diff --git a/Code/Module/Events.php b/Code/Module/Events.php index 911270d1b..72c18a346 100644 --- a/Code/Module/Events.php +++ b/Code/Module/Events.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use DateTime; use Code\Lib\PermissionDescription; use Code\Web\Controller; @@ -92,14 +93,14 @@ class Events extends Controller if ($adjust) { - $start = datetime_convert($tz, 'UTC', $start); + $start = Time::convert($tz, 'UTC', $start); if (!$nofinish) { - $finish = datetime_convert($tz, 'UTC', $finish); + $finish = Time::convert($tz, 'UTC', $finish); } } else { - $start = datetime_convert('UTC', 'UTC', $start); + $start = Time::convert('UTC', 'UTC', $start); if (!$nofinish) { - $finish = datetime_convert('UTC', 'UTC', $finish); + $finish = Time::convert('UTC', 'UTC', $finish); } } @@ -118,7 +119,7 @@ class Events extends Controller $freq = ((array_key_exists('freq', $_REQUEST) && $_REQUEST['freq']) ? escape_tags(trim($_REQUEST['freq'])) : EMPTY_STR); $interval = ((array_key_exists('interval', $_REQUEST) && intval($_REQUEST['interval'])) ? 1 : 0); $count = ((array_key_exists('count', $_REQUEST) && intval($_REQUEST['count'])) ? intval($_REQUEST['count']) : 0); - $until = ((array_key_exists('until', $_REQUEST) && $_REQUEST['until']) ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['until']) : NULL_DATE); + $until = ((array_key_exists('until', $_REQUEST) && $_REQUEST['until']) ? Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['until']) : NULL_DATE); $byday = []; if ((!$freq) || (!in_array($freq, ['DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY']))) { @@ -183,7 +184,7 @@ class Events extends Controller $acl->set($x[0]); $created = $x[0]['created']; - $edited = datetime_convert(); + $edited = Time::convert(); if ( $x[0]['allow_cid'] === '<' . $channel['channel_hash'] . '>' @@ -194,7 +195,7 @@ class Events extends Controller $share = true; } } else { - $created = $edited = datetime_convert(); + $created = $edited = Time::convert(); if ($share) { $acl->set_from_array($_POST); } else { @@ -422,22 +423,22 @@ class Events extends Controller $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); } - $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); - $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); - $sday = datetime_convert('UTC', $tz, $sdt, 'd'); - $shour = datetime_convert('UTC', $tz, $sdt, 'H'); - $sminute = datetime_convert('UTC', $tz, $sdt, 'i'); + $syear = Time::convert('UTC', $tz, $sdt, 'Y'); + $smonth = Time::convert('UTC', $tz, $sdt, 'm'); + $sday = Time::convert('UTC', $tz, $sdt, 'd'); + $shour = Time::convert('UTC', $tz, $sdt, 'H'); + $sminute = Time::convert('UTC', $tz, $sdt, 'i'); - $stext = datetime_convert('UTC', $tz, $sdt); + $stext = Time::convert('UTC', $tz, $sdt); $stext = substr($stext, 0, 14) . "00:00"; - $fyear = datetime_convert('UTC', $tz, $fdt, 'Y'); - $fmonth = datetime_convert('UTC', $tz, $fdt, 'm'); - $fday = datetime_convert('UTC', $tz, $fdt, 'd'); - $fhour = datetime_convert('UTC', $tz, $fdt, 'H'); - $fminute = datetime_convert('UTC', $tz, $fdt, 'i'); + $fyear = Time::convert('UTC', $tz, $fdt, 'Y'); + $fmonth = Time::convert('UTC', $tz, $fdt, 'm'); + $fday = Time::convert('UTC', $tz, $fdt, 'd'); + $fhour = Time::convert('UTC', $tz, $fdt, 'H'); + $fminute = Time::convert('UTC', $tz, $fdt, 'i'); - $ftext = datetime_convert('UTC', $tz, $fdt); + $ftext = Time::convert('UTC', $tz, $fdt); $ftext = substr($ftext, 0, 14) . "00:00"; $type = ((x($orig_event)) ? $orig_event['etype'] : 'event'); @@ -537,8 +538,8 @@ class Events extends Controller ]); /* end edit/create form */ - $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y'); - $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm'); + $thisyear = Time::convert('UTC', date_default_timezone_get(), 'now', 'Y'); + $thismonth = Time::convert('UTC', date_default_timezone_get(), 'now', 'm'); if (!$y) { $y = intval($thisyear); } @@ -590,11 +591,11 @@ class Events extends Controller } } - $start = datetime_convert('UTC', 'UTC', $start); - $finish = datetime_convert('UTC', 'UTC', $finish); + $start = Time::convert('UTC', 'UTC', $start); + $finish = Time::convert('UTC', 'UTC', $finish); - $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); - $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); + $adjust_start = Time::convert('UTC', date_default_timezone_get(), $start); + $adjust_finish = Time::convert('UTC', date_default_timezone_get(), $finish); if (x($_GET, 'id')) { $r = q( @@ -645,7 +646,7 @@ class Events extends Controller if ($r) { foreach ($r as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j')); + $j = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'j')); if (!x($links, $j)) { $links[$j] = z_root() . '/' . App::$cmd . '#link-' . $j; } @@ -659,15 +660,15 @@ class Events extends Controller if ($r) { foreach ($r as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'j')); - $d = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : datetime_convert('UTC', 'UTC', $rr['dtstart'], $fmt)); + $j = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'j') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'j')); + $d = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], $fmt) : Time::convert('UTC', 'UTC', $rr['dtstart'], $fmt)); $d = day_translate($d); - $start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtstart'], 'c')); + $start = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtstart'], 'c') : Time::convert('UTC', 'UTC', $rr['dtstart'], 'c')); if ($rr['nofinish']) { $end = null; } else { - $end = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : datetime_convert('UTC', 'UTC', $rr['dtend'], 'c')); + $end = (($rr['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $rr['dtend'], 'c') : Time::convert('UTC', 'UTC', $rr['dtend'], 'c')); // give a fake end to birthdays so they get crammed into a // single day on the calendar diff --git a/Code/Module/Fhublocs.php b/Code/Module/Fhublocs.php index a2374ca73..6587165ae 100644 --- a/Code/Module/Fhublocs.php +++ b/Code/Module/Fhublocs.php @@ -4,6 +4,7 @@ namespace Code\Module; use App; use Code\Lib\Libzot; use Code\Lib\Channel; +use Code\Lib\Time; use Code\Web\Controller; /* fix missing or damaged hublocs */ @@ -100,8 +101,8 @@ class Fhublocs extends Controller { 'hubloc_callback' => z_root() . '/nomad', 'hubloc_sitekey' => $sitekey, 'hubloc_network' => 'nomad', - 'hubloc_updated' => datetime_convert(), - 'hubloc_connected' => datetime_convert() + 'hubloc_updated' => Time::convert(), + 'hubloc_connected' => Time::convert() ] ); diff --git a/Code/Module/Home.php b/Code/Module/Home.php index de3e64360..97d331536 100644 --- a/Code/Module/Home.php +++ b/Code/Module/Home.php @@ -8,6 +8,7 @@ use Code\Lib\ActivityStreams; use Code\Lib\Activity; use Code\Lib\JcsEddsa2022; use Code\Lib\Crypto; +use Code\Lib\Time; use Code\Web\HTTPSig; use Code\Web\Controller; use Code\Lib\Channel; @@ -35,7 +36,7 @@ class Home extends Controller $x['proof'] = (new JcsEddsa2022)->sign($x, $channel); $ret = json_encode($x, JSON_UNESCAPED_SLASHES); logger('data: ' . jindent($ret), LOGGER_DATA); - $headers['Date'] = datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); + $headers['Date'] = Time::convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); $headers['Digest'] = HTTPSig::generate_digest_header($ret); $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; diff --git a/Code/Module/Impel.php b/Code/Module/Impel.php index 93b928fbf..499ef6735 100644 --- a/Code/Module/Impel.php +++ b/Code/Module/Impel.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use URLify; use Code\Lib\IConfig; use Code\Web\Controller; @@ -81,10 +82,10 @@ class Impel extends Controller $m['menu_name'] = $j['pagetitle']; $m['menu_desc'] = $j['desc']; if ($j['created']) { - $m['menu_created'] = datetime_convert($j['created']); + $m['menu_created'] = Time::convert($j['created']); } if ($j['edited']) { - $m['menu_edited'] = datetime_convert($j['edited']); + $m['menu_edited'] = Time::convert($j['edited']); } $m['menu_flags'] = 0; @@ -128,7 +129,7 @@ class Impel extends Controller if ($j['edited']) { $x = q( "update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", - dbesc(datetime_convert('UTC', 'UTC', $j['edited'])), + dbesc(Time::convert('UTC', 'UTC', $j['edited'])), intval($menu_id), intval(local_channel()) ); @@ -144,8 +145,8 @@ class Impel extends Controller $arr['body'] = $j['body']; $arr['term'] = $j['term']; $arr['layout_mid'] = $j['layout_mid']; - $arr['created'] = datetime_convert('UTC', 'UTC', $j['created']); - $arr['edited'] = datetime_convert('UTC', 'UTC', $j['edited']); + $arr['created'] = Time::convert('UTC', 'UTC', $j['created']); + $arr['edited'] = Time::convert('UTC', 'UTC', $j['edited']); $arr['owner_xchan'] = get_observer_hash(); $arr['author_xchan'] = (($j['author_xchan']) ? $j['author_xchan'] : get_observer_hash()); $arr['mimetype'] = (($j['mimetype']) ? $j['mimetype'] : 'text/x-multicode'); diff --git a/Code/Module/Import.php b/Code/Module/Import.php index 91c8cc95b..e74f77eae 100644 --- a/Code/Module/Import.php +++ b/Code/Module/Import.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use URLify; use Code\Web\Controller; use Code\Web\HTTPSig; @@ -238,9 +239,9 @@ class Import extends Controller 'xchan_follow' => z_root() . '/follow?f=&url=%s', 'xchan_name' => $channel['channel_name'], 'xchan_network' => 'nomad', - 'xchan_updated' => datetime_convert(), - 'xchan_photo_date' => datetime_convert(), - 'xchan_name_date' => datetime_convert() + 'xchan_updated' => Time::convert(), + 'xchan_photo_date' => Time::convert(), + 'xchan_name_date' => Time::convert() ] ); } @@ -281,7 +282,7 @@ class Import extends Controller if ($xchan['xchan_hash'] === $channel['channel_hash']) { $r = q( "update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(z_root() . '/photo/profile/l/' . $channel['channel_id']), dbesc(z_root() . '/photo/profile/m/' . $channel['channel_id']), dbesc(z_root() . '/photo/profile/s/' . $channel['channel_id']), @@ -298,7 +299,7 @@ class Import extends Controller $r = q( "update xchan set xchan_updated = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -341,7 +342,7 @@ class Import extends Controller 'hubloc_host' => App::get_hostname(), 'hubloc_callback' => z_root() . '/nomad', 'hubloc_sitekey' => get_config('system', 'pubkey'), - 'hubloc_updated' => datetime_convert() + 'hubloc_updated' => Time::convert() ] ); @@ -587,8 +588,8 @@ class Import extends Controller $hz_server = $m['scheme'] . '://' . $m['host']; - $since = datetime_convert(date_default_timezone_get(), date_default_timezone_get(), '0001-01-01 00:00'); - $until = datetime_convert(date_default_timezone_get(), date_default_timezone_get(), 'now + 1 day'); + $since = Time::convert(date_default_timezone_get(), date_default_timezone_get(), '0001-01-01 00:00'); + $until = Time::convert(date_default_timezone_get(), date_default_timezone_get(), 'now + 1 day'); $poll_interval = get_config('system', 'poll_interval', 3); $page = 0; diff --git a/Code/Module/Inbox.php b/Code/Module/Inbox.php index a37dc684d..6d3ea211e 100644 --- a/Code/Module/Inbox.php +++ b/Code/Module/Inbox.php @@ -6,6 +6,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\HTTPSig; use Code\Lib\ActivityStreams; use Code\Lib\Activity; @@ -200,7 +201,7 @@ class Inbox extends Controller // update the hubloc_connected timestamp, ignore failures q("update hubloc set hubloc_connected = '%s' where hubloc_hash = '%s' and hubloc_network = 'activitypub'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($observer_hash) ); diff --git a/Code/Module/Invite.php b/Code/Module/Invite.php index eb9c00f1e..f940cdbc1 100644 --- a/Code/Module/Invite.php +++ b/Code/Module/Invite.php @@ -4,6 +4,7 @@ namespace Code\Module; use App; use Code\Lib\Apps; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Navbar; use Code\Render\Theme; @@ -133,7 +134,7 @@ class Invite extends Controller $r = q( "INSERT INTO register (hash,created,uid,password,lang) VALUES ('%s', '%s',0,'','') ", dbesc($invite_code), - dbesc(datetime_convert()) + dbesc(Time::convert()) ); if (!is_site_admin()) { diff --git a/Code/Module/Item.php b/Code/Module/Item.php index d109dac63..fa4faf829 100644 --- a/Code/Module/Item.php +++ b/Code/Module/Item.php @@ -23,6 +23,7 @@ use Code\Lib\Libsync; use Code\Lib\Activity; use Code\Lib\ActivityStreams; use Code\Lib\JcsEddsa2022; +use Code\Lib\Time; use Code\Web\HTTPSig; use Code\Web\Controller; use Code\Lib\Libzot; @@ -442,12 +443,12 @@ class Item extends Controller // this is in days, convert to absolute time $channel_comments_closed = get_pconfig($profile_uid, 'system', 'close_comments'); if (intval($channel_comments_closed)) { - $channel_comments_closed = datetime_convert(date_Default_timezone_get(), 'UTC', 'now + ' . intval($channel_comments_closed) . ' days'); + $channel_comments_closed = Time::convert(date_Default_timezone_get(), 'UTC', 'now + ' . intval($channel_comments_closed) . ' days'); } else { $channel_comments_closed = NULL_DATE; } - $comments_closed = ((isset($_REQUEST['comments_closed']) && $_REQUEST['comments_closed']) ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['comments_closed']) : $channel_comments_closed); + $comments_closed = ((isset($_REQUEST['comments_closed']) && $_REQUEST['comments_closed']) ? Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['comments_closed']) : $channel_comments_closed); $is_poll = ((trim($_REQUEST['poll_answers'][0]) != '' && trim($_REQUEST['poll_answers'][1]) != '') ? true : false); @@ -470,12 +471,12 @@ class Item extends Controller $owner_hash = null; $message_id = ((x($_REQUEST, 'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : ''); - $created = ((x($_REQUEST, 'created')) ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['created']) : datetime_convert()); + $created = ((x($_REQUEST, 'created')) ? Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['created']) : Time::convert()); // Because somebody will probably try this and create a mess if ($created <= NULL_DATE) { - $created = datetime_convert(); + $created = Time::convert(); } $post_id = ((x($_REQUEST, 'post_id')) ? intval($_REQUEST['post_id']) : 0); @@ -924,8 +925,8 @@ class Item extends Controller if (Apps::system_app_installed($profile_uid, 'Expire Posts')) { if (x($_REQUEST, 'expire')) { - $expires = datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['expire']); - if ($expires <= datetime_convert()) { + $expires = Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['expire']); + if ($expires <= Time::convert()) { $expires = NULL_DATE; } } @@ -1394,7 +1395,7 @@ class Item extends Controller $datarray['obj'] = $obj; $obj_type = 'Question'; if ($obj['endTime']) { - $d = datetime_convert('UTC', 'UTC', $obj['endTime']); + $d = Time::convert('UTC', 'UTC', $obj['endTime']); if ($d > NULL_DATE) { $comments_closed = $d; } @@ -1473,11 +1474,11 @@ class Item extends Controller $datarray['owner_xchan'] = (($owner_hash) ? $owner_hash : $owner_xchan['xchan_hash']); $datarray['author_xchan'] = $observer['xchan_hash']; $datarray['created'] = $created; - $datarray['edited'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? datetime_convert() : $created); + $datarray['edited'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? Time::convert() : $created); $datarray['expires'] = $expires; - $datarray['commented'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? datetime_convert() : $created); - $datarray['received'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? datetime_convert() : $created); - $datarray['changed'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? datetime_convert() : $created); + $datarray['commented'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? Time::convert() : $created); + $datarray['received'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? Time::convert() : $created); + $datarray['changed'] = (($orig_post && (!intval($orig_post['item_unpublished']))) ? Time::convert() : $created); $datarray['comments_closed'] = $comments_closed; $datarray['mid'] = $mid; $datarray['parent_mid'] = $parent_mid; @@ -1750,7 +1751,7 @@ class Item extends Controller if ($uid && $uid == $profile_uid && (is_item_normal($datarray))) { q( "update channel set channel_lastpost = '%s' where channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($uid) ); } @@ -2034,7 +2035,7 @@ class Item extends Controller $matches = null; if (preg_match('/\[ends](.*?)\[\/ends]/ism', $body, $matches)) { - $obj['endTime'] = datetime_convert(date_default_timezone_get(), 'UTC', $matches[1], ISO8601); + $obj['endTime'] = Time::convert(date_default_timezone_get(), 'UTC', $matches[1], ISO8601); $body = str_replace('[ends]' . $matches[1] . '[/ends]', EMPTY_STR, $body); } @@ -2074,7 +2075,7 @@ class Item extends Controller $obj['oneOf'] = $ptr; } - $obj['endTime'] = datetime_convert(date_default_timezone_get(), 'UTC', 'now + ' . $expire_value . ' ' . $expire_unit, ISO8601); + $obj['endTime'] = Time::convert(date_default_timezone_get(), 'UTC', 'now + ' . $expire_value . ' ' . $expire_unit, ISO8601); if ($item['item_private']) { $obj['to'] = Activity::map_acl($item); diff --git a/Code/Module/Like.php b/Code/Module/Like.php index 4ae08e359..80ece8b2c 100644 --- a/Code/Module/Like.php +++ b/Code/Module/Like.php @@ -5,6 +5,7 @@ namespace Code\Module; use App; use Code\Lib\Libsync; use Code\Lib\Activity; +use Code\Lib\Time; use Code\Web\Controller; use Code\Daemon\Run; use Code\Lib\Channel; @@ -269,7 +270,7 @@ class Like extends Controller $arr['parent_mid'] = ($is_rsvp) ? reverse_activity_mid($item['parent_mid']) : $item['parent_mid']; $arr['owner_xchan'] = $thread_owner['xchan_hash']; $arr['author_xchan'] = $observer['xchan_hash']; - $arr['created'] = $arr['edited'] = datetime_convert(); + $arr['created'] = $arr['edited'] = Time::convert(); $arr['verb'] = (($undo) ? 'Undo' : $activity); diff --git a/Code/Module/Manage.php b/Code/Module/Manage.php index 23fcdbebf..dd48e85a6 100644 --- a/Code/Module/Manage.php +++ b/Code/Module/Manage.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\PConfig; use Code\Lib\ServiceClass; @@ -115,15 +116,15 @@ class Manage extends Controller WHERE event.uid = %d AND dtstart < '%s' AND dtstart > '%s' and dismissed = 0 ORDER BY dtstart ASC ", intval($channels[$x]['channel_id']), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + 7 days')), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now + 7 days')), + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now - 1 days')) ); if ($events) { $channels[$x]['all_events'] = count($events); if ($channels[$x]['all_events']) { - $str_now = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d'); + $str_now = Time::convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d'); foreach ($events as $e) { $bd = false; if ($e['etype'] === 'birthday') { @@ -132,7 +133,7 @@ class Manage extends Controller } else { $channels[$x]['events']++; } - if (datetime_convert('UTC', ((intval($e['adjust'])) ? date_default_timezone_get() : 'UTC'), $e['dtstart'], 'Y-m-d') === $str_now) { + if (Time::convert('UTC', ((intval($e['adjust'])) ? date_default_timezone_get() : 'UTC'), $e['dtstart'], 'Y-m-d') === $str_now) { $channels[$x]['all_events_today']++; if ($bd) { $channels[$x]['birthdays_today']++; diff --git a/Code/Module/Photos.php b/Code/Module/Photos.php index cc6b1caa2..5d49d4b4e 100644 --- a/Code/Module/Photos.php +++ b/Code/Module/Photos.php @@ -9,6 +9,7 @@ use Code\Lib\Libprofile; use Code\Lib\Channel; use Code\Lib\ServiceClass; use Code\Lib\PermissionDescription; +use Code\Lib\Time; use Code\Web\Controller; use Code\Access\AccessControl; use Code\Daemon\Run; @@ -252,7 +253,7 @@ class Photos extends Controller $width = $ph->getWidth(); $height = $ph->getHeight(); - $edited = datetime_convert(); + $edited = Time::convert(); q( "update attach set filesize = %d, edited = '%s' where hash = '%s' and uid = %d", @@ -437,7 +438,7 @@ class Photos extends Controller $obj['name'] = (($title) ? $title : $p[0]['filename']); $obj['summary'] = (($desc) ? $desc : $p[0]['filename']); - $obj['updated'] = datetime_convert('UTC', 'UTC', 'now', ISO8601); + $obj['updated'] = Time::convert('UTC', 'UTC', 'now', ISO8601); $obj['source'] = ['content' => $body, 'mediaType' => 'text/x-multicode']; $obj['content'] = bbcode($body . $footer_text, ['export' => true]); if (isset($obj['url']) && is_array($obj['url'])) { @@ -458,7 +459,7 @@ class Photos extends Controller dbesc(($title) ? $title : ''), dbesc($obj), dbesc($body . $footer_text), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($acl->is_private()), intval(1 - (int) $visibility), intval($item_id) @@ -1019,7 +1020,7 @@ class Photos extends Controller $photo = array( 'href' => z_root() . '/photo/' . $hires['resource_id'] . '-' . $hires['imgscale'] . '.' . $phototypes[$hires['mimetype']], 'title' => t('View Full Size'), - 'src' => z_root() . '/photo/' . $lores['resource_id'] . '-' . $lores['imgscale'] . '.' . $phototypes[$lores['mimetype']] . '?f=&_u=' . datetime_convert('', '', '', 'ymdhis') + 'src' => z_root() . '/photo/' . $lores['resource_id'] . '-' . $lores['imgscale'] . '.' . $phototypes[$lores['mimetype']] . '?f=&_u=' . Time::convert('', '', '', 'ymdhis') ); if ($nextlink) { diff --git a/Code/Module/Ping.php b/Code/Module/Ping.php index d7a1de51d..78d97b564 100644 --- a/Code/Module/Ping.php +++ b/Code/Module/Ping.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Enotify; use Code\Lib\Apps; @@ -112,7 +113,7 @@ class Ping extends Controller $basic_presence = true; q( "update chatpresence set cp_last = '%s' where cp_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['cp_id']) ); } @@ -121,7 +122,7 @@ class Ping extends Controller "insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client) values( '%s', '%s', '%s', '%s' ) ", dbesc(get_observer_hash()), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc('online'), dbesc($_SERVER['REMOTE_ADDR']) ); @@ -245,9 +246,9 @@ class Ping extends Controller "UPDATE item SET item_unseen = 0 WHERE uid = %d AND item_unseen = 1", intval(local_channel()) ); - $_SESSION['loadtime_stream'] = datetime_convert(); + $_SESSION['loadtime_stream'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_stream', $_SESSION['loadtime_stream']); - $_SESSION['loadtime_channel'] = datetime_convert(); + $_SESSION['loadtime_channel'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_channel', $_SESSION['loadtime_channel']); break; case 'home': @@ -255,15 +256,15 @@ class Ping extends Controller "UPDATE item SET item_unseen = 0 WHERE uid = %d AND item_unseen = 1 AND item_wall = 1", intval(local_channel()) ); - $_SESSION['loadtime_channel'] = datetime_convert(); + $_SESSION['loadtime_channel'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_channel', $_SESSION['loadtime_channel']); break; case 'all_events': $r = q( "UPDATE event SET dismissed = 1 WHERE uid = %d AND dismissed = 0 AND dtstart < '%s' AND dtstart > '%s' ", intval(local_channel()), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now - 1 days')) ); break; case 'notify': @@ -273,7 +274,7 @@ class Ping extends Controller ); break; case 'pubs': - $_SESSION['loadtime_pubstream'] = datetime_convert(); + $_SESSION['loadtime_pubstream'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_pubstream', $_SESSION['loadtime_pubstream']); break; default: @@ -518,15 +519,15 @@ class Ping extends Controller and etype in ( 'event', 'birthday' ) ORDER BY dtstart DESC LIMIT 1000", intval(local_channel()), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now - 1 days')) ); if ($r) { foreach ($r as $rr) { - $strt = datetime_convert('UTC', (($rr['adjust']) ? date_default_timezone_get() : 'UTC'), $rr['dtstart']); - $today = substr($strt, 0, 10) === datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d'); - $when = day_translate(datetime_convert('UTC', (($rr['adjust']) ? date_default_timezone_get() : 'UTC'), $rr['dtstart'], $bd_format)) . (($today) ? ' ' . t('[today]') : ''); + $strt = Time::convert('UTC', (($rr['adjust']) ? date_default_timezone_get() : 'UTC'), $rr['dtstart']); + $today = substr($strt, 0, 10) === Time::convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d'); + $when = day_translate(Time::convert('UTC', (($rr['adjust']) ? date_default_timezone_get() : 'UTC'), $rr['dtstart'], $bd_format)) . (($today) ? ' ' . t('[today]') : ''); $result[] = [ 'notify_link' => z_root() . '/events', /// @FIXME this takes you to an edit page and it may not be yours, we really want to just view the single event --> '/events/event/' . $rr['event_hash'], @@ -750,15 +751,15 @@ class Ping extends Controller and etype in ( 'event', 'birthday' ) ORDER BY dtstart ASC ", intval(local_channel()), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), - dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), + dbesc(Time::convert('UTC', date_default_timezone_get(), 'now - 1 days')) ); if ($events) { $result['all_events'] = count($events); if ($result['all_events']) { - $str_now = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d'); + $str_now = Time::convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d'); foreach ($events as $x) { $bd = false; if ($x['etype'] === 'birthday') { @@ -767,7 +768,7 @@ class Ping extends Controller } else { $result['events']++; } - if (datetime_convert('UTC', ((intval($x['adjust'])) ? date_default_timezone_get() : 'UTC'), $x['dtstart'], 'Y-m-d') === $str_now) { + if (Time::convert('UTC', ((intval($x['adjust'])) ? date_default_timezone_get() : 'UTC'), $x['dtstart'], 'Y-m-d') === $str_now) { $result['all_events_today']++; if ($bd) { $result['birthdays_today']++; @@ -855,9 +856,9 @@ class Ping extends Controller PConfig::Delete(local_channel(), 'system', 'seen_items'); } - $_SESSION['loadtime_channel'] = datetime_convert(); - $_SESSION['loadtime_stream'] = datetime_convert(); - $_SESSION['loadtime_pubstream'] = datetime_convert(); + $_SESSION['loadtime_channel'] = Time::convert(); + $_SESSION['loadtime_stream'] = Time::convert(); + $_SESSION['loadtime_pubstream'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_channel', $_SESSION['loadtime_channel']); PConfig::Set(local_channel(), 'system', 'loadtime_stream', $_SESSION['loadtime_stream']); diff --git a/Code/Module/Profile_photo.php b/Code/Module/Profile_photo.php index d917c95c1..f79bae9ac 100644 --- a/Code/Module/Profile_photo.php +++ b/Code/Module/Profile_photo.php @@ -9,6 +9,7 @@ namespace Code\Module; */ use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Libsync; use Code\Lib\Libprofile; @@ -206,7 +207,7 @@ class Profile_photo extends Controller "UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s' where xchan_hash = '%s'", dbesc($im->getType()), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(z_root() . '/photo/profile/l/' . $channel['channel_id']), dbesc(z_root() . '/photo/profile/m/' . $channel['channel_id']), dbesc(z_root() . '/photo/profile/s/' . $channel['channel_id']), @@ -417,7 +418,7 @@ class Profile_photo extends Controller $r = q( "UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($channel['xchan_hash']) ); diff --git a/Code/Module/Pubstream.php b/Code/Module/Pubstream.php index 03a99ec52..b09973ca4 100644 --- a/Code/Module/Pubstream.php +++ b/Code/Module/Pubstream.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\PermissionDescription; use Code\Lib\PConfig; @@ -97,7 +98,7 @@ class Pubstream extends Controller Navbar::set_selected(t('Public Stream')); if (!$mid) { - $_SESSION['loadtime_pubstream'] = datetime_convert(); + $_SESSION['loadtime_pubstream'] = Time::convert(); if (local_channel()) { PConfig::Set(local_channel(), 'system', 'loadtime_pubstream', $_SESSION['loadtime_pubstream']); } @@ -194,7 +195,7 @@ class Pubstream extends Controller $abook_uids = " and abook.abook_channel = " . intval(App::$profile['profile_uid']) . " "; } - $simple_update = ((isset($_SESSION['loadtime_pubstream']) && $_SESSION['loadtime_pubstream']) ? " AND item.changed > '" . datetime_convert('UTC', 'UTC', $_SESSION['loadtime_pubstream']) . "' " : ''); + $simple_update = ((isset($_SESSION['loadtime_pubstream']) && $_SESSION['loadtime_pubstream']) ? " AND item.changed > '" . Time::convert('UTC', 'UTC', $_SESSION['loadtime_pubstream']) . "' " : ''); if ($this->loading) { $simple_update = ''; diff --git a/Code/Module/Removeaccount.php b/Code/Module/Removeaccount.php index 2a76d96ca..fd20874e2 100644 --- a/Code/Module/Removeaccount.php +++ b/Code/Module/Removeaccount.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Account; use Code\Render\Theme; @@ -47,7 +48,7 @@ class Removeaccount extends Controller } if ($account['account_password_changed'] > NULL_DATE) { - $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours'); + $d1 = Time::convert('UTC', 'UTC', 'now - 48 hours'); if ($account['account_password_changed'] > $d1) { notice(t('Account removals are not allowed within 48 hours of changing the account password.') . EOL); return; diff --git a/Code/Module/Removeme.php b/Code/Module/Removeme.php index 8cf6f8dfb..17da86b68 100644 --- a/Code/Module/Removeme.php +++ b/Code/Module/Removeme.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Channel; use Code\Render\Theme; @@ -46,7 +47,7 @@ class Removeme extends Controller } if ($account['account_password_changed'] > NULL_DATE) { - $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours'); + $d1 = Time::convert('UTC', 'UTC', 'now - 48 hours'); if ($account['account_password_changed'] > $d1) { notice(t('Channel removals are not allowed within 48 hours of changing the account password.') . EOL); return; diff --git a/Code/Module/Search.php b/Code/Module/Search.php index faa955042..94488a304 100644 --- a/Code/Module/Search.php +++ b/Code/Module/Search.php @@ -13,6 +13,7 @@ use Code\Lib\Libprofile; use Code\Lib\Libzot; use Code\Lib\Navbar; use Code\Lib\Queue; +use Code\Lib\Time; use Code\Render\Theme; use Code\Web\Controller; use Code\Web\HTTPSig; @@ -108,7 +109,7 @@ class Search extends Controller } if ($this->loading) { - $_SESSION['loadtime'] = datetime_convert(); + $_SESSION['loadtime'] = Time::convert(); } Navbar::set_selected('Search'); diff --git a/Code/Module/Settings/Account.php b/Code/Module/Settings/Account.php index 7e63dbb34..eb1598daa 100644 --- a/Code/Module/Settings/Account.php +++ b/Code/Module/Settings/Account.php @@ -4,6 +4,7 @@ namespace Code\Module\Settings; use App; use Code\Extend\Hook; +use Code\Lib\Time; use Code\Render\Theme; class Account @@ -76,7 +77,7 @@ class Account where account_id = %d", dbesc($salt), dbesc($password_encoded), - dbesc(datetime_convert()), + dbesc(Time::convert()), intval(get_account_id()) ); if ($r) { diff --git a/Code/Module/Settings/Channel.php b/Code/Module/Settings/Channel.php index 91fd0a7f9..2475f6c40 100644 --- a/Code/Module/Settings/Channel.php +++ b/Code/Module/Settings/Channel.php @@ -19,6 +19,7 @@ use Code\Lib\Libacl; use Code\Lib\Features; use Code\Lib\Menu; use Code\Extend\Hook; +use Code\Lib\Time; use Code\Render\Theme; @@ -218,7 +219,7 @@ class Channel $r = q( "update xchan set xchan_name = '%s', xchan_name_date = '%s' where xchan_url = '%s'", dbesc($channel_name), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(z_root() . '/channel/' . $channel['channel_address']) ); $r = q( diff --git a/Code/Module/Settings/Profile_edit.php b/Code/Module/Settings/Profile_edit.php index a86ee48e7..03b2435c9 100644 --- a/Code/Module/Settings/Profile_edit.php +++ b/Code/Module/Settings/Profile_edit.php @@ -10,6 +10,7 @@ use Code\Lib\Navbar; use Code\Lib\Features; use Code\Daemon\Run; use Code\Extend\Hook; +use Code\Lib\Time; use Sabre\VObject\Reader; use Code\Render\Theme; @@ -133,7 +134,7 @@ class Profile_edit $ignore_year = true; $dob = substr($dob, 5); } - $dob = datetime_convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d')); + $dob = Time::convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d')); if ($ignore_year) { $dob = '0000-' . $dob; } @@ -243,7 +244,7 @@ class Profile_edit if (!strlen($howlong)) { $howlong = NULL_DATE; } else { - $howlong = datetime_convert(date_default_timezone_get(), 'UTC', $howlong); + $howlong = Time::convert(date_default_timezone_get(), 'UTC', $howlong); } // linkify the relationship target if applicable @@ -493,7 +494,7 @@ class Profile_edit $r = q( "UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_hash = '%s'", dbesc($name), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($channel['xchan_hash']) ); $r = q( @@ -626,7 +627,7 @@ class Profile_edit '$marital' => self::marital_selector($r[0]['marital']), '$marital_min' => self::marital_selector_min($r[0]['marital']), '$with' => ['with', t("Who (if applicable)"), $r[0]['partner'], t('Examples: cathy123, Cathy Williams, cathy@example.com')], - '$howlong' => ['howlong', t('Since (date)'), ($r[0]['howlong'] <= NULL_DATE ? '' : datetime_convert('UTC', date_default_timezone_get(), $r[0]['howlong']))], + '$howlong' => ['howlong', t('Since (date)'), ($r[0]['howlong'] <= NULL_DATE ? '' : Time::convert('UTC', date_default_timezone_get(), $r[0]['howlong']))], '$sexual' => self::sexpref_selector($r[0]['sexual']), '$sexual_min' => self::sexpref_selector_min($r[0]['sexual']), '$pronouns' => self::pronouns_selector($r[0]['pronouns']), diff --git a/Code/Module/Settings/Tokens.php b/Code/Module/Settings/Tokens.php index d76088300..d7ad23e96 100644 --- a/Code/Module/Settings/Tokens.php +++ b/Code/Module/Settings/Tokens.php @@ -8,6 +8,7 @@ use Code\Access\PermissionLimits; use Code\Lib\ServiceClass; use Code\Lib\AccessList; use Code\Lib\Libsync; +use Code\Lib\Time; use Code\Render\Theme; @@ -34,7 +35,7 @@ class Tokens $token_errs++; } if (trim($_POST['expires'])) { - $expires = datetime_convert(date_default_timezone_get(), 'UTC', $_POST['expires']); + $expires = Time::convert(date_default_timezone_get(), 'UTC', $_POST['expires']); } else { $expires = NULL_DATE; } @@ -137,8 +138,8 @@ class Tokens 'abook_xchan' => $atoken_xchan, 'abook_profile' => $profile_assign, 'abook_feed' => 0, - 'abook_created' => datetime_convert(), - 'abook_updated' => datetime_convert(), + 'abook_created' => Time::convert(), + 'abook_updated' => Time::convert(), 'abook_instance' => z_root() ] ); @@ -303,7 +304,7 @@ class Tokens '$url2' => z_root() . '/photos/' . $channel['channel_address'], '$name' => array('name', t('Login Name') . ' *', (($atoken) ? $atoken['atoken_name'] : ''), ''), '$token' => array('token', t('Login Password') . ' *', (($atoken) ? $atoken['atoken_token'] : new_token()), ''), - '$expires' => array('expires', t('Expires (yyyy-mm-dd)'), (($atoken['atoken_expires'] && $atoken['atoken_expires'] > NULL_DATE) ? datetime_convert('UTC', date_default_timezone_get(), $atoken['atoken_expires']) : ''), ''), + '$expires' => array('expires', t('Expires (yyyy-mm-dd)'), (($atoken['atoken_expires'] && $atoken['atoken_expires'] > NULL_DATE) ? Time::convert('UTC', date_default_timezone_get(), $atoken['atoken_expires']) : ''), ''), '$them' => t('Their Settings'), '$me' => t('My Settings'), '$perms' => $perms, diff --git a/Code/Module/Stream.php b/Code/Module/Stream.php index ca341ecb8..671ddfb5e 100644 --- a/Code/Module/Stream.php +++ b/Code/Module/Stream.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\AccessList; use Code\Lib\Apps; @@ -49,10 +50,10 @@ class Stream extends Controller $o = ''; if ($this->loading && intval(App::$pager['page']) <= 1) { - $_SESSION['loadtime_stream'] = datetime_convert(); + $_SESSION['loadtime_stream'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_stream', $_SESSION['loadtime_stream']); // stream is a superset of channel when it comes to notifications - $_SESSION['loadtime_channel'] = datetime_convert(); + $_SESSION['loadtime_channel'] = Time::convert(); PConfig::Set(local_channel(), 'system', 'loadtime_channel', $_SESSION['loadtime_channel']); } @@ -431,10 +432,10 @@ class Stream extends Controller $sql_extra3 = ''; if ($datequery) { - $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery)))); + $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(Time::convert(date_default_timezone_get(), '', $datequery)))); } if ($datequery2) { - $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(), '', $datequery2)))); + $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(Time::convert(date_default_timezone_get(), '', $datequery2)))); } $sql_extra3 = (($nouveau) ? '' : $sql_extra3); diff --git a/Code/Module/Tasks.php b/Code/Module/Tasks.php index 3650f039c..9907c9e27 100644 --- a/Code/Module/Tasks.php +++ b/Code/Module/Tasks.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Libsync; use Code\Lib\Apps; @@ -61,13 +62,13 @@ class Tasks extends Controller $event['event_status_date'] = NULL_DATE; $event['event_percent'] = 0; $event['event_sequence'] = $event['event_sequence'] + 1; - $event['edited'] = datetime_convert(); + $event['edited'] = Time::convert(); } else { $event['event_status'] = 'COMPLETED'; - $event['event_status_date'] = datetime_convert(); + $event['event_status_date'] = Time::convert(); $event['event_percent'] = 100; $event['event_sequence'] = $event['event_sequence'] + 1; - $event['edited'] = datetime_convert(); + $event['edited'] = Time::convert(); } $x = event_store_event($event); if ($x) { @@ -89,7 +90,7 @@ class Tasks extends Controller $event['event_xchan'] = $channel['channel_hash']; $event['etype'] = 'task'; $event['nofinish'] = true; - $event['created'] = $event['edited'] = $event['dtstart'] = datetime_convert(); + $event['created'] = $event['edited'] = $event['dtstart'] = Time::convert(); $event['adjust'] = 1; $event['allow_cid'] = '<' . $channel['channel_hash'] . '>'; $event['summary'] = escape_tags($_REQUEST['summary']); diff --git a/Code/Module/Thing.php b/Code/Module/Thing.php index 7f00a06f7..d1fc6b4cc 100644 --- a/Code/Module/Thing.php +++ b/Code/Module/Thing.php @@ -4,6 +4,7 @@ namespace Code\Module; use App; use Code\Access\AccessControl; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Libprofile; use Code\Lib\Libsync; @@ -129,7 +130,7 @@ class Thing extends Controller dbesc($name), dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash), dbesc($local_photo), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($x['allow_cid']), dbesc($x['allow_gid']), dbesc($x['deny_cid']), @@ -177,7 +178,7 @@ class Thing extends Controller } - $created = datetime_convert(); + $created = Time::convert(); $url = (($url) ? $url : z_root() . '/thing/' . $hash); $r = q( diff --git a/Code/Module/Uexport.php b/Code/Module/Uexport.php index 39da4ec75..83e31c65d 100644 --- a/Code/Module/Uexport.php +++ b/Code/Module/Uexport.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Channel; use Code\Render\Theme; @@ -58,7 +59,7 @@ class Uexport extends Controller public function get() { - $y = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y'); + $y = Time::convert('UTC', date_default_timezone_get(), 'now', 'Y'); $yearurl = z_root() . '/uexport/' . $y; $janurl = z_root() . '/uexport/' . $y . '/1'; diff --git a/Code/Module/Webpages.php b/Code/Module/Webpages.php index 0b6766830..891747d39 100644 --- a/Code/Module/Webpages.php +++ b/Code/Module/Webpages.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Time; use Code\Web\Controller; use Code\Lib\Apps; use Code\Lib\Channel; @@ -250,8 +251,8 @@ class Webpages extends Controller 'pageurl' => str_replace('%2f', '/', $rr['v']), 'pagetitle' => urldecode($rr['v']), 'title' => $rr['title'], - 'created' => datetime_convert('UTC', date_default_timezone_get(), $rr['created']), - 'edited' => datetime_convert('UTC', date_default_timezone_get(), $rr['edited']), + 'created' => Time::convert('UTC', date_default_timezone_get(), $rr['created']), + 'edited' => Time::convert('UTC', date_default_timezone_get(), $rr['edited']), 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', 'lockstate' => $lockstate ); diff --git a/Code/Photo/PhotoDriver.php b/Code/Photo/PhotoDriver.php index c53973c6d..3fb362402 100644 --- a/Code/Photo/PhotoDriver.php +++ b/Code/Photo/PhotoDriver.php @@ -3,6 +3,7 @@ namespace Code\Photo; use App; +use Code\Lib\Time; use Imagick; use Code\Lib\Channel; @@ -454,7 +455,7 @@ abstract class PhotoDriver $p['allow_gid'] = (($arr['allow_gid']) ? $arr['allow_gid'] : ''); $p['deny_cid'] = (($arr['deny_cid']) ? $arr['deny_cid'] : ''); $p['deny_gid'] = (($arr['deny_gid']) ? $arr['deny_gid'] : ''); - $p['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert()); + $p['edited'] = (($arr['edited']) ? $arr['edited'] : Time::convert()); $p['title'] = (($arr['title']) ? $arr['title'] : ''); $p['description'] = (($arr['description']) ? $arr['description'] : ''); $p['photo_usage'] = intval($arr['photo_usage']); diff --git a/Code/Storage/Browser.php b/Code/Storage/Browser.php index 2f4e70b24..eefea9c21 100644 --- a/Code/Storage/Browser.php +++ b/Code/Storage/Browser.php @@ -3,6 +3,7 @@ namespace Code\Storage; use App; +use Code\Lib\Time; use Sabre\DAV; use Sabre\DAV\INode; use Code\Lib\PermissionDescription; @@ -274,7 +275,7 @@ class Browser extends DAV\Browser\Plugin { $ft['type'] = $type; $ft['size'] = $size; $ft['sizeFormatted'] = userReadableSize($size); - $ft['lastmodified'] = (($lastmodified) ? datetime_convert('UTC', date_default_timezone_get(), $lastmodified) : ''); + $ft['lastmodified'] = (($lastmodified) ? Time::convert('UTC', date_default_timezone_get(), $lastmodified) : ''); $ft['iconFromType'] = getIconFromType($type); $f[] = $ft; diff --git a/Code/Storage/Directory.php b/Code/Storage/Directory.php index 0761acd25..b8f156a90 100644 --- a/Code/Storage/Directory.php +++ b/Code/Storage/Directory.php @@ -3,6 +3,7 @@ namespace Code\Storage; use App; +use Code\Lib\Time; use Sabre\DAV; use Code\Lib\Libsync; use Code\Daemon\Run; @@ -255,7 +256,7 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo $deny_gid = $channel['channel_deny_gid']; } - $created = $edited = datetime_convert(); + $created = $edited = Time::convert(); $r = q("INSERT INTO attach ( aid, uid, hash, creator, filename, folder, os_storage, filetype, filesize, revision, is_photo, content, created, edited, os_path, display_path, allow_cid, allow_gid, deny_cid, deny_gid ) VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ", @@ -600,7 +601,7 @@ class Directory extends DAV\Node implements DAV\ICollection, DAV\IQuota, DAV\IMo if (!$r) return ''; } - return datetime_convert('UTC', 'UTC', $r[0]['edited'], 'U'); + return Time::convert('UTC', 'UTC', $r[0]['edited'], 'U'); } diff --git a/Code/Storage/File.php b/Code/Storage/File.php index 1e58ff3f8..01b2356bd 100644 --- a/Code/Storage/File.php +++ b/Code/Storage/File.php @@ -3,6 +3,7 @@ namespace Code\Storage; use App; +use Code\Lib\Time; use Sabre\DAV; use Code\Lib\Libsync; use Code\Daemon\Run; @@ -245,7 +246,7 @@ class File extends DAV\Node implements DAV\IFile { } // returns now() - $edited = datetime_convert(); + $edited = Time::convert(); $d = q("UPDATE attach SET filesize = '%s', is_photo = %d, edited = '%s' WHERE hash = '%s' AND uid = %d", dbesc($size), @@ -397,7 +398,7 @@ class File extends DAV\Node implements DAV\IFile { */ public function getLastModified() { - return datetime_convert('UTC', 'UTC', $this->data['edited'], 'U'); + return Time::convert('UTC', 'UTC', $this->data['edited'], 'U'); } /** diff --git a/Code/Update/_1252.php b/Code/Update/_1252.php index e03de8baf..95441d6eb 100644 --- a/Code/Update/_1252.php +++ b/Code/Update/_1252.php @@ -3,7 +3,8 @@ namespace Code\Update; use Code\Lib\Channel; - +use Code\Lib\Time; + class _1252 { @@ -28,7 +29,7 @@ class _1252 q( "update xchan set xchan_name = '%s', xchan_name_date = '%s' where xchan_hash = '%s'", dbesc($sitename), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($sys['channel_hash']) ); } diff --git a/Code/Web/HTTPSig.php b/Code/Web/HTTPSig.php index 62b7fb0c2..2aac24fc6 100644 --- a/Code/Web/HTTPSig.php +++ b/Code/Web/HTTPSig.php @@ -2,6 +2,7 @@ namespace Code\Web; +use Code\Lib\Time; use DateTime; use DateTimeZone; use Code\Lib\ActivityStreams; @@ -156,8 +157,8 @@ class HTTPSig if ($h === 'date') { $d = new DateTime($headers[$h]); $d->setTimezone(new DateTimeZone('UTC')); - $dplus = datetime_convert('UTC', 'UTC', 'now + 1 day'); - $dminus = datetime_convert('UTC', 'UTC', 'now - 1 day'); + $dplus = Time::convert('UTC', 'UTC', 'now + 1 day'); + $dminus = Time::convert('UTC', 'UTC', 'now - 1 day'); $c = $d->format('Y-m-d H:i:s'); if ($c > $dplus || $c < $dminus) { logger('bad time: ' . $c); diff --git a/Code/Widget/Archive.php b/Code/Widget/Archive.php index c0986ef94..9e97a7489 100644 --- a/Code/Widget/Archive.php +++ b/Code/Widget/Archive.php @@ -4,6 +4,7 @@ namespace Code\Widget; use App; use Code\Lib\Features; +use Code\Lib\Time; use Code\Render\Theme; @@ -42,7 +43,7 @@ class Archive implements WidgetInterface return ''; } - $cutoff_year = intval(datetime_convert('', date_default_timezone_get(), 'now', 'Y')) - $visible_years; + $cutoff_year = intval(Time::convert('', date_default_timezone_get(), 'now', 'Y')) - $visible_years; $cutoff = array_key_exists($cutoff_year, $ret); return replace_macros(Theme::get_template('posted_date_widget.tpl'), [ diff --git a/boot.php b/boot.php index 7e173e489..5337abbb2 100755 --- a/boot.php +++ b/boot.php @@ -1,6 +1,7 @@ datetime_convert(datetime: 'now - 3 days')) { + if($t > Time::convert(datetime: 'now - 3 days')) { // Wait for 3 days before we do anything so as not to swamp the admin with messages return true; } - set_config('system', 'lastcroncheck', datetime_convert()); + set_config('system', 'lastcroncheck', Time::convert()); - if(($d) && ($d > datetime_convert(datetime: 'now - 3 days'))) { + if(($d) && ($d > Time::convert(datetime: 'now - 3 days'))) { // Scheduled tasks have run successfully in the last 3 days. return true; } @@ -1963,6 +1964,6 @@ function get_loadtime($module) { return ($x); } } - return datetime_convert(); + return Time::convert(); } diff --git a/include/api.php b/include/api.php index e0d8de752..20ad9d9d9 100644 --- a/include/api.php +++ b/include/api.php @@ -2,6 +2,7 @@ use Code\Lib\Api_router; use Code\Extend\Hook; +use Code\Lib\Time; require_once("include/conversation.php"); require_once("include/html2plain.php"); @@ -57,7 +58,7 @@ function api_user() function api_date($str) { // Wed May 23 06:01:13 +0000 2007 - return datetime_convert('UTC', 'UTC', $str, 'D M d H:i:s +0000 Y'); + return Time::convert('UTC', 'UTC', $str, 'D M d H:i:s +0000 Y'); } diff --git a/include/api_zot.php b/include/api_zot.php index 75dde5ec6..e80e3d7eb 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -1,6 +1,7 @@ $mindate ])); @@ -207,8 +208,8 @@ function api_attach_list($type) $start = ((array_key_exists('start', $_REQUEST)) ? intval($_REQUEST['start']) : 0); $records = ((array_key_exists('records', $_REQUEST)) ? intval($_REQUEST['records']) : 0); - $since = ((array_key_exists('since', $_REQUEST)) ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['since']) : NULL_DATE); - $until = ((array_key_exists('until', $_REQUEST)) ? datetime_convert(date_default_timezone_get(), 'UTC', $_REQUEST['until']) : datetime_convert()); + $since = ((array_key_exists('since', $_REQUEST)) ? Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['since']) : NULL_DATE); + $until = ((array_key_exists('until', $_REQUEST)) ? Time::convert(date_default_timezone_get(), 'UTC', $_REQUEST['until']) : Time::convert()); $x = attach_list_files(api_user(), get_observer_hash(), $hash, $filename, $filetype, 'created asc', $start, $records, $since, $until); diff --git a/include/attach.php b/include/attach.php index b4e4a7694..d048dd37a 100644 --- a/include/attach.php +++ b/include/attach.php @@ -14,6 +14,7 @@ use Code\Daemon\Run; use Code\Lib\Channel; use Code\Lib\ServiceClass; use Code\Extend\Hook; +use Code\Lib\Time; use Code\Render\Theme; use Code\Storage\Stdio; @@ -231,7 +232,7 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $ $since = NULL_DATE; } if (! $until) { - $until = datetime_convert(); + $until = Time::convert(); } $sql_extra .= " and created >= '" . dbesc($since) . "' and created <= '" . dbesc($until) . "' "; @@ -754,7 +755,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) $overwrite = $import_replace || get_pconfig($channel_id, 'system', 'overwrite_dup_files'); if (($overwrite) || ($options === 'import')) { if (! array_key_exists('edited', $arr)) { - $arr['edited'] = datetime_convert(); + $arr['edited'] = Time::convert(); } $options = 'replace'; $existing_id = $existing[0]['id']; @@ -874,7 +875,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) if (array_key_exists('created', $arr)) { $created = $arr['created']; } else { - $created = datetime_convert(); + $created = Time::convert(); } if (array_key_exists('edited', $arr)) { @@ -1520,7 +1521,7 @@ function attach_mkdir($channel, $observer_hash, $arr = null) $path = ''; } - $created = datetime_convert(); + $created = Time::convert(); $os_path = ltrim($path . '/' . $arr['hash'], '/'); $display_path = ltrim($dpath . '/' . $arr['filename'], '/'); @@ -1862,7 +1863,7 @@ function attach_delete($channel_id, $resource, $is_photo = 0) // update the parent folder's lastmodified timestamp $e = q( "UPDATE attach SET edited = '%s' WHERE hash = '%s' AND uid = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($r[0]['folder']), intval($channel_id) ); @@ -2463,9 +2464,9 @@ function filepath_macro($s) { return str_replace( [ '%Y', '%m', '%d' ], - [ datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y'), - datetime_convert('UTC', date_default_timezone_get(), 'now', 'm'), - datetime_convert('UTC', date_default_timezone_get(), 'now', 'd') + [ Time::convert('UTC', date_default_timezone_get(), 'now', 'Y'), + Time::convert('UTC', date_default_timezone_get(), 'now', 'm'), + Time::convert('UTC', date_default_timezone_get(), 'now', 'd') ], $s ); diff --git a/include/auth.php b/include/auth.php index 1902d995e..01cf951dc 100644 --- a/include/auth.php +++ b/include/auth.php @@ -15,6 +15,7 @@ use Code\Lib\AConfig; use Code\Lib\Channel; use Code\Lib\Libzot; use Code\Extend\Hook; +use Code\Lib\Time; require_once('include/api_auth.php'); require_once('include/security.php'); @@ -185,7 +186,7 @@ function log_failed_login($errormsg) { $authlog = get_config('system', 'authlog'); if ($authlog) { - @file_put_contents($authlog, datetime_convert() . ':' . session_id() . ' ' . $errormsg . PHP_EOL, FILE_APPEND); + @file_put_contents($authlog, Time::convert() . ':' . session_id() . ' ' . $errormsg . PHP_EOL, FILE_APPEND); } } @@ -231,7 +232,7 @@ if ( ); if ($x) { App::$session->new_cookie(60 * 60 * 24); // one day - $_SESSION['last_login_date'] = datetime_convert(); + $_SESSION['last_login_date'] = Time::convert(); unset($_SESSION['visitor_id']); // no longer a visitor authenticate_success($x[0], false, true, true); } @@ -268,10 +269,10 @@ if ( App::$account = $r; $login_refresh = false; if (! x($_SESSION, 'last_login_date')) { - $_SESSION['last_login_date'] = datetime_convert('UTC', 'UTC'); + $_SESSION['last_login_date'] = Time::convert('UTC', 'UTC'); } - if (strcmp(datetime_convert('UTC', 'UTC', 'now - 12 hours'), $_SESSION['last_login_date']) > 0) { - $_SESSION['last_login_date'] = datetime_convert(); + if (strcmp(Time::convert('UTC', 'UTC', 'now - 12 hours'), $_SESSION['last_login_date']) > 0) { + $_SESSION['last_login_date'] = Time::convert(); App::$session->extend_cookie(); $login_refresh = true; } @@ -332,7 +333,7 @@ if ( // Also log failed logins to a separate auth log to reduce overhead for server side intrusion prevention $authlog = get_config('system', 'authlog'); if ($authlog) { - @file_put_contents($authlog, datetime_convert() . ':' . session_id() . ' ' . $error . "\n", FILE_APPEND); + @file_put_contents($authlog, Time::convert() . ':' . session_id() . ' ' . $error . "\n", FILE_APPEND); } notice(t('Login failed.') . EOL); goaway(z_root() . '/login'); @@ -361,7 +362,7 @@ if ( // if we haven't failed up this point, log them in. - $_SESSION['last_login_date'] = datetime_convert(); + $_SESSION['last_login_date'] = Time::convert(); if (! $atoken) { authenticate_success($account, $channel, true, true); } diff --git a/include/bbcode.php b/include/bbcode.php index af368ac98..eb11e3fa7 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -6,6 +6,7 @@ use Code\Lib\Oembed; use Code\Lib\SvgSanitizer; use Code\Extend\Hook; use chillerlan\QRCode\QRCode; +use Code\Lib\Time; /** @@ -661,7 +662,7 @@ function bb_ShareAttributes($match) } - $reldate = '' . datetime_convert('UTC', date_default_timezone_get(), $posted, 'r') . ''; + $reldate = '' . Time::convert('UTC', date_default_timezone_get(), $posted, 'r') . ''; // I was going to wrap this in
to make it semantically correct HTML and permit cross-platform styling, but doing so results in text/plain // projects stripping out the content completely. Hence that effort was reverted. diff --git a/include/connections.php b/include/connections.php index 90f0d7535..b74d5d194 100644 --- a/include/connections.php +++ b/include/connections.php @@ -2,6 +2,7 @@ /** @file */ +use Code\Lib\Time; use Sabre\VObject\Component\VCard; use Sabre\VObject\Reader; use Code\Daemon\Run; @@ -254,8 +255,8 @@ function abook_toggle_flag($abook, $flag) $r = q( "update abook set abook_connected = '%s', abook_updated = '%s' where abook_id = %d and abook_channel = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), intval($abook['abook_id']), intval($abook['abook_channel']) ); diff --git a/include/conversation.php b/include/conversation.php index c914bf7fa..d63c0b356 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -12,6 +12,7 @@ use Code\Lib\Features; use Code\Extend\Hook; use Code\Access\Permissions; use Code\Access\PermissionLimits; +use Code\Lib\Time; use Code\Lib\XConfig; use Code\Render\Theme; @@ -535,7 +536,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa $has_tags = $body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']; - if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) { + if (strcmp(Time::convert('UTC', 'UTC', $item['created']), Time::convert('UTC', 'UTC', 'now - 12 hours')) > 0) { $is_new = true; } @@ -594,10 +595,10 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa 'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf(t('from %s'), $item['app']), - 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), - 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), - 'editedtime' => (($item['edited'] != $item['created']) ? sprintf(t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), - 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf(t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : ''), + 'isotime' => Time::convert('UTC', date_default_timezone_get(), $item['created'], 'c'), + 'localtime' => Time::convert('UTC', date_default_timezone_get(), $item['created'], 'r'), + 'editedtime' => (($item['edited'] != $item['created']) ? sprintf(t('last edited: %s'), Time::convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), + 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf(t('Expires: %s'), Time::convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : ''), 'location' => $location, 'divider' => false, 'indent' => '', @@ -1169,11 +1170,11 @@ function z_status_editor($x, $popup = false) $defexpire = ((($z = get_pconfig($x['profile_uid'], 'system', 'default_post_expire')) && (! $webpage)) ? $z : ''); if ($defexpire) { - $defexpire = datetime_convert('UTC', date_default_timezone_get(), $defexpire, 'Y-m-d H:i'); + $defexpire = Time::convert('UTC', date_default_timezone_get(), $defexpire, 'Y-m-d H:i'); } else { $defexpire = ((($z = intval(get_pconfig($x['profile_uid'], 'system', 'selfexpiredays'))) && (! $webpage)) ? $z : ''); if ($defexpire) { - $defexpire = datetime_convert('UTC', date_default_timezone_get(), "now + $defexpire days", 'Y-m-d H:i'); + $defexpire = Time::convert('UTC', date_default_timezone_get(), "now + $defexpire days", 'Y-m-d H:i'); } } @@ -1185,11 +1186,11 @@ function z_status_editor($x, $popup = false) $closecommdays = EMPTY_STR; } - $defcommuntil = (($closecommdays) ? datetime_convert('UTC', date_default_timezone_get(), 'now + ' . $closecommdays . ' days') : EMPTY_STR); + $defcommuntil = (($closecommdays) ? Time::convert('UTC', date_default_timezone_get(), 'now + ' . $closecommdays . ' days') : EMPTY_STR); $defpublish = ((($z = get_pconfig($x['profile_uid'], 'system', 'default_post_publish')) && (! $webpage)) ? $z : ''); if ($defpublish) { - $defpublish = datetime_convert('UTC', date_default_timezone_get(), $defpublish, 'Y-m-d H:i'); + $defpublish = Time::convert('UTC', date_default_timezone_get(), $defpublish, 'Y-m-d H:i'); } $cipher = get_pconfig($x['profile_uid'], 'system', 'default_cipher'); @@ -1839,7 +1840,7 @@ function prepare_page($item) return replace_macros(Theme::get_template($tpl), [ '$author' => (($naked) ? '' : $item['author']['xchan_name']), '$auth_url' => (($naked) ? '' : zid($item['author']['xchan_url'])), - '$date' => (($naked) ? '' : datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'Y-m-d H:i')), + '$date' => (($naked) ? '' : Time::convert('UTC', date_default_timezone_get(), $item['created'], 'Y-m-d H:i')), '$title' => zidify_links(smilies(bbcode($item['title']))), '$body' => $body['html'], '$preview' => $preview, diff --git a/include/datetime.php b/include/datetime.php index b1b461b47..4bbf692f2 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -2,6 +2,7 @@ use Code\Lib\Features; +use Code\Lib\Time; use Code\Render\Theme; @@ -157,7 +158,7 @@ function dob($dob) if ($dob === '0000-00-00' || $dob === '') { $value = ''; } else { - $value = (($ignore_year) ? datetime_convert('UTC', 'UTC', $dob, 'm-d') : datetime_convert('UTC', 'UTC', $dob, 'Y-m-d')); + $value = (($ignore_year) ? Time::convert('UTC', 'UTC', $dob, 'm-d') : Time::convert('UTC', 'UTC', $dob, 'Y-m-d')); } $age = age($value, App::$user['timezone'], App::$user['timezone']); @@ -270,7 +271,7 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke function relative_date($posted_date, $format = null) { - $localtime = datetime_convert('UTC', date_default_timezone_get(), $posted_date); + $localtime = Time::convert('UTC', date_default_timezone_get(), $posted_date); $abs = strtotime($localtime); @@ -359,11 +360,11 @@ function age($dob, $owner_tz = '', $viewer_tz = '') $viewer_tz = date_default_timezone_get(); } - $birthdate = datetime_convert('UTC', $owner_tz, $dob . ' 00:00:00+00:00', 'Y-m-d'); + $birthdate = Time::convert('UTC', $owner_tz, $dob . ' 00:00:00+00:00', 'Y-m-d'); list($year,$month,$day) = explode("-", $birthdate); - $year_diff = datetime_convert('UTC', $viewer_tz, 'now', 'Y') - $year; - $curr_month = datetime_convert('UTC', $viewer_tz, 'now', 'm'); - $curr_day = datetime_convert('UTC', $viewer_tz, 'now', 'd'); + $year_diff = Time::convert('UTC', $viewer_tz, 'now', 'Y') - $year; + $curr_month = Time::convert('UTC', $viewer_tz, 'now', 'm'); + $curr_day = Time::convert('UTC', $viewer_tz, 'now', 'd'); if (($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day))) { $year_diff--; @@ -410,7 +411,7 @@ function get_first_dim($y, $m) { $d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m)); - return datetime_convert('UTC', 'UTC', $d, 'w'); + return Time::convert('UTC', 'UTC', $d, 'w'); } /** @@ -436,8 +437,8 @@ function cal($y = 0, $m = 0, $links = false, $class = '') $mtab = [ ' ', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; - $thisyear = datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y'); - $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm'); + $thisyear = Time::convert('UTC', date_default_timezone_get(), 'now', 'Y'); + $thismonth = Time::convert('UTC', date_default_timezone_get(), 'now', 'm'); if (! $y) { $y = $thisyear; } @@ -453,7 +454,7 @@ function cal($y = 0, $m = 0, $links = false, $class = '') $started = false; if (($y == $thisyear) && ($m == $thismonth)) { - $tddate = intval(datetime_convert('UTC', date_default_timezone_get(), 'now', 'j')); + $tddate = intval(Time::convert('UTC', date_default_timezone_get(), 'now', 'j')); } $str_month = day_translate($mtab[$m]); @@ -526,15 +527,15 @@ function z_birthday($dob, $tz, $format = "Y-m-d H:i:s") $tmp_dob = substr($dob, 5); $tmp_d = substr($dob, 8); if (intval($tmp_dob) && intval($tmp_d)) { - $y = datetime_convert($tz, $tz, 'now', 'Y'); + $y = Time::convert($tz, $tz, 'now', 'Y'); $bd = $y . '-' . $tmp_dob . ' 00:00'; $t_dob = strtotime($bd); - $now = strtotime(datetime_convert($tz, $tz, 'now')); + $now = strtotime(Time::convert($tz, $tz, 'now')); if ($t_dob < $now) { $bd = sprintf("%d-%s 00:00", intval($y) + 1, $tmp_dob); } - $birthday = datetime_convert($tz, 'UTC', $bd, $format); + $birthday = Time::convert($tz, 'UTC', $bd, $format); } return $birthday; @@ -569,8 +570,8 @@ function update_birthdays() 'uid' => $rr['abook_channel'], 'account' => $rr['abook_account'], 'event_xchan' => $rr['xchan_hash'], - 'dtstart' => datetime_convert('UTC', 'UTC', $rr['abook_dob']), - 'dtend' => datetime_convert('UTC', 'UTC', $rr['abook_dob'] . ' + 1 day '), + 'dtstart' => Time::convert('UTC', 'UTC', $rr['abook_dob']), + 'dtend' => Time::convert('UTC', 'UTC', $rr['abook_dob'] . ' + 1 day '), 'adjust' => intval(Features::enabled($rr['abook_channel'], 'smart_birthdays')), 'summary' => sprintf(t('%1$s\'s birthday'), $rr['xchan_name']), 'description' => sprintf(t('Happy Birthday %1$s'), '[zrl=' . $rr['xchan_url'] . ']' . $rr['xchan_name'] . '[/zrl]'), diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php index 69c873f5d..cc2503020 100755 --- a/include/dba/dba_pdo.php +++ b/include/dba/dba_pdo.php @@ -1,5 +1,7 @@ getMessage() . "\n", FILE_APPEND); + file_put_contents('dbfail.out', Time::convert() . "\nConnect: " . $e->getMessage() . "\n", FILE_APPEND); } return false; @@ -98,7 +100,7 @@ class dba_pdo extends dba_driver if ($this->error) { db_logger('dba_pdo: ERROR: ' . printable($sql) . "\n" . $this->error, LOGGER_NORMAL, LOG_ERR); if (file_exists('dbfail.out') && strpos($this->error, 'Duplicate entry') === false) { - file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND); + file_put_contents('dbfail.out', Time::convert() . "\n" . printable($sql) . "\n" . $this->error . "\n", FILE_APPEND); } } } diff --git a/include/event.php b/include/event.php index a11542cb7..8e69250d3 100644 --- a/include/event.php +++ b/include/event.php @@ -5,6 +5,7 @@ * @brief Event related functions. */ +use Code\Lib\Time; use Sabre\VObject; use Code\Lib\Libsync; use Code\Lib\Activity; @@ -43,15 +44,15 @@ function format_event_html($ev) $o .= '

 ' . zidify_links(smilies(bbcode($ev['summary']))) . '

' . "\r\n"; $o .= '
' . t('Starts:') . ' ' - . (($ev['adjust']) ? day_translate(datetime_convert( + . (($ev['adjust']) ? day_translate(Time::convert( 'UTC', date_default_timezone_get(), $ev['dtstart'], $bd_format )) - : day_translate(datetime_convert( + : day_translate(Time::convert( 'UTC', 'UTC', $ev['dtstart'], @@ -61,15 +62,15 @@ function format_event_html($ev) if (! $ev['nofinish']) { $o .= '
' . t('Finishes:') . ' ' - . (($ev['adjust']) ? day_translate(datetime_convert( + . (($ev['adjust']) ? day_translate(Time::convert( 'UTC', date_default_timezone_get(), $ev['dtend'], $bd_format )) - : day_translate(datetime_convert( + : day_translate(Time::convert( 'UTC', 'UTC', $ev['dtend'], @@ -106,7 +107,7 @@ function format_event_obj($jobject) 'id' => z_root() . '/event/' . $r[0]['resource_id'], 'summary' => bbcode($arr['summary']), // RFC3339 Section 4.3 - 'startTime' => (($arr['adjust']) ? datetime_convert('UTC','UTC',$arr['dtstart'], ISO8601) : datetime_convert('UTC','UTC',$arr['dtstart'],'Y-m-d\\TH:i:s-00:00')), + 'startTime' => (($arr['adjust']) ? Time::convert('UTC','UTC',$arr['dtstart'], ISO8601) : Time::convert('UTC','UTC',$arr['dtstart'],'Y-m-d\\TH:i:s-00:00')), 'content' => bbcode($arr['description']), 'location' => [ 'type' => 'Place', 'content' => $arr['location'] ], 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ], @@ -114,7 +115,7 @@ function format_event_obj($jobject) 'actor' => Activity::encode_person($r[0],false), ]; if(! $arr['nofinish']) { - $x['endTime'] = (($arr['adjust']) ? datetime_convert('UTC','UTC',$arr['dtend'], ISO8601) : datetime_convert('UTC','UTC',$arr['dtend'],'Y-m-d\\TH:i:s-00:00')); + $x['endTime'] = (($arr['adjust']) ? Time::convert('UTC','UTC',$arr['dtend'], ISO8601) : Time::convert('UTC','UTC',$arr['dtend'],'Y-m-d\\TH:i:s-00:00')); } ******/ @@ -127,12 +128,12 @@ function format_event_obj($jobject) $event['header'] = replace_macros(Theme::get_template('event_item_header.tpl'), [ '$title' => $title, '$dtstart_label' => t('Starts:'), - '$dtstart_title' => datetime_convert('UTC', 'UTC', $object['startTime'], ((strpos($object['startTime'], 'Z')) ? ISO8601 : 'Y-m-d\TH:i:s' )), - '$dtstart_dt' => ((strpos($object['startTime'], 'Z')) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $object['startTime'], $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $object['startTime'], $bd_format))), + '$dtstart_title' => Time::convert('UTC', 'UTC', $object['startTime'], ((strpos($object['startTime'], 'Z')) ? ISO8601 : 'Y-m-d\TH:i:s' )), + '$dtstart_dt' => ((strpos($object['startTime'], 'Z')) ? day_translate(Time::convert('UTC', date_default_timezone_get(), $object['startTime'], $bd_format)) : day_translate(Time::convert('UTC', 'UTC', $object['startTime'], $bd_format))), '$finish' => array_key_exists('endTime', $object), '$dtend_label' => t('Finishes:'), - '$dtend_title' => datetime_convert('UTC', 'UTC', $dtend, ((strpos($object['startTime'], 'Z')) ? ISO8601 : 'Y-m-d\TH:i:s' )), - '$dtend_dt' => ((strpos($object['startTime'], 'Z')) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $dtend, $bd_format)) : day_translate(datetime_convert('UTC', 'UTC', $dtend, $bd_format))) + '$dtend_title' => Time::convert('UTC', 'UTC', $dtend, ((strpos($object['startTime'], 'Z')) ? ISO8601 : 'Y-m-d\TH:i:s' )), + '$dtend_dt' => ((strpos($object['startTime'], 'Z')) ? day_translate(Time::convert('UTC', date_default_timezone_get(), $dtend, $bd_format)) : day_translate(Time::convert('UTC', 'UTC', $dtend, $bd_format))) ]); @@ -178,14 +179,14 @@ function format_event_ical($ev) $o = "\r\nBEGIN:VEVENT"; - $o .= "\r\nCREATED:" . datetime_convert('UTC', 'UTC', $ev['created'], 'Ymd\\THis\\Z'); - $o .= "\r\nLAST-MODIFIED:" . datetime_convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); - $o .= "\r\nDTSTAMP:" . datetime_convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); + $o .= "\r\nCREATED:" . Time::convert('UTC', 'UTC', $ev['created'], 'Ymd\\THis\\Z'); + $o .= "\r\nLAST-MODIFIED:" . Time::convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); + $o .= "\r\nDTSTAMP:" . Time::convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); if ($ev['dtstart']) { - $o .= "\r\nDTSTART:" . datetime_convert('UTC', 'UTC', $ev['dtstart'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); + $o .= "\r\nDTSTART:" . Time::convert('UTC', 'UTC', $ev['dtstart'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); } if ($ev['dtend'] && ! $ev['nofinish']) { - $o .= "\r\nDTEND:" . datetime_convert('UTC', 'UTC', $ev['dtend'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); + $o .= "\r\nDTEND:" . Time::convert('UTC', 'UTC', $ev['dtend'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); } if ($ev['summary']) { $o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']); @@ -215,14 +216,14 @@ function format_todo_ical($ev) $o = ''; $o .= "\r\nBEGIN:VTODO"; - $o .= "\r\nCREATED:" . datetime_convert('UTC', 'UTC', $ev['created'], 'Ymd\\THis\\Z'); - $o .= "\r\nLAST-MODIFIED:" . datetime_convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); - $o .= "\r\nDTSTAMP:" . datetime_convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); + $o .= "\r\nCREATED:" . Time::convert('UTC', 'UTC', $ev['created'], 'Ymd\\THis\\Z'); + $o .= "\r\nLAST-MODIFIED:" . Time::convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); + $o .= "\r\nDTSTAMP:" . Time::convert('UTC', 'UTC', $ev['edited'], 'Ymd\\THis\\Z'); if ($ev['dtstart']) { - $o .= "\r\nDTSTART:" . datetime_convert('UTC', 'UTC', $ev['dtstart'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); + $o .= "\r\nDTSTART:" . Time::convert('UTC', 'UTC', $ev['dtstart'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); } if ($ev['dtend'] && ! $ev['nofinish']) { - $o .= "\r\nDUE:" . datetime_convert('UTC', 'UTC', $ev['dtend'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); + $o .= "\r\nDUE:" . Time::convert('UTC', 'UTC', $ev['dtend'], 'Ymd\\THis' . (($ev['adjust']) ? '\\Z' : '')); } if ($ev['summary']) { $o .= "\r\nSUMMARY:" . format_ical_text($ev['summary']); @@ -231,7 +232,7 @@ function format_todo_ical($ev) if ($ev['event_status']) { $o .= "\r\nSTATUS:" . $ev['event_status']; if ($ev['event_status'] === 'COMPLETED') { - $o .= "\r\nCOMPLETED:" . datetime_convert('UTC', 'UTC', $ev['event_status_date'], 'Ymd\\THis\\Z'); + $o .= "\r\nCOMPLETED:" . Time::convert('UTC', 'UTC', $ev['event_status_date'], 'Ymd\\THis\\Z'); } } if (intval($ev['event_percent'])) { @@ -401,10 +402,10 @@ function bbtoevent($s) if (preg_match("/\[event\-timezone\](.*?)\[\/event\-timezone\]/is", $s, $match)) { $tz = $match[1]; if (array_key_exists('dtstart', $ev)) { - $ev['dtstart'] = datetime_convert($tz, 'UTC', $ev['dtstart']); + $ev['dtstart'] = Time::convert($tz, 'UTC', $ev['dtstart']); } if (array_key_exists('dtend', $ev)) { - $ev['dtend'] = datetime_convert($tz, 'UTC', $ev['dtend']); + $ev['dtend'] = Time::convert($tz, 'UTC', $ev['dtend']); } } @@ -442,8 +443,8 @@ function sort_by_date($arr) function ev_compare($a, $b) { - $date_a = (($a['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $a['dtstart']) : $a['dtstart']); - $date_b = (($b['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $b['dtstart']) : $b['dtstart']); + $date_a = (($a['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $a['dtstart']) : $a['dtstart']); + $date_b = (($b['adjust']) ? Time::convert('UTC', date_default_timezone_get(), $b['dtstart']) : $b['dtstart']); if ($date_a === $date_b) { return strcasecmp($a['description'], $b['description']); @@ -456,8 +457,8 @@ function ev_compare($a, $b) function event_store_event($arr) { - $arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert()); - $arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert()); + $arr['created'] = (($arr['created']) ? $arr['created'] : Time::convert()); + $arr['edited'] = (($arr['edited']) ? $arr['edited'] : Time::convert()); $arr['etype'] = (($arr['etype']) ? $arr['etype'] : 'event' ); $arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : ''); $arr['event_priority'] = (($arr['event_priority']) ? $arr['event_priority'] : 0); @@ -468,7 +469,7 @@ function event_store_event($arr) } if (array_key_exists('event_status_date', $arr)) { - $arr['event_status_date'] = datetime_convert('UTC', 'UTC', $arr['event_status_date']); + $arr['event_status_date'] = Time::convert('UTC', 'UTC', $arr['event_status_date']); } else { $arr['event_status_date'] = NULL_DATE; } @@ -553,9 +554,9 @@ function event_store_event($arr) deny_cid = '%s', deny_gid = '%s' WHERE id = %d AND uid = %d", - dbesc(datetime_convert('UTC', 'UTC', $arr['edited'])), - dbesc(datetime_convert('UTC', 'UTC', $arr['dtstart'])), - dbesc(datetime_convert('UTC', 'UTC', $arr['dtend'])), + dbesc(Time::convert('UTC', 'UTC', $arr['edited'])), + dbesc(Time::convert('UTC', 'UTC', $arr['dtstart'])), + dbesc(Time::convert('UTC', 'UTC', $arr['dtend'])), dbesc($arr['summary']), dbesc($arr['description']), dbesc($arr['location']), @@ -563,7 +564,7 @@ function event_store_event($arr) intval($arr['adjust']), intval($arr['nofinish']), dbesc($arr['event_status']), - dbesc(datetime_convert('UTC', 'UTC', $arr['event_status_date'])), + dbesc(Time::convert('UTC', 'UTC', $arr['event_status_date'])), intval($arr['event_percent']), dbesc($arr['event_repeat']), intval($arr['event_sequence']), @@ -600,10 +601,10 @@ function event_store_event($arr) intval($arr['account']), dbesc($arr['event_xchan']), dbesc($hash), - dbesc(datetime_convert('UTC', 'UTC', $arr['created'])), - dbesc(datetime_convert('UTC', 'UTC', $arr['edited'])), - dbesc(datetime_convert('UTC', 'UTC', $arr['dtstart'])), - dbesc(datetime_convert('UTC', 'UTC', $arr['dtend'])), + dbesc(Time::convert('UTC', 'UTC', $arr['created'])), + dbesc(Time::convert('UTC', 'UTC', $arr['edited'])), + dbesc(Time::convert('UTC', 'UTC', $arr['dtstart'])), + dbesc(Time::convert('UTC', 'UTC', $arr['dtend'])), dbesc($arr['summary']), dbesc($arr['description']), dbesc($arr['location']), @@ -611,7 +612,7 @@ function event_store_event($arr) intval($arr['adjust']), intval($arr['nofinish']), dbesc($arr['event_status']), - dbesc(datetime_convert('UTC', 'UTC', $arr['event_status_date'])), + dbesc(Time::convert('UTC', 'UTC', $arr['event_status_date'])), intval($arr['event_percent']), dbesc($arr['event_repeat']), intval($arr['event_sequence']), @@ -766,7 +767,7 @@ function parse_vobject($ical, $type) $dtstart = $ical->DTSTART->getDateTime(); $ev['adjust'] = (($ical->DTSTART->isFloating()) ? 0 : 1); - $ev['dtstart'] = datetime_convert( + $ev['dtstart'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtstart->format(DateTimeInterface::W3C) @@ -775,14 +776,14 @@ function parse_vobject($ical, $type) if (isset($ical->DUE)) { $dtend = $ical->DUE->getDateTime(); - $ev['dtend'] = datetime_convert( + $ev['dtend'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtend->format(DateTimeInterface::W3C) ); } elseif (isset($ical->DTEND)) { $dtend = $ical->DTEND->getDateTime(); - $ev['dtend'] = datetime_convert( + $ev['dtend'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtend->format(DateTimeInterface::W3C) @@ -798,16 +799,16 @@ function parse_vobject($ical, $type) if (isset($ical->CREATED)) { $created = $ical->CREATED->getDateTime(); - $ev['created'] = datetime_convert('UTC', 'UTC', $created->format(DateTimeInterface::W3C)); + $ev['created'] = Time::convert('UTC', 'UTC', $created->format(DateTimeInterface::W3C)); } if (isset($ical->{'DTSTAMP'})) { $edited = $ical->{'DTSTAMP'}->getDateTime(); - $ev['edited'] = datetime_convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); + $ev['edited'] = Time::convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); } if (isset($ical->{'LAST-MODIFIED'})) { $edited = $ical->{'LAST-MODIFIED'}->getDateTime(); - $ev['edited'] = datetime_convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); + $ev['edited'] = Time::convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); } if (isset($ical->{'X-ZOT-LOCATION'})) { @@ -847,7 +848,7 @@ function parse_vobject($ical, $type) if (isset($ical->{'COMPLETED'})) { $completed = $ical->{'COMPLETED'}->getDateTime(); - $ev['event_status_date'] = datetime_convert('UTC', 'UTC', $completed->format(DateTimeInterface::W3C)); + $ev['event_status_date'] = Time::convert('UTC', 'UTC', $completed->format(DateTimeInterface::W3C)); } if (isset($ical->{'PERCENT-COMPLETE'})) { @@ -917,7 +918,7 @@ function event_import_ical($ical, $uid) // logger('dtstart: ' . var_export($dtstart,true)); - $ev['dtstart'] = datetime_convert( + $ev['dtstart'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtstart->format(DateTimeInterface::W3C) @@ -925,7 +926,7 @@ function event_import_ical($ical, $uid) if (isset($ical->DTEND)) { $dtend = $ical->DTEND->getDateTime(); - $ev['dtend'] = datetime_convert( + $ev['dtend'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtend->format(DateTimeInterface::W3C) @@ -940,12 +941,12 @@ function event_import_ical($ical, $uid) if (isset($ical->CREATED)) { $created = $ical->CREATED->getDateTime(); - $ev['created'] = datetime_convert('UTC', 'UTC', $created->format(DateTimeInterface::W3C)); + $ev['created'] = Time::convert('UTC', 'UTC', $created->format(DateTimeInterface::W3C)); } if (isset($ical->{'LAST-MODIFIED'})) { $edited = $ical->{'LAST-MODIFIED'}->getDateTime(); - $ev['edited'] = datetime_convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); + $ev['edited'] = Time::convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); } if (isset($ical->{'X-ZOT-LOCATION'})) { @@ -1034,7 +1035,7 @@ function event_import_ical_task($ical, $uid) // logger('dtstart: ' . var_export($dtstart,true)); - $ev['dtstart'] = datetime_convert( + $ev['dtstart'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtstart->format(DateTimeInterface::W3C) @@ -1043,7 +1044,7 @@ function event_import_ical_task($ical, $uid) if (isset($ical->DUE)) { $dtend = $ical->DUE->getDateTime(); - $ev['dtend'] = datetime_convert( + $ev['dtend'] = Time::convert( (($ev['adjust']) ? 'UTC' : date_default_timezone_get()), 'UTC', $dtend->format(DateTimeInterface::W3C) @@ -1059,17 +1060,17 @@ function event_import_ical_task($ical, $uid) if (isset($ical->CREATED)) { $created = $ical->CREATED->getDateTime(); - $ev['created'] = datetime_convert('UTC', 'UTC', $created->format(DateTimeInterface::W3C)); + $ev['created'] = Time::convert('UTC', 'UTC', $created->format(DateTimeInterface::W3C)); } if (isset($ical->{'DTSTAMP'})) { $edited = $ical->{'DTSTAMP'}->getDateTime(); - $ev['edited'] = datetime_convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); + $ev['edited'] = Time::convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); } if (isset($ical->{'LAST-MODIFIED'})) { $edited = $ical->{'LAST-MODIFIED'}->getDateTime(); - $ev['edited'] = datetime_convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); + $ev['edited'] = Time::convert('UTC', 'UTC', $edited->format(DateTimeInterface::W3C)); } if (isset($ical->{'X-ZOT-LOCATION'})) { @@ -1128,7 +1129,7 @@ function event_import_ical_task($ical, $uid) if (isset($ical->{'COMPLETED'})) { $completed = $ical->{'COMPLETED'}->getDateTime(); - $ev['event_status_date'] = datetime_convert('UTC', 'UTC', $completed->format(DateTimeInterface::W3C)); + $ev['event_status_date'] = Time::convert('UTC', 'UTC', $completed->format(DateTimeInterface::W3C)); } if (isset($ical->{'PERCENT-COMPLETE'})) { @@ -1211,7 +1212,7 @@ function event_store_item($arr, $event, $deliver = true, $addAndSync = true) 'id' => z_root() . '/event/' . $r[0]['resource_id'], 'name' => $arr['summary'], // RFC3339 Section 4.3 - 'startTime' => (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtstart'], ISO8601) : datetime_convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')), + 'startTime' => (($arr['adjust']) ? Time::convert('UTC', 'UTC', $arr['dtstart'], ISO8601) : Time::convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')), 'content' => bbcode($arr['description']), 'location' => [ 'type' => 'Place', 'content' => $arr['location'] ], 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ], @@ -1222,7 +1223,7 @@ function event_store_item($arr, $event, $deliver = true, $addAndSync = true) ]; if (! $arr['nofinish']) { - $x['endTime'] = (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtend'], ISO8601) : datetime_convert('UTC', 'UTC', $arr['dtend'], 'Y-m-d\\TH:i:s-00:00')); + $x['endTime'] = (($arr['adjust']) ? Time::convert('UTC', 'UTC', $arr['dtend'], ISO8601) : Time::convert('UTC', 'UTC', $arr['dtend'], 'Y-m-d\\TH:i:s-00:00')); } if ($event['event_repeat']) { $x['eventRepeat'] = $event['event_repeat']; @@ -1335,7 +1336,7 @@ function event_store_item($arr, $event, $deliver = true, $addAndSync = true) 'id' => z_root() . '/event/' . $event['event_hash'], 'name' => $arr['summary'], // RFC3339 Section 4.3 - 'startTime' => (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtstart'], ISO8601) : datetime_convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')), + 'startTime' => (($arr['adjust']) ? Time::convert('UTC', 'UTC', $arr['dtstart'], ISO8601) : Time::convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')), 'content' => bbcode($arr['description']), 'location' => [ 'type' => 'Place', 'content' => bbcode($arr['location']) ], 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ], @@ -1346,7 +1347,7 @@ function event_store_item($arr, $event, $deliver = true, $addAndSync = true) ]; if (! $arr['nofinish']) { - $y['endTime'] = (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtend'], ISO8601) : datetime_convert('UTC', 'UTC', $arr['dtend'], 'Y-m-d\\TH:i:s-00:00')); + $y['endTime'] = (($arr['adjust']) ? Time::convert('UTC', 'UTC', $arr['dtend'], ISO8601) : Time::convert('UTC', 'UTC', $arr['dtend'], 'Y-m-d\\TH:i:s-00:00')); } if ($arr['event_repeat']) { $y['eventRepeat'] = $arr['event_repeat']; diff --git a/include/feedutils.php b/include/feedutils.php index 4560e4741..c471814aa 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -7,6 +7,7 @@ use Code\Lib\Img_filesize; use Code\Extend\Hook; +use Code\Lib\Time; use Code\Render\Theme; @@ -28,7 +29,7 @@ function get_public_feed($channel, $params) $params['type'] = ((x($params, 'type')) ? $params['type'] : 'xml'); $params['begin'] = ((x($params, 'begin')) ? $params['begin'] : NULL_DATE); - $params['end'] = ((x($params, 'end')) ? $params['end'] : datetime_convert('UTC', 'UTC', 'now')); + $params['end'] = ((x($params, 'end')) ? $params['end'] : Time::convert('UTC', 'UTC', 'now')); $params['start'] = ((x($params, 'start')) ? $params['start'] : 0); $params['records'] = ((x($params, 'records')) ? $params['records'] : 40); $params['direction'] = ((x($params, 'direction')) ? $params['direction'] : 'desc'); @@ -104,7 +105,7 @@ function get_feed_for($channel, $observer_hash, $params) '$generator_uri' => z_root(), '$feed_id' => xmlify($channel['xchan_url']), '$feed_title' => xmlify($channel['channel_name']), - '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ISO8601)), + '$feed_updated' => xmlify(Time::convert('UTC', 'UTC', 'now', ISO8601)), '$author' => $feed_author, '$profile_page' => xmlify($channel['xchan_url']), ]); @@ -305,7 +306,7 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) } if ($item['deleted']) { - return '' . "\r\n"; + return '' . "\r\n"; } create_export_photo_body($item); @@ -338,8 +339,8 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0) } $o .= '' . xmlify(prepare_text($body, $item['mimetype'])) . '' . "\r\n"; $o .= '' . xmlify($item['mid']) . '' . "\r\n"; - $o .= '' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ISO8601)) . '' . "\r\n"; - $o .= '' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ISO8601)) . '' . "\r\n"; + $o .= '' . xmlify(Time::convert('UTC', 'UTC', $item['created'] . '+00:00', ISO8601)) . '' . "\r\n"; + $o .= '' . xmlify(Time::convert('UTC', 'UTC', $item['edited'] . '+00:00', ISO8601)) . '' . "\r\n"; $o .= '' . "\r\n"; diff --git a/include/hubloc.php b/include/hubloc.php index e479f6071..6cacf8dc0 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -6,6 +6,7 @@ */ use Code\Lib\Channel; +use Code\Lib\Time; use Code\Lib\Url; use Code\Daemon\Run; @@ -90,8 +91,8 @@ function prune_hub_reinstalls() // see if this url has more than one sitekey, indicating it has been re-installed. if (count($x) > 1) { - $d1 = datetime_convert('UTC', 'UTC', $x[0]['c']); - $d2 = datetime_convert('UTC', 'UTC', 'now - 3 days'); + $d1 = Time::convert('UTC', 'UTC', $x[0]['c']); + $d2 = Time::convert('UTC', 'UTC', 'now - 3 days'); // allow some slop period, say 3 days - just in case this is a glitch or transient occurrence // Then remove any hublocs pointing to the oldest entry. @@ -284,7 +285,7 @@ function hubloc_mark_as_down($posturl) function hubloc_delete($hubloc) { if (is_array($hubloc) && array_key_exists('hubloc_id',$hubloc)) { q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($hubloc['hubloc_id']), ); } diff --git a/include/import.php b/include/import.php index cc3ce8ed2..451ae7707 100644 --- a/include/import.php +++ b/include/import.php @@ -2,6 +2,7 @@ use Code\Lib\IConfig; use Code\Lib\Libzot; +use Code\Lib\Time; use Code\Web\HTTPSig; use Code\Lib\Apps; use Code\Lib\LibBlock; @@ -710,10 +711,10 @@ function sync_apps($channel, $apps) } if ((! $app['app_created']) || ($app['app_created'] <= NULL_DATE)) { - $app['app_created'] = datetime_convert(); + $app['app_created'] = Time::convert(); } if ((! $app['app_edited']) || ($app['app_edited'] <= NULL_DATE)) { - $app['app_edited'] = datetime_convert(); + $app['app_edited'] = Time::convert(); } $app['app_channel'] = $channel['channel_id']; @@ -946,10 +947,10 @@ function sync_chatrooms($channel, $chatrooms) unset($chatroom['cr_uid']); if ((! $chatroom['cr_created']) || ($chatroom['cr_created'] <= NULL_DATE)) { - $chatroom['cr_created'] = datetime_convert(); + $chatroom['cr_created'] = Time::convert(); } if ((! $chatroom['cr_edited']) || ($chatroom['cr_edited'] <= NULL_DATE)) { - $chatroom['cr_edited'] = datetime_convert(); + $chatroom['cr_edited'] = Time::convert(); } $chatroom['cr_aid'] = $channel['channel_account_id']; @@ -1202,10 +1203,10 @@ function import_menus($channel, $menus) $m['menu_name'] = $menu['pagetitle']; $m['menu_desc'] = $menu['desc']; if ($menu['created']) { - $m['menu_created'] = datetime_convert('UTC', 'UTC', $menu['created']); + $m['menu_created'] = Time::convert('UTC', 'UTC', $menu['created']); } if ($menu['edited']) { - $m['menu_edited'] = datetime_convert('UTC', 'UTC', $menu['edited']); + $m['menu_edited'] = Time::convert('UTC', 'UTC', $menu['edited']); } $m['menu_flags'] = 0; if ($menu['flags']) { @@ -1267,10 +1268,10 @@ function sync_menus($channel, $menus) $m['menu_name'] = $menu['pagetitle']; $m['menu_desc'] = $menu['desc']; if ($menu['created']) { - $m['menu_created'] = datetime_convert('UTC', 'UTC', $menu['created']); + $m['menu_created'] = Time::convert('UTC', 'UTC', $menu['created']); } if ($menu['edited']) { - $m['menu_edited'] = datetime_convert('UTC', 'UTC', $menu['edited']); + $m['menu_edited'] = Time::convert('UTC', 'UTC', $menu['edited']); } $m['menu_flags'] = 0; if ($menu['flags']) { @@ -1596,7 +1597,7 @@ function sync_files($channel, $files) // streamed directly to disk and avoid consuming PHP memory if it's a huge // audio/video file or something. - $time = datetime_convert(); + $time = Time::convert(); $parr = [ 'hash' => $channel['channel_hash'], @@ -1685,7 +1686,7 @@ function sync_files($channel, $files) } if (intval($p['imgscale']) && ((intval($p['os_storage'])) || (! $p['content']))) { - $time = datetime_convert(); + $time = Time::convert(); $parr = [ 'hash' => $channel['channel_hash'], @@ -1763,7 +1764,7 @@ function sync_files($channel, $files) // set this or the next channel refresh will wipe out the profile photo with one that's fetched remotely // and lacks the file context; as we probably didn't receive an xchan record in the sync packet q("update xchan set xchan_photo_date = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($channel['channel_hash']) ); } @@ -1942,12 +1943,12 @@ function import_webpage_element($element, $channel, $type) $arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid']; $arr['created'] = $iteminfo[0]['created']; } else { // otherwise, generate the creation times and unique id - $arr['created'] = datetime_convert('UTC', 'UTC'); + $arr['created'] = Time::convert('UTC', 'UTC'); $arr['uuid'] = new_uuid(); $arr['mid'] = $arr['parent_mid'] = z_root() . '/item/' . $arr['uuid']; } // Update the edited time whether or not the element already exists - $arr['edited'] = datetime_convert('UTC', 'UTC'); + $arr['edited'] = Time::convert('UTC', 'UTC'); // Import the actual element content $arr['body'] = file_get_contents($element['path']); // The element owner is the channel importing the elements @@ -2047,8 +2048,8 @@ function get_webpage_elements($channel, $type = 'all') 'url' => $rr['iid'], 'pagetitle' => $rr['v'], 'title' => $rr['title'], - 'created' => datetime_convert('UTC', date_default_timezone_get(), $rr['created']), - 'edited' => datetime_convert('UTC', date_default_timezone_get(), $rr['edited']), + 'created' => Time::convert('UTC', date_default_timezone_get(), $rr['created']), + 'edited' => Time::convert('UTC', date_default_timezone_get(), $rr['edited']), 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', //'lockstate' => $lockstate ]; diff --git a/include/items.php b/include/items.php index 833aa555f..0fb0d9b27 100644 --- a/include/items.php +++ b/include/items.php @@ -22,6 +22,7 @@ use Code\Lib\ObjCache; use Code\Lib\PConfig; use Code\Lib\LibBlock; use Code\Lib\ThreadListener; +use Code\Lib\Time; use Code\Lib\Tombstone; use Code\Access\PermissionLimits; use Code\Access\PermissionRoles; @@ -195,7 +196,7 @@ function comments_are_now_closed($item) { return $x['closed']; } - if ($item['comments_closed'] > NULL_DATE && datetime_convert() > $item['comments_closed']) { + if ($item['comments_closed'] > NULL_DATE && Time::convert() > $item['comments_closed']) { return true; } @@ -530,18 +531,18 @@ function get_item_elements($x) { logger('get_item_elements: message summary length exceeds max_import_size: truncated'); } - $arr['created'] = datetime_convert('UTC','UTC',$x['created']); - $arr['edited'] = datetime_convert('UTC','UTC',$x['edited']); + $arr['created'] = Time::convert('UTC','UTC',$x['created']); + $arr['edited'] = Time::convert('UTC','UTC',$x['edited']); $arr['expires'] = ((x($x,'expires') && $x['expires']) - ? datetime_convert('UTC','UTC',$x['expires']) + ? Time::convert('UTC','UTC',$x['expires']) : NULL_DATE); $arr['commented'] = ((x($x,'commented') && $x['commented']) - ? datetime_convert('UTC','UTC',$x['commented']) + ? Time::convert('UTC','UTC',$x['commented']) : $arr['created']); $arr['comments_closed'] = ((x($x,'comments_closed') && $x['comments_closed']) - ? datetime_convert('UTC','UTC',$x['comments_closed']) + ? Time::convert('UTC','UTC',$x['comments_closed']) : NULL_DATE); $arr['title'] = (($x['title']) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8',false) : ''); @@ -882,9 +883,9 @@ function import_author_unknown($x) { 'xchan_hash' => $x['url'], 'xchan_guid' => $x['url'], 'xchan_url' => $x['url'], - 'xchan_updated' => datetime_convert(), + 'xchan_updated' => Time::convert(), 'xchan_name' => (($name) ?: t('(Unknown)')), - 'xchan_name_date' => datetime_convert(), + 'xchan_name_date' => Time::convert(), 'xchan_network' => 'unknown' ] ); @@ -895,8 +896,8 @@ function import_author_unknown($x) { if($photos) { $r = q("update xchan set xchan_updated = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' and xchan_network = 'unknown'", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -1346,7 +1347,7 @@ function get_profile_elements($profile) { $arr['desc'] = (($profile['title']) ? htmlspecialchars($profile['title'],ENT_COMPAT,'UTF-8',false) : ''); - $arr['dob'] = datetime_convert('UTC','UTC',$profile['birthday'],'Y-m-d'); + $arr['dob'] = Time::convert('UTC','UTC',$profile['birthday'],'Y-m-d'); $arr['age'] = (($profile['age']) ? intval($profile['age']) : 0); $arr['gender'] = (($profile['gender']) ? htmlspecialchars($profile['gender'], ENT_COMPAT,'UTF-8',false) : ''); @@ -1548,16 +1549,16 @@ function item_store($arr, $deliver = true, $addAndSync = true) { $arr['author_xchan'] = ((x($arr,'author_xchan')) ? notags(trim($arr['author_xchan'])) : ''); $arr['owner_xchan'] = ((x($arr,'owner_xchan')) ? notags(trim($arr['owner_xchan'])) : ''); - $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); - $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); - $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : NULL_DATE); - $arr['commented'] = ((x($arr,'commented') !== false) ? datetime_convert('UTC','UTC',$arr['commented']) : datetime_convert()); - $arr['comments_closed'] = ((x($arr,'comments_closed') !== false) ? datetime_convert('UTC','UTC',$arr['comments_closed']) : NULL_DATE); + $arr['created'] = ((x($arr,'created') !== false) ? Time::convert('UTC','UTC',$arr['created']) : Time::convert()); + $arr['edited'] = ((x($arr,'edited') !== false) ? Time::convert('UTC','UTC',$arr['edited']) : Time::convert()); + $arr['expires'] = ((x($arr,'expires') !== false) ? Time::convert('UTC','UTC',$arr['expires']) : NULL_DATE); + $arr['commented'] = ((x($arr,'commented') !== false) ? Time::convert('UTC','UTC',$arr['commented']) : Time::convert()); + $arr['comments_closed'] = ((x($arr,'comments_closed') !== false) ? Time::convert('UTC','UTC',$arr['comments_closed']) : NULL_DATE); $arr['html'] = ((array_key_exists('html',$arr)) ? $arr['html'] : ''); if($deliver) { - $arr['received'] = datetime_convert(); - $arr['changed'] = datetime_convert(); + $arr['received'] = Time::convert(); + $arr['changed'] = Time::convert(); } else { @@ -1566,8 +1567,8 @@ function item_store($arr, $deliver = true, $addAndSync = true) { // will still take place through backdoor methods. Since these fields are rarely used // otherwise, just preserve the original timestamp. - $arr['received'] = ((x($arr,'received') !== false) ? datetime_convert('UTC','UTC',$arr['received']) : datetime_convert()); - $arr['changed'] = ((x($arr,'changed') !== false) ? datetime_convert('UTC','UTC',$arr['changed']) : datetime_convert()); + $arr['received'] = ((x($arr,'received') !== false) ? Time::convert('UTC','UTC',$arr['received']) : Time::convert()); + $arr['changed'] = ((x($arr,'changed') !== false) ? Time::convert('UTC','UTC',$arr['changed']) : Time::convert()); } $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : ''); @@ -2115,12 +2116,12 @@ function item_store_update($arr, $deliver = true, $addAndSync = true) { if (intval($orig[0]['item_unpublished'])) { - $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert()); + $arr['created'] = ((x($arr,'created') !== false) ? Time::convert('UTC','UTC',$arr['created']) : Time::convert()); $arr['edited'] = $arr['created']; - $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : NULL_DATE); + $arr['expires'] = ((x($arr,'expires') !== false) ? Time::convert('UTC','UTC',$arr['expires']) : NULL_DATE); if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] > NULL_DATE) - $arr['comments_closed'] = datetime_convert('UTC','UTC',$arr['comments_closed']); + $arr['comments_closed'] = Time::convert('UTC','UTC',$arr['comments_closed']); else $arr['comments_closed'] = NULL_DATE; @@ -2133,11 +2134,11 @@ function item_store_update($arr, $deliver = true, $addAndSync = true) { else { unset($arr['created']); - $arr['expires'] = ((x($arr,'expires') !== false) ? datetime_convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']); + $arr['expires'] = ((x($arr,'expires') !== false) ? Time::convert('UTC','UTC',$arr['expires']) : $orig[0]['expires']); if(array_key_exists('comments_closed',$arr) && $arr['comments_closed'] > NULL_DATE) - $arr['comments_closed'] = datetime_convert('UTC','UTC',$arr['comments_closed']); + $arr['comments_closed'] = Time::convert('UTC','UTC',$arr['comments_closed']); else $arr['comments_closed'] = $orig[0]['comments_closed']; @@ -2146,7 +2147,7 @@ function item_store_update($arr, $deliver = true, $addAndSync = true) { $arr['changed'] = $orig[0]['changed']; } - $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert()); + $arr['edited'] = ((x($arr,'edited') !== false) ? Time::convert('UTC','UTC',$arr['edited']) : Time::convert()); $arr['revision'] = ((x($arr,'revision') && $arr['revision'] > 0) ? intval($arr['revision']) : 0); $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']); @@ -2334,7 +2335,7 @@ function item_update_parent_commented($item) { if(intval($item['item_blocked']) === ITEM_MODERATED) $update_parent = false; - if($item['created'] < datetime_convert('','','now - 4 days')) + if($item['created'] < Time::convert('','','now - 4 days')) $update_parent = false; if($update_parent) { @@ -2344,8 +2345,8 @@ function item_update_parent_commented($item) { ); q("UPDATE item set commented = '%s', changed = '%s' WHERE id = %d", - dbesc(($z) ? $z[0]['commented'] : datetime_convert()), - dbesc(datetime_convert()), + dbesc(($z) ? $z[0]['commented'] : Time::convert()), + dbesc(Time::convert()), intval($item['parent']) ); } @@ -3026,7 +3027,7 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr $arr['parent'] = intval($r[0]['parent']); $arr['mid'] = $r[0]['mid']; $arr['parent_mid'] = $r[0]['parent_mid']; - $arr['edited'] = datetime_convert(); + $arr['edited'] = Time::convert(); } else { logger('unable to locate original group post ' . $item['mid']); @@ -3205,7 +3206,7 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr } q("update channel set channel_lastpost = '%s' where channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($channel['channel_id']) ); @@ -3288,7 +3289,7 @@ function start_delivery_chain($channel, $item, $item_id, bool|array $parent, $gr } q("update channel set channel_lastpost = '%s' where channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($channel['channel_id']) ); } @@ -3785,13 +3786,13 @@ function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL, $force = false, $ match ($stage) { DROPITEM_PHASE2 => q("UPDATE item SET item_pending_remove = 1, body = '', title = '', changed = '%s', edited = '%s' WHERE id = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), intval($item['id']) ), DROPITEM_PHASE1 => q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where id = %d", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), intval($item['id']) ), default => q("DELETE FROM item WHERE id = %d", @@ -3894,7 +3895,7 @@ function first_post_date($uid, $wall = false) { ); if ($r) { - return datetime_convert('UTC',date_default_timezone_get(),$r[0]['created'], 'Y-m-d'); + return Time::convert('UTC',date_default_timezone_get(),$r[0]['created'], 'Y-m-d'); } return false; @@ -3914,10 +3915,10 @@ function list_post_dates($uid, $wall, $mindate) { $ret = []; - $dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d'); + $dnow = Time::convert('',date_default_timezone_get(),'now','Y-m-d'); if ($mindate) { - $dthen = datetime_convert('',date_default_timezone_get(), $mindate); + $dthen = Time::convert('',date_default_timezone_get(), $mindate); } else { $dthen = first_post_date($uid, $wall); @@ -3943,14 +3944,14 @@ function list_post_dates($uid, $wall, $mindate) { $dyear = intval(substr($dnow,0,4)); $dstart = substr($dnow,0,8) . '01'; $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); - $start_month = datetime_convert('','',$dstart,'Y-m-d'); - $end_month = datetime_convert('','',$dend,'Y-m-d'); - $str = day_translate(datetime_convert('','',$dnow,'F')); + $start_month = Time::convert('','',$dstart,'Y-m-d'); + $end_month = Time::convert('','',$dend,'Y-m-d'); + $str = day_translate(Time::convert('','',$dnow,'F')); if (! $ret[$dyear]) { $ret[$dyear] = []; } $ret[$dyear][] = [ $str, $end_month, $start_month ]; - $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); + $dnow = Time::convert('','',$dnow . ' -1 month', 'Y-m-d'); } return $ret; @@ -3959,7 +3960,7 @@ function list_post_dates($uid, $wall, $mindate) { function posted_dates($uid,$wall) { - $dnow = datetime_convert('UTC',date_default_timezone_get(),'now','Y-m-d'); + $dnow = Time::convert('UTC',date_default_timezone_get(),'now','Y-m-d'); $dthen = first_post_date($uid,$wall); @@ -3985,11 +3986,11 @@ function posted_dates($uid,$wall) { while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { $dstart = substr($dnow,0,8) . '01'; $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); - $start_month = datetime_convert('','',$dstart,'Y-m-d'); - $end_month = datetime_convert('','',$dend,'Y-m-d'); - $str = day_translate(datetime_convert('','',$dnow,'F Y')); + $start_month = Time::convert('','',$dstart,'Y-m-d'); + $end_month = Time::convert('','',$dend,'Y-m-d'); + $str = day_translate(Time::convert('','',$dnow,'F Y')); $ret[] = [$str,$end_month,$start_month]; - $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); + $dnow = Time::convert('','',$dnow . ' -1 month', 'Y-m-d'); } return $ret; } @@ -4101,7 +4102,7 @@ function zot_feed($uid, $observer_hash, $arr) { $encoding = ((array_key_exists('encoding',$arr)) ? $arr['encoding'] : 'zot'); if(array_key_exists('mindate',$arr)) { - $mindate = datetime_convert('UTC','UTC',$arr['mindate']); + $mindate = Time::convert('UTC','UTC',$arr['mindate']); } if(array_key_exists('message_id',$arr)) { @@ -4323,10 +4324,10 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C } if ($arr['datequery']) { - $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery'])))); + $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(Time::convert('UTC','UTC',$arr['datequery'])))); } if ($arr['datequery2']) { - $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert('UTC','UTC',$arr['datequery2'])))); + $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(Time::convert('UTC','UTC',$arr['datequery2'])))); } if ($arr['search']) { @@ -4679,8 +4680,8 @@ function send_profile_photo_activity($channel,$photo,$profile) { $arr['obj'] = [ 'type' => ACTIVITY_OBJ_NOTE, - 'published' => datetime_convert('UTC', 'UTC', 'now', ISO8601), - 'updated' => datetime_convert('UTC', 'UTC', 'now', ISO8601), + 'published' => Time::convert('UTC', 'UTC', 'now', ISO8601), + 'updated' => Time::convert('UTC', 'UTC', 'now', ISO8601), 'id' => $arr['mid'], 'url' => [ 'type' => 'Link', 'mediaType' => $photo['mimetype'], 'href' => z_root() . '/photo/profile/l/' . $channel['channel_id'] ], 'source' => [ 'content' => $arr['body'], 'mediaType' => 'text/x-multicode' ], @@ -4895,7 +4896,7 @@ function item_create_edit_activity($post) { $new_item['verb'] = ACTIVITY_UPDATE; $new_item['item_thread_top'] = 0; - $new_item['created'] = $new_item['edited'] = datetime_convert(); + $new_item['created'] = $new_item['edited'] = Time::convert(); $new_item['obj_type'] = (($update_item['item_thread_top']) ? ACTIVITY_OBJ_NOTE : ACTIVITY_OBJ_COMMENT); $new_item['obj'] = json_encode([ 'type' => $new_item['obj_type'], diff --git a/include/misc.php b/include/misc.php index ded111a00..10cd32e2b 100644 --- a/include/misc.php +++ b/include/misc.php @@ -16,6 +16,7 @@ use Code\Lib\Config; use Code\Lib\Channel; use Code\Lib\Features; use Code\Extend\Hook; +use Code\Lib\Time; use Code\Render\Theme; use Code\Lib\ActivityStreams; use Michelf\MarkdownExtra; @@ -738,7 +739,7 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; - $s = datetime_convert('UTC', 'UTC', 'now', ISO8601) . ':' . log_priority_str($priority) . ':' . logid() . ':' . $where . $msg . PHP_EOL; + $s = Time::convert('UTC', 'UTC', 'now', ISO8601) . ':' . log_priority_str($priority) . ':' . logid() . ':' . $where . $msg . PHP_EOL; $pluginfo = ['filename' => $logfile, 'loglevel' => $level, 'message' => $s,'priority' => $priority, 'logged' => false]; if (! (App::$module == 'setup')) { @@ -779,7 +780,7 @@ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) if (file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; - $s = datetime_convert('UTC', 'UTC', 'now', ISO8601) . ':' . log_priority_str($priority) . ':' . logid() . ':' . $where . $msg . PHP_EOL; + $s = Time::convert('UTC', 'UTC', 'now', ISO8601) . ':' . log_priority_str($priority) . ':' . logid() . ':' . $where . $msg . PHP_EOL; @file_put_contents(BTLOGGER_DEBUG_FILE, $s, FILE_APPEND); } @@ -850,7 +851,7 @@ function dlogger($msg, $level = 0) $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; - @file_put_contents($logfile, datetime_convert('UTC', 'UTC', 'now', ISO8601) . ':' . logid() . ' ' . $where . $msg . PHP_EOL, FILE_APPEND); + @file_put_contents($logfile, Time::convert('UTC', 'UTC', 'now', ISO8601) . ':' . logid() . ' ' . $where . $msg . PHP_EOL, FILE_APPEND); } @@ -1921,7 +1922,7 @@ function prepare_body(&$item, $attach = false, $opts = false) if ($cache_expire <= 0) { $cache_expire = 60; } - $cache_enable = !((($cache_expire) && ($item['created'] < datetime_convert('UTC', 'UTC', 'now - ' . $cache_expire . ' days')))); + $cache_enable = !((($cache_expire) && ($item['created'] < Time::convert('UTC', 'UTC', 'now - ' . $cache_expire . ' days')))); // disable Unicode RTL over-ride since it can destroy presentation in some cases, use HTML or CSS instead $s = str_replace([ '‮', '‮', html_entity_decode('‮', ENT_QUOTES, 'UTF-8') ], [ '','','' ], $s); @@ -1995,8 +1996,8 @@ function format_poll($item, $s, $opts) if ($item['comments_closed'] > NULL_DATE) { $closing = true; - $t = datetime_convert('UTC', date_default_timezone_get(), $item['comments_closed'], 'Y-m-d H:i'); - $closed = datetime_convert() > $item['comments_closed']; + $t = Time::convert('UTC', date_default_timezone_get(), $item['comments_closed'], 'Y-m-d H:i'); + $closed = Time::convert() > $item['comments_closed']; if ($closed) { $commentable = false; } diff --git a/include/network.php b/include/network.php index 709d3e1a0..49a2d4255 100644 --- a/include/network.php +++ b/include/network.php @@ -2,6 +2,7 @@ use Code\Lib\Config; use Code\Lib\Libzot; +use Code\Lib\Time; use Code\Lib\Zotfinger; use Code\Lib\Webfinger; use Code\Lib\Channel; @@ -59,7 +60,7 @@ function as_return_and_die($obj, $channel, $contextType = null, $signObject = tr } $json = json_encode($data, JSON_UNESCAPED_SLASHES); logger('data: ' . jindent($json), LOGGER_DATA); - $headers['Date'] = datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); + $headers['Date'] = Time::convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'); $headers['Digest'] = HTTPSig::generate_digest_header($json); $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; diff --git a/include/photos.php b/include/photos.php index 57fefbea3..144681367 100644 --- a/include/photos.php +++ b/include/photos.php @@ -9,6 +9,7 @@ use Code\Lib\Apps; use Code\Lib\Activity; use Code\Access\AccessControl; use Code\Access\PermissionLimits; +use Code\Lib\Time; use Code\Web\HTTPHeaders; use Code\Daemon\Run; use Code\Lib\ServiceClass; @@ -415,8 +416,8 @@ function photo_upload($channel, $observer, $args) 'type' => ACTIVITY_OBJ_PHOTO, 'name' => $title, 'summary' => $p['description'], - 'published' => datetime_convert('UTC', 'UTC', $p['created'], ISO8601), - 'updated' => datetime_convert('UTC', 'UTC', $p['edited'], ISO8601), + 'published' => Time::convert('UTC', 'UTC', $p['created'], ISO8601), + 'updated' => Time::convert('UTC', 'UTC', $p['edited'], ISO8601), 'attributedTo' => $attribution, // This is a placeholder and will get over-ridden by the item mid, which is critical for sharing as a conversational item over activitypub 'id' => z_root() . '/photo/' . $photo_hash, @@ -472,12 +473,12 @@ function photo_upload($channel, $observer, $args) if ($object['commentPolicy']) { $object['commentPolicy'] .= ' '; } - $object['commentPolicy'] .= 'until=' . datetime_convert('UTC', 'UTC', $item['created'], ISO8601); + $object['commentPolicy'] .= 'until=' . Time::convert('UTC', 'UTC', $item['created'], ISO8601); } elseif (array_key_exists('comments_closed', $item) && $item['comments_closed'] !== EMPTY_STR && $item['comments_closed'] > NULL_DATE) { if ($object['commentPolicy']) { $object['commentPolicy'] .= ' '; } - $object['commentPolicy'] .= 'until=' . datetime_convert('UTC', 'UTC', $item['comments_closed'], ISO8601); + $object['commentPolicy'] .= 'until=' . Time::convert('UTC', 'UTC', $item['comments_closed'], ISO8601); } if ($item['mid'] === $item['parent_mid']) { diff --git a/include/security.php b/include/security.php index a1292c97d..10bfff514 100644 --- a/include/security.php +++ b/include/security.php @@ -3,7 +3,8 @@ use Code\Lib\AConfig; use Code\Lib\Channel; use Code\Extend\Hook; -use Code\Storage\Stdio; +use Code\Lib\Time; +use Code\Storage\Stdio; /** * @file include/security.php * @@ -56,10 +57,10 @@ function authenticate_success($user_record, $channel = false, $login_initial = f if (($login_initial || $update_lastlog) && (! (isset($_SESSION['sudo']) && $_SESSION['sudo']))) { q( "update account set account_lastlog = '%s' where account_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($_SESSION['account_id']) ); - App::$account['account_lastlog'] = datetime_convert(); + App::$account['account_lastlog'] = Time::convert(); $lastlog_updated = true; Hook::call('logged_in', App::$account); } @@ -331,10 +332,10 @@ function change_channel($change_channel) // Update the active timestamp at most once a day - if (substr($r[0]['channel_active'], 0, 10) !== substr(datetime_convert(), 0, 10) && (! (isset($_SESSION['sudo']) && $_SESSION['sudo']))) { + if (substr($r[0]['channel_active'], 0, 10) !== substr(Time::convert(), 0, 10) && (! (isset($_SESSION['sudo']) && $_SESSION['sudo']))) { $z = q( "UPDATE channel SET channel_active = '%s' WHERE channel_id = %d", - dbesc(datetime_convert()), + dbesc(Time::convert()), intval($r[0]['channel_id']) ); } diff --git a/include/taxonomy.php b/include/taxonomy.php index d92295165..a47ca4b01 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -5,6 +5,7 @@ use Code\Lib\Apps; use Code\Lib\Channel; use Code\Extend\Hook; +use Code\Lib\Time; // post categories and "save to file" use the same item.file table for storage. // We will differentiate the different uses by wrapping categories in angle brackets @@ -400,7 +401,7 @@ function pub_tagadelic($mode, $limit, $recent, $safemode, $type) } if ($recent) { - $sql_extra .= " and item.created > '" . datetime_convert('UTC', 'UTC', 'now - ' . intval($recent) . ' days ') . "' "; + $sql_extra .= " and item.created > '" . Time::convert('UTC', 'UTC', 'now - ' . intval($recent) . ' days ') . "' "; } if ($safemode) { diff --git a/include/xchan.php b/include/xchan.php index 436c5ad3d..2e5fb19b8 100644 --- a/include/xchan.php +++ b/include/xchan.php @@ -1,6 +1,7 @@ ((array_key_exists('xchan_connpage', $arr)) ? $arr['xchan_connpage'] : ''), 'xchan_name' => ((array_key_exists('xchan_name', $arr)) ? $arr['xchan_name'] : ''), 'xchan_network' => ((array_key_exists('xchan_network', $arr)) ? $arr['xchan_network'] : ''), - 'xchan_created' => ((array_key_exists('xchan_created', $arr)) ? datetime_convert('UTC', 'UTC', $arr['xchan_created']) : datetime_convert()), - 'xchan_updated' => ((array_key_exists('xchan_updated', $arr)) ? datetime_convert('UTC', 'UTC', $arr['xchan_updated']) : datetime_convert()), - 'xchan_photo_date' => ((array_key_exists('xchan_photo_date', $arr)) ? datetime_convert('UTC', 'UTC', $arr['xchan_photo_date']) : NULL_DATE), - 'xchan_name_date' => ((array_key_exists('xchan_name_date', $arr)) ? datetime_convert('UTC', 'UTC', $arr['xchan_name_date']) : NULL_DATE), + 'xchan_created' => ((array_key_exists('xchan_created', $arr)) ? Time::convert('UTC', 'UTC', $arr['xchan_created']) : Time::convert()), + 'xchan_updated' => ((array_key_exists('xchan_updated', $arr)) ? Time::convert('UTC', 'UTC', $arr['xchan_updated']) : Time::convert()), + 'xchan_photo_date' => ((array_key_exists('xchan_photo_date', $arr)) ? Time::convert('UTC', 'UTC', $arr['xchan_photo_date']) : NULL_DATE), + 'xchan_name_date' => ((array_key_exists('xchan_name_date', $arr)) ? Time::convert('UTC', 'UTC', $arr['xchan_name_date']) : NULL_DATE), 'xchan_hidden' => ((array_key_exists('xchan_hidden', $arr)) ? intval($arr['xchan_hidden']) : 0), 'xchan_orphan' => ((array_key_exists('xchan_orphan', $arr)) ? intval($arr['xchan_orphan']) : 0), 'xchan_censored' => ((array_key_exists('xchan_censored', $arr)) ? intval($arr['xchan_censored']) : 0), @@ -112,9 +113,9 @@ function xchan_store($arr) } } - $x['xchan_updated'] = datetime_convert(); - $x['xchan_name_date'] = datetime_convert(); - $x['xchan_photo_date'] = datetime_convert(); + $x['xchan_updated'] = Time::convert(); + $x['xchan_name_date'] = Time::convert(); + $x['xchan_photo_date'] = Time::convert(); $x['xchan_system'] = false; $result = xchan_store_lowlevel($x); @@ -126,10 +127,10 @@ function xchan_store($arr) if (in_array($r[0]['network'] , [ 'zot6', 'nomad' ])) { return true; } - if ($r[0]['xchan_photo_date'] < datetime_convert('UTC', 'UTC', $arr['photo_date'])) { + if ($r[0]['xchan_photo_date'] < Time::convert('UTC', 'UTC', $arr['photo_date'])) { $update_photo = true; } - if ($r[0]['xchan_name_date'] < datetime_convert('UTC', 'UTC', $arr['name_date'])) { + if ($r[0]['xchan_name_date'] < Time::convert('UTC', 'UTC', $arr['name_date'])) { $update_name = true; } } @@ -139,8 +140,8 @@ function xchan_store($arr) if ($photos) { $x = q( "update xchan set xchan_updated = '%s', xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc(Time::convert()), + dbesc(Time::convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -152,9 +153,9 @@ function xchan_store($arr) if ($update_name && $arr['name']) { $x = q( "update xchan set xchan_updated = '%s', xchan_name = '%s', xchan_name_date = '%s' where xchan_hash = '%s'", - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc(escape_tags($arr['name'])), - dbesc(datetime_convert()), + dbesc(Time::convert()), dbesc($arr['hash']) ); }