forked from delipress/delipress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelipress_helpers.php
134 lines (110 loc) · 3.73 KB
/
delipress_helpers.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
<?php
defined( 'ABSPATH' ) or die( 'Cheatin’ uh?' );
function delipress_is_local(){
$host = null;
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$host = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else if(isset($_SERVER["REMOTE_ADDR"])){
$host = $_SERVER["REMOTE_ADDR"];
}
if($host === null){
return;
}
if(isset($_SERVER["REMOTE_USER"])){
return true;
}
return ( substr($host,0,8) == "192.168." || substr($host,0,6) == "127.0." || substr($host,0,4) == "172." || $host == "::1");
}
function delipress_full_url( $s )
{
$ssl = ( ! empty( $s['HTTPS'] ) && $s['HTTPS'] == 'on' );
$sp = strtolower( $s['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
$port = (isset($s['SERVER_PORT']) ) ? $s['SERVER_PORT'] : "";
$port = ( ( ! $ssl && $port=='80' ) || ( $ssl && $port=='443' ) ) ? '' : ':'.$port;
$host = ( isset( $s['HTTP_HOST'] ) ) ? $s['HTTP_HOST'] : null ;
$host = isset( $host ) ? $host : $s['SERVER_NAME'] . $port;
return $protocol . '://' . $host . $s['REQUEST_URI'];
}
/**
* Get size information for all currently-registered image sizes.
*
* @global $_wp_additional_image_sizes
* @uses get_intermediate_image_sizes()
* @return array $sizes Data for all currently-registered image sizes.
*/
function delipress_get_image_sizes_thumbnail_id($thumbnailId) {
global $_wp_additional_image_sizes;
$sizes = array();
$intermediates = get_intermediate_image_sizes();
foreach ( $intermediates as $_size ) {
$srcImage = wp_get_attachment_image_src($thumbnailId, $_size);
if ( in_array( $_size, array('thumbnail', 'medium', 'medium_large', 'large') ) ) {
$sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" );
$sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" );
$sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" );
$sizes[ $_size ]['url'] = $srcImage[0];
} elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
$sizes[ $_size ] = array(
'width' => $_wp_additional_image_sizes[ $_size ]['width'],
'height' => $_wp_additional_image_sizes[ $_size ]['height'],
'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
'url' => $srcImage[0],
);
}
}
$srcImage = wp_get_attachment_image_src($thumbnailId, "full");
$sizes["full"] = array(
'width' => $srcImage[1],
'height' => $srcImage[2],
'crop' => false,
'url' => $srcImage[0],
);
return $sizes;
}
function delipress_js_str($s)
{
return '"' . addcslashes($s, "\0..\37\"\\") . '"';
}
function delipress_js_array($array)
{
$temp = array_map('delipress_js_str', $array);
return '[' . implode(',', $temp) . ']';
}
function delipress_get_url_premium(){
$locale = get_locale();
switch($locale){
case "fr_FR":
return "https://delipress.io/fr/tarifs/";
default:
return "https://delipress.io/pricing";
}
}
function delipress_get_documentation_url(){
$locale = get_locale();
switch($locale){
case "fr_FR":
return "http://delipress.io/fr/documentation/accueil";
default:
return "http://delipress.io/documentation/home";
}
}
function delipress_array_flatten(array $array)
{
$flat = array(); // initialize return array
$stack = array_values($array); // initialize stack
while($stack) // process stack until done
{
$value = array_shift($stack);
if (is_array($value)) // a value to further process
{
$stack = array_merge(array_values($value), $stack);
}
else // a value to take
{
$flat[] = $value;
}
}
return $flat;
}