Code Duplication    Length = 46-48 lines in 4 locations

mod/gc_mobile_api/models/wire.php 4 locations

@@ 147-194 (lines=48) @@
144
		));
145
		$wire_posts = json_decode($all_wire_posts);
146
147
		foreach ($wire_posts as $wire_post) {
148
			$wire_post_obj = get_entity($wire_post->guid);
149
			$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
150
151
			$url = "";
152
			if (!empty($reshare)) {
153
				$url = $reshare->getURL();
154
			}
155
156
			$text = "";
157
			if (!empty($reshare->title)) {
158
				$text = $reshare->title;
159
			} elseif (!empty($reshare->name)) {
160
				$text = $reshare->name;
161
			} elseif (!empty($reshare->description)) {
162
				$text = elgg_get_excerpt($reshare->description, 140);
163
			}
164
165
			$wire_post->shareURL = $url;
166
			$wire_post->shareText = gc_explode_translation($text, $lang);
167
168
			$likes = elgg_get_annotations(array(
169
				'guid' => $wire_post->guid,
170
				'annotation_name' => 'likes'
171
			));
172
			$wire_post->likes = count($likes);
173
174
			$liked = elgg_get_annotations(array(
175
				'guid' => $wire_post->guid,
176
				'annotation_owner_guid' => $user_entity->guid,
177
				'annotation_name' => 'likes'
178
			));
179
			$wire_post->liked = count($liked) > 0;
180
181
			$replied = elgg_get_entities_from_metadata(array(
182
				"metadata_name" => "wire_thread",
183
				"metadata_value" => $thread_id,
184
				"type" => "object",
185
				"subtype" => "thewire",
186
				"owner_guid" => $user_entity->guid
187
			));
188
			$wire_post->replied = count($replied) > 0;
189
190
			$wire_post->thread_id = $thread_id;
191
192
			$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
193
			$wire_post->description = wire_filter($wire_post->description);
194
		}
195
	} else {
196
		$wire_posts = elgg_list_entities(array(
197
			"type" => "object",
@@ 295-340 (lines=46) @@
292
293
	$wire_posts = json_decode($all_wire_posts);
294
295
	foreach ($wire_posts as $wire_post) {
296
		$wire_post_obj = get_entity($wire_post->guid);
297
		$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
298
299
		$url = "";
300
		if (!empty($reshare)) {
301
			$url = $reshare->getURL();
302
		}
303
304
		$text = "";
305
		if (!empty($reshare->title)) {
306
			$text = $reshare->title;
307
		} elseif (!empty($reshare->name)) {
308
			$text = $reshare->name;
309
		} elseif (!empty($reshare->description)) {
310
			$text = elgg_get_excerpt($reshare->description, 140);
311
		}
312
313
		$wire_post->shareURL = $url;
314
		$wire_post->shareText = gc_explode_translation($text, $lang);
315
316
		$likes = elgg_get_annotations(array(
317
			'guid' => $wire_post->guid,
318
			'annotation_name' => 'likes'
319
		));
320
		$wire_post->likes = count($likes);
321
322
		$liked = elgg_get_annotations(array(
323
			'guid' => $wire_post->guid,
324
			'annotation_owner_guid' => $user_entity->guid,
325
			'annotation_name' => 'likes'
326
		));
327
		$wire_post->liked = count($liked) > 0;
328
329
		$replied = elgg_get_entities_from_metadata(array(
330
			"metadata_name" => "wire_thread",
331
			"metadata_value" => $wire_post->wire_thread,
332
			"type" => "object",
333
			"subtype" => "thewire",
334
			"owner_guid" => $user_entity->guid
335
		));
336
		$wire_post->replied = count($replied) > 0;
337
338
		$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
339
		$wire_post->description = wire_filter($wire_post->description);
340
	}
341
342
	return $wire_posts;
343
}
@@ 370-416 (lines=47) @@
367
	));
368
	$wire_posts = json_decode($all_wire_posts);
369
370
	foreach ($wire_posts as $wire_post) {
371
		$wire_post_obj = get_entity($wire_post->guid);
372
373
		$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
374
375
		$url = "";
376
		if (!empty($reshare)) {
377
			$url = $reshare->getURL();
378
		}
379
380
		$text = "";
381
		if (!empty($reshare->title)) {
382
			$text = $reshare->title;
383
		} elseif (!empty($reshare->name)) {
384
			$text = $reshare->name;
385
		} elseif (!empty($reshare->description)) {
386
			$text = elgg_get_excerpt($reshare->description, 140);
387
		}
388
389
		$wire_post->shareURL = $url;
390
		$wire_post->shareText = gc_explode_translation($text, $lang);
391
392
		$likes = elgg_get_annotations(array(
393
			'guid' => $wire_post->guid,
394
			'annotation_name' => 'likes'
395
		));
396
		$wire_post->likes = count($likes);
397
398
		$liked = elgg_get_annotations(array(
399
			'guid' => $wire_post->guid,
400
			'annotation_owner_guid' => $user_entity->guid,
401
			'annotation_name' => 'likes'
402
		));
403
		$wire_post->liked = count($liked) > 0;
404
405
		$replied = elgg_get_entities_from_metadata(array(
406
			"metadata_name" => "wire_thread",
407
			"metadata_value" => $wire_post->wire_thread,
408
			"type" => "object",
409
			"subtype" => "thewire",
410
			'owner_guid' => $user_entity->guid
411
		));
412
		$wire_post->replied = count($replied) > 0;
413
414
		$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
415
		$wire_post->description = wire_filter($wire_post->description);
416
	}
417
418
	return $wire_posts;
419
}
@@ 452-497 (lines=46) @@
449
	));
450
	$wire_posts = json_decode($all_wire_posts);
451
452
	foreach ($wire_posts as $wire_post) {
453
		$wire_post_obj = get_entity($wire_post->guid);
454
		$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
455
456
		$url = "";
457
		if (!empty($reshare)) {
458
			$url = $reshare->getURL();
459
		}
460
461
		$text = "";
462
		if (!empty($reshare->title)) {
463
			$text = $reshare->title;
464
		} elseif (!empty($reshare->name)) {
465
			$text = $reshare->name;
466
		} elseif (!empty($reshare->description)) {
467
			$text = elgg_get_excerpt($reshare->description, 140);
468
		}
469
470
		$wire_post->shareURL = $url;
471
		$wire_post->shareText = gc_explode_translation($text, $lang);
472
473
		$likes = elgg_get_annotations(array(
474
			'guid' => $wire_post->guid,
475
			'annotation_name' => 'likes'
476
		));
477
		$wire_post->likes = count($likes);
478
479
		$liked = elgg_get_annotations(array(
480
			'guid' => $wire_post->guid,
481
			'annotation_owner_guid' => $viewer->guid,
482
			'annotation_name' => 'likes'
483
		));
484
		$wire_post->liked = count($liked) > 0;
485
486
		$replied = elgg_get_entities_from_metadata(array(
487
			"metadata_name" => "wire_thread",
488
			"metadata_value" => $wire_post->wire_thread,
489
			"type" => "object",
490
			"subtype" => "thewire",
491
			"owner_guid" => $viewer->guid
492
		));
493
		$wire_post->replied = count($replied) > 0;
494
495
		$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
496
		$wire_post->description = wire_filter($wire_post->description);
497
	}
498
499
	return $wire_posts;
500
}