summaryrefslogtreecommitdiff
path: root/lib/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/extension/admin.php2
-rw-r--r--lib/plugins/extension/helper/extension.php29
-rw-r--r--lib/plugins/extension/helper/gui.php49
-rw-r--r--lib/plugins/extension/helper/repository.php73
4 files changed, 136 insertions, 17 deletions
diff --git a/lib/plugins/extension/admin.php b/lib/plugins/extension/admin.php
index c9f37affb..51d4a8d1d 100644
--- a/lib/plugins/extension/admin.php
+++ b/lib/plugins/extension/admin.php
@@ -48,7 +48,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
// initialize the remote repository
/* @var helper_plugin_extension_repository $repository */
$repository = $this->loadHelper('extension_repository');
- $repository->init();
+
if(!$repository->hasAccess()){
$url = $this->gui->tabURL('', array('purge'=>1));
diff --git a/lib/plugins/extension/helper/extension.php b/lib/plugins/extension/helper/extension.php
index 296b81ac5..53753fcc1 100644
--- a/lib/plugins/extension/helper/extension.php
+++ b/lib/plugins/extension/helper/extension.php
@@ -14,8 +14,9 @@ if(!defined('DOKU_TPLLIB')) define('DOKU_TPLLIB', DOKU_INC.'lib/tpl/');
* Class helper_plugin_extension_extension represents a single extension (plugin or template)
*/
class helper_plugin_extension_extension extends DokuWiki_Plugin {
+ private $id;
private $name;
- private $is_template;
+ private $is_template = false;
private $localInfo;
private $remoteInfo;
private $managerData;
@@ -32,13 +33,18 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
/**
* Set the name of the extension this instance shall represents, triggers loading the local and remote data
*
- * @param string $name The base name of the extension
- * @param bool $is_template If the extension is a template
+ * @param string $id The id of the extension (prefixed with template: for templates)
* @return bool If some (local or remote) data was found
*/
- public function setExtension($name, $is_template) {
- $this->name = $name;
- $this->is_template = $is_template;
+ public function setExtension($id) {
+ $this->id = $id;
+ $this->name = $id;
+
+ if(substr($id, 0 , 9) == 'template'){
+ $this->name = substr($id, 10);
+ $this->is_template = true;
+ }
+
$this->localInfo = array();
$this->managerData = array();
$this->remoteInfo = array();
@@ -129,6 +135,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
}
/**
+ * Get the ID of the extension
+ *
+ * This is the same as getName() for plugins, for templates it's getName() prefixed with 'template:'
+ *
+ * @return string
+ */
+ public function getID() {
+ return $this->id;
+ }
+
+ /**
* Get the name of the installation directory
*
* @return string The name of the installation directory
diff --git a/lib/plugins/extension/helper/gui.php b/lib/plugins/extension/helper/gui.php
index 7c83a3854..cf5b8a347 100644
--- a/lib/plugins/extension/helper/gui.php
+++ b/lib/plugins/extension/helper/gui.php
@@ -16,10 +16,13 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
protected $tabs = array('plugins', 'templates', 'search');
+ /** @var string the extension that should have an open info window FIXME currently broken*/
+ protected $infofor = '';
+
/**
* display the plugin tab
*/
- public function tabPlugins(){
+ public function tabPlugins() {
/* @var Doku_Plugin_Controller $plugin_controller */
global $plugin_controller;
@@ -31,8 +34,8 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
/* @var helper_plugin_extension_list $list */
$list = $this->loadHelper('extension_list');
$list->start_form();
- foreach ($pluginlist as $name) {
- $extension->setExtension($name, false);
+ foreach($pluginlist as $name) {
+ $extension->setExtension($name);
$list->add_row($extension, $name == $this->infoFor);
}
$list->end_form();
@@ -42,7 +45,7 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
/**
* Display the template tab
*/
- public function tabTemplates(){
+ public function tabTemplates() {
echo $this->locale_xhtml('intro_templates');
// FIXME do we have a real way?
@@ -54,8 +57,8 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
/* @var helper_plugin_extension_list $list */
$list = $this->loadHelper('extension_list');
$list->start_form();
- foreach ($tpllist as $name) {
- $extension->setExtension($name, true);
+ foreach($tpllist as $name) {
+ $extension->setExtension("template:$name");
$list->add_row($extension, $name == $this->infoFor);
}
$list->end_form();
@@ -65,8 +68,34 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
/**
* Display the search tab
*/
- public function tabSearch(){
+ public function tabSearch() {
+ global $INPUT;
echo $this->locale_xhtml('intro_search');
+
+ $form = new Doku_Form(array('action' => $this->tabURL('', array(), '&')));
+ $form->addElement(form_makeTextField('q', $INPUT->str('q'), 'Search'));
+ $form->addElement(form_makeButton('submit', '', 'Search'));
+ $form->printForm();
+
+ if(!$INPUT->bool('q')) return;
+
+
+ /* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */
+ $repository = $this->loadHelper('extension_repository');
+ $result = $repository->search($INPUT->str('q'));
+
+ /* @var helper_plugin_extension_extension $extension */
+ $extension = $this->loadHelper('extension_extension');
+ /* @var helper_plugin_extension_list $list */
+ $list = $this->loadHelper('extension_list');
+ $list->start_form();
+ foreach($result as $name) {
+ $extension->setExtension($name);
+ $list->add_row($extension, $name == $this->infoFor);
+ }
+ $list->end_form();
+ $list->render();
+
}
/**
@@ -106,10 +135,10 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
*
* @param string $tab tab to load, empty for current tab
* @param array $params associative array of parameter to set
- *
+ * @param string $sep seperator to build the URL
* @return string
*/
- public function tabURL($tab = '', $params = array()) {
+ public function tabURL($tab = '', $params = array(), $sep = '&') {
global $ID;
if(!$tab) $tab = $this->currentTab();
@@ -118,7 +147,7 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
'page' => 'extension',
'tab' => $tab,
);
- return wl($ID, array_merge($defaults, $params));
+ return wl($ID, array_merge($defaults, $params), false, $sep);
}
}
diff --git a/lib/plugins/extension/helper/repository.php b/lib/plugins/extension/helper/repository.php
index 21082c0d8..98128a9a3 100644
--- a/lib/plugins/extension/helper/repository.php
+++ b/lib/plugins/extension/helper/repository.php
@@ -109,6 +109,79 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
}
return array();
}
+
+ protected function cacheData($name, $data){
+
+ }
+
+ /**
+ * Search for plugins or templates using the given query string
+ *
+ * @param string $q the query string
+ * @return array a list of matching extensions
+ */
+ public function search($q){
+ $query = $this->parse_query($q);
+ $query['fmt'] = 'php';
+
+ $httpclient = new DokuHTTPClient();
+ $data = $httpclient->post(EXTENSION_REPOSITORY_API, $query);
+ if ($data === false) return array();
+ $result = unserialize($data);
+
+ $ids = array();
+
+ // store cache info for each extension
+ foreach($result as $ext){
+ $name = $ext['name'];
+ $cache = new cache('##extension_manager##'.$name, 'repo');
+ $cache->storeCache(serialize($ext));
+ $ids[] = $name;
+ }
+
+ return $ids;
+ }
+
+ /**
+ * Parses special queries from the query string
+ *
+ * @param string $q
+ * @return array
+ */
+ protected function parse_query($q){
+ $parameters = array(
+ 'tag' => array(),
+ 'mail' => array(),
+ 'type' => array()
+ );
+
+ // extract tags
+ if(preg_match_all('/(^|\s)(tag:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
+ foreach($matches as $m){
+ $q = str_replace($m[2], '', $q);
+ $parameters['tag'][] = $m[3];
+ }
+ }
+ // extract author ids
+ if(preg_match_all('/(^|\s)(authorid:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
+ foreach($matches as $m){
+ $q = str_replace($m[2], '', $q);
+ $parameters['mail'][] = $m[3];
+ }
+ }
+ // extract types
+ if(preg_match_all('/(^|\s)(type:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
+ foreach($matches as $m){
+ $q = str_replace($m[2], '', $q);
+ $parameters['type'][] = $m[3];
+ }
+ }
+
+ // FIXME make integer from type value
+
+ $parameters['q'] = trim($q);
+ return $parameters;
+ }
}
// vim:ts=4:sw=4:et: