diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2013-09-13 03:01:55 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2013-09-13 03:01:55 +0400 |
commit | aac90cac2c4725a523ab8c2fc0cededcfc470aee (patch) | |
tree | 90cd40ceeba8751e973306c12bb5182a7af496d2 /plugins | |
parent | 4ef16c94c0e958d2b7ca0eb1fb8bcb00949ca270 (diff) |
find plugins and themes by searching or by sorting
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CorePluginsAdmin/Controller.php | 32 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/MarketplaceApiClient.php | 56 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/templates/browsePlugins.twig | 12 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/templates/browseThemes.twig | 14 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/templates/extend.twig | 8 |
5 files changed, 99 insertions, 23 deletions
diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index e5a69e5aa5..0f4ddc6022 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -22,23 +22,39 @@ use Piwik\Url; */ class Controller extends \Piwik\Controller\Admin { + private $validSortMethods = array('popular', 'newest', 'alpha'); + private $defaultSortMethod = 'popular'; - function browsePlugins() + public function browsePlugins() { - $view = $this->configureView('@CorePluginsAdmin/browsePlugins'); + $query = Common::getRequestVar('query', '', 'string', $_POST); + $sort = Common::getRequestVar('sort', $this->defaultSortMethod, 'string'); + if (!in_array($sort, $this->validSortMethods)) { + $sort = $this->defaultSortMethod; + } + + $marketplace = new MarketplaceApiClient(); - $plugins = json_decode(file_get_contents('http://plugins.piwik.org/api/1.0/plugins')); - $view->plugins = $plugins->plugins; + $view = $this->configureView('@CorePluginsAdmin/browsePlugins'); + $view->plugins = $marketplace->searchForPlugins('', $query, $sort); + $view->query = $query; echo $view->render(); } - function browseThemes() + public function browseThemes() { - $view = $this->configureView('@CorePluginsAdmin/browseThemes'); + $query = Common::getRequestVar('query', '', 'string', $_POST); + $sort = Common::getRequestVar('sort', $this->defaultSortMethod, 'string'); + if (!in_array($sort, $this->validSortMethods)) { + $sort = $this->defaultSortMethod; + } + + $marketplace = new MarketplaceApiClient(); - $plugins = json_decode(file_get_contents('http://plugins.piwik.org/api/1.0/themes')); - $view->plugins = $plugins->plugins; + $view = $this->configureView('@CorePluginsAdmin/browseThemes'); + $view->plugins = $marketplace->searchForThemes('', $query, $sort); + $view->query = $query; echo $view->render(); } diff --git a/plugins/CorePluginsAdmin/MarketplaceApiClient.php b/plugins/CorePluginsAdmin/MarketplaceApiClient.php new file mode 100644 index 0000000000..4578a211b3 --- /dev/null +++ b/plugins/CorePluginsAdmin/MarketplaceApiClient.php @@ -0,0 +1,56 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package CorePluginsAdmin + */ +namespace Piwik\Plugins\CorePluginsAdmin; +use Piwik\Http; + +/** + * + * @package CorePluginsAdmin + */ +class MarketplaceApiClient extends \Piwik\Controller\Admin +{ + + private function fetch($method, $params) + { + $endpoint = 'http://plugins.piwik.org/api/1.0/'; + $query = http_build_query($params); + + $url = sprintf('%s%s?%s', $endpoint, $method, $query); + + $result = Http::sendHttpRequest($url, 5); + $result = json_decode($result); + + return $result; + } + + public function searchForPlugins($keywords, $query, $sort) + { + $response = $this->fetch('plugins', array('keywords' => $keywords, 'query' => $query, 'sort' => $sort)); + + if (!empty($response->plugins)) { + return $response->plugins; + } + + return array(); + } + + public function searchForThemes($keywords, $query, $sort) + { + $response = $this->fetch('themes', array('keywords' => $keywords, 'query' => $query, 'sort' => $sort)); + + if (!empty($response->plugins)) { + return $response->plugins; + } + + return array(); + } + +} diff --git a/plugins/CorePluginsAdmin/templates/browsePlugins.twig b/plugins/CorePluginsAdmin/templates/browsePlugins.twig index 5d11cccb8d..8f0b09bc4c 100644 --- a/plugins/CorePluginsAdmin/templates/browsePlugins.twig +++ b/plugins/CorePluginsAdmin/templates/browsePlugins.twig @@ -14,14 +14,16 @@ <h2>Extend Piwik by installing a new plugin</h2> <div> - <input placeholder="Search" type="text" name="q"/> - <button type="submit">Search</button> + <a href="{{ linkTo({'sort': 'popular', 'query': ''}) }}">popular</a> | - <a href="#">popular</a> + <a href="{{ linkTo({'sort': 'newest', 'query': ''}) }}">newest</a> | - <a href="#">newest</a> + <a href="{{ linkTo({'sort': 'alpha', 'query': ''}) }}">alpha</a> | - <a href="#">alpha</a> + <form action="{{ linkTo({'sort': ''}) }}" method="POST" style="display:inline"> + <input value="{{ query }}" placeholder="Search" type="text" name="query"/> + <button type="submit">Search</button> + </form> </div> </div> diff --git a/plugins/CorePluginsAdmin/templates/browseThemes.twig b/plugins/CorePluginsAdmin/templates/browseThemes.twig index 4b57149ac9..b9ad21a1ff 100644 --- a/plugins/CorePluginsAdmin/templates/browseThemes.twig +++ b/plugins/CorePluginsAdmin/templates/browseThemes.twig @@ -13,17 +13,19 @@ <div style="max-width:980px;"> - <h2>Extend Piwik by installing a new plugin</h2> + <h2>Enjoy another look & feel by installing a new theme</h2> <div> - <input placeholder="Search" type="text" name="q"/> - <button type="submit">Search</button> + <a href="{{ linkTo({'sort': 'popular', 'query': ''}) }}">popular</a> | - <a href="#">popular</a> + <a href="{{ linkTo({'sort': 'newest', 'query': ''}) }}">newest</a> | - <a href="#">newest</a> + <a href="{{ linkTo({'sort': 'alpha', 'query': ''}) }}">alpha</a> | - <a href="#">alpha</a> + <form action="{{ linkTo({'sort': ''}) }}" method="POST" style="display:inline"> + <input value="{{ query }}" placeholder="Search" type="text" name="query"/> + <button type="submit">Search</button> + </form> </div> </div> diff --git a/plugins/CorePluginsAdmin/templates/extend.twig b/plugins/CorePluginsAdmin/templates/extend.twig index 5f13b6e4e5..a0e4ed18cb 100644 --- a/plugins/CorePluginsAdmin/templates/extend.twig +++ b/plugins/CorePluginsAdmin/templates/extend.twig @@ -20,10 +20,10 @@ <div style="width:50%;float:left;"> <h3>Get new functionality</h3> - by <a href="{{ linkTo({'action':'browsePlugins'}) }}">installing a new plugin</a> + by <a href="{{ linkTo({'action':'browsePlugins', 'sort': ''}) }}">installing a new plugin</a> <p> - <a href="{{ linkTo({'action':'browsePlugins'}) }}"><img src="" width="250" height="250"/></a> + <a href="{{ linkTo({'action':'browsePlugins', 'sort': ''}) }}"><img src="" width="250" height="250"/></a> </p> <p>or <a href="#">write your own plugin</a></p> @@ -31,10 +31,10 @@ <div style="width:50%;float:left;"> <h3>Enjoy another look & feel</h3> - by <a href="{{ linkTo({'action':'browseThemes'}) }}">installing a new theme</a> + by <a href="{{ linkTo({'action':'browseThemes', 'sort': ''}) }}">installing a new theme</a> <p> - <a href="{{ linkTo({'action':'browseThemes'}) }}"><img src="" width="250" height="250"/></a> + <a href="{{ linkTo({'action':'browseThemes', 'sort': ''}) }}"><img src="" width="250" height="250"/></a> </p> <p>or <a href="#">design your own theme</a></p> |