forked from jhuesser/bzu-jodel-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.php
85 lines (76 loc) · 2.75 KB
/
new.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
<?php
session_start();
//Set default values for head & load it
$title = "Create Post | SocialDomayn";
$stylesheet = "jodel.css";
include 'functions/header.php';
//Load API functions
require 'functions/apicalls.php';
require 'functions/jodelmeta.php';
$config = require('config.php');
$apiroot = $config->apiUrl;
$userid = $_SESSION['userid'];
if(!isset($_SESSION['userid'])) {
die('You need to <a href="login.php">login</a> first');
}
//Get userdata
$callurl = $apiroot . "jodlers?transform=1&filter=jodlerID,eq," . $userid;
$userjson = getCall($callurl);
$user = json_decode($userjson, true);
foreach($user['jodlers'] as $jodler){
//get karma and account state
$karma = $jodler['karma'];
$accstate = $jodler['account_state'];
}
//set user data in session values
$_SESSION['karma'] = $karma;
$_SESSION['acctype'] = $accstate;
if(isset($_GET['post'])){
//new post created
//encode special chars to avoid injection
$jodel = htmlspecialchars($_POST['jodel'], ENT_QUOTES);
//set color as local value
$color = $_POST['color'];
//insert new post in DB, $postfields as JSON with all data
$postfields = "{\n \"jodlerIDFK\": \"$userid\",\n \"colorIDFK\": \"$color\",\n \"jodel\": \"$jodel\"\n}";
$callurl = $apiroot . "jodels";
$posted = postCall($callurl, $postfields);
//update the authors karma for creating a post
$karma = $karma + $config->karma_calc['create_jodel'];
$postfields = "{\n \n \"karma\": $karma\n}";
$callurl = $apiroot . "jodlers/" . $userid;
$karmaupdated = putCall($callurl, $postfields);
//redirect to post overview
header('Location: ' . $config->baseUrl . 'jodels.php');
}
?>
<!-- main menu -->
<div id="top"></div>
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link" href="jodels.php"><i class="fa fa-chevron-left" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:window.location.reload();"><i class="fa fa-refresh" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="user.php"><i class="fa fa-user" aria-hidden="true"></i><?php echo $_SESSION['karma'];?></a>
</li>
</ul>
<div class="test"></div>
<!-- end main menu -->
<?php
$colorhex = getRandomColor();
?>
<!-- post form -->
<form action="?post=1" method="POST">
<div class="form-group">
<label for="jodel">Enter your message</label>
<textarea class="form-control" rows="10" name="jodel" placeholder="Your post" style="color:white;background-color:#<?php echo $colorhex;?>"></textarea>
</div>
<!-- save the color in a hidden field -->
<input type="hidden" name="color" value="<?php echo $colornmb;?>">
<button type="submit" class="btn btn-warning">Submit</button>
</form>
<!-- end post form -->
<?php include 'functions/footer.php';