-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
153 lines (123 loc) · 5.94 KB
/
Copy pathindex.php
File metadata and controls
153 lines (123 loc) · 5.94 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
// Include utility functions
require '_funcs.php';
// Include the script elements
require '_scripts.php';
// Phrase indices
$imageIndex = rand(1, 7);
$titleIndex = 0;
$leadInIndex = 0;
$jobIndex = 0;
$nameIndex = 0;
$storyIndex = 0;
$motivationIndex = 0;
$leadOutIndex = 0;
// Is the user asking for a particular combination?
$urlChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$urlCharsArray = str_split($urlChars);
$existing = false;
if (preg_match('#^/([a-zA-Z]{7})$#', $_SERVER['REQUEST_URI'], $params)) {
// Looks like we got a match...
$id = $params[1];
$titleIndex = array_search($id[0], $urlCharsArray);
$leadInIndex = array_search($id[1], $urlCharsArray);
$jobIndex = array_search($id[2], $urlCharsArray);
$nameIndex = array_search($id[3], $urlCharsArray);
$storyIndex = array_search($id[4], $urlCharsArray);
$motivationIndex = array_search($id[5], $urlCharsArray);
$leadOutIndex = array_search($id[6], $urlCharsArray);
$existing = $titleIndex < count($titles) &&
$leadInIndex < count($leadIns) &&
$jobIndex < count($jobs) &&
$nameIndex < count($names) &&
$storyIndex < count($stories) &&
$motivationIndex < count($motivations) &&
$leadOutIndex < count($leadOuts);
}
if (!$existing) {
// Pick 'em at random
$titleIndex = rand(0, count($titles)-1);
$leadInIndex = rand(0, count($leadIns)-1);
$jobIndex = rand(0, count($jobs)-1);
$nameIndex = rand(0, count($names)-1);
$storyIndex = rand(0, count($stories)-1);
$motivationIndex = rand(0, count($motivations)-1);
$leadOutIndex = rand(0, count($leadOuts)-1);
}
// Additional variable grammar...
$noName = empty($names[$nameIndex]);
$needsAnA = $noName && (startsWith($names[$nameIndex], 'A ') || startsWith($names[$nameIndex], 'Once') || startsWith($names[$nameIndex], 'Famous'));
// Build the full "script"
$movieTitle = getString($titles, $titleIndex);
$moviePlot = ($needsAnA) ? 'A ' : '';
$moviePlot .= getString($leadIns, $leadInIndex, $needsAnA) . ' ';
$moviePlot .= getString($jobs, $jobIndex) . ' ';
$moviePlot .= getString($names, $nameIndex) . ' ';
$moviePlot .= getString($stories, $storyIndex) . ' ';
$moviePlot .= getString($motivations, $motivationIndex) . ' ';
$moviePlot .= getString($leadOuts, $leadOutIndex);
// Generate the URL for this film
$uniqueUrl = '';
$uniqueUrl .= $urlChars[$titleIndex];
$uniqueUrl .= $urlChars[$leadInIndex];
$uniqueUrl .= $urlChars[$jobIndex];
$uniqueUrl .= $urlChars[$nameIndex];
$uniqueUrl .= $urlChars[$storyIndex];
$uniqueUrl .= $urlChars[$motivationIndex];
$uniqueUrl .= $urlChars[$leadOutIndex];
// Share message for Twitter
$shareMessage = 'Jason Statham stars in ' . strtoupper($movieTitle) . ': ' . truncateString($moviePlot, 65, true) . ' http://' . $_SERVER['HTTP_HOST'] . '/' . $uniqueUrl . ' #stathamator';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" content="Daniel G Wood" />
<meta name="copyright" content="©2017 Daniel G Wood" />
<meta name="description" content="<?php echo $moviePlot; ?>">
<meta property="og:title" content="<?php echo $movieTitle; ?> - The Stathamator">
<meta property="og:description" content="<?php echo $moviePlot; ?>">
<meta itemprop="name" content="<?php echo $movieTitle; ?> - The Stathamator">
<meta itemprop="description" content="<?php echo $moviePlot; ?>">
<meta property="og:email" content="daniel.g.wood@gmail.com" />
<meta property="og:type" content="website" />
<meta property="og:image" content="assets/statham<?php echo $imageIndex; ?>.jpg" />
<meta property="og:site_name" content="stathamator.com" />
<meta property="fb:admins" content="512686422" />
<meta itemprop="image" content="assets/statham<?php echo $imageIndex; ?>.jpg" />
<title><?php echo $movieTitle; ?> - The Stathamator</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inconsolata|Share:700">
<link rel="stylesheet" href="assets/all.css" />
<link rel="shortcut icon" href="assets/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" href="assets/apple-touch-icon.png" />
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-435VM9ES2B"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-435VM9ES2B');
</script>
</head>
<body>
<header>
<h1>The Stathamator</h1>
</header>
<section>
<img class="stathe" src="assets/statham<?php echo $imageIndex; ?>.jpg" alt="Jason Statham" />
<span class="starring">Jason Statham stars in</span>
<h2><?php echo $movieTitle; ?></h2>
<p><?php echo $moviePlot; ?></p>
</section>
<nav>
<a class="button" href="/" title="Make another film"><img src="assets/refresh.png" alt="" /></a>
<a class="button" href="https://twitter.com/intent/tweet?text=<?php echo urlencode($shareMessage); ?>" target="_blank" title="Tweet this!"><img src="assets/twitter.png" alt="" /></a>
<a class="button" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . '/' . $uniqueUrl); ?>" target="_blank" title="Share on Facebook"><img src="assets/facebook.png" alt="" /></a>
</nav>
<footer>
<small>Made by <a href="https://twitter.com/danielgwood">@danielgwood</a> whilst watching <em>a lot</em> of Statham films. Icons by <a rel="nofollow" href="http://simpleicon.com/" target="_blank">SimpleIcon</a> (CC BY 3.0).</small>
</footer>
<!-- JS -->
<script> history.replaceState(null, null, '<?php echo $uniqueUrl; ?>'); </script>
</body>
</html>