Beispiel #1
0
 /**
  * Method used to end with
  * a Rss value from
  * an endpoint.
  */
 public static function endWithRSS($_payload, $feed_title = '', $code = 200)
 {
     global $app;
     $plugins = self::getPayload($_payload);
     // retrieve app config
     $app_config = self::getConfig();
     $url = $app_config['client_url'];
     // create a feed
     $feed = new \Suin\RSSWriter\Feed();
     // create a channel
     $channel = new \Suin\RSSWriter\Channel();
     $channel->title($feed_title)->url($url)->language('en-US')->pubDate(time())->lastBuildDate(time())->ttl(60)->appendTo($feed);
     foreach ($plugins->toArray() as $current_plugin) {
         $plugin = Plugin::with('descriptions', 'authors', 'versions', 'screenshots', 'tags', 'langs')->short()->where('key', '=', $current_plugin['key'])->where('active', '=', 1)->first();
         if ($plugin) {
             $plugin = $plugin->toArray();
             // compute date
             $date = $plugin['date_updated'] != "" ? $plugin['date_updated'] : ($plugin['date_added'] != "" ? $plugin['date_added'] : date("Y-m-d"));
             // compute description
             $description = "";
             foreach ($plugin['descriptions'] as $current_desc) {
                 if ($current_desc['lang'] == 'en') {
                     $description = $current_desc['long_description'];
                     break;
                 }
             }
             if (empty($description)) {
                 $description = $plugin['descriptions'][0]['long_description'];
             }
             // find last version (the first in list)
             $version_num = $version_compat = "";
             $last_version = array_shift($plugin['versions']);
             if ($last_version != NULL) {
                 $version_num = $last_version['num'];
                 $version_compat = $last_version['compatibility'];
                 $description .= "<br />\n                                <br /> Version: {$version_num}\n                                <br /> Compatibility: {$version_compat}";
             }
             // add plugin to feed
             $item = new \Suin\RSSWriter\Item();
             $item->title($plugin['name'] . " " . $version_num)->description($description)->contentEncoded($description)->url($url . '/#/plugin/' . $plugin['key'])->pubDate(strtotime($date))->guid($plugin['name'] . "_" . $date . "_" . $version_num, true)->appendTo($channel);
         }
     }
     // render feed
     $app->halt($code, $feed->render());
 }
Beispiel #2
0
    $html = str_get_html($html_str);
    $meta = array('title' => trim($html->find('.people .basic-info h3 a', 0)->plaintext), 'link' => JIANSHU_USERS_ROOT . $id, 'description' => trim($html->find('.people .about .intro', 0)->plaintext));
    $notes = array();
    foreach ($html->find('.recent-post .latest-notes li') as $article) {
        $note = new stdClass();
        $title = $article->find('.title a', 0);
        $note->uri = $title->href;
        $note->title = trim($title->plaintext);
        $notes[] = $note;
    }
    // Notes
    foreach ($notes as $note) {
        fetchNote($note);
    }
    // Feed
    $feed = new \Suin\RSSWriter\Feed();
    $channel = new \Suin\RSSWriter\Channel();
    $channel->title($meta['title'])->url($meta['link'])->description($meta['description'])->appendTo($feed);
    foreach ($notes as $note) {
        $item = new \Suin\RSSWriter\Item();
        $item = $item->title($note->title . ' by ' . $note->author)->url(JIANSHU . $note->uri)->description($note->body)->pubDate(strtotime($note->created))->appendTo($channel);
    }
    $res = $app->response();
    $res->status(200);
    $res->header('Content-Type', 'application/rss+xml; charset=utf-8');
    $res->header('X-Powered-By', 'Slim');
    $res->body($feed->render());
    return $res;
})->name('feeds.users')->conditions(array('id' => '[a-zA-Z0-9]*'));
// Run app
$app->run();