-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.php
54 lines (50 loc) · 1.6 KB
/
utils.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
<?php
/**
* @return the value at $index in $array or $default if $index is not set.
*/
function idx(array $array, $key, $default = null) {
return array_key_exists($key, $array) ? $array[$key] : $default;
}
function he ($str) {
return htmlentities($str, ENT_QUOTES, 'UTF-8');
}
function fullUrl ($page, $encode = false) {
$https = ($_SERVER['HTTPS']) ? 'https' : 'http';
$ret = "$https://{$_SERVER['HTTP_HOST']}/$page";
return ($encode) ? $encode($ret) : $ret;
}
function getFacebookAppToken () {
$url = 'https://graph.facebook.com/oauth/access_token?'.
'client_id=' . getenv('FACEBOOK_APP_ID') .
'&client_secret=' . getenv('FACEBOOK_SECRET') .
'&grant_type=client_credentials';
$res = file_get_contents($url);
list(, $token) = explode('=', $res);
return $token;
}
function getFlashMessage ($output = 'html', $before = '<li>', $after = '</li>') {
global $pgps_flashmsg;
if (count($pgps_flashmsg)) {
$out = '';
foreach ($pgps_flashmsg as $msg) {
switch ($output) {
case 'HTML':
case 'html':
$out .= '<ul>';
$out .= $before . he($msg) . $after;
$out .= '</ul>';
default:
break;
}
}
return $out;
}
}
// Backwards compatibility to PHP 5.3, such as default Heroku buildpack.
function my_pg_escape_identifier ($str) {
if (function_exists('pg_escape_identifier')) {
return pg_escape_identifier($str);
} else {
return "\"$str\""; // Just quote it.
}
}