View Single Post
Old 12-10-2003, 01:05 AM   #4
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
Bear with me, the code change to show thumbnail images requires a little bit of explanation.

Say you're using PhpDig to index "http://ownsite/". The pages contain links like "http://ownsite/dir/some.html". PhpDig finds these links and indexes the corresponding pages.
You also have thumbnail images that represent your HTML pages in some way, for example "some_t.jpg" for "some.html"; you store these thumbnail images in the same directory as the page, so our sample thumbnail is reachable via url "http://ownsite/dir/some_t.jpg".

Note that I am not addressing the issue of how to produce "some_t.jpg". I am assuming that it exists. Also, the code below assumes the thumbnail to be in the same directory as the HTML page, but this requirement can be relaxed.

If a search finds the HTML page, you want to display the thumbnail.
You must indicate in the search template where you want the thumbnail to appear, e.g. by inserting some directive like "<phpdig:thumbnail/>". I am assuming that you have looked at templates and that you understand how they work.
On second thoughts, it is nice that people can click on the thumbnail to get to the page. So the thumbnail <IMG> must be included in an <A> element.
It so happens that we already have a phpdig template directive to insert a clickable image; if the link must be to the found page, it is of the form: "<phpdig:complete_path src='xxx'/>".
Only we cannot put a fixed source, as the source depends on the page that is found. We'll come back to the template directive later.

Meanwhile, I'll tell you about the code for the template formatting. That is where you'll have to do a PHP code change.
Open libs/function_phpdig_form.php, locate function phpdigParseTags. There is a line:
Quote:
$replacement = '<a href="'.$t_strings[$regs[1]].'"'.$target.'><img src="'.$regs[3].'" border="0" align="bottom" alt="" /></a>';
Insert the following code just before that line:
Quote:
if (substr($regs[3], 0, 8) == "nothumb/")
{
if (ereg("[a-zA-Z0-9.?&=_-]+thumb=", $t_strings[$regs[1]]))
{
$regs[3] = ereg_replace("[a-zA-Z0-9.?&=_-]+thumb=", "", $t_strings[$regs[1]]);
}
else
{
$regs[3] = substr($regs[3], 8);
}
}
The most important piece here is the regular expression "[a-zA-Z0-9.?&=_-]+thumb=". It looks in the URL of the found page, e.g. "http://ownsite/dir/some.html" and expects to find "thumb=" somewhere in that URL.
Now here is the trick that I have used to make this code do what I want it to do: in my "http://ownsite/", the URLs pointing to other pages are not just ordinary URLs but URLs with an extra little tail.
For example, you'll find hyperlinks like "<a href='http://ownsite/dir/some.html?thumb=some_t.jpg'>Next page</a>".
For clicking from page to page, the "?thumb=xxx" tail is ignored. But when PhpDig comes along, it stores the complete URL, including the "?thumb=xxx" tail, in its database.
So, when later a search finds this page, "<phpdig:complete_path/>" will include the tail and the regular expression will find it. The "ereg_replace" then just manufactures an URL for the thumbnail image.

One final addition is about the template directive "<phpdig:complete_path src='xxx'/>". It must clearly express that it is used here for thumbnails, not for something else. So for example, we could have " src='thumbnail' " as a special placeholder. (Remember, the thumbnail URL is dynamic, we cannot plug a static one here.)
There will be pages that have no thumbnail, i.e. some page URLs in my site will still be like "http://ownsite/dir/some.html" with no "?thumb=xxx" tail. As I now have a template that is longing for inserting a clickable image, I have to provide a "by default" image.
This "by default" image will be in my PhpDig directory, not in the indexed site. Say we use "tpl_img/cprgo.gif" as default image.
The template directive therefore is not only a special placeholder, but at the same time tells PhpDig which image to use for found pages that have no corresponding thumbnail image. Here is the template directive that I use:
<phpdig:complete_path src="nothumb/tpl_img/cprgo.gif"/>
The "nothumb/" part tells the above code that this is the special placeholder. Any relative path can be provided after the "nothumb/" part, to point to the default thumbnail image.

There, I've said it! I hope you're still with me...

The thumbnail trick works, I've tried it out. In the site that I want to index, many pages have a corresponding thumbnail.
The above code is still somewhat rigid, it wants the thumbnail image to be alongside the HTML page. This serves my need perfectly.
If you want the thumbnails to be somewhere else, no doubt you'll see a way to implement it by adapting the above code somewhat.
__________________
René Haentjens, Ghent University
renehaentjens is offline   Reply With Quote