How to add most read topics in ojs 3.1?

Thanks for the help.

So, I read up a bit more with the help of @ctgraham and it seems that I missed out on other similar functions for PublishedArticle like getAuthorString().

I was able to obtain the data set I needed using:
$articles[$resultRow['submission_id']]['articleAuthors'] = $article->getAuthorString();

Thanks for both your help.

1 Like

Great, did not know that one.

Dear @ajnyga
We want to add published date and author information on the plugin. We tried adding this <div class="date_published"><span class="fa fa-calendar"></span>{$article->getDatePublished()|date_format:"%Y-%m-%d"}</div>but did work. Some sidebar got lost

<ul class="most_read">
		{foreach from=$resultMetrics item=article}
			<li class="most_read_article">
				<div class="most_read_article_title"><a href="{url journal=$article.journalPath page="article" op="view" path=$article.articleId}">{$article.articleTitle}</a></div>
				<div class="most_read_article_journal"><span class="fa fa-eye"></span> {$article.metric}</div>
				<div class="date_published"><span class="fa fa-calendar"></span>{$article->getDatePublished()|date_format:"%Y-%m-%d"}</div>
				
			</li>
		{/foreach}	
		</ul>

Did you check the error log?

Here is the error log

PHP Fatal error: Call to a member function getDatePublished() on array in /home/k2542002/public_html/cache/t_compile/426c7901dcce1f7ee6c5842275c71ac3c37e88d9^%%E7^E75^E7569244%%mostRead%3Ablock.tpl.php on line 20

Yeah the plugin does not send an object to the template.

You can add a new array value to the cachmiss function mostRead/MostReadBlockPlugin.inc.php at master · ajnyga/mostRead · GitHub
and then call that in the template the same way the other values are called.

I tried adding this $articles[$resultRow['submission_id']]['DatePublished'] = $article->getDatePublished(); to line 95 and. <div class="date_published"><span class="fa fa-calendar"></span>{$article->getDatePublished()|date_format:"%Y-%m-%d"}</div>to the block.tpl
The sidebar got lost all.
This is what I understand to your hint. Sorry, I am a newbie in coding

It is weird, I cannot get back my sidebar, even I deleted the plugin. And I could not access the Administration as admin and could not change theme. I save default theme but turn back to the current theme
https://jurnalbeta.ac.id

Try this in the template: {$article.DatePublished}

Compare how $article.metric is set here mostRead/MostReadBlockPlugin.inc.php at master · ajnyga/mostRead · GitHub and called here https://github.com/ajnyga/mostRead/blob/master/block.tpl#L17

1 Like

Thanks @ajnyga

Could you make a suggestion to this?
The footer get lost as well

I would try clearing the OJS cache, *.php from cache and cache/t_compile. And if you just deleted the plugin from plugins/block/ by deleting the folder, then it is probably a good idea to upload it again using the unmodified original version.

1 Like

you mean all .php file in public_html/cache and public_html/cache/t_compile should be deleted?

I tried deleting all .php file but the site went blank at all. I also tried changing with new ojs files, it got blank as well. So, I turn back to the old ojs files. Sidebar and footer are still missing

I tried set config.inc.php to off, I got the following errors

**Warning** : file_put_contents(/home/k2542002/public_html/cache/fc-locale-8c15ce7dfec31e437114d80f1f936272.php): failed to open stream: Permission denied in  **/home/k2542002/public_html/lib/pkp/classes/cache/FileCache.inc.php**  on line  **90**

**Deprecated** : Non-static method Application::getName() should not be called statically, assuming $this from incompatible context in  **/home/k2542002/public_html/lib/pkp/classes/install/form/InstallForm.inc.php**  on line  **149**

**Deprecated** : Non-static method Application::getName() should not be called statically, assuming $this from incompatible context in  **/home/k2542002/public_html/lib/pkp/classes/install/form/InstallForm.inc.php**  on line  **151**

**Deprecated** : Non-static method Application::getName() should not be called statically, assuming $this from incompatible context in  **/home/k2542002/public_html/lib/pkp/classes/install/form/InstallForm.inc.php**  on line  **153**

**Deprecated** : Non-static method VersionCheck::getCurrentCodeVersion() should not be called statically, assuming $this from incompatible context in  **/home/k2542002/public_html/lib/pkp/classes/install/form/MaintenanceForm.inc.php**  on line  **37**

**Deprecated** : Non-static method PKPRequest::getUserVar() should not be called statically, assuming $this from incompatible context in  **/home/k2542002/public_html/lib/pkp/classes/form/Form.inc.php**  on line  **369**

**Deprecated** : Non-static method PKPRequest::_checkThis() should not be called statically, assuming $this from incompatible context in  **/home/k2542002/public_html/lib/pkp/classes/core/PKPRequest.inc.php**  on line  **592**

**Warning** : Cannot modify header information - headers already sent by (output started at /home/k2542002/public_html/lib/pkp/classes/cache/FileCache.inc.php:90) in  **/home/k2542002/public_html/lib/pkp/classes/template/PKPTemplateManager.inc.php**  on line  **867**

**Warning** : Cannot modify header information - headers already sent by (output started at /home/k2542002/public_html/lib/pkp/classes/cache/FileCache.inc.php:90) in  **/home/k2542002/public_html/lib/pkp/classes/template/PKPTemplateManager.inc.php**  on line  **868**

**Fatal error** : Smarty error: unable to write to $compile_dir '/home/k2542002/public_html/cache/t_compile'. Be sure $compile_dir is writable by the web server user. in  **/home/k2542002/public_html/lib/pkp/lib/vendor/smarty/smarty/libs/Smarty.class.php**  on line  **1094**

Dear @ajnyga
We have restored the backup ojs file. The web is back to normal. I wonder, how could the trial of customizing plugin codes affect the other elements of OJS as we have experienced?

Hi,

For me it sounds like your cache folder was not writable “Fatal error : Smarty error: unable to write to $compile_dir”. Restoring a backup also restored the folder permissions.

Editing a plugin code does not affect folder permissions so I am not sure what has happened.

But when you experimented with the plugin and added a call to an object it created an error and the rest of the sidebar disappeared. Removing the block would had solved this together with emptying the cache, but the new cache file’s could ne be written so you ended up with a blank page.

I usually test changes to plugins using a local test installation. OJS is very easy to install using for example XAMP.

This should be actually. The cache folder permission is 0755 along with contained folders. How to make it writable?

See How should file permissions be set?

It is a bit different depending on your server.

1 Like

@ajnyga How is the $article.metric updated? I implemented this on an ojs server, but the view count stays the same after multiple views.

it has a 24 hour cache