Making a plugin for OJS3

The PKP framework includes a Java-like implementation of an import() function. For example:

It wraps require_once and is bootstrapped here:

I’d recommend leveraging this function for consistency.

2 Likes

Hi @ctgraham,

Thanks for the answer. I have rewrited my code to fit OJS style. Now I have a problem to get XML from article galley. Plugin is uploaded to the github. The problem occurs here: https://github.com/Vitaliy-1/JATSParserPlugin/blob/master/JatsParserPlugin.inc.php#L136
I have no idea in OJS classes methods. This code was copied from @ajnyga’s embedGalley.
PHP logs tell me Call to undefined method Article::getGalleys(). So, can you give me a hint how to deliver JATS XML to my parser? Also there is a lot of deprecation about Non-static method Request through ::

Maybe it should be not: $article = $smarty->get_template_vars('article'); but $article = $smarty->get_template_vars('publishedArticle');?

Hmm, after fix it works only for one language and only for last issue. In other case it throws: Uncaught Error: Call to a member function getGalleys() on null (couldn’t find galley I suppose).

The error is suggesting that $smarty->get_template_vars('article') does not return a article object at all.

If I recall correctly, you were wishing to add a dynamic galley. You should check the lensGalley plugin in that case: lensGalley/LensGalleyPlugin.inc.php at master · ajnyga/lensGalley · GitHub

I think that the biggest problem with embedGalley is statistics. I do not know how they should be considered because galley files are not getting opened and OJS is counting galley downloads.

Stats are proper. If you embed the xml fikes into abstract page. The stats will count abstract views only. If some one opens xml or pdf, then that will add upto the downloads stats.

However, if you want to create a new static page and embed xml into it, then you can do that as well. You can create a new html galley and link it to an external page.

If this was the problem you meant. Then its completely fine. Also, when you embed the xml files onto abstract page, google scholar counts as html and not abstract. Win win for us.

thanks @varshilmehta!

I am actually thinking a situation where you compare statistics for journals using the plugin and for journals not using the plugin. Our site theme has a “top articles of the week” stat in the site front page. At the moment it is counting the downloads, but that is of course not fair for journals with embedded HTML. I will have to find out what COUNTER says about this.

Do you know if there are some meta tags etc. for Google scholar to tell that the full text is on that page? I was looking that it would be maybe possible to add a feature to embedGalley that adds the XML references and list them for google scholar: Improve Google Scholar exposure with reference metatags!

Google was able to pick up. So dont worry about it. You can have a look on my site. Thanks

For start I wished to test plugin statically. It works only with several articles and with $smarty->get_template_vars('publishedArticle'). So the object PublishedArticle in most cases returns null. As for Article object there is a weird things to. For example, in 2 articles it returns articles with other id (and all the data). In several cases it not returns galleys.

So my main problem is that i don’t know how to retrieve JATS XML galley from article detail page in terms of PHP code in the plugin.

this is weird, because I have not encountered a similar problem with embedGalley. I mean the article object should be there always, because it is the article page. Do you have similar problems with embedGalley if you test it with the same articles?

Ok. I will test with embedGalley plugin. As far as I can see the problem is related to the hook, that is used. With Template::Article::Main hook all seems to be OK, but not with Footer hook.

Before doing more work, I want also to ask you the best way to expose article with PHP. My idea, after taking a look at the OJS code more precisely, is parse XML into POPO objects, assign data to the variables like here: https://github.com/Vitaliy-1/JATSParserPlugin/blob/master/JatsParserPlugin.inc.php#L156 and expose them through tpl file. In this case front-end will be generated according to smarty native way. What do you think about this approach?

And one more question is about order inside the hooks. Did you figure out how to change it, because in my case article statistics goes before the article main text?

The order inside hooks is a work in progress. Alec has something ready, but the work is not finished yet. I do not know the details.

I would definitely assign multiple variables of course depending on what you want to do with the layout.

Have tested embedGalley plugin. The problem occurs with several articles. From error log:
PHP Fatal error: Uncaught Error: Call to undefined method Article::getGalleys() in plugins\generic\embedGalley\EmbedGalleyPlugin.inc.php:147

Also Recommend Articles by Author plugin not always working. They both use Footer hook. I think the reason is in loading order. Maybe this plugins are loaded actually before the Article object is created? Is it possible?

Edit: seems to be a conflict between this plugins. After disabling the latter embedGalleys works fine.

I want completely change the front-end look of articles. Do it more PLOS- or elifesciences-like :slight_smile: Don’t know if it is better to do it with javascipt or change theme files. Also I am not aware how will work assigning ArrayObjects to smarty templates.

1 Like

That is weird, because I have one journal using the plugin without any problems and I think that a couple of others are using it as well.

I think it is the same problem as here: Article display page behaving differently - #14 by hannanhazari

Do you have the Recommend Articles by Author plugin enabled at the same time as embedGalley?

Do you happen to use defaultManuscript theme?

It feels as this is not so much connected to embedGalley but a bug in OJS?

About the themes, I have been looking at PLOS One as well, especially the tabbed view of their articles: http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0176009
I think that it would be a nice layout to have at least these tabs:

  • Article (abstract, main metadata, maybe full text)
  • How to cite (this takes a lot of room at the moment)
  • Authors (if author biographies available)
  • Statistics (if enabled, the problem is that at the moment the stats plugin is just hooked to a multipurpose hook. You would have to add a new hook and fork the stats plugin to hook it in the right place)
  • References (if available)

A have a work on progress theme that uses Jquery UI tabs (Tabs | jQuery UI).

Another way of making room to the abstract page would be using these Accordion | jQuery UI in the abstract page side bar.

Can you try changing this to return true;

I have a feeling that return false will prevent other plugins from using the same hook? @asmecher?

edit: note to self, I have that in embedGalley as well… But I recall reading (can not remember where) that return false would prevent other plugins from using the hook. I could be wrong here. I can not test that right now so if you can let me know, thanks!

Nope. Not helping. There is a need to note that, for example, with the last article embedGalley works on primary locale and not working with second locale. The same case if for recommend by author. But I don’t understand why is so, because for the 80% of articles all works fine.

We use own theme. It is much like default but with several bootstrap tweaks.

I have already used bootstrap for tabs and for small screen adaptation. Thinks, this is better option. You can see how the tabs and accordion (on small screens) look like in our articles: Psychological help in oncology practice | Psychosomatic Medicine and General Practice
Mostly I want to do the same, but on article detail page.

1 Like

I have a feeling that this would be a problem with any plugin using that hook and maybe also with the other hook you mentioned if other plugins use that. I will test embedGalley next week together with the other plugin. Maybe Alec with comment by then.