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

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