-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
67 lines (56 loc) · 1.38 KB
/
functions.php
File metadata and controls
67 lines (56 loc) · 1.38 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
<?php if (!defined('ROOT')) die('ROOT const not set.');
// functions.php
load_module('module'); // load the general abstract module implementation
bootstrap(); // perform the initial file checking
$dependencies = array(
'MongoClient'
);
function bootstrap() {
check_functions($GLOBALS['dependencies']);
}
/**
* check if the functions in the param exist
* if they do not exists - the module is not installed, so die
* serves as basic dependency checking
*/
function check_functions($functions, $die_on_error = true) {
foreach ($functions as $f) {
if (!function_exists($f)) {
if (class_exists($f)) {
continue;
}
msg('check_functions() Error: function '.$f.' does not exist. '.
'Install the related php module first!');
if ($die_on_error) {
exit;
}
}
}
}
function msg($message, $level = 0) {
echo $message."\n";
}
/**
* load module from the modules directory
*/
function load_module($module) {
$candidate = ROOT.'/modules/'.$module.'/'.$module.'.php';
if (!file_exists($candidate)) {
msg('Module '.$module.' does not exist!');
return;
}
require_once $candidate;
}
/**
* get the mongo database. Mongo is the main database storage.
*/
function get_mongo($db = null, $collection = null) {
$m = new MongoClient();
if ($db && $collection) {
return $m->{$db}->{$collection};
} else if (!$collection) {
return $m->{$db};
} else {
return $m;
}
}