Пример #1
0
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    return;
}
if (!empty($auth['user_id'])) {
    $partner_data = fn_get_partner_data($auth['user_id']);
    if (!empty($partner_data)) {
        $titles = fn_get_static_data_section('T');
        if (!empty($titles) && is_array($titles)) {
            foreach ($titles as $t) {
                if (!empty($t['param']) && $t['param'] == @$partner_data['title']) {
                    $partner_data['title_descr'] = $t['descr'];
                }
            }
        }
        $partner_data['total_payouts'] = db_get_field("SELECT SUM(amount) FROM ?:affiliate_payouts WHERE partner_id = ?i", $auth['user_id']);
        $cnt_period = Registry::if_get('addons.affiliate.number_last_periods', 10);
        $start_date = fn_get_date_of_payment_period($cnt_period);
        if (!empty($start_date)) {
            $last_payouts = array();
            $k = $cnt_period;
            $max_amount = 0;
            $cur_date = getdate(TIME);
            $checkpoint_1 = 1;
            $checkpoint_2 = 16;
            $checkpoint_return = $cur_date['mday'] < $checkpoint_2 ? false : true;
            while (!empty($k)) {
                switch (Registry::get('addons.affiliate.payment_period')) {
                    case '1w':
                        $end_date = $start_date + 7 * 24 * 3600;
                        break;
                    case '2w':
Пример #2
0
 /**
  * Call cache actions - get, set, clear
  *
  * @param string $action action name
  * @param array $params action parameters
  *
  * @return mixed data depend on action
  */
 static function _cache_actions($action, $params = array())
 {
     if (empty(self::$_cache_backend)) {
         self::$_cache_backend = Registry::if_get('config.cache_backend', 'file');
     }
     if (!class_exists('Cache_backend_' . self::$_cache_backend)) {
         include DIR_CORE . 'cache/class.cache_backend_' . self::$_cache_backend . '.php';
         if (!class_exists('Cache_backend_' . self::$_cache_backend)) {
             die('Cache backend class ("' . self::$_cache_backend . '") was not found.');
         }
     }
     return call_user_func_array(array('Cache_backend_' . self::$_cache_backend, $action), $params);
 }
Пример #3
0
/**
 * Get list of templates that should be overriden by addons
 *
 * @param string $resource_name base template name
 * @param object $view templater object
 * @return string overridden template name
 */
function fn_addon_template_overrides($resource_name, &$view)
{
    static $init = false;
    $o_name = 'template_overrides_' . AREA;
    if ($init == false) {
        Registry::register_cache($o_name, array(), CACHE_LEVEL_STATIC);
        if (!Registry::is_exist($o_name)) {
            $template_overrides = array();
            foreach (Registry::get('addons') as $a => $_settings) {
                $odir = $view->template_dir . '/addons/' . $a . '/overrides';
                if (is_dir($odir)) {
                    $tpls = fn_get_dir_contents($odir, false, true, '', '', true);
                    foreach ($tpls as $k => $t) {
                        if (empty($template_overrides[md5($t)])) {
                            $template_overrides[md5($t)] = 'addons/' . $a . '/overrides/' . $t;
                        }
                    }
                }
            }
            if (empty($template_overrides)) {
                $template_overrides['plug'] = true;
            }
            Registry::set($o_name, $template_overrides);
        }
        $init = true;
    }
    return Registry::if_get($o_name . '.' . md5($resource_name), $resource_name);
}
Пример #4
0
function fn_log_event($type, $action, $data = array())
{
    $update = false;
    $content = array();
    $actions = Registry::get('settings.Logging.log_type_' . $type);
    $cut_data = Registry::if_get('log_cut_data', false);
    Registry::del('log_cut_data');
    if (empty($actions) || $action && !empty($actions) && empty($actions[$action])) {
        return false;
    }
    if (!empty($_SESSION['auth']['user_id'])) {
        $user_id = $_SESSION['auth']['user_id'];
    } else {
        $user_id = 0;
    }
    if ($type == 'users' && $action == 'logout' && !empty($data['user_id'])) {
        $user_id = $data['user_id'];
    }
    if ($user_id) {
        $udata = db_get_row("SELECT firstname, lastname, email FROM ?:users WHERE user_id = ?i", $user_id);
    }
    $event_type = 'N';
    // notice
    if (!empty($data['backtrace'])) {
        $_btrace = array();
        $func = '';
        foreach (array_reverse($data['backtrace']) as $v) {
            if (empty($v['file'])) {
                $func = $v['function'];
                continue;
            } elseif (!empty($func)) {
                $v['function'] = $func;
                $func = '';
            }
            $_btrace[] = array('file' => !empty($v['file']) ? $v['file'] : '', 'line' => !empty($v['line']) ? $v['line'] : '', 'function' => $v['function']);
        }
        $data['backtrace'] = serialize($_btrace);
    } else {
        $data['backtrace'] = '';
    }
    if ($type == 'orders') {
        $order_status_descr = fn_get_statuses(STATUSES_ORDER, true, true, true);
        $content = array('order' => '# ' . $data['order_id']);
        if ($action == 'status') {
            $content['status'] = $order_status_descr[$data['status_from']] . ' -> ' . $order_status_descr[$data['status_to']];
        }
    } elseif ($type == 'products') {
        $product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $data['product_id'], Registry::get('settings.Appearance.admin_default_language'));
        $content = array('product' => $product . ' (#' . $data['product_id'] . ')');
        if ($action == 'low_stock') {
            // log stock - warning
            $event_type = 'W';
        }
    } elseif ($type == 'categories') {
        $category = db_get_field("SELECT category FROM ?:category_descriptions WHERE category_id = ?i AND lang_code = ?s", $data['category_id'], Registry::get('settings.Appearance.admin_default_language'));
        $content = array('category' => $category . ' (#' . $data['category_id'] . ')');
    } elseif ($type == 'database') {
        if ($action == 'error') {
            $content = array('error' => $data['error']['message'], 'query' => $data['error']['query']);
            $event_type = 'E';
        }
    } elseif ($type == 'requests') {
        $long_data = strlen($data['response']) > LOG_MAX_DATA_LENGTH;
        if (!empty($cut_data)) {
            $data['data'] = preg_replace("/\\<(" . implode('|', $cut_data) . ")\\>(.*?)\\<\\/(" . implode('|', $cut_data) . ")\\>/s", '<${1}>******</${1}>', $data['data']);
            $data['data'] = preg_replace("/(" . implode('|', $cut_data) . ")=(.*?)(&)/s", '${1}=******${3}', $data['data']);
        }
        $content = array('url' => $data['url'], 'request' => $data['data'], 'response' => $long_data == false && preg_match('//u', $data['response']) ? $data['response'] : '');
    } elseif ($type == 'users') {
        if (!empty($data['time'])) {
            if (empty($_SESSION['log']['login_log_id'])) {
                return false;
            }
            $content = db_get_field('SELECT content FROM ?:logs WHERE log_id = ?i', $_SESSION['log']['login_log_id']);
            $content = unserialize($content);
            $minutes = ceil($data['time'] / 60);
            $hours = floor($minutes / 60);
            if ($hours) {
                $minutes -= $hours * 60;
            }
            if ($hours || $minutes) {
                $content['loggedin_time'] = ($hours ? $hours . ' |hours| ' : '') . ($minutes ? $minutes . ' |minutes|' : '');
            }
            if (!empty($data['timeout']) && $data['timeout']) {
                $content['timeout'] = true;
            }
            $update = $_SESSION['log']['login_log_id'];
        } else {
            if (!empty($data['user_id'])) {
                $info = db_get_row("SELECT firstname, lastname, email FROM ?:users WHERE user_id = ?i", $data['user_id']);
                $content = array('user' => $info['firstname'] . ($info['firstname'] || $info['lastname'] ? ' ' : '') . $info['lastname'] . '; ' . $info['email'] . ' (#' . $data['user_id'] . ')');
            } elseif (!empty($data['user'])) {
                $content = array('user' => $data['user']);
            }
            if (in_array($action, array('session', 'failed_login'))) {
                $ip = fn_get_ip();
                $content['ip_address'] = empty($data['ip']) ? $ip['host'] : $data['ip'];
            }
        }
        if ($action == 'failed_login') {
            // failed login - warning
            $event_type = 'W';
        }
    }
    fn_set_hook('save_log', $type, $action, $data, $user, $content, $event_type);
    $content = serialize($content);
    if ($update) {
        db_query('UPDATE ?:logs SET content = ?s WHERE log_id = ?i', $content, $update);
    } else {
        $row = array('user_id' => $user_id, 'timestamp' => TIME, 'type' => $type, 'action' => $action, 'event_type' => $event_type, 'content' => $content, 'backtrace' => $data['backtrace']);
        $log_id = db_query("INSERT INTO ?:logs ?e", $row);
        if ($type = 'users' && $action == 'session') {
            $_SESSION['log']['login_log_id'] = $log_id;
        }
    }
    return true;
}
Пример #5
0
/**
 * Cache query
 * 
 * @param string $query query which must be cached
 * @param string $value value received after the query was fulfilled
 */
function db_cache_query($query, $value, $args)
{
    $memc = new Memcache();
    $memc->connect('127.0.0.1', 11211) or die("Could not connect");
    $cache_name = serialize(array('query' => $query, 'args' => $args));
    preg_match_all("/\\?:(\\w+)/", $query, $m);
    $key = "c" . md5($cache_name);
    $memc->set($key, serialize($value), false, 60);
    $memc->close();
    return $value;
    Registry::register_cache('cquery_' . md5($cache_name), array_unique($m[1]), CACHE_LEVEL_STATIC);
    Registry::set('cquery_' . md5($cache_name), $value);
    Registry::register_cache('cached_queries', array(), CACHE_LEVEL_STATIC, true);
    $cached_queries = Registry::if_get('cached_queries', array());
    if (!isset($cached_queries['cquery_' . md5($cache_name)])) {
        $cache_handler = array('cquery_' . md5($cache_name) => array_unique($m[1]));
        $cached_queries = array_merge($cached_queries, $cache_handler);
        Registry::set('cached_queries', $cached_queries);
    }
    return $value;
}