Reading an html galley, and displaying below abstract - Plugin

I am trying to customize OJS 3.0.2, and I wish to develop a plugin to display the HTML article below the abstract. I have nearly managed, but am stuck at how to get the file contents of a html galley.

I have looked at HTMLArticleGalley plugin, and came across this:

	function _getHTMLContents($request, $galley) {
		$journal = $request->getJournal();
		$submissionFile = $galley->getFile();
		$contents = file_get_contents($submissionFile->getFilePath());

		// Replace media file references
		$submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
		import('lib.pkp.classes.submission.SubmissionFile'); // Constants
		$embeddableFiles = array_merge(
			$submissionFileDao->getLatestRevisions($submissionFile->getSubmissionId(), SUBMISSION_FILE_PROOF),
			$submissionFileDao->getLatestRevisionsByAssocId(ASSOC_TYPE_SUBMISSION_FILE, $submissionFile->getFileId(), $submissionFile->getSubmissionId(), SUBMISSION_FILE_DEPENDENT)
		);
		$referredArticle = null;
		$articleDao = DAORegistry::getDAO('ArticleDAO');

However, i need some one to explain what is happening. I code in PHP, and understand smarty, but there are too many variables and DAO and extensions of objects to keep trace.

I cannot find a list of functions for a galley, and this is limiting my work.

Thanks

Stephen

This will be a 3rd plugin of its kind :slight_smile:
You can look at: embedGalley/EmbedGalleyPlugin.inc.php at master · ajnyga/embedGalley · GitHub This plugin converts JATS XML with XSLT into HTML and displays it on article detail page (under abstract)
or: https://github.com/Vitaliy-1/JATSParserPlugin/blob/master/JatsParserPlugin.inc.php This plugin parses JATS XML into PHP objects and displays it on article detail page through smarty.

I tried your parser. However the plugin page in the journal manager just kept on loading. Is it not yet ready?

Yep. Will be ready soon, but not yet. Although eternal loading is a strange behavior. What do you see in PHP error log?

you could achieve what you are hoping fairly easily by using one of the plugins @Vitaliy mentioned as base.

Just check for html instead of xml: embedGalley/EmbedGalleyPlugin.inc.php at master · ajnyga/embedGalley · GitHub

And skip the conversion: embedGalley/EmbedGalleyPlugin.inc.php at master · ajnyga/embedGalley · GitHub

What you do need to think about is what to do with the HTML. You could replace the _parseXML function with a function that only gets the HTML between the body tags. If you embed the full html, you will end up with unvalid html.

where do I find a list of the functions associated with the objects?

TemplateManager?

Application::request?

Where dio I find a reference for these?

Stephen

My PHP error log has been de activated by the host server. Is there any other way to find out?

there is not much reference available, I usually just see what others have done in the plugins or in the OJS core.

See @asmecher’s answer here: [OJS 3] Technical Reference?

There is also a link here, if this helps you: http://pkp.sfu.ca/ojs/doxygen/master/html/index.html

1 Like

By default it’s apache error.log. Without error logs its impossible to find out causes of troubles. OK, I will prepare plugin for front-end developing at the end of the week. You can try than.

1 Like

Found that site as well.

I have seen your and vitaliy’s code. I think I am slowly getting there.

If i am correct, first register the plugin to a hook, then get the html content: i will be using DOMdocument to select only the body, and then strip the

Then I attach that to the smarty template (this is where I dtill need smoe time)

If I download one plugin, how can I add it to OJS? the admin pages still do not show a way of doing this. Should I just upload by ftp in the directory?

thanks

Stephen

That sounds about right. Of course a lot depends on the HTML file you are embedding.

I usually upload the plugins with ftp. If you upload the through the backend, I think they have to be tar.gz compressed.

I am not managing at all……

I have tried using ajnyga’s plugin, and started to modify, but I do not know how the plugin gets called in the first place.

I have a button on the page, to load this html: but I do not understand how to trigger the plugin, like the default action when one clicks on the Galley links.

I am actually thinking of doing all this by addin some php file, and load dynamiccally via javascript, but I still need access to the article classes as used by OJS

The lack of a tutorial / reference to formulate a plugin is frustrating.

stephen

The way embedGalley works is that it detects whether the article has XML galleys. If it has, it will then open the XML galley file, convert it to HTML, run a few HTML filters and then embed that HTML to the article abstract page.

You just need to have the plugin activated and add a JATS XML galley to an article. Everything else is automatic.

If you click on a galley link, it will open a different view than the abstract page. I understood from your first post, that you want it under the abstract?

There is no need fully understand OJS code to make a plugin. Moreover OJS is complicated system, that evolved for a very long time.
On what stage you have stuck?:
Getting HTML from a galley?
Assigning variables to smarty?
Making Smarty template?
Connecting to a hook?

Plugin requires minimum PHP7.0
What version you are using?

5.6. If i use 7, my website does not show up only.

PHP7 requires mysqli instead of mysql driver, did you try change it in your OJS config?

No. i will try doing it.

I have made a lot of progress over the last few days.

I have managed to read the html galley, and get it into the abstract page.

However, I am not using a plugin approach - i will try that later once I get everything in order. I have instead hijacked the code, and included some php to deal with the requests.

Now i need to know how to get the Journal short path. Would anyone know how to access it from php, smarty?

thanks again

stephen

I retrieve XML from plugin with this code:

$articleArrays = $smarty->get_template_vars('article');
foreach ($articleArrays->getGalleys() as $galley) {
    if ($galley && in_array($galley->getFileType(), array('application/xml', 'text/xml'))) {
	  $xmlGalley = $galley;
    }
}

Maybe, if you change xml to html, you retrieve needed galley?

Creating DOM:

$document = new DOMDocument;
$document->load($xmlGalley->getFile()->getFilePath());

After this you can do standard operations with DOM and save it.
Assigning a variable to the smarty.

$smarty->assign('document', $document);

your smarty template:

$output .= $smarty->fetch($this->getTemplatePath() . 'yourSmarty.tpl');