yf_sites_info classGet info about sites.
| File | plugins/sys/classes/yf_sites_info.class.php |
|---|---|
| Use | _class('sites_info') |
A site sets them in its config with $PROJECT_CONF['sites_info']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$_config_file_namestring |
'site_vars.php' |
Sites config file name |
$_consts_to_parsearray |
|
Config constants to parse |
$_get_const_patternstring |
'/define\\s*\\(\\s*["\\']*##CONST_NAME##["\\']*[\\s\t]*,[\\s\t]*["\\']*([^\\'"]+)["\\']*\\s*\\)/Uims' |
@conf_skip Patterns to get constant value |
$_index_file_namestring |
'index.php' |
Name of sites index file |
$infoarray |
[] |
@conf_skip Container for sites info |
None without a leading underscore.
_ hooks and helpers; not routable as page actionspublic 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'];
}
}
}