-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
107 lines (92 loc) · 1.79 KB
/
functions.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
<?php
/**
* Application Functions File
* Set standard things like error reporting by configuration (config/config.php) file
* Magic autoload function
*
* @author Aiden Tailor <[email protected]>
* @copyright 2011 Aiden Tailor
*/
// Error Reporting
if ($GLOBALS['CONFIG']['display_errors'])
{
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL | E_STRICT);
}
else
{
ini_set('display_errors', 0);
ini_set('error_reporting', 0);
}
/**
* PHP magic autoload function
*
* @param $strClass
* @return null
*/
function __autoload($strClass)
{
// Library
$library = 'libraries/' . $strClass . '.php';
if (file_exists($library))
{
include $library;
return;
}
// Module
foreach (scan('modules/') as $strFolder)
{
if (substr($strFolder, 0, 1) == '.')
{
continue;
}
if (file_exists('modules/' . $strFolder . '/' . $strClass . '.php'))
{
include_once('modules/' . $strFolder . '/' . $strClass . '.php');
return;
}
}
}
/**
* Quickly dump something in between HTML <pre> Tags
*
* @param $var what to dump
*/
function dump($var)
{
echo '<pre>';
var_dump($var);
echo '</pre>';
}
/**
* Scan a directory and return its files and folders as array
*
* @param string
* @return array
*/
function scan($strFolder)
{
global $arrScanCache;
// Add trailing slash
if (substr($strFolder, -1, 1) != '/')
{
$strFolder .= '/';
}
// Load from cache
if (isset($arrScanCache[$strFolder]))
{
return $arrScanCache[$strFolder];
}
$arrReturn = array();
// Scan directory
foreach (scandir($strFolder) as $strFile)
{
if ($strFile == '.' || $strFile == '..')
{
continue;
}
$arrReturn[] = $strFile;
}
$arrScanCache[$strFolder] = $arrReturn;
return $arrReturn;
}