Example #1
0
    public function run($mod = false)
    {
        global $bio, $core, $file, $warning;
        if (!($rewrite = enable_rewrite())) {
            $warning->now('Enable mod_rewrite on Apache.');
        }
        require_once XFS . XCOR . 'modules.php';
        if ($mod === false) {
            $mod = request_var('module', '');
        }
        $mod = !empty($mod) ? $mod : 'home';
        if (!($_module = $core->cache->load('module_' . str_replace('/', '_', $mod)))) {
            $sql = 'SELECT *
				FROM _modules
				WHERE module_alias = ?';
            if (!($_module = $core->cache->store(sql_fieldrow(sql_filter($sql, $mod))))) {
                $warning->now('no_module');
            }
        }
        $_module->module_path = XFS . XMOD . $_module->module_path . $_module->module_basename;
        if (!@file_exists($_module->module_path)) {
            $warning->now('no_path: ' . $_module->module_path);
        }
        @(require_once $_module->module_path);
        $_object = '__' . $mod;
        if (!class_exists($_object)) {
            $warning->now();
        }
        $module = new $_object();
        $module->m($mod);
        if (@method_exists($module, 'install')) {
            $module->_install();
        }
        if (!defined('ULIB')) {
            define('ULIB', _link() . str_replace(w('../ ./'), '', LIB));
        }
        if (empty($this->input)) {
            $_input = array();
            if ($arg = request_var('args', '')) {
                foreach (explode('.', $arg) as $str_pair) {
                    $pair = explode(':', $str_pair);
                    if (isset($pair[0]) && isset($pair[1]) && !empty($pair[0])) {
                        $this->input[$pair[0]] = $pair[1];
                    }
                }
            }
            if (isset($_POST) && count($_POST)) {
                $_POST = _utf8($_POST);
                $this->input = array_merge($this->input, $_POST);
            }
        }
        $module->levels($this->input);
        if (!method_exists($module, $module->x(1))) {
            $warning->now();
        }
        if ($module->auth() && (!$module->x(1) || !in_array($module->x(1), $module->exclude))) {
            $module->signin();
        }
        //
        // All verifications passed, so start session for the request
        $bio->start(true);
        $bio->setup();
        if (!$module->auth_access() && $module->auth()) {
            $warning->now();
        }
        $module->navigation('home', '', '');
        $module->navigation($module->m(), '');
        if ($module->x(1) != 'home' && @method_exists($module, 'init')) {
            $module->init();
        }
        hook(array($module, $module->x(1)));
        if (!$module->_template()) {
            $module->_template($mod);
        }
        //
        // Output template
        $page_module = 'MODULE_' . $mod;
        if ($bio->is_lang($page_module)) {
            $module->page_title($page_module);
        }
        $browser_upgrade = false;
        if (!$core->v('skip_browser_detect') && ($list_browser = $file->read(XFS . XCOR . 'store/need_browser'))) {
            $browser_list = w();
            foreach ($list_browser as $row) {
                $e = explode(' :: ', $row);
                $browser_list[$e[0]] = $e[1];
            }
            foreach ($browser_list as $browser => $version) {
                if (_browser($browser) && _browser($browser, $version)) {
                    v_style(array('visual' => ULIB . LIB_VISUAL));
                    $module->_template('browsers');
                    $browser_upgrade = true;
                }
            }
        }
        $sv = array('X1' => $module->x(1), 'X2' => $module->x(2), 'NAVIGATION' => $module->get_navigation(), 'BROWSER_UPGRADE' => $browser_upgrade);
        _layout($module->_template(), $module->page_title(), $sv);
    }
