Code Duplication    Length = 46-48 lines in 3 locations

mod/gc_mobile_api/models/wire.php 3 locations

@@ 108-155 (lines=48) @@
105
		));
106
		$wire_posts = json_decode($all_wire_posts);
107
108
		foreach($wire_posts as $wire_post){
109
			$wire_post_obj = get_entity($wire_post->guid);
110
			$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
111
112
			$url = "";
113
			if( !empty( $reshare ) ){
114
				$url = $reshare->getURL();
115
			}
116
117
			$text = "";
118
			if ( !empty($reshare->title) ) {
119
				$text = $reshare->title;
120
			} else if ( !empty($reshare->name) ) {
121
				$text = $reshare->name;
122
			} else if ( !empty($reshare->description) ) {
123
				$text = elgg_get_excerpt($reshare->description, 140);
124
			}
125
126
			$wire_post->shareURL = $url;
127
			$wire_post->shareText = gc_explode_translation($text, $lang);
128
129
			$likes = elgg_get_annotations(array(
130
				'guid' => $wire_post->guid,
131
				'annotation_name' => 'likes'
132
			));
133
			$wire_post->likes = count($likes);
134
135
			$liked = elgg_get_annotations(array(
136
				'guid' => $wire_post->guid,
137
				'annotation_owner_guid' => $user_entity->guid,
138
				'annotation_name' => 'likes'
139
			));
140
			$wire_post->liked = count($liked) > 0;
141
142
			$replied = elgg_get_entities_from_metadata(array(
143
				"metadata_name" => "wire_thread",
144
				"metadata_value" => $thread_id,
145
				"type" => "object",
146
				"subtype" => "thewire",
147
				"owner_guid" => $user_entity->guid
148
			));
149
			$wire_post->replied = count($replied) > 0;
150
151
			$wire_post->thread_id = $thread_id;
152
153
			$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
154
			$wire_post->description = wire_filter($wire_post->description);
155
		}
156
	} else {
157
		$wire_posts = elgg_list_entities(array(
158
			"type" => "object",
@@ 262-307 (lines=46) @@
259
260
	$wire_posts = json_decode($all_wire_posts);
261
262
	foreach($wire_posts as $wire_post){
263
		$wire_post_obj = get_entity($wire_post->guid);
264
		$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
265
266
		$url = "";
267
		if( !empty( $reshare ) ){
268
			$url = $reshare->getURL();
269
		}
270
271
		$text = "";
272
		if ( !empty($reshare->title) ) {
273
			$text = $reshare->title;
274
		} else if ( !empty($reshare->name) ) {
275
			$text = $reshare->name;
276
		} else if ( !empty($reshare->description) ) {
277
			$text = elgg_get_excerpt($reshare->description, 140);
278
		}
279
280
		$wire_post->shareURL = $url;
281
		$wire_post->shareText = gc_explode_translation($text, $lang);
282
283
		$likes = elgg_get_annotations(array(
284
			'guid' => $wire_post->guid,
285
			'annotation_name' => 'likes'
286
		));
287
		$wire_post->likes = count($likes);
288
289
		$liked = elgg_get_annotations(array(
290
			'guid' => $wire_post->guid,
291
			'annotation_owner_guid' => $user_entity->guid,
292
			'annotation_name' => 'likes'
293
		));
294
		$wire_post->liked = count($liked) > 0;
295
296
		$replied = elgg_get_entities_from_metadata(array(
297
			"metadata_name" => "wire_thread",
298
			"metadata_value" => $wire_post->wire_thread,
299
			"type" => "object",
300
			"subtype" => "thewire",
301
			"owner_guid" => $user_entity->guid
302
		));
303
		$wire_post->replied = count($replied) > 0;
304
305
		$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
306
		$wire_post->description = wire_filter($wire_post->description);
307
	}
308
309
	return $wire_posts;
310
}
@@ 331-376 (lines=46) @@
328
	));
329
	$wire_posts = json_decode($all_wire_posts);
330
331
	foreach( $wire_posts as $wire_post ){
332
		$wire_post_obj = get_entity($wire_post->guid);
333
334
		$reshare = $wire_post_obj->getEntitiesFromRelationship(array("relationship" => "reshare", "limit" => 1))[0];
335
336
		$url = "";
337
		if( !empty( $reshare ) ){
338
			$url = $reshare->getURL();
339
		}
340
341
		$text = "";
342
		if ( !empty($reshare->title) ) {
343
			$text = $reshare->title;
344
		} else if ( !empty($reshare->name) ) {
345
			$text = $reshare->name;
346
		} else if ( !empty($reshare->description) ) {
347
			$text = elgg_get_excerpt($reshare->description, 140);
348
		}
349
350
		$wire_post->shareURL = $url;
351
		$wire_post->shareText = gc_explode_translation($text, $lang);
352
353
		$likes = elgg_get_annotations(array(
354
			'guid' => $wire_post->guid,
355
			'annotation_name' => 'likes'
356
		));
357
		$wire_post->likes = count($likes);
358
359
		$liked = elgg_get_annotations(array(
360
			'guid' => $wire_post->guid,
361
			'annotation_owner_guid' => $user_entity->guid,
362
			'annotation_name' => 'likes'
363
		));
364
		$wire_post->liked = count($liked) > 0;
365
366
		$replied = elgg_get_entities_from_metadata(array(
367
			"metadata_name" => "wire_thread",
368
			"metadata_value" => $wire_post->wire_thread,
369
			"type" => "object",
370
			"subtype" => "thewire",
371
			'owner_guid' => $user_entity->guid
372
		));
373
		$wire_post->replied = count($replied) > 0;
374
375
		$wire_post->userDetails = get_user_block($wire_post->owner_guid, $lang);
376
		$wire_post->description = wire_filter($wire_post->description);
377
	}
378
379
	return $wire_posts;