yf_common class

Class where most common used functions are stored.

Fileplugins/common/classes/yf_common.class.php
Use_class('common')

Public properties

A site sets them in its config with $PROJECT_CONF['common']['NAME'] = ...;

PropertyDefaultDescription
$BS_COLOR_MODES
array
['light', 'dark', 'auto'] Bootstrap 5.3 colour modes of conf bs_color_mode / bs_color_mode_<main type> and of the yf_color_mode cookie (auto follows the OS)
$BS_THEMES
array
['bs3' => ['bootstrap', 'slate', 'cyborg'], 'bs4' => ['bootstrap', 'slate', 'cyborg'], 'bs5' => ['bootstrap', 'slate', 'cyborg']] css_framework => the themes the framework serves itself (assets/themes/); any other configured name falls back to "bootstrap" with one warning per request
$EMPTY_PAGE_DEBUG_INFO
bool
true Display debug info for the empty page
$MEDIA_PATH
string
'' Required for the compatibility with old main class
$MESSAGES_AS_TOASTS
bool
false show_messages() under bs5 renders Bootstrap 5 toasts (html()->toast(), errors stay until closed) instead of alerts; Bootstrap 3 / 4 keep the alerts
$SPHINX_EMPTY_LOG_PATH
string
'' Log file for SphinxQL queries that found nothing; sphinxsearch uses it when its own EMPTY_RESULTS_LOG_PATH is empty
$TRACK_USER_ERRORS
bool
false Store user-level errors
$TRANSLIT_FROM
string
'cp1251' Translit from encoding
$URL_FORCE_DASHES
bool
false Used by propose url from name
$USER_ERRORS []
$_bs_theme_warned
array
[] theme name => true, one warning per request
$_current_theme null
$_get_vars_cache null

Public methods 146

add_get_vars

public function add_get_vars($add_skip = [])

Add variables that came from $_GET array.

    public function add_get_vars($add_skip = [])
    {
        // Cache it
        if (isset($this->_get_vars_cache)) {
            return $this->_get_vars_cache;
        }
        $string = '';
        $skip = array_merge(
            ['task', 'object', 'action', 'section', 'id', 'post_id', 'language'],
            (array) $add_skip
        );
        foreach ((array) $_GET as $name => $value) {
            // Skip some vars
            if (in_array($name, $skip)) {
                continue;
            }
            // Process array
            if (is_array($value)) {
                foreach ((array) $value as $k2 => $v2) {
                    if (is_array($v2)) {
                        continue;
                    }
                    $string .= '&' . urlencode($name) . '[' . urlencode($k2) . ']=' . urlencode($v2);
                }
            } else {
                $string .= '&' . urlencode($name) . '=' . urlencode($value);
            }
        }
        $this->_get_vars_cache = $string;
        return $string;
    }

add_message

public function add_message($text = '', $level = 'info', $key = '', $options = null)
    public function add_message($text = '', $level = 'info', $key = '', $options = null)
    {
        if ( ! strlen($text)) {
            return false;
        }
        $is_translate = true;
        isset($options['translate']) && $is_translate = (bool) $options['translate'];
        if ($is_translate) {
            $text = t($text);
        }
        if ($key) {
            $_SESSION['permanent'][$level][$key] = $text;
        } else {
            $_SESSION['permanent'][$level][$text] = $text;
        }
        return true;
    }
public function admin_wall_add($data = [])
    public function admin_wall_add($data = [])
    {
        return _class('admin_methods')->admin_wall_add($data);
    }

bs_color_mode

public function bs_color_mode($main_type = '')

Bootstrap 5 colour mode of the page (light, dark, auto), '' when off: css_framework is not bs5 or neither conf bs_color_mode_<main type> nor bs_color_mode is one of $BS_COLOR_MODES (default: off, no data-bs-theme on <html>). With bs_theme_allow_override_for_<main type> on (the switch of the yf_theme cookie) the visitor's choice, the yf_color_mode cookie that the switcher sets, wins.

    public function bs_color_mode($main_type = '')
    {
        if (conf('css_framework') !== 'bs5') {
            return '';
        }
        $main_type = $main_type ?: MAIN_TYPE;
        $mode = conf('bs_color_mode_' . $main_type) ?: conf('bs_color_mode');
        if ( ! in_array($mode, $this->BS_COLOR_MODES, true)) {
            return '';
        }
        $cookie = $_COOKIE['yf_color_mode'] ?? '';
        if (conf('bs_theme_allow_override_for_' . $main_type) && in_array($cookie, $this->BS_COLOR_MODES, true)) {
            $mode = $cookie;
        }
        return $mode;
    }
public function bs_color_mode_attr()

Attributes of the <html> tag for the colour mode ({execute(common,bs_color_mode_attr)} in the bs5 layouts): data-bs-theme and data-yf-color-mode, '' when off. auto renders the scheme the yf_bs5_color_modes asset saw last (yf_color_scheme cookie, light on a first visit) and the asset follows the OS from there.

    public function bs_color_mode_attr()
    {
        $mode = $this->bs_color_mode();
        if ($mode === '') {
            return '';
        }
        asset('yf_bs5_color_modes');
        $scheme = $mode === 'auto' ? ((($_COOKIE['yf_color_scheme'] ?? '') === 'dark') ? 'dark' : 'light') : $mode;
        return ' data-bs-theme="' . $scheme . '" data-yf-color-mode="' . $mode . '"';
    }
public function bs_color_mode_switcher()

Light / dark / auto dropdown of a bs5 navbar (template bs_color_mode_switcher), shown next to the theme switcher when a colour mode is on and the visitor may override it (bs_theme_allow_override_for_<main type>); '' otherwise.

    public function bs_color_mode_switcher()
    {
        $mode = $this->bs_color_mode();
        if ($mode === '' || ! conf('bs_theme_allow_override_for_' . MAIN_TYPE)) {
            return '';
        }
        asset('yf_bs5_color_modes');
        return tpl()->parse('bs_color_mode_switcher', ['cur' => $mode]);
    }
public function bs_current_theme($main_type = '', $force = false)
    public function bs_current_theme($main_type = '', $force = false)
    {
        if ( ! $main_type) {
            $main_type = MAIN_TYPE;
        }
        $theme = $main_type === 'admin' ? 'slate' : 'bootstrap';
        if (isset($this->_current_theme) && ! $force) {
            return $this->_current_theme;
        }
        $conf_theme = conf('DEF_BOOTSTRAP_THEME_' . strtoupper($main_type)) ?: conf('DEF_BOOTSTRAP_THEME');
        if ($conf_theme) {
            $theme = $conf_theme;
        }
        $allow_override = conf('bs_theme_allow_override_for_' . $main_type);
        $avail_themes = $this->bs_get_avail_themes();
        $css_fw = conf('css_framework') ?: 'bs3';
        if ($css_fw !== 'bs5' && ! in_array($theme, $avail_themes, true) && in_array($theme, _class('bs_theme')->site_themes(), true)) {
            // site themes are bs5 only (CSS variables): Bootstrap 3 renders their base
            $theme = _class('bs_theme')->base_of($theme);
        }
        if ( ! in_array($theme, $avail_themes, true)) {
            if ( ! isset($this->_bs_theme_warned[$theme])) {
                $this->_bs_theme_warned[$theme] = true;
                trigger_error('BS theme "' . $theme . '" is not available for css_framework ' . $css_fw . ' (Bootswatch was replaced by the internal themes '
                    . implode(', ', $avail_themes) . ', see https://github.com/yfix/yf/blob/master/docs/UPGRADING.md); using "bootstrap"', E_USER_WARNING);
            }
            $theme = 'bootstrap';
        }
        if (($_GET['yf_theme'] ?? null) && in_array($_GET['yf_theme'], $avail_themes) && $allow_override) {
            $theme = $_GET['yf_theme'];
            setcookie('yf_theme', $theme, 0, '/');
            unset($_GET['yf_theme']);
            js_redirect('/@object/@action/@id/@page');
        } elseif (($_COOKIE['yf_theme'] ?? null) && in_array($_COOKIE['yf_theme'], $avail_themes)) {
            if ( ! $force || $allow_override) {
                $theme = ($_COOKIE['yf_theme'] ?? null);
            }
        }
        $this->_current_theme = $theme;
        return $theme;
    }
