Пример #1
0
 /**
  * Get the unique cache instance
  *
  * @param array $cfg Config for the cache instance
  * @return cache_abstract The instance
  */
 public static function getInstance(array $cfg = array())
 {
     if (!self::$cfg) {
         self::$cfg = new config(factory::loadCfg(__CLASS__));
     }
     return factory::get('cache_' . self::$cfg->use, $cfg);
 }
Пример #2
0
	/**
	 * Initialize nyro
	 */
	private static function init() {
		if (!self::$cfg) {
			factory::init();
			if (DEV) {
				debug::timer('nyro');
				debug::timer('nyroProcess');
			}
			request::init();
			self::$cfg = new config(factory::loadCfg(__CLASS__));
			file::init();
			session::initFlash();
		}
	}
Пример #3
0
 /**
  * Init the config object
  */
 protected static function init()
 {
     if (self::$cfg == null) {
         self::$cfg = new config(factory::loadCfg(__CLASS__));
     }
 }
Пример #4
0
	/**
	 * Init the session configuration
	 */
	private static function initCfg() {
		if (!self::$cfg)
			self::$cfg = new config(factory::loadCfg(__CLASS__));
	}
Пример #5
0
 /**
  * Overload a config from an other class.
  * The class could not exists
  *
  * @param string $className
  * @param bool $parent Indicate if the search should load the parent config (if virtual, should be false!)
  */
 public function overload($className, $parent = false)
 {
     factory::mergeCfg($this->vars, factory::loadCfg($className, $parent));
 }
Пример #6
0
	/**
	 * Initialize the request object
	 * Call by the init function from nyro class
	 */
	public static function init() {
		if (!empty(self::$requestArray))
			return;

		self::$cfg = new config(factory::loadCfg(__CLASS__));

		$alias = array();
		$outs = '(\.('.implode('|', array_keys(self::$cfg->outCfg)).'))';
		foreach(self::$cfg->alias as $k=>$v) {
			if ($k == '/') {
				$alias['(/.{2})?/?'] = '\1'.$v;
				$alias['(/.{2})?'.$outs] = '\1'.$v.'\2';
			} else {
				$k = '(/.{2})?'.$k;
				$tmp = explode('\\', $v);
				$t = '\\1'.$tmp[0];
				unset($tmp[0]);
				$i = 2;
				foreach($tmp as $tt) {
					$t.='\\'.(intval(substr($tt, 0, 1))+1).substr($tt, 1);
					$i++;
				}
				if (!preg_match($outs, $k))
					$alias[$k.'(.*)'] = $t.'\\'.$i;
				$alias[$k] = $t;
			}
		}
		$alias = array_reverse($alias, true);
		self::$cfg->alias = $alias;

		// Put the default lang at the top of available langs
		$avlLangsTmp = self::$cfg->avlLang;
		$avlLangs = array();
		foreach($avlLangsTmp as $k=>$v) {
			if ($k == self::$cfg->lang) {
				$avlLangs[$k] = $v;
				unset($avlLangsTmp[$k]);
			}
		}
		self::$cfg->avlLang = array_merge($avlLangs, $avlLangsTmp);

		$secure = (array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] == 'on');

		$protocol = $secure? 'https' : 'http';

		$controller = basename($_SERVER['SCRIPT_FILENAME']);

		$serverName = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : (array_key_exists('SERVER_NAME', $_SERVER) ? $_SERVER['SERVER_NAME'] : self::$cfg->defaultServerName);
		$stdPort = $secure ? '443' : '80';
		$port = (array_key_exists('SERVER_PORT', $_SERVER) && $_SERVER['SERVER_PORT'] != $stdPort && $_SERVER['SERVER_PORT'])? ':'.$_SERVER['SERVER_PORT'] : '';
		$domain = $protocol.'://'.$serverName.$port;

		$scriptName = $_SERVER['SCRIPT_NAME'];
		$requestUri = urldecode(array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : ('/'.$scriptName.(array_key_exists(1, $_SERVER['argv']) ? $_SERVER['argv'][1] : '')));

		$redir = null;
		$forceServerName = null;
		if (self::$cfg->forceServerName
		    && strpos($serverName, 'localhost') === false
		    && strtolower(self::$cfg->forceServerName) != strtolower($serverName)) {
			$forceServerName = self::$cfg->forceServerName;
			$redir = $protocol.'://'.$forceServerName.$port.$requestUri;
		}
		if (self::$cfg->forceNoOut
		    && self::$cfg->noOut
		    && ($pos = strpos($requestUri, self::$cfg->noOut))
		    && $pos + strlen(self::$cfg->noOut) == strlen($requestUri)
		    ) {
			if ($redir)
			    $redir = substr($redir, 0, -1*(strlen(self::$cfg->noOut)+1));
			else
			    $redir = $domain.substr($requestUri, 0, $pos-1);
		}
		if (self::$cfg->noController && strpos($requestUri, self::$cfg->noController) !== false) {
			if (!$redir)
			    $redir = $domain.$requestUri;
			$redir = str_replace(self::$cfg->noController.'/', '', $redir);
			if ($pos = strpos($redir, self::$cfg->noController))
				$redir = substr($redir, 0, $pos);
		}

		$path = '/';
		$requestUriTmp = explode('/', substr($requestUri, 1));
		$scriptNameTmp = explode('/', substr($scriptName, 1));
		$min = min(count($requestUriTmp), count($scriptNameTmp));
		$i = 0;
		while ($i < $min && $requestUriTmp[$i] == $scriptNameTmp[$i]) {
			$path.= $requestUriTmp[$i].'/';
			$i++;
		}

		$pathWithController = (strpos($requestUri, $controller) !== false);

		if ($pathWithController) {
			if (strpos($path, $controller) !== false)
				$path = substr($path, 0, -strlen($controller)-1);
			$len = strlen($path.$controller);
			$request = (isset($requestUri[$len]) && $requestUri[$len] == '?') ? '' : substr($requestUri, $len+1);
		} else
			$request = substr($requestUri, strlen($path));

		if (self::$cfg->forceNoLang) {
			$forceNoLang = self::$cfg->forceNoLang === true ? self::$cfg->lang : self::$cfg->forceNoLang;
			if ($requestUri != $path && strpos($requestUri, '/'.$forceNoLang.'/') !== false && $request) {
				$redir = str_replace('/'.$forceNoLang.'/', '/', $redir ? $redir : $domain.$requestUri);
			}
		} else if (self::$cfg->forceLang) {
			$forceLang = self::$cfg->forceLang === true ? self::$cfg->lang : self::$cfg->forceLang;
			if ($requestUri != $path && strpos($requestUri, '/'.$forceLang.'/') === false
					&& $request) {
				$continue = true;
				$i = 0;
				$cpt = count(self::$cfg->noForceLang);
				while($continue && $i < $cpt) {
					if (strpos($request, self::$cfg->noForceLang[$i]) === 0)
						$continue = false;
					$i++;
				}
				if ($continue) {
					// lang not found, force it
					$redirWork = $redir ? $redir : $domain.$requestUri;
					$search = ($forceServerName ? $forceServerName : $domain).$path.($pathWithController? $controller.'/' : null);
					$pos = strpos($redirWork, $search) + strlen($search);
					$end = $pos < strlen($redirWork) ? strpos($redirWork, '/', $pos+1) : false;
					$end = $end ? $end-$pos : strlen($redirWork);
					$curLang = substr($redirWork, $pos, $end);
					if (!self::isLang($curLang))
						$redir = substr($redirWork, 0, $pos).$forceLang.'/'.substr($redirWork, $pos);
				}
			}
		}

		if ($redir) {
		    header('HTTP/1.0 301 Moved Permanently');
		    header('Location: '.$redir);
		    exit;
		}

		self::extractGet($request, true);

		self::$requestedUriInfo = self::analyseRequest($request);

		self::$uriInfo = array_merge(array(
				'secure'=>$secure,
				'protocol'=>$protocol,
				'controller'=>$controller,
				'serverName'=>$serverName,
				'domain'=>$domain,
				'path'=>$path,
				'pathWithController'=>$pathWithController,
				'request'=>$request,
				'lang'=>self::$cfg->lang,
				'module'=>self::$cfg->module,
				'moduleScaffold'=>null,
				'action'=>self::$cfg->action,
				'param'=>self::$cfg->param,
				'text'=>self::$cfg->text,
				'out'=>self::$cfg->out
			), self::$requestedUriInfo);

		if (self::$cfg->forceSecure)
			request::forceSecure();

		self::fixFiles();
	}
