Code Duplication    Length = 107-108 lines in 2 locations

get-posts-ajax.php 1 location

@@ 97-204 (lines=108) @@
94
		?>
95
		<div class="nextPosts">
96
		<?php
97
		for($i = 0; $i<$loops; $i++) {
98
		
99
			if(isset($posts[$i])) {
100
				$lastPostId = $posts[$i]['post_id'];
101
102
				
103
				$now = new DateTime();
104
				$d = new DateTime($posts[$i]["created_at"]);
105
				
106
				
107
				//Time to time difference
108
							$timediff = $now->diff($d);
109
110
							$timediff_inSeconds = (string)$timediff->format('%s');
111
							$timediff_inMinutes = (string)$timediff->format('%i');
112
							$timediff_inHours = (string)$timediff->format('%h');
113
							$timediff_inDays = (string)$timediff->format('%d');
114
							$timediff_inMonth = (string)$timediff->format('%m');
115
							if($timediff_inMonth!=0) {
116
									$timediff = $timediff_inMonth . "m";
117
							}
118
							else
119
							{
120
								if($timediff_inDays!=0)
121
								{
122
									$timediff = $timediff_inDays . "d";
123
								}
124
								else
125
								{
126
									if($timediff_inHours!=0)
127
									{
128
										$timediff = $timediff_inHours . "h";
129
									}
130
									else
131
									{
132
										if($timediff_inMinutes!=0)
133
										{
134
											$timediff = $timediff_inMinutes . "m";
135
										}
136
										else
137
										{
138
											$timediff = $timediff_inSeconds . "s";
139
										}
140
									}
141
								}
142
							}
143
						?>
144
145
				<article id ="postId-<?php echo $posts[$i]["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $posts[$i]["color"];?>;">
146
					<content>
147
						<?php 
148
						if(isset($posts[$i]["image_url"])) {
149
							echo '<img src="' . $posts[$i]["image_url"] . '">';
150
						}
151
						else {
152
							echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($posts[$i]["message"])));
153
						}
154
						?>
155
					</content>
156
					<aside>
157
						<a href="index.php?vote=up&postID=<?php echo $posts[$i]["post_id"];?>">
158
							<i class="fa fa-angle-up fa-3x"></i>
159
						</a>	
160
							<br />
161
						<?php echo $posts[$i]["vote_count"];?><br />
162
						<a href="index.php?vote=down&postID=<?php echo $posts[$i]["post_id"];?>">
163
							<i class="fa fa-angle-down fa-3x"></i>
164
						</a>
165
					</aside>
166
167
					<footer>
168
						<table>
169
							<tr>
170
								<td class="time">
171
									<span data-tooltip="Time">
172
										<i class="fa fa-clock-o"></i>
173
										<?php echo $timediff;?>
174
									</span> 
175
								</td>
176
								<td class="comments">
177
									<?php if($showCommentIcon) {?>
178
									<span data-tooltip="Comments">
179
										<a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postID=<?php echo $posts[$i]["post_id"];?>">
180
											<i class="fa fa-commenting-o"></i>
181
											<?php if(array_key_exists("child_count", $posts[$i])) {
182
														echo $posts[$i]["child_count"];
183
													} else echo "0";
184
											?>
185
											</a>
186
									</span>
187
									<?php } ?>
188
								</td>
189
								<td class="distance">
190
									<span data-tooltip="Distance">
191
										<i class="fa fa-map-marker"></i>
192
										<?php echo $posts[$i]["distance"];?> km
193
									</span>
194
								</td>
195
							</tr>
196
						</table>
197
					</footer>
198
				</article>
199
200
201
202
				<?php 
203
			}
204
		}
205
		?>
206
		</div>
207
		<div class="lastPostId">

index.php 1 location

@@ 262-368 (lines=107) @@
259
							}
260
							
261
262
							for($i = 0; $i<$loops; $i++) {
263
							
264
							if(isset($posts[$i])) {
265
							$lastPostId = $posts[$i]['post_id'];
266
267
							
268
							$now = new DateTime();
269
							$d = new DateTime($posts[$i]["created_at"]);
270
							
271
							
272
							//Time to time difference
273
							$timediff = $now->diff($d);
274
275
							$timediff_inSeconds = (string)$timediff->format('%s');
276
							$timediff_inMinutes = (string)$timediff->format('%i');
277
							$timediff_inHours = (string)$timediff->format('%h');
278
							$timediff_inDays = (string)$timediff->format('%d');
279
							$timediff_inMonth = (string)$timediff->format('%m');
280
							if($timediff_inMonth!=0) {
281
									$timediff = $timediff_inMonth . "m";
282
							}
283
							else
284
							{
285
								if($timediff_inDays!=0)
286
								{
287
									$timediff = $timediff_inDays . "d";
288
								}
289
								else
290
								{
291
									if($timediff_inHours!=0)
292
									{
293
										$timediff = $timediff_inHours . "h";
294
									}
295
									else
296
									{
297
										if($timediff_inMinutes!=0)
298
										{
299
											$timediff = $timediff_inMinutes . "m";
300
										}
301
										else
302
										{
303
											$timediff = $timediff_inSeconds . "s";
304
										}
305
									}
306
								}
307
							}
308
						?>
309
						
310
						<article id ="postId-<?php echo $posts[$i]["post_id"]; ?>" class="jodel" style="background-color: #<?php echo $posts[$i]["color"];?>;">
311
							<content>
312
								<?php 
313
								if(isset($posts[$i]["image_url"])) {
314
									echo '<img src="' . $posts[$i]["image_url"] . '">';
315
								}
316
								else {
317
									echo str_replace('  ', ' &nbsp;', nl2br(htmlspecialchars($posts[$i]["message"])));
318
								}
319
								?>
320
							</content>
321
							<aside>
322
								<a href="index.php?vote=up&postID=<?php echo $posts[$i]["post_id"];?>">
323
									<i class="fa fa-angle-up fa-3x"></i>
324
								</a>	
325
									<br />
326
								<?php echo $posts[$i]["vote_count"];?><br />
327
								<a href="index.php?vote=down&postID=<?php echo $posts[$i]["post_id"];?>">
328
									<i class="fa fa-angle-down fa-3x"></i>
329
								</a>
330
							</aside>
331
						
332
							<footer>
333
								<table>
334
									<tr>
335
										<td class="time">
336
											<span data-tooltip="Time">
337
												<i class="fa fa-clock-o"></i>
338
												<?php echo $timediff;?>
339
											</span> 
340
										</td>
341
										<td class="comments">
342
											<?php if($showCommentIcon) {?>
343
											<span data-tooltip="Comments">
344
												<a href="index.php?getPostDetails=true&view=<?php echo $view;?>&postID=<?php echo $posts[$i]["post_id"];?>">
345
													<i class="fa fa-commenting-o"></i>
346
													<?php if(array_key_exists("child_count", $posts[$i])) {
347
																echo $posts[$i]["child_count"];
348
															} else echo "0";
349
													?>
350
													</a>
351
											</span>
352
											<?php } ?>
353
										</td>
354
										<td class="distance">
355
											<span data-tooltip="Distance">
356
												<i class="fa fa-map-marker"></i>
357
												<?php echo $posts[$i]["distance"];?> km
358
											</span>
359
										</td>
360
									</tr>
361
								</table>
362
							</footer>
363
						</article>
364
						
365
366
						
367
						<?php }
368
						} ?>
369
370
					</content>
371