public function bs_get_avail_themes($css_fw = '')
    public function bs_get_avail_themes($css_fw = '')
    {
        if ( ! $css_fw) {
            $css_fw = conf('css_framework');
        }
        if ( ! $css_fw) {
            $css_fw = 'bs3';
        }
        // any other css_framework (empty) renders Bootstrap 3 (assets/bootstrap/bootstrap-theme.php)
        $themes = array_values((array) ($this->BS_THEMES[$css_fw] ?? $this->BS_THEMES['bs3'] ?? ['bootstrap']));
        if ($css_fw === 'bs5') {
            $themes = array_merge($themes, _class('bs_theme')->site_themes());
        }
        sort($themes);
        return $themes;
    }
public function bs_theme_changer()
    public function bs_theme_changer()
    {
        return tpl()->parse('bs_theme_changer', [
            'cur_theme' => $this->bs_current_theme(),
            'themes' => $this->bs_get_avail_themes(),
        ]) . $this->bs_color_mode_switcher();
    }

bs_theme_html

public function bs_theme_html()
    public function bs_theme_html()
    {
        $theme = $this->bs_current_theme();
        return tpl()->parse('bs_theme_html', ['cur_theme' => $this->bs_current_theme()]);
    }

check_box

public function check_box($box_name, $values = [], $selected = '', $add_str = '')

Simple check box.

    public function check_box($box_name, $values = [], $selected = '', $add_str = '')
    {
        return _class('html')->check_box($box_name, $values, $selected, $add_str);
    }
public function check_user_ban($info = [], $user_info = [])

Check if user is banned.

    public function check_user_ban($info = [], $user_info = [])
    {
        return _class('user_ban', 'classes/common/')->_check($info, $user_info);
    }

connect_db2

public function connect_db2()

Secondary database connection.

    public function connect_db2()
    {
        if ( ! defined('DB_HOST2')) {
            return false;
        }
        global $db2;
        if ( ! is_object($db2)) {
            $db_class_name = main()->load_class_file('db', 'classes/');
            if ($db_class_name && class_exists($db_class_name)) {
                $db2 = new $db_class_name('mysql', 1, constant('DB_PREFIX2'));
                $db2->connect(
                    constant('DB_HOST2'),
                    constant('DB_USER2'),
                    constant('DB_PSWD2'),
                    constant('DB_NAME2'),
                    true,
                    defined('DB_SSL2') ? constant('DB_SSL2') : false,
                    defined('DB_PORT2') ? constant('DB_PORT2') : '',
                    defined('DB_SOCKET2') ? constant('DB_SOCKET2') : '',
                    defined('DB_CHARSET2') ? constant('DB_CHARSET2') : ''
                );
            }
        }
        return $db2;
    }

crop_image

public function crop_image($source_file_path, $dest_file_path, $LIMIT_X, $LIMIT_Y, $pos_left, $pos_top)

Do crop image.

    public function crop_image($source_file_path, $dest_file_path, $LIMIT_X, $LIMIT_Y, $pos_left, $pos_top)
    {
        return _class('image_manip', 'classes/common/')->crop($source_file_path, $dest_file_path, $LIMIT_X, $LIMIT_Y, $pos_left, $pos_top);
    }
public function css_class_body($extra = [])
    public function css_class_body($extra = [])
    {
        if ( ! is_array($extra)) {
            $extra = [];
        }
        $main = main();
        $extra['css_framework'] = 'cssfw-' . strtolower(conf('css_framework'));
        $theme = (string) $this->bs_current_theme();
        $base = _class('bs_theme')->base_of($theme);
        // a site theme also carries its base's class, so per-theme fixes (.bs-theme-slate) still apply
        $extra['bs_theme'] = 'bs-theme-' . strtolower($theme) . ($base !== '' && $base !== $theme ? ' bs-theme-' . $base : '');
        $extra['main_type'] = 'main-type-' . strtolower(MAIN_TYPE);
        $extra['is_common_page'] = $main->is_common_page() ? 'is-common-page' : '';
        $extra['is_ajax'] = $main->is_ajax() ? 'is-ajax' : '';
        $extra['is_post'] = $main->is_post() ? 'is-post' : '';
        $extra['is_dev'] = $main->is_dev() ? 'is-dev' : '';
        $extra['is_debug'] = $main->is_debug() ? 'is-debug' : '';
        $extra['is_https'] = $main->is_https() ? 'is-https' : '';
        $extra['is_spider'] = $main->is_spider() ? 'is-spider' : '';
        $extra['is_redirect'] = $main->is_redirect() ? 'is-redirect' : '';
        $extra['is_unit_test'] = $main->is_unit_test() ? 'is-unit-test' : '';
        $extra['is_logged_in'] = $main->is_logged_in() ? 'is-logged-in' : 'is-guest';
        $extra['is_banned'] = $main->is_banned() ? 'is-banned' : '';
        $extra['group_id'] = ($group = MAIN_TYPE_ADMIN ? $main->ADMIN_GROUP : $main->USER_GROUP) ? 'groupid-' . strtolower($group) : '';
        $extra['site_id'] = ($site_id = $main->SITE_ID) ? 'siteid-' . strtolower($site_id) : '';
        $extra['get_object'] = 'get-object-' . strtolower((string) ($_GET['object'] ?? ''));
        $extra['get_action'] = 'get-action-' . strtolower((string) ($_GET['action'] ?? ''));
        $extra['get_id'] = ($_GET['id'] ?? '') ? 'get-id-' . strtolower((string) $_GET['id']) : '';
        $extra['language'] = 'lang-' . strtolower(conf('language') ?: 'en');
        $extra['country'] = ($_SERVER['GEOIP_COUNTRY_CODE'] ?? '') ? 'country-' . strtolower((string) $_SERVER['GEOIP_COUNTRY_CODE']) : '';
        $extra['currency'] = ($currency = conf('currency')) ? 'currency-' . strtolower($currency) : '';
        return implode(' ', array_filter($extra));
    }
public function dashboard2_display($name)
    public function dashboard2_display($name)
    {
        return _class('dashboards2')->display($name);
    }
public function dashboard_display($name)
    public function dashboard_display($name)
    {
        return _class('dashboards', 'classes/common/')->display($name);
    }

date_box

public function date_box($selected_date = '', $years = '', $name_postfix = '', $add_str = '', $order = 'ymd', $show_text = 1, $translate = 1)
    public function date_box($selected_date = '', $years = '', $name_postfix = '', $add_str = '', $order = 'ymd', $show_text = 1, $translate = 1)
    {
        return _class('html')->date_box($selected_date, $years, $name_postfix, $add_str, $order, $show_text, $translate);
    }

date_box2

public function date_box2($name = '', $selected = '', $range = '', $add_str = '', $show_what = 'ymd', $show_text = 1, $translate = 1)
    public function date_box2($name = '', $selected = '', $range = '', $add_str = '', $show_what = 'ymd', $show_text = 1, $translate = 1)
    {
        return _class('html')->date_box2($name, $selected, $range, $add_str, $show_what, $show_text, $translate);
    }

date_picker

public function date_picker($name, $cur_date = '')
    public function date_picker($name, $cur_date = '')
    {
        return _class('html')->date_picker($name, $cur_date);
    }

datetime_box2

public function datetime_box2($name = '', $selected = '', $range = '', $add_str = '', $show_what = 'ymdhis', $show_text = 1, $translate = 1)
    public function datetime_box2($name = '', $selected = '', $range = '', $add_str = '', $show_what = 'ymdhis', $show_text = 1, $translate = 1)
    {
        return _class('html')->datetime_box2($name, $selected, $range, $add_str, $show_what, $show_text, $translate);
    }

db2_connect

public function db2_connect()

Secondary database connection.

    public function db2_connect()
    {
        return $this->connect_db2();
    }
public function delete_uploaded_file($path_to = '')

Delete uploaded file.

    public function delete_uploaded_file($path_to = '')
    {
        return _class('remote_files', 'classes/common/')->do_delete($path_to);
    }

