function getContent($opts, $sParam)
{
	$url = $opts['url'];
	if (strpos($url, 'http://') !== false || strpos($url, 'https://') !== false)
	{
		// load External URL		
    	$content = file_get_contents($url);
    	// Set to the default text if we didn't get anything
    	if (!$content) $content = $opts['default'];
		return $content;
	}
	else {
		// load Internal URL (relative URL)
		// example: /sign-in => array('ext/authentication', 'SignIn')	
		list($loc, $className) = parseUri($url);
		$fullpath = BASE.'/app/'.$loc.'/'.$className.'.php';
		
		if (file_exists($fullpath))
		{			
			ob_start();
	 		// load extension
			require_once $fullpath;
			$ctr = new $className();
			$ctr->handle(array($sParam));			

			$content = ob_get_contents();			
			ob_end_clean();
			return $content;
		}
	}
    return '';
}
	/**
	 * Process URI to know which controller to load
	 * @return an array: controller Path, Name, Params
	 */
	public static function parseRoute($route)
	{
		if (strpos($route, '/dispatcher.php') !== false) {
			return array('controller', 'Home', '');
		}
		$params = null;
				
		// first, check if URI matched with Custom URI Mappings in 'conf/app_mapping.php'
		$mpArr = parseUri($route);
		if ($mpArr != null)
		{
            if (isset($mpArr[2]) != null) {
                return array($mpArr[0], $mpArr[1], $mpArr[2]); // path, name, params
            }
            else {
                return array($mpArr[0], $mpArr[1], null); // path, name
            }
		}
        return array(null, null, null);
	}
Example #3
0
<?php

/**
 * This file starts x4xphp framework's main program,
 * load config, execute filter, find Controller and execute it, etc
 * @author yangrl <*****@*****.**>
 */
namespace CORE;

include_once COREPATH . 'common.php';
// x4xphp run process:
// read config
// find required class and method
//var_dump($_SERVER);
$parsed = parseUri($_SERVER['REQUEST_URI']);
if (is_array($parsed)) {
    list($path, $class, $method) = $parsed;
    $c = findController($class, $path);
    $c->_execute($method);
} else {
    show404();
}
// execute controller