OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



owns plugin creation

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

owns plugin creation

Postby 2261422 » Thu Apr 29, 2010 10:23 am

I want to create my own plugin, but I don't understand the OJS's plugin structure, for example I don't know against which Hook must I register my plugin.
I have seen the register and callback functions but I need more informaton, can somebody help me?

Hooks are used by plugins as a notification tool and to override behaviors built into OJS and in the OJS technical reference manual there is an example to add an entry to the Journal Manager's list of functions, available by following the “Journal Manager” link from User Home.

and here is a code's part:

<?php
import('classes.plugins.GenericPlugin');
class ExamplePlugin extends GenericPlugin {
function register($category, $path) {
if (parent::register($category, $path)) {
HookRegistry::register(
'Templates::Manager::Index::ManagementPages',
array(&$this, 'callback')
);
return true;
}
return false;
}[*]

is here where I don't know how to proceed, I wanna add a portion of code in the respective search tpl, when the “search” link is clicked, but I don't know against which hook I must register my new plugin. in the above example the HookRegistry class use the method register agains ('Templates::Manager::Index::ManagementPages'), to what correspond Templates and its "methods" (::Manager::Index::ManagementPages for the manager)?

I watched a hook list but I don't find the one that I need for the code to be added when the search link is clicked,how can I know for a "generic plugin" which hook must be called when?
thanks
2261422
 
Posts: 33
Joined: Mon Jul 06, 2009 8:08 am

Re: owns plugin creation

Postby jmacgreg » Mon May 03, 2010 1:53 pm

Hi 2261422,

While we appreciate your interest in creating plugins, you also PM'd this question to me, and I'm guessing possibly to other members of the team. Please refrain from sending us unsolicited PM's. We'll get to this thread as soon as we can.

Cheers,
James
jmacgreg
 
Posts: 4162
Joined: Tue Feb 14, 2006 10:50 am

Re: owns plugin creation

Postby 2261422 » Tue May 04, 2010 7:53 am

Ok, sorry I don't mind that that would be a problem, that won't occur again.
I'll be waiting for your answer, thanks.
2261422
 
Posts: 33
Joined: Mon Jul 06, 2009 8:08 am

Re: owns plugin creation

Postby mcrider » Wed May 05, 2010 9:41 am

Hi 2261422,

You have to be sure there is a hook being called wherever you want the plugin's code to be loaded. For instance, the Templates::Manager::Index::ManagementPages hook is called in templates/manager/index.tpl (using the 'call_hook' smarty function)--You can add this same call to the search template you're talking about and the relevant code should be loaded.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: owns plugin creation

Postby 2261422 » Sat May 08, 2010 4:10 pm

Thank you so so much, just to be clear, Can I name my plugins like I want?. For instance in my plugin's file ini.php, can I call the hoockregistry funtion like this:
...
function register($category, $path) {
if (parent::register($category, $path)) {
HookRegistry::register(
'mi_plugin',
array(&$this, 'callback')
);
...
And call the hook into the tpl which wll be modified, in my case advancedsearch.tpl as follows:
....
{call_hook name="mi_plugin"}
...

I'm so thankful.
2261422
 
Posts: 33
Joined: Mon Jul 06, 2009 8:08 am

Re: owns plugin creation

Postby mcrider » Tue May 11, 2010 10:15 am

Hi there,

Yes, I think so--I believe the way we usually write hook names is just to make it easier to tell what they are. You should be able to name them whatever you want, but you'll have to try it yourself to be sure :)

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: owns plugin creation

Postby Tadas » Thu Apr 21, 2011 12:51 am

I registered hooks:
Code: Select all
function register($category, $path) {
      
      $success = parent::register($category, $path);
      if ($success && $this->getEnabled()) {
         // 1. Testing purposes only
         HookRegistry::register('Templates::Common::Footer::PageFooter', array($this, 'insertList'));
         // 2. Insert Cited-By linking to article.tpl
         HookRegistry::register('citedby', array($this, 'insertList'));
      }
      return $success;
   }


And put a hook in templates/article/article.tpl (below abstract) where I want to see my plugin:
Code: Select all
{call_hook name="citedby"}


Hook 1 is working, but hook 2 is not. Where is the point?
Tadas
 
Posts: 23
Joined: Fri Jan 28, 2011 3:02 am

Re: owns plugin creation

Postby Tadas » Thu Apr 21, 2011 6:31 am

one more thing:
I tryed to put
Code: Select all
HookRegistry::register('citedby', array($this, 'insertList'));
in google analytics plugin, because I used it as a base for creating my plugin, and I realised that plugin put two codes in the article.tpl, so it means my hook
Code: Select all
{call_hook name="citedby"}
works. So I decided to change code line by line I check out when the hook stops working and I found that this happens when I change names of google analytics plugin classes. Interesting is thing that other hooks in other tpl files are still working, but only this one in article.tpl stops working. What is this? Is it magic?
Tadas
 
Posts: 23
Joined: Fri Jan 28, 2011 3:02 am

Re: owns plugin creation

Postby mcrider » Thu Apr 28, 2011 10:09 am

Hi Tadas,

Your new plugin is probably not being registered in the versions table, whereas the GA plugin already is. Running the OJS upgrade script should register it.

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: owns plugin creation

Postby Tadas » Thu Apr 28, 2011 11:22 pm

Hello Matt,

Thanks for advice, I did upgrade and checked the versions table, to realise if plugin is registered successfuly and everything is correct, but this didn't make any effect to solve the issue... :(

so there must be another reason, why my plugin isn't displayed in any templates/article/*.tpl, wherever I put my hook, while in any other *.tpl is shown propertly if I put my hook there.
Tadas
 
Posts: 23
Joined: Fri Jan 28, 2011 3:02 am

Re: owns plugin creation

Postby Tadas » Fri Apr 29, 2011 11:30 am

I just upgraded the plugin by itself (no changes) and everything is working now, so I think it will be finished very soon :)
Tadas
 
Posts: 23
Joined: Fri Jan 28, 2011 3:02 am

Re: owns plugin creation

Postby Tadas » Fri Jun 03, 2011 12:01 am

how do I get issue year in the article view?
Tadas
 
Posts: 23
Joined: Fri Jan 28, 2011 3:02 am


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 4 guests