divide_pages

public function divide_pages($sql = '', $url_path = '', $render_type = '', $records_on_page = 0, $num_records = 0, $tpls_path = '', $add_get_vars = 1, $extra = [])

This function generate dividing table contents per pages.

    public function divide_pages($sql = '', $url_path = '', $render_type = '', $records_on_page = 0, $num_records = 0, $tpls_path = '', $add_get_vars = 1, $extra = [])
    {
        $sql_is_query_builder = $sql_is_object = $sql_is_callable = false;
        if (is_array($sql)) {
            $sql_is_array = true;
        } elseif (is_callable($sql)) {
            $sql_is_callable = true;
        } elseif (is_object($sql)) {
            if ($sql instanceof yf_db_query_builder_driver) {
                $sql_is_query_builder = true;
            } else {
                $sql_is_object = true;
            }
        }
        if ($sql_is_query_builder) {
            $sql = $sql->sql();
        } elseif ($sql_is_object) {
            $sql = obj2arr($sql);
        } elseif ($sql_is_callable) {
            $sql = (array) $sql(func_get_args());
        }
        // Override default method for input array
        $method = is_array($sql) ? 'go_with_array' : 'go';
        return _class('divide_pages', 'classes/common/')->$method($sql, $url_path, $render_type, $records_on_page, $num_records, $tpls_path, $add_get_vars, $extra);
    }

email_page

public function email_page($text = '')

Send given text to a desired email address.

    public function email_page($text = '')
    {
        return _class('email_page', 'classes/common/')->go($text);
    }

email_verify

public function email_verify($email = '', $check_mx = false, $check_by_smtp = false, $check_blacklists = false)

Email verifying function.

    public function email_verify($email = '', $check_mx = false, $check_by_smtp = false, $check_blacklists = false)
    {
        return _class('validate')->_email_verify($email, $check_mx, $check_by_smtp, $check_blacklists);
    }

encode_email

public function encode_email($addr = '', $as_html_link = false)

Encode given address to prevent spam-bots harvesting.

    public function encode_email($addr = '', $as_html_link = false)
    {
        return _class('utils')->encode_email($addr, $as_html_link);
    }

error_403

public function error_403($msg = '')

Show error and set response header to "403 Forbidden".

    public function error_403($msg = '')
    {
        if ((MAIN_TYPE_ADMIN && is_logged_in()) || DEBUG_MODE) {
            // Do not override status header for logged in admin, just display error inlined
            ! $msg && $msg = t('403 Forbidden');
        } else {
            // All other cases
            header((($_SERVER['SERVER_PROTOCOL'] ?? null) ? ($_SERVER['SERVER_PROTOCOL'] ?? null) : 'HTTP/1.1') . ' 403 Forbidden');
            main()->IS_403 = true;
        }
        if (DEBUG_MODE) {
            no_graphics(true);
            $body = '<b>404 Not found</b><br />' . PHP_EOL . '<i>' . $msg . '</i>';
            $body .= '<pre><small>' . htmlspecialchars(main()->trace_string()) . '</small></pre>';
            return print common()->show_empty_page($body, ['full_width' => 1]);
        }
        return $this->_show_error_message($msg);
    }

error_404

public function error_404($msg = '')

Show error and set response header to "404 Not Found".

    public function error_404($msg = '')
    {
        if ((MAIN_TYPE_ADMIN && is_logged_in()) || DEBUG_MODE) {
            // Do not override status header for logged in admin, just display error inlined
            ! $msg && $msg = t('404 Not Found');
        } else {
            // All other cases
            headers_sent() || header(($_SERVER['SERVER_PROTOCOL'] ?? '' ?: 'HTTP/1.1') . ' 404 Not Found');
            main()->IS_404 = true;
        }
        if (DEBUG_MODE) {
            no_graphics(true);
            $body = '<b>404 Not found</b><br />' . PHP_EOL . '<i>' . $msg . '</i>';
            $body .= '<pre><small>' . htmlspecialchars(main()->trace_string()) . '</small></pre>';
            return print common()->show_empty_page($body, ['full_width' => 1]);
        }
        return $this->_show_error_message($msg);
    }

fetch_rss

public function fetch_rss($params = [])

Get data from RSS feeds and return it as array.

    public function fetch_rss($params = [])
    {
        return _class('rss_data', 'classes/common/')->fetch_data($params);
    }
public function file_is_exists($path_to = '')

Check if file exists.

    public function file_is_exists($path_to = '')
    {
        return _class('remote_files', 'classes/common/')->file_is_exists($path_to);
    }
public function filemtime_remote($path_to = '')

Remote file last-modification time.

    public function filemtime_remote($path_to = '')
    {
        return _class('remote_files', 'classes/common/')->filemtime_remote($path_to);
    }

form2

public function form2($replace = [], $params = [])

Form2 chained wrapper.

    public function form2($replace = [], $params = [])
    {
        $form = clone _class('form2');
        return $form->chained_wrapper($replace, $params);
    }
public function format_file_size($fs = 0, $digits_count = 0)

Format file size.

    public function format_file_size($fs = 0, $digits_count = 0)
    {
        if ($digits_count == 0) {
            return ($fs < 1024 * 1024) ? round($fs / 1024, 3) . ' Kb' : (($fs < 1024 * 1024 * 1024) ? round($fs / (1024 * 1024), 3) . ' Mb' : round($fs / (1024 * 1024 * 1024), 3) . ' Gb');
        }
        return ($fs < 1048576) ? round($fs / 1024, $digits_count - strlen(round($fs / 1024, 0))) . ' Kb' : (($fs < 1073741824) ? round($fs / 1048576, $digits_count - strlen(round($fs / 1048576, 0))) . ' Mb' : round($fs / 1073741824, $digits_count - strlen(round($fs / 1073741824, 0))) . ' Gb');
    }

format_time

public function format_time($timestamp, $accuracy = 'second')

Format time.

    public function format_time($timestamp, $accuracy = 'second')
    {
        $timestamp = (int) $timestamp;
        if ($timestamp == 0) {
            return 0;
        }
        $out = '';
        $periods = ['year', 'month', 'day', 'hour', 'minute', 'second'];
        list($length_accur) = array_keys($periods, $accuracy);
        $lengths = [31536000, 2592000, 86400, 3600, 60, 1];
        for ($i = 0; $timestamp > $lengths[$length_accur]; $i++) {
            $value = (int) ($timestamp / $lengths[$i]);
            if ($value != 0) {
                $out .= $value . ' ' . $periods[$i] . ($value > 1 ? 's ' : ' ');
            }
            $r = fmod($timestamp, $lengths[$i]);
            if ($r == 0) {
                break;
            }
            $timestamp = $r;
        }
        return $out;
    }
public function gen_account_name($id = 0, $prefix = 'u', $length = 5, $padding_char = '0')

Create account name of fixed length with given prefix.

    public function gen_account_name($id = 0, $prefix = 'u', $length = 5, $padding_char = '0')
    {
        if ( ! $id) {
            return false;
        }
        if ($length < strlen($id)) {
            $length = strlen($id);
        }
        return $prefix . str_pad($id, $length, $padding_char, STR_PAD_LEFT);
    }
public function get_browser_info()

Check if user is banned.

    public function get_browser_info()
    {
        return _class('client_utils', 'classes/common/')->_get_browser_info();
    }
public function get_console_params()

Helper to get params from command line.

    public function get_console_params()
    {
        foreach ((array) ($_SERVER['argv'] ?? null) as $key => $argv) {
            if ($argv == '--params' && isset($_SERVER['argv'][$key + 1])) {
                return unserialize(($_SERVER['argv'][$key + 1] ?? ''));
            }
        }
        return false;
    }

get_diff

public function get_diff($str1, $str2, $type = 'side_by_side')
    public function get_diff($str1, $str2, $type = 'side_by_side')
    {
        return _class('diff', 'classes/common/')->get_diff($str1, $str2, $type);
    }

get_file_ext

public function get_file_ext($file_path = '')

Return file extension.

    public function get_file_ext($file_path = '')
    {
        return pathinfo($file_path, PATHINFO_EXTENSION);
    }
