Use PHP in entries

This is the right place to report general bugs, make suggestions or ask for help.
Lubomír Ludvík
Posts: 44
Joined: Wed Feb 20, 2019 7:44 pm
Location: Rouchovany
Contact:

Re: Use PHP in entries

Post by Lubomír Ludvík » Tue Feb 16, 2021 10:47 am

Tongara: Move to the previous page

Code: Select all

[html]<a href="javascript:history.back(1)">Back</a>[/html]
dsteuer: autor is ChrisBlank https://wiki.flatpress.org/res:plugins: ... #inlinephp

dsteuer
Posts: 48
Joined: Sun May 24, 2020 11:21 am

Re: Use PHP in entries

Post by dsteuer » Tue Feb 16, 2021 11:18 am

Oh, ok, corrected. I even looked at the legacy page but missed it.

You have linked a version 1.8.2 for download, on the legacy page there is 1.0. Can you say, where do you have 1.8.2 from, because Chris' page has gone
from the nets.

Lubomír Ludvík
Posts: 44
Joined: Wed Feb 20, 2019 7:44 pm
Location: Rouchovany
Contact:

Re: Use PHP in entries

Post by Lubomír Ludvík » Tue Feb 16, 2021 11:40 am

Sorry, I compare "version" and all is 1.0

Tongara
Posts: 77
Joined: Wed Jan 22, 2020 11:09 am
Location: Birmingham, UK
Contact:

Re: Use PHP in entries

Post by Tongara » Wed Feb 17, 2021 6:26 am

Lubomír Ludvík wrote: Tue Feb 16, 2021 10:47 am Tongara: Move to the previous page

Code: Select all

[html]<a href="javascript:history.back(1)">Back</a>[/html]
Haha I am well aware on how to create a back link in Javascript. If you read my post again, that is not exactly what I am trying to do here. It is appreciated, though.

Will put here again, just in case anyone misses it in all the other discussion.
Tongara wrote: Mon Feb 15, 2021 9:03 am With how my website is set up, I wanted the option of adding a custom "Back" link to Static pages much like you see on the main news post pages and index page of flatpress. The idea would be that the static.tpl would contain a line of code for the back button, and it would somehow grab it's code from elsewhere on a static page using a PHP echo so that I could define the target URL on the fly.

So, on the static template the "a href" would work something like this:

Code: Select all

<a href="<?php echo $link;?>">Back</a>
Then of course comes the plugin code, which can be seen in the following file:
https://mega.nz/file/8lgXDSSL#dKqbPuJYp ... v8vjcLJgYY

Then based on the code above, I define the actual link on a Static page in the following way:

Code: Select all

[pagelinks]pagename[/pagelinks]
Sadly, the URL never gets defined, and as such the URL ends up as "mysite.com/<?php%20echo%20$link;?>" instead of "mysite.com/pagename".

I've made sure the plugin is enabled, and I can see in the site's header that the plugin is loaded on the page. I'm sure I'm just missing something really small and I'm going to feel like an idiot when it's pointed out what I'm doing wrong, but the forums are here to help support us, so I'm looking forward to feel foolish! haha

Maybe there is a better way than using PHP for this task? I'm open to ideas!

User avatar
Arvid
FlatPress Coder
Posts: 555
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Use PHP in entries

Post by Arvid » Sat Feb 20, 2021 12:21 pm

Tongara wrote: Mon Feb 15, 2021 9:03 am Sadly, the URL never gets defined, and as such the URL ends up as "mysite.com/<?php%20echo%20$link;?>" instead of "mysite.com/pagename".
You need to tell your plugin to assign Smarty variables.

Code: Select all

function yourFunction() {
	global $smarty;
	$smarty->assign('yourvariable', 'some value');
These can then be used in the templates:

Code: Select all

<a href="{$yourvariable}">Back</a>


Lubomír Ludvík wrote: Mon Feb 15, 2021 2:09 pm plugin inlinephp
http://flatpress.cz/flatpress/fp-plugin ... inephp.zip

Code: Select all

[exec]echo(rand(10,100));
echo PHP_VERSION;[/exec]
This might look like an easy time saver, but be aware that this opens a complete new dimension of risk.
If I manage to get into your admin account, the most evil I can do is destroying your blog's content (deleting entries and files, changing config etc.). Just exactly the functions FlatPress and its plugins provide.
But if you have this plugin enabled, I could use every function of PHP to break out of your FP instance and f**k up your server, or to set up my own malware on it, e.g. a spam relay or phishing sites.
I strongly advise against using such a plugin. Instead, build your plugin that does exactly what you need, but nothing more.

Maybe we should add this warning to the wiki page as well.


dsteuer wrote: Tue Feb 16, 2021 9:36 am Arvid: There is a superfluous copy in res:plugins. Looks like only admin can remove files after upload.
Found a few files there ;) These two can be deleted?

Tongara
Posts: 77
Joined: Wed Jan 22, 2020 11:09 am
Location: Birmingham, UK
Contact:

Re: Use PHP in entries

Post by Tongara » Sat Feb 20, 2021 6:29 pm

Arvid wrote: Sat Feb 20, 2021 12:21 pm You need to tell your plugin to assign Smarty variables.

Code: Select all

function yourFunction() {
	global $smarty;
	$smarty->assign('yourvariable', 'some value');
These can then be used in the templates:

Code: Select all

<a href="{$yourvariable}">Back</a>
Would I still be able to set what that variable is on a per static page basis (as my code awas attempting to allow me), or would it just be the same variable every time? Because the former is the desired behaviour.

I'm also a bit overwhelmed about how to add such to my existing code, so any advice with the code I've posted would be super.

dsteuer
Posts: 48
Joined: Sun May 24, 2020 11:21 am

Re: Use PHP in entries

Post by dsteuer » Sun Feb 21, 2021 11:26 am

Arvid wrote: Sat Feb 20, 2021 12:21 pm [
dsteuer wrote: Tue Feb 16, 2021 9:36 am Arvid: There is a superfluous copy in res:plugins. Looks like only admin can remove files after upload.
Found a few files there ;) These two can be deleted?
Yes. Those were my mistakes.

Detlef

User avatar
Arvid
FlatPress Coder
Posts: 555
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Use PHP in entries

Post by Arvid » Mon Feb 22, 2021 6:13 pm

Tongara wrote: Sat Feb 20, 2021 6:29 pm Would I still be able to set what that variable is on a per static page basis (as my code awas attempting to allow me), or would it just be the same variable every time? Because the former is the desired behaviour.

I'm also a bit overwhelmed about how to add such to my existing code, so any advice with the code I've posted would be super.
Unfortunately, I am too short of time atm to build working example code :(
For now, please inspect how other plugins utilize Smarty variables. It's easy to find, they all call $smarty->assign().

It would be great to have some sort of tutorial on how to develop plugins and use Smarty one day. I put that on my list.

dsteuer wrote: Sun Feb 21, 2021 11:26 amYes.
Done 8-)

Tongara
Posts: 77
Joined: Wed Jan 22, 2020 11:09 am
Location: Birmingham, UK
Contact:

Re: Use PHP in entries

Post by Tongara » Fri Feb 26, 2021 11:40 pm

Fair enough. I think I'll just focus on my blog content for now and maybe come back to this at some point in the future.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests