-
Notifications
You must be signed in to change notification settings - Fork 0
/
bobbnotwp.inc_
264 lines (218 loc) · 6.34 KB
/
bobbnotwp.inc_
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php // (C) Copyright 2011-2023 Bobbing Wide
/**
* Functions for a system which is NOT WordPress
*
* It could be Drupal or some other PHP based CMS, perhaps not even a CMS
*/
/**
* Get the value for an option field
*
* I need to decide if I should prefix each field with bw_
* Decision: I didn't prefix the fields in Drupal settings
*
*/
if ( !function_exists( "bw_get_option" ) ) {
function bw_get_option( $field ) {
if ( function_exists( "variable_get" ) ) {
$value = variable_get( $field, "" );
} else {
$value = bw_array_get( $GLOBALS, $field, null );
}
return( $value );
}
}
/**
* Dummy implementation of add_filter() so that shortcodes.php can be copied unchanged from WordPress.
*/
if ( !function_exists( "add_filter" ) ) {
function add_filter() {
// Dummy implementation of add_filter() so that shortcodes.php can be copied unchanged from WordPress.
}
}
/**
* Dummy implementation of add_action for non WordPress sites
*/
if ( !function_exists( "add_action" ) ) {
function add_action( $tag, $function_to_add, $priority=NULL, $accepted_args=NULL ) {
// e.g. add_action( admin_init', array($this, 'bw_pp_admin_init'));
}
}
/**
* Dummy implementation of apply_filters() so that shortcodes.php can be copied unchanged from WordPress.
*/
if ( !function_exists( "apply_filters" ) ) {
function apply_filters( $filter, $value ) {
return $value;
}
}
/**
* Dummy implementation of get_translations_for_domain for non WordPress sites
*/
if ( !function_exists( "get_translations_for_domain" ) ) {
function get_translations_for_domain( $domain ) {
return( new NOOP_Translations );
}
if ( !class_exists( 'NOOP_Translations' ) ):
/**
* Provides the same interface as Translations, but doesn't do anything
*/
class NOOP_Translations {
var $entries = array();
var $headers = array();
function add_entry($entry) {
return true;
}
function set_header($header, $value) {
}
function set_headers($headers) {
}
function get_header($header) {
return false;
}
function translate_entry(&$entry) {
return false;
}
function translate($singular, $context=null) {
return $singular;
}
function select_plural_form($count) {
return 1 == $count? 0 : 1;
}
function get_plural_forms_count() {
return 2;
}
function translate_plural($singular, $plural, $count, $context = null) {
return 1 == $count? $singular : $plural;
}
function merge_with(&$other) {
}
}
endif;
}
if ( !function_exists( "wp_strip_all_tags" ) ) {
function wp_strip_all_tags( $text ) { return( $text ); }
}
if ( !function_exists( "esc_attr" ) ) {
function esc_attr( $text ) { return( $text ); }
}
if ( !function_exists( "esc_url" ) ) {
function esc_url( $url ) { return $url; }
}
/**
* Drupal implementation of site_url using the 'domain' variable
* This is to allow for local implementations e.g. qw/contacts
*/
function site_url( $path=NULL, $scheme='http:' ) {
$url = $scheme;
$url .= '//';
$url .= bw_get_option( 'domain' );
$url .= $path;
return( $url );
}
//echo "here" . PHP_EOL;
if ( bw_is_drupal() ) {
require_once( "shortcodes.php" ); // This is a copy of the WordPress include specifically for the Drupal version of oik.
}
if ( !function_exists( "_doing_it_wrong" ) ) {
function _doing_it_wrong( $function, $message, $version ){
trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
}
}
if ( !function_exists( "_deprecated_function" ) ) {
function _deprecated_function( $function, $version, $replacement=null ) {
print_r( debug_backtrace() );
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
die();
}
}
if ( !function_exists( "__" ) ) {
function __( $text, $textdomain=null ) {
return $text;
}
}
if ( !function_exists( "is_textdomain_loaded" ) ) {
function is_textdomain_loaded( $domain ) {
return false;
}
}
/**
* Recursive directory creation based on full path.
*
* Will attempt to set permissions on folders.
*
* @since 2.0.1
*
* @param string $target Full path to attempt to create.
* @return bool Whether the path was created. True if path already exists.
*/
function wp_mkdir_p( $target ) {
$wrapper = null;
// Strip the protocol.
if ( wp_is_stream( $target ) ) {
list( $wrapper, $target ) = explode( '://', $target, 2 );
}
// From php.net/mkdir user contributed notes.
$target = str_replace( '//', '/', $target );
// Put the wrapper back on the target.
if ( null !== $wrapper ) {
$target = $wrapper . '://' . $target;
}
/*
* Safe mode fails with a trailing slash under certain PHP versions.
* Use rtrim() instead of untrailingslashit to avoid formatting.php dependency.
*/
$target = rtrim( $target, '/' );
if ( empty( $target ) ) {
$target = '/';
}
if ( file_exists( $target ) ) {
return @is_dir( $target );
}
// Do not allow path traversals.
if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
return false;
}
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' !== $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {
$target_parent = dirname( $target_parent );
}
// Get the permission bits.
$stat = @stat( $target_parent );
if ( $stat ) {
$dir_perms = $stat['mode'] & 0007777;
} else {
$dir_perms = 0777;
}
if ( @mkdir( $target, $dir_perms, true ) ) {
/*
* If a umask is set that modifies $dir_perms, we'll have to re-set
* the $dir_perms correctly with chmod()
*/
if ( ( $dir_perms & ~umask() ) != $dir_perms ) {
$folder_parts = explode( '/', substr( $target, strlen( $target_parent ) + 1 ) );
for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
chmod( $target_parent . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
}
}
return true;
}
return false;
}
/**
* Tests if a given path is a stream URL
*
* @since 3.5.0
*
* @param string $path The resource path or URL.
* @return bool True if the path is a stream URL.
*/
function wp_is_stream( $path ) {
$scheme_separator = strpos( $path, '://' );
if ( false === $scheme_separator ) {
// $path isn't a stream.
return false;
}
$stream = substr( $path, 0, $scheme_separator );
return in_array( $stream, stream_get_wrappers(), true );
}