Skip to content

Commit

Permalink
Merge pull request #141 from jhuesser/jhuesser-workingtree
Browse files Browse the repository at this point in the history
performance & workaround
  • Loading branch information
jhuesser authored May 25, 2017
2 parents e0e3274 + 83f8321 commit d8577ec
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 16 deletions.
11 changes: 8 additions & 3 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'functions/votes.php';
$apiroot = $config->apiUrl;
$baseurl = $config->baseUrl;
$mainaction = true;

//check if user is logged in. if not, redirect to login page
if(!isset($_SESSION['userid'])) {
Expand Down Expand Up @@ -39,27 +40,30 @@
}

if(isset($_GET['upvotecomment'])){
$mainaction = false;
//upvote a comment
voteComment( $_GET['upvotecomment'], "up");
}


if(isset($_GET['downvotecomment'])){
$mainaction = false;
//Downvote a comment
voteComment( $_GET['downvotecomment'], "down");
}

if(isset($_GET['upvotejodel'])){
$mainaction = false;
//upvote post
voteJodel( $_GET['upvotejodel'], "up");
}

if(isset($_GET['downvotejodel'])){
$mainaction = false;
//downvote post
voteJodel( $_GET['downvotejodel'], "down");
}


if($mainaction == true){
?>
<!-- main menu -->
<div id="top"></div>
Expand Down Expand Up @@ -182,4 +186,5 @@


<?php
include 'functions/footer.php';
include 'functions/footer.php';
}
2 changes: 1 addition & 1 deletion functions/usermanipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function manipulateUser($user, $role, $mycaps){
}

if($execute == true){
$callurl = $apiroot . "/jodlers/" . $user;
$callurl = $apiroot . "jodlers/" . $user;
$postfields = "{\n \n \"account_state\": \"$role\"\n\n}";
$changes = putCall($callurl, $postfields);
}
Expand Down
9 changes: 7 additions & 2 deletions jodels.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
require 'functions/usermanipulation.php';
$apiroot = $config->apiUrl;
$baseurl = $config->baseUrl;

$mainaction = true;
if(!isset($_SESSION['userid'])) {
header('Location: ' . $config->baseUrl . 'login.php');

Expand Down Expand Up @@ -44,15 +44,18 @@

//if joels.php?upvotejodel=$jodelID is called, upvote it
if(isset($_GET['upvotejodel'])){
$mainaction = false;
voteJodel( $_GET['upvotejodel'], "up");

}

//if jodels.php?downvotejodel=$jodelID ist called, downvote post
if(isset($_GET['downvotejodel'])){
$mainaction = false;
voteJodel( $_GET['downvotejodel'], "down");

}
if($mainaction == true){
//If jodels.php?sort=$sort is called, post should be sorted
if(isset($_GET['sort'])){
$parameter = $_GET['sort'];
Expand Down Expand Up @@ -81,6 +84,7 @@

}
}

?>
<!-- Top / Main Navigation -->
<div id="top"></div>
Expand Down Expand Up @@ -203,4 +207,5 @@

<?php
//include footer
include 'functions/footer.php';
include 'functions/footer.php';
}
7 changes: 5 additions & 2 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
$config = require('config.php');
$apiroot = $config->apiUrl;

$mainaction = true;
//If user sent loginform, set values
if(isset($_GET['login'])) {
$mainaction = false;
$username = $_POST['username'];
$password = $_POST['password'];
//check if captcha is solved
Expand Down Expand Up @@ -60,7 +62,7 @@


}

if($mainaction == true){

?>
<div id="top"></div>
Expand Down Expand Up @@ -106,4 +108,5 @@

<!-- end login form -->
<?php
include 'functions/footer.php';
include 'functions/footer.php';
}
1 change: 1 addition & 0 deletions new.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
//new post created
//encode special chars to avoid injection
$jodel = htmlspecialchars($_POST['jodel'], ENT_QUOTES);
$jodel = trim(preg_replace('/\s\s+/', ' ', $jodel));
//set color as local value
$color = $_POST['color'];
//insert new post in DB, $postfields as JSON with all data
Expand Down
1 change: 1 addition & 0 deletions newcomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$jodel = $_GET['comment'];
//encode special chars to avoid injection
$comment = htmlspecialchars($_POST['comment'], ENT_QUOTES);
$comment = trim(preg_replace('/\s\s+/', ' ', $comment));
//set color as local value
$color = $_POST['color'];
//get data from original post
Expand Down
7 changes: 6 additions & 1 deletion signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
$config = require('config.php');
$apiroot = $config->apiUrl;

$mainaction = true;

if(isset($_GET['register'])) {
$mainaction = false;
//User wants to register
//set local values for easy handling
$error = false;
Expand Down Expand Up @@ -74,6 +77,7 @@


}
if($mainaction == true){

?>
<div id="top"></div>
Expand Down Expand Up @@ -125,4 +129,5 @@
</div>
</div>
<!-- end form -->
<?php include 'functions/footer.php';
<?php include 'functions/footer.php';
}
7 changes: 6 additions & 1 deletion user/colormgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$title = "Add color | SocialDomayn";
$stylesheet = "jodel.css";
include '../functions/header.php';
$mainaction = true;

//check if user is logged in & has required caps
$mycaps = $_SESSION['my_caps'];
Expand All @@ -18,6 +19,7 @@
$apiroot = $config->apiUrl;

if(isset($_GET['addcolor'])){
$mainaction = false;
//user wants to add a color
//save colorname & hexcode in values
$colorname = $_POST['colorname'];
Expand All @@ -32,6 +34,7 @@
}