Example #2
0
function _login($message = false, $error = false)
{
    global $bio;
    if (!$bio->v()) {
        $bio->start();
    }
    if (!$bio->_lang_check()) {
        $bio->setup();
    }
    if ($bio->v('is_member')) {
        return;
    }
    if ($bio->v('is_bot')) {
        redirect(_link());
    }
    if ($error === false) {
        $error = $message !== false ? $bio->_lang($message) : false;
    } else {
        $error = $bio->_lang($error);
    }
    if ($error !== false && f($error)) {
        _style('error', array('MESSAGE' => $error));
    }
    $sv = array('REDIRECT_TO' => str_replace(_link(), '', $bio->v('session_page')));
    _layout('login', 'LOGIN', $sv);
}
Example #3
0
function _xfs($mod = false, $wdir = false, $warg = false)
{
	global $user, $style;
	
	include_once(XFS . 'core/modules.php');
	
	if ($mod === false)
	{
		$mod = request_var('module', '');
	}
	$mod = (!empty($mod)) ? $mod : 'home';
	
	$mod_dir = './base/_' . $mod;
	$p_dir = ($wdir === false && @file_exists($mod_dir) && is_dir($mod_dir)) ? true : false;
	
	if (!$p_dir)
	{
		$mod_dir = './base/_' . (($wdir !== false) ? $wdir . '/_' : '') . $mod;
		
		$mod_path = $mod_dir . '.php';
		$mod_class = '__' . $mod;
		
		if (!@file_exists($mod_path))
		{
			_fatal();
		}
		include_once($mod_path);
		
		if (!class_exists($mod_class))
		{
			_fatal();
		}
		$module = new $mod_class();
	}
	
	if ($warg === false)
	{
		$warg = array();
		$arg = request_var('args', '');
		if (!empty($arg))
		{
			foreach (explode('.', $arg) as $v)
			{
				$el = explode(':', $v);
				if (isset($el[0]) && isset($el[1]) && !empty($el[0]))
				{
					$warg[$el[0]] = $el[1];
				}
			}
		}
		
		if (isset($_POST) && count($_POST))
		{
			$_POST = _utf8($_POST);
			$warg = array_merge($warg, $_POST);
		}
	}
	
	if ($p_dir)
	{
		_xfs(((isset($warg['x1'])) ? $warg['x1'] : ''), $mod, $warg);
	}
	else
	{
		if (isset($module->auth) && $module->auth)
		{
			$v_auth_exclude = (isset($module->auth_exclude) && (isset($warg['x1']) && in_array($warg['x1'], $module->auth_exclude))) ? true : false;
			if (!$v_auth_exclude)
			{
				_login();
			}
		}
		
		$warg_x = 0;
		foreach ($warg as $warg_k => $warg_v)
		{
			if (preg_match('/x\d+/i', $warg_k))
			{
				$warg_x = str_replace('x', '', $warg_k);
			}
		}
		
		if ($wdir !== false)
		{
			for ($i = 0; $i < $warg_x; $i++)
			{
				$warg['x' . ($i + 1)] = (isset($warg['x' + ($i + 2)])) ? $warg['x' + ($i + 2)] : '';
			}
		}
	}
	
	date_default_timezone_set('America/Guatemala');
	
	$module->arg = $warg;
	$module->xlevel();
	if (!method_exists($module, $module->level['x1']))
	{
		_fatal();
	}
	
	// Session start
	$user->start(true);
	$user->setup();
	
	if (!$module->auth_access($user->data))
	{
		_fatal();
	}
	
	if (!defined('LIB')) define('LIB', '../space/');
	
	if (!defined('LIBD')) define('LIBD', _link() . str_replace('../', '', LIB));
	
	$module->module = $mod;
	
	if (@method_exists($module, 'install'))
	{
		$module->install();
	}
	
	$module->navigation('home', '', '');
	$module->navigation($module->module, '');
	
	$module->{$module->level['x1']}();
	
	if (empty($module->template))
	{
		$module->template = $mod;
	}
	
	if (@file_exists('./base/tree'))
	{
		$menu = array_map('trim', @file('./base/tree'));
		foreach ($menu as $i => $row)
		{
			if (!$i) $style->assign_block_vars('tree', array());
			
			$row = trim($row);
			$row_level = strripos($row, '*') + 1;
			preg_match('#^\*{0,} (.*?) <(.*?)>$#i', $row, $row_key);
			
			$row_mod = array(dvar(array_key(explode('/', $row_key[2]), 1), 'index'));
			
			if ($row_level > 1) $row_mod[] = array_key(explode(':', array_key(explode('.', array_key(explode('/', $row_key[2]), 2)), 0)), 1);
			
			$row_auth = implode('_', $row_mod);
			if (!$user->auth_get($row_auth)) continue;
			
			$row_style = '.row' . (($row_level == 1) ? '' : '.sub' . ($row_level - 1));
			$style->assign_block_vars('tree' . $row_style, array(
				'V_NAME' => trim(str_replace('*', '', $row_key[1])),
				'V_LINK' => _link() . substr($row_key[2], 1))
			);
		}
	}
	
	//
	// Output template
	$page_smodule = 'CONTROL_' . strtoupper($mod);
	if (is_lang($page_smodule))
	{
		$module->page_title($page_smodule);
	}
	
	$sv = array(
		'MODE' => $module->level['x1'],
		'MANAGE' => $module->level['x2'],
		'NAVIGATION' => $module->get_navigation()
	);
	_layout($module->template, $module->page_title(), $sv);
}