The place for javascript in Ojs 3.1.x.x

Dear all,
I want to add image slider in for example additional content. I have googled about it. To do, it has 3 codes; html, css and javascript.

Where the JS codes will be placed?
Is it in custom tags in setting?

@Vitaliy
@asmecher

You can look how I have done in through a plugin. It displays 3 latest articles’ sliders on the main page. But I also have added one custom method in PublishedArticle class. Although, with minimal modifications, you can do this without latter.

Thanks @Vitaliy. I will make a try.
If it does not use plugin, how to work with or where to place JavaScript in ojs to make carousel work?
For example make image slider in sidebar

Hi

I uploaded the plugin, yet it is not work. I cannot see it in the generic plugins-ojs 3.1-1.
I changed the name as browse and, then browsePlugin. when adding with second name, the plugins cannot upload.

bests,

This plugin is not intended for public use. As I wrote earlier, it requires changes in OJS core.
Method getPublishedArticlesBySection, that I have used there, doesn’t exist in original OJS PublishedArticle class.

Thank you very much for your quick respond.

How can I use this plugin with child theme or how can I modify the plugin?
If you help, I will be glad.
Thanks again.

This plugin retrieves 3 articles from the database (that user points from the plugin settings tab in the dashboard), seeks attached to the XML images with file name slider.png or slider.jpg and displays these images as sliders on the index page. If you want to use this functionality, I can guide you though needed modifications.

Dear Vitaliy,
I want to use this function for recent articles (three or more) on the home page, like your journal: Psychosomatic Medicine and General Practice
Register. How can I make it? Can you help me about modification for child theme? I do not use the images. I want to use only recent articles names as a slider.

Bests,
Gökmen

That’s the method I have added in PublishedArticleDAO class:

function getPublishedArticlesBySection($journalId = null, $rangeInfo = null, $reverse = false, $sections) {
        $params = $this->getFetchParameters();
        if ($journalId) $params[] = (int) $journalId;
        $result = $this->retrieveRange(
            'SELECT	ps.*,
				s.*,
				' . $this->getFetchColumns() . '
			FROM	published_submissions ps
				LEFT JOIN submissions s ON ps.submission_id = s.submission_id
				LEFT JOIN issues i ON ps.issue_id = i.issue_id
				' . $this->getFetchJoins() . '
			WHERE 	i.published = 1
				' . ($journalId?'AND s.context_id = ?':'') . '
				AND s.status <> ' . STATUS_DECLINED . '
				AND se.section_id IN ('. $sections . ')
			ORDER BY ps.date_published '. ($reverse?'DESC':'ASC'),
            $params,
            $rangeInfo
        );

        return new DAOResultFactory($result, $this, '_fromRow');
    }

It retrieves articles by section id’s (you can view section id in the database).
But if you don’t need that specificity, you can change it in the code to the method, which this DAO class already has, for example getPublishedArticlesByJournalId

What you will need, is to modify this plugin’s method (function):

For example, we have on line 72:
$publishedArticleObjects = $publishedArticleDao->getPublishedArticlesBySection($journalId = null, $rangeInfoArticles, $reverse = true, "3,4,9");
You can change it to something like:
$publishedArticleObjects = $publishedArticleDao->getPublishedArticlesJournalId($journalId = null, $rangeInfoArticles, $reverse = true);

Than you will need to make an array: $publishedArticles = array();
iterate through articles and write what you need to that array.
Another step is to assign this array to the template:

$smarty->assign('publishedArticles', $publishedArticles);
$output .= $smarty->fetch($this->getTemplatePath() . 'browseLatest.tpl');

You can see this template here:

When this will be done, I can show you how to make settings form for the plugin.

