From 556f0b42370b85918968d0d6a7a86047103608b4 Mon Sep 17 00:00:00 2001 From: KamaleiZestri <38802353+KamaleiZestri@users.noreply.github.com> Date: Fri, 24 Jun 2022 04:59:24 -0500 Subject: [PATCH] [NewgroundsBridge] Add Bridge (#2849) --- bridges/NewgroundsBridge.php | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 bridges/NewgroundsBridge.php diff --git a/bridges/NewgroundsBridge.php b/bridges/NewgroundsBridge.php new file mode 100644 index 00000000..f84ad8c0 --- /dev/null +++ b/bridges/NewgroundsBridge.php @@ -0,0 +1,80 @@ + [ + 'username' => [ + 'name' => 'Username', + 'type' => 'text', + 'required' => true, + 'exampleValue' => 'TomFulp' + ] + ] + ]; + + public function collectData() + { + $username = $this->getInput('username'); + if (!preg_match('/^\w+$/', $username)) { + throw new \Exception('Illegal username'); + } + + $html = getSimpleHTMLDOM($this->getURI()); + + $posts = $html->find('.item-portalitem-art-medium'); + + foreach ($posts as $post) { + $item = []; + + $item['author'] = $username; + $item['uri'] = $post->href; + + $titleOrRestricted = $post->find('h4')[0]->innertext; + + // Newgrounds doesn't show public previews for NSFW content. + if ($titleOrRestricted === 'Restricted Content: Sign in to view!') { + $item['title'] = 'NSFW: ' . $item['uri']; + $item['content'] = << +{$item['title']} + +EOD; + } else { + $item['title'] = $titleOrRestricted; + $item['content'] = << +{$item['title']} + +EOD; + } + + $this->items[] = $item; + } + } + + public function getName() + { + if ($this->getInput('username')) { + return sprintf('%s - %s', $this->getInput('username'), self::NAME); + } + return parent::getName(); + } + + public function getURI() + { + if ($this->getInput('username')) { + return sprintf('https://%s.newgrounds.com/art', $this->getInput('username')); + } + return parent::getURI(); + } +}