Completed
Push — master ( 64efce...1ec187 )
by mains
02:46
created

index.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
	include('php/jodel-web.php');
3
	$posts;
4
	
5
	//Get Post Details
6
	if(isset($_GET['postId']) && isset($_GET['getPostDetails']))
7
	{
8
		$userHandleBuffer = [];
9
10
		$accountCreator = new GetPostDetails();
11
		$accountCreator->setAccessToken($jodelAccountForView->accessToken);
12
		$data = $accountCreator->execute();
13
14
		if(array_key_exists('status_code', $data) && $data->status_code == 404)
15
		{
16
			header('HTTP/1.1 410 Gone');
17
			include 'error-pages/410.php';
18
			exit;
19
		}
20
21
		$posts[0] = $data;
22
23
		if(array_key_exists('children', $data)) {
24
			foreach($data['children'] as $key => $child)
25
			{
26
				
27
				if(!$child["parent_creator"] == 1)
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal parent_creator does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
28
				{
29
					$numberForUser = array_search($child['user_handle'], $userHandleBuffer);
30
					if($numberForUser === FALSE)
31
					{
32
						array_push($userHandleBuffer, $child['user_handle']);
33
						$data['children'][$key]['user_handle'] = count($userHandleBuffer);
34
					}
35
					else
36
					{
37
						$data['children'][$key]['user_handle'] = $numberForUser + 1;
38
					}
39
				}
40
41
				array_push($posts, $data['children'][$key]);
42
			}
43
		}
44
	}
45
	//Get Posts and Hashtags
46
	else
47
	{
48
		$posts = $view->getPosts($jodelAccountForView);
49
	}
50
	if(!isset($posts[0]))
51
	{
52
		error_log('Fehler: ' . print_r($posts, true) . print_r($posts['recent'], true) . print_r($posts['posts'], true));
53
	}
54
55
	$title = $view->getTitle($posts[0]);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56
	$description = $view->getMetaDescription($posts[0]);
57
	if($view->isDetailedView)
58
	{
59
		$backButton = $view->back()->toUrl() . '#postId-' . $view->postId;
60
	}
61
	else
62
	{
63
		$backButton = '';
64
	}
65
	include 'templates/header.php';
66
?>
67
		
68
		<div class="mainContent container">		
69
			<div class="content row">
70
				<article class="topContent col-sm-8">
71
72
					<content id="posts">
73
						<?php
74
							foreach($posts as $post)
75
							{
76
								$view->lastPostId = $post['post_id'];
77
								$view->jodelToHtml($post);
78
							} ?>
79
					</content>
80
					
81
					<?php if(!isset($_GET['postId']) && !isset($_GET['getPostDetails'])) { ?>
82
						<p id="loading">
83
							Loading…
84
						</p>
85
					<?php } ?>
86
				</article>
87
			
88
				<aside class="topSidebar col-sm-4 sidebar-outer">
89
					<div class="fixed">
90
						<article>
91
							<div>
92
								<h2>Position / Hashtag</h2>
93
								<form method="get">
94
									<input type="text" id="city" name="search" placeholder="<?php if(isset($newPositionStatus)) echo $newPositionStatus; ?>" required>
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
95
									<label>try: #jhj</label><br>
96
									<input type="submit" value="Set Location" /> 
97
								</form>
98
							</div>
99
						</article>
100
101
						<article>
102
							<div>
103
								<h2>Karma</h2>
104
								<?php echo $jodelAccountForKarma->getKarma(); ?>
105
							</div>
106
						</article>
107
108
						<article>
109
							<div>
110
								<?php if(isset($_GET['postId']) && isset($_GET['getPostDetails'])) { ?>
111
								<h2>Comment on Jodel</h2>
112
								<form method="POST">				
113
										<input type="hidden" name="ancestor" value="<?php echo htmlspecialchars($_GET['postId']);?>" />
114
										<textarea id="message" name="message" placeholder="Send a comment on a Jodel to all students within 10km" required></textarea> 
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 137 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
115
									<br />
116
									<input type="submit" value="SEND" /> 
117
								</form>
118
									<?php } else { ?>
119
								<h2>New Jodel</h2>
120
								<form method="POST">
121
									<textarea id="message" name="message" placeholder="Send a Jodel to all students within 10km" required></textarea> 
0 ignored issues
show
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
122
									<br />
123
									<select id="postColorPicker" name="color">
124
										<option value="06A3CB">Blue</option>
125
										<option value="8ABDB0">Teal</option>
126
										<option value="9EC41C">Green</option>
127
										<option value="FFBA00">Yellow</option>
128
										<option value="DD5F5F">Red</option>
129
										<option value="FF9908">Orange</option>
130
									</select> 
131
									<br />
132
									<input type="submit" value="SEND" /> 
133
								</form>
134
								<?php } ?>
135
							</div>
136
						</article>
137
							
138
						<article>
139
							<div>
140
								<h2>Login</h2>
141
							</div>
142
						</article>
143
					</div>
144
				</aside>
145
			</div>
146
			<?php include 'templates/nav-bottom.php';?>
147
		</div>
148
		<?php
149
			$includeEmojiAndAjax = TRUE;
150
			include 'templates/footer.php';
151
		?>