OJS 2.x - URL Link for logo plugin problem

Hello all,

I’m writing a plugin for OJS 2 that adds a JQuery/Javascript tag to the <HEAD> area of the pages, wrapping the logotype image, if available, with an <A> tag with the link that is defined in the locale files. To customize the link, enable the Custom Translator Plugin and modify the plugin’s URL translation key.

My URL For Logo Plugin installed fine, but system went down.
Once I removed the folder from OJS, system got back online.

I used the TinyMCE generic plugin as a base and removed what I thought was unnecessary, but I’m not sure if anything is missing.

I’m sure there’s a typo, coding error somewhere, but, it’s beyond me…

<?php

    /**
     * @file plugins/generic/urlforlogo/UrlForLogoPlugin.inc.php
     *
     * Copyright (c) 2013-2016 Simon Fraser University Library
     * Copyright (c) 2003-2016 John Willinsky
     * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
     *
     * @class UrlForLogoPlugin
     * @ingroup plugins_generic_urlforlogo
     *
     * @brief urlforlogo WYSIWYG plugin for textareas - to allow cross-browser HTML editing
     */


    import('lib.pkp.classes.plugins.GenericPlugin');

    class UrlForLogoPlugin extends GenericPlugin {
    	/**
    	 * Register the plugin, if enabled; note that this plugin
    	 * runs under both Journal and Site contexts.
    	 * @param $category string
    	 * @param $path string
    	 * @return boolean
    	 */
    	function register($category, $path) {
    		if (parent::register($category, $path)) {
    			if ($this->getEnabled()) {
    				HookRegistry::register('TemplateManager::display',array(&$this, 'callback'));
    			}
    			return true;
    		}
    		return false;
    	}

    	/**
    	 * Get the name of the settings file to be installed on new journal
    	 * creation.
    	 * @return string
    	 */
    	function getContextSpecificPluginSettingsFile() {
    		return $this->getPluginPath() . '/settings.xml';
    	}

    	/**
    	 * Get the name of the settings file to be installed site-wide when
    	 * OJS is installed.
    	 * @return string
    	 */
    	function getInstallSitePluginSettingsFile() {
    		return $this->getPluginPath() . '/settings.xml';
    	}

    	/**
    	 * Hook callback function for TemplateManager::display
    	 * @param $hookName string
    	 * @param $args array
    	 * @return boolean
    	 */
    	function callback($hookName, $args) {
    		$baseUrl = $templateManager->get_template_vars('baseUrl');
    		$additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
    		$logoUrl = ._return('plugins.generic.urlforlogo.url');
    		$allLocales = AppLocale::getAllLocales();
    		$localeList = array();
    		foreach ($allLocales as $key => $locale) {
    			$localeList[] = String::substr($key, 0, 2);
    		}

    		$urlforlogoScript = '
    		<script language="javascript" type="text/javascript">
    			$("#header").children("h1").children("img.first").wrap($("<a>",{
    			   href:"'.$logoUrl.'"
    			}));
    		</script>';

    		$templateManager->assign('additionalHeadData', $additionalHeadData."\n".$urlforlogoScript);
    		
    		return false;
    	}

    	/**
    	 * Get the display name of this plugin
    	 * @return string
    	 */
    	function getDisplayName() {
    		return __('plugins.generic.urlforlogo.name');
    	}

    	/**
    	 * Get the description of this plugin
    	 * @return string
    	 */
    	function getDescription() {
    		return __('plugins.generic.urlforlogo.description');
    	}


    	/**
    	 * Get a list of available management verbs for this plugin
    	 * @return array
    	 */
    	function getManagementVerbs() {
    		$verbs = array();
    		parent::getManagementVerbs();
    		return $verbs;
    	}
    }
    ?>

Have you checked your error log for messages?

This line seems odd to me:
$logoUrl = ._return('plugins.generic.urlforlogo.url');

Hello @ctgraham,

Yes…
I removed the period and the return…
Now it’s $logoUrl = __(‘plugins.generic.urlforlogo.ul’);

Is that correct, or should I keep the __return?

Also, not sure if it’s related, but since I installed the plugin I’m running into this error when opening other pages within the Custom Locale Plugin:

http://revista.ibict.br/editora/manager/plugin/generic/customlocaleplugin/editLocaleFile/pt_BR/plugins%2Fgeneric%2FobjectsForReview%2Flocale%2Fpt_BR%2Flocale.xml?referenceLocaleContentsPage=3#localeContents

Not Found

The requested URL /index.php/editora/manager/plugin/generic/customlocaleplugin/editLocaleFile/pt_BR/plugins/generic/objectsForReview/locale/pt_BR/locale.xml was not found on this server.

The function __() is used for translation. The effect of this line will now look up the key “plugins.generic.urlforlogo.ul” in the currently selected locale and assign the translated phrase to $logoUrl.

Is that your intent here? It looks like you will later use $logoUrl as if it was an actual URL.

Hello @ctgraham,

Yes, that’s the idea.
Since the plugin doesn’t have a configuration form, I see it easier to customize by journal with the Custom Translator Plugin. If all journals use the same URL, no need to change the URL… just use the Translator plugin and change the default URL.

Ok. I see you described that earlier.

Are you still getting a fatal error after the changes?

Does the “Not Found” error from the Custom Locale Plugin appear and disappear only when this new plugin is active?

Hello @ctgraham,

I made changes to the code, including renaming the plugin file, the class, moving the variable to another line… but every time I add it to the generic plugins folder, system crashes.

I run the php/tools upgrade upgrade (check doesn’t generate any errors) without errors.

I updated the tar.gz file… Can’t figure out what’s going on, but must be something really stupid, like a missing closing brace, semi-colon…

If you look in the webserver’s error log, you should find a message describing the fatal error. Paste it here.

Helll @ctgraham,

Here are some errors:
PHP Fatal error: Call to a member function get_template_vars() on a non-object in /var/www/devojs.ibict.br/plugins/generic/urlforlogo/UrlForLogoPlugin.inc.php on line 62

NOTICE: Undefined variable: templateManager (/var/www/devojs.ibict.br/plugins/generic/urlforlogo/UrlForLogoPlugin.inc.php:62)

[UPDATE]

I was missing an $templateManager = & $args[0];. I’m not sure if it’s correct, but now the plugin doesn’t crash OJS…
It’s not adding the javascript on the header… I’m now running the upgrade to see if it changes anything…