Пример #1
0
 public function getPostPage(APIClient $client)
 {
     $posts = $client->retrieveRecentPosts(200);
     $topPosts = array();
     foreach ($posts as $p) {
         // Calculate value: replies * 20 + reposts * 15 + stars * 10
         $value = $p->get('num_replies') * 20 + $p->get('num_reposts') * 15 + $p->get('num_stars') * 10;
         // Must be at least 10 to be considered
         if ($value < 10) {
             continue;
         }
         $p->setMetaField('topposts.value', $value);
         $p->setMetaField('topposts.temperature', round(35 + $value * 0.05, 1) . "°C");
         $topPosts[] = $p;
     }
     usort($topPosts, function ($a, $b) {
         return $b->getMetaField('topposts.value') - $a->getMetaField('topposts.value');
     });
     // Use only top 10 posts
     $top10Posts = new PostPage();
     for ($i = 1; $i <= 10; $i++) {
         if (isset($topPosts[$i])) {
             $top10Posts->add($topPosts[$i]);
         }
     }
     return $top10Posts;
 }
Пример #2
0
 public function getPostPage(APIClient $client)
 {
     $posts = $client->retrievePostsWithHashtag('adnblog');
     $longposts = new PostPage();
     foreach ($posts as $p) {
         if ($p->hasAnnotation(LongpostsPlugin::ANNOTATION_TYPE)) {
             $longposts->add($p);
         }
     }
     return $longposts;
 }
Пример #3
0
 public static function handleWebmention(Request $r, $domain, APIClient $client)
 {
     $source = $r->request->get('source');
     $target = $r->request->get('target');
     if (!isset($source) || !isset($target)) {
         return new Response('source and target parameters required.', 400);
     }
     if (strpos($target, $domain) === false) {
         return new Response('Webmention endpoint not reponsible for target.', 400);
     }
     try {
         $externalPost = Parser::parse($source, $target);
     } catch (\Exception $e) {
         return new Response('Exception caught: ' . $e->getMessage(), 500);
     }
     $text = 'Received a ' . $externalPost->getType() . ' from ' . $externalPost->getAuthorName() . '.';
     $post = array('text' => $text, 'reply_to' => (int) substr($target, strrpos($target, '/') + 1), 'entities' => array('links' => array(array('pos' => 0, 'len' => strlen($text), 'url' => $source))), 'annotations' => array(array('type' => 'net.app.core.crosspost', 'value' => array('canonical_url' => $source)), array('type' => 'com.indiewebcamp.webmentions-reaction', 'value' => array('author' => $externalPost->getAuthorName(), 'type' => $externalPost->getType()))));
     $client->createPost($post);
     return new Response('', 202);
 }