Beispiel #1
0
<?php

use Illuminate\Database\Capsule\Manager as DB;
use API\Core\Tool;
use API\Model\Plugin;
use API\OAuthServer\OAuthHelper;
$version_plugins = Tool::makeEndpoint(function ($version) {
    OAuthHelper::needsScopes(['version', 'plugins']);
    $plugins = Tool::paginateCollection(Plugin::short()->with('authors', 'versions', 'descriptions')->withAverageNote()->descWithLang(Tool::getRequestLang())->withGlpiVersion($version));
    Tool::endWithJson($plugins);
});
$app->get('/version/:version/plugin', $version_plugins);
$app->options('/version/:version/plugin', function () {
});
Beispiel #2
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 #3
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 #4
0
<?php

/**
 * Search
 *
 * This REST module hooks on
 * following URLs
 *
 * /search
 */
use API\Core\Tool;
use Illuminate\Database\Capsule\Manager as DB;
// Minimal length of search string
$search_min_length = 2;
$search = function () use($app) {
    global $search_min_length, $allowed_languages;
    $body = Tool::getBody();
    if ($body == NULL || !isset($body->query_string) || strlen($body->query_string) < $search_min_length) {
        return Tool::endWithJson(["error" => "Your search string needs to " . "have at least " . $search_min_length . " chars"], 400);
    }
    $query_string = $body->query_string;
    $_search = Tool::paginateCollection(\API\Model\Plugin::short()->with('authors', 'versions', 'descriptions')->withDownloads()->withAverageNote()->descWithLang(Tool::getRequestLang())->where('name', 'LIKE', "%{$query_string}%")->orWhere('plugin_description.short_description', 'LIKE', "%{$query_string}%")->orWhere('plugin_description.long_description', 'LIKE', "%{$query_string}%"));
    Tool::endWithJson($_search);
};
$app->post('/search', $search);
$app->options('/search', function () {
});
Beispiel #5
0
/**
 * 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
 */
$popular = function () use($app) {
    $popular_plugins = Plugin::popularTop(10)->where('active', '=', 1)->get();
    Tool::endWithJson($popular_plugins);
};
/**
 * Trending plugins
 *  most popular the 2 last weeks
 */
$trending = function () use($app) {
    $trending_plugins = Plugin::trendingTop(10)->where('active', '=', 1)->get();
Beispiel #6
0
<?php

/**
 * Search
 *
 * This REST module hooks on
 * following URLs
 *
 * /search
 */
use API\Core\Tool;
use Illuminate\Database\Capsule\Manager as DB;
use API\OAuthServer\OAuthHelper;
// Minimal length of search string
$search_min_length = 2;
$search = Tool::makeEndpoint(function () use($app) {
    OAuthHelper::needsScopes(['plugins:search']);
    global $search_min_length, $allowed_languages;
    $body = Tool::getBody();
    if ($body == NULL || !isset($body->query_string) || strlen($body->query_string) < $search_min_length) {
        Tool::endWithJson(["error" => "Your search string needs to " . "have at least " . $search_min_length . " chars"], 400);
    }
    $query_string = $body->query_string;
    $_search = Tool::paginateCollection(\API\Model\Plugin::short()->with('authors', 'versions', 'descriptions')->withAverageNote()->descWithLang(Tool::getRequestLang())->where('active', '=', true)->where(function ($q) use($query_string) {
        return $q->where('name', 'LIKE', "%{$query_string}%")->orWhere('key', 'LIKE', "%{$query_string}%")->orWhere('plugin_description.short_description', 'LIKE', "%{$query_string}%")->orWhere('plugin_description.long_description', 'LIKE', "%{$query_string}%");
    })->orderBy('download_count', 'DESC')->orderBy('note', 'DESC')->orderBy('name', 'ASC'));
    Tool::endWithJson($_search);
});
$app->post('/search', $search);
$app->options('/search', function () {
});