Not logged in. · Lost password · Register
Forum: General Help and Support Development RSS
[SOLVED] Question about the SEARCH_RESULT_FULLPAGE-hook
Avatar
cziehr #1
Member since Jan 2011 · 577 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
Subject: [SOLVED] Question about the SEARCH_RESULT_FULLPAGE-hook
Hello everyone,

I try to create a plugin which shows an icon in front of a search result, if the page is in a certain namespace. Until now, I hacked the dokuwiki-core to achieve this, but with the upgrade to Greebo my hack doesn't work any more, so I decided to write a plugin. I've written a small plugin two years ago and have a bit experience with the basics of plugin programming, but I'm really no expert.

As a first step, I tried to simply show the text TEST in front of every search result, and implement the condition if the page is in a given namespace after this works. But I'm not able to get even this functionality running. Maybe someone has a clue for me what I did wrong?

Here is the code of my action.php I've got so far. I created a plugin skeleton with the wizard, but since this is the only file where I've changed something I guess the other files are not necessary to lead me to the right way. If they are, you can find the whole (not working) plugin at github: https://github.com/cziehr/dokuwiki-plugin-nsiconinsearch

<?php
if (!defined('DOKU_INC')) {
    die();
}

class action_plugin_nsiconinsearch extends DokuWiki_Action_Plugin
{

    public function register(Doku_Event_Handler $controller)
    {
        $controller->register_hook('SEARCH_RESULT_FULLPAGE', 'BEFORE', $this, 'handle_search_result_fullpage');
  
    }

    public function handle_search_result_fullpage(Doku_Event $event, $param)
    {

        $event->data['resultHeader'][] = '<p>TEST</p>';

    }

}

Thanks,
Christoph
This post was edited 2 times, last on 2018-12-17, 17:39 by cziehr.
Edit reason: Changed code with advise from Myron from the second post
Avatar
turnermm (Moderator) #2
Member since Oct 2009 · 4642 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
I think you want
$event->data['resultHeader'][] = '<p>TEST</p>';
Not   $event->$data
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
cziehr #3
Member since Jan 2011 · 577 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
Thanks for your reply, Myron. You are right that the $ is not correct in this place.

But after I deletet the $, it still doesn't work, there is no TEST displayed in my search results. I'm not sure if I implemented the code for the SEARCH_RESULT_FULLPAGE-hook correctly. Does anybody has another idea what could be wrong in my code?

EDIT: I took a look at the watchcycle-plugin, which does something similar to the plugin I want to create. What I don't understand: I believe I use nearly the same code as the watchcycle-plugin does as can be seen at the bottom of this file: https://github.com/cosmocode/dokuwiki-plugin-watchcycle/bl… - but in contrast to this plugin, my plugin doesn't work.

I tried also if my way works on the SEARCH_RESULT_PAGELOOKUP-hook, which is used for search results when the search term is found in the page name - but this also doesn't work. My code is now:

<?php

if (!defined('DOKU_INC')) {
    die();
}

class action_plugin_nsiconinsearch extends DokuWiki_Action_Plugin
{

    public function register(Doku_Event_Handler $controller)
    {
        $controller->register_hook('SEARCH_RESULT_PAGELOOKUP', 'BEFORE', $this, 'handle_search_result_pagelookup');
        $controller->register_hook('SEARCH_RESULT_FULLPAGE', 'BEFORE', $this, 'handle_search_result_fullpage');
    }

    public function handle_search_result_pagelookup(Doku_Event $event, $param)
    {
        $icon = "<p>TEST</p>";
        $event->data['listItemContent'][] = $icon;
    }

    public function handle_search_result_fullpage(Doku_Event $event, $param)
    {
        $icon = "<p>TEST</p>";
        $event->data['resultHeader'][] = $icon;
    }
}

I've no clue what I can do now.
This post was edited 2 times, last on 2018-12-09, 20:56 by cziehr.
Avatar
turnermm (Moderator) #4
Member since Oct 2009 · 4642 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
This works for me.

<?php

if (!defined('DOKU_INC')) {
    die();
}

<?php
/* file: lib/plugins/fsearch/action.php */
class action_plugin_fsearch extends DokuWiki_Action_Plugin
{

    public function register(Doku_Event_Handler $controller)
    {  
         $controller->register_hook('SEARCH_RESULT_FULLPAGE', 'BEFORE', $this, 'fullpage',array());
    }

    public function fullpage(Doku_Event $event, $param)
    {
        $icon = "<p>TEST</p>";
        $event->data['resultHeader'][] = $icon;  
   //   $this->write_debug($event);
    }
   
    function write_debug($data) {
        $text = print_r($data,1); 
        $handle = fopen(DOKU_INC ."/fsearch.txt", "a");
   
     fwrite($handle,"$text\n");
     fclose($handle);
 
    }
}
If you uncomment
  //   $this->write_debug($event);
you should get a debugging output to the root dowkuwiki directory--as long as it is writable by the web server.  If not, then you have a mis-configuration somewhere.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
cziehr #5
Member since Jan 2011 · 577 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
Thank you very much for your help!

The plugin is finished and works very well. I've created a page for the plugin at https://www.dokuwiki.org/plugin:nsiconinsearch

First I did not understand what was wrong with my code at the beginning, but then I realized the reason must be that I stored the directory for the plugin development seperatly, and not directly in the webserver path, and put a symlink from the directory to the webserver path.

But anyway, everything works fine now. Thanks again.
Avatar
turnermm (Moderator) #6
Member since Oct 2009 · 4642 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
 :-)
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-06-17, 21:05:50 (UTC +02:00)