Joined: Jun 2008
Posts: 92
Likes: 1
Journeyman
Journeyman
Joined: Jun 2008
Posts: 92
Likes: 1
I'm creating a small class in Control Panel > Display > General > Default Header When I use this class in Control Panel > Content > Forums > Forum Introduction Body The class is "not found". I tried making a static class (having all static members) and it was also not found. Wouldn't the static class be globally available during the entire request? How can I create a globally-available class for inserting some custom code? Thanks in advance for help
Last edited by mmem700; 01/31/2019 5:54 PM .
Today they call you "crazy". Tomorrow they call you "ahead of your time".
Joined: Apr 2004
Posts: 1,945
Likes: 145
Joined: Apr 2004
Posts: 1,945
Likes: 145
Im not sure I fully understand your question , but I'd like to bring a few things up in case they are related to what you are asking:
Headers and footers are called from within the Smarty 3.1 templates which display the pages.
note1: You cannot insert {php} or {include_php} in the templates - I believe this also affects the PHP global keyword.
SOURCE:
https://www.ubbcentral.com/forums/u...e-ubb-threads-7-7-0-changelog#Post261732 [UPDATE] Removed the 2.x backwards compatibility from the Smarty library. This means faster pages all around. It also means that if you you've customized your templates to use {php} or {include_php} functions, you'll need to move those items in to your php scripts.
note2: For using JavaScript within your templates, your braces need to have spaces on either side of them, so as to not be confused by Smarty 3, as being Smarty script commands.
Anything relating to custom Smarty 3.1 code can be researched at
https://www.smarty.net.
Joined: Jun 2008
Posts: 92
Likes: 1
Journeyman
Journeyman
Joined: Jun 2008
Posts: 92
Likes: 1
I'm doing something like this in the
Control Panel > Display > General > Default Header
field...
<?php
class myclass {
public static function GetAPath () {
return '/web/vhosts/orbisvitae.com/htdocs/Header.html' ;
}
}
?>
and then using the class in
Control Panel > Content > Forums > Forum Introduction Body
<?php
$x = myclass :: GetAPath ();
?>
But PHP is responding saying the class is not available when calling
$x = myclass::GetAPath();
Today they call you "crazy". Tomorrow they call you "ahead of your time".
Joined: Apr 2004
Posts: 1,945
Likes: 145
Joined: Apr 2004
Posts: 1,945
Likes: 145
It probably has something to do with security. You are attempting to run php within the Smarty 3.1 templates.
Again, you may want to look at moving your custom code in to the php scripts, and out of the templates. Thats the advice directly from Smarty 3.1
"Put your PHP logic in PHP scripts or plugin functions instead"
https://www.smarty.net/docs/en/language.function.php.tpl
Joined: Apr 2004
Posts: 1,945
Likes: 145
Joined: Apr 2004
Posts: 1,945
Likes: 145
if your custom code worked in the old UBB.threads 7.5.x or 7.6.x, but not in UBB.threads 7.7.x, then its 100% related to Smarty 3.1 security. UBB.threads 7.7.x removes SmartyBC (Smarty 2.x Backwards Compatibility) in favor of using the current pure version, Smarty 3.1. But if you are still on the old UBB.threads 7.5.x or 7.6.x, then I dont have an answer.
Last edited by isaac; 01/31/2019 6:35 PM . Reason: fixed typos
Joined: Jun 2008
Posts: 92
Likes: 1
Journeyman
Journeyman
Joined: Jun 2008
Posts: 92
Likes: 1
OK... We just upgraded to 7.7.0 and are reorganizing things to make management easier because we run 2 forums. I didn't realize that code placed in these textboxes (screencap below) were within the smarty templates. So, is it still OK to have PHP in the "Default Header" field? If so, that will still be useful. Thanks for the help.
Attachments
Last edited by mmem700; 01/31/2019 6:40 PM .
Today they call you "crazy". Tomorrow they call you "ahead of your time".
Joined: Apr 2004
Posts: 1,945
Likes: 145
Joined: Apr 2004
Posts: 1,945
Likes: 145
I didn't realize that code placed in these textboxes (screencap below) were within the smarty templates. So, is it still OK to have PHP in the "Default Header" field? If so, that will still be useful.
I guess it is still is ok to have php there -
But you are trying to communicate between the two. That's ultimately where I believe you are being blocked at. Especially after reading:
Wouldn't the static class be globally available during the entire request? How can I create a globally-available class for inserting some custom code?
If your custom code worked in the old UBB.threads 7.5.x or 7.6.x, but not in UBB.threads 7.7.x, then its 100% related to Smarty 3.1 security.
Joined: Jun 2006
Posts: 16,301
Likes: 116
Joined: Jun 2006
Posts: 16,301
Likes: 116
Looking at your code, if you're just trying to include an external page to pull layout elements (like what I have
here ) you can simply use a PHP include like:
<?php include($_SERVER["DOCUMENT_ROOT"] ."/includes/header.forum.inc.php"); ?> If I'm reading your code correctly you might be trying to include one header for two sites which may belong to different users on the machine, which could have any number of problems (such as permissions on the server); I'd advise you keep any includes local to every user, versus attempting to use only one file for various user accounts.
Joined: Jun 2008
Posts: 92
Likes: 1
Journeyman
Journeyman
Joined: Jun 2008
Posts: 92
Likes: 1
Thanks for that. I ended up just placing an include() near the top of the ubbthreads.php file. This includes a class that I wrote for adding a bit of functionality here and there and to stay organized. It's working well. I will remember to re-insert it after each upgrade. Thanks again.
Today they call you "crazy". Tomorrow they call you "ahead of your time".
2 members (Ruben , ahmed047 ),
776
guests, and
161
robots.
Key:
Admin ,
Global Mod ,
Mod