From 194d80c326fe9c2c953dbbe815aa65eb1229b22f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 22 Feb 2017 22:04:56 +0000 Subject: [PATCH 1/5] Bugfix for badly formatted date time string. --- include/dbm.php | 11 +++++++++++ include/socgraph.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/dbm.php b/include/dbm.php index 62ebb1af08..0e12417501 100644 --- a/include/dbm.php +++ b/include/dbm.php @@ -86,5 +86,16 @@ class dbm { public static function esc_array(&$arr, $add_quotation = false) { array_walk($arr, 'self::esc_array_callback', $add_quotation); } + + /** + * Checks Converts any date string into a SQL compatible date string + * + * @param string $date a date string in any format + * @return string SQL style date string + */ + public static function date($date) { + $timestamp = strtotime($date); + return date('Y-m-d H:i:s'); + } } ?> diff --git a/include/socgraph.php b/include/socgraph.php index 32c151c043..f0ce5875ad 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -622,7 +622,7 @@ function poco_last_updated($profile, $force = false) { $last_updated = "0000-00-00 00:00:00"; q("UPDATE `gcontact` SET `updated` = '%s', `last_contact` = '%s' WHERE `nurl` = '%s'", - dbesc($last_updated), dbesc(datetime_convert()), dbesc(normalise_link($profile))); + dbesc(dbm::date($last_updated)), dbesc(datetime_convert()), dbesc(normalise_link($profile))); if (($gcontacts[0]["generation"] == 0)) q("UPDATE `gcontact` SET `generation` = 9 WHERE `nurl` = '%s'", From c84565633ee4cdea437ee220ce018baf24d325e3 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 22 Feb 2017 22:25:35 +0000 Subject: [PATCH 2/5] Added check for invalid "contact-type" --- include/socgraph.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/socgraph.php b/include/socgraph.php index f0ce5875ad..8f6a551d84 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1592,6 +1592,11 @@ function get_gcontact_id($contact) { */ function update_gcontact($contact) { + // Check for invalid "contact-type" value + if (isset($contact['contact-type']) AND (intval($contact['contact-type']) < 0)) { + $contact['contact-type'] = 0; + } + /// @todo update contact table as well $gcontact_id = get_gcontact_id($contact); From ffeae7e04888a3362d951b0100ad6f377a4efbe4 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Feb 2017 05:45:06 +0000 Subject: [PATCH 3/5] Bugfix for bugfix :-) --- include/dbm.php | 4 ++-- include/socgraph.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/dbm.php b/include/dbm.php index 0e12417501..e88f2a4d9d 100644 --- a/include/dbm.php +++ b/include/dbm.php @@ -93,9 +93,9 @@ class dbm { * @param string $date a date string in any format * @return string SQL style date string */ - public static function date($date) { + public static function date($date = 'now') { $timestamp = strtotime($date); - return date('Y-m-d H:i:s'); + return date('Y-m-d H:i:s', $timestamp); } } ?> diff --git a/include/socgraph.php b/include/socgraph.php index 8f6a551d84..a0dd88df2d 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -622,7 +622,7 @@ function poco_last_updated($profile, $force = false) { $last_updated = "0000-00-00 00:00:00"; q("UPDATE `gcontact` SET `updated` = '%s', `last_contact` = '%s' WHERE `nurl` = '%s'", - dbesc(dbm::date($last_updated)), dbesc(datetime_convert()), dbesc(normalise_link($profile))); + dbesc(dbm::date($last_updated)), dbesc(dbm::date()), dbesc(normalise_link($profile))); if (($gcontacts[0]["generation"] == 0)) q("UPDATE `gcontact` SET `generation` = 9 WHERE `nurl` = '%s'", From 06b16cce8b72de01a797568b635cbce650a07a5b Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Feb 2017 07:09:55 +0000 Subject: [PATCH 4/5] Define the lowest possible datetime string as "0001-01-01 00:00:00" --- include/dbm.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/dbm.php b/include/dbm.php index e88f2a4d9d..d28d49d63b 100644 --- a/include/dbm.php +++ b/include/dbm.php @@ -95,6 +95,12 @@ class dbm { */ public static function date($date = 'now') { $timestamp = strtotime($date); + + // Don't allow lower date strings as '0001-01-01 00:00:00' + if ($timestamp < -62135596800) { + $timestamp = -62135596800; + } + return date('Y-m-d H:i:s', $timestamp); } } From ca6171eb5c317f788258611c8580b3694eb31756 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Feb 2017 07:21:47 +0000 Subject: [PATCH 5/5] For 3.5.1 use "0000-00-00 00:00:00" as lowest datetime value --- include/dbm.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/dbm.php b/include/dbm.php index d28d49d63b..fedc2e4fdb 100644 --- a/include/dbm.php +++ b/include/dbm.php @@ -96,11 +96,18 @@ class dbm { public static function date($date = 'now') { $timestamp = strtotime($date); - // Don't allow lower date strings as '0001-01-01 00:00:00' + // Workaround for 3.5.1 if ($timestamp < -62135596800) { - $timestamp = -62135596800; + return '0000-00-00 00:00:00'; } + // The above will be removed in 3.5.2 + // The following will then be enabled + // Don't allow lower date strings as '0001-01-01 00:00:00' + //if ($timestamp < -62135596800) { + // $timestamp = -62135596800; + //} + return date('Y-m-d H:i:s', $timestamp); } }