-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquotify.php
executable file
·228 lines (217 loc) · 8.89 KB
/
quotify.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!--META DATA -->
<title>quotifier.ca</title>
<link rel="icon" type="image/png" href="doublequotes.png"/>
<meta name="author" content="Kevin Camellini">
<meta name="description" content="Comment your code with random quotes.">
<meta name="keywords" content="comments, fun quotes, code, github, bootstrap, software, develoeper, gandhi">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- FontAwesome -->
<script src="https://use.fontawesome.com/e0af25fb51.js"></script>
<!-- Custom Style Sheet -->
<link href="css/style4.css" rel="stylesheet" type="text/css">
</head>
<body onload="setYear()">
<!-- Body -->
<div class="landing">
<div class="container-fluid">
<div class="row-fluid">
<?php
/* ----- QUOTIFIER VARIABLES ------ */
$smajsonFile = file_get_contents("data.json");
// First line of data.json containts "data =", not valid json
$lines = explode("\n", $smajsonFile);
// Remove first line
$smajsonFile = implode("\n", array_slice($lines, 1));
$smajsonShiz = json_decode($smajsonFile, true);
$authors = $smajsonShiz['authors'];
$quotes = $smajsonShiz['quotes'];
$ext = $smajsonShiz['fileext'];
/* ----- FILE VARIABLES ------ */
$submitvalue = $_POST['submit'];
$temp = $_FILES['fileToUpload']['tmp_name'];
$size = $_FILES['fileToUpload']['size'];
$name = $_FILES['fileToUpload']['name'];
$contents = file_get_contents($temp);
$upext = pathinfo($name, PATHINFO_EXTENSION);
$myfile = "input.txt";
$uploadOk =1;
if($_POST['submit']){
/*------ Limit file upload size ------ */
echo "<h1>“ Quotifer ”</h1>";
if ($size > 500000 || $size==0) {
echo "<h4>Your file must be < 500 kb:</h4>
<ul><li>Quit tryna h4x us.</li></ul>";
}
/*------ Allow only certain file formats ------ */
$extensionexists = false;
foreach($ext as $key => $value) {
if ($key == $upext)
$extensionexists = true;
}
if (!$extensionexists){
echo "<h4>Only the following formats are supported:</h4>
<ul>
<li>.rb</li>
<li>.java</li>
<li>.py</li>
<li>.cpp</li>
<li>.tex</li>
<li>.js</li>
<li>.o</li>
<li>.swift</li>
<li>.json</li>
<li>.php</li>
<li>.html</li>
<li>.css</li>
</ul>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "
<h4>Your file was not uploaded..</h4>
<a type=\"button\" class=\"btn btn-warning \" href=\"http://quotifier.ca\">
<span class=\"glyphicon glyphicon-triangle-left\" aria-hidden=\"true\"></span> Back
</a>";
}
// if everything is ok, quotify the file
else if ($submitvalue == "Quotify")
quotify($myfile);
// if everything is ok, boringify the file
else if ($submitvalue == "Boringify")
boringify($myfile);
}else{
header("Location: index.html");
}
/* ----- QUOTIFIER AWESOMENESS METHODS ------ */
// Genreate a random quote with a random author
function genquote(){
global $authors, $quotes;
$rand_quote = rand(0, sizeof($quotes)-1);
$rand_author = rand(0, sizeof($authors)-1);
return '"'.$quotes[$rand_quote].'" - '.$authors[$rand_author];
}
// Spice up the files mojo with some quotes
function quotify($filename){
global $temp,$ext,$upext,$name;
//chmod -R 777 input.txt
$openfile = fopen($filename, "w+") or die("Unable to open file..");
$opentemp = fopen($temp, "r") or die("Unable to open file..");
$fullfile = "";
$counter = 0;
while(!feof($opentemp)) {
$line = fgets($opentemp);
$counter++;
$fullfile = $fullfile."".$line;
$random = rand(5,15);
if( fmod($counter,$random) == 0){
/* Support for HTML, adds the closing tag */
if($upext==html)
$fullfile = $fullfile.$ext[$upext].genquote()."-->\n";
/* Support for CSS, adds the closing tag */
else if($upext==css)
$fullfile = $fullfile.$ext[$upext].genquote()."*/\n";
else
$fullfile = $fullfile.$ext[$upext].genquote()."\n";
}
}
echo "<h4>Your New(better) File: </h4>";
echo "<a type=\"button\" class=\"btn btn-info fileinput-button\" href=\"input.txt\" download=$name>
<span class=\"glyphicon glyphicon-download-alt\" aria-hidden=\"true\"></span> Download Commented File
</a>
<br/><br/>
<pre>";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $fullfile) as $l){
echo "</code>".$l."</code><br/>";
}
echo "</pre>
<a type=\"button\" class=\"btn btn-warning\" href=\"http://quotifier.ca\">
<span class=\"glyphicon glyphicon-triangle-left\"></span> Back
</a>";
fwrite($openfile,$fullfile);
fclose($openfile);
fclose($opentemp);
}
// Make the file hella boring by removing quotes
function boringify($filename){
global $temp,$ext,$upext,$name;
$openfile = fopen($filename, "w+") or die("Unable to open file..");
$opentemp = fopen($temp, "r") or die("Unable to open file..");
$fullfile = "";
while(!feof($opentemp)) {
$line = fgets($opentemp);
/* Check if substring 0-5 is a double quote, don't write it if it is */
if((substr($line,0,2) != ($ext[$upext]."\"")) && (substr($line,0,3) != ($ext[$upext]."\"")) && (substr($line,0,4) != ($ext[$upext]."\"")) && (substr($line,0,5) != ($ext[$upext]."\"")))
$fullfile = $fullfile."".$line;
}
echo "<h4>Your New(boring) File: </h4>";
echo "<a type=\"button\" class=\"btn btn-info fileinput-button\" href='input.txt' download=$name>
<span class=\"glyphicon glyphicon-download-alt\"></span> Download Commented File
</a>
<br/><br/>
<pre>";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $fullfile) as $l){
echo "</code>".$l."</code><br/>";
}
echo "</pre>
<a type=\"button\" class=\"btn btn-warning\" href=\"http://quotifier.ca\">
<span class=\"glyphicon glyphicon-triangle-left\"></span> Back
</a>";
fwrite($openfile,$fullfile);
fclose($openfile);
fclose($opentemp);
}
/* ----- DEBUGGER ------ */
function debugger( $data ){
$output = $data;
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log( 'Debug Objects: " . $output . "' );</script>";
}
?>
</div>
</div>
</div>
<!-- Footer -->
<div class="footer text-center">
<div class="container-fluid">
<div class="row-fluid social">
<a href="https://twitter.com/famingolabs" target="_blank">
<span class="fa fa-twitter"></span>
</a>
<a href="mailto:hello@famingolabs.com?Subject=Quotifier%20app">
<span class="fa fa-envelope-o"></span>
</a>
</div>
<div class="row-fluid famingo">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding: 0 0;">
<p class="text-muted"><a href="http://www.famingolabs.com" target="_blank">© <span id="yearFooter"></span> Famingo Labs Inc.</a> All rights reserved.</p>
</div>
</div>
</div>
</div>
<!-- jQuery JavaScript -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous">
</script>
<!-- Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous">
</script>
<!-- Custom Scripts -->
<script type="text/javascript" src="data.json"></script>
<script type="text/javascript" src="script/script15.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-108009963-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-108009963-4');
</script>
</body>
</html>