Table of Contents

NP_QueryLog

Stores and displayes all the search queries performed on your weblog.

General Plugin info
Author: -=Xiffy=-, mod by admun (Edmond Hui)
Current Version: 0.02
Download: -
Code: code
Demo: -
Forum Thread: -

This is a very simple plugin that listens to your searchbox in your weblog. Everytime a visitor performs a search on your site (mind you, NOT google) the query is logged to the database.

You can retrieve a list of the latest internal searchquery by adding <%QueryLog%> to the skinpart of your likings.

Options

This plugin has one option; the amount to display.

<%QueryLog(20)%>

will show the last 20 searches performed on your site.

Code

<?php
class NP_QueryLog extends NucleusPlugin {
 
	function getEventList() { return array('PreSkinParse');	}
 
	function event_preSkinParse($data) {
	  global $query;
          // security fix.... strip script tags and alike.... I got a
          // cross-site redirect hack.....
          $query = strip_tags($query);
	  if ($data['type'] == "search" ) {
      $sqlquery = "INSERT INTO ". sql_table('plugin_querylog') ." (querystr) VALUES ('".addslashes($query) ."')";
	    sql_query($sqlquery);
	  }
	}
 
  function doSkinVar($skintype, $amount = 10) {
    $query = "SELECT querystr "
           . ", UNIX_TIMESTAMP(querywhen) AS querywhen"
           . " FROM ".sql_table('plugin_querylog')
           . " ORDER BY querywhen DESC"
           .  " LIMIT ". intval($amount);
    $refs = sql_query($query);
    if ($refs) {
        echo "<ul class='search'>";
        while ($obj = mysql_fetch_object($refs)) 
            echo "<li>".
                 strftime("%d.%m.%Y - %H:%M:%S",$obj->querywhen + (0 * 3600)).
                 " : <a href=\"/blog/?blogid=1&amp;amount=0&amp;query=".
                 urlencode($obj->querystr)."\">". 
                 htmlspecialchars($obj->querystr).
                 "</a></li>";
        echo "</ul>";
    }
  }
 
  function getName()   { return 'QueryLog'; }
  function getAuthor() { return '-=Xiffy=-, admun (Edmond Hui)'; }
  function getURL()    { return 'http://xiffy.nl/weblog/'; }
  function getVersion(){ return '0.02'; }
  function getDescription() {return 'Keeps track of the queries run on your weblog  <%QueryLog(10)%> to see the top searches'; }
 
  function install(){
      sql_query ("CREATE TABLE ".sql_table('plugin_querylog')." (querystr VARCHAR(120) NOT NULL, querywhen TIMESTAMP NOT NULL, logid int(11) NOT NULL auto_increment, KEY qeurystr (querystr), KEY id (logid))");
  }
 
  function uninstall(){
      sql_query ("DROP TABLE ".sql_table('plugin_querylog'));
  }
 
  function getTableList() {
      return array(sql_table('plugin_querylog'));
  }
 
	function supportsFeature($feature) {
		switch($feature) {
			case 'SqlTablePrefix':
				return 1;
			default:
				return 0;
		}
	}
}
?>

Plugin review

NP_QueryLog version 0.02 works with Nucleus CMS version 3.31 - 2007-10-28 Armon

querylog.txt · Last modified: 2007/10/28 16:22 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki