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
    $all = Tool::paginateCollection(\API\Model\Author::mostActive()->contributorsOnly());
    Tool::endWithJson($all);
};
$top = function () use($app) {
    $top = \API\Model\Author::mostActive(10)->get();
    Tool::endWithJson($top);
};
$single = function ($id) use($app) {
    $single = \API\Model\Author::withPluginCount()->find($id);
    Tool::endWithJson($single);
};
$author_plugins = function ($id) use($app) {
    $author_plugins = \API\Model\Author::find($id);
    if (!$author_plugins) {
        return Tool::endWithJson(["error" => "Cannot find author"]);
    }
    Tool::endWithJson(Tool::paginateCollection(\API\Model\Plugin::with('versions', 'authors')->short()->withDownloads()->withAverageNote()->descWithLang(Tool::getRequestLang())->whereAuthor($author_plugins->id)));
};
// HTTP REST Map
$app->get('/author', $all);
$app->get('/author/top', $top);
$app->get('/author/:id', $single);
$app->get('/author/:id/plugin', $author_plugins);
$app->options('/author', function () {
});
$app->options('/author/top', function () {
});
$app->options('/author/:id', function ($id) {
});
$app->options('/author/:id/plugin', function ($id) {
});
Beispiel #3
0
});
$tag_single = Tool::makeEndpoint(function ($key) use($app) {
    OAuthHelper::needsScopes(['tag']);
    $tag = Tag::where('key', '=', $key)->first();
    if ($tag == NULL) {
        throw new \API\Exception\ResourceNotFound('Tag', $key);
    }
    Tool::endWithJson($tag);
});
$tag_plugins = Tool::makeEndpoint(function ($key) use($app) {
    OAuthHelper::needsScopes(['tag', 'plugins']);
    $tag = Tag::where('key', '=', $key)->first();
    if ($tag == NULL) {
        throw new \API\Exception\ResourceNotFound('Tag', $key);
    }
    $plugins = Tool::paginateCollection(Plugin::with('versions', 'authors')->short()->withAverageNote()->descWithLang(Tool::getRequestLang())->withTag($tag));
    Tool::endWithJson($plugins);
});
// HTTP rest map
$app->get('/tags', $tags_all);
$app->get('/tags/top', $tags_top);
$app->get('/tags/:id/plugin', $tag_plugins);
$app->get('/tags/:id', $tag_single);
$app->options('/tags', function () {
});
$app->options('/tags/top', function () {
});
$app->options('/tags/:id/plugin', function ($id) {
});
$app->options('/tags/:id', function ($id) {
});
Beispiel #4
0
 * /plugin
 * /plugin/popular
 * /plugin/trending
 * /plugin/star
 */
use API\Core\Tool;
use Illuminate\Database\Capsule\Manager as DB;
use API\Model\Plugin;
use API\Model\PluginStar;
use ReCaptcha\ReCaptcha;
use API\Core\ValidableXMLPluginDescription;
/**
 * Fetching infos of a single plugin
 */
$single = function ($key) use($app) {
    $plugin = Plugin::with('descriptions', 'authors', 'versions', 'screenshots', 'tags')->short()->withAverageNote()->withNumberOfVotes()->withCurrentVersion()->withDownloads()->where('key', '=', $key)->where('active', '=', 1)->first();
    if ($plugin) {
        Tool::endWithJson($plugin);
    } else {
        Tool::endWithJson(['error' => 'No plugin has that key'], 400);
    }
};
/**
 * List of all plugins
 */
$all = function () use($app) {
    $plugins = Tool::paginateCollection(Plugin::short()->with('authors', 'versions', 'descriptions')->withDownloads()->withAverageNote()->descWithLang(Tool::getRequestLang())->where('active', '=', 1));
    Tool::endWithJson($plugins);
};
/**
 * Most popular plugins