From 9b075f4ac890918daead0cfeaab49b5230da8bf9 Mon Sep 17 00:00:00 2001 From: Tobias Duehr Date: Wed, 29 Apr 2020 12:50:44 +0200 Subject: [PATCH] More generic author handling --- src/Resources/contao/Author.php | 85 +++++++++++++++++++++++++++++ src/Resources/contao/ContaoJson.php | 9 +-- 2 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 src/Resources/contao/Author.php diff --git a/src/Resources/contao/Author.php b/src/Resources/contao/Author.php new file mode 100644 index 0000000..ae137e0 --- /dev/null +++ b/src/Resources/contao/Author.php @@ -0,0 +1,85 @@ +model = UserModel::findById($id, ['disable'], ['']); + if (!$this->model) $this->model = null; + } + + public function toJson(): ContaoJson + { + if (!$this->model) { + return parent::toJson(); + } + $author = $this->model->row(); + unset($author['id']); + unset($author['tstamp']); + unset($author['backendTheme']); + unset($author['themes']); + unset($author['imageSizes']); + unset($author['fullscreen']); + unset($author['uploader']); + unset($author['showHelp']); + unset($author['thumbnails']); + unset($author['useRTE']); + unset($author['useCE']); + unset($author['password']); + unset($author['pwChange']); + unset($author['admin']); + unset($author['groups']); + unset($author['inherit']); + unset($author['modules']); + unset($author['pagemounts']); + unset($author['alpty']); + unset($author['filemounts']); + unset($author['fop']); + unset($author['forms']); + unset($author['formp']); + unset($author['amg']); + unset($author['disable']); + unset($author['start']); + unset($author['stop']); + unset($author['session']); + unset($author['new_records']); + unset($author['tl_page_tree']); + unset($author['tl_page_node']); + unset($author['fieldset_states']); + unset($author['tl_image_size']); + unset($author['tl_page']); + unset($author['tl_user']); + unset($author['tl_settings']); + unset($author['tl_news_archive']); + unset($author['tl_article_tl_page_tree']); + unset($author['filetree']); + unset($author['dateAdded']); + unset($author['secret']); + unset($author['useTwoFactor']); + unset($author['lastLogin']); + unset($author['currentLogin']); + unset($author['locked']); + unset($author['news']); + unset($author['newp']); + unset($author['newsfeeds']); + unset($author['newsfeedp']); + unset($author['trustedTokenVersion']); + unset($author['backupCodes']); + unset($author['loginAttempts']); + unset($author['fields']); + unset($author['elements']); + return new ContaoJson($author); + } +} diff --git a/src/Resources/contao/ContaoJson.php b/src/Resources/contao/ContaoJson.php index 6e34f5d..c671435 100644 --- a/src/Resources/contao/ContaoJson.php +++ b/src/Resources/contao/ContaoJson.php @@ -6,7 +6,6 @@ use Contao\Model; use Contao\Controller; use Contao\StringUtil; -use Contao\UserModel; /** * ContaoJson tries to pack "everything Contao" into a JSON-serializable package. @@ -118,13 +117,7 @@ private function handleObject(object $object) $data->{$key} = (new File($src, $object->size ?? null))->toJson(); } } else if ($key == 'author' && is_numeric($value)) { - $userModel = UserModel::findById($value); - $author = (object) [ - 'id' => $userModel->id, - 'name' => $userModel->name, - 'singleSRC' => $userModel->singleSRC - ]; - $data->{$key} = new ContaoJson($author); + $data->{$key} = (new Author($value))->toJson(); } else { $data->{$key} = new self($value); }