aboutsummaryrefslogtreecommitdiff
path: root/bridges/CuriousCatBridge.php
diff options
context:
space:
mode:
Diffstat (limited to 'bridges/CuriousCatBridge.php')
-rw-r--r--bridges/CuriousCatBridge.php158
1 files changed, 80 insertions, 78 deletions
diff --git a/bridges/CuriousCatBridge.php b/bridges/CuriousCatBridge.php
index 641da5d8..573c776f 100644
--- a/bridges/CuriousCatBridge.php
+++ b/bridges/CuriousCatBridge.php
@@ -1,108 +1,110 @@
<?php
-class CuriousCatBridge extends BridgeAbstract {
- const NAME = 'Curious Cat Bridge';
- const URI = 'https://curiouscat.me';
- const DESCRIPTION = 'Returns list of newest questions and answers for a user profile';
- const MAINTAINER = 'VerifiedJoseph';
- const PARAMETERS = array(array(
- 'username' => array(
- 'name' => 'Username',
- 'type' => 'text',
- 'required' => true,
- 'exampleValue' => 'koethekoethe',
- )
- ));
- const CACHE_TIMEOUT = 3600;
+class CuriousCatBridge extends BridgeAbstract
+{
+ const NAME = 'Curious Cat Bridge';
+ const URI = 'https://curiouscat.me';
+ const DESCRIPTION = 'Returns list of newest questions and answers for a user profile';
+ const MAINTAINER = 'VerifiedJoseph';
+ const PARAMETERS = [[
+ 'username' => [
+ 'name' => 'Username',
+ 'type' => 'text',
+ 'required' => true,
+ 'exampleValue' => 'koethekoethe',
+ ]
+ ]];
- public function collectData() {
+ const CACHE_TIMEOUT = 3600;
- $url = self::URI . '/api/v2/profile?username=' . urlencode($this->getInput('username'));
+ public function collectData()
+ {
+ $url = self::URI . '/api/v2/profile?username=' . urlencode($this->getInput('username'));
- $apiJson = getContents($url);
+ $apiJson = getContents($url);
- $apiData = json_decode($apiJson, true);
+ $apiData = json_decode($apiJson, true);
- foreach($apiData['posts'] as $post) {
- $item = array();
+ foreach ($apiData['posts'] as $post) {
+ $item = [];
- $item['author'] = 'Anonymous';
+ $item['author'] = 'Anonymous';
- if ($post['senderData']['id'] !== false) {
- $item['author'] = $post['senderData']['username'];
- }
+ if ($post['senderData']['id'] !== false) {
+ $item['author'] = $post['senderData']['username'];
+ }
- $item['uri'] = $this->getURI() . '/post/' . $post['id'];
- $item['title'] = $this->ellipsisTitle($post['comment']);
+ $item['uri'] = $this->getURI() . '/post/' . $post['id'];
+ $item['title'] = $this->ellipsisTitle($post['comment']);
- $item['content'] = $this->processContent($post);
- $item['timestamp'] = $post['timestamp'];
+ $item['content'] = $this->processContent($post);
+ $item['timestamp'] = $post['timestamp'];
- $this->items[] = $item;
- }
- }
+ $this->items[] = $item;
+ }
+ }
- public function getURI() {
+ public function getURI()
+ {
+ if (!is_null($this->getInput('username'))) {
+ return self::URI . '/' . $this->getInput('username');
+ }
- if (!is_null($this->getInput('username'))) {
- return self::URI . '/' . $this->getInput('username');
- }
+ return parent::getURI();
+ }
- return parent::getURI();
- }
+ public function getName()
+ {
+ if (!is_null($this->getInput('username'))) {
+ return $this->getInput('username') . ' - Curious Cat';
+ }
- public function getName() {
+ return parent::getName();
+ }
- if (!is_null($this->getInput('username'))) {
- return $this->getInput('username') . ' - Curious Cat';
- }
+ private function processContent($post)
+ {
+ $author = 'Anonymous';
- return parent::getName();
- }
+ if ($post['senderData']['id'] !== false) {
+ $authorUrl = self::URI . '/' . $post['senderData']['username'];
- private function processContent($post) {
-
- $author = 'Anonymous';
-
- if ($post['senderData']['id'] !== false) {
- $authorUrl = self::URI . '/' . $post['senderData']['username'];
-
- $author = <<<EOD
+ $author = <<<EOD
<a href="{$authorUrl}">{$post['senderData']['username']}</a>
EOD;
- }
+ }
- $question = $this->formatUrls($post['comment']);
- $answer = $this->formatUrls($post['reply']);
+ $question = $this->formatUrls($post['comment']);
+ $answer = $this->formatUrls($post['reply']);
- $content = <<<EOD
+ $content = <<<EOD
<p>{$author} asked:</p>
<blockquote>{$question}</blockquote><br/>
<p>{$post['addresseeData']['username']} answered:</p>
<blockquote>{$answer}</blockquote>
EOD;
- return $content;
- }
-
- private function ellipsisTitle($text) {
- $length = 150;
-
- if (strlen($text) > $length) {
- $text = explode('<br>', wordwrap($text, $length, '<br>'));
- return $text[0] . '...';
- }
-
- return $text;
- }
-
- private function formatUrls($content) {
-
- return preg_replace(
- '/(http[s]{0,1}\:\/\/[a-zA-Z0-9.\/\?\&=\-_]{4,})/ims',
- '<a target="_blank" href="$1" target="_blank">$1</a> ',
- $content
- );
-
- }
+ return $content;
+ }
+
+ private function ellipsisTitle($text)
+ {
+ $length = 150;
+
+ if (strlen($text) > $length) {
+ $text = explode('<br>', wordwrap($text, $length, '<br>'));
+ return $text[0] . '...';
+ }
+
+ return $text;
+ }
+
+ private function formatUrls($content)
+ {
+ return preg_replace(
+ '/(http[s]{0,1}\:\/\/[a-zA-Z0-9.\/\?\&=\-_]{4,})/ims',
+ '<a target="_blank" href="$1" target="_blank">$1</a> ',
+ $content
+ );
+ }
}