feedback? plugin to link journals across locales

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

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

Forum rules
The Public Knowledge Project Support Forum is moving to

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.
Posts: 7
Joined: Mon Jan 05, 2009 9:11 am

feedback? plugin to link journals across locales

Postby samuelwan » Tue Jan 06, 2009 3:24 pm

I don't have a lot of experience with PHP and I'm new to the OJS framework (which is very nice, btw), so I'm posting my solution here with the hope that someone can suggest to me a better approach, or save themselves some time.

I've created a plugin that generates a horizontal nav menu linking to multiple journals in an OJS installation. In my situation, each journal has a different primary locale. When I visit a non-English journal, the API doesn't easily allow you to retrieve titles for all other journals. The API tries to retrieve each journal's title based on each journal's primary locale, but the title will not appear if the journal hasn't defined a title for all locales, which is prone to human error. For example, if the current journal has a Portuguese primary locale, the title of a journal with Spanish primary locale cannot be retrieved through the API if the user has not defined the Portuguese journal's title in the Spanish locale (or any other locale).

I began by studying the and files in /classes/journal/. After some frustration with how these classes force all requests through localization (which hides data from other locales), I realized that I would have to create a plugin that duplicates the procedure WITHOUT locale filtering.

Step 1) Journal::getJournals() function does not work for multiple languages
First, my plugin had to recreate the function "&_returnJournalFromRow" from /classes/journal/ for the *sole* purpose of commenting out the $journal->setPrimaryLocale() call. That setPrimaryLocale function was the culprit which filtered out all other journals, and I'm still not sure why.

Step 2) Journal::getJournalTitle() function does not work for multiple languages
Once I retrieved a list of all enabled journals, I had to work around the Journal::getJournalTitle(). That function will not retrieve a title for journals that haven't defined titles in the current journal's primary locale. Unfortunately, the path of API calls lead to a core DataObject.getData function which ultimately filters by locales, so there's no clean way to bypass this. My solution was to get the journal's raw settings via journal->getSettings(), convert all the locale titles to a numeric array, and retrieve the first index by default.

Code: Select all

class JournalsNavBarPlugin extends GenericPlugin {
        // Register the plugin for a custom hook that's called by /templates/common/header.tpl
        function register($category, $path) {
                if (parent::register($category, $path)) {
                        if ( $this->getEnabled() ) {
                        return true;
                return false;
        // Modified code copied from the "&getJournals" function in /classes/journal/
        function callback($hookName, &$args) {
                $templateMgr = &TemplateManager::getManager();
                $journalDao = &DAORegistry::getDAO('JournalDAO');
                $result = &$journalDao->retrieve(
                        'SELECT * FROM journals WHERE enabled=1 ORDER BY seq'
                $journals = &new DAOResultFactory($result, $this, 'createJournalFromRow');
                $journalLinks = array();
                while ($journal =& $journals->next()) {
                        // Get raw journal settings and then get the first locale's title
                        $settings = $journal->getSettings();
                        $titleArray = array_values($settings["title"]); // convert to numerically indexed array
                        array_push($journalLinks, array(
                                "title" => $titleArray[0],
                                "url"  => $journal->getPath()
                $templateMgr->assign_by_ref('journalLinks', $journalLinks);
                $templateMgr->display($this->getTemplatePath() . 'journalsNavBar.tpl');
      // A copy of "&_returnJournalFromRow" function from /classes/journal/
      // Note: I had to specifically comment out the setPrimaryLocale call because it filtered out all other journals
         function createJournalFromRow(&$row) {
                $journal = &new Journal();
                // $journal->setPrimaryLocale($row['primary_locale']);

                // HookRegistry::call('JournalDAO::_returnJournalFromRow', array(&$journal, &$

                return $journal;

My plugin template simply relies on the {section} tag to loop through an array of titles and urls. I took this approach because couldn't figure out how to reinsert locale-safe titles into the Journals iterator, and don't know enough about Smarty templating to modify the {url} tag:

Code: Select all

<div id="journals_navbar" style="padding-left:10%">
<ul class="menu">
        {section name=link loop=$journalLinks}
                        <a href="{url page="index" op=$journalLinks[link].url}">{$journalLink$

I've only been working with OJS for a couple of days, and I'm sort of new to PHP, so any feedback or suggestions would be much appreciated.

Return to “OJS Development”

Who is online

Users browsing this forum: No registered users and 2 guests