Hi, I have added @ajnyga codes in my front page plugins .inc.php file with the indexsite code in the front page tpl. However it is not yet seen. Any idea on what to do next?
$result = $metricsDao->retrieve("SELECT submission_id, SUM(metric) AS metric FROM metrics WHERE (day BETWEEN CURDATE()-INTERVAL 1 WEEK AND CURDATE()) AND (assoc_type='515' AND submission_id IS NOT NULL) GROUP BY submission_id ORDER BY metric DESC LIMIT 5");
while (!$result->EOF) {
$resultRow = $result->GetRowAssoc(false);
$article = $publishedArticleDao->getPublishedArticleByArticleId($resultRow['submission_id']);
$journal = $journalDao->getById($article->getJournalId());
$articles[$resultRow['submission_id']]['journalPath'] = $journal->getPath();
$articles[$resultRow['submission_id']]['journalName'] = $journal->getLocalizedName();
$articles[$resultRow['submission_id']]['articleId'] = $article->getBestArticleId();
$articles[$resultRow['submission_id']]['articleTitle'] = $article->getLocalizedTitle();
$articles[$resultRow['submission_id']]['metric'] = $resultRow['metric'];
$result->MoveNext();
}
$result->Close();
$cache->setEntireCache($articles);
return $result;
I tried adding them in the init function n my themes inc.php file. But then the site stops working. This is the themeâs inc.php without your addition
<?php
/**
* @file plugins/themes/default/DefaultManuscriptChildThemePlugin.inc.php
*
* Copyright (c) 2014-2017 Simon Fraser University Library
* Copyright (c) 2003-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
* Modyfied by Vitaliy Bezsheiko, MD
* @class DefaultManuscriptChildThemePlugin
* @ingroup plugins_themes_default_manuscript
*
* @brief Default theme
*/
import('lib.pkp.classes.plugins.ThemePlugin');
class ManuscriptJats extends ThemePlugin {
/**
* Initialize the theme's styles, scripts and hooks. This is only run for
* the currently active theme.
*
* @return null
*/
public function init() {
// Load additional template data
HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));
// Initialize the parent theme
$this->setParent('defaultthemeplugin');
$this->removeScript('jQueryTagIt');
$this->removeScript('popper');
$this->removeScript('bsUtil');
$this->removeScript('bsDropdown');
// Add bootstrap and jquery ui css
$this->addStyle('my-custom-style1', 'styles/bootstrap/bootstrap.min.css');
$this->addStyle('my-custom-style2', 'styles/bootstrap/bootstrap-theme.min.css');
$this->addStyle('my-custom-style3', 'jquery-ui/jquery-ui.min.css');
$this->addStyle('my-custom-style4', 'jquery-ui/jquery-ui.structure.min.css');
$this->addStyle('my-custom-style5', 'jquery-ui/jquery-ui.theme.min.css');
$this->addStyle('my-custom-style6', 'styles/article_detail.css');
// Add bootstrap and jquery ui javascript
//$this->addScript('my-javascript1', 'js/jquery.min.js');
//$this->addScript('my-javascript2', 'jquery-ui/jquery-ui.min.js');
$this->addScript('my-javascript3', 'js/bootstrap.min.js');
// Add custom styles
$this->modifyStyle('stylesheet', array('addLess' => array('styles/index.less')));
// Add custom menus
$this->addMenuArea(array('primary', 'user'));
// Remove the typography options of the parent theme.
// `removeOption` was introduced in OJS 3.0.2
if (method_exists($this, 'removeOption')) {
$this->removeOption('typography');
}
// Add the option for an accent color
$this->addOption('accentColour', 'colour', array(
'label' => 'plugins.themes.manuscript-jats.option.accentColour.label',
'description' => 'plugins.themes.default.option.colour.description',
'default' => '#F7BC4A',
));
// Load the Montserrat and Open Sans fonts
$this->addStyle(
'font',
'//fonts.googleapis.com/css?family=Montserrat:400,700|Noto+Serif:400,400i,700,700i',
array('baseUrl' => '')
);
// Dequeue any fonts loaded by parent theme
// `removeStyle` was introduced in OJS 3.0.2
if (method_exists($this, 'removeStyle')) {
$this->removeStyle('fontNotoSans');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSansNotoSerif');
$this->removeStyle('fontLato');
$this->removeStyle('fontLora');
$this->removeStyle('fontLoraOpenSans');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
}
// Start with a fresh array of additionalLessVariables so that we can
// ignore those added by the parent theme. This gets rid of @font
// variable overrides from the typography option
$additionalLessVariables = array();
// Update colour based on theme option from parent theme
if ($this->getOption('baseColour') !== '#1E6292') {
$additionalLessVariables[] = '@bg-base:' . $this->getOption('baseColour') . ';';
if (!$this->isColourDark($this->getOption('baseColour'))) {
$additionalLessVariables[] = '@text-bg-base:rgba(0,0,0,0.84);';
}
}
// Update accent colour based on theme option
if ($this->getOption('accentColour') !== '#F7BC4A') {
$additionalLessVariables[] = '@accent:' . $this->getOption('accentColour') . ';';
}
if ($this->getOption('baseColour') && $this->getOption('accentColour')) {
$this->modifyStyle('stylesheet', array('addLessVariables' => join('', $additionalLessVariables)));
}
}
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName() {
return __('plugins.themes.manuscript-jats.name');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.themes.manuscript-jats.description');
}
}
?>
<?php
/**
* @file plugins/themes/default/DefaultManuscriptChildThemePlugin.inc.php
*
* Copyright (c) 2014-2017 Simon Fraser University Library
* Copyright (c) 2003-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
* Modyfied by Vitaliy Bezsheiko, MD
* @class DefaultManuscriptChildThemePlugin
* @ingroup plugins_themes_default_manuscript
*
* @brief Default theme
*/
import('lib.pkp.classes.plugins.ThemePlugin');
class ManuscriptJats extends ThemePlugin {
/**
* Initialize the theme's styles, scripts and hooks. This is only run for
* the currently active theme.
*
* @return null
*/
public function init() {
// Load additional template data
HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));
// Initialize the parent theme
$this->setParent('defaultthemeplugin');
$this->removeScript('jQueryTagIt');
$this->removeScript('popper');
$this->removeScript('bsUtil');
$this->removeScript('bsDropdown');
// Add bootstrap and jquery ui css
$this->addStyle('my-custom-style1', 'styles/bootstrap/bootstrap.min.css');
$this->addStyle('my-custom-style2', 'styles/bootstrap/bootstrap-theme.min.css');
$this->addStyle('my-custom-style3', 'jquery-ui/jquery-ui.min.css');
$this->addStyle('my-custom-style4', 'jquery-ui/jquery-ui.structure.min.css');
$this->addStyle('my-custom-style5', 'jquery-ui/jquery-ui.theme.min.css');
$this->addStyle('my-custom-style6', 'styles/article_detail.css');
// Add bootstrap and jquery ui javascript
//$this->addScript('my-javascript1', 'js/jquery.min.js');
//$this->addScript('my-javascript2', 'jquery-ui/jquery-ui.min.js');
$this->addScript('my-javascript3', 'js/bootstrap.min.js');
// Add custom styles
$this->modifyStyle('stylesheet', array('addLess' => array('styles/index.less')));
// Add custom menus
$this->addMenuArea(array('primary', 'user'));
// Remove the typography options of the parent theme.
// `removeOption` was introduced in OJS 3.0.2
if (method_exists($this, 'removeOption')) {
$this->removeOption('typography');
}
// Add the option for an accent color
$this->addOption('accentColour', 'colour', array(
'label' => 'plugins.themes.manuscript-jats.option.accentColour.label',
'description' => 'plugins.themes.default.option.colour.description',
'default' => '#F7BC4A',
));
// Load the Montserrat and Open Sans fonts
$this->addStyle(
'font',
'//fonts.googleapis.com/css?family=Montserrat:400,700|Noto+Serif:400,400i,700,700i',
array('baseUrl' => '')
);
// Dequeue any fonts loaded by parent theme
// `removeStyle` was introduced in OJS 3.0.2
if (method_exists($this, 'removeStyle')) {
$this->removeStyle('fontNotoSans');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSansNotoSerif');
$this->removeStyle('fontLato');
$this->removeStyle('fontLora');
$this->removeStyle('fontLoraOpenSans');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
}
// Start with a fresh array of additionalLessVariables so that we can
// ignore those added by the parent theme. This gets rid of @font
// variable overrides from the typography option
$additionalLessVariables = array();
// Update colour based on theme option from parent theme
if ($this->getOption('baseColour') !== '#1E6292') {
$additionalLessVariables[] = '@bg-base:' . $this->getOption('baseColour') . ';';
if (!$this->isColourDark($this->getOption('baseColour'))) {
$additionalLessVariables[] = '@text-bg-base:rgba(0,0,0,0.84);';
}
}
// Update accent colour based on theme option
if ($this->getOption('accentColour') !== '#F7BC4A') {
$additionalLessVariables[] = '@accent:' . $this->getOption('accentColour') . ';';
}
if ($this->getOption('baseColour') && $this->getOption('accentColour')) {
$this->modifyStyle('stylesheet', array('addLessVariables' => join('', $additionalLessVariables)));
}
}
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName() {
return __('plugins.themes.manuscript-jats.name');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.themes.manuscript-jats.description');
}
}
?>
you just add the two functions to the theme plugin: loadTemplateData and _cacheMiss, just like you did when you added them to the browseplugin file. Then you add the hook call I mentioned above to the init function.
This is hard to debug while I do not have a similar theme installed anywhere. But at least I think that you do not need the language selector part there. You could try this and if you still get a blank page then there is an error on the page I am not seeing only by looking at the code. You should see it in the error logs.
<?php
/**
* @file plugins/themes/default/DefaultManuscriptChildThemePlugin.inc.php
*
* Copyright (c) 2014-2017 Simon Fraser University Library
* Copyright (c) 2003-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
* Modyfied by Vitaliy Bezsheiko, MD
* @class DefaultManuscriptChildThemePlugin
* @ingroup plugins_themes_default_manuscript
*
* @brief Default theme
*/
import('lib.pkp.classes.plugins.ThemePlugin');
class ManuscriptJats extends ThemePlugin {
/**
* Initialize the theme's styles, scripts and hooks. This is only run for
* the currently active theme.
*
* @return null
*/
public function init() {
// Load additional template data
HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));
// Initialize the parent theme
$this->setParent('defaultthemeplugin');
$this->removeScript('jQueryTagIt');
$this->removeScript('popper');
$this->removeScript('bsUtil');
$this->removeScript('bsDropdown');
// Add bootstrap and jquery ui css
$this->addStyle('my-custom-style1', 'styles/bootstrap/bootstrap.min.css');
$this->addStyle('my-custom-style2', 'styles/bootstrap/bootstrap-theme.min.css');
$this->addStyle('my-custom-style3', 'jquery-ui/jquery-ui.min.css');
$this->addStyle('my-custom-style4', 'jquery-ui/jquery-ui.structure.min.css');
$this->addStyle('my-custom-style5', 'jquery-ui/jquery-ui.theme.min.css');
$this->addStyle('my-custom-style6', 'styles/article_detail.css');
// Add bootstrap and jquery ui javascript
//$this->addScript('my-javascript1', 'js/jquery.min.js');
//$this->addScript('my-javascript2', 'jquery-ui/jquery-ui.min.js');
$this->addScript('my-javascript3', 'js/bootstrap.min.js');
// Add custom styles
$this->modifyStyle('stylesheet', array('addLess' => array('styles/index.less')));
// Add custom menus
$this->addMenuArea(array('primary', 'user'));
// Remove the typography options of the parent theme.
// `removeOption` was introduced in OJS 3.0.2
if (method_exists($this, 'removeOption')) {
$this->removeOption('typography');
}
// Add the option for an accent color
$this->addOption('accentColour', 'colour', array(
'label' => 'plugins.themes.manuscript-jats.option.accentColour.label',
'description' => 'plugins.themes.default.option.colour.description',
'default' => '#F7BC4A',
));
// Load the Montserrat and Open Sans fonts
$this->addStyle(
'font',
'//fonts.googleapis.com/css?family=Montserrat:400,700|Noto+Serif:400,400i,700,700i',
array('baseUrl' => '')
);
// Dequeue any fonts loaded by parent theme
// `removeStyle` was introduced in OJS 3.0.2
if (method_exists($this, 'removeStyle')) {
$this->removeStyle('fontNotoSans');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSansNotoSerif');
$this->removeStyle('fontLato');
$this->removeStyle('fontLora');
$this->removeStyle('fontLoraOpenSans');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
$this->removeStyle('fontNotoSerif');
}
// Start with a fresh array of additionalLessVariables so that we can
// ignore those added by the parent theme. This gets rid of @font
// variable overrides from the typography option
$additionalLessVariables = array();
// Update colour based on theme option from parent theme
if ($this->getOption('baseColour') !== '#1E6292') {
$additionalLessVariables[] = '@bg-base:' . $this->getOption('baseColour') . ';';
if (!$this->isColourDark($this->getOption('baseColour'))) {
$additionalLessVariables[] = '@text-bg-base:rgba(0,0,0,0.84);';
}
}
// Update accent colour based on theme option
if ($this->getOption('accentColour') !== '#F7BC4A') {
$additionalLessVariables[] = '@accent:' . $this->getOption('accentColour') . ';';
}
if ($this->getOption('baseColour') && $this->getOption('accentColour')) {
$this->modifyStyle('stylesheet', array('addLessVariables' => join('', $additionalLessVariables)));
}
}
/**
* Get the display name of this plugin
* @return string
*/
function getDisplayName() {
return __('plugins.themes.manuscript-jats.name');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.themes.manuscript-jats.description');
}
/**
* Get the HTML contents for this block.
* @param $templateMgr object
* @param $request PKPRequest
*/
public function loadTemplateData($hookName, $args) {
$templateMgr = $args[0];
$request = Application::getRequest();
$context = $request->getContext();
// Start Most read
$metricsDao = DAORegistry::getDAO('MetricsDAO');
$cacheManager =& CacheManager::getManager();
$cache =& $cacheManager->getCache('mostread', $context->getId(), array($this, '_cacheMiss'));
$daysToStale = 1;
$cachedMetrics = false;
if (time() - $cache->getCacheTime() > 60 * 60 * 24 * $daysToStale) {
$cachedMetrics = $cache->getContents();
$cache->flush();
}
$resultMetrics = $cache->getContents();
if (!$resultMetrics && $cachedMetrics) {
$resultMetrics = $cachedMetrics;
$cache->setEntireCache($cachedMetrics);
} elseif (!$resultMetrics) {
$cache->flush();
}
$templateMgr->assign('resultMetrics', $resultMetrics);
// End Most read
}
function _cacheMiss($cache) {
$metricsDao = DAORegistry::getDAO('MetricsDAO');
$publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
$journalDao = DAORegistry::getDAO('JournalDAO');
$result = $metricsDao->retrieve("SELECT submission_id, SUM(metric) AS metric FROM metrics WHERE (day BETWEEN CURDATE()-INTERVAL 1 WEEK AND CURDATE()) AND (assoc_type='515' AND submission_id IS NOT NULL) GROUP BY submission_id ORDER BY metric DESC LIMIT 5");
while (!$result->EOF) {
$resultRow = $result->GetRowAssoc(false);
$article = $publishedArticleDao->getPublishedArticleByArticleId($resultRow['submission_id']);
$journal = $journalDao->getById($article->getJournalId());
$articles[$resultRow['submission_id']]['journalPath'] = $journal->getPath();
$articles[$resultRow['submission_id']]['journalName'] = $journal->getLocalizedName();
$articles[$resultRow['submission_id']]['articleId'] = $article->getBestArticleId();
$articles[$resultRow['submission_id']]['articleTitle'] = $article->getLocalizedTitle();
$articles[$resultRow['submission_id']]['metric'] = $resultRow['metric'];
$result->MoveNext();
}
$result->Close();
$cache->setEntireCache($articles);
return $result;
}
}
?>
That is odd. There could be numerous reasons for the error, but if the code itself has an error, then you should see fatal php error in the logs.
Now that it is working again, did you 1) edit the file again and remove the additions you made or 2) replaced the edited file with an original file without the changes.
Because if you did number 2, then maybe the way you save the changes to the file changes the file permissions or something similar? Again, hard to say without seeing.
I mean just try to pass the âThis is my custom data. It could be any PHP variable.â text to your front page template and show it there. If you are getting the same problems with a simple code like that, then the problem is not probably the code itself but something different.
Yes! It is easier to debug when you start by sending something simple. I mean the code is made for a site level theme plugin so there could be something I am not seeing which would create problems with a journal level theme plugin.
he estado mirando el codigo y depurando en consola y el problema esta
PHP Fatal error: Uncaught Error: Call to undefined method PublishedArticleDAO::getPublishedArticleByArticleId() cuando hacemos esa llamada, si quisieran ayudar por favor, me sucede lo mismo como podemos arreglar esta llamada