Subversion-Projekte lars-tiefland.ci

Revision

Revision 68 | Revision 2107 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 68 Revision 2049
Zeile 4... Zeile 4...
4
 *
4
 *
5
 * An open source application development framework for PHP
5
 * An open source application development framework for PHP
6
 *
6
 *
7
 * This content is released under the MIT License (MIT)
7
 * This content is released under the MIT License (MIT)
8
 *
8
 *
9
 * Copyright (c) 2014 - 2016, British Columbia Institute of Technology
9
 * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
10
 *
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Zeile 27... Zeile 27...
27
 * THE SOFTWARE.
27
 * THE SOFTWARE.
28
 *
28
 *
29
 * @package	CodeIgniter
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32
 * @copyright	Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
32
 * @copyright	Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
33
 * @license	http://opensource.org/licenses/MIT	MIT License
33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
34
 * @link	https://codeigniter.com
35
 * @since	Version 1.0.0
35
 * @since	Version 1.0.0
36
 * @filesource
36
 * @filesource
37
 */
37
 */
Zeile 484... Zeile 484...
484
	 *				or leave it to the Output class
484
	 *				or leave it to the Output class
485
	 * @return	object|string
485
	 * @return	object|string
486
	 */
486
	 */
487
	public function view($view, $vars = array(), $return = FALSE)
487
	public function view($view, $vars = array(), $return = FALSE)
488
	{
488
	{
489
		return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
489
		return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
490
	}
490
	}
Zeile 491... Zeile 491...
491
 
491
 
Zeile 492... Zeile 492...
492
	// --------------------------------------------------------------------
492
	// --------------------------------------------------------------------
Zeile 517... Zeile 517...
517
	 * @param 	string	$val	Value to set, only used if $vars is a string
517
	 * @param 	string	$val	Value to set, only used if $vars is a string
518
	 * @return	object
518
	 * @return	object
519
	 */
519
	 */
520
	public function vars($vars, $val = '')
520
	public function vars($vars, $val = '')
