Work Around for deprecation of PHP INCLUDE

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
Frank Rizzo
Registered User
Posts: 144
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Work Around for deprecation of PHP INCLUDE

Post by Frank Rizzo »

Firstly forgive me for posting in the wrong section (I assume this is where this post should go) and if there is already a post on this (I tried search but searching for PHP and / or INCLUDE finds too many posts because they are generic search terms).

I am looking for a solution to the deprecation of PHP including.

I replied to the 3.3.8 discussion topic stating that my template files have many, many PHP includes such as:

Code: Select all

<!-- PHP -->
if($_SESSION['valid_subscription'] == 1) {
	// display forum here
} else {
	echo '<div class="alert alert-warning"><h4>This section is for subscribers only</h4></div>';
}
</-- ENDPHP -->
I was informed to post in the appropriate section, which I believe is here.

So what's the solution? How do I set up a "small extension that employs our events system"?

Note this is my own dedicated server, not shared and I am aware why PHP including is deprecated. But I 100% need this facility because my forum is so integrated with the main site.
User avatar
david63
Registered User
Posts: 20614
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by david63 »

Can you not create a template variable in the appropriate .php file and then pass that to the appropriate template file?

In the example above if you do your test in a php file (possibly where the header is defined) and create, say, SESSION_VALID then pass that to the template you would have

Code: Select all

{% if SESSION_VALID %}
	// display forum here
{% else %}
	<div class="alert alert-warning"><h4>This section is for subscribers only</h4></div>
{% endif %}
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
Frank Rizzo
Registered User
Posts: 144
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by Frank Rizzo »

Ok, that looks a good solution. I should be able to get that sorted.

One other issue I have is that my forum sits within a overall website menu theme. i.e. I have a site menu bar at the top and the forum is in the middle of the page. This is done using this code in the overall_header.html file:

Code: Select all

<!-- PHP -->
	include('/home/example/public_html/sitetheme_menubar.php');
<!-- ENDPHP -->
That will not work in 3.3.8 so I copied the sitetheme_menubar.php file to the template directory and did this:

Code: Select all

<!-- INCLUDE sitetheme_menubar.php -->
That file is included and partially rendered. However, there is PHP code in the file to determine if the visitor has logged in or not to the main site. This does not run and just displays the php code text.

How can I get the php in the sitetheme_menbar.php to run?
User avatar
david63
Registered User
Posts: 20614
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by david63 »

Can you post the contents of sitetheme_menubar.php
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
Frank Rizzo
Registered User
Posts: 144
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by Frank Rizzo »

Here's an abridged version

Code: Select all

<?php if(empty($code) || ($code <> 'a' && $code <> 'b' && $code <> 'c')) include('/home/example/php_incs2/a.php'); ?>

  <!-- ======= Header ======= -->
  <header id="header" class="header fixed-top" data-scrollto-offset="0">
	<div class="container d-flex justify-content-between">

      <a href="/" class="logo scrollto me-auto me-lg-0"><h1>Exa<span>mple</span></h1></a>

      <nav id="navbar" class="navbar navbar-expand-lg">
        <ul>
          <li class="dropdown"><a href="#"><span>Popular</span></a>
            <ul class="shadow">
		<li><a class="dropdown-item" href="/xyz1.php">Example 1</a></li>
		<li><a class="dropdown-item" href="/xyz2.php">Example 2</a></li>
		<li><a class="dropdown-item" href="/xyz3.php">Example 3</a></li>
            </ul>
          </li>


	<li class="dropdown megamenu"><a href="#"><span>Produce</span></a>
            <ul class="shadow">
              <li>
		<h6 class="mega-title">Fruit</h6>
		<hr class="mx-3 color-secondary">
		<a href="/<?php echo $code; ?>/apples/">Apples</a>
		<a href="/<?php echo $code; ?>/pears/">Pears</a>
		<a href="/<?php echo $code; ?>/oranges/">Oranges</a>
              </li>


