-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsiteadd.php
113 lines (98 loc) · 3.69 KB
/
siteadd.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
<?php
$title = '';
$description = '';
$favicon = '';
$showTitleInput = false;
$showDescriptionInput = false;
$showFaviconURLInput = false;
if (isset($_POST['url'])) {
$url = $_POST['url'];
$url = rtrim($url, '/');
// Add http:// or https:// if missing
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
// Fetch the website content
$htmlContent = @file_get_contents($url);
if ($htmlContent !== false) {
preg_match("/<title>(.*?)<\/title>/i", $htmlContent, $titleMatch);
$title = $titleMatch[1] ?? '';
preg_match("/<meta name=\"description\" content=\"(.*?)\"/i", $htmlContent, $descriptionMatch);
$description = $descriptionMatch[1] ?? '';
// If meta description is not found, use og:description
if (empty($description)) {
preg_match("/<meta property=\"og:description\" content=\"(.*?)\"/i", $htmlContent, $ogDescriptionMatch);
$description = $ogDescriptionMatch[1] ?? '';
}
if (empty($description)) {
$showDescriptionInput = true;
}
$favicon = findFavicon($htmlContent, $url);
if (empty($favicon)) {
$showFaviconURLInput = true;
}
} else {
$showTitleInput = true;
$showDescriptionInput = true;
$showFaviconURLInput = true;
}
}
function findFavicon($htmlContent, $url) {
$patterns = [
'/<link[^>]*rel=["\'](?:icon|shortcut icon|apple-touch-icon)[^>]*href=["\']([^"\']+)/i',
];
foreach ($patterns as $pattern) {
preg_match($pattern, $htmlContent, $matches);
if (!empty($matches[1])) {
return (strpos($matches[1], 'http') === 0) ? $matches[1] : $url . '/' . ltrim($matches[1], '/');
}
}
return '';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Website Directory</title>
<!-- Add your CSS styling here -->
</head>
<body>
<h1>Website Directory</h1>
<form action="" method="post">
<input type="text" name="url" placeholder="Enter website URL">
<button type="submit">Search</button>
</form>
<?php if (!empty($title) || !empty($description) || !empty($favicon)) : ?>
<h2>Website Information</h2>
<?php if (!empty($title)) : ?>
<p>Title: <?php echo $title; ?></p>
<?php elseif ($showTitleInput) : ?>
<form action="" method="post">
<label for="manualTitle">Custom Title:</label>
<input type="text" id="manualTitle" name="manualTitle" placeholder="Enter custom title">
<br>
</form>
<?php endif; ?>
<?php if (!empty($description)) : ?>
<p>Description: <?php echo $description; ?></p>
<?php elseif ($showDescriptionInput) : ?>
<form action="" method="post">
<label for="manualDescription">Custom Description:</label>
<input type="text" id="manualDescription" name="manualDescription" placeholder="Enter custom description">
<br>
</form>
<?php endif; ?>
<?php if (!empty($favicon)) : ?>
<h2>Favicon</h2>
<img src="<?php echo $favicon; ?>" alt="Website Favicon" />
<?php elseif ($showFaviconURLInput) : ?>
<form action="" method="post">
<label for="manualFavicon">Custom Favicon URL:</label>
<input type="text" id="manualFavicon" name="manualFavicon" placeholder="Enter custom favicon URL">
<br>
</form>
<?php endif; ?>
<?php endif; ?>
</body>
</html>