HEX
Server: Apache/2.4.25 (Debian)
System: Linux server17 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
User: web37 (1062)
PHP: 7.4.30
Disabled: show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
Upload Files
File: /var/www/web37/htdocs/fickanzeiger/models/OtherReferrerSiteModel.php
<?php
/**
 * Arfooo
 * 
 * @package    Arfooo
 * @copyright  Copyright (c) Arfooo Annuaire (fr) and Arfooo Directory (en)
 *             by Guillaume Hocine (c) 2007 - 2010
 *             http://www.arfooo.com/ (fr) and http://www.arfooo.net/ (en)
 * @author     Guillaume Hocine & Adrian Galewski
 * @license    http://creativecommons.org/licenses/by/2.0/fr/ Creative Commons
 */


class OtherReferrerSiteModel extends Model
{
    protected $primaryKey = "referrerSiteId";

    function removeAll()
    {
        $c = new Criteria();
        $this->del($c);
        $this->site->update(array("referrerTimes" => 0), $c);

        $todayDate = date("Y-m-d");
        $this->setting->set('topReferrersLastResetDate', $todayDate);
        Cacher::getInstance()->clean("tag", array("setting"));
    }

    function incReferrerTimesOfSiteIfSiteIsInscripted($referrerUrl)
    {
        $hostName = AppRouter::getHostNameFromUrl($referrerUrl);
        if (empty($hostName)) {
            return;
        }

        $c = new Criteria();
        $c->add("url", str_replace(array("%", "_"), "", $hostName) . "%", "LIKE");
        $this->site->update(array("_referrerTimes" => "referrerTimes + 1"), $c);
    }

    function saveRefferingFromNotRegisteredSite($referrerUrl)
    {
        $hostName = AppRouter::getHostNameFromUrl($referrerUrl);
        if (empty($hostName)) {
            return;
        }

        $c = new Criteria();
        $c->add("url", $hostName);

        if ($this->getCount($c)) {
            $this->update(array("_ReferrerTimes" => "ReferrerTimes + 1"), $c);
        } else {
            $record = new OtherReferrerSiteRecord();
            $record->url = $hostName;
            $record->referrerTimes = 1;
            $record->save();
        }

    }

    function checkReset()
    {
        $removalNeeded = false;

        $todayDate = date("Y-m-d");
        $lastResetDate = Config::get('topReferrersLastResetDate');

        if (!preg_match('#^[0-9]{4}-[0-9]{2}-[0-9]{2}$#', $lastResetDate, $match)) {
            // invalid date
            $removalNeeded = true;
        } else {
            $todayTime = strtotime($todayDate);
            $nextRefreshTime = strtotime($lastResetDate . " + " . Config::get('deletionPeriodOfTopReferrers') . " days");

            if ($nextRefreshTime <= $todayTime) {
                $removalNeeded = true;
            }
        }

        if ($removalNeeded) {
            $this->removeAll();
        }
    }

    function saveReferrer($referrerUrl)
    {
        $this->checkReset();

        $ip = Request::getInstance()->getIp();
        $type = "ref";

        if (!$this->visit->exists($ip, $type, null, 24)) {
            $this->incReferrerTimesOfSiteIfSiteIsInscripted($referrerUrl);
            $this->saveRefferingFromNotRegisteredSite($referrerUrl); // save for registered sites too

            $visit = new VisitRecord();
            $visit->ip = $ip;
            $visit->type = $type;
            $visit->save();
        }
    }
}

class OtherReferrerSiteRecord extends ModelRecord
{

}