public function get_formatted_file_size($file_name = '', $digits_count = 0)

Return file size formatted.

    public function get_formatted_file_size($file_name = '', $digits_count = 0)
    {
        return $this->format_file_size(file_exists($file_name) ? filesize($file_name) : 0, $digits_count);
    }

get_ip

public function get_ip($check_type = 'force')

Get user IP address.

    public function get_ip($check_type = 'force')
    {
        return _class('client_utils', 'classes/common/')->_get_ip($check_type);
    }
public function get_remote_page($page_url = '', $cache_ttl = -1, $options = [], &$requests_info = [])

Get remote file using CURL extension.

    public function get_remote_page($page_url = '', $cache_ttl = -1, $options = [], &$requests_info = [])
    {
        return _class('remote_files', 'classes/common/')->get_remote_page($page_url, $cache_ttl, $options, $requests_info);
    }
public function get_spiders_ips_sql($field_name = 'ip')

Return SQL part for detecting search engine ips.

    public function get_spiders_ips_sql($field_name = 'ip')
    {
        return _class('spider_detection', 'classes/common/')->get_spiders_ips_sql($field_name);
    }
public function get_static_conf($type = false, $value = false, $translate = true)
    public function get_static_conf($type = false, $value = false, $translate = true)
    {
        return _class('common_static_conf', 'classes/common/')->get_static_conf($type, $value, $translate);
    }
public function get_whois_info($url, $server = '')

Get file using HTTP request (grabbed from drupal 5.1).

    public function get_whois_info($url, $server = '')
    {
        return _class('other_common', 'classes/common/')->get_whois_info($url, $server);
    }

gmtime

public function gmtime()

current GMT time.

    public function gmtime()
    {
        return strtotime('now GMT');
    }

http_request

public function http_request($url, $headers = [], $method = 'GET', $data = null, $retry = 3)

Get file using HTTP request (grabbed from drupal 5.1).

    public function http_request($url, $headers = [], $method = 'GET', $data = null, $retry = 3)
    {
        return _class('remote_files', 'classes/common/')->http_request($url, $headers, $method, $data, $retry);
    }
public function intrusion_detection()

Try to detect intrusions (XSS and other hack stuff).

    public function intrusion_detection()
    {
        return _class('intrusion_detection', 'classes/common/')->check();
    }

is_messages

public function is_messages()
    public function is_messages()
    {
        $result = isset($_SESSION['permanent']) && count((array) ($_SESSION['permanent'] ?? null)) > 0;
        return $result;
    }
public function is_search_engine_url($url = '')

Searches given URL for known search engines hosts.

Returns string name of the found search engine

    public function is_search_engine_url($url = '')
    {
        return _class('spider_detection', 'classes/common/')->is_search_engine_url($url);
    }

is_utf8

public function is_utf8($content)

is_utf8.

    public function is_utf8($content)
    {
        require_php_lib('yf_utf8_funcs');
        include_once 'is_utf8.php';
        return is_utf8($content);
    }

jevix_parse

public function jevix_parse($text = '', $params = [])

Parse text using jevix.

    public function jevix_parse($text = '', $params = [])
    {
        return _class('other_common', 'classes/common/')->jevix_parse($text, $params);
    }

l

public function l($name = '', $data = '', $lang = '')

Localize current piece of data.

    public function l($name = '', $data = '', $lang = '')
    {
        return _class('l10n')->$name($data, $lang);
    }

log_exec

public function log_exec()

Alias.

    public function log_exec()
    {
        return _class('logs')->log_exec();
    }

make_alphabet

public function make_alphabet($url, &$chars, $get_var_name = 'id', $q_var = 'id')

Create Alphabet search criteria.Make alphabet html and query limit for selected chars.

    public function make_alphabet($url, &$chars, $get_var_name = 'id', $q_var = 'id')
    {
        return _class('make_alphabet', 'classes/common/')->go($url, $chars, $get_var_name, $q_var);
    }

make_thumb

public function make_thumb($source_file_path = '', $dest_file_path = '', $LIMIT_X = -1, $LIMIT_Y = -1, $watermark_path = '', $ext = '')

Make thumbnail using best available method.

    public function make_thumb($source_file_path = '', $dest_file_path = '', $LIMIT_X = -1, $LIMIT_Y = -1, $watermark_path = '', $ext = '')
    {
        return _class('make_thumb', 'classes/common/')->go($source_file_path, $dest_file_path, $LIMIT_X, $LIMIT_Y, $watermark_path, $ext);
    }

make_translit

public function make_translit($string)

Create translit from Russian or Ukrainian text.

    public function make_translit($string)
    {
        return _class('translit', 'classes/common/')->make($string);
    }

message_error

public function message_error($text = '', $options = null)
    public function message_error($text = '', $options = null)
    {
        return $this->add_message($text, 'error', '', $options);
    }

message_info

public function message_info($text = '', $options = null)
    public function message_info($text = '', $options = null)
    {
        return $this->add_message($text, 'info', '', $options);
    }
public function message_success($text = '', $options = null)
    public function message_success($text = '', $options = null)
    {
        return $this->add_message($text, 'success', '');
    }
public function message_warning($text = '', $options = null)
    public function message_warning($text = '', $options = null)
    {
        return $this->add_message($text, 'warning', '', $options);
    }
public function multi_check_box($box_name, $values = [], $selected = [], $horizontal = true, $type = 2, $add_str = '', $translate = 0, $name_as_array = false)

Processing many checkboxes at one time.

    public function multi_check_box($box_name, $values = [], $selected = [], $horizontal = true, $type = 2, $add_str = '', $translate = 0, $name_as_array = false)
    {
        return _class('html')->multi_check_box($box_name, $values, $selected, $horizontal, $type, $add_str, $translate, $name_as_array);
    }
public function multi_file_size($page_urls, $options = [], $max_threads = 50)

Get several remote files sizes.

    public function multi_file_size($page_urls, $options = [], $max_threads = 50)
    {
        return _class('remote_files', 'classes/common/')->multi_file_size($page_urls, $options, $max_threads);
    }

multi_request

public function multi_request($page_urls = [], $options = [], &$requests_info = [])

Get several remote files at one time.

    public function multi_request($page_urls = [], $options = [], &$requests_info = [])
    {
        return _class('remote_files', 'classes/common/')->_multi_request($page_urls, $options, $requests_info);
    }
public function multi_request_safe($page_urls = [], $options = [], $chunk_size = 50)

'Safe' multi_request, which splits inpu array into smaller chunks to prevent server breaking.

    public function multi_request_safe($page_urls = [], $options = [], $chunk_size = 50)
    {
        return _class('remote_files', 'classes/common/')->multi_request_safe($page_urls, $options, $chunk_size);
    }

multi_select

public function multi_select($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $disabled = false)

Generate multi-select box.

    public function multi_select($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $disabled = false)
    {
        return _class('html')->multi_select($name, $values, $selected, $show_text, $type, $add_str, $translate, $level, $disabled);
    }
public function multi_select_box($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $disabled = false)

Alias for the multi_select.

    public function multi_select_box($name, $values = [], $selected = '', $show_text = false, $type = 2, $add_str = '', $translate = 0, $level = 0, $disabled = false)
    {
        return $this->multi_select($name, $values, $selected, $show_text, $type, $add_str, $translate, $level, $disabled);
    }
public function multi_upload_image($new_file_path, $k, $name_in_form = 'image', $max_image_size = 0, $is_local = false)

Do multi upload image.

    public function multi_upload_image($new_file_path, $k, $name_in_form = 'image', $max_image_size = 0, $is_local = false)
    {
        return _class('multi_upload_image', 'classes/common/')->go($new_file_path, $k, $name_in_form, $max_image_size, $is_local);
    }

num2str

public function num2str($number, $currency_id = null, $lang_id = null)

Returns the sum in words (for money).

    public function num2str($number, $currency_id = null, $lang_id = null)
    {
        return _class('common_num2string', 'classes/common/')->num2str($number, $currency_id, $lang_id);
    }

pdf_page

public function pdf_page($html = '', $file = '', $type = 'I')

