Install a new plugin (management -> ... -> plugins)

To discuss the technical development of the Open Monograph Press.

Moderators: jmacgreg, John

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.
carola
Posts: 93
Joined: Mon Jun 09, 2014 10:07 pm

Install a new plugin (management -> ... -> plugins)

Postby carola » Sun Jun 15, 2014 11:17 pm

Hi,

what does the installation routine in management -> settings -> website -> plugin do?

I tested it for a plugin that only needs one folder in plugins/blocks and it worked fine. But now I have a plugin analogous to the information block plugin with entries in pages, lib/pkp/templates, pkp/locale and locale, including entries in preexisting files. Is it also possible to install such a plugin? Or do I have to change the structure of the files so that all code needed is in one folder that is copies to plugins/blocks?

best,
Carola

JasonNugent
Site Admin
Posts: 910
Joined: Tue Jan 10, 2006 6:20 am

Re: Install a new plugin (management -> ... -> plugins)

Postby JasonNugent » Mon Jun 16, 2014 7:34 am

Hi Carola,

Plugins are meant to exist inside a single directory, as a sub folder of the category in plugins/ they belong to. The way you get them to work with other pages in other places is through 'hooks' that the plugin needs to hook against. These are usually in 'generic' category plugins. The installation process takes a zip file, lets you upload it, and places it inside a single directory. It won't install files in multiple places.

regards,
Jason

carola
Posts: 93
Joined: Mon Jun 09, 2014 10:07 pm

Re: Install a new plugin (management -> ... -> plugins)

Postby carola » Mon Jun 16, 2014 12:59 pm

Thank you!

Are there any plugins (using hooks) for omp-1.1.0 I can download, install and inspect? In the galery, there only seem to be plugins for OJS.

best,
Carola

asmecher
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm
Contact:

Re: Install a new plugin (management -> ... -> plugins)

Postby asmecher » Mon Jun 16, 2014 1:52 pm

Hi Carola,

As far as I'm aware, there are no third-party plugins for OMP yet. It's a young application compared to OJS. The built-in plugins should serve as useful examples.

Regards,
Alec Smecher
Public Knowledge Project Team

carola
Posts: 93
Joined: Mon Jun 09, 2014 10:07 pm

Re: Install a new plugin (management -> ... -> plugins)

Postby carola » Tue Jun 17, 2014 6:14 pm

Hi,

is there a hook list for OMP? I only found one for OJS. Does the LoadHandler-hook work for OMP? When I tested it, the callback was never run, so now I use Template::Common::Sidebar.

And in the callback function, how can I change where to look for the pages? For instance, how can I make sure that the index.php in the plugin directory is called and not omp/pages/pluginname/index.php?

I tried

Code: Select all

$this->import('pages.newPlugin.NewPluginHandler');


but still omp/pages/pluginname/index.php is run.

best,
Carola

JasonNugent
Site Admin
Posts: 910
Joined: Tue Jan 10, 2006 6:20 am

Re: Install a new plugin (management -> ... -> plugins)

Postby JasonNugent » Wed Jun 18, 2014 6:10 am

Hi Carola,

There is no written list of plugin hooks for OMP yet, and even the OJS one is out of date. The best source for information is the codebase itself. You can search for 'HookRegistry' in the code to find the places where hooks are called.

If you import a class that you want to use as a handler, you can define the handler with something like:

Code: Select all

define('HANDLER_CLASS', 'YourHandler');


An example of how this might work is in the BrowsePlugin that ships with OJS.

Regards,
Jason

carola
Posts: 93
Joined: Mon Jun 09, 2014 10:07 pm

Re: Install a new plugin (management -> ... -> plugins)

Postby carola » Wed Jun 18, 2014 6:24 am

Thanks!

Code: Select all

define('HANDLER_CLASS', 'YourHandler');


I did define it like that, and I checked the path, still it calls the handler from the wrong place. I think it's PageRouter, I will try to find out about it.

asmecher
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm
Contact:

Re: Install a new plugin (management -> ... -> plugins)

Postby asmecher » Wed Jun 18, 2014 9:43 am

Hi Carola,

There's no up-to-date hook list for either OJS or OMP; we found that the OJS hook documentation quickly got out of date. We're talking about ways to improve our own documentation process, but in the meantime, the code is the best reference for hooks.

As for the LoadHandler hook, it exists just like in OJS -- it's implemented in lib/pkp/classes/core/PKPPageRouter.inc.php -- but a common pitfall for writing plugins is forgetting to register the plugin with the system. To do this, put your plugin in place and ensure it has an accurate version.xml descriptor. (Use the others for a template here.) Then run...

Code: Select all

php tools/upgrade.php upgrade
...to register all plugins with the system. (Make sure you back up your DB before you do this in case you run into trouble.)

If a plugin isn't registered with the system, it'll never get loaded, and thus hook callbacks will never be registered.

Regards,
Alec Smecher
Public Knowledge Project Team

carola
Posts: 93
Joined: Mon Jun 09, 2014 10:07 pm

Re: Install a new plugin (management -> ... -> plugins)

Postby carola » Wed Jun 18, 2014 11:40 pm

Thanks, I upgraded now, but still the LoadHandler-callback doesn't work.

I tracked it down to those lines

Code: Select all

if ($result = call_user_func($hook, $hookName, $args)) {
   break;
}


in HookRegistry.inc.php

$hookName is LoadHandler and the parameters are all correct, but the code in my callback function isn't executed and $result is false.

I register the hook:

Code: Select all

HookRegistry::register('LoadHandler', array(&$this, 'callbackLoader'));


and implement the callback

Code: Select all


function callbackLoader($hookName, $args) {
   $datei_handle=fopen("beta.txt","a");
   fwrite($datei_handle,"in BetaBlockPlugin->callbackLoader: ".$page['name']."  ".$this->getPluginPath()."\r\n");
   fclose($datei_handle);
   return true;
}


The same works fine with Templates::Common::LeftSidebar but not with LoadHandler.

EDIT: I tried the same with a generic plugin and it works (LoadHandler). I also didn't find a single example where a block plugin uses the LoadHandler hook.

best,
Carola

JasonNugent
Site Admin
Posts: 910
Joined: Tue Jan 10, 2006 6:20 am

Re: Install a new plugin (management -> ... -> plugins)

Postby JasonNugent » Thu Jun 19, 2014 5:05 am

Hi Carola,

Yes, it would probably need to be a Generic plugin, instead of a Block plugin. The reason is that the Generic category of plugin is loaded very early on in the PKP code stack, because it is possible to write plugin hooks against things that occur very early on (like in the page routing). Other categories of plugins, like the block plugin category, are only loaded in certain places, via the loadCategory() method in the PluginRegistry class. The reason behind this is that loading plugin categories can be an expensive operation and most plugin categories are only needed in certain areas.

If you want to be absolutely certain that you can write hooks against the plugins you want, anywhere within OJS, I'd recommend writing a generic category plugin. Otherwise, you might find that you can't intercept certain hooks unless you go and modify the OJS core code and add the necessary calls to loadCategory, but then you're modifying OJS and those customizations would need to be carried across upgrades.

Regards,
Jason

carola
Posts: 93
Joined: Mon Jun 09, 2014 10:07 pm

Re: Install a new plugin (management -> ... -> plugins)

Postby carola » Thu Jun 19, 2014 7:07 am

Hi Jason,

thanks a lot, that's exactly the information I needed!

best,
Carola


Return to “OMP Development”

Who is online

Users browsing this forum: No registered users and 1 guest