yf_sites_info class

Get info about sites.

Fileplugins/sys/classes/yf_sites_info.class.php
Use_class('sites_info')

Public properties

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

PropertyDefaultDescription
$_config_file_name
string
'site_vars.php' Sites config file name
$_consts_to_parse
array
['SITE_UPLOADS_DIR', 'SITE_ADVERT_PHOTOS_DIR', 'SITE_LINKS_BANNERS_DIR', 'SITE_AVATARS_DIR', 'SITE_BLOG_IMAGES_DIR', 'SITE_GALLERY_DIR', ... (7 items)]
array (
  0 => 'SITE_UPLOADS_DIR',
  1 => 'SITE_ADVERT_PHOTOS_DIR',
  2 => 'SITE_LINKS_BANNERS_DIR',
  3 => 'SITE_AVATARS_DIR',
  4 => 'SITE_BLOG_IMAGES_DIR',
  5 => 'SITE_GALLERY_DIR',
  6 => 'DEFAULT_SKIN',
)
Config constants to parse
$_get_const_pattern
string
'/define\\s*\\(\\s*["\\']*##CONST_NAME##["\\']*[\\s\t]*,[\\s\t]*["\\']*([^\\'"]+)["\\']*\\s*\\)/Uims' @conf_skip Patterns to get constant value
$_index_file_name
string
'index.php' Name of sites index file
$info
array
[] @conf_skip Container for sites info

Public methods 4

None without a leading underscore.

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

__construct

public function __construct($skip_files_info = false)
    public function __construct($skip_files_info = false)
    {
        $this->_get_info_from_db();
        if (empty($skip_files_info)) {
            $this->_get_sites_info();
        }
    }
public function _get_info_from_db()

Get first sites info from db.

    public function _get_info_from_db()
    {
        if ( ! empty($this->info)) {
            return false;
        }
        // Get sites infos from db
        $sites_info_from_db = main()->get_data('sites');
        // Get users sites paths
        foreach ((array) $sites_info_from_db as $A) {
            $tmp = $A;
            foreach ((array) $tmp as $k => $v) {
                $tmp[$k] = stripslashes($v);
            }
            $A = $tmp;
            // Skip sites with empty paths
            if (empty($A['real_path']) || empty($A['web_path'])) {
                continue;
            }
            $web_path = eval("return '" . $A['web_path'] . "';") . '/';
            $web_path = str_replace('\\', '/', str_replace('//', '/', $web_path));
            $real_path = eval('return ' . $A['real_path'] . ';') . '/';
            $real_path = str_replace('\\', '/', str_replace('//', '/', $real_path));
            // Skip wrong sites paths
            if ($real_path == '/' || ! file_exists($real_path)) {
                continue;
            }
            // Store info
            $this->info[$A['id']]['name'] = $A['name'];
            $this->info[$A['id']]['WEB_PATH'] = $web_path;
            $this->info[$A['id']]['REAL_PATH'] = $real_path;
        }
    }
public function _get_site_current_theme($SITE_INFO = [])

Get site current theme.

    public function _get_site_current_theme($SITE_INFO = [])
    {
        $index_file_path = $SITE_INFO['REAL_PATH'] . $this->_index_file_name;
        if ( ! file_exists($index_file_path)) {
            return false;
        }
        $tmp_string = file_get_contents($index_file_path);
        if (empty($tmp_string)) {
            return false;
        }
        // Try to get config item value
        $cur_pattern = str_replace('##CONST_NAME##', 'DEFAULT_SKIN', $this->_get_const_pattern);
        if (preg_match($cur_pattern, $tmp_string, $found)) {
            return $found['1'];
        }
        return false;
    }
public function _get_sites_info()

Get user sites detailed info (real_paths, web_paths, paths to images etc).

    public function _get_sites_info()
    {
        // Process config files
        foreach ((array) $this->info as $site_id => $info) {
            $tmp_string = '';
            $found = [];
            $config_path = $info['REAL_PATH'] . $this->_config_file_name;
            // Try to get config file contents
            if ( ! file_exists($config_path)) {
                $config_path = $info['REAL_PATH'] . $this->_index_file_name;
            }
            if ( ! file_exists($config_path)) {
                continue;
            }
            $tmp_string = file_get_contents($config_path);
            if (empty($tmp_string)) {
                continue;
            }
            // Get constants
            foreach ((array) $this->_consts_to_parse as $const_name) {
                $cur_pattern = str_replace('##CONST_NAME##', $const_name, $this->_get_const_pattern);
                if ( ! preg_match($cur_pattern, $tmp_string, $found)) {
                    continue;
                }
                $this->info[$site_id][$const_name] = $found['1'];
            }
        }
    }