HEX
Server: Apache/2.4.25
System: Linux ion14 4.9.0-8-amd64 #1 SMP Debian 4.9.144-3.1 (2019-02-19) x86_64
User: (10087)
PHP: 7.4.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,system, exec, shell_exec, passthru, popen, proc_open
Upload Files
File: /home/www/web115/wordpress/wp-content/plugins/digimember/application/model/data/ip_counter.php
<?php

class digimember_IpCounterData extends ncore_BaseData
{
    const store_log_days = 90;

    function getForUser( $user_id )
    {
        $user_id = ncore_washInt( $user_id );

        $table = $this->sqlTableName();

        $date = ncore_dbDate( 'now', 'date' );

        $sql = "SELECT COUNT(DISTINCT ip) AS count
                FROM `$table`
                WHERE user_id = $user_id
                  AND DATE(created) = '$date'";

        $rows = $this->db()->query( $sql );
        $row = $rows[0];
        $count = $row->count;

        return intval($count);
    }

    function count( $user_id )
    {
        $ip = ncore_clientIp();

        $table = $this->sqlTableName();

        $user_id = ncore_washInt( $user_id );
        $ip = ncore_washText( $ip, '.' );

        if (!$user_id || !$ip)
        {
            return;
        }

        $date = ncore_dbDate( 'now', 'date' );

        $sql = "UPDATE `$table`
                SET count = count + 1
                WHERE ip = '$ip'
                  AND user_id = $user_id
                  AND created LIKE '$date %'";

        $this->db()->query( $sql );

        if (!$this->db()->modified())
        {
            $data = array(
                'count' => 1,
                'ip' => $ip,
                'user_id' => $user_id,
            );

            $this->create( $data );
        }
    }

    public function cronDaily()
    {
        $db = $this->db();

        $table = $this->sqlTableName();

        $days = self::store_log_days;

        $now = ncore_dbDate();

        $db->query("DELETE FROM `$table`
                    WHERE created < '$now' - INTERVAL $days DAY");

        // LEGACY CODE - REMOVE in 2019
        // remove old clear text ip
        $db->query("DELETE FROM `$table`
                    WHERE ip LIKE '%.%.%' OR ip LIKE '%::%'");
    }

    public function deleteForUserId($userId)
    {
        $db = $this->db();

        $table = $this->sqlTableName();

        $db->query("DELETE FROM `$table`
                    WHERE user_id = '$userId'");
    }

    //
    // protected section
    //
    protected function sqlBaseTableName()
    {
        return 'ip_counter';
    }

    protected function sqlTableMeta()
    {
       $columns = array(
        'ip' => 'string[63]',
        'user_id' => 'int',
        'count' => 'int',
       );

       $indexes = array( 'user_id', 'ip' );

       $meta = array(
        'columns' => $columns,
        'indexes' => $indexes,
       );

       return $meta;
    }

}