Permalink
Browse files

fit codes to my current coding standard

  • Loading branch information...
kazmiya committed Dec 8, 2010
1 parent b80c9dd commit 08ff1a8209a9b8a5ce39d93d15cddc3d606fcbf8
Showing with 123 additions and 64 deletions.
  1. +0 −10 README
  2. +17 −0 README.rst
  3. +91 −43 action.php
  4. +2 −2 conf/default.php
  5. +7 −3 conf/metadata.php
  6. +2 −2 lang/en/settings.php
  7. +2 −2 lang/ja/settings.php
  8. +2 −2 plugin.info.txt
View
10 README

This file was deleted.

Oops, something went wrong.
View
@@ -0,0 +1,17 @@
================================
No Highlight Plugin for DokuWiki
================================
Disables search term highlightings.
Documentation
http://www.dokuwiki.org/plugin:nohighlight
Download URL for the Plugin Manager
http://github.com/kazmiya/dokuwiki-plugin-nohighlight/zipball/master
Compatible with DokuWiki 2009-12-25 "Lemming" or later.
See COPYING for license info.
Copyright (c) 2010 Kazutaka Miyasaka <kazmiya@gmail.com>
View
@@ -1,18 +1,24 @@
<?php
/**
* DokuWiki Plugin No Highlight
* NoHighlight Plugin for DokuWiki / action.php
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@gmail.com>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@gmail.com>
*/
// must be run within DokuWiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
if (!defined('DOKU_INC')) {
die();
}
if (!defined('DOKU_PLUGIN')) {
define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
}
require_once(DOKU_PLUGIN.'action.php');
require_once DOKU_PLUGIN . 'action.php';
class action_plugin_nohighlight extends DokuWiki_Action_Plugin {
class action_plugin_nohighlight extends DokuWiki_Action_Plugin
{
/**
* Stores original array of highlight candidates
*/
@@ -27,37 +33,61 @@ class action_plugin_nohighlight extends DokuWiki_Action_Plugin {
/**
* Registers event handlers
*/
function register(&$controller) {
$controller->register_hook('DOKUWIKI_STARTED',
'BEFORE', $this, 'disableHighlight', array());
$controller->register_hook('DOKUWIKI_STARTED',
'AFTER', $this, 'removeUrlParams', array('do' => 'get'));
$controller->register_hook('SEARCH_QUERY_FULLPAGE',
'AFTER', $this, 'removeUrlParams', array('do' => 'modify'));
$controller->register_hook('FULLTEXT_SNIPPET_CREATE',
'BEFORE', $this, 'removeUrlParams', array('do' => 'restore'));
function register(&$controller)
{
$controller->register_hook(
'DOKUWIKI_STARTED', 'BEFORE',
$this, 'disableHighlight', array()
);
$controller->register_hook(
'DOKUWIKI_STARTED', 'AFTER',
$this, 'removeUrlParams', array('do' => 'get')
);
$controller->register_hook(
'SEARCH_QUERY_FULLPAGE', 'AFTER',
$this, 'removeUrlParams', array('do' => 'modify')
);
$controller->register_hook(
'FULLTEXT_SNIPPET_CREATE', 'BEFORE',
$this, 'removeUrlParams', array('do' => 'restore')
);
}
/**
* Disables search term highlighting
*/
function disableHighlight(&$event, $param) {
function disableHighlight(&$event, $param)
{
global $HIGH;
global $ACT;
if ($ACT !== 'show' && $ACT !== 'search') return;
if ($ACT !== 'show' && $ACT !== 'search') {
return;
}
$this->setConfig();
switch ($this->disable_highlight) {
case 'none':
return;
case 'all': // disable all highlighting features
// disable all highlighting features
case 'all':
$HIGH = '';
break;
case 'query': // disable highlighting by URL param ?s[]=term
if (!empty($_REQUEST['s'])) $HIGH = '';
// disable highlighting by URL param ?s[]=term
case 'query':
if (!empty($_REQUEST['s'])) {
$HIGH = '';
}
break;
case 'auto': // disable auto-highlight via search engines
// disable auto-highlight via search engines
case 'auto':
$HIGH = isset($_REQUEST['s']) ? (string) $_REQUEST['s'] : '';
break;
}
@@ -66,7 +96,8 @@ function disableHighlight(&$event, $param) {
/**
* Sets per-user or site-wide configurations
*/
function setConfig() {
function setConfig()
{
@session_start();
if (isset($_REQUEST['nohighlight'])) {
@@ -89,18 +120,23 @@ function setConfig() {
}
/**
* Manipulates highlight candidates to remove ?s[]=term from search result URLs
* Manipulates highlight terms to remove ?s[]=term from search result URLs
*/
function removeUrlParams(&$event, $param) {
if (!$this->remove_url_params) return;
function removeUrlParams(&$event, $param)
{
if (!$this->remove_url_params) {
return;
}
switch ($param['do']) {
case 'get':
$this->getCandidatesFromReferer();
break;
case 'modify':
$this->modifyCandidates($event->data['highlight']);
break;
case 'restore':
$this->restoreCandidates($event->data['highlight']);
break;
@@ -109,36 +145,47 @@ function removeUrlParams(&$event, $param) {
/**
* Gets highlight candidates from HTTP_REFERER info
* (A compensation for "remove_url_paarams" option)
* (A compensation for "remove_url_params" option)
*/
function getCandidatesFromReferer() {
function getCandidatesFromReferer()
{
global $HIGH;
global $ACT;
if ($ACT !== 'show') return;
if (!empty($HIGH)) return;
if (!isset($_SERVER['HTTP_REFERER'])) return;
if (in_array($this->disable_highlight, array('all', 'auto'))) return;
if (
$ACT !== 'show' ||
!empty($HIGH) ||
!isset($_SERVER['HTTP_REFERER']) ||
in_array($this->disable_highlight, array('all', 'auto'))
) {
return;
}
$referer = (string) $_SERVER['HTTP_REFERER'];
if (!preg_match('/^'.preg_quote(DOKU_URL, '/').'.*[?&]do=search/', $referer)) return;
if (!preg_match('/[?&]id=([^&]+)/', $referer, $matches)) return;
// users seem to have jumped from search result link in this wiki
require_once(DOKU_INC.'inc/fulltext.php');
$parsed_query = ft_queryParser(urldecode($matches[1]));
if (
strpos($referer, DOKU_URL) === 0 &&
preg_match('/[?&]do=search&id=([^&]+)/', $referer, $matches)
) {
// users seem to have jumped from search result link in this wiki
require_once DOKU_INC . 'inc/fulltext.php';
// set highlight candidates
$HIGH = $parsed_query['highlight'];
// set highlight candidates
$parsed_query = ft_queryParser(urldecode($matches[1]));
$HIGH = $parsed_query['highlight'];
}
}
/**
* Modifies highlight candidates
*/
function modifyCandidates(&$highlight) {
function modifyCandidates(&$highlight)
{
$functions = array();
$traces = debug_backtrace();
foreach ($traces as $trace) $functions[] = $trace['function'];
foreach (debug_backtrace() as $trace) {
$functions[] = $trace['function'];
}
// hack if called via html_search()
if (in_array('html_search', $functions)) {
@@ -152,7 +199,8 @@ function modifyCandidates(&$highlight) {
/**
* Restores highlight candidates
*/
function restoreCandidates(&$highlight) {
function restoreCandidates(&$highlight)
{
// snippet creation with no highlight term causes heavy load
if (!empty($this->highlight_orig)) {
$highlight = $this->highlight_orig;
View
@@ -2,8 +2,8 @@
/**
* Default configuration for nohighlight plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@affrc.go.jp>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@affrc.go.jp>
*/
$conf['disable_highlight'] = 'all';
View
@@ -2,9 +2,13 @@
/**
* Configuration metadata for nohighlight plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@affrc.go.jp>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@affrc.go.jp>
*/
$meta['disable_highlight'] = array('multichoice', '_choices' => array('all', 'query', 'auto', 'none'));
$meta['disable_highlight'] = array(
'multichoice',
'_choices' => array('all', 'query', 'auto', 'none')
);
$meta['remove_url_params'] = array('onoff');
View
@@ -2,8 +2,8 @@
/**
* English language file for nohighlight plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@gmail.com>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@gmail.com>
*/
$lang['disable_highlight'] = 'Disable search term highlighting features in a wiki page';
View
@@ -2,8 +2,8 @@
/**
* Japanese language file for nohighlight plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@gmail.com>
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Kazutaka Miyasaka <kazmiya@gmail.com>
*/
$lang['disable_highlight'] = 'Wiki ページ上での検索ワードのハイライト機能を無効化する';
View
@@ -1,7 +1,7 @@
base nohighlight
author Kazutaka Miyasaka
email kazmiya@gmail.com
date 2010-01-23
date 2010-12-08
name No Highlight Plugin
desc Disables search term highlighting features
desc Disables search term highlightings
url http://www.dokuwiki.org/plugin:nohighlight

0 comments on commit 08ff1a8

Please sign in to comment.