-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
69 lines (63 loc) · 1.89 KB
/
functions.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
<?php if (!defined('DIRECTSCRIPT')) exit('No direct script access allowed');
function plural($str, $force = FALSE) {
$str = strtolower(trim($str));
$end = substr($str, -1);
if ($end == 'y') { // Y preceded by vowel => regular plural
$vowels = array('a', 'e', 'i', 'o', 'u');
$str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
} elseif ($end == 's') {
if ($force == TRUE) { $str .= 'es'; }
} else {
$str .= 's';
}
return $str;
}
function singular($str) {
$str = strtolower(trim($str));
$end = substr($str, -3);
if ($end == 'ies') {
$str = substr($str, 0, strlen($str)-3).'y';
} elseif ($end == 'ses') {
$str = substr($str, 0, strlen($str)-2);
} else {
$end = substr($str, -1);
if ($end == 's') { $str = substr($str, 0, strlen($str)-1); }
}
return $str;
}
function stripslashes_deep(&$value) {
if (is_array($value)) {
array_map('stripslashes_deep', $value);
} else {
stripslashes($value);
}
}
function curl_request($opts){
$ch = curl_init();
if ($opts['type'] == 'POST'){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $opts['params']);
} else {
$opts['url'] .= '?';
foreach ($opts['params'] as $k => $v){
$url .= $k.'='.$v.'&';
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $opts['type']);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $opts['url']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if (isset($opts['headers']) && !empty($opts['headers'])){
curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
}
if (isset($opts['httpauth']) && $opts['httpauth'] != ''){
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $opts['httpauth']);
}
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return array('response' => $response, 'info' => $info);
}
?>