Hi maverick
The basic problem to get a log about links clicked in your site is not how to write a macro. First, we have to understand, what a link is in our template. Also if we build in the template lists of links apparently the same way as the list of files, there is one basic difference: A reference to a file on our server creates a request to our server, and a link creates a request to the site where the link points to. Once the user has our page with links, we can shutdown our server and the user can still use the links, as we are not involved in serving the pages of the link.
So, to get some log, we must do two things at the same time when a link is clicked on our page:
a) create a 'non-destructive' request to our server. Non destructive means here, it should not load a new page from the server, as this would replace aour page and no further link could be done, nor should it initiata a download of a file like if the user would have clicked to a file for download. With this request we should pass some information to our server that indicates what link was pressed.
b) once the request to our server is done, execute the wanted link.
I found a workaround to achieve both things:
1) place somwhere in your template a small image, with a label (id) named 'fake'.
<img id="fake" src ="/dummy.jpg">
add this dummy.jpg to your root folder.
2) place the following javascript in your header:
<script type="text/javascript">
function fakelink(url)
{
document.getElementById("fake").src="/dummy.jpg?s="+url;
window.open(url);
}
</script>
This script, when invoked, reloads the source of our img placed in the template. Adding the urlvar with '?s=....' we pass the url of the link: This moves the desired information to our server, at the same time it avoids that the img gets loaded from the caché (at least for different links, using the same link more than one time could be lost , but it's ok so if we want only to know that a user has used the link. If we would register every time the user uses the link in one session, we could add some time-information in the urlvar)
Te request to reload this img gives now a log entry like the following:
17/11/2009 8:24:16 192.168.1.3:1632 {lan} Fully downloaded - 6,30 KB @ 1802 KB/s - /dummy.jpg?s=http://www.rejetto.com/wiki/index.php/HFS:_Template_symbols
if the url we link to is
http://www.rejetto.com/wiki/index.php/HFS:_Template_symbolsOnce the img is reloaded, a new window or tab with the page of the site we want to link is opened !
3) To invoke this script, we have to change in the [link] section of our template the anchor code to the following:
<a href="%encoded-folder%" onclick="fakelink('%item-url%')">%new%<img align=top src="/~img_link">%item-name%</a>
4) The link works as expected, and you have information of a completed download in your server and in your log. It's up to you what you do with that info in the log. Maybe knowing a download of 'dummy.jpg' means that a link was used is enough, otherwise use a event script on the 'on download completed' event to create a log entry as you like it.
--------------------
PD: Did some test how it works with different browsers:
Firefox + Opera: As expected, new tab is opened and log shows 'requested get' + 'fully downloaded with full urlvar info.
Chrome: Opens new tab, but only logs 'requested get' - no download done
Safari: Opens new window, but no request for reloading img is passed to hfs :-(
IE 8: (surprisingly !!) Opens new window, and log shows 'requested get' + 'fully downloaded with full urlvar info.