-
Notifications
You must be signed in to change notification settings - Fork 2
/
core.php
101 lines (79 loc) · 1.86 KB
/
core.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
<?php
$weepy_actions = array();
$weepy_filters = array();
function clean_uri($uri) {
$result = preg_replace('/\/$/', '', $uri);
$result = preg_replace('/\?.*$/', '', $result);
return $result;
}
function get_header() {
require_once('./header.php');
}
function get_footer() {
require_once('./footer.php');
}
function wp_head() {
do_action('wp_head');
}
function wp_footer() {
do_action('wp_footer');
}
function add_action($tag, $fn) {
global $weepy_actions;
if (!array_key_exists($tag, $weepy_actions)) {
$weepy_actions[$tag] = array();
}
$weepy_actions[$tag][] = $fn;
}
function do_action($tag, $arg = '') {
global $weepy_actions;
if (!array_key_exists($tag, $weepy_actions)) {
return false;
}
$funcs = $weepy_actions[$tag];
if (!empty($funcs)) {
foreach ($funcs as $func) {
call_user_func($func, $arg);
}
}
}
function add_filter($tag, $fn) {
global $weepy_filters;
if (!array_key_exists($tag, $weepy_filters)) {
$weepy_filters[$tag] = array();
}
$weepy_filters[$tag][] = $fn;
}
function apply_filters($tag, $default) {
global $weepy_filters;
if (!array_key_exists($tag, $weepy_filters)) {
return $default;
}
$funcs = $weepy_filters[$tag];
$result = $default;
if (!empty($funcs)) {
foreach ($funcs as $func) {
$result = call_user_func($func, $result);
}
}
return $result;
}
function body_class() {
$uri = clean_uri($_SERVER['REQUEST_URI']);
$parts = preg_split('/\//', $uri);
//pp($parts,'parts');
$parts = apply_filters('body_class', $parts);
if (empty($parts)) {
return false;
}
$class_str = trim(join(' ', $parts));
//pp($class_str,'class_str');
echo sprintf('class="%s"', $class_str);
}
function header_error($code, $msg = 'Unspecified error') {
header("HTTP/1.0 $code $msg");
die($msg);
}
function error_404() {
header_error(404, 'Not found');
}