-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaderHelper.php
More file actions
79 lines (78 loc) · 2.62 KB
/
headerHelper.php
File metadata and controls
79 lines (78 loc) · 2.62 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
<?php
/**
* @author Jeremic Nemanja nemanja@joker.rs
* @license GNU
* @version 0.0.9
*/
/**
* @param string|NULL $title
* @param string|NULL $description
* @param string|NULL $keywords
* @param string|NULL $type
* @param string|NULL $image
* @param string|NULL $url
* @param string|NULL $robots
* @param array|NULL $css
* @return string
*/
function headerHelper(
?string $title = null,
?string $description = null,
?string $keywords = null,
?string $type = null,
?string $image = null,
?string $url = null,
?string $robots = null,
?array $css = null
): ?string
{
$return = null;
if (isset($title)) {
$return .= "<meta name=\"title\" content=\"$title\">\n";
$return .= "<meta property=\"og:title\" content=\"$title\">\n";
$return .= "<meta itemprop=\"name\" content=\"$title\">\n";
$return .= "<meta name=\"twitter:title\" content=\"$title\">\n";
}
if (isset($description)) {
$return .= "<meta name=\"description\" content=\"$description\">\n";
$return .= "<meta itemprop=\"description\" content=\"$description\">\n";
$return .= "<meta property=\"og:description\" content=\"$description\">\n";
$return .= "<meta name=\"twitter:description\" content=\"$description\">\n";
}
if (isset($keywords)) {
$return .= "<meta name=\"keywords\" content=\"$keywords\">\n";
$return .= "<meta property=\"og:keywords\" content=\"$keywords\">\n";
}
if (isset($type)) {
$return .= "<meta property=\"og:type\" content=\"$type\">\n";
}
if (isset($image)) {
$return .= "<meta property=\"og:image\" content=\"$image\">\n";
$return .= "<meta property=\"image\" content=\"$image\">\n";
$return .= "<meta property=\"twitter:image\" content=\"$image\">\n";
}
if ($url === null) {
$url .= $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'];
}
if ($_SERVER['REQUEST_URI'] !== '/') {
$url .= $_SERVER['REQUEST_URI'];
} else {
$url .= DIRECTORY_SEPARATOR;
}
$return .= "<meta property=\"og:url\" content=\"$url\">\n";
$return .= "<meta name=\"twitter:url\" content=\"$url\">\n";
$return .= "<meta name=\"twitter:card\" content=\"summary\">\n";
if (isset($robots)) {
$return .= "<meta name=\"robots\" content=\"$robots\">\n";
}
if (!isset($title)) {
$title = $url;
}
$return .= "<title>$title</title>\n";
if (isset($css) && is_array($css)) {
foreach ($css as $css_url) {
$return .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"$css_url\">\n";
}
}
return $return;
}