521
	{
521
	{
522
		if (is_string($vars))
522
		$vars = is_string($vars)
523
		{
-
 
524
			$vars = array($vars => $val);
523
			? array($vars => $val)
525
		}
-
 
526
 
-
 
527
		$vars = $this->_ci_object_to_array($vars);
524
			: $this->_ci_prepare_view_vars($vars);
Zeile 528... Zeile 525...
528
 
525
 
529
		if (is_array($vars) && count($vars) > 0)
526
		foreach ($vars as $key => $val)
530
		{
-
 
531
			foreach ($vars as $key => $val)
-
 
532
			{
527
		{
533
				$this->_ci_cached_vars[$key] = $val;
-
 
534
			}
528
			$this->_ci_cached_vars[$key] = $val;
Zeile 535... Zeile 529...
535
		}
529
		}
536
 
530
 
Zeile 589... Zeile 583...
589
	 * @param	string|string[]	$helpers	Helper name(s)
583
	 * @param	string|string[]	$helpers	Helper name(s)
590
	 * @return	object
584
	 * @return	object
591
	 */
585
	 */
592
	public function helper($helpers = array())
586
	public function helper($helpers = array())
593
	{
587
	{
594
		foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
588
		is_array($helpers) OR $helpers = array($helpers);
-
 
589
		foreach ($helpers as &$helper)
595
		{
590
		{
-
 
591
			$filename = basename($helper);
-
 
592
			$filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename));
-
 
593
			$filename = strtolower(preg_replace('#(_helper)?(.php)?$#i', '', $filename)).'_helper';
-
 
594
			$helper   = $filepath.$filename;
-
 
595
 
596
			if (isset($this->_ci_helpers[$helper]))
596
			if (isset($this->_ci_helpers[$helper]))
597
			{
597
			{
598
				continue;
598
				continue;
599
			}
599
			}
Zeile 600... Zeile 600...
600
 
600
 
601
			// Is this a helper extension request?
601
			// Is this a helper extension request?
602
			$ext_helper = config_item('subclass_prefix').$helper;
602
			$ext_helper = config_item('subclass_prefix').$filename;
603
			$ext_loaded = FALSE;
603
			$ext_loaded = FALSE;
604
			foreach ($this->_ci_helper_paths as $path)
604
			foreach ($this->_ci_helper_paths as $path)
605
			{
605
			{
606
				if (file_exists($path.'helpers/'.$ext_helper.'.php'))
606
				if (file_exists($path.'helpers/'.$ext_helper.'.php'))
Zeile 932... Zeile 932...
932
		 * You can either set variables using the dedicated $this->load->vars()
932
		 * You can either set variables using the dedicated $this->load->vars()
933
		 * function or via the second parameter of this function. We'll merge
933
		 * function or via the second parameter of this function. We'll merge
934
		 * the two types and cache them so that views that are embedded within
934
		 * the two types and cache them so that views that are embedded within
935
		 * other views can have access to these variables.
935
		 * other views can have access to these variables.
936
		 */
936
		 */
937
		if (is_array($_ci_vars))
-
 
938
		{
-
 
939
			foreach (array_keys($_ci_vars) as $key)
-
 
940
			{
-
 
941
				if (strncmp($key, '_ci_', 4) === 0)
-
 
942
				{
-
 
943
					unset($_ci_vars[$key]);
-
 
944
				}
-
 
945
			}
-
 
946
 
-
 
947
			$this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
937
		empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
948
		}
-
 
949
		extract($this->_ci_cached_vars);
938
		extract($this->_ci_cached_vars);
Zeile 950... Zeile 939...
950
 
939
 
951
		/*
940
		/*
952
		 * Buffer the output
941
		 * Buffer the output
Zeile 1374... Zeile 1363...
1374
	}
1363
	}
Zeile 1375... Zeile 1364...
1375
 
1364
 
Zeile 1376... Zeile 1365...
1376
	// --------------------------------------------------------------------
1365
	// --------------------------------------------------------------------
1377
 
1366
 
1378
	/**
1367
	/**
1379
	 * CI Object to Array translator
1368
	 * Prepare variables for _ci_vars, to be later extract()-ed inside views
1380
	 *
1369
	 *
1381
	 * Takes an object as input and converts the class variables to
1370
	 * Converts objects to associative arrays and filters-out internal
1382
	 * an associative array with key/value pairs.
1371
	 * variable names (i.e. keys prexied with '_ci_').
1383
	 *
1372
	 *
1384
	 * @param	object	$object	Object data to translate
1373
	 * @param	mixed	$vars
1385
	 * @return	array
1374
	 * @return	array
1386
	 */
1375
	 */
-
 
1376
	protected function _ci_prepare_view_vars($vars)
-
 
1377
	{
-
 
1378
		if ( ! is_array($vars))
1387
	protected function _ci_object_to_array($object)
1379
		{
-
 
1380
			$vars = is_object($vars)
-
 
1381
				? get_object_vars($object)
-
 
1382
				: array();
-
 
1383
		}
-
 
1384
 
-
 
1385
		foreach (array_keys($vars) as $key)
-
 
1386
		{
-
 
1387
			if (strncmp($key, '_ci_', 4) === 0)
-
 
1388
			{
-
 
1389
				unset($vars[$key]);
-
 
1390
			}
-
 
1391
		}
1388
	{
1392
 
Zeile 1389... Zeile 1393...
1389
		return is_object($object) ? get_object_vars($object) : $object;
1393
		return $vars;
Zeile 1390... Zeile 1394...
1390
	}
1394
	}
Zeile 1402... Zeile 1406...
1402
	protected function &_ci_get_component($component)
1406
	protected function &_ci_get_component($component)
1403
	{
1407
	{
1404
		$CI =& get_instance();
1408
		$CI =& get_instance();
1405
		return $CI->$component;
1409
		return $CI->$component;
1406
	}
1410
	}
1407
 
-
 
1408
	// --------------------------------------------------------------------
-
 
1409
 
-
 
1410
	/**
-
 
1411
	 * Prep filename
-
 
1412
	 *
-
 
1413
	 * This function prepares filenames of various items to
-
 
1414
	 * make their loading more reliable.
-
 
1415
	 *
-
 
1416
	 * @param	string|string[]	$filename	Filename(s)
-
 
1417
	 * @param 	string		$extension	Filename extension
-
 
1418
	 * @return	array
-
 
1419
	 */
-
 
1420
	protected function _ci_prep_filename($filename, $extension)
-
 
1421
	{
-
 
1422
		if ( ! is_array($filename))
-
 
1423
		{
-
 
1424
			return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
-
 
1425
		}
-
 
1426
		else
-
 
1427
		{
-
 
1428
			foreach ($filename as $key => $val)
-
 
1429
			{
-
 
1430
				$filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
-
 
1431
			}
-
 
1432
 
-
 
1433
			return $filename;
-
 
1434
		}
-
 
1435
	}
-
 
1436
 
-
 
1437
}
1411
}