blob: ab04b11461ecd7d0aabcbfc31e1486b367bdd8fb (
plain)
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
|
<?php
/**
* Miscellaneous useful functions
*/
class Misc{
/**
* Retrieve value from array by key, with default value support.
*
* @param array $array Input array
* @param string $key Key to retrieve from the array
* @param mixed $default Default value to return if the key is not found
* @return mixed An array value if it was found or default value if it is not
* @access public
* @static
*/
public static function arr($array,$key,$default=null){
if (isset($array[$key]))
return $array[$key];
return $default;
}
/**
* Find full path to either a class or view by name.
* It will search in the /system folder first, then the /application folder
* and then in all enabled modules.
*
* @param string $type Type of the file to find. Either 'class' or 'view'
* @param string $name Name of the file to find
* @return boolean Return Full path to the file or False if it is not found
* @access public
* @static
*/
public static function find_file($type, $name) {
$folders = array(SYSDIR, APPDIR);
foreach(Config::get('modules') as $module)
$folders[] = MODDIR.$module.'/';
if($type=='class'){
$subfolder = 'classes/';
$dirs = array_reverse(explode('_', strtolower($name)));
$fname = array_pop($dirs);
$subfolder.=implode('/',$dirs).'/';
}
if ($type == 'view') {
$subfolder = 'views/';
$fname=$name;
}
foreach($folders as $folder) {
$file = $folder.$subfolder.$fname.'.php';
if (file_exists($file)) {
return($file);
}
}
return false;
}
}
|