OJS3: Adding "Most recent articles" option

Greetings,

After some time using OJS3 as a platform for electronic journal I have came up with the idea to add some functionality on the site. I think there is a need to add some sort of “Most recent articles” (or “Latest”). Moreover, I think as usage statistics plugin is properly working, maybe option like browse articles by “most viewed” could also be implemented?

In our journal we are planning to publish articles as continuous process, without waiting for full issue formation for placing it on the web. I think that it is very convenient to publish article just after it is processed to xml and pdf. So such option as view latest articles is quite helpful for readers to stay in touch with constantly updating content.

@asmecher - if such feature is not planned for developing in near future I would like to know from where I could start for developing such plugin for OJS3 by myself? Maybe, if it is not to complicated I could do this as my first project in php, which I have started to learn in a free time.

1 Like

Hi @Vitaliy,

OJS 2.x had an option that permitted this by combining two plugins – the Web Feed plugin (built into OJS including OJS 3.0), which provides RSS/Atom feeds of the most recent content, and the External Feed plugin, available for OJS 2.x, which embeds an RSS/Atom feed on the homepage. The nice thing about this combination is that the latest OJS content is an option, but you can also mix/match other RSS feeds with greater flexibility. We don’t have concrete plans to forward-port the External Feed plugin – it’s part of the greater set of plugins needing some attention – so if you’re interested, maybe working with updating that plugin would be a good place to start?

Regards,
Alec Smecher
Public Knowledge Project Team

@asmecher,

Thanks for the reply. For now I am taking courses in html/css/javascript and additionally learn php. I know some trics but deeper understanding of principles is better.Think will be ready for some coding in late december.

Hi @asmecher,

I have started the work on the possibility for display latest articles.
laid my hands on editing of indexJournal.tpl and from there as can be seen can call only articles from the latest issue. As example:
{$publishedArticles|print_r}
How can I call all published articles? Is modification of php code where this variable is assigned to smarty required? Where is it exactly?
Edit: I have managed to call all published articles from the plugin. What do you think of this function, is it OK to call articles like this?:

function browseLatest($hookName, $params) {
    $smarty =& $params[1];
    $output =& $params[2];

    // Get articles except Editorial and News
    $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
    $publishedArticleObjects = $publishedArticleDao->getPublishedArticlesByJournalId($journalId = null, $rangeInfo = null, $reverse = true);
    $publishedArticles = array();
    $publishedNews = array();

    $showArticlesCount = 0;
    $showNewsCount = 0;
    while ((($showArticlesCount + $showNewsCount) < 19) && $publishedArticle = $publishedArticleObjects->next()) {
        if ($showArticlesCount < 10 && ($publishedArticle->getSectionId() != 5)) {
            $publishedArticles[]['articles'][] = $publishedArticle;
            $showArticlesCount = $showArticlesCount + 1;
        } elseif ($showNewsCount < 10 && ($publishedArticle->getSectionId() == 5)) {
            $publishedNews[]['articles'][] = $publishedArticle;
            $showNewsCount = $showNewsCount + 1;
        }
    }

    $smarty->assign('publishedArticles', $publishedArticles);
    $smarty->assign('publishedNews', $publishedNews);

    $output .= $smarty->fetch($this->getTemplatePath() . 'browseLatest.tpl');
    return false;
}
4 Likes

Hi @Vitaliy,

This is an OK approach, but I’d watch out for performance problems as the number of articles gets large. The $rangeInfo object is used to specify a subset of results when fetching from the database so that you can e.g. provide paging.

Regards,
Alec Smecher
Public Knowledge Project Team

I did a “most read articles of the week” feature to our site front page and found out that there were a lot of performance issues (large metrics table). These were however very easy to solve with the OJS file cache. So @Vitaliy if you have performance issues with that script (probably not?) I can help you with a file cache code.

I haven’t use metrics table yet, I suppose :slight_smile: Other tables are not so big for now.

Thanks @asmecher,

So you mean this class: pkp-lib/DBResultRange.inc.php at a31da6eb6c9839479d285b90d840253ba5ac2024 · pkp/pkp-lib · GitHub?

$count is a number of articles to show, suppose number of articles in my case. And $page? Hmm, I don’t understand, “The number of pages to skip” - what pages are meant?

Hi @Vitaliy,

The DBResultRange class is intended to provide paging. So if you were displaying 20 items per page, page 1 would be items 1-20, page 2 would be items 21-40, etc.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like