Phundament-Components
[ class tree: Phundament-Components ] [ index: Phundament-Components ] [ all elements ]

Source for file LGeoIP.php

Documentation is available at LGeoIP.php

  1. <?php
  2.  
  3. /**
  4.  * Class file.
  5.  *
  6.  * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  7.  * @copyright 2005, diemeisterei GmbH. All rights reserved.
  8.  * @author $Author: schmunk $
  9.  * @version $Revision: 236 $  $Date: 2006-05-30 23:39:46 +0200 (Di, 30 Mai 2006) $ $HeadURL: https://svn.sourceforge.net/svnroot/lithron/trunk/packages/LContainer/LBrick.php $
  10.  * @package Phundament.Components
  11.  * @subpackage Modules
  12.  */
  13.  
  14. /**
  15.  * Important: Order of Overrides
  16.  * User Role 'GeoIp.CODE' (most important)
  17.  * Session Value 'LGeoIP_OverrideIp'
  18.  * Parameter 'OverrideIp' in application.xml
  19.  *
  20.  * @package System.Util
  21.  * @subpackage Modules
  22.  */
  23.  
  24. Prado :: setPathOfAlias("LGeoIP"dirname(__FILE__));
  25. Prado :: using("LGeoIP.LGeoIP.3rdParty.GeoIP");
  26.  
  27. class LGeoIP extends TModule
  28. {
  29.     public $Instance;
  30.     public $Class;
  31.     private $_d;
  32.  
  33.     function init($config)
  34.     {
  35.         parent :: init($config);
  36.         $this->InstanceNet_GeoIP :: getInstance(Prado :: getPathOfAlias('LGeoIP''/LGeoIP/3rdParty/GeoIP.dat');
  37.  
  38.         if ($ip$this->Application->Session['LGeoIP_OverrideIp'])
  39.             $addr$ip;
  40.         elseif ($ip$this->Application->Parameters['OverrideIp']$addr$ip;
  41.         else
  42.             $addr$_SERVER['REMOTE_ADDR'];
  43.  
  44.         Prado :: trace("Remote addr$addr""Lithron.LGeoIP");
  45.         try
  46.         {
  47.             $this->_d['CountryCode']$this->Instance->lookupCountryCode($addr);
  48.             $this->_d['CountryName']$this->Instance->lookupCountryName($addr);
  49.             if (empty ($this->_d['CountryCode']))
  50.                 throw new Exception;
  51.             Prado :: trace("c" $this->_d['CountryName']"Lithron.LGeoIP");
  52.         }
  53.         catch (Exception $e)
  54.         {
  55.             Prado :: trace("Country could not be detected""Lithron.LGeoIP");
  56.             $this->_d['CountryCode']"INT";
  57.             $this->_d['CountryName']"International";
  58.         }
  59.  
  60.     }
  61.  
  62.     function checkSpecialRole()
  63.     {
  64.         // TODO - BIIIIG // remove this !!!
  65.         if (isset ($_REQUEST['LGeoIP_DebugPwd']))
  66.         {
  67.             if ($_REQUEST['LGeoIP_DebugPwd'== "TEMP")
  68.             {
  69.                 $this->_d['CountryCode']$_REQUEST['LGeoIP_CountryCode'];
  70.                 $this->_d['CountryName']"A land named: " $_REQUEST['LGeoIP_CountryCode'];
  71.             }
  72.         }
  73.  
  74.         // init is too early :( TODO - Session Hack
  75.         elseif ($this->Application->User instanceof TUserforeach ($this->Application->User->getRoles(AS $role)
  76.         {
  77.             if ($_overridestrtoupper(str_replace("LGeoIP."""strstr($role"LGeoIP."))))
  78.             {
  79.                 $this->Session['LGeoIP.CountryCode']$this->_d['CountryCode']$_override;
  80.                 $this->Session['LGeoIP.CountryName']$this->_d['CountryName']"Admin from " $_override;
  81.             }
  82.         }
  83. else
  84.     if ($this->Session['LGeoIP.CountryCode'])
  85.     {
  86.         #echo "SESSHACK";
  87.         $this->_d['CountryCode']$this->Session['LGeoIP.CountryCode'];
  88.         $this->_d['CountryName']$this->Session['LGeoIP.CountryName'];
  89.     }
  90.  
  91. }
  92.  
  93. function getCountryCode()
  94. {
  95.     $this->checkSpecialRole();
  96.     return $this->_d['CountryCode'];
  97. }
  98.  
  99. function getCountryName()
  100. {
  101.     $this->checkSpecialRole();
  102.     return $this->_d['CountryName'];
  103. }
  104.  
  105. {
  106.     try
  107.     {
  108.         return $this->publishAsset('LGeoIP/images/' strtolower($this->getCountryCode('.gif'));
  109.     }
  110.     catch (Exception $e)
  111.     {
  112.         Prado::log($e->getMessage(),8,"Lithron.LGeoIP");
  113.         return "";
  114.     }
  115.  
  116. }
  117.  
  118. }
  119. ?>

Documentation generated on Sun, 25 Feb 2007 16:10:30 +0100 by phpDocumentor 1.3.1