Location: PHPKode > projects > Obsessive Website Statistics > ows/plugins/disabled/05_ows_db_limit.php
	$Id: 05_ows_db_limit.php 99 2007-08-25 06:34:13Z randomperson83 $

	Obsessive Web Statistics
    Copyright (C) 2007 Dustin Spicuzza <hide@address.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
	You need to add configuration variables to enable this to work. Otherwise, it will fail.
	Supported variables are as follows (subkeys of $cfg['websites']['websitename']):
	['enable_db_limit']		true/false. MUST be set, or it will fail.
	['days_to_keep']		Integer that tells us how many days should be kept in the 
							database. If you do not set this, it will default to 30 days. 

class OWSDBLimit implements iPlugin, iRejectPlugin {

	// this should return a unique ID identifying the plugin, should start with an alpha,
	// should use basename instead of just __FILE__ otherwise it could expose path information
	public function getPluginId(){
		return 'p'. md5(basename(__FILE__) . get_class());

	// returns an associative array describing the plugin
	public function getPluginInformation(){
		// automagically increment the revision number :)
		$revision = trim(str_replace('Rev:','',str_replace('$','','$Rev: 99 $')));
		return array(
			'author' => 'Dustin Spicuzza (OWS builtin)',
			'pluginName' => 'DB Limit Plugin',
			'version' => "1.0.$revision",
			'description' => 'Attempts to limit the size of the database, by only allowing in records less than X days old.',
			'url' => 'http://obsessive.sourceforge.net/'
	var $do_compare = false;
	var $earliest_date = false;
		Treat this like a constructor. This is called before all phases of
		analysis, and is only called once per website. It should be used to
		clean up website-specific variables. Like SQL id's. 
	public function InitializeRejection($website){
		// initialize this
		$this->fact_table = db_escape_string(str_replace('.','_',$website));
		$date_table = db_escape_string(str_replace('.','_',$website) . '_date');
		// get website options
		$options = get_website_options($website);
		// ensure that the user initialized the options for this, otherwise
		// we should fail!
		if (!array_key_exists('enable_db_limit',$options))
			return show_error("You need to add configuration options for this plugin (" . basename(__FILE__) . ")!");
		$this->do_compare = $options['enable_db_limit'];
		if ($this->do_compare){
			if (!array_key_exists('days_to_keep',$options))
				$options['days_to_keep'] = 30;
			// determine how many days to keep
			$this->earliest_date = strtotime('-' . intval($options['days_to_keep']+1) . ' days');
			if (!db_is_valid_result(db_query("DELETE $this->fact_table FROM $this->fact_table INNER JOIN $date_table ON $date_table.date_id = $this->fact_table.date_id WHERE $date_table.date <= '" . date("Y-m-d",$this->earliest_date) . "'")))
				return false;
		return true;

		This function returns true or false. If it returns true, analysis is not performed on
		the line. If false, the analysis engine performs analysis on the line.
	function RejectLine($website, $line){
		if ($this->do_compare){
			// transform date
			$date = strtotime(str_replace('/',' ',$line['Date']));
			// compare it
			if ($date <= $this->earliest_date)
				return true;
		return false;

$db_limit = new OWSDBLimit();

Return current item: Obsessive Website Statistics