-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
390 lines (314 loc) · 13.3 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
class bill{
/**
* @var string The new image name, to be provided or will be generated.
*/
protected $name;
/**
* @var string The full image path (dir + image + mime)
*/
protected $fullPath;
/**
* @var string The folder or image storage location
*/
protected $location;
/**
* @var string The folder or image storage location
*/
protected $strings;
/**
* @var string The folder or image storage location
*/
public $error;
/**
* Returns the image name
*
* @return string
*/
public function getName()
{
if (!$this->name) {
return uniqid(true) . "_" . str_shuffle(implode(range("e", "q")));
}
return $this->name;
}
/**
* Returns the full path of the image ex "location/image.mime"
*
* @return string
*/
public function getFullPath()
{
$this->fullPath = $this->location . "/" . $this->name . ".jpg";
return $this->fullPath;
}
public function setLocation($dir = "bills", $permission = 0666)
{
if (!file_exists($dir) && !is_dir($dir) && !$this->location) {
$createFolder = @mkdir("" . $dir, (int) $permission, true);
if (!$createFolder) {
$this->error = "Folder " . $dir . " could not be created";
return ;
}
}
$this->location = $dir;
return $this;
}
public function getLocation()
{
if(!$this->location){
$this->setLocation();
}
return $this->location;
}
public function upload($strings)
{
$bill = $this;
/* set and get folder name */
$bill->fullPath = $this->getLocation(). "/";
$bill->name = $this->getName().'.jpg';
$imgPath = 'image.jpg'; //the bill template
$image = imagecreatefromjpeg($imgPath);
$color = imagecolorallocate($image, 0, 0, 0);
$fontsize ='30';
/* Font mac osx */
$font = '/Library/Fonts/Arial Black.ttf';
/* Font windows (http://superuser.com/a/407811) */
// $font = 'C:\Windows\Fonts';
/* Font linux (http://askubuntu.com/a/353310)
Standard Locations:
/usr/share/fonts
/usr/local/share/fonts
*/
if(isset($_POST['does_what'])){
if(empty(array_filter($_POST['does_what']))){
$this->error = 'Your Bill dosent say ANYTHING...';
return ;
}
if(empty($_POST['does_what'][0])){
$this->error = 'Your Bill dosent have a name...';
return ;
}
if(empty($_POST['does_what'][1])){
$this->error = 'Your Bill dosent do anything...';
return ;
}
if(empty($_POST['does_what'][2])){
$this->error = 'Your Bill need to do more...';
return ;
}
if(empty($_POST['does_what'][3])){
$this->error = 'Your Bill need to do more...';
return ;
}
$strings = array();
foreach($_POST['does_what'] as $key => $value){
if($key == 0){
$strings[] = "This is " . $value;
}else{
$strings[] = $value;
}
}
}
if(count($strings)>8){
$this->error = "To many bills";
return ;
}
foreach($strings as $value){
if(strlen($value)>31){
$this->error = '<b>Whoops</b>, to long Bill conversation.';
return ;
}
}
$offset = 100;
foreach($strings as $value){
imagettftext($image, $fontsize, 0, 50, $offset, $color, $font, $value);
$offset = $offset + 50;
}
if(!$this->moveUploadedFile($image, $bill->fullPath.$bill->name)){
$this->error = 'Error with file creation';
return ;
}
if(isset($this->error)){
return false;
}
header('Location: index.php?billpath='.$bill->name);
}
/**
* Final upload method to be called, isolated for testing purposes
*
* @param $tmp_name int the temporary location of the image file
* @param $destination int upload destination
*
* @return bool
*/
public function moveUploadedFile($tmp_name, $destination)
{
return imagejpeg($tmp_name, $destination);
}
}
if(isset($_POST["submit"])){
$formdata = $_POST["does_what"]; // dont forget to sanitize any post data
//than you can call your class function and pass this data
$bill = new bill();
if(!$bill->upload($formdata)){
$upload_error = TRUE;
}
}
if(isset($_GET['billpath'])){
if(!preg_match('/^[a-z0-9_]+\.jpg$/', $_GET['billpath'])){
echo 'Unknown error';
return false;
}
$imagepreview = preg_replace('/[^-a-zA-Z0-9_]/', '', $_GET['billpath']);
$imagepreview = 'bills/' . $_GET['billpath'];
}else{
$imagesDir = 'bills/';
$images = glob($imagesDir . '*.{jpg}', GLOB_BRACE);
$imagepreview = $images[array_rand($images)]; // See comments
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>belikebill.se</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:url" content="http://www.belikebill.se" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Be like Bill, Bill is smart" />
<meta property="og:description" content="Bill minds his own business" />
<meta property="og:image" content="http://www.belikebill.se/<?php echo $imagepreview; ?>" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="360" />
<meta property="og:image:height" content="188" />
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAYMEi8HEBg+CxIbZxojMncRGiQxBgMDAQAAAAAAAAAAAAAAAAAAAAAAAAAA
AA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAGSAqLyw9Vf9sjaTxaoWVBgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAElmaAMoOk3kT3mgvgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALkFTfE52nWMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAA//8AAMD/AACAPwAAgA8AAAADAAAAAQAAgAEAAMAAAADAAAAA8AMAAP53AAD+fwAA/n8AAP5/
AAD+fwAA//8AAA==" rel="icon" type="image/x-icon" />
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- fa -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
</head>
<body>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-sm-4">
<?php echo isset($upload_error) ? '<div class="alert alert-danger">' . $bill->error .'</div>' : ''; ?>
<img class="img-responsive" src="<?php echo $imagepreview; ?>"><br>
<a href="<?php echo $imagepreview; ?>"><i class="fa fa-file-image-o"></i> URL to this Bill</a><br>
<a class="btn btn-lg btn-success" href="#">
<i class="fa fa-facebook-official fa-2x pull-left"></i> Share your Bill!<br>on Facebook!</a><br><br>
<a href="index.php"><button type="button" class="btn btn-info"><i class="fa fa-random"></i> Randomize another Bill!</button></a><br>
</div>
<div class="col-sm-4">
<h1>Make your own Bill!</h1>
<form action="index.php" method="post">
<div class="form-group">
<label>Name: </label>
<input type="text" id="namn" class="form-control pull-right" name="does_what[]" required>Chars left: <span id="chars_namn"></span>
</div>
<div class="form-group">
<label>Does what?: </label>
<input type="text" id="does_what_1" class="form-control pull-right" name="does_what[]" required>Chars left: <span id="chars_does_what_1"></span>
</div>
<div class="form-group">
<label>Does what?: </label>
<input type="text" id="does_what_2" class="form-control pull-right" name="does_what[]" required>Chars left: <span id="chars_does_what_2"></span>
</div>
<div class="form-group">
<label>Does what?: </label>
<input type="text" id="does_what_3" class="form-control pull-right" name="does_what[]" required>Chars left: <span id="chars_does_what_3"></span>
</div>
<div class="form-group">
<label>Does what? (optional): </label>
<input type="text" id="does_what_4" class="form-control pull-right" name="does_what[]">Chars left: <span id="chars_does_what_4"></span>
</div>
<div class="form-group">
<label>Does what? (optional): </label>
<input type="text" id="does_what_5" class="form-control pull-right" name="does_what[]">Chars left: <span id="chars_does_what_5"></span>
</div>
<div class="form-group">
<label>Does what? (optional): </label>
<input type="text" id="does_what_6" class="form-control pull-right" name="does_what[]">Chars left: <span id="chars_does_what_6"></span>
</div>
<div class="form-group">
<label>Does what? (optional): </label>
<input type="text" id="does_what_7" class="form-control pull-right" name="does_what[]">Chars left: <span id="chars_does_what_7"></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-default" name="submit" value="submit">
</div>
</form>
</div></div></div>
<style>
.container { margin-top: 5px; }
</style>
<!-- Latest compiled and minified jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js" type="text/javascript"></script>
<!-- Latest compiled and minified Bootstrap JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script>
(function($) {
$.fn.extend( {
limiter: function(limit, elem) {
$(this).on("keyup focus", function() {
setCount(this, elem);
});
function setCount(src, elem) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
chars = limit;
}
elem.html( limit - chars );
}
setCount($(this)[0], elem);
}
});
})(jQuery);
var chars_namn = $("#chars_namn");
$("#namn").limiter(30, chars_namn);
var chars_does_what_1 = $("#chars_does_what_1");
$("#does_what_1").limiter(30, chars_does_what_1);
var chars_does_what_2 = $("#chars_does_what_2");
$("#does_what_2").limiter(30, chars_does_what_2);
var chars_does_what_3 = $("#chars_does_what_3");
$("#does_what_3").limiter(30, chars_does_what_3);
var chars_does_what_4 = $("#chars_does_what_4");
$("#does_what_4").limiter(30, chars_does_what_4);
var chars_does_what_5 = $("#chars_does_what_5");
$("#does_what_5").limiter(30, chars_does_what_5);
var chars_does_what_6 = $("#chars_does_what_6");
$("#does_what_6").limiter(30, chars_does_what_6);
var chars_does_what_7 = $("#chars_does_what_7");
$("#does_what_7").limiter(30, chars_does_what_7);
</script>
</body>
</html>