<?php				
if($subscriber_loggedin == 1) {
?>

	<li class="dropdown"><a class="dropdown-item" href="#"><i class="bi bi-person"></i></a>
		<ul class="shadow dropdown-menu">
			<li class="pb-2 ps-4"><h6 class="text-overflow"><?php echo $subscriber_username; ?></h6></li>
			<li><hr class="dropdown-divider"></li>
			<li><a class="dropdown-item" href="/settings/user-control-panel"><i class="bi bi-gear me-2"></i>Settings</a></li>
			<li><a class="dropdown-item" href="/settings/profile"><i class="bi bi-person-circle me-2"></i>My Account</a></li>
			<li><a class="dropdown-item" href="/sitelogout.php"><i class="bi bi-power me-2"></i>Logout</a></li>
		</ul>
	</li>


<?php
} else {
?>

        <li data-bs-toggle="modal" data-bs-target="#signin-modal"><a href="#"><i class="bi bi-person me-2"></i>Login / Subscribe</a></li>

<?php
}
?>
Basically it's a menu header, with mega menu and some code in there to display either the subscriber is already logged in menu, or if not logged in then the login link (as in for the main site not the forum).
User avatar
david63
Registered User
Posts: 20614
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by david63 »

I cannot tell where $code is coming from but again if you can deal with that in a .php file and pass CODE, or whatever you want to call it, to the template then you can use a include to add the rest of that file (just remove the PHP and name it as a .html file.

That then just leaves the a.php file and I cannot help with that as i do not know what it is/does.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
Frank Rizzo
Registered User
Posts: 144
Joined: Sun Jan 05, 2003 11:10 pm
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by Frank Rizzo »

OK, I think I get this now.

I need to set template variables in the corresponding forum root files and then in the templates themselves detect what the variables are set and include the relevant file.

This would be the case for your example

Code: Select all

{% if SESSION_VALID %}
	// display forum here
{% else %}
	<div class="alert alert-warning"><h4>This section is for subscribers only</h4></div>
{% endif %}
and I can use similar for in my abridged sitetheme_menubar.php

Code: Select all

<?php				
if($subscriber_loggedin == 1) {
?>

	<li class="dropdown"><a class="dropdown-item" href="#"><i class="bi bi-person"></i></a>
		<ul class="shadow dropdown-menu">
			<li class="pb-2 ps-4"><h6 class="text-overflow"><?php echo $subscriber_username; ?></h6></li>
			<li><hr class="dropdown-divider"></li>
			<li><a class="dropdown-item" href="/settings/user-control-panel"><i class="bi bi-gear me-2"></i>Settings</a></li>
			<li><a class="dropdown-item" href="/settings/profile"><i class="bi bi-person-circle me-2"></i>My Account</a></li>
			<li><a class="dropdown-item" href="/sitelogout.php"><i class="bi bi-power me-2"></i>Logout</a></li>
		</ul>
	</li>


<?php
} else {
?>

        <li data-bs-toggle="modal" data-bs-target="#signin-modal"><a href="#"><i class="bi bi-person me-2"></i>Login / Subscribe</a></li>

<?php
}
?>

That would become:

Code: Select all

{% if SUBSCRIBER_LOGGEDIN %}
	<!-- INCLUDE logged_in.html --> //this is a file containing the logged in menu drop down, i.e. links to the subscriber account, options
{% else %}
	<!-- INCLUDE not_logged_in.html --> //this is a file containing the 'Login' drop down box
{% endif %}
As for the $code stuff. This is used to control what can be seen on the menu. If on a previous page a visitor has selected say Vegan then they will not see meat items on the menu. If they select Meat, they don't see vegan etc. I guess I can use the template vars for that too.
User avatar
david63
Registered User
Posts: 20614
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Work Around for deprecation of PHP INCLUDE

Post by david63 »

It may be a bit advanced for you but a lot of what you are trying to do can actually be done in Twig as it has a lot of built in functionality.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
Post Reply

Return to “phpBB Custom Coding”