if(isset($_GET['delcol'])){
$mainaction = false;
//user wants to delete a color
//get ID of color to delete
$colorid = $_GET['delcol'];
Expand All @@ -42,6 +45,7 @@
//redirect
header('Location: ' . $config->baseUrl . 'user/colormgmt.php');
}
if($mainaction == true){
?>
<div id="top"></div>
<!-- main menu -->
Expand Down Expand Up @@ -117,4 +121,5 @@
<?php
}
//include footer
include '../functions/footer.php';
include '../functions/footer.php';
}
7 changes: 6 additions & 1 deletion user/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$title = "Moderation | SocialDomayn";
$stylesheet = "jodel.css";
include '../functions/header.php';
$mainaction = true;

//check if user is logged in & has required caps
$mycaps = $_SESSION['my_caps'];
Expand All @@ -21,6 +22,7 @@

//if content is moderated
if(isset($_GET['type']) && isset($_GET['approve']) || isset($_GET['deny']) || isset($_GET['idc'])){
$mainaction = false;
//get type of the content
$type = $_GET['type'];

Expand Down Expand Up @@ -111,7 +113,7 @@
}
header('Location: ' . $baseurl . 'user/mod.php');
}

if($mainaction == true){
?>
<div id="top"></div>
<!-- main menu -->
Expand Down Expand Up @@ -292,6 +294,9 @@
}
}
}

include '../functions/footer.php';
}
?>


7 changes: 5 additions & 2 deletions user/postmgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$title = "Postmanagement | SocialDomayn";
$stylesheet = "jodel.css";
include '../functions/header.php';
$mainaction = true;

//check if user is logged in & has required caps
$mycaps = $_SESSION['my_caps'];
Expand Down Expand Up @@ -59,6 +60,7 @@
}
//delete a post
if(isset($_GET['del'])){
$mainaction = false;
//get post to delete and setup delete URL for API, call it, redirect back
$post2del = $_GET['del'];
$callurl = $apiroot . "jodels/" . $post2del;
Expand All @@ -68,6 +70,7 @@

//update a post
if(isset($_GET['update'])){
$mainaction = false;
//get all values and do not allow injections
$postid = $_POST['jodelID'];
$author = htmlspecialchars($_POST['author'], ENT_QUOTES);
Expand All @@ -87,7 +90,7 @@
}



if($mainaction == false){

?>
<div class="container">
Expand Down Expand Up @@ -194,4 +197,4 @@
</div> <!-- end post card somewhere here -->
</div><?php

}
}}
6 changes: 4 additions & 2 deletions user/resetpasswd.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$title = "Reset Password | SocialDomayn";
$stylesheet = "jodel.css";
include '../functions/header.php';
$mainaction = true;

//check if user is logged in & has required caps
$mycaps = $_SESSION['my_caps'];
Expand All @@ -20,6 +21,7 @@


if (isset($_GET['resetpasswd'])){
$mainaction == false;
$user2reset = $_POST['user'];
$newpasswd = $_POST['passwd'];
$password_hash = password_hash($newpasswd, PASSWORD_DEFAULT);
Expand All @@ -28,7 +30,7 @@
putCall($callurl, $postfields);
header('Location: ' . $config->baseUrl . 'user/resetpasswd.php');
}

if($mainaction == true){
?>

<div id="top"></div>
Expand Down Expand Up @@ -99,4 +101,4 @@
}
//include footer
include '../functions/footer.php';

}
11 changes: 10 additions & 1 deletion user/usermgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$title = "Manage Users | SocialDomayn";
$stylesheet = "jodel.css";
include '../functions/header.php';
$mainaction = true;

//check if user is logged in & has required caps
$mycaps = $_SESSION['my_caps'];
Expand All @@ -22,6 +23,7 @@
$mycaps = $_SESSION['my_caps'];

if(isset($_GET['deluser'])){
$mainaction = false;
//user wants to delete a color
//get ID of color to delete
$user = $_GET['deluser'];
Expand All @@ -36,30 +38,37 @@


if(isset($_GET['ban'])){
$mainaction = false;
$updated = manipulateUser($_GET['ban'], 0, $mycaps);
header('Location: ' . $config->baseUrl . 'user/usermgmt.php');
}
if(isset($_GET['active'])){
$mainaction = false;
$updated = manipulateUser($_GET['active'], 1, $mycaps);
header('Location: ' . $config->baseUrl . 'user/usermgmt.php');
}
if(isset($_GET['mod'])){
$mainaction = false;
$updated = manipulateUser($_GET['mod'], 2, $mycaps);
header('Location: ' . $config->baseUrl . 'user/usermgmt.php');
}
if(isset($_GET['admin'])){
$mainaction = false;
$updated = manipulateUser($_GET['admin'], 3, $mycaps);
header('Location: ' . $config->baseUrl . 'user/usermgmt.php');
}
if(isset($_GET['superadmin'])){
$mainaction = false;
$updated = manipulateUser($_GET['superadmin'], 4, $mycaps);
header('Location: ' . $config->baseUrl . 'user/usermgmt.php');
}
if(isset($updated)){
$mainaction = false;
if($updated == false){
$_SESSION['errorMsg'] = "Something went wrong!";
}
}
if($mainaction == false){

?>

Expand Down Expand Up @@ -138,4 +147,4 @@
}
//include footer
include '../functions/footer.php';
}

0 comments on commit d8577ec

Please sign in to comment.