Hi,
we are using OJS 2.x and i made a plugin which changes the layout of the webiste to
our needs. I also added now an “lougout” button, but I only want to display it if
a user is logged in otherwise there should be a login button.
Is there a posibility to this with javascript. Which elements can i check?
Thanks.
Best regards,
Matthias
If you have made an OJS plugin, you have access to the full PHP framework. Is there a reason you want to perform the check in Javascript instead of simply using a PHP call?
No there is no need for me to use JavaScript i can also do it with PHP, is the PHP framework documented?
The version 2.4.8’s API documentation (via doxygen) is available here:
https://pkp.sfu.ca/ojs/doxygen/stable/html/index.html
The function you want is:
https://pkp.sfu.ca/ojs/doxygen/stable/html/classValidation.html#a916567ab2e4a2851dc0a8d33e002882d
For an example in PHP of checking whether a user is logged in, see:
$this->register_function('url', array(&$this, 'smartyUrl'));
// ajax load into a div
$this->register_function('load_url_in_div', array(&$this, 'smartyLoadUrlInDiv'));
if (!defined('SESSION_DISABLE_INIT')) {
/**
* Kludge to make sure no code that tries to connect to
* the database is executed (e.g., when loading
* installer pages).
*/
$this->assign('isUserLoggedIn', Validation::isLoggedIn());
$application =& PKPApplication::getApplication();
$currentVersion =& $application->getCurrentVersion();
$this->assign('currentVersionString', $currentVersion->getVersionString());
$this->assign('itemsPerPage', Config::getVar('interface', 'items_per_page'));
$this->assign('numPageLinks', Config::getVar('interface', 'page_links'));
}
$this->initialized = false;
which drives the template conditional here:
Okay, thanks for your answer. Is there a method to check if i am logged in my alternate header too?
There i can’t use PHP i have only the possibility use javascript and i want to place a login button in header.
Thanks in advance.
If your alternate header is using the PKPTemplateManager for display (it probably is), the Smarty variable $isUserLoggedIn
will be available to you.
I receive an “Uncaught ReferenceError: $isUserLoggedIn is not defined”, if I use this variable. How can i check if my header is using this PKPTTemplateManger.
Typically, some code will instanciate a PKPTemplateManager
:
$request
);
} else {
return $this->download(
array($galley->getArticleId(), $galley->getId()),
$request
);
}
}
$templateMgr =& TemplateManager::getManager($request);
$templateMgr->addJavaScript('js/relatedItems.js');
$templateMgr->addJavaScript('js/inlinePdf.js');
$templateMgr->addJavaScript('js/pdfobject.js');
if (!$galley) {
// Get the subscription status if displaying the abstract;
// if access is open, we can display links to the full text.
import('classes.issue.IssueAction');
// The issue may not exist, if this is an editorial user
Then display a particular template using the PKPTemplateManager
object:
'query' => 'search.allFields',
'authors' => 'search.author',
'title' => 'article.title',
'abstract' => 'search.abstract',
'indexTerms' => 'search.indexTerms',
'galleyFullText' => 'search.fullText'
));
// consider public identifiers
$pubIdPlugins =& PluginRegistry::loadCategory('pubIds', true);
$templateMgr->assign('pubIdPlugins', $pubIdPlugins);
$templateMgr->display('article/article.tpl');
}
/**
* Article interstitial page before PDF is shown
* @param $args array
* @param $request Request
* @param $galley ArticleGalley
*/
function viewPDFInterstitial($args, &$request, $galley = null) {
$articleId = isset($args[0]) ? $args[0] : 0;
This template will include other templates, (for example, a common header):
Can you share you code to show how your header is being referenced?