DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:confsearch

confsearch Plugin

Compatible with DokuWiki

Angua

plugin A plugin that allow you to add a configurable searchbox in any part of the wiki. Very useful to add a search box for the current name space.

Last updated on
2011-11-24
Provides
Syntax
Repository
Source

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to searchform

Tagged with namespace, search, syntax, user

By sermelo

Wiki Version

Tested for Angua version, but it could work for others ones. Please if you tested in another version and it works edit this page to tell us your experience. Thank you

  • Weatherwax - works but seems escaping the @ character is not necessary and breaks the namespace specification. ie @@ns@ only needs to be @ns in the preconfigured usage.

What is this Plugin for?

This is a syntax plugin, that means that allow you to insert a new syntax tag to have a new functionality. In this case the functionality is a configurable search form. It is very useful to specially to have a searchbox for the current namespace. Also you can exclude a name space to the search and more things that you can read here

Installation

Here are the general instructions about how to install a plugin.

But for a manual Installation:

  1. Go to directory: yourwiki/lib/plugins/
  2. Create a directory called confsearch
  3. Go to the new directory, so you must be in yourwiki/lib/plugins/confsearch/
  4. Create a file called syntax.php and copy all the source code, that is at the end of the page, to the file
  5. That's all

Syntax

Add “{confsearch}” To add a simple search form. No parameters are needed, but can be added for preconfigured searches.

For example

{confsearch> search syntax parameters > button name}

In “search syntax parameters” you can add what you wish. All that you write there will be added to the search as is when search button is clicked. There are two patterns abailable: @@NS@ that is the namespace and @USER@ that is the name of the user.

For example if you want to do a search in the namespace of the page:

{confsearch> @@NS@ > Search in @NS@}

The double “@” is because to search in a name space you have to write “ @namespace” to look for in it. To know more about search sintaxis you can go here

Code

I use the code of this plugin as base. So I have to thanks to Adolfo González Blázquez his contribution

If you want to use the repository, it is hosted in github: https://github.com/sermelo/confsearch/

syntax.php
<?php
/**
 * Plugin Search Form: Inserts a search form in any page
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Sergio Merino <sergio.merino@thecorpora.com>
 * @code based on the plugin searchform from Adolfo González Blázquez
 */
 
// must be run within Dokuwiki
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_confsearch extends DokuWiki_Syntax_Plugin {
 
	function getInfo(){
		return array(
			'author' => 'Sergio Merino',
			'email'  => 'sergio.merino@thecorpora.com',
			'date'   => '2011-11-24',
			'name'   => 'Configurable Search Form Plugin',
			'desc'   => 'Inserts a configurable search form in any page',
			'url'    => '',
		);
    }
 
    function getType() { return 'substition'; }
    function getSort() { return 138; }
 
    function connectTo($mode) {
		$this->Lexer->addSpecialPattern('\{confsearch[^\}]*\}',$mode,'plugin_confsearch');
    }
 
    function getLastCrumb()
    {
	$br = breadcrumbs();
	$lastcrumb = '';
	foreach ($br as $a=>$b) $lastcrumb=$a;
	return $lastcrumb;
    }
 
    function getBaseNs($id)
    {
	return getNS(cleanID($id));
    }
 
    function handle($match, $state, $pos, &$handler) {  
    	return array($match, $state, $pos);
    }
 
    function buttonname($data) {
        $params=trim($data[0]," \{\}");
        list($pluginname,$parameters,$button)=split(">",$params,3);
        $replacedparams = str_replace(array(
                '@NS@',
                '@USER@',
                ),
            array(
                $this->getBaseNs($this->getLastCrumb()),
                $_SERVER['REMOTE_USER'],
                ), $button); 
        if ($replacedparams=="")
        	$replacedparams="Search";
        return $replacedparams;
    }
 
    function processparameters($data) {
        $params=trim($data[0]," \{\}");
        list($pluginname,$parameters,$button)=split(">",$params,3);
        $replacedparams = str_replace(array(
                '@NS@',
                '@USER@',
                ),
            array(
                $this->getBaseNs($this->getLastCrumb()),
                $_SERVER['REMOTE_USER'],
                ), $parameters);  
        return $replacedparams;
    }
 
    function render($mode, &$renderer, $data) {
 
 		global $lang;
 
 
		if ($mode == 'xhtml') {
 
			$renderer->doc .= '<div id="searchform_plugin">'."\n";
			$renderer->doc .= '<form name="ns_search" action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search2" method="get"><div class="no">'."\n";
			$renderer->doc .= '<input type="hidden" name="do" value="search" />'."\n";
			$renderer->doc .= '<input type="hidden" id="dw__ns" name="ns" value="'.$this->processparameters($data).'">'."\n";
//Debug line			$renderer->doc .= 'Debug--'.$this->processparameters($data);
                        $renderer->doc .= '<input type="text" id="qsearch2__in" accesskey="f" name="id" class="edit" autocomplete="off">'."\n";
                        $renderer->doc .= '<input type="submit" value="'.$this->buttonname($data).'" class="button" title="Search App" onclick= "document.ns_search.id.value= document.ns_search.id.value+\' \'+document.ns_search.ns.value" />'."\n";
 
                        $renderer->doc .= '<div id="qsearch2__out" class="ajax_qsearch JSpopup"></div>'."\n";
			$renderer->doc .= '</div></form>'."\n";
			$renderer->doc .= '</div>'."\n";
			return true;
		}
		else{
			$renderer->doc .= 'Hola';
		}
		return false;
	}
}
?>
plugin/confsearch.txt · Last modified: 2015-11-28 21:27 by Aleksandr