-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.php
More file actions
108 lines (86 loc) · 2.08 KB
/
function.php
File metadata and controls
108 lines (86 loc) · 2.08 KB
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
<?php
/**
* require file.
* example:
* import( 'core.data.member' );
*/
function import ($FilePath) {
$FilePath = str_replace('.', '/', $FilePath) . '.php';
if ( file_exists( MODULE_DIR . "/{$FilePath}" ) ) {
require_once MODULE_DIR . "/{$FilePath}";
}
elseif( file_exists( SYS . "/module/{$FilePath}" ) ) {
require_once SYS . "/module/{$FilePath}";
}
else {
return false;
throw new YPiException( "not found file:'{$FilePath}.php'" );
}
}
//Check the POST submit mode
function isPost () {
return (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')? TRUE : FALSE;
}
//Check the AJAX submit mode
function isAjax () {
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) {
if('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])){
return true;
}
}
return false;
}
//Create a directory. Support the creation of multi-level directory.
function makedir ( $path, $permissions = 0777 ) {
$result = array();
while( $path != dirname( $path) ) {
array_push( $result, $path );
$path = dirname( $path );
}
sort( $result );
foreach( $result as $directory ) {
if ( !file_exists( $directory ) ) mkdir( $directory, $permissions );
if ( !file_exists( $directory ) ) return false;
}
return true;
}
function def (&$value, $default='') {
if ( !isset($value) || is_null($value) ) {
return $default;
}
else {
$value;
}
}
function dump() {
$params = func_get_args();
$output = array();
foreach($params as $item) {
array_push($output, htmlspecialchars(print_r($item, true)));
}
echo '<pre>', implode("\n", $output), '</pre>';
}
function trims( $variable ) {
if(is_array($variable)) {
return array_map( "trims", $variable );
}
elseif ( is_null( $variable ) ) {
return null;
}
else {
return trim( $variable );
}
}
//View rendering controller
function Render( $controller, $action=null ) {
$route = route::instance( $controller, $action );
$route->render();
}
function & LoadModule ( $module ) {
$result = YPi::loadModule( $module );
return $result;
}
function _T( $string, $dict='default' ) {
$word = Lang::text( $string, $dict );
return $word;
}