Recent Topics

1 Sep 26, 2008 15:53    

Hey guys, I made this for work so I can't really host it anywhere... I will paste it into here as its a small code.

I must admit I had a few problems getting to grips with the API, so some code in there is unnecessary but atleast it works!

Description:

The user interface will allow you to add HTML code to be displayed according to country, currently it had HTML for U.S. U.K. and Global.


<?php
/**
 * This file implements the TEST plugin.
 *
 * For the most recent and complete Plugin API documentation
 * see {@link Plugin} in ../evocore/_plugin.class.php.
 *
 * This file is part of the evoCore framework - {@link http://evocore.net/}
 * See also {@link http://sourceforge.net/projects/evocms/}.
 *
 * @copyright (c)2003-2008 by Francois PLANQUE - {@link http://fplanque.net/}
 * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
 *
 * {@internal License choice
 * - If you have received this file as part of a package, please find the license.txt file in
 *   the same folder or the closest folder above for complete license terms.
 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
 *   then you must choose one of the following licenses before using the file:
 *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
 *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
 * }}
 *
 * {@internal Open Source relicensing agreement:
 * Daniel HAHLER grants Francois PLANQUE the right to license
 * Daniel HAHLER's contributions to this file and the b2evolution project
 * under any OSI approved OSS license (http://www.opensource.org/licenses/).
 * }}
 *
 * @package plugins
 *
 * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
 * @author fplanque: Francois PLANQUE - {@link http://fplanque.net/}
 * @author blueyed: Daniel HAHLER
 *
 * @version $Id: _test.plugin.php,v 1.72 2008/01/21 09:35:41 fplanque Exp $
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


/**
 * TEST Plugin
 *
 * This plugin responds to virtually all possible plugin events :P
 *
 * @package plugins
 */
class geoip_plugin extends Plugin
{
	/**
	 * Variables below MUST be overriden by plugin implementations,
	 * either in the subclass declaration or in the subclass constructor.
	 */
	var $name = 'GeoIPHTML';
	var $code = 'evo_geoip';
	var $priority = 20;
	var $version = '0.1';
	var $author = 'fone-me.com';
	var $help_url = '';  // empty URL defaults to manual wiki

	/*
	 * These variables MAY be overriden.
	 */
	var $apply_rendering = 'opt-out';
	var $number_of_installs = 1;
	var $group = 'widget';


	/**
	 * Init
	 *
	 * This gets called after a plugin has been registered/instantiated.
	 */
	function PluginInit( & $params )
	{
		$this->short_desc = 'GeoIP HTML';
		$this->long_desc = 'This plugin check the location of an IP (user) and returns HTML accordingly.';
	}


	/**
	 * Get the settings that the plugin can use.
	 *
	 * Those settings are transfered into a Settings member object of the plugin
	 * and can be edited in the backoffice (Settings / Plugins).
	 *
	 * @see Plugin::GetDefaultSettings()
	 * @see PluginSettings
	 * @see Plugin::PluginSettingsValidateSet()
	 * @return array
	 */
	function GetDefaultSettings( & $params )
	{
		
		$r = array(
			'GB' => array(
				'label' => 'GB',
				'type' => 'textarea',
				'note' => 'Insert GB HTML.',
			),
			'US' => array(
				'label' => 'US',
				'type' => 'textarea',
				'note' => 'Insert US HTML.',
			),
			'Global' => array(
				'label' => 'Global',
				'type' => 'textarea',
				'note' => 'If the user is not US or GB, I want to display something worth displaying.',
			),
		);

		if( $params['for_editing'] )
		{ // we're asked for the settings for editing:
			if( $this->Settings->get('my_select') == 'mon' )
			{
				$r['a_disabled_one']['disabled'] = false;
			}
		}

		return $r;
	}
	
		function get_widget_param_definitions( & $params )
	{
		
		$r = array(
			'GB' => array(
				'label' => 'GB',
				'type' => 'html_textarea',
				'note' => 'Insert GB HTML.',
			),
			'US' => array(
				'label' => 'US',
				'type' => 'html_textarea',
				'note' => 'Insert US HTML.',
			),
			'Global' => array(
				'label' => 'Global',
				'type' => 'html_textarea',
				'note' => 'If the user is not US or GB, I want to display something worth displaying.',
			),
		);
		
		foreach ($r as $c=>$v) {
			
			addslashes($params[$c]);
			
		}
				
		return $r;
	}


	function SkinTag( $params ) {		
		
		$this->getHTML($params);
		
	}
	
	function getHTML( $params ) {
		
		if (isset($_GET['bamf'])) {
		
		$_SERVER['REMOTE_ADDR'] = $_GET['bamf'];
		
		}
		
		$country = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
		
		if ($country == "GB") {
		//GB
			echo $params['GB'];
			
		} else if ($country == "US") {
		//US
			echo $params['US'];	
			
		} else {
		//Global
			echo $params['Global'];
			
		}
		
	}
	
	
		function RenderItemAsHtml( & $params )
	{
		// Dummy placeholder. Without it the plugin would ne be considered to be a renderer...
		return false;
	}


	/**
	 * Perform rendering (at display time, i-e: NOT cached)
	 *
	 * @see Plugin::DisplayItemAsHtml()
	 */
	function DisplayItemAsHtml( & $params )
	{
		$content = & $params['data'];

		return true;
	}
	
}
?>

Requires: Maxmind GeoIP (Compiled in linux)

Note: This is not a serious plugin, and will probably NEVER be updated!

Feel free to edit and use.


Form is loading...