-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getlinkinfo-v2.php
249 lines (211 loc) · 7.84 KB
/
getlinkinfo-v2.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
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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Get the URL from the query string
$url = $_GET['url'];
// Set the desired location
$location = 'US';
// Set the user agent header to simulate a normal device
$userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36';
// Set additional headers
$headers = [
"Accept-Language: en-US,en;q=0.9",
];
// Initialize the cURL session
$ch = curl_init();
// Set cURL options for retrieving the response headers
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 50); // Increase the maximum number of redirects
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
// Execute the cURL request to retrieve the response headers
$response = curl_exec($ch);
// echo '<pre>' , var_dump($response) , '</pre>';
// Check for cURL errors
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
exit;
}
// Get the content type from the response headers
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
// Close the cURL session
curl_close($ch);
// Check if the URL points to an image file based on the content type
if (strpos($contentType, 'image') !== false) {
// Create a new cURL session for fetching the image data
$ch = curl_init();
// Set cURL options for fetching the image data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 50); // Increase the maximum number of redirects
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $url);
// Execute the cURL request to fetch the image data
$imageData = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
exit;
}
// Close the cURL session
curl_close($ch);
// Extract the filename from the URL
$filename = basename($url);
// Use Imagick to get image details
$imagick = new Imagick();
$imagick->readImageBlob($imageData);
// Retrieve the image dimensions and size
$width = $imagick->getImageWidth();
$height = $imagick->getImageHeight();
$resolution = $width . 'x' . $height;
// Calculate the file size
$fileSize = strlen($imageData);
if ($fileSize >= 1048576) {
$fileSize = round($fileSize / 1048576, 2) . ' MB';
} elseif ($fileSize >= 1024) {
$fileSize = round($fileSize / 1024, 2) . ' KB';
} else {
$fileSize .= ' Bytes';
}
// Decode the title using html_entity_decode
$filename = html_entity_decode($filename, ENT_QUOTES | ENT_HTML5, 'UTF-8');
// Encase the image information in <linkinfo> tags
$result = "<linkinfo>{$filename} ({$resolution}) {$fileSize}</linkinfo>";
//$result .= '<img src="' . {$url} . '">';
$result .= "<br>";
$result .= '<img src="'. $url . '" style="width: 250px;">';
} else {
// Initialize the cURL session for fetching the page content
$ch = curl_init();
// Set cURL options for fetching the page content
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $url);
// Execute the cURL request to fetch the page content
$response = curl_exec($ch);
// Show the page that has been curl'd
// echo '<pre>' , var_dump($response) , '</pre>';
// Check for cURL errors
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
exit;
}
// Close the cURL session
curl_close($ch);
// Find the title using regular expressions based on the website
if (strpos($url, 'discord.gg') !== false) {
// Filter for Discord
preg_match('/<meta\s+property="og:title"\s+content="([^"]+)"\s*\/?>/i', $response, $matches);
$title = '';
if (isset($matches[1])) {
$title = html_entity_decode($matches[1], ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
} elseif (strpos($url, 'reddit.com') !== false) {
// Filter for Reddit
preg_match('/<shreddit-title[^>]*title="([^"]+)"[^>]*>/', $response, $matches);
$title = '';
if (isset($matches[1])) {
$title = html_entity_decode($matches[1], ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
} elseif (strpos($url, 'aliexpress.com') !== false) {
// Filter for Aliexpress
preg_match('/"title"\s*:\s*"([^"]+)"/', $response, $matches);
$title = '';
if (isset($matches[1])) {
$json = json_decode($matches[1], true);
if (isset($json['title'])) {
$title = $json['title'];
}
}
} else {
// Filter for other websites (with <title> or <h1> tags)
preg_match('/<title[^>]*>([^<]*)<\/title>|<h1[^>]*>([^<]*)<\/h1>/i', $response, $matches);
//echo '<pre>' , var_dump($matches) , '</pre>';
}
// Check if the $matches array has at least one non-empty match
if (isset($matches[1]) && strlen($matches[1]) > 0) {
// Decode the title using html_entity_decode
$title = html_entity_decode($matches[1], ENT_QUOTES | ENT_HTML5, 'UTF-8');
// Encase the title in <linkinfo> tags
$result = "<linkinfo>{$title}</linkinfo>";
} elseif (isset($matches[2]) && strlen($matches[2]) > 0) {
// Decode the title using html_entity_decode
$title = html_entity_decode($matches[2], ENT_QUOTES | ENT_HTML5, 'UTF-8');
// Encase the title in <linkinfo> tags
$result = "<linkinfo>{$title}</linkinfo>";
} else {
// Set a default title if no match was found
$result = "No Title Found";
}
}
// Output the result
echo '<body style="background: black;color: white; font-family: Consolas;">';
echo "<title>Website Title Grabber v2.0</title>";
echo '<prefix style="color: #8cd6d6;">Title: </prefix>';
echo $result;
echo "<br>";
echo "<br>";
echo "Brought to by Moodkiller";
echo "<br>";
echo "Ver 2.0";
echo "<br>";
echo '<img src="https://i.giphy.com/media/BOPrq7m5jYS1W/giphy.webp" style="width: 175px;">';
?>
<!DOCTYPE html>
<html>
<head>
<title>Debug Output</title>
<style>
.debug-section {
margin-bottom: 10px;
}
.debug-button {
cursor: pointer;
padding: 5px 10px;
background-color: #eaeaea;
border: 1px solid #ccc;
border-radius: 3px;
}
.debug-content {
display: none;
margin-top: 10px;
padding: 10px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 3px;
}
</style>
<script>
function toggleDebugContent() {
var debugContent = document.getElementById('debug-content');
debugContent.style.display = (debugContent.style.display === 'none') ? 'block' : 'none';
}
</script>
</head>
<body>
<div class="debug-section">
<button class="debug-button" onclick="toggleDebugContent()">Toggle Debug Output</button>
<div id="debug-content" class="debug-content">
<h4>preg_match Output:</h4>
<?php
// preg_match('/<title[^>]*>([^<]*)<\/title>|<h1[^>]*>([^<]*)<\/h1>/i', $response, $matches);
var_dump($matches);
?>
<h4>cURL Response:</h4>
<pre><?php echo htmlspecialchars($response); ?></pre>
</div>
</div>
<!-- Rest of your HTML content -->
</body>
</html>