From a55c1d7c2c67eff90f70dc8f0e86b7d241855015 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 2 Oct 2019 20:34:29 +0200 Subject: [PATCH] Add support for XenForo 2.1 --- .../system/exporter/XF2xExporter.class.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/files/lib/system/exporter/XF2xExporter.class.php b/files/lib/system/exporter/XF2xExporter.class.php index 7740bf4..396770e 100644 --- a/files/lib/system/exporter/XF2xExporter.class.php +++ b/files/lib/system/exporter/XF2xExporter.class.php @@ -14,6 +14,7 @@ use wcf\system\request\LinkHandler; use wcf\system\Regex; use wcf\system\WCF; use wcf\util\FileUtil; +use wcf\util\JSON; use wcf\util\MessageUtil; use wcf\util\PasswordUtil; use wcf\util\UserUtil; @@ -302,7 +303,12 @@ class XF2xExporter extends AbstractExporter { 'birthday' => $row['dob_year'].'-'.$row['dob_month'].'-'.$row['dob_day'] ]; - $customFields = unserialize($row['custom_fields']); + try { + $customFields = self::decodeJsonOrSerialized($row['custom_fields']); + } + catch (\Exception $e) { + $customFields = null; + } if ($customFields) { foreach ($customFields as $key => $value) { @@ -419,7 +425,12 @@ class XF2xExporter extends AbstractExporter { $selectOptions = []; if ($row['field_choices']) { - $field_choices = @unserialize($row['field_choices']); + try { + $field_choices = self::decodeJsonOrSerialized($row['field_choices']); + } + catch (\Exception $e) { + $field_choices = null; + } if (!$field_choices) continue; foreach ($field_choices as $key => $value) { $selectOptions[] = $key.':'.$value; @@ -1745,4 +1756,19 @@ class XF2xExporter extends AbstractExporter { return $mentionRegex->replace($message, "\\1"); } + + /** + * Decodes either JSON or deserializes. + * + * @param string $jsonOrSerialized + * @return mixed + */ + private static function decodeJsonOrSerialized($jsonOrSerialized) { + if (strpos($jsonOrSerialized, '{') === 0 || strpos($jsonOrSerialized, '{') === 0) { + return JSON::decode($jsonOrSerialized); + } + else { + return unserialize($jsonOrSerialized); + } + } } -- 2.20.1