PDA

View Full Version : Embedding results in a dynamic page


Anonymous
09-19-2005, 12:27 PM
Our web page template is generated using PHP, not static HTML

I've been able to get the Zoom results into the PHP page by manually editing the Settings.php file and changing the '$TemplateFilename' value to "http://our.website.com/search_template.php" so that it is processed by PHP before being processed by Search.php (IYSWIM)

However, whenever I regenerate the search, I need to change this file manually again.

Is there a setting somewhere I'm missing in the Zoom configuration which sets this option through there?

wrensoft
09-19-2005, 12:40 PM
You should not need to edit the settings.php file.

Rather see the instructions here,
http://www.wrensoft.com/zoom/support/faq_ssi.html

---
David

Anonymous
09-19-2005, 01:27 PM
Thanks

(Changing the $TemplateFilename setting works just as well, and seems easier to me though.. :) )

wrensoft
09-19-2005, 09:54 PM
The settings file contains a bunch of important data that needs to be correct (like the number of records in the index files). So this file needs to be overwritten each time the index is updated.

-----
David

Ray
09-20-2005, 01:01 AM
Changing the $TemplateFilename in settings.php will not work in most cases, because the PHP code in your template will not be processed. It will only work if your template file does not contain PHP commands, in which case, the file would essentially be static HTML despite the fact that it has been given a PHP extension. Perhaps that is what's actually happening for you? Or do you have a special server configuration setup to allow PHP commands to be executed from the output of a PHP script?

Anonymous
09-20-2005, 10:25 AM
Changing the $TemplateFilename in settings.php will not work in most cases, because the PHP code in your template will not be processed. It will only work if your template file does not contain PHP commands, in which case, the file would essentially be static HTML despite the fact that it has been given a PHP extension.

Sorry, but that's not right at all..

PHP lets you specify URLs in file open/read commands, so if you open a 'file' called "http://www.site.com/index.php", PHP will read that file from the web server - AFTER the server's PHP has processed it. So, the reading PHP script will see the output of the PHP script, not the source of the PHP script. The PHP script can read files from totally different servers this way.

Well, this is the case if 'fopen_wrappers' have been enabled (which is usually the case, and is the default in Windows versions of PHP)

Zoom uses the 'file' command to read the file into the array, if you specify a URL as the filename (as I said in my OP), it reads the contents of that URL, JUST AS IF you were reading it from a web browser.

See http://uk2.php.net/manual/en/function.fopen.php and
http://uk2.php.net/manual/en/wrappers.php

Try it and see.

For a quick test, make a PHP script something like:


<?php
echo "

This is Zoom's search page</p>";
$f = file('http://www.wrensoft.com/search.php');
for($i=0;$i<sizeof($f);$i++) echo "$i) ".htmlentities($f[$i])."
";
?>

This will print out the output of the search.php script on the Wrensoft site.

Ray
09-21-2005, 05:19 AM
You are mostly correct, but note that there are two important additional criterias. First of all, fopen will only see the output of the PHP script if the filename specified is an absolute URL of the form "http://www.mysite.com/page.php".

Zoom does not use an absolute URL for the template filename. This way, the search engine can be placed in any folder of your website (or on a completely different website all together) - so long as all the files are in the same folder. If we were to introduce this requirement, we would then need users to specify exactly where the files will be, and we also lose the flexibility of allowing the files to be moved. This is important, as it increases the number of dependant variables involved in an installation.

So to clarify, yes, changing TemplateFilename in settings.php will work but ONLY if you specify an absolute URL for the filename AND if your server has allow_url_fopen (http://au3.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen) enabled.

However, we do not recommend this. The supported method of usage to achieve the same thing (a dynamically generated search template/layout) is described here:
http://www.wrensoft.com/zoom/support/faq_ssi.html

This method would not require any changes to the settings file, nor does it require an absolute URL for the template file. It will also work on servers that have allow_url_fopen disabled (note that allow_url_fopen is commonly disabled - especially on servers offering shared hosting, because it is a significant security risk (http://www.technosailor.com/lessons-in-web-security-php-and-remote-file-execution)).