Thank you for your respond.
I try to make your suggestions.
First, I changed the “$publishedArticleObjects = $publishedArticleDao->getPublishedArticlesBySection($journalId = null, $rangeInfoArticles, $reverse = true, “3,4,9”);” as “$publishedArticleObjects = $publishedArticleDao->getPublishedArticlesJournalId($journalId = null, $rangeInfoArticles, $reverse = true);” in the BrowsePlugin.inc.php#L63
However, I do not understand the second and following step. How can create the $publishedArticles = array(); and where?

Best,
Gökmen.

In next part of code I am making 2 arrays. First is for latest articles and the second for sliders:

$publishedArticles = array(); 
$browseArticles = array();

Then I am iterating though PublishedArticle objects and writing data in this to arrays.

while ($publishedArticle = $publishedArticleObjects->next()) {
            $publishedArticles[] = $publishedArticle;
            if ($publishedArticle->getId() == $sliderFirst) {
                $browseArticles = $this->slidersSearch($params, $publishedArticle, $browseArticles);
            } elseif ($publishedArticle->getId() == $sliderSecond) {
                $browseArticles = $this->slidersSearch($params, $publishedArticle, $browseArticles);
            } elseif ($publishedArticle->getId() == $sliderThird) {
                $browseArticles = $this->slidersSearch($params, $publishedArticle, $browseArticles);
            }
        }

this line I check if the articles id is the one I need for slider:
$publishedArticle->getId() == $sliderFirst
You can even refactor this part of the code to structure it better.
slidersSearch is my custom function, you can view it in the bottom of the file.

After that I am assigning to the Smarty template:
$smarty->assign('browseArticles', $browseArticles);

Dear @Vitaliy,
Once I tried the plugin, the index journal only show slider, news, editorial. Is it possible to edit your plugin to have sliders, recent articles (column display as oldGregg), additional content and sidebar?

I want to customize my journal in that way. I am using manuscript-jats

Have you modified PHP file accordingly?

If yes, you need now to modify frontend. Latest articles block is starting from here:

you can see from there that I am iterating over 3 array (3 foreach loops). You need only one, where your articles assigned. Supposing that’s $publishedArticles array.

Also, keep in mind that I will not support this plugin (it was not ever released for public) and manuscript-jats child theme (it was replaced with Old Gregg Theme).
Manuscript-JATS theme will stop working in one of the future release (3.1.1 or 3.2.0) as there will be a major upgrade of Smarty Template Engine.

Well, I think OldGregg is a future choice. I will switch to OldGregg, still waiting for 1.1.0.1 for journal summary and sliders in indexJournal

Thanks for your contribution for our journal

Hi Vitaliy,

I made modification, yet I cannot worked the plugin.
I you help me I will be glad.

The plugin was never released for public use because it needs the changes in OJS core. In the PublishedArticleDAO class need to be a new method:

function getPublishedArticlesBySection($journalId = null, $rangeInfo = null, $reverse = false, $sections) {
        $params = $this->getFetchParameters();
        if ($journalId) $params[] = (int) $journalId;
        $result = $this->retrieveRange(
            'SELECT	ps.*,
				s.*,
				' . $this->getFetchColumns() . '
			FROM	published_submissions ps
				LEFT JOIN submissions s ON ps.submission_id = s.submission_id
				LEFT JOIN issues i ON ps.issue_id = i.issue_id
				' . $this->getFetchJoins() . '
			WHERE 	i.published = 1
				' . ($journalId?'AND s.context_id = ?':'') . '
				AND s.status <> ' . STATUS_DECLINED . '
				AND se.section_id IN ('. $sections . ')
			ORDER BY ps.date_published '. ($reverse?'DESC':'ASC'),
            $params,
            $rangeInfo
        );

        return new DAOResultFactory($result, $this, '_fromRow');
    }

But I see that this plugin (with or without modifications) is extensevely used by the community. So I suppose, I’ll make a few changes, so never this question shall rise again :slight_smile:

it is great news :slight_smile:
I look forward to hearing from you.

Thanks very much.

Hi Vitality,

Can you changes the browsePlugin for child theme or others?

You mean integrate it with a theme?