Create PDF 'on the fly' from the given content.

    public function pdf_page($html = '', $file = '', $type = 'I')
    {
        return _class('pdf_page', 'classes/common/')->go($html, $file, $type);
    }

print_page

public function print_page($text = '')

Show print version of the given page.

    public function print_page($text = '')
    {
        main()->no_graphics(true);
        return print tpl()->parse('system/common/print_page', [
            'text' => $text,
            'path_to_tpls' => WEB_PATH . tpl()->TPL_PATH,
        ]);
    }
public function quick_send_mail($email_to, $subject, $html)

Quick send mail (From admin info).

    public function quick_send_mail($email_to, $subject, $html)
    {
        return $this->send_mail(SITE_ADMIN_EMAIL, defined('SITE_ADMIN_NAME') ? SITE_ADMIN_NAME : 'Site admin', $email_to, '', $subject, strip_tags($html), $html);
    }

radio_box

public function radio_box($box_name, $values = [], $selected = '', $horizontal = true, $type = 2, $add_str = '', $translate = 0)

Processing radio buttons.

    public function radio_box($box_name, $values = [], $selected = '', $horizontal = true, $type = 2, $add_str = '', $translate = 0)
    {
        return _class('html')->radio_box($box_name, $values, $selected, $horizontal, $type, $add_str, $translate);
    }

rand_name

public function rand_name($Length = 8)

Simple random password creator with specified length (max 32 symbols) //.

    public function rand_name($Length = 8)
    {
        return substr(md5(microtime(true) . rand()), 0, $Length);
    }

rar_extract

public function rar_extract($archive_name, $EXTRACT_PATH)
    public function rar_extract($archive_name, $EXTRACT_PATH)
    {
        if (function_exists('rar_open')) {
            $rar = rar_open($archive_name);
            $list = rar_list($rar);
            foreach ($list as $file) {
                $file = explode('"', $file);
                $entry = rar_entry_get($rar, $file[1]);
                $entry->extract($EXTRACT_PATH);
            }
            rar_close($rar);
        }
    }

redirect

public function redirect($location, $rewrite = true, $redirect_type = 'js', $text = '', $ttl = 3)

Do redirect user to the specified location.

    public function redirect($location, $rewrite = true, $redirect_type = 'js', $text = '', $ttl = 3)
    {
        return _class('redirect')->_go($location, $rewrite, $redirect_type, $text, $ttl);
    }
public function remote_file_size($page_url = '')

Get remote file using CURL extension.

    public function remote_file_size($page_url = '')
    {
        return _class('remote_files', 'classes/common/')->remote_file_size($page_url);
    }

rss_page

public function rss_page($data = '', $params = [])

Create RSS 'on the fly' from the given content.

    public function rss_page($data = '', $params = [])
    {
        return _class('rss_data', 'classes/common/')->show_rss_page($data, $params);
    }

select_box

public function select_box($name, $values = [], $selected = '', $show_text = true, $type = 2, $add_str = '', $translate = 0, $level = 0)

This function generate select box with tree hierarhy inside.

    public function select_box($name, $values = [], $selected = '', $show_text = true, $type = 2, $add_str = '', $translate = 0, $level = 0)
    {
        return _class('html')->select_box($name, $values, $selected, $show_text, $type, $add_str, $translate, $level);
    }

send_mail

public function send_mail($email_from, $name_from = '', $email_to = '', $name_to = '', $subject = '', $text = '', $html = '', $attaches = [], $charset = '', $old_param1 = '', $force_mta_opts = [], $priority = null, $smtp = [])

Send emails with attachments with DEBUG ability.

    public function send_mail($email_from, $name_from = '', $email_to = '', $name_to = '', $subject = '', $text = '', $html = '', $attaches = [], $charset = '', $old_param1 = '', $force_mta_opts = [], $priority = null, $smtp = [])
    {
        $params = null;
        if (is_array($email_from)) {
            $params = $email_from;
            $params['email_from'] = $params['from_mail'];
        }
        if ( ! is_array($params)) {
            $params = [];
        }
        $params['email_from'] = ($params['from_mail'] ?? null) ?: ($params['email_from'] ?? null) ?: $email_from;
        $params['name_from'] = ($params['from_name'] ?? null) ?: ($params['name_from'] ?? null) ?: $name_from;
        $params['email_to'] = ($params['to_mail'] ?? null) ?: ($params['email_to'] ?? null) ?: $email_to;
        $params['name_to'] = ($params['to_name'] ?? null) ?: ($params['name_to'] ?? null) ?: $name_to;
        $params['subject'] = ($params['subj'] ?? null) ?: ($params['subject'] ?? null) ?: $subject;
        $params['text'] = ($params['text'] ?? null) ?: $text;
        $params['html'] = ($params['html'] ?? null) ?: $html;
        $params['attaches'] = ($params['attach'] ?? null) ?: ($params['attaches'] ?? null) ?: $attaches;
        $params['charset'] = ($params['charset'] ?? null) ?: $charset;
        $params['mta_params'] = ($params['force_mta_opts'] ?? null) ?: ($params['mta_params'] ?? null) ?: $force_mta_opts;
        $params['priority'] = ($params['priority'] ?? null) ?: $priority ?: 3;
        $params['smtp'] = ($params['smtp'] ?? null) ?: $smtp;
        return _class('send_mail')->send($params);
    }
public function send_notify_mail_to_admin($subject, $html)

Quick email notification to the admin (from the system).

    public function send_notify_mail_to_admin($subject, $html)
    {
        return $this->send_mail(SITE_ADMIN_EMAIL, constant('SITE_NAME') . ' system notification', SITE_ADMIN_EMAIL, '', $subject, strip_tags($html), $html);
    }
public function server_is_busy($msg = '')

Display message if server is overloaded.

    public function server_is_busy($msg = '')
    {
        $replace = [
            'msg' => $msg,
        ];
        return tpl()->parse('system/server_is_busy', $replace);
    }

set_notice

public function set_notice($text = '')

Set notice to display on next page (usually after redirect).

    public function set_notice($text = '')
    {
        $_SESSION['_user_notices'][crc32($text)] = $text;
    }
public function shop_generate_image_name($product_id, $image_id, $media = false)
    public function shop_generate_image_name($product_id, $image_id, $media = false)
    {
        return module('shop')->_generate_image_name($product_id, $image_id, $media);
    }
public function shop_get_images($product_id)
    public function shop_get_images($product_id)
    {
        return module('shop')->_get_images($product_id);
    }
public function show_debug_info()

Create simple table with debug info.

    public function show_debug_info()
    {
        return _class('debug')->go();
    }
public function show_empty_page($text = '', $params = [])

Show empty page (useful for popup windows, etc).

    public function show_empty_page($text = '', $params = [])
    {
        main()->no_graphics(true);
        $output = tpl()->parse('empty_page', [
            'text' => $text,
            'title' => $params['title'],
            'close_button' => (int) ((bool) $params['close_button']),
            'full_width' => (int) ((bool) $params['full_width']),
        ]);
        $output .= tpl()->_get_quick_page_info();
        $output = tpl()->_apply_output_filters($output);
        main()->_send_main_headers(strlen($output));
        echo $output;
    }

show_ga

public function show_ga()
    public function show_ga()
    {
        if (DEBUG_MODE || MAIN_TYPE_ADMIN) {
            return false;
        }
        $body = [];
        // override this method and insert your google analytics tracking code here and all other analytics codes too
        return $body ? implode(PHP_EOL, $body) : '';
    }
public function show_left_filter()
    public function show_left_filter()
    {
        $obj = module_safe($_GET['object'] ?? null);
        $method = '_show_filter';
        if (method_exists($obj, $method) && ! (isset($obj->USE_FILTER) && ! $obj->USE_FILTER)) {
            return $obj->$method();
        }
    }

show_messages