Пример #7
0
	/**
	 * Initialize the security instance parametred
	 */
	private static function init() {
		self::$cfg = new config(factory::loadCfg(__CLASS__));
		self::$instance = factory::get('security_'.self::$cfg->use);
	}
Пример #8
0
 /**
  * Initialize the factory configuration
  */
 public static function init()
 {
     self::$constants = get_defined_constants(true);
     self::initCache();
     self::$cfg = new config(factory::loadCfg(__CLASS__));
 }
Пример #9
0
	/**
	 * Get an icon
	 *
	 * @param array $prm Icon configuration. Available key:
	 *  - string name: action name (required)
	 *  - string type: icon type
	 *  - bool imgTag: true if the return should be a valid html img tag. if false, will return he url
	 *  - string alt: alt text for the image, used only if imgTag = true
	 *  - array attr: attributes added to the img tag
	 * @return unknown
	 */
	public static function getIcon(array $prm) {
		$ret = null;

		static $cfg;
		if (!$cfg)
			$cfg = factory::loadCfg('icons', false);

		if (config::initTab($prm, array(
			'name'=>null,
			'type'=>$cfg['default'],
			'imgTag'=>true,
			'alt'=>'',
			'attr'=>array(),
		))) {
			if (array_key_exists($prm['type'], $cfg['icons'])
				&& is_array($cfg['icons'][$prm['type']])
				&& in_array($prm['name'], $cfg['icons'][$prm['type']])) {
					$ret = request::get('path').$cfg['dir'].'/'.$prm['type'].request::getCfg('sepParam').$prm['name'].$cfg['ext'];
			} else if ($prm['type'] != $cfg['default']) {
				$ret = self::getIcon(array('name'=>$prm['name'], 'imgTag'=>false));
			}

			if ($ret && $prm['imgTag']) {
				$alt = $prm['alt']? $prm['alt'] : ucFirst($prm['name']);
				$ret = self::htmlTag('img', array_merge(array(
					'src'=>$ret,
					'alt'=>$alt
				), $prm['attr']));
			}
		}
		return $ret;
	}