-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresources.php
More file actions
136 lines (110 loc) · 3.43 KB
/
resources.php
File metadata and controls
136 lines (110 loc) · 3.43 KB
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
<?php
// Set default timezone
date_default_timezone_set('America/New_York');
// Set domain
$domain = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
// Create DB object
$db = new mysqli($db['host'], $db['user'], $db['password'], $db['name']);
// Create unique paste ID
function createPasteID() {
global $db;
do {
$repeat = false;
$id = generateRandomString(8);
$check = $db->query("SELECT id FROM blogs WHERE id = '$id'");
if($check->num_rows != 0) {
$repeat = true;
}
else {
return $id;
}
} while($repeat = true);
}
function console_log($output, $with_script_tags = true) {
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
// Create random string
function some_function($string){
$done = substr($string,0,100);
return $done;
}
function generateRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
// Check string to see if contains flag words
function checkForFlags($str) {
global $site;
$isFlagged = false;
$flaggedWord = null;
$str = strtolower($str);
foreach($site['flagWords'] as $word) {
if(stripos($str, $word) !== false) {
$isFlagged = true;
$flaggedWord = $word;
}
}
return [$isFlagged, $flaggedWord];
}
// API function
function apiRequest($url, $post=FALSE, $headers=array()) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
if($post)
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$headers[] = 'Accept: application/json';
if(session('access_token'))
$headers[] = 'Authorization: Bearer ' . session('access_token');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
return json_decode($response);
}
// Get function
function get($key, $default=NULL) {
return array_key_exists($key, $_GET) ? $_GET[$key] : $default;
}
// Session function
function session($key, $default=NULL) {
return array_key_exists($key, $_SESSION) ? $_SESSION[$key] : $default;
}
function sendEmbed($title, $url, $fields) {
global $site;
$timestamp = date("c", strtotime("now"));
$json = json_encode([
"username" => "Paste Now",
"embeds" => [
[
"title" => $title,
"type" => "rich",
"url" => $url,
"timestamp" => $timestamp,
"footer" => [
"icon_url" => $site['logo'],
],
"fields" => $fields,
],
],
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
$ch = curl_init($site['webhook']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?>