Jump to content
TNG Community
fluffy82

installation in WordPress

Recommended Posts

fluffy82

Question...

I have installed TNG in my WordPress following the Kloosterman method. TNG was installed, as prescribed by the "method", in a subfolder. Stupidly enough I called it "tng_11", but that's the least of my worries. The path to all TNG files is: httpdocs/tng_11/

Is it possible to have TNG installed not in a subfolder, but straight into the WordPress folder? So that all files/pages would be directly behind httpdocs/ ? Or will this be a problem when Wordpress updates?

The main reason is that I just can't get the data from TNG to work outside the tng_11 folder...
For example https://huygens-vandemoortel-ancestry.be/tng_11/statistics_small.php works fine, but when I move the exact same php into the root folder or copy the code into a php widget, I just get a blank page. Before you ask: yes, I use the full path (/httpdocs/tng_11/......) when including other files. I think the problem is that TNG doesn't, and uses ./ and ../ in stead of the full path...

I gues that wouldn't be a problem if TNG would always be in the root, next to WordPress in stead of "below".

 

Second part of the question: if (and that's a very big IF) I would decide to install TNG in the root rather than in a subfolder, I suppose it won't be possible to just move all files on my server and simply change the path in the admin configuration section? I will have to do a clean install? And if I do that, will I need to remove my database, or (if the tables already exist) will the installation process recognise them and just us the existing tables in stead of creating new ones?

Thanks for your suggestions!

Share this post


Link to post
Share on other sites
theKiwi

1 - you can use the TNG variable $rootpath to tell TNG the path to files that sometimes are hard to find in a WordPress environment

2 - you should be able to just move all the files, and then update the RootPath setting in your config.php file

Roger

Share this post


Link to post
Share on other sites
fluffy82
26 minutes ago, theKiwi said:

1 - you can use the TNG variable $rootpath to tell TNG the path to files that sometimes are hard to find in a WordPress environment

It's the other way around. TNG finds the files perfectly, but WordPress doesn't seem to find them...
When using a hyperlink (something like https://www.mysite.com/tng_11/file.php) there's no problem. But when I try to execute a php in WordPress, which needs something from TNG, it doesn't work... A require function, for example... None of these work, they always result in an error (file not found).

require("tng_begin.php");
require("/tng_11/tng_begin.php");
require("./tng_11/tng_begin.php");
require("../tng_11/tng_begin.php");
require("/httpdocs/tng_11/tng_begin.php");

To give you a concrete example: I'm trying to use some of the variables that make up the statistics.php on my (Wordpress) home page. I know a simple include() or require() won't work, but even something like

$getString = http_build_query(array ('stat_avgyears'=>$avgyears, 'stat_avgdays'=>$avgdays));
header('Location: /httpdocs/tng_11/statistics.php?$getString');

doesn't work because it just can't find the statistics.php page...

26 minutes ago, theKiwi said:

2 - you should be able to just move all the files, and then update the RootPath setting in your config.php file

That's good news! I think I'll try that over the weekend - taking good note of which files are being moved where (there are img and css folders already, being used by Wordpress I suppose, so I'll have to "merge" them). If it doesn't make accessing the TNG files easier, I can always revert.

Share this post


Link to post
Share on other sites
theKiwi
1 hour ago, fluffy82 said:

It's the other way around. TNG finds the files perfectly, but WordPress doesn't seem to find them...
 When using a hyperlink (something like https://www.mysite.com/tng_11/file.php) there's no problem. But when I try to execute a php in WordPress, which needs something from TNG, it doesn't work... A require function, for example... None of these work, they always result in an error (file not found).

require("tng_begin.php");
require("/tng_11/tng_begin.php");
require("./tng_11/tng_begin.php");
require("../tng_11/tng_begin.php");
require("/httpdocs/tng_11/tng_begin.php");

 

You are trying to tell WordPress a relative path, which in my experience doesn't work - you have to tell it the absolute path from your server's root, which is the rootpath that is stored in the $rootpath variable.

So 

require ( $rootpath . "tng_begin.php");

should work.

Roger

Share this post


Link to post
Share on other sites
fluffy82
8 hours ago, theKiwi said:

You are trying to tell WordPress a relative path, which in my experience doesn't work - you have to tell it the absolute path from your server's root, which is the rootpath that is stored in the $rootpath variable.

So 

require ( $rootpath . "tng_begin.php");

should work.

Roger

WordPress doesn't use $rootpath in its system. $rootpath is a variable that's defined within TNG, though, and thus inaccessible from within a non-TNG page on WordPress...

When I do this:

<?php
$path = get_home_path(); ?>
print "Path: ".$root_path;

I got: /var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/

Trying require("/var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/tng_begin.php"); didn't work, and this

<?php
$path = get_home_path();
$path = wp_normalize_path ($path);

require($path . "/tng_11/tng_begin.php");
?>

Also didn't do anything...

I'm baffled... TNG seems to be completely inaccessible this way.

I have a .php that works, without header or footer, just with the necessary code. When I either paste the complete code into my widget, or just put an echo() for the php, it doesn't work either, while it should. It really seems as if TNG is blocking access from "outside" itself somehow...

Share this post


Link to post
Share on other sites
fluffy82

I think I have found the source of my problem...

To be using variables from another file, shouldn't those be set as "global"? I don't think they are...

Share this post


Link to post
Share on other sites
KevyNC

I was doing some testing of setting up a new Website (using UsbWebserver).  I have run in to some similar issues to what you have described but I was not sure if it was wordpress or TNG.

Sometimes it can get confusing of what broke/fixed.  Unfortunately due to other commitments I have not been able to play with it to find problem.  I have removed the TNG Addin, and using custom (menu) links load  the TNG pages now,  however I lose the  Word  menu header etc.  But I am basically brand new to  Wordpress so that could be part of it.  Thanks for sharing

 

Kevin

 

Share this post


Link to post
Share on other sites
klooster
  • The reason my method places TNG in a subdir of the root is that I do not want files of two different programs (WP and TNG) in the same directory.
  • In the WP_TNG-topmenu.php which is located in the subdir of WP, are the lines:

<?php
require ("../wp-blog-header.php");
get_header ();
 ?>

The " ../ " before wp-blogheader.php directs WP from the TNG subdir to the root where WP is installed and then loads wp.blogheader.php

If you make a link like you mentioned " https://huygens-vandemoortel-ancestry.be/tng_11/statistics_small.php " and you want to place it in a widget, you should use the FULL path not a relative one. In the widget you should do this as follows: <a href=" https://huygens-vandemoortel-ancestry.be/tng_11/statistics_small.php ">Statistics</a>. You have to do that in the HTML mode, not in the text mode.

If you get a blank page then there is something wrong with the path in WP_TNG-topmenu.php!

If you follow my instruction ( TNG-WP integration ) to the letter, then you do not have to change anything the core files of TNG or to the core file’s of WordPress.

 


 

 

Share this post


Link to post
Share on other sites
fluffy82

Hi Cees,

thank you for your input.

I have followed your instructions to the letter, and everything, including hyperlinks, works like a charm.
But I'm starting to fear that what I want to do is just not possible. Using the full path won't work, as far as I know (and correct me if I'm wrong) you can't require() or include() a webpage, only files on your own server. I don't think Wordpress will recognise it and accept it as a server file, but will treat it as an external website. I'll try it out tonight.

The line you showed, <a href=" https://huygens-vandemoortel-ancestry.be/tng_11/statistics_small.php ">Statistics</a>, will just display the word "Statistics" which redirects you to the webpage when you click on it. That's not what I want.

I need one of two things:

1) I don't need a link to a page within my widget, but the actual content of the page.
The statistics_small.php I have made, only outputs a list (with a relative content made by queries). It has no header, footer or whatever. The output is just 10 lines, numbered 1 to 10. I want those 10 lines to show up in my widget. For some reason, the .php code works fine if it is accessed as a webpage, but copying the code into the php widget doesn't work. Calling and printing the .php without putting all of the code doesn't work either. I'm now experimenting with the [embed] possibility in Wordpress, but I'm trying to find out how to correctly register my site and whether or not that's safe to do.

2) access the existing and functioning statistics.php from withn a widget and use the variables. The statistics.php has a lot of calculations for the number of people, percentage of women, average age etc. These all have a variable name (I don't know by heart exactly which names, but it's something like $totalpeople, $avgage,  $totalmale, $totalfemale etc). I would like to be able to use these variables in a widget. Something like:

"Welcome to my website. Here you can find <?php echo $totalpeople; ?> persons of which <?php echo $totalmale; ?> are male and <?php echo $totalfemale; ?> are female."
(or, of course, build a table within the php code calling the original statistics.php and write echo "Welcome to my website. Here you find {$totalpeople} persons" etc)

I could just make a html and put in the numbers by hand, but I want them to update when I change my tree. I seem to be unable to retrieve the variables from the .php file. My guess is that in order to do that, the statistics.php should make the $ global (which isn't the case, and I don't want to alter the file).

 

I have two working .php files that output exactly what I need. With option 1) I would just show these existing .php files within a widget on my homepage. In option 2) I would rewrite some html, using the variables taken from the existing pages.

Regards,
Tom

Share this post


Link to post
Share on other sites
klooster

WordPress doesn’t allow php scripts to run from content directly by default. Even if you plan to write it in php enclosures <?php     ?>, it will not work.

The quickest and easiest way to do this is to use a plugin that allows you to run PHP embedded in post content.There are several plugins that will do this, check this page:

best-plugins-add-php-code-wordpress

 

 

Share this post


Link to post
Share on other sites
fluffy82
1 hour ago, klooster said:

WordPress doesn’t allow php scripts to run from content directly by default. Even if you plan to write it in php enclosures <?php     ?>, it will not work.

The quickest and easiest way to do this is to use a plugin that allows you to run PHP embedded in post content.There are several plugins that will do this, check this page:

best-plugins-add-php-code-wordpress

 

 

I am using a plugin that enables php in widgets. That's not the problem, it works. When I put something simple, like <?php echo("Does this work?"); ?> the only thing displayed is Does this work? When using include() to get inside statistics.php, all the rest gets an output, but the variables are empty. When I use require() or require_once(), the script dies and my page isn't displayed properly, it stops loading at the point where this code should be executed. The same happens when I do an include with the full path [starting with include("/var/www/ etc)].

If you go to my homepage (https://huygens-vandemoortel-ancestry.be) you can see "Statistieken" below the round pictures. The code I used for that is:

<table>
<?php
include("/tng_11/tng_begin.php");
include("/tng_11/statistics.php");

echo "<tr><td><span><a href='/tng_11/search.php?mybool=AND&tree=huygensv'>Totaal aantal personen<a/></span></td>\n";
echo "<td><span>$totalpeople &nbsp;</span></td></tr>\n";

echo "<tr><td><span><a href='/tng_11/search.php?mybool=AND&tree=huygensv&mygender=M&gequalify=equals'>Mannen</a></span></td>\n";
echo "<td><span>$fmt_males ($percentmales%) &nbsp;</span></td></tr>\n";

echo "<tr><td><span><a href='/tng_11/search.php?mybool=AND&tree=huygensv&mygender=F&gequalify=equals'>Vrouwen</a></span></td>\n";
echo "<td><span>$fmt_females ($percentfemales%) &nbsp;</span></td></tr>\n";

echo "<tr><td><span><a href='/tng_11/search.php?mybool=AND&tree=huygensv&mygender=U&gequalify=equals'>Onbekend geslacht</a></span></td>\n";
echo "<td><span>$fmt_unknownsex ($percentunknownsex%) &nbsp;</span></td></tr>\n";

echo "<tr><td><span>In leven</span></td>\n";
echo "<td><span>$numliving &nbsp;</span></td></tr>\n";

echo "<tr><td><span><a href='/tng_11/surnames.php?tree=huygensv'>Aantal familienamen</a></span></td>\n";
echo "<td><span>$uniquesurnames &nbsp;</span></td></tr>\n";

echo "<tr><td><span>Gemiddelde leeftijd</span></td>\n";
echo "<td><span>$avgyears jaar, $avgdays dagen &nbsp;</span></td></tr>\n";
?>
</table>

<a href='https://huygens-vandemoortel-ancestry.be/tng_11/statistics.php' style="font-weight:300;font-size: 0.85em;">Volledige lijst statistieken</a>

 

Note that I just left include("/tng_11/statistics.php"); there because any other path to the file or different function makes the script stop and renders my homepage inaccessible. This is the only one that keeps the page browseable. I prefer the numbers to be empty rather than have no homepage at all, while I'm trying to figure this out.

Tom

Share this post


Link to post
Share on other sites
klooster

Oké,  now I understand what you are trying to accomplish.

require, require_once, include and include_once are all the same with one exception: require will emit a fatal error on failure where as include will emit warning.

Sometimes " " does not work, try ' '
include ('/tng_11/tng_begin.php');

You have to do that in the HTML mode, not in the text mode.

 

WARNING:  It is unsafe to use include with a URL, because it allows another server control of yours. 

Share this post


Link to post
Share on other sites
fluffy82
41 minutes ago, klooster said:

Sometimes " " does not work, try ' '
include ('/tng_11/tng_begin.php');

Unfortunately, that doesn't make any difference... The fact that the script fails when using require(), does that mean it can't locate the file, or that there is something in the target file which for some reason cannot be executed?

Share this post


Link to post
Share on other sites
klooster

Retrieving error log entries allows you to diagnose the problem.

The following constant definitions need to be either added or edited in your wp-config.php file:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Most WordPress installations already have an entry for WP_DEBUG set to false so you’ll need to change this value to true. It’s not that common to have WP_DEBUG_LOG already set in the wp-config so most likely you’ll have to add that line.

After you’re done editing ensure that WP_DEBUG and WP_DEBUG_LOG are set to true and that each constant is only defined once in wp-config.php.

Repeat the failed WordPress operation.
You may have observed the problems on a particular screen on the admin page, page on your site or are experiencing something as catastrophic as your site not coming up at all. Go into WordPress and simply repeat the operation or refresh the page that isn’t working properly.

Go to the WordPress content folder and open debug.log.
Go to the WordPress content folder. This is usually called wp-content, unless you renamed it with a security plugin.

Open the log file debug.log, go to the bottom and look for line entries with timestamps that correspond to your recent site interactions. You may see zero, one, or many lines with the appropriate timestamp.

 

PS: you can also install the "Error Log Monitor" plugin or similar plugin

Share this post


Link to post
Share on other sites
fluffy82
5 hours ago, klooster said:

Retrieving error log entries allows you to diagnose the problem.

Sorry for the delay, I had to change the wp_config and didn't have acces to it until I came home.

So, the fatal errors...

When using require('../tng_11/statistics.php'); it says "no such file exists in..." and then gives the path of the plugin, in stead of the root + /tng_11/ etc.

When using the full path (/var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/) it gives two errors:

1) fatal error

Cannot redeclare findlangfolder() (previously declared in /var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/genlib.php:1374) in /var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/genlib.php on line 1374

2) warning

mysqli_free_result() expects parameter 1 to be mysqli_result, null given in /var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/tngconnect.php on line 81

(deze warning wordt herhaald, voor line 50)

 

I know that sometimes using require_once() resolves error 1, but not in this case. Using require_once() gives the same fatal error and warnings.

Share this post


Link to post
Share on other sites
fluffy82
11 minutes ago, fluffy82 said:

1) fatal error

Cannot redeclare findlangfolder() (previously declared in /var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/genlib.php:1374) in /var/www/vhosts/huygens-vandemoortel-ancestry.be/httpdocs/tng_11/genlib.php on line 1374

In genlib.php, lines 1374 to 1385 are:

function findlangfolder( $file ) {
	global $mylanguage, $language;

	if( file_exists("$mylanguage/$file") )
		$foundlang = "$mylanguage";
	elseif( file_exists("languages/$language/$file") )
		$foundlang = "languages/$language";
	else
		$foundlang = "languages/English";

	return $foundlang;
}

I personally don't see an issue with it... It's not something I ever touched, it's the code that came with TNG.
In the file, this is the only instance findlangfolder is declared.

Share this post


Link to post
Share on other sites
klooster
  • There is nothing wrong with the genlib.php.

    Assuming you don't really have two PHP functions defined with the same name, this "cannot redeclare" function error message is usually caused by using the require or include functions to include the same common file (and therefore its functions) more than once.

A fix to this problem is to change your "include" or "require" statements to "include_once" or "require_once". That is, change a statement like this: 

require 'common.inc';

to this;

require_once 'common.inc';

and the dreaded PHP cannot redeclare function error message should go away.

 

  • If this does not work, you could try something like this with the function in genlib.php

You can wrap the function in an if statement with a function_exists check.

Before:

  function findlangfolder ( $file ) {
   // whatever the function does
  }
After:

if (!function_exists('findlangfolder')) {
  function findlangfolder ( $file ) {
   // whatever the function does
  }
}
 

The disadvantage of this method is that after updating TNG the modifcations are gone, so, you have to update genlip,php again.

Share this post


Link to post
Share on other sites
fluffy82
33 minutes ago, klooster said:

A fix to this problem is to change your "include" or "require" statements to "include_once" or "require_once".

I tried that (sorry if it wasn't clear, I mentioned it at the bottom of my first post, before the one with the genlib code) but it doesn't help. That's why I went to look at the genlib code.

 

33 minutes ago, klooster said:

You can wrap each function in an if statement with a function_exists check.

The disadvantage of this method is that after updating TNG the modifcations are gone, so, you have to update genlip,php again.

I want to avoid changing TNG files, of course. I'll keep this in mind if I can find no other solution at all...

Thanks for your assistance, Cees! You're the best.

Share this post


Link to post
Share on other sites
fluffy82
2 hours ago, klooster said:

You can wrap each function in an if statement with a function_exists check.

Just for fun, I did try this, and the fatal error seems to have gone. For the findlangfolder.... Now it gives the same error for the custom_menu() function (which indeed appears several times in genlib).

So if and whenI fix that, I'm sure it will just jump the error to the next function... Doing all of them with the above method seems like a bad idea (TNG updates, as you mentioned).
I will have to find out why these functions are called more than once... Could it be because the genlib.php is already called in another widget on the same page?

EDIT: I disabled the other TNG widgets on the page, but that didn't change anything... That's clearly not the issue

EDIT 2: the widget is the issue it seems... Just disabling the widgets on the page doesn't help because the plugin which provides them is still loaded, even if it's not used on the page. Deactivating the pluging made the error go away (being replaced by dozens of "illegal string" errors, but that's a next issue). The bottom line is that I will probably not be able to use my own code as long as I'm using the TNG Widgets plugin 😥

Share this post


Link to post
Share on other sites
klooster

Oh... you are using the TNG widget plugin!

I have no idea how the TNG widget plugin works. The TNG widget is probably the cause.

BUT: to execute PHP scripts in a normal WP text widget by default is not possible. WordPress doesn’t comes with this feature because of security issues.

 

You can use few plugins like PHP text widget and PHP Code Widget but you can also  do it without a plugin.

FInd the functions.php file of your current theme and add the following code at the end of the file.

function php_execute($html){
if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
add_filter('widget_text','php_execute',100);

Now clear the cache if you use Cache Plugins such as WPSuper Cache or W3 Total cache.

To check the working,Paste the following PHP code in a text widget

 <?php echo 'Hello World !!!' ?>

Now check the place where you have placed the widget,You should see “Hello World !!!

Share this post


Link to post
Share on other sites
fluffy82

I'm not using a normal text widget, I'm using an enhanced text widget, which is able to read and/or execute Text, HTML, CSS, JavaScript, Flash, Shortcodes, or PHP. That works fine. The columns you see on my home page are completely made within the php code that calls for the variables.

Not sure about the statistics, but i'll try to integrate the second part of my project (Top 10 places) into the TNG Widgets plugin. Hoping that the procedure is similar to the existing Top 10 surnames widget...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×