(this is a repost of my previous topic, disappear after forum update)
Hi,
I like to see keywords per visit near the "came from", ok you can pass your mouse on url and try to read it but i'm lazy.
I'm not a good programmer but I have done some mod and it's working fine so others can use it, and I hope you will improve and put in next version.
I also notice a problem with URL containing htmlspecialchars, it's happen sometimes
Here is the code (for v1.2.9) :
The idea is to detect keyword and put it at the start of the line, we use Google url rules as general : q=keywords
1) in components/com_joomlawatch/class.joomlawatch.helper.php
Find line 146
| Code: |
function truncate($str, $len = ""«») {
|
Add before
| Code: |
function truncateUrl($str, $len) {
if (strlen($str)+$len < 120)
return $str;
else
return substr($str, 0, 120-$len) . "...";
}
|
(120 is line lenght, good for 1024x800 window, adapt it to your needs)
2) in components/com_joomlawatch/class.joomlawatch.html.php
Find line 443 to 446
| Code: |
if (@ $row->referer) {
$refererTruncated = $this->joomlaWatch->helper->truncate($row->referer);
$output .= "<i style='color: gray;'> " . _JW_VISITS_CAME_FROM . ": <a href='$row->referer' target='_blank' style='color: gray;' title='$row->referer'>$refererTruncated</a></i>";
}
|
Replace by
| Code: |
if (@ $row->referer) {
$output .= "</td><tr><td colspan=8>"; // use all columns
$refererTruncated = str_replace('?', '&', $row->referer); // to prevent url starting with search?q= because we use '&q=' to detect keywords
// Some others search engines don't use 'q=' so we convert it (add yours)
$refererTruncated = str_replace('_nkw=', 'q=', $refererTruncated); // Ebay
$refererTruncated = str_replace('rdata=', 'q=', $refererTruncated); // Voila
$refererTruncated = str_replace('keyword=', 'q=', $refererTruncated);
// We write in blue an engine short name (add yours) with a code for later split
$refererTruncated = str_replace('http://www.google.com/search', '<font color=blue>GoogleCOM</font> {sp}', $refererTruncated);
$refererTruncated = str_replace('http://www.google.fr/search', '<font color=blue>GoogleFR</font> {sp}', $refererTruncated);
$refererTruncated = str_replace('http://shop.ebay.fr/', '<font color=blue>EbayFR</font> {sp}', $refererTruncated);
// No we are ready to separate keywords
$refererTruncated = explode('&', $refererTruncated);
foreach ($refererTruncated as $rtvalue) {
if (substr($rtvalue, 0, 2) == 'q=')
$rtq = str_replace('q=', '', $rtvalue);
else
$rtr .= $rtvalue.'&';
}
if ($rtq=='') $rtq='---'; // if no keyword
if (strpos($rtr, '{sp}')===false) $rtr='{sp}'.$rtr; // if no engine short name
$refererTruncated = "<b>".rawurldecode($rtq)."</b> " . _JW_VISITS_CAME_FROM . ": " . $rtr; // we construct the line
list ($rtq, $rtr) = split ('{sp}',$refererTruncated); // keep formatting things away (as blue engine name)
$rtr = htmlspecialchars_decode($rtr); // don't count specials char in strlen
$rtr = $this->joomlaWatch->helper->truncateUrl($rtr, strlen($rtq)); // reduce to line length
$refererTruncated = $rtq . htmlspecialchars($rtr); // rebuild the line
unset($rtq,$rtr); // empty var for next row
$output .= "<i style='color: gray;'><a href='$row->referer' target='_blank' style='color: gray;' title='$row->referer'>refererTruncated</a></i>";
}
|
Done ! Enjoy
expected result :