[pLog-svn] r1829 - plugins/trunk/unported/google
jondaley at devel.plogworld.net
jondaley at devel.plogworld.net
Wed Apr 13 10:40:09 GMT 2005
Author: jondaley
Date: 2005-04-13 10:40:08 +0000 (Wed, 13 Apr 2005)
New Revision: 1829
Modified:
plugins/trunk/unported/google/plugingoogle.class.php
Log:
this isn't ported, but I am cleaning up my plugin directory, and there are a couple changes that will are useful, if anyone ever ports this plugin
Modified: plugins/trunk/unported/google/plugingoogle.class.php
===================================================================
--- plugins/trunk/unported/google/plugingoogle.class.php 2005-04-13 10:30:12 UTC (rev 1828)
+++ plugins/trunk/unported/google/plugingoogle.class.php 2005-04-13 10:40:08 UTC (rev 1829)
@@ -1,14 +1,14 @@
<?php
- include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
- include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
- include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+include_once( PLOG_CLASS_PATH."class/net/url.class.php" );
- /**
- * Implementation to highlight the search terms if the user is coming from google.
- *
- * Based on google_hilite from Textism, http://www.textism.com/tools/google_hilite/
- */
+/**
+ * Implementation to highlight the search terms if the user is coming from google.
+ *
+ * Based on google_hilite from Textism, http://www.textism.com/tools/google_hilite/
+ */
class PluginGoogle extends PluginBase {
var $colors = Array( "yellow",
@@ -24,8 +24,8 @@
function PluginGoogle()
{
- $this->PluginBase();
-
+ $this->PluginBase();
+ $this->id = "google";
$this->desc = <<<EOD
This plugin will highlight the search terms entered by a Google user when arriving to
your blog.<br/><br/>To enable the plugin, you must include \{\$google->start()} somewhere in the
@@ -49,88 +49,99 @@
<br/><br/>
Please reports any bugs to the pLog team! :)
EOD;
+
$this->author = "The pLog team";
$this->totalReplacements = 0;
$this->highlightedTerms = "";
- }
+}
- function start()
- {
- ob_start();
- }
+function start()
+{
+ ob_start();
+}
- function google_hilite($text) {
+function google_hilite($text) {
- //$ref = urldecode($_SERVER[HTTP_REFERER]);
+ //$ref = urldecode($_SERVER[HTTP_REFERER]);
- $url = new Url($_SERVER["HTTP_REFERER"]);
+ $url = new Url($_SERVER["HTTP_REFERER"]);
- # let's see if the referrer is google
- //if (preg_match('/^http:\/\/w?w?w?\.?google.*/i',$url->getHost())) {
- if (preg_match('/^w?w?w?\.?google.*/i',$url->getHost())) {
+ # let's see if the referrer is google
+ //if (preg_match('/^http:\/\/w?w?w?\.?google.*/i',$url->getHost())) {
+ if (preg_match('/^w?w?w?\.?google.*/i',$url->getHost())) {
- # chop the search terms into an array
- $query_array = $url->getQueryArray();
+ # chop the search terms into an array
+ // and separate all the different parameters
+ $reqParams = explode( "&", $url->getQuery());
- if( $query_array["q"] == "" || empty($query_array["q"]))
- return false;
+ $query_array = Array();
+ foreach( $reqParams as $param ) {
+ // now, for every parameter, get rid of the '='
+ $parts = explode( "=", $param );
+ $var = $parts[0];
+ $value = urldecode($parts[1]);
+ if(strncmp($value, "site:", 5) && strncmp($value, "inurl:", 6)){
+ $query_array[$var] = $value;
+ }
+ }
- // otherwise, we can proceed to highlight the words!
- $searchTerms = explode( " ", $query_array["q"] );
+ if( $query_array["q"] == "" || empty($query_array["q"]))
+ return false;
- // assign a color to each google search term
+ // otherwise, we can proceed to highlight the words!
+ $searchTerms = explode( " ", $query_array["q"]);
+ // assign a color to each google search term
$i=0;
- $this->highlightedTerms = "<div class=\"googlepluginmessage\">Google user, I have highlighted the following terms for you: ";
+ $this->highlightedTerms = "<div class=\"googlepluginmessage\">Welcome Google user, I have highlighted the following terms for you: ";
- for($i=0; $i<count($searchTerms); $i++ ) {
- $searchTerms[$i] = trim(str_replace( "+", "", $searchTerms[$i]));
- $searchTerms[$i] = str_replace( "\"", "", $searchTerms[$i]);
- $assignedColors[$searchTerms[$i]] = $this->colors[$i%count($this->colors)];
+ for($i=0; $i<count($searchTerms); $i++ ) {
+ $searchTerms[$i] = trim(str_replace( "+", "", $searchTerms[$i]));
+ $searchTerms[$i] = str_replace( "\"", "", $searchTerms[$i]);
+ $assignedColors[$searchTerms[$i]] = $this->colors[$i%count($this->colors)];
- $this->highlightedTerms .= "<span style=\"background:".$assignedColors[$searchTerms[$i]]."\">".$searchTerms[$i]."</span> ";
- }
+ $this->highlightedTerms .= "<span style=\"background:".$assignedColors[$searchTerms[$i]]."\">".$searchTerms[$i]."</span> ";
+ }
- //print($highlightedTerms);
- $this->highlightedTerms .= "</div>";
+ //print($highlightedTerms);
+ $this->highlightedTerms .= "</div>";
- # loop through the search terms
- foreach($searchTerms as $b){
+ # loop through the search terms
+ foreach($searchTerms as $b){
- if( $b != "" || !empty($b)) {
- //$b = trim($b);
- // if the string ends up having '+' sings, the regular expression
+ if( $b != "" || !empty($b)) {
+ //$b = trim($b);
+ // if the string ends up having '+' sings, the regular expression
// parser will surely not like it!
$b = trim(str_replace( "+", "", $b ));
- if (!preg_match('/<.+>/',$text)) {
- # If there are no tags in the text, we'll just do a simple search and replace
- $text = preg_replace('/(\b'.$b.'\b)/i','<span style="background:'.$assignedColors[$b].'">$1</span>',$text);
- $this->totalReplacements++;
- }
- else {
- # If there are tags, we need to stay outside them
- $text = preg_replace('/(?<=>)([^<]+)?(\b'.$b.'\b)/i','$1<span style="background:'.$assignedColors[$b].'">$2</span>',$text);
- $this->totalReplacements++;
- }
- }
- }
- }
+ if (!preg_match('/<.+>/',$text)) {
+ # If there are no tags in the text, we'll just do a simple search and replace
+ $text = preg_replace('/(\b'.$b.'\b)/i','<span style="background:'.$assignedColors[$b].'">$1</span>',$text);
+ $this->totalReplacements++;
+ }
+ else {
+ # If there are tags, we need to stay outside them
+ $text = preg_replace('/(?<=>)([^<]+)?(\b'.$b.'\b)/i','$1<span style="background:'.$assignedColors[$b].'">$2</span>',$text);
+ $this->totalReplacements++;
+ }
+ }
+ }
+ }
- return $text;
- }
+ return $text;
+ }
- function end()
- {
- $contents = ob_get_contents();
+ function end()
+ {
+ $contents = ob_get_contents();
- ob_end_clean();
+ ob_end_clean();
- $hilite = $this->google_hilite($contents);
- $hilite = str_replace( "[googleplugin]", $this->highlightedTerms, $hilite );
+ $hilite = $this->google_hilite($contents);
+ $hilite = str_replace( "[googleplugin]", $this->highlightedTerms, $hilite );
- print( $hilite );
- }
+ print( $hilite );
}
+}
- PluginManager::registerPlugin( "google", "PluginGoogle" );
?>
More information about the pLog-svn
mailing list