Ejemplo n.º 1
0
 public function get()
 {
     $response = $this->http->getResponse('GET', 'http://shortiki.com/export/api.php?format=json&type=random&amount=1');
     if ($response && $response->getStatusCode() === 200 && ($body = $response->getBody())) {
         $body = json_decode($body, true)[0];
         $body = preg_replace('#<br(?: /)?>#', PHP_EOL, $body['content']);
         return $body;
     }
     return null;
 }
Ejemplo n.º 2
0
 public function getBash()
 {
     $response = $this->http->getResponse('GET', 'http://bash.im/forweb/?u');
     if ($response && $response->getStatusCode() === 200 && ($body = $response->getBody())) {
         $body = preg_replace("/'\\s*\\+\\s*'/", '', $body);
         $body = preg_replace('/<br(?:\\s\\/|)>/', "\r\n", $body);
         $body = preg_replace('/^.+1em 0\\;\\">/is', '', $body);
         $body = preg_replace('/<\\/div><small>.+$/is', '', $body);
         return html_entity_decode(trim($body));
     }
     return null;
 }
Ejemplo n.º 3
0
 public function getAnekdot()
 {
     $response = $this->http->getResponse('GET', 'http://www.anekdot.ru/rss/random.html');
     if ($response && $response->getStatusCode() === 200 && ($body = $response->getBody())) {
         $body = preg_replace("/^.+var anekdot_texts = \\['/is", '', $body);
         $body = preg_replace('/<br(?:\\s\\/|)>/', "\r\n", $body);
         $body = preg_replace("/'\\];.+\$/s", '', $body);
         $body = explode("','", $body);
         $body = $body[array_rand($body)];
         return \Util::toUTF(html_entity_decode(trim($body)));
     }
     return null;
 }
Ejemplo n.º 4
0
 public function getTopNews()
 {
     $topNews = [];
     $response = $this->http->getResponse('GET', $this->pluginConfig['url']);
     if ($response && $response->getStatusCode() === 200 && ($body = $response->getBody())) {
         $lines = preg_split('/\\r?\\n/', $body);
         $title = array_shift($lines);
         // csv title
         foreach ($lines as $line) {
             if ($line == '') {
                 continue;
             }
             list($url, $title, $visitors, $delta, $shift, $id) = explode("\t", $line);
             $topNews[] = ['url' => $url, 'title' => $title, 'visitors' => $visitors, 'delta' => $delta, 'shift' => $shift, 'id' => $id];
         }
     }
     return $topNews;
 }