add basic files

This commit is contained in:
Daniel Seifert 2011-10-19 20:05:36 +00:00
parent 429c6cd8c5
commit 0dab33beae
6 changed files with 312 additions and 0 deletions

5
.gitattributes vendored
View File

@ -1 +1,6 @@
* text=auto !eol
copy_this/core/d3ce_online_users.php -text
copy_this/modules/d3ce_usersonline/views/d3ce_oxcmp_utils_usersonline.php -text
copy_this/out/basic/tpl/inc/d3ce_usersonline.tpl -text
setup+doku/readme_de.txt -text
setup+doku/readme_en.txt -text

View File

@ -0,0 +1,70 @@
<?php
/**
* 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/>.
*
* @author Aggrosoft, Data Development
*/
class d3ce_online_users extends oxI18n
{
/**
* Object core table name
*
* @var string
*/
protected $_sCoreTbl = 'd3ce_online_users';
/**
* Current class name
*
* @var string
*/
protected $_sClassName = 'd3ce_online_users';
public function __construct($aParams = null)
{
parent::__construct();
$this->init( 'd3ce_online_users' );
}
public function clearOldItems($iExpTime)
{
$exptime = time() - $iExpTime;
oxDb::getDb()->Execute("delete from ".$this->_sCoreTbl." where timevisit < $exptime");
}
public function getActUserItem($sUserIPHash)
{
$sSelect = "select count(*) from $this->_sCoreTbl where visitor='".$sUserIPHash."'";
return oxDb::getDb()->getOne( $sSelect );
}
public function getUserCount()
{
$sSelect = "select count(*) from ".$this->_sCoreTbl." order by timevisit desc";
$iCount = oxDb::getDb()->getOne($sSelect);
return $iCount;
}
public function setActTimeVisit($sUserIpHash)
{
oxDb::getDb()->Execute("update ".$this->_sCoreTbl." set timevisit='".time()."', oxclass = '".$this->getConfig()->getActiveView()->getClassName()."' where visitor='".$sUserIpHash."'");
}
public function insertActUser($sUserIpHash)
{
oxDb::getDb()->Execute("insert into ".$this->_sCoreTbl." (visitor,timevisit,oxclass) values ('".$sUserIpHash."','".time()."', '".$this->getConfig()->getActiveView()->getClassName()."')");
}
}

View File

@ -0,0 +1,144 @@
<?php
/**
* 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/>.
*
* @author Aggrosoft, Data Development
*/
class d3ce_oxcmp_utils_usersonline extends d3ce_oxcmp_utils_usersonline_parent
{
protected $_iExpTime = 600; // (in seconds)
protected $_sUserIpHash = null;
protected $_remoteAddr = null;
protected $_httpClientIp = null;
protected $_httpXForwardedFor = null;
protected $_httpXForwarded = null;
protected $_httpForwardedFor = null;
protected $_httpForwarded = null;
protected $_httpVia = null;
protected $_httpXComingFrom = null;
protected $_httpComingFrom = null;
protected $_proxyIp = null;
protected $_directIp = null;
public function init()
{
$this->blIsComponent = true;
parent::init();
}
public function render()
{
$ret = parent::render();
//WE ARE NOT ALLOWED TO STORE THE REAL IP
$this->_sUserIpHash = md5($this->_getTrueIP());
$this->utime = time();
$oUserOnline = &oxNew('d3ce_online_users');
$oUserOnline->clearOldItems($this->_iExpTime);
$iUserExist = $oUserOnline->getActUserItem($this->_sUserIpHash);
if ($iUserExist > 0) {
$oUserOnline->setActTimeVisit($this->_sUserIpHash);
} else {
$oUserOnline->insertActUser($this->_sUserIpHash);
}
$this->_oParent->_aViewData['usersonline'] = $oUserOnline->getUserCount();
return $ret;
}
private function _getIpData($sTargetVarName, $sDataName)
{
if (empty($this->{$sTargetVarName}))
{
if (!empty($_SERVER) && isset($_SERVER[$sDataName]))
$this->{$sTargetVarName} = $_SERVER[$sDataName];
else if (!empty($_ENV) && isset($_ENV[$sDataName]))
$this->{$sTargetVarName} = $_ENV[$sDataName];
else if (@getenv($sDataName))
$this->{$sTargetVarName} = getenv($sDataName);
}
}
private function _getTrueIP()
{
$this->_getIpData('_remoteAddr','REMOTE_ADDR');
$this->_getIpData('_httpClientIp','HTTP_CLIENT_IP');
$this->_getIpData('_httpXForwardedFor','HTTP_X_FORWARDED_FOR');
$this->_getIpData('_httpXForwarded','HTTP_X_FORWARDED');
$this->_getIpData('_httpForwardedFor','HTTP_FORWARDED_FOR');
$this->_getIpData('_httpForwarded','HTTP_FORWARDED');
$this->_getIpData('_httpVia','HTTP_VIA');
$this->_getIpData('_httpXComingFrom','HTTP_X_COMING_FROM');
$this->_getIpData('_httpComingFrom','HTTP_COMING_FROM');
// Gets the default ip sent by the user
if (!empty($this->_remoteAddr))
$this->_directIp = $this->_remoteAddr;
// Gets the proxy ip sent by the user
if (!empty($this->_httpXForwardedFor))
$this->_proxyIp = $this->_httpXForwardedFor;
else if (!empty($this->_httpXForwarded))
$this->_proxyIp = $this->_httpXForwarded;
else if (!empty($this->_httpForwardedFor))
$this->_proxyIp = $this->_httpForwardedFor;
else if (!empty($this->_httpForwarded))
$this->_proxyIp = $this->_httpForwarded;
else if (!empty($this->_httpVia))
$this->_proxyIp = $this->_httpVia;
else if (!empty($this->_httpXComingFrom))
$this->_proxyIp = $this->_httpXComingFrom;
else if (!empty($this->_httpComingFrom))
$this->_proxyIp = $this->_httpComingFrom;
// Returns the true IP if it has been found, else ...
if (empty($this->_proxyIp))
{
// True IP without proxy
return $this->_directIp;
}
else
{
$is_ip = ereg('^([0-9]{1,3}.){3,3}[0-9]{1,3}', $this->_proxyIp, $regs);
if ($is_ip && (count($regs) > 0))
{
// True IP behind a proxy
return $regs[0];
}
else
{
if (empty($this->_httpClientIp))
{
// Can't define IP: there is a proxy but we don't have
// information about the true IP
return "(unbekannt) " . $this->_proxyIp;
}
else
{
// better than nothing
return $this->_httpClientIp;
}
}
}
}
}

