-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.php
194 lines (171 loc) · 3.89 KB
/
base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
/**
* Fuel is a fast, lightweight, community driven PHP5 framework.
*
* @package Fuel
* @version 1.0
* @author Fuel Development Team
* @license MIT License
* @copyright 2010 - 2011 Fuel Development Team
* @link http://fuelphp.com
*/
/**
* Loads in a core class and optionally an app class override if it exists.
*
* @param string $path
* @param string $folder
* @return void
*/
if ( ! function_exists('import'))
{
function import($path, $folder = 'classes')
{
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
require_once COREPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
if (is_file(APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php'))
{
require_once APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
}
}
}
if ( ! function_exists('logger'))
{
function logger($level, $msg, $method = null)
{
if ($level > \Config::get('log_threshold'))
{
return false;
}
! class_exists('Fuel\\Core\\Log') and import('log');
! class_exists('Log') and class_alias('Fuel\\Core\\Log', 'Log');
return \Log::write($level, $msg, $method);
}
}
/**
* Takes an array of attributes and turns it into a string for an html tag
*
* @param array $attr
* @return string
*/
if ( ! function_exists('array_to_attr'))
{
function array_to_attr($attr)
{
$attr_str = '';
if ( ! is_array($attr))
{
$attr = (array) $attr;
}
foreach ($attr as $property => $value)
{
// Ignore null values
if (is_null($value))
{
continue;
}
// If the key is numeric then it must be something like selected="selected"
if (is_numeric($property))
{
$property = $value;
}
$attr_str .= $property.'="'.$value.'" ';
}
// We strip off the last space for return
return trim($attr_str);
}
}
/**
* Create a XHTML tag
*
* @param string The tag name
* @param array|string The tag attributes
* @param string|bool The content to place in the tag, or false for no closing tag
* @return string
*/
if ( ! function_exists('html_tag'))
{
function html_tag($tag, $attr = array(), $content = false)
{
$has_content = (bool) ($content !== false and $content !== null);
$html = '<'.$tag;
$html .= ( ! empty($attr)) ? ' '.(is_array($attr) ? array_to_attr($attr) : $attr) : '';
$html .= $has_content ? '>' : ' />';
$html .= $has_content ? $content.'</'.$tag.'>' : '';
return $html;
}
}
/**
* A case-insensitive version of in_array.
*
* @param mixed $needle
* @param array $haystack
* @return bool
*/
if ( ! function_exists('in_arrayi'))
{
function in_arrayi($needle, $haystack)
{
return in_array(strtolower($needle), array_map('strtolower', $haystack));
}
}
/**
* Renders a view and returns the output.
*
* @param string The view name/path
* @param array The data for the view
* @return string
*/
if ( ! function_exists('render'))
{
function render($view, $data = array())
{
return \View::forge($view, $data)->render();
}
}
/**
* A wrapper function for Lang::get()
*
* @param mixed The string to translate
* @param array The parameters
* @return string
*/
if ( ! function_exists('__'))
{
function __($string, $params = array(), $default = null)
{
return \Lang::get($string, $params, $default);
}
}
/**
* Encodes the given string. This is just a wrapper function for Security::htmlentities()
*
* @param mixed The string to encode
* @return string
*/
if ( ! function_exists('e'))
{
function e($string)
{
return Security::htmlentities($string);
}
}
/**
* Takes a classname and returns the actual classname for an alias or just the classname
* if it's a normal class.
*
* @param string classname to check
* @return string real classname
*/
if ( ! function_exists('get_real_class'))
{
function get_real_class($class)
{
static $classes = array();
if ( ! array_key_exists($class, $classes))
{
$reflect = new ReflectionClass($class);
$classes[$class] = $reflect->getName();
}
return $classes[$class];
}
}