If you search MSN for the phrase "tgreer Sample JDF", you'll find my forum. Currently, the first result takes you directly to a thread. Scroll down to the bottom. As a guest, you'll see a message at the bottom that shows both the search engine, and the search terms, you used. I use this in conjuction with the "Welcome Message" plugin found on this site (Installed!).
I've got this working for most of the major search engines. However, I'm not using phrases, and I'm sure my code isn't the most efficient. I'd like the forum's help in polishing this.
Plugin: name: search_terms, hook_location: global_start
PHP Code:
$keywords = "";
$search_engine = "";
$search_terms = "";
$search_welcome = "";
$search_terms = "";
if ((isset($_SERVER['HTTP_REFERER'])) and ($_SERVER['HTTP_REFERER']!= ''))
{
global $keywords;
global $search_engine;
global $search_terms;
global $search_welcome;
$keywords = "";
$url = urldecode($_SERVER['HTTP_REFERER']);
// google
if (eregi("www\.google",$url))
{
preg_match("'q=([^&]+)'", " $url ", $keywords);
$search_engine = 'google';
$search_terms = $keywords[1];
$show['showSearchWelcome'] = true;
$show['search_engine'] = $search_engine;
$show['search_terms'] = $search_terms;
}
// Yahoo
if ((eregi("yahoo\.com",$url)) or (eregi("search\.yahoo",$url)))
{
preg_match("'p=([^&]+)'", " $url ", $keywords);
$search_engine = 'Yahoo';
$search_terms = $keywords[1];
$show['showSearchWelcome'] = true;
$show['search_engine'] = $search_engine;
$show['search_terms'] = $search_terms;
}
// MSN
if (eregi("search\.msn",$url))
{
preg_match("'q=([^&]+)'", " $url ", $keywords);
$search_engine = 'MSN';
$search_terms = $keywords[1];
$show['showSearchWelcome'] = true;
$show['search_engine'] = $search_engine;
$show['search_terms'] = $search_terms;
}
// AllTheWeb
if (eregi("www\.alltheweb",$url))
{
preg_match("'q=([^&]+)'", " $url ", $keywords);
$search_engine = 'AllTheWeb';
$search_terms = $keywords[1];
$show['showSearchWelcome'] = true;
$show['search_engine'] = $search_engine;
$show['search_terms'] = $search_terms;
}
// Looksmart
if (eregi("looksmart\.com",$url))
{
preg_match("'qt=([^&]+)'", " $url ", $keywords);
$search_engine = 'Looksmart';
$search_terms = $keywords[1];
$show['showSearchWelcome'] = true;
$show['search_engine'] = $search_engine;
$show['search_terms'] = $search_terms;
}
}
Because scope issues always confound me, I'm putting the terms I need inside of "show". Good, bad, ugly? You tell me.
Template: forumrules
PHP Code:
<!-- tgreer -->
<if condition="$show['guest']">
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0">
<thead>
<tr>
<td class="tcat">You're Invited!</td>
</tr>
</thead>
<tbody>
<tr>
<td class="panel">
<div class="smallfont">
<p>
<if condition="$show['showSearchWelcome']">
You've reached this site because you searched <em>$show[search_engine]</em> for <em>$show[search_terms]</em>. <strong>PrintForum</strong> discusses this and many other topics of interest to the digital printing industry. Please <a href='/register.php?'>join our community today</a>. Registration is free and easy. Don't just <strong>browse</strong>, participate!
</if>
<if condition="!$show['showSearchWelcome']">
<strong>PrintForum</strong> discusses many topics of interest to the digital printing industry. Please <a href='/register.php?'>join our community today</a>. Registration is free and easy. Don't just <strong>browse</strong>, participate!
</if>
</p>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</if>
<if condition="!$show['guest']">
<!-- tgreer -->
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="180">
<thead>
<tr>
<td class="thead">
<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumrules')"><img id="collapseimg_forumrules" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumrules].gif" alt="" border="0" /></a>
$vbphrase[posting_rules]
</td>
</tr>
</thead>
<tbody id="collapseobj_forumrules" style="$vbcollapse[collapseobj_forumrules]">
<tr>
<td class="alt1" nowrap="nowrap"><div class="smallfont">
<if condition="!$show['codeonly']">
<div><phrase 1="$rules[postnew]">$vbphrase[you_may_x_post_new_threads]</phrase></div>
<div><phrase 1="$rules[postreply]">$vbphrase[you_may_x_post_replies]</phrase></div>
<div><phrase 1="$rules[attachment]">$vbphrase[you_may_x_post_attachments]</phrase></div>
<div><phrase 1="$rules[edit]">$vbphrase[you_may_x_edit_your_posts]</phrase></div>
<hr />
</if>
<div><phrase 1="misc.php?$session[sessionurl]do=bbcode" 2="$bbcodeon">$vbphrase[vb_code_is_x]</phrase></div>
<div><phrase 1="misc.php?$session[sessionurl]do=showsmilies" 2="$smilieson">$vbphrase[smilies_are_x]</phrase></div>
<div><phrase 1="misc.php?$session[sessionurl]do=bbcode#imgcode" 2="$imgcodeon">$vbphrase[img_code_is_x]</phrase></div>
<div><phrase 1="$htmlcodeon">$vbphrase[html_code_is_x]</phrase></div>
</div></td>
</tr>
</tbody>
</table>
<!-- tgreer -->
</if>
You can see that this would benefit from using phrases. How would you clean this up?
Also, I'm interested in plugin development. How could this be turned into an importable plug-in?