Example #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;
 }
Example #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;
 }