Location: PHPKode > projects > Obsessive Website Statistics > ows/plugins/50_ows_individual.php
<?php
/*
	$Id: 50_ows_individual.php 87 2007-08-14 06:00:25Z 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
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    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/>.
	
	This plugin is intended to provide the user easy to access 'canned' reports.
	So yes, there are other ways you can get these reports.. but hopefully this
	plugin will provide simple ways to get at them. 
	
	TODO: The columns to display should be more generic, use an array to generate them
	or something. Easier to add to them.

*/


class OWSSpecific implements iPlugin, iFilterPlugin{

	var $prefix;

	function __construct(){
		$this->prefix = $this->getPluginId() . '_';
	}

	// 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: 87 $')));
		return array(
			'author' => 'Dustin Spicuzza (OWS builtin)',
			'pluginName' => 'Specific Analysis Plugin',
			'version' => "1.0.$revision",
			'description' => 'Shows more specific analysis information. It may duplicate query types, but it is designed to provide a number of commonly used and useful reports.',
			'url' => 'http://obsessive.sourceforge.net/'
		);
	}

	
	// returns name of filter to show to user
	public function getDisplayName(){
		return "Specific Analysis";
	}
	
	// this function outputs html which is displayed inside of a form
	// submit button is already defined for you
	public function showOptions(){
	
		// so, give the user some canned report types to show
		//
		// ugh. This isn't working exactly how I thought it should.. needs to be tweaked
		// hmm. Better?
		
		echo '<div class="floater"><p><u>Reports:</u></p><div class="alignright">' . 
			'External Referrers' . plugin_checkbox($this, 'extreferrer', true) .
			'<br/>Everything' . plugin_checkbox($this, 'everything', false) .
			'<br/>File Downloads' . plugin_checkbox($this, 'files', false) .
			'<br/>Image Accesses' . plugin_checkbox($this, 'img', false) .
			'<br/>404 Errors' . plugin_checkbox($this, '404', false) .
			'</div></div>';
	
		// add (useful) columns they can display
		echo '<div class="floater"><p><u>Columns to display:</u></p><table>' . 
			'<tr><td>Date</td><td>' . generate_select_from_array($this->prefix . 'c_date', 'sortdesc', $this->col_disp) . '</td></tr>' .
			'<tr><td>Time</td><td>' . generate_select_from_array($this->prefix . 'c_time', 'sortdesc', $this->col_disp) . '</td></tr>' .
			'<tr><td>Hostname</td><td>' . generate_select_from_array($this->prefix . 'c_host', 'no', $this->col_disp) . '</td></tr>' .
			'<tr><td>Request String</td><td>' . generate_select_from_array($this->prefix . 'c_request', 'no', $this->col_disp) . '</td></tr>' .
			'<tr><td>Filename</td><td>' . generate_select_from_array($this->prefix . 'c_filename', 'yes', $this->col_disp) . '</td></tr>' .
			'<tr><td>Bytes</td><td>' . generate_select_from_array($this->prefix . 'c_bytes', 'no', $this->col_disp) . '</td></tr>' .
			'<tr><td>Referrer</td><td>' . generate_select_from_array($this->prefix . 'c_referrer', 'yes', $this->col_disp) . '</td></tr>' .
			'<tr><td>User-Agent</td><td>' . generate_select_from_array($this->prefix . 'c_agent', 'no', $this->col_disp) . '</td></tr>' .
			'</table></div>';
	
		show_common_limits();	
	}
	
	// array of column options
	var $col_disp = array(array('yes','Show'),array('sortasc','Sorted Ascending'), array('sortdesc','Sorted Decending'),array('no','-'));
	
	// makes decisions based on column options
	private function add_var($query,$dimension,$varname){
	
		$var = get_post_var($this->prefix . "c_$varname");
		$dimension = $query->DIMENSION($dimension);
		
		switch($var){
			case 'yes':
				$query->SELECT("$dimension.$varname");
				break;
			// this is aggregate function, doesn't belong here
			//case 'distinct':
			//	$query->SELECT("DISTINCT $dimension.$varname");
			//	$query->SELECT("COUNT($dimension.$varname)",$varname . '_s');
			//	$query->GROUP_BY("$dimension.$varname");
			//	break;
			case 'sortasc':
				$query->SELECT("$dimension.$varname");
				$query->ORDER_BY("$dimension.$varname ASC");
			case 'sortdesc':
				$query->SELECT("$dimension.$varname");
				$query->ORDER_BY("$dimension.$varname DESC");
		}
	}
	
	// this function shows the filtered results
	public function showResults($domain){
	
		
		$query = new SQLSelect($domain);
		
		// add common options
		foreach (
			array('date','time','host','filename','request','referrer','agent')
			as $var){
			
			// TODO: get rid of this special case, use a better style of array
			if ($var == 'filename')
				$this->add_var($query,'request','filename');
			else
				$this->add_var($query,$var,$var);
		}
		
		// external referrers
		if (get_post_var($this->prefix . 'extreferrer') == 'yes'){
		
			echo "<div class=\"floater\"><h4>External Referrers</h4>";
		
			$q = clone $query;	// copy the object
		
			$dimension = $q->DIMENSION('referrer');
			$q->WHERE("$dimension.is_external = TRUE AND $dimension.referrer <> ''");
			
			show_result_table($q);
			
			echo "</div>";
		}
		
		// everything
		if (get_post_var($this->prefix . 'everything') == 'yes'){
		
			echo "<div class=\"floater\"><h4>Everything</h4>";
		
			$q = clone $query;	// copy the object
			
			show_result_table($q);
			echo "</div>";
		}
		
		
		// file downloads
		if (get_post_var($this->prefix . 'files') == 'yes'){
		
			echo "<div class=\"floater\"><h4>File Downloads</h4>";
		
			$q = clone $query;	// copy the object
			
			$dimension = $q->DIMENSION('request');
			$q->WHERE("$dimension.is_download = TRUE");
		
			show_result_table($q);
			echo "</div>";
		}
		
		
		// image downloads
		if (get_post_var($this->prefix . 'img') == 'yes'){
		
			echo "<div class=\"floater\"><h4>Image Downloads</h4>";
		
			$q = clone $query;	// copy the object
			
			$dimension = $q->DIMENSION('request');
			$q->WHERE("$dimension.is_image = TRUE");
		
			show_result_table($q);
			echo "</div>";
		}
		
		
		// 404 Errors
		if (get_post_var($this->prefix . '404') == 'yes'){
		
			echo "<div class=\"floater\"><h4>404 Errors</h4>";
		
			$q = clone $query;	// copy the object
			
			$dimension = $q->DIMENSION('status');
			$q->WHERE("$dimension.status = 404");
			
			show_result_table($q);
			echo "</div>";
		}
		
	}
}



register_plugin('filter',new OWSSpecific());

?>
Return current item: Obsessive Website Statistics