View File

@ -0,0 +1,6 @@
<strong class="h2" id="test_LeftSideInfoHeader">Online</strong>
[{strip}]
<div class="partners" style="padding-left: 10px;">
[{$usersonline }] User(s)
</div>
[{/strip}]

45
setup+doku/readme_de.txt Normal file
View File

@ -0,0 +1,45 @@
Authors: Aggrosoft it intelligence, D3 Data Development
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/>.
-----------------------------------------------------------------------
Installation:
Kopieren Sie die Inhalte des "copy_this"-Ordner in Ihr Shop-Verzeichnis,
Führen Sie folgendes Script in Ihrer Datenbank aus:
CREATE TABLE d3ce_online_users (
`id` int(11) NOT NULL auto_increment,
`visitor` varchar(100) default NULL,
`timevisit` int(11) NOT NULL default '0',
`oxclass` varchar(32) collate latin1_general_ci NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
Fügen Sie nun das Modul zu Ihrem Shop hinzu:
oxcmp_utils => d3ce_usersonline/views/d3ce_oxcmp_utils_usersonline
Sie können den counter nun in eines Ihrer Templates einbauen (evtl. _left.tpl)
Hierfür benötigen Sie lediglich folgende Zeile:
[{include file="inc/d3ce_usersonline.tpl"}]
HINWEIS:
Da nach deutschem Recht nicht einfach irgendwelche IP's in der DB abgespeichert werden
dürfen und Sie auch sicherlich kein Interesse an den IP's haben wird aus der User IP
ein Hash errechnet und dieser zum Vergleich herangezogen und gespeichert.

42
setup+doku/readme_en.txt Normal file
View File

@ -0,0 +1,42 @@
Authors: Aggrosoft it intelligence, D3 Data Development
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/>.
-----------------------------------------------------------------------
Installation:
Copy the contents in the "copy_this"-folder into your oxid folder.
Execute the following SQL Script in your oxid database (tools menu in admin backend):
CREATE TABLE d3ce_online_users (
id int(11) NOT NULL auto_increment,
visitor varchar(100) default NULL,
timevisit int(11) NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
Add the Module to your Oxid Modules in the admin backend:
oxcmp_utils => d3ce_usersonline/views/d3ce_oxcmp_utils_usersonline
Now you can include the counter anywhere in your templates (e.g. _left.tpl)
You just need the following line:
[{include file="inc/d3ce_usersonline.tpl"}]
LEGAL NOTICE:
The users ip is never saved in your database, the ip will be hashed before it is stored.