public function show_messages()
    public function show_messages()
    {
        if ( ! $this->is_messages()) {
            return false;
        }
        $body = [];
        $level_to_style = [
            'info' => 'alert alert-info',
            'success' => 'alert alert-success',
            'warning' => 'alert alert-warning',
            'error' => 'alert alert-error alert-danger',
        ];
        $is_bs5 = conf('css_framework') === 'bs5';
        if ($is_bs5) {
            $level_to_style['error'] = 'alert alert-danger';
        }
        foreach ((array) $level_to_style as $level => $css_style) {
            $messages = $_SESSION['permanent'][$level] ?? null;
            if ( ! is_array($messages) || ! count((array) $messages)) {
                continue;
            }
            // messages quote request data (a login, an IP) and the page template parses this block again
            $messages = _escape_tpl_braces($messages);
            if ($is_bs5 && $this->MESSAGES_AS_TOASTS) {
                $body[] = _class('html')->toast(implode('<br />' . PHP_EOL, $messages), ['type' => $level] + ($level === 'error' ? ['autohide' => false] : []));
                continue;
            }
            if ($is_bs5) {
                $body[] = '<div class="' . $css_style . ' alert-dismissible fade show" role="alert">' . implode('<br />' . PHP_EOL, $messages)
                    . '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="' . t('Close') . '"></button></div>';
                continue;
            }
            $body[] = '<div class="' . $css_style . '"><button type="button" class="close" data-dismiss="alert">×</button>' . implode('<br />' . PHP_EOL, $messages) . '</div>';
        }
        unset($_SESSION['permanent']);
        if ($is_bs5 && $this->MESSAGES_AS_TOASTS && $body) {
            return _class('html')->toast_container(['toasts' => $body]);
        }
        return implode(PHP_EOL, $body);
    }

show_notices

public function show_notices($keep = false, $force_text = '')

Show formatted contents of notices for user.

    public function show_notices($keep = false, $force_text = '')
    {
        if ($force_text) {
            $this->set_notice($force_text);
        }
        $name_in_session = '_user_notices';
        $items = ($_SESSION[$name_in_session] ?? null);
        if ( ! $keep) {
            $_SESSION[$name_in_session] = [];
            unset($_SESSION[$name_in_session]);
        }
        return $items ? tpl()->parse('system/user_notices', ['items' => _escape_tpl_braces($items)]) : '';
    }
public function show_side_column_hooked()
    public function show_side_column_hooked()
    {
        $obj = module_safe($_GET['object'] ?? null);
        $method = '_hook_side_column';
        if (method_exists($obj, $method)) {
            return $obj->$method();
        }
    }
public function sphinx_escape_string($string)
    public function sphinx_escape_string($string)
    {
        return _class('sphinxsearch')->escape_string($string);
    }

sphinx_query

public function sphinx_query($sql, $need_meta = false)

Sphinx QL query wrapper.

    public function sphinx_query($sql, $need_meta = false)
    {
        return _class('sphinxsearch')->query($sql, $need_meta);
    }
public function strip_tags_smart($content)

strip_tags_smart.

    public function strip_tags_smart($content)
    {
        require_php_lib('yf_utf8_funcs');
        include_once 'strip_tags_smart.php';
        return strip_tags_smart($content);
    }

table2

public function table2($data = [], $params = [])

Table2 chained wrapper.

    public function table2($data = [], $params = [])
    {
        $table = clone _class('table2');
        return $table->chained_wrapper($data, $params);
    }

text_typos

public function text_typos($text = '', $params = [])

Parse text using jevix.

    public function text_typos($text = '', $params = [])
    {
        return _class('text_typos', 'classes/')->process($text, $params);
    }

threaded_exec

public function threaded_exec($object, $action = 'show', $threads_params = [], $max_threads = 10)

Threaded execution of the given object/action.

    public function threaded_exec($object, $action = 'show', $threads_params = [], $max_threads = 10)
    {
        return _class('threads')->threaded_exec($object, $action, $threads_params, $max_threads);
    }

time_box

public function time_box($selected_time = '', $name_postfix = '', $add_str = '', $show_text = 1, $translate = 1)
    public function time_box($selected_time = '', $name_postfix = '', $add_str = '', $show_text = 1, $translate = 1)
    {
        return _class('html')->time_box($selected_time, $name_postfix, $add_str, $show_text, $translate);
    }

time_box2

public function time_box2($name = '', $selected = '', $add_str = '', $show_text = 1, $translate = 1)
    public function time_box2($name = '', $selected = '', $add_str = '', $show_text = 1, $translate = 1)
    {
        return _class('html')->time_box2($name, $selected, $add_str, $show_text, $translate);
    }

trace

public function trace()

Simple trace without dumping whole objects.

    public function trace()
    {
        $trace = [];
        foreach (debug_backtrace() as $k => $v) {
            if ( ! $k) {
                continue;
            }
            $v['object'] = is_object($v['object']) ? get_class($v['object']) : null;
            $trace[$k - 1] = $v;
        }
        return $trace;
    }

trace_string

public function trace_string()

Print nice.

    public function trace_string()
    {
        $e = new Exception();
        return implode(PHP_EOL, array_slice(explode(PHP_EOL, $e->getTraceAsString()), 1, -1));
    }
public function unhtmlspecialchars($text = '')

