-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.php
executable file
·138 lines (105 loc) · 4.4 KB
/
helper.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
function _die () {
die (
array_rand ( array(
'Eris is pleased to see your efford to cause discord!',
'Only a Pope is allowed to do this!',
'Don\'t tell anybody about the frogs!',
'Out of order!',
'No Exit!',
'Hail Eris!\nAll Hail Discordia!',
'Καλλιστι!',
'ALL RITES REVERSED Ⓚ REPRINT WHAT YOU LIKE!'
) )
);
}
if (! function_exists('get_class_name')) {
function get_class_name ($class) {
if (is_object($class))
$class = get_class($class);
if (! is_string($class))
return false;
$components = explode('\\', $class);
return $components[count($components) - 1];
}
}
function _ping ($amount = 1){
if (WP_DEBUG === false)
return;
$backtrace = debug_backtrace();
$backtrace_size = sizeof($backtrace);
$i_end = $amount == 0 ? $backtrace_size : min($backtrace_size, $amount + 1);
for ($i = 1; $i < $i_end; $i++) {
$parent_scope = (object)$backtrace[$i];
$parent_scope->class = isset($parent_scope->class) ? $parent_scope->class : '';
$parent_scope->function = isset($parent_scope->function) ? $parent_scope->function : '';
$parent_scope->line = isset($parent_scope->line) ? $parent_scope->line : '';
$parent_scope->file = isset($parent_scope->file) ? $parent_scope->file : '';
$msg = "$parent_scope->class::$parent_scope->function ($parent_scope->line -> $parent_scope->file)";
_log($msg);
}
}
function _log ($var){
if (WP_DEBUG === true){
if (is_array($var) || is_object($var)){
error_log(print_r($var, true));
} else {
error_log($var);
}
}
}
function _var_dump (&$var) {
echo "<pre>";
var_dump($var);
echo "</pre><br/>";
}
function _compile($file) {
ob_start();
require $file;
return ob_get_clean();
}
function normalizeString ($string) {
$string = trim($string);
$string = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string);
$string = preg_replace('/[^A-Za-z0-9 -]+/', "", $string);
$string = preg_replace('/[^\w-]+/', "-", $string);
$string = strToLower($string);
return $string;
}
function startsWith ($haystack, $needle) {
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function contains ($haystack, $needle) {
return strstr(haystack, $needle);
}
function endsWith ($haystack, $needle) {
$length = strlen($needle);
$start = $length * -1;
return (substr($haystack, $start) === $needle);
}
function loadScriptsInPathWithIDPrefix ($path, $id_prefix) {
$filenames = glob("$path/*.js");
foreach ($filenames as $filename) {
$js_name = preg_replace("/\/?[^\/]+\/|\.js/", "", $filename);
$js_name_dependecies = explode(".", $js_name);
array_pop($js_name_dependecies);
$url = site_url(str_replace(WP_CONTENT_DIR, "wp-content", "$path/$js_name.js") );
wp_enqueue_script("$id_prefix-$js_name", $url );
}
}
function loadStylesInPathWithIDPrefix ($path, $id_prefix) {
$filenames = glob("$path/*.css");
if (file_exists("$path/reset.css")) wp_enqueue_style("$id_prefix-reset", site_url( str_replace(WP_CONTENT_DIR, "wp-content", "$path/reset.css") ), array(), false, false );
// if (file_exists("$path/grid.css")) wp_enqueue_style("$id_prefix-grid", site_url( str_replace(WP_CONTENT_DIR, "wp-content", "$path/grid.css") ), array(), false, false );
if (file_exists("$path/layout.css")) wp_enqueue_style("$id_prefix-layout", site_url( str_replace(WP_CONTENT_DIR, "wp-content", "$path/layout.css") ), array(), false, false );
if (file_exists("$path/typography.css")) wp_enqueue_style("$id_prefix-typography", site_url( str_replace(WP_CONTENT_DIR, "wp-content", "$path/typography.css") ), array(), false, false );
foreach ($filenames as $filename) {
$css_name = preg_replace("/\/?[^\/]+\/|\.css/", "", $filename);
if ($css_name == "grid" || $css_name == "reset" || $css_name == "layout" || $css_name == "typography")
continue;
$url = site_url( str_replace(WP_CONTENT_DIR, "wp-content", "$path/$css_name.css") );
wp_enqueue_style("$id_prefix-$css_name", $url, array(), false, false );
}
}
?>