-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
138 lines (112 loc) · 3.42 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
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
<?php
// if (isset($_POST) && isset($_POST['quote'])) {
// if ($_POST['quote'] == "") {
// die();
// }
// $quote = "\n".trim($_POST['quote']);
// file_put_contents('quotes.json', $quote, FILE_APPEND | LOCK_EX);
// $quotes = explode("\n", file_get_contents('quotes.json'));
// echo count($quotes);
// die();
// }
$quotes = file_get_contents('quotes.json');
$quotes = json_decode($quotes, true);
$quotes = $quotes['quotes'];
$numquotes = count($quotes);
function randomQuoteNo() {
global $numquotes;
return rand(0, $numquotes - 1);
}
function getQuote($quoteNo) {
global $quotes;
$quoteNo = floor($quoteNo);
if (!empty($quoteNo) && is_numeric($quoteNo)) {
if (is_numeric($quoteNo) && ($quoteNo >= 0) && ($quoteNo < count($quotes))) {
return json_encode($quotes[$quoteNo]);
} else {
return json_encode($quotes[0]);
}
} else {
return json_encode($quotes[0]);
}
}
// q = "API" call, 'quote' loads page on that specific quote ie for links
if (isset($_GET['q']) && is_numeric($_GET['q']) && $_GET['q'] >= 0 && $_GET['q'] <= $numquotes) {
die(getQuote($_GET['q']));
} else if (isset($url['q']) && is_numeric($url['q']) && $url['q'] >= 0 && $url['q'] <= $numquotes) {
die(getQuote($url['q']));
} else {
if (isset($_GET['quote']) && is_numeric($_GET['quote']) && $_GET['quote'] >= 0 && $_GET['quote'] < $numquotes) {
$startingQuoteNo = $_GET['quote'];
} else if (isset($url['quote']) && is_numeric($url['quote']) && $url['quote'] >= 0 && $url['quote'] < $numquotes) {
$startingQuoteNo = $url['quote'];
} else {
$startingQuoteNo = randomQuoteNo();
}
}
?>
<!doctype html>
<head>
<meta charset="UTF-8">
<title>
Quotes
</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="ZeroClipboard.min.js"></script>
<link rel="stylesheet" type="text/css" href="quotes.css">
<script type="text/javascript" src="quotes.js"></script>
<script type="text/javascript">
var quoteNo = <?php echo $startingQuoteNo; ?>;
var maxQuotes = <?php echo $numquotes ?>;
var pageName = "<?php echo $_SERVER['PHP_SELF']?>";
</script>
</head>
<body>
<div class="page">
<div id="pillar-left" class="pillar">
<div class="pillar-container">
<div class="arrow-container"><</div>
</div>
</div>
<div class="quote-container ui-helper-clearfix">
<?php
$firstquote = getQuote($startingQuoteNo);
$firstquote = json_decode($firstquote, true);
$firstquote = $firstquote;
?>
<p class="quote" id="quote">
<?php echo $firstquote['quote']; ?>
</p>
<p class="quoteby" id="quoteby">
<?php echo $firstquote['by']; ?>
</p>
</div>
<div id="pillar-right" class="pillar">
<div class="pillar-container">
<div class="arrow-container">></div>
</div>
</div>
</div>
<div class="footer">
<div id="links">
<div class="footer-container swf hideme">
<a id="copy-to-clipboard-quote" class="quote" href="#">COPY</a>
</div>
<div class="footer-container swf hideme">
<a id="copy-to-clipboard-url" class="quote" href="#">URL</a>
</div>
<div class="footer-container hideme">
<a id="submit-quote-link" class="quote" href="#">ADD</a>
</div>
<div class="footer-container">
<a id="randomquote" class="quote" href="#">RAND</a>
</div>
</div>
<div id="form">
<form id="quote-form">
<input class="quote-text" type="text" name="quote" width="100%"/>
</form>
</div>
</div>
<body>
</html>