PHP Includes

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
sporto
Posts: 160
Joined: Mon 10. Nov 2003, 18:01
Location: USA, Chicago

PHP Includes

Post by sporto »

I'm confused. I haven't updated to the latest release yet, but I don't understand what you write about PHP includes.
the PHP replacement tag for including external PHP files or HTML snippits (or any normal text file) is no longer processed as last.
Does this mean that there is no way to include external PHP files? If so, I think that is a loss. I think that was an important feature. And if so, why did you remove this? Now, maybe I just didn't understand correctly.

thanks for your help.
Rylas
Posts: 9
Joined: Fri 7. Nov 2003, 16:17

Post by Rylas »

Oliver did not replace this, you must simply use:

{PHP:my_script.php}

inside one of your templates, just like the documentation quotes:
{PHP:my_external.php}
All output of "my_external.php" script will be inserted. This is very powerful. You can use any availabe content var of phpwcms for your script or connet to other external sources.
Sample: <?php echo PHP_VERSION." // date: ".date("Y-m-d"); ?> =
output: 4.3.3 // date: 2003-11-17
MarcoB
Posts: 30
Joined: Thu 13. Nov 2003, 03:30
Contact:

Post by MarcoB »

i am confused.... when i post data to a include script, it's not using the cms format when outputting the data, i'm posting it to index.php is that not right ?

http://www.silver.nl/index.php
Professional webhosting...
http://www.silver.nl - sales@silver.nl
Rylas
Posts: 9
Joined: Fri 7. Nov 2003, 16:17

Post by Rylas »

I see what your saying, your trying to use POST from the script you included to show the script again with the test results while still showing the CMS layout and functions, this could very well be an issue.

I havent experimented with this tag yet, as im sure there is a way to include at least the header and the footer inside the script when you execute it, let me look at the code real quick and see if I can find a solution...

*looks*

Ok I found a solution, but it is not for newbies.

In index.php (from the phpwcms core), you need to basically separate it into two files, header.php and footer.php, both being in your base phpwcms directory.

Copy the following to header.php:

Code: Select all

