-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
89 lines (80 loc) · 2.18 KB
/
Copy pathindex.php
File metadata and controls
89 lines (80 loc) · 2.18 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='http://fonts.googleapis.com/css?family=Nunito' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<style>
iframe {
width:100%;
height:500px;
overflow:hidden;
}
</style>
</head>
<body>
<div class="container">
<img id="logo" src="img/stirling_dojo.jpg" alt="Stirling CoderDojo Logo">
<h1>Stirling CoderDojo Meme Showcase</h1>
<hr/>
<?php
define('MEMES_DIR', 'memes');
define('MEMES_PER_ROW', 2);
define('BOOTSTRAP_SPAN_CLASS', "col-md-".(12/MEMES_PER_ROW));
function memeTitle($memeFile) {
$fp = file_get_contents($memeFile);
if (!$fp)
return $memeFile;
$res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
if (!$res)
{
return $url;
}
else
{
return $title_matches[1];
}
}
$memeFiles = array();
if ($handle = opendir('memes')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && strtolower(substr($file, strrpos($file, '.') + 1)) == 'html')
{
array_push($memeFiles, MEMES_DIR.'/'.$file);
}
}
closedir($handle);
if (count($memeFiles) > 0)
{
$chunkedMemeFiles = array_chunk($memeFiles, MEMES_PER_ROW);
foreach ($chunkedMemeFiles as $memeFilesChunk)
{
echo '<div class="row">';
foreach ($memeFilesChunk as $memeFile)
{
echo '<div class="'.BOOTSTRAP_SPAN_CLASS.'">
<h2><a href="'.$memeFile.'">'.memeTitle($memeFile).'</a></h2>
<iframe scrolling="no" src="'.$memeFile.'"></iframe>
</div>';
}
echo '</div>';
}
}
else
{
echo "<p>Uh oh! No memes found.</p>";
}
}
?>
<div class="push"></div>
</div> <!-- end container -->
<footer>
Made at
<a href="http://coderdojoscotland.com/clubs/stirling">Stirling CoderDojo</a>,
<a href="http://coderdojoscotland.com/">CoderDojo Scotland</a>
</footer>
</body>
</html>