1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\BlackBar; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\BlackBar\Controller; |
6
|
|
|
use GeminiLabs\BlackBar\Profiler; |
7
|
|
|
|
8
|
|
|
final class Application |
9
|
|
|
{ |
10
|
|
|
const DEBUG = 'debug'; |
11
|
|
|
const ID = 'blackbar'; |
12
|
|
|
const LANG = '/languages/'; |
13
|
|
|
|
14
|
|
|
public $errors = array(); |
15
|
|
|
public $file; |
16
|
|
|
public $profiler; |
17
|
|
|
|
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
$this->file = realpath( dirname( __DIR__ ).'/'.static::ID.'.php' ); |
21
|
|
|
$this->profiler = new Profiler; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param int $errno |
26
|
|
|
* @param string $errstr |
27
|
|
|
* @param string $errfile |
28
|
|
|
* @param int $errline |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function errorHandler( $errno, $errstr, $errfile, $errline ) |
32
|
|
|
{ |
33
|
|
|
$errorCodes = array( |
34
|
|
|
2 => 'Warning', |
35
|
|
|
8 => 'Notice', |
36
|
|
|
2048 => 'Strict', |
37
|
|
|
8192 => 'Deprecated', |
38
|
|
|
); |
39
|
|
|
$errname = array_key_exists( $errno, $errorCodes ) |
40
|
|
|
? $errorCodes[$errno] |
41
|
|
|
: 'Unknown'; |
42
|
|
|
$hash = md5( $errno.$errstr.$errfile.$errline ); |
43
|
|
|
if( array_key_exists( $hash, $this->errors )) { |
44
|
|
|
$this->errors[$hash]['count']++; |
45
|
|
|
} |
46
|
|
|
else { |
47
|
|
|
$this->errors[$hash] = array( |
48
|
|
|
"errno" => $errno, |
49
|
|
|
"message" => $errstr, |
50
|
|
|
"file" => $errfile, |
51
|
|
|
"name" => $errname, |
52
|
|
|
"line" => $errline, |
53
|
|
|
"count" => 0, |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function init() |
62
|
|
|
{ |
63
|
|
|
$controller = new Controller( $this ); |
64
|
|
|
add_action( 'admin_enqueue_scripts', array( $controller, 'enqueueAssets' )); |
65
|
|
|
add_action( 'wp_enqueue_scripts', array( $controller, 'enqueueAssets' )); |
66
|
|
|
add_action( 'plugins_loaded', array( $controller, 'registerLanguages' )); |
67
|
|
|
add_action( 'admin_footer', array( $controller, 'renderBar' )); |
68
|
|
|
add_action( 'wp_footer', array( $controller, 'renderBar' )); |
69
|
|
|
add_filter( 'admin_body_class', array( $controller, 'filterBodyClasses' )); |
70
|
|
|
add_filter( 'gform_noconflict_scripts', array( $controller, 'filterNoconflictScripts' )); |
71
|
|
|
add_filter( 'gform_noconflict_styles', array( $controller, 'filterNoconflictStyles' )); |
72
|
|
|
add_filter( 'all', array( $controller, 'initProfiler' )); |
73
|
|
|
apply_filters( 'debug', 'Profiler Started' ); |
74
|
|
|
apply_filters( 'debug', 'blackbar/profiler/noise' ); |
75
|
|
|
set_error_handler( array( $this, 'errorHandler' ), E_ALL|E_STRICT ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $file |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function path( $file = '' ) |
83
|
|
|
{ |
84
|
|
|
return plugin_dir_path( $this->file ).ltrim( trim( $file ), '/' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $view |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function render( $view, array $data = array() ) |
92
|
|
|
{ |
93
|
|
|
$file = $this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ))); |
94
|
|
|
if( !file_exists( $file ))return; |
95
|
|
|
extract( $data ); |
96
|
|
|
include $file; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $path |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function url( $path = '' ) |
104
|
|
|
{ |
105
|
|
|
return esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' )); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|