<?php
/*************************************************************************************
   Copyright notice
   
   (c) 2002-2003 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
 
   This script is part of PHPWCMS. The PHPWCMS web content management system is
   free software; you can redistribute it and/or modify it under the terms of
   the GNU General Public License as published by the Free Software Foundation;
   either version 2 of the License, or (at your option) any later version.
  
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license 
   from the author is found in LICENSE.txt distributed with these scripts.
  
   This script is distributed in the hope that it will be useful, but WITHOUT ANY 
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/


// this is for testing only
// returns how long this script is processed
// remove comments // to use this - look at the end of this
// page too
//
// require ("include/inc_lib/ext/phpsniff/phpTimer.class.php");
// $timer =& new phpTimer();
// $timer->start('main');



require_once ("include/inc_conf/conf.inc.php");
require_once ("include/inc_lib/default.inc.php");
require_once ("include/inc_conf/conf.pagelayout.inc.php");
require_once ("include/inc_conf/conf.template_default.inc.php");

require_once ("include/inc_lib/general.inc.php");
require_once ("include/inc_front/front.func.inc.php");
require_once ("include/inc_front/content.func.inc.php");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--

phpwcms | open source web content management system

          developed by Oliver Georgi (webverbund.de)
          released under The GNU General Public License
          visit project page: http://www.phpwcms.de

//-->
<html>
<head>
<title><?php echo $content["pagetitle"] ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php echo $block["htmlhead"] ?>
<script src="<?php echo ".".$phpwcms["templates"] ?>inc_js/frontend.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo ".".$phpwcms["templates"]."inc_css/".$block["css"] ?>">
</head>

<body <?php echo $content["body"] ?>>
<?php

if (basename($PHP_SELF) == "index.php") {
  echo $content["all"];
} else {
  do_action();
}
save that to header.php

now put this in footer.php:

Code: Select all

// show how long it needs to create content
// remove comments // to use it
// $timer->stop('main');
// echo spacer(5)."<br><span class=\"v09\">&nbsp;created in ".($timer->get_current('main'))." sec</span>";
// echo "<br>".spacer(5);

?>
</body>
</html>
now, this should be the only thing in your index.php file:

Code: Select all

<?php

include "header.php";
include "footer.php";

?>
And in the custom script:

Code: Select all

<?php

include "header.php";

function do_action() {
  <your custom script here>;
}

include "footer.php";

?>
Like I said, its no easy job, and it probably wont work, but at least give it a shot.
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

@rylas:
This is not neccessary. With your sample you will loose all layout definition. If you use this it's easier to link to a new page.

Here is my sample for including own PHP functionality and to handle posts or something else.


Make a new file "test_form.inc.php" and put this into phpwcms root dir. Fill in the following code:

Code: Select all

<hr>
<strong>Post-Test</strong>
<?php if(!$_POST["count_submit"]) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>" method="post" name="myposttest" id="myposttest">
counter&nbsp;<input name="counter" type="text" id="counter">&nbsp;<input name="count_submit" type="submit" id="submit" value="send">
</form>
<?php } else { ?>
your counter value: <?php echo $_POST["counter"] ?><br>
<a href="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>">fill in again</a><?php } ?>
<hr>
Then create an article and add the replacement tag:

Code: Select all

{PHP:test_form.inc.php}
What I mean with that:
the PHP replacement tag for including external PHP files or HTML snippits (or any normal text file) is no longer processed as last.
Before change the PHP replacement tag was processed in an extra PHP function. But this makes problems if you want to send some frontend vars to include scripts - so I have excluded the replacement part for PHP and put this in the frontend renderer direct behind the menu processing. And then all formatting replacements are processed. The advantage of this is you can also use phpwcms replacement tags in your PHP includes.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
sporto
Posts: 160
Joined: Mon 10. Nov 2003, 18:01
Location: USA, Chicago

Post by sporto »

It all makes sense to me now. THanks!
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

Oliver Georgi wrote:@rylas:
This is not neccessary. With your sample you will loose all layout definition. If you use this it's easier to link to a new page.

Here is my sample for including own PHP functionality and to handle posts or something else.


Make a new file "test_form.inc.php" and put this into phpwcms root dir. Fill in the following code:

Code: Select all

<hr>
<strong>Post-Test</strong>
<?php if(!$_POST["count_submit"]) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>" method="post" name="myposttest" id="myposttest">
counter&nbsp;<input name="counter" type="text" id="counter">&nbsp;<input name="count_submit" type="submit" id="submit" value="send">
</form>
<?php } else { ?>
your counter value: <?php echo $_POST["counter"] ?><br>
<a href="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'] ?>">fill in again</a><?php } ?>
<hr>
Then create an article and add the replacement tag:

Code: Select all

{PHP:test_form.inc.php}
What I mean with that:
the PHP replacement tag for including external PHP files or HTML snippits (or any normal text file) is no longer processed as last.
Before change the PHP replacement tag was processed in an extra PHP function. But this makes problems if you want to send some frontend vars to include scripts - so I have excluded the replacement part for PHP and put this in the frontend renderer direct behind the menu processing. And then all formatting replacements are processed. The advantage of this is you can also use phpwcms replacement tags in your PHP includes.

Oliver
In above example, is it possible to put "test_form.inc.php" in other directories instead of root directory?

Bijan
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

Hi Bijan,

yes it's possible - you can put the php file in any dir - all you have to do is choosing the correct path ;-)

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

So, if I have a directory named "test", is this how I need to used the code? :oops:
  • {PHP:test/test_form.inc.php}
Also, I just thought of another question.
What do I need to do, if I want my "test_form.inc.php" in an article, to show up only after I click on a link, or click a button?

Bijan
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

That's right Bijan :)

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
Executter
Posts: 78
Joined: Thu 29. Jul 2004, 15:37
Location: Koblenz, Deutschland
Contact:

Post by Executter »

Mein Englisch ist schlecht und PHP kann ich auch nicht ^^

Aber wenn ich ein Script in den Content einpflegen mag,
welches mehrere Variablen beinhaltet (2 st.) und jede variable mehrere arrays hat... dann gibt es keine möglichkeit die auszulesen?

also...
ich include das script und schreib dann echo $var1['array2'];

normalerweise.

aber im wcms geht das ja nich....
also muss ich das include und das echo in eine neue datei schreiben und die mit dem {PHP:x.php} befehl in den content bringen.

das klappt auch. mit einer variable/array.... aber wenn ich jetzt 2 will und eine weitere datei schreibe, dann wird mit nur ne weiße seite angezeigt.

ich kann aber die beiden variablen/arrays nicht in eine schreiben,
weil die ja in dem content formatiert dargestellt werden sollen.

das mit der weißen seite, dachte ich lag daran, dass dann ja 2x das gleiche script includet wird... deshalb hab ich bei der 2. datei das include rausgenommen....

aber dann wird mir nur aus der 1. datei die variable angezeigt....


kurz:
- ein script, 2 dateien die das script includen und vars auslesen, 2 mal in content einfügen > leere seite

- ein script, 2 dateien, die erste includet und ließt aus, die 2. ließt nur aus und es werden nur die vars der ersten angezeigt....

Und auf Iframe würd ich dankend verzichten wenn möglich.

Ich hoffe das geht irgendwie.
Executter
Armin Rüdiger Vieweg
Design & Programmierung

Image
Website: http://www.dewecon.de
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

versuchs mal mit Globalen Variablen.

Jedes Include wird immer nur innerhalb einer Funktion ausgeführt - deswegen sind Variablen der Form $meineVar immer nur innerhalb dieses einen Includes/Funktion verfügbar.

Du kannst diese Variable aber auch als $GLOBALS['meinevar'] definieren und damit arbeiten - dann wird diese Global und steht Dir systemweit zur Verfügung.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
ErikvdB
Posts: 11
Joined: Wed 12. Jul 2006, 16:03

Post by ErikvdB »

Hey!
I tried your example (including test_form.inc.php), but for some reasons my $_POST variable is a completely empty array. So when I put

Code: Select all

print_r($_POST);
in test_form.inc.php, it will give Array () at any time :-(

Any clue?

[edit]I'm using v1.2.6 release[/edit]
User avatar
Oliver Georgi
Site Admin
Posts: 9900
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

If $_POST is empty this is fully normal as long as you haven't sent a form using method "post"

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
ErikvdB
Posts: 11
Joined: Wed 12. Jul 2006, 16:03

Post by ErikvdB »

Thanx Oliver for your quick reply.

I expect that my $_POST should not be empty when I submit this (part of the) form:


Code: Select all

	<form method="post" action="?id=87,61,0,0,1,0">
	<table>
    		<td><b>Omschrijving:</b></td>
	      <td><textarea cols="40" rows="2" name="omschrijving"></textarea></td>
	    </tr>

		<tr>
		<td><input type="submit" name="submit" value="Toevoegen"></td><td>&nbsp;</td>
		</table>
	</form>
Post Reply