blob: 0ccfe1ea4b9a57cb730b01955a054ad6561b6c42 [file] [log] [blame]
Pascal Kriete69c97a72011-04-20 21:44:54 -04001<?php
2
3// Set up the global CI functions in their most minimal core representation
4
Taufan Adityab2e10b72012-05-27 15:31:53 +07005if ( ! function_exists('get_instance'))
Pascal Kriete69c97a72011-04-20 21:44:54 -04006{
Andrey Andreevf243ce12012-06-09 23:34:21 +03007 function &get_instance()
Taufan Adityab2e10b72012-05-27 15:31:53 +07008 {
9 $test = CI_TestCase::instance();
Andrey Andreev36de42e2012-06-10 13:55:55 +030010 $test = $test->ci_instance();
11 return $test;
Taufan Adityab2e10b72012-05-27 15:31:53 +070012 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040013}
14
Pascal Kriete69c97a72011-04-20 21:44:54 -040015// --------------------------------------------------------------------
16
Taufan Adityab2e10b72012-05-27 15:31:53 +070017if ( ! function_exists('get_config'))
18{
Andrey Andreevf243ce12012-06-09 23:34:21 +030019 function &get_config()
20 {
Taufan Adityab2e10b72012-05-27 15:31:53 +070021 $test = CI_TestCase::instance();
Andrey Andreev62fd52d2012-06-10 07:11:41 +030022 $config = $test->ci_get_config();
23 return $config;
Taufan Adityab2e10b72012-05-27 15:31:53 +070024 }
25}
26
27if ( ! function_exists('config_item'))
28{
29 function config_item($item)
30 {
31 $config =& get_config();
Andrey Andreevf243ce12012-06-09 23:34:21 +030032
Taufan Adityab2e10b72012-05-27 15:31:53 +070033 if ( ! isset($config[$item]))
34 {
35 return FALSE;
36 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030037
Taufan Adityab2e10b72012-05-27 15:31:53 +070038 return $config[$item];
Pascal Kriete88b29632011-04-21 01:21:55 -040039 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040040}
41
dchill427ecc5cd2012-10-12 16:25:51 -040042if ( ! function_exists('get_mimes'))
43{
44 /**
45 * Returns the MIME types array from config/mimes.php
46 *
47 * @return array
48 */
49 function &get_mimes()
50 {
51 static $_mimes = array();
52
53 if (empty($_mimes))
54 {
55 $path = realpath(PROJECT_BASE.'application/config/mimes.php');
56 if (is_file($path))
57 {
58 $_mimes = include($path);
59 }
60 }
61
62 return $_mimes;
63 }
64}
65
Pascal Kriete69c97a72011-04-20 21:44:54 -040066// --------------------------------------------------------------------
67
Taufan Adityab2e10b72012-05-27 15:31:53 +070068if ( ! function_exists('load_class'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040069{
Taufan Adityab2e10b72012-05-27 15:31:53 +070070 function load_class($class, $directory = 'libraries', $prefix = 'CI_')
Pascal Kriete69c97a72011-04-20 21:44:54 -040071 {
Alex Bilbied6d11502012-06-02 11:12:55 +010072 if ($directory !== 'core' OR $prefix !== 'CI_')
Taufan Adityab2e10b72012-05-27 15:31:53 +070073 {
74 throw new Exception('Not Implemented: Non-core load_class()');
75 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030076
Taufan Adityab2e10b72012-05-27 15:31:53 +070077 $test = CI_TestCase::instance();
Andrey Andreevf243ce12012-06-09 23:34:21 +030078
Taufan Adityab2e10b72012-05-27 15:31:53 +070079 $obj =& $test->ci_core_class($class);
Andrey Andreevf243ce12012-06-09 23:34:21 +030080
Taufan Adityab2e10b72012-05-27 15:31:53 +070081 if (is_string($obj))
82 {
Andrey Andreevf243ce12012-06-09 23:34:21 +030083 throw new Exception('Bad Isolation: Use ci_set_core_class to set '.$class);
Taufan Adityab2e10b72012-05-27 15:31:53 +070084 }
Andrey Andreevf243ce12012-06-09 23:34:21 +030085
Taufan Adityab2e10b72012-05-27 15:31:53 +070086 return $obj;
Pascal Kriete69c97a72011-04-20 21:44:54 -040087 }
Pascal Kriete69c97a72011-04-20 21:44:54 -040088}
89
90// This is sort of meh. Should probably be mocked up with
91// controllable output, so that we can test some of our
92// security code. The function itself will be tested in the
93// bootstrap testsuite.
94// --------------------------------------------------------------------
95
Taufan Adityab2e10b72012-05-27 15:31:53 +070096if ( ! function_exists('remove_invisible_characters'))
Pascal Kriete69c97a72011-04-20 21:44:54 -040097{
Taufan Adityab2e10b72012-05-27 15:31:53 +070098 function remove_invisible_characters($str, $url_encoded = TRUE)
Pascal Kriete69c97a72011-04-20 21:44:54 -040099 {
Taufan Adityab2e10b72012-05-27 15:31:53 +0700100 $non_displayables = array();
Andrey Andreevf243ce12012-06-09 23:34:21 +0300101
Taufan Adityab2e10b72012-05-27 15:31:53 +0700102 // every control character except newline (dec 10)
103 // carriage return (dec 13), and horizontal tab (dec 09)
Andrey Andreevf243ce12012-06-09 23:34:21 +0300104
Taufan Adityab2e10b72012-05-27 15:31:53 +0700105 if ($url_encoded)
106 {
107 $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
108 $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
109 }
Andrey Andreevf243ce12012-06-09 23:34:21 +0300110
Taufan Adityab2e10b72012-05-27 15:31:53 +0700111 $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
Pascal Kriete69c97a72011-04-20 21:44:54 -0400112
Taufan Adityab2e10b72012-05-27 15:31:53 +0700113 do
114 {
115 $str = preg_replace($non_displayables, '', $str, -1, $count);
116 }
117 while ($count);
Pascal Kriete69c97a72011-04-20 21:44:54 -0400118
Taufan Adityab2e10b72012-05-27 15:31:53 +0700119 return $str;
120 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400121}
122
123
124// Clean up error messages
125// --------------------------------------------------------------------
126
Taufan Adityab2e10b72012-05-27 15:31:53 +0700127if ( ! function_exists('show_error'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400128{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700129 function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
130 {
131 throw new RuntimeException('CI Error: '.$message);
132 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400133}
134
Taufan Adityab2e10b72012-05-27 15:31:53 +0700135if ( ! function_exists('show_404'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400136{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700137 function show_404($page = '', $log_error = TRUE)
138 {
139 throw new RuntimeException('CI Error: 404');
140 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400141}
142
Taufan Adityab2e10b72012-05-27 15:31:53 +0700143if ( ! function_exists('_exception_handler'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400144{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700145 function _exception_handler($severity, $message, $filepath, $line)
146 {
147 throw new RuntimeException('CI Exception: '.$message.' | '.$filepath.' | '.$line);
148 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400149}
150
Pascal Kriete69c97a72011-04-20 21:44:54 -0400151// We assume a few things about our environment ...
152// --------------------------------------------------------------------
153
Taufan Adityab2e10b72012-05-27 15:31:53 +0700154if ( ! function_exists('is_php'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400155{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700156 function is_php($version = '5.0.0')
157 {
158 return ! (version_compare(PHP_VERSION, $version) < 0);
159 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400160}
161
Taufan Adityab2e10b72012-05-27 15:31:53 +0700162if ( ! function_exists('is_really_writable'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400163{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700164 function is_really_writable($file)
165 {
166 return is_writable($file);
167 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400168}
169
Taufan Adityab2e10b72012-05-27 15:31:53 +0700170if ( ! function_exists('is_loaded'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400171{
dchill424f42be52012-10-21 21:31:19 -0400172 function &is_loaded()
Taufan Adityab2e10b72012-05-27 15:31:53 +0700173 {
dchill424f42be52012-10-21 21:31:19 -0400174 $loaded = array();
175 return $loaded;
Taufan Adityab2e10b72012-05-27 15:31:53 +0700176 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400177}
178
Taufan Adityab2e10b72012-05-27 15:31:53 +0700179if ( ! function_exists('log_message'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400180{
vlakoffd0c30ab2013-05-07 07:49:23 +0200181 function log_message($level, $message, $php_error = FALSE)
Taufan Adityab2e10b72012-05-27 15:31:53 +0700182 {
183 return TRUE;
184 }
Pascal Kriete69c97a72011-04-20 21:44:54 -0400185}
186
Taufan Adityab2e10b72012-05-27 15:31:53 +0700187if ( ! function_exists('set_status_header'))
Pascal Kriete69c97a72011-04-20 21:44:54 -0400188{
Taufan Adityab2e10b72012-05-27 15:31:53 +0700189 function set_status_header($code = 200, $text = '')
190 {
191 return TRUE;
192 }
dchill424f42be52012-10-21 21:31:19 -0400193}