Run php script in Custom Block Manager (OJS 3.0.2.0, Native Child Theme)

Hi @NateWr

We are using your child theme (https://github.com/NateWr/default-manuscript). Thank you for this theme, it`s really nice and usefull for me.

I would like to know if it is possible to run a php script in the Custom Block Manager. I would like to have on my right sidebar a Custom Block with fotos which are randomly displayed. Selected fotos I already uploaded to a specific folder. I used this php skript in a created Custom Block:

<?php // Wählen Sie das Verzeichnis $verz = opendir ('/public/site/images/.....'); // Hier werden die Bilder in einen Array eingelesen $bildarray = array(); // Bilder werden nicht wiederholt while ($file = readdir ($verz)) { if (!is_dir($file)) { array_push($bildarray, $file); } } closedir($verz); // Die Zahl 3 gibt an, wieviele Bilder aus dem Bildordner angezeigt werden sollen. $rand_var = array_rand($bildarray, 3); for($x = 0; $x < count($rand_var); $x++) { echo ""; } ?>

But unfortunatly nothing happens. It es possible?

Hi again,

You can not enter php code that way, it would be a security issue to allow that.

You could create a new custom block plugin. See for example https://github.com/pkp/ojs/tree/master/plugins/blocks/languageToggle

Unfortunately, there are no detailed instructrions available for plugin development. But basically you just need take a copy of an existing plugin, rename the folder, the filenames and the names also inside the files.

Then you add the basic functionality here: https://github.com/pkp/ojs/blob/master/plugins/blocks/languageToggle/LanguageToggleBlockPlugin.inc.php#L90

And then edit the template file which shows the ouput: https://github.com/pkp/ojs/blob/master/plugins/blocks/languageToggle/block.tpl

2 Likes