Revert html special chars.

    public function unhtmlspecialchars($text = '')
    {
        $trans_tbl = [
            '"' => '"',
            '&' => '&',
            '\'' => ''',
            '<' => '<',
            '>' => '>',
        ];
        $trans_tbl = array_flip($trans_tbl);
        return strtr($text, $trans_tbl);
    }
public function upload_archive($new_file_path, $name_in_form = 'archive')

Do upload archive file (zip, rar, tar accepted).

    public function upload_archive($new_file_path, $name_in_form = 'archive')
    {
        return _class('upload_archive', 'classes/common/')->go($new_file_path, $name_in_form);
    }

upload_file

public function upload_file($path_tmp = '', $new_dir = '', $new_file = '')

Upload given file to remote server from this server.

    public function upload_file($path_tmp = '', $new_dir = '', $new_file = '')
    {
        return _class('remote_files', 'classes/common/')->do_upload($path_tmp, $new_dir, $new_file);
    }

upload_image

public function upload_image($new_file_path, $name_in_form = 'image', $max_image_size = 0, $is_local = false)

Do upload image.

    public function upload_image($new_file_path, $name_in_form = 'image', $max_image_size = 0, $is_local = false)
    {
        return _class('upload_image', 'classes/common/')->go($new_file_path, $name_in_form, $max_image_size, $is_local);
    }
public function url_to_absolute($base_url, $relative_url)

Convert URL to absolute form.

    public function url_to_absolute($base_url, $relative_url)
    {
        return _class('url_to_absolute', 'classes/common/')->url_to_absolute($base_url, $relative_url);
    }

url_verify

public function url_verify($url = '', $absolute = false)

Verify url.

    public function url_verify($url = '', $absolute = false)
    {
        return _class('validate')->_url_verify($url, $absolute);
    }

user

public function user($user_id, $fields = 'full', $params = '', $return_sql = false)

Get user info(s) by id(s).

    public function user($user_id, $fields = 'full', $params = '', $return_sql = false)
    {
        $db = db()->from('user')->where('id', $user_id);
        return $return_sql ? $db->sql() : $db->get();
    }

user_wall_add

public function user_wall_add($data = [])
    public function user_wall_add($data = [])
    {
        return db()->insert('user_walls', db()->es_for_builder([
            'message' => isset($data['message']) ? $data['message'] : (isset($data[0]) ? $data[0] : ''),
            'user_id' => isset($data['user_id']) ? $data['user_id'] : (isset($data[1]) ? $data[1] : ''),
            'object_id' => isset($data['object_id']) ? $data['object_id'] : (isset($data[2]) ? $data[2] : (isset($_GET['id']) ? ($_GET['id'] ?? null) : '')),
            'object' => isset($data['object']) ? $data['object'] : (isset($data[3]) ? $data[3] : ($_GET['object'] ?? null)),
            'action' => isset($data['action']) ? $data['action'] : (isset($data[4]) ? $data[4] : ($_GET['action'] ?? null)),
            'important' => isset($data['important']) ? $data['important'] : (isset($data[5]) ? $data[5] : 0),
            'old_data' => json_encode(isset($data['old_data']) ? $data['old_data'] : (isset($data[6]) ? $data[6] : '')),
            'new_data' => json_encode(isset($data['new_data']) ? $data['new_data'] : (isset($data[7]) ? $data[7] : '')),
            'add_date' => date('Y-m-d H:i:s'),
            'server_id' => (int) main()->SERVER_ID,
            'site_id' => (int) main()->SITE_ID,
            'read' => isset($data['read']) ? $data['read'] : 0,
            'type' => isset($data['type']) ? $data['type'] : '',
        ]));
    }

utf8_clean

public function utf8_clean($text = '', $params = [])

strip_tags_smart.

    public function utf8_clean($text = '', $params = [])
    {
        return _class('utf8_clean', 'classes/common/')->_do($text, $params);
    }
public function utf8_html_entity_decode($content)

utf8_html_entity_decode.

    public function utf8_html_entity_decode($content)
    {
        require_php_lib('yf_utf8_funcs');
        include_once 'utf8_html_entity_decode.php';
        return utf8_html_entity_decode($content, true);
    }

zip_extract

public function zip_extract($archive_name, $EXTRACT_PATH)
    public function zip_extract($archive_name, $EXTRACT_PATH)
    {
        $zip = new ZipArchive();
        $res = $zip->open($archive_name);
        if ($res === true) {
            $zip->extractTo($EXTRACT_PATH);
            $zip->close();
        }
    }

Methods starting with _ hooks and helpers; not routable as page actions

__call

public function __call($name, $args)

Catch missing method call.

    public function __call($name, $args)
    {
        return main()->extend_call($this, $name, $args);
    }

__construct

public function __construct()

Constructor.

    public function __construct()
    {
        define('COMMON_LIB', 'classes/common/');
        $this->MEDIA_PATH = WEB_PATH;
        if (defined('MEDIA_PATH')) {
            $this->MEDIA_PATH = MEDIA_PATH;
        }
    }
public function _add_activity_points($user_id = 0, $task_name = '', $action_value = '', $record_id = 0)

Try to add activity points.

    public function _add_activity_points($user_id = 0, $task_name = '', $action_value = '', $record_id = 0)
    {
        return module_safe('activity')->_auto_add_points($user_id, $task_name, $action_value, $record_id);
    }
public function _check_multi_accounts($target_user_id = 0, $source_user_id = 0)

Check multi-accounts.

    public function _check_multi_accounts($target_user_id = 0, $source_user_id = 0)
    {
        return _class('multi_accounts', 'classes/common/')->_check($target_user_id, $source_user_id);
    }
public function _convert_charset($text = '', $charset_from = '', $charset_into = 'utf-8')

Check if given IP matches given CIDR.

    public function _convert_charset($text = '', $charset_from = ''/*ISO-8859-1*/, $charset_into = 'utf-8')
    {
        if ( ! strlen($text)) {
            return false;
        }
        return _class('convert_charset')->go($text, $charset_from, $charset_into);
    }

_create_cloud

public function _create_cloud($cloud_data = [], $params = [])

Creates tags cloud.

    public function _create_cloud($cloud_data = [], $params = [])
    {
        return _class('common_tags_cloud', 'classes/common/')->create($cloud_data, $params);
    }
public function _currency_convert($number = 0, $c_from = '', $c_to = '')

Converter between well-known currencies.

    public function _currency_convert($number = 0, $c_from = '', $c_to = '')
    {
        return _class('other_common', 'classes/common/')->_currency_convert($number, $c_from, $c_to);
    }

_cut_bb_codes

public function _cut_bb_codes($body = '')

Cut BB Codes from the given text.

    public function _cut_bb_codes($body = '')
    {
        return preg_replace('/\[[^\]]+\]/ims', '', $body);
    }

_error_exists

public function _error_exists($error_key = '')

Chec if user error exists.

    public function _error_exists($error_key = '')
    {
        if ( ! empty($error_key)) {
            return (bool) $this->USER_ERRORS[$error_key];
        }
        return isset($this->USER_ERRORS) && count((array) $this->USER_ERRORS) ? true : false;
    }
public function _format_time_value($value = '', $round_to = 4)

Format execution time.

    public function _format_time_value($value = '', $round_to = 4)
    {
        if (empty($value)) {
            $value = 0.0001;
        }
        return substr(round((float) $value, $round_to), 0, $round_to + 2);
    }
public function _get_country_by_ip($ip = '')

Get country by IP address using maxmind API (http://geolite.maxmind.com/download/geoip/api/php/).

Returns 2-byte (uppercased) or false if something wrong

    public function _get_country_by_ip($ip = '')
    {
        return _class('other_common', 'classes/common/')->_get_country_by_ip($ip);
    }
public function _get_error_messages($key = '')

Show formatted contents of user errors.

    public function _get_error_messages($key = '')
    {
        if ( ! $this->USER_ERRORS) {
            return false;
        }
        return $key ? $this->USER_ERRORS[$key] : $this->USER_ERRORS;
    }
public function _get_geo_data_from_db($cur_ip = '')

Get geo info by IP from db.

    public function _get_geo_data_from_db($cur_ip = '')
    {
        return _class('other_common', 'classes/common/')->_get_geo_data_from_db($cur_ip);
    }
public function _get_time_diff_human($seconds, $delimiter = ' ', $need_return = false, $only_text = false, $need_closing_tag = false)
    public function _get_time_diff_human($seconds, $delimiter = ' ', $need_return = false, $only_text = false, $need_closing_tag = false)
    {
        $d = [];
        $tr = [
            'years' => ['years', 'year', 'years'],
            'months' => ['months', 'month', 'months'],
            'days' => ['days', 'day', 'days'],
            'hours' => ['hours', 'hour', 'hours'],
            'minutes' => ['minutes', 'minute', 'minutes'],
            'seconds' => ['seconds', 'second', 'seconds'],
        ];
        $check_format = null;
        if ($need_return && is_array($need_return)) {
            $check_format = true;
        }
        if ($check_format && in_array('years', $need_return)) {
            $d['years'] = floor($seconds / (3600 * 24 * 365));
            $seconds -= $d['years'] * (3600 * 24 * 365);
        }
        if ($check_format && in_array('months', $need_return)) {
            $d['months'] = floor($seconds / (3600 * 24 * 365 / 12));
            $seconds -= $d['months'] * (3600 * 24 * 365 / 12);
        }
        if ($check_format && in_array('days', $need_return)) {
            $d['days'] = floor($seconds / (3600 * 24));
            $seconds -= $d['days'] * (3600 * 24);
        }
        if ($check_format && in_array('hours', $need_return)) {
            $d['hours'] = floor($seconds / 3600);
            $seconds -= $d['hours'] * 3600;
        }
        if ($check_format && in_array('minutes', $need_return)) {
            $d['minutes'] = floor($seconds / 60);
            $seconds -= $d['minutes'] * 60;
        }
        if ($check_format && in_array('seconds', $need_return)) {
            $d['seconds'] = $seconds;
        }
        $out = [];
        foreach ($d as $name => $val) {
            if ( ! $val) {
                continue;
            }
            // English: singular for exactly 1, the Slavic last-digit forms no longer apply
            $str = (int) $val === 1 ? $tr[$name][1] : $tr[$name][0];
            $out[] = $only_text ? $str : $val . ' ' . $str;
        }
        $open_tag = '';
        $close_tag = '';
        if ($need_closing_tag) {
            $open_tag = '<' . $delimiter . '>';
            $close_tag = '</' . $delimiter . '>';
            $delimiter = $close_tag . $open_tag;
        }
        return $open_tag . implode($delimiter, $out) . $close_tag;
    }

_ip_is_banned

public function _ip_is_banned($CUR_IP = '')

Check if given IP is banned.

    public function _ip_is_banned($CUR_IP = '')
    {
        if ( ! $CUR_IP) {
            $CUR_IP = common()->get_ip();
        }
        if ( ! $CUR_IP) {
            return false;
        }
        // We allow wildcards here (example: banned_ip: 192.168.*)
        $_banned_ips_array = main()->get_data('banned_ips');
        foreach ((array) $_banned_ips_array as $_ip => $_info) {
            $IP_MATCHED = false;
            $_ip = preg_replace('/[^0-9\.\*]/', '', $_ip);
            // Check as subnetwork with wildcard
            if (false != strpos($_ip, '*')) {
                $IP_MATCHED = preg_match('#' . str_replace(['.', '*'], ['\\.', '.*'], $_ip) . '#', $CUR_IP);
                // Check as subnetwork in CIDR format
            } elseif (false != strpos($_ip, '/')) {
                $IP_MATCHED = common()->_is_ip_in_cidr($CUR_IP, $_ip);
            } else {
                $IP_MATCHED = ($CUR_IP == $_ip);
            }
            if ($IP_MATCHED) {
                return true;
            }
        }
        return false;
    }

_is_ignored

public function _is_ignored($target_user_id, $owner_id)

Check if user is ignored by second one.

    public function _is_ignored($target_user_id, $owner_id)
    {
        if (empty($target_user_id) || empty($owner_id) || $target_user_id == $owner_id) {
            return false;
        }
        return (bool) db()->query_num_rows(
            'SELECT * FROM ' . db('ignore_list') . ' WHERE user_id=' . (int) $owner_id . ' AND target_user_id=' . (int) $target_user_id
        );
    }
public function _is_ip_in_cidr($iptocheck, $CIDR)

Check if given IP matches given CIDR.

    public function _is_ip_in_cidr($iptocheck, $CIDR)
    {
        return _class('other_common', 'classes/common/')->_is_ip_in_cidr($iptocheck, $CIDR);
    }
public function _is_ip_to_skip($cur_ip = '')

Get geo info by IP from db.

    public function _is_ip_to_skip($cur_ip = '')
    {
        return _class('other_common', 'classes/common/')->_is_ip_to_skip($cur_ip);
    }

_is_spider

public function _is_spider($ip = '', $ua = '')

new method checking for spider by ip address (database from http://www.iplists.com/).

    public function _is_spider($ip = '', $ua = '')
    {
        return _class('spider_detection', 'classes/common/')->_is_spider($ip, $ua);
    }
public function _log_user_action($action_name, $member_id, $object_name = '', $object_id = 0)

Log user actions for stats.

    public function _log_user_action($action_name, $member_id, $object_name = '', $object_id = 0)
    {
        return _class('logs')->_log_user_action($action_name, $member_id, $object_name, $object_id);
    }
public function _make_thumb_remote($url, $filename)

Makes thumb of remote web page parameters: page url, filename(without extension).

    public function _make_thumb_remote($url, $filename)
    {
        $command = '/usr/src/webthumb-1.01/webthumb "' . $url . '" | pnmcrop -black | pamcut -top 95 -right -16 -bottom -40 | pnmtojpeg > ' . $filename;
        exec($command);
    }

_my_split

public function _my_split($text = '', $split_token = '', $split_length = 0)

Adaptively split large text into smaller parts by token with part size limit.

    public function _my_split($text = '', $split_token = '', $split_length = 0)
    {
        return _class('other_common', 'classes/common/')->_my_split($text, $split_token, $split_length);
    }
public function _propose_url_from_name($name = '', $force_dashes = null)

Convert name into URL-friendly string.

    public function _propose_url_from_name($name = '', $force_dashes = null)
    {
        if (empty($name)) {
            return '';
        }
        $url = str_replace([';', ',', '.', ':', ' ', '/'], '_', $name);
        $url = preg_replace('/[_-]{2,}/', '_', $url);
        $url = trim(trim(trim($url), '_-'));

        $url = common()->make_translit($url);

        $url = strtolower(preg_replace('/[^a-z0-9_-]+/i', '', $url));

        if ( ! isset($force_dashes)) {
            $force_dashes = $this->URL_FORCE_DASHES;
        }
        if ($force_dashes) {
            $url = str_replace('_', '-', $url);
            $url = preg_replace('/[-]{2,}/', '-', $url);
            $url = trim(trim(trim($url), '-'));
        } else {
            $url = str_replace('-', '_', $url);
            $url = preg_replace('/[_]{2,}/', '_', $url);
            $url = trim(trim(trim($url), '_'));
        }
        return $url;
    }

_raise_error

public function _raise_error($text = '', $error_key = '')

Raise user error.

    public function _raise_error($text = '', $error_key = '')
    {
        $text = t((string) $text);
        $error_key = (string) $error_key;
        if ( ! $text) {
            return false;
        }
        if ( ! isset($this->USER_ERRORS)) {
            $this->USER_ERRORS = [];
        }
        if ($error_key) {
            $this->USER_ERRORS[$error_key] = $text;
        } else {
            $this->USER_ERRORS[] = $text;
        }
        return true;
    }
public function _remove_activity_points($user_id = 0, $task_name = '', $record_id = 0)

Try to remove activity points.

    public function _remove_activity_points($user_id = 0, $task_name = '', $record_id = 0)
    {
        return module_safe('activity')->_auto_remove_points($user_id, $task_name, $record_id);
    }
public function _remove_error_messages($key = '')
    public function _remove_error_messages($key = '')
    {
        if ($key) {
            unset($this->USER_ERRORS[$key]);
        } else {
            $this->USER_ERRORS = [];
        }
    }
public function _show_error_inline($error_key = '')

Show formatted single error message.

    public function _show_error_inline($error_key = '')
    {
        if (empty($error_key)) {
            return false;
        }
        // Try to get error message
        $error_msg = '';
        if (isset($this->USER_ERRORS[$error_key])) {
            $error_msg = $this->USER_ERRORS[$error_key];
        }
        // Last check
        if (empty($error_msg)) {
            return false;
        }
        // Prepare template
        $replace = [
            'text' => _escape_tpl_braces($error_msg),
            'key' => $error_key,
        ];
        return tpl()->parse('system/error_inline', $replace);
    }
public function _show_error_message($cur_error_msg = '', $clear_error = true)

Show formatted contents of user errors.

    public function _show_error_message($cur_error_msg = '', $clear_error = true)
    {
        // Prevent recursive display
        if (strlen($cur_error_msg) && false !== strpos($cur_error_msg, '<!--YF_ERROR_MESSAGE_START-->')) {
            return t($cur_error_msg);
        }
        if ( ! isset($this->USER_ERRORS)) {
            $this->USER_ERRORS = [];
        }
        if (strlen($cur_error_msg)) {
            $this->USER_ERRORS[] = $cur_error_msg;
        }
        foreach ((array) $this->USER_ERRORS as $error_key => $value) {
            if (empty($value)) {
                continue;
            }
            $items[$error_key] = _escape_tpl_braces($value);
        }
        if ($this->TRACK_USER_ERRORS && ! empty($this->USER_ERRORS)) {
            _class('logs')->save_user_error($this->USER_ERRORS);
        }
        if ($clear_error) {
            $this->_remove_error_messages();
        }
        if (conf('IS_SPIDER')) {
            return false;
        }
        if (empty($items)) {
            return '';
        }
        $replace = [
            'items' => $items,
            'error' => 'error', // DO NOT REMOVE THIS!!! NEEDED TO AVOID INFINITE LOOP INSIDE TPL CLASS
        ];
        return tpl()->parse('system/error_message', $replace);
    }
public function _show_execution_time()

Show execution time info.

    public function _show_execution_time()
    {
        main()->_time_end = $this->_format_time_value(microtime(true) - main()->_time_start);
        return '<div align="center" id="debug_exec_time">' . _ucfirst(t('page_generated_in')) . ' ' . main()->_time_end . ' ' . t('seconds') . ',   ' . t('number_of_queries') . ' = ' . (int) (db()->NUM_QUERIES) . '</div>' . PHP_EOL;
    }

_unaccent

public function _unaccent($text = '', $case = 0)

Remove accents from symbols.

    public function _unaccent($text = '', $case = 0)
    {
        if (is_array($text)) {
            foreach ((array) $text as $k => $v) {
                $text[$k] = $this->_unaccent($v);
            }
            return $text;
        }
        if ( ! strlen($text)) {
            return $text;
        }
        return _class('utf8_clean', 'classes/common/')->_unaccent($text, $case);
    }
public function _validate_url_by_http($url)

Verify url using remote call.

    public function _validate_url_by_http($url)
    {
        return _class('validate')->_validate_url_by_http($url);
    }