Add PHP code in sidebar plugin

Post Reply
User avatar
Powerack
Ssr. Bludit
Posts: 12
Joined: Sat Jul 31, 2021 8:00 pm
Location: Prague
Contact:

Hello again!

I am sure somewhere here may be solution for my little problem, but I think tat's better post new topic for it, because I really can't find it... :(

I was trying include PHP code in different areas in Bludit with that I only add somewhere

Code: Select all

<?php echo 'Number of directories in location is '.$directorycount; ?>
<?php echo 'Number of files in location is '.$filescount; ?>


and it will show the string I needed. I aiming to sidebar area where I expecting few strings to be shown. My first goal is count files in one directory separated from bludit, but on same domain. My script worked on other pages, but when I tried include it to Bludit, I'we seen only code itself or nothing.

Is there any plugin or anything where I just put my PHP code, it solve little counting and show number I'm looking for?

Tried: "About", "HTML Code" and "Textarea" plugins. Even tried modify them. Nothing works.

Before you ask, I am trying to create thing that counts directories in specified location and files in another specified location, store them into strings and remember it for further use.
Working on powerack.cz | Bludit 3.14.1 & extremely modified Blog X
I am guy. Don't think about my profile image too much.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

Add the code to the template sidebar of your theme.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
Powerack
Ssr. Bludit
Posts: 12
Joined: Sat Jul 31, 2021 8:00 pm
Location: Prague
Contact:

Well I helped myself with this. I opened one of easy plugins, replaced all neccessary codes with mine. It will be much better, if I actually can use textbox to update all I want, but I have access to my server anytime and can change everything in matter of seconds.

Here is the code I updated:

Code: Select all

<?php

class pluginCustomPHP extends Plugin {

	public function init()
	{
		$this->dbFields = array(
			'label'=>'Custom PHP by Powerack',
			
		);
	}

	public function form()
	{
		global $L;

		// Show the description of the plugin in the settings
		$html  = '<div class="alert alert-primary" role="alert">';
		$html .= $this->description();
		$html .= '</div>';

		// Label of the plugin to show in the sidebar
		$html .= '<div>';
		$html .= '<label>'.$L->get('Label').'</label>';
		$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">';
		$html .= '<span class="tip">'.$L->get('This title will be used as defaulf if not changed').'</span>';
		$html .= '</div>';

		return $html;
	}

	public function siteSidebar()
	{
		// RESET VALUES BEFORE CONTINUE
		$filecount = 0;
		$totalgames = 0;
		$totalvns = 0;
		$onlinegames = 0;

		// COUNT TOTAL GAMES IN DOWNLOAD FOLDER
		$gamesdir = "./games/";
		$games = glob($gamesdir . "*");
		$totalgames = count($games) -1; // minus one dir with data

		// COUNT TOTAL ONLINE PLAYABLE GAMES
		$playdir = "./play/";
		$playgames = glob($playdir . "*");
		$onlinegames = count($playgames);

		// MESSAGE BEFORE PLUGIN
		$messagebefore = 'Message before code:';

		// MESSAGE AFTER PLUGIN
		$messageafter = 'Message after code';
		
// ALL OF THIS WILL NEED SOME REWRITE AFTER I FINISH OTHER THINGS, BUT IT WORKING FOR NOW SO DON'T NEED IMPROVEMENTS RIGHT NOW.		
		
		// SHOW IN THE SIDEBAR FOLLOWING CONTENT
		$html  = '<div class="plugin plugin-custom-php">';
		$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>';
		$html .= '<div class="plugin-content">';
		$html .= '<div class="custom-php bsh mid">'.$messagebefore.'<br><br><span class="yellow">'.$totalgames.'</span><span class="rsh"> visual novels for <a href="https://txlair.eu/games">download</a><br><span class="yellow bsh">'.$onlinegames.'</span><span class="rsh"> visual novels for <a href="https://txlair.eu/play-now">play online</a></span><br><br>'.$messageafter.'</div>';
 		$html .= '</div>';
 		$html .= '</div>';

		return $html;
	}
}
I have massively restyled theme (Blog X) so I added my styling in plugin instead of updating stylesheet.
Working on powerack.cz | Bludit 3.14.1 & extremely modified Blog X
I am guy. Don't think about my profile image too much.
Post Reply