-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
67 lines (51 loc) · 1.81 KB
/
index.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
<!DOCTYPE html>
<?php
// Text files containing vim commands
define("BASIC_COMMAND_FILE", "commandFiles/basicCommands.txt");
define("MEDIUM_COMMAND_FILE", "commandFiles/mediumCommands.txt");
define("ADVANCED_COMMAND_FILE", "commandFiles/advancedCommands.txt");
// Delimiter separating commands from explanations
define("DELIMITER", "--");
?>
<html>
<head>
<meta charset utf-8 />
<link rel="stylesheet" href="teach-me-vim.css" />
<title> Teach me a vim command </title>
</head>
<body>
<h1 id="mainTitle">Teach me a vim command</h1>
<form method="post" id="mainButtons">
<input class="centralButtons" type="submit" name="basicButton" value="ROOKIE"/>
<input class="centralButtons" type="submit" name="mediumButton" value="AVERAGE"/>
<input class="centralButtons" type="submit" name="advancedButton" value="SPECIALIST"/>
</form>
<p id="commandToDisplay">
<?php
function getRandomLine($filename)
{
$lines = file($filename);
return $lines[array_rand($lines)];
}
function getRandomLineParsed($filename)
{
return str_replace(DELIMITER, '<br />', getRandomLine($filename));
}
$vimCmd = "";
if(isset($_POST['basicButton']))
{
$vimCmd = (string) getRandomLineParsed(BASIC_COMMAND_FILE);
}
elseif(isset($_POST['mediumButton']))
{
$vimCmd = (string) getRandomLineParsed(MEDIUM_COMMAND_FILE);
}
elseif(isset($_POST['advancedButton']))
{
$vimCmd = (string) getRandomLineParsed(ADVANCED_COMMAND_FILE);
}
echo $vimCmd;
?>
</p>
</body>
</html>