Completed
Pull Request — master (#1886)
by
unknown
34:17 queued 15:28
created

blog.php ➔ get_blogposts_by_owner()   C

Complexity

Conditions 13
Paths 136

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
nc 136
nop 6
dl 0
loc 57
rs 6.3166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * Exposes API endpoints for Blog entities
4
 */
5
6
elgg_ws_expose_function(
7
	"get.blogpost",
8
	"get_blogpost",
9
	array(
10
		"user" => array('type' => 'string', 'required' => true),
11
		"guid" => array('type' => 'int', 'required' => true),
12
		"lang" => array('type' => 'string', 'required' => false, 'default' => "en")
13
	),
14
	'Retrieves a blog post & all replies based on user id and blog post id',
15
	'POST',
16
	true,
17
	false
18
);
19
20
elgg_ws_expose_function(
21
	"get.blogposts",
22
	"get_blogposts",
23
	array(
24
		"user" => array('type' => 'string', 'required' => true),
25
		"limit" => array('type' => 'int', 'required' => false, 'default' => 10),
26
		"offset" => array('type' => 'int', 'required' => false, 'default' => 0),
27
		"filters" => array('type' => 'string', 'required' => false, 'default' => ""),
28
		"lang" => array('type' => 'string', 'required' => false, 'default' => "en")
29
	),
30
	'Retrieves blog posts & all replies based on user id',
31
	'POST',
32
	true,
33
	false
34
);
35
36
elgg_ws_expose_function(
37
	"get.blogpostsbyowner",
38
	"get_blogposts_by_owner",
39
	array(
40
		"user" => array('type' => 'string', 'required' => true),
41
		"limit" => array('type' => 'int', 'required' => false, 'default' => 10),
42
		"offset" => array('type' => 'int', 'required' => false, 'default' => 0),
43
		"filters" => array('type' => 'string', 'required' => false, 'default' => ""),
44
		"lang" => array('type' => 'string', 'required' => false, 'default' => "en"),
45
		"target" => array('type' => 'string', 'required'=> false, 'default' => '')
46
	),
47
	'Retrieves blog posts & all replies based on user id',
48
	'POST',
49
	true,
50
	false
51
);
52
53
elgg_ws_expose_function(
54
 "get.blogpostsbycolleague",
55
 "get_blogposts_by_colleague",
56
 array(
57
	"user" => array('type' => 'string', 'required' => true),
58
	"limit" => array('type' => 'int', 'required' => false, 'default' => 10),
59
	"offset" => array('type' => 'int', 'required' => false, 'default' => 0),
60
	"filters" => array('type' => 'string', 'required' => false, 'default' => ""),
61
	"lang" => array('type' => 'string', 'required' => false, 'default' => "en")
62
 ),
63
 'Retrieves a container\'s blogs based on user id and container guid. Used for groups, as a group\'s blogs have container_id of the group.',
64
 'POST',
65
 true,
66
 false
67
);
68
69
elgg_ws_expose_function(
70
 "get.blogpostsbycontainer",
71
 "get_blogposts_by_container",
72
 array(
73
	 "user" => array('type' => 'string', 'required' => true),
74
	 "guid" => array('type' => 'int', 'required' => true),
75
	 "limit" => array('type' => 'int', 'required' => false, 'default' => 10),
76
	 "offset" => array('type' => 'int', 'required' => false, 'default' => 0),
77
	 "lang" => array('type' => 'string', 'required' => false, 'default' => "en")
78
 ),
79
 'Retrieves a container\'s blogs based on user id and container guid. Used for groups, as a group\'s blogs have container_id of the group.',
80
 'POST',
81
 true,
82
 false
83
);
84
85
elgg_ws_expose_function(
86
 "get.blogedit",
87
 "get_blog_edit",
88
 array(
89
	 "user" => array('type' => 'string', 'required' => true),
90
	 "guid" => array('type' => 'int', 'required' => true),
91
	 "lang" => array('type' => 'string', 'required' => false, 'default' => "en")
92
 ),
93
 'Retrieves a blog post based on user id and blog post id, with only info needed for edit form',
94
 'POST',
95
 true,
96
 false
97
);
98
99
elgg_ws_expose_function(
100
 "save.blog",
101
 "save_blog",
102
 array(
103
	 "user" => array('type' => 'string', 'required' => true),
104
	 "title" => array('type' => 'string', 'required' => true),
105
	 "excerpt" => array('type' =>'string', 'required' => false, 'default' => ''),
106
	 "body" => array('type' =>'string', 'required' => true),
107
	 "container_guid" => array('type' =>'string', 'required' => false, 'default' => ''),
108
	 "blog_guid" => array('type' =>'string', 'required' => false, 'default' => ''),
109
	 "comments" => array('type' =>'int', 'required' => false, 'default' => 1),
110
	 "access" => array('type' =>'int', 'required' => false, 'default' => 1),
111
	 "status" => array('type' =>'int', 'required' => false, 'default' => 0),
112
	 "lang" => array('type' => 'string', 'required' => false, 'default' => "en")
113
 ),
114
 'Posts/Saves a blog post',
115
 'POST',
116
 true,
117
 false
118
);
119
120
function foreach_blogs($blogs, $user_entity, $lang)
121
{
122
	foreach ($blogs as $blog_post) {
123
		$blog_post->title = gc_explode_translation($blog_post->title, $lang);
124
		$blog_post->description = gc_explode_translation($blog_post->description, $lang);
125
126
		$likes = elgg_get_annotations(array(
127
			'guid' => $blog_post->guid,
128
			'annotation_name' => 'likes'
129
		));
130
		$blog_post->likes = count($likes);
131
132
		$liked = elgg_get_annotations(array(
133
			'guid' => $blog_post->guid,
134
			'annotation_owner_guid' => $user_entity->guid,
135
			'annotation_name' => 'likes'
136
		));
137
		$blog_post->liked = count($liked) > 0;
138
139
		$blog_post->comments = get_entity_comments($blog_post->guid);
140
141
		$blog_post->userDetails = get_user_block($blog_post->owner_guid, $lang);
142
143
		$group = get_entity($blog_post->container_guid);
144
		$blog_post->group = gc_explode_translation($group->name, $lang);
145
146
		if (is_callable(array($group, 'getURL'))) {
147
			$blog_post->groupURL = $group->getURL();
148
		}
149
	}
150
	return $blogs;
151
}
152
153
function get_blogpost($user, $guid, $lang)
154
{
155
	$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
156
	if (!$user_entity) {
157
		return "User was not found. Please try a different GUID, username, or email address";
158
	}
159
	if (!$user_entity instanceof ElggUser) {
160
		return "Invalid user. Please try a different GUID, username, or email address";
161
	}
162
163
	$entity = get_entity($guid);
164
	if (!isset($entity)) {
165
		return "Blog was not found. Please try a different GUID";
166
	}
167
168
	if (!elgg_is_logged_in()) {
169
		login($user_entity);
170
	}
171
172
	$blog_posts = elgg_list_entities(array(
173
		'type' => 'object',
174
		'subtype' => 'blog',
175
		'guid' => $guid
176
	));
177
	$blog_post = json_decode($blog_posts)[0];
178
179
	$blog_post->title = gc_explode_translation($blog_post->title, $lang);
180
	$blog_post->description = gc_explode_translation($blog_post->description, $lang);
181
182
	$likes = elgg_get_annotations(array(
183
		'guid' => $blog_post->guid,
184
		'annotation_name' => 'likes'
185
	));
186
	$blog_post->likes = count($likes);
187
188
	$liked = elgg_get_annotations(array(
189
		'guid' => $blog_post->guid,
190
		'annotation_owner_guid' => $user_entity->guid,
191
		'annotation_name' => 'likes'
192
	));
193
	$blog_post->liked = count($liked) > 0;
194
195
	$blog_post->comments = get_entity_comments($blog_post->guid);
196
197
	$blog_post->userDetails = get_user_block($blog_post->owner_guid, $lang);
198
199
	$group = get_entity($blog_post->container_guid);
200
	$blog_post->group = gc_explode_translation($group->name, $lang);
201
202
	if (is_callable(array($group, 'getURL'))) {
203
		$blog_post->groupURL = $group->getURL();
204
	}
205
206
	return $blog_post;
207
}
208
209
function get_blogposts($user, $limit, $offset, $filters, $lang)
210
{
211
	$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
212
	if (!$user_entity) {
213
		return "User was not found. Please try a different GUID, username, or email address";
214
	}
215
	if (!$user_entity instanceof ElggUser) {
216
		return "Invalid user. Please try a different GUID, username, or email address";
217
	}
218
219
	if (!elgg_is_logged_in()) {
220
		login($user_entity);
221
	}
222
223
	$filter_data = json_decode($filters);
224
	if (!empty($filter_data)) {
225
		$params = array(
226
			'type' => 'object',
227
			'subtype' => 'blog',
228
			'limit' => $limit,
229
			'offset' => $offset
230
		);
231
232
		if ($filter_data->name) {
233
			$db_prefix = elgg_get_config('dbprefix');
234
			$params['joins'] = array("JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid");
235
			$params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')");
236
		}
237
238
		$all_blog_posts = elgg_list_entities_from_metadata($params);
239
	} else {
240
		$all_blog_posts = elgg_list_entities(array(
241
			'type' => 'object',
242
			'subtype' => 'blog',
243
			'limit' => $limit,
244
			'offset' => $offset
245
		));
246
	}
247
248
	$blog_posts = json_decode($all_blog_posts);
249
250
	$blogs = foreach_blogs($blog_posts, $user_entity, $lang);
251
252
	return $blogs;
253
}
254
255
function get_blogposts_by_owner($user, $limit, $offset, $filters, $lang, $target)
256
{
257
	$user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
258
	if (!$user_entity) {
259
		return "User was not found. Please try a different GUID, username, or email address";
260
	}
261
	if (!$user_entity instanceof ElggUser) {
262
		return "Invalid user. Please try a different GUID, username, or email address";
263
	}
264
265
	$target_entity = $user_entity;
266
	if (!empty($target)){
267
		$target_entity =  is_numeric($target) ? get_user($target) : (strpos($target, '@') !== false ? get_user_by_email($target)[0] : get_user_by_username($target));
268
		if (!$target_entity) {
269
			return "Target user was not found. Please try a different GUID, username, or email address";
270
		}
271
		if (!$target_entity instanceof ElggUser) {
272
			return "Invalid target user. Please try a different GUID, username, or email address";
273
		}
274
	}
275
276
	if (!elgg_is_logged_in()) {
277
		login($user_entity);
278
	}
279
	$filter_data = json_decode($filters);
280
	if (!empty($filter_data)) {
281
		$params = array(
282
			'type' => 'object',
283
			'subtype' => 'blog',
284
			'owner_guid' => $target_entity->guid,
285
			'limit' => $limit,
286
			'offset' => $offset
287
		);
288
289
		if ($filter_data->name) {
290
			$db_prefix = elgg_get_config('dbprefix');
291
			$params['joins'] = array("JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid");
292
			$params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')");
293
		}
294
295
		$all_blog_posts = elgg_list_entities_from_metadata($params);
296
	} else {
297
		$all_blog_posts = elgg_list_entities(array(
298
			'type' => 'object',
299
			'subtype' => 'blog',
300
			'owner_guid' => $target_entity->guid,
301
			'limit' => $limit,
302
			'offset' => $offset
303
		));
304
	}
305
306
	$blog_posts = json_decode($all_blog_posts);
307
308
	$blogs = foreach_blogs($blog_posts, $user_entity, $lang);
309
310
	return $blogs;
311
}
312
313
function get_blogposts_by_colleague($user, $limit, $offset, $filters, $lang, $target)
314
{
315
 $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
316
 if (!$user_entity) {
317
	 return "User was not found. Please try a different GUID, username, or email address";
318
 }
319
 if (!$user_entity instanceof ElggUser) {
320
	 return "Invalid user. Please try a different GUID, username, or email address";
321
 }
322
323
 if (!elgg_is_logged_in()) {
324
	 login($user_entity);
325
 }
326
327
 $filter_data = json_decode($filters);
328
 if (!empty($filter_data)) {
329
 	$params = array(
330
		'type' => 'object',
331
		'subtype' => 'blog',
332
		'relationship' => 'friend',
333
		'relationship_guid' => $user_entity->guid,
334
		'relationship_join_on' => 'container_guid',
335
		'limit' => $limit,
336
		'offset' => $offset
337
 	);
338
339
 	if ($filter_data->name) {
340
 		$db_prefix = elgg_get_config('dbprefix');
341
 		$params['joins'] = array("INNER JOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid");
342
 		$params['wheres'] = array("(oe.title LIKE '%" . $filter_data->name . "%' OR oe.description LIKE '%" . $filter_data->name . "%')");
343
 	}
344
345
 	$all_blog_posts = elgg_list_entities_from_relationship($params);
346
 } else {
347
	 $all_blog_posts = elgg_list_entities_from_relationship(array(
348
		 'type' => 'object',
349
		 'subtype' => 'blog',
350
		 'relationship' => 'friend',
351
		 'relationship_guid' => $user_entity->guid,
352
		 'relationship_join_on' => 'container_guid',
353
		 'limit' => $limit,
354
		 'offset' => $offset
355
	 ));
356
	}
357
 $blog_posts = json_decode($all_blog_posts);
358
359
 $blogs = foreach_blogs($blog_posts, $user_entity, $lang);
360
361
 return $blogs;
362
}
363
364
365
function get_blogposts_by_container($user, $guid, $limit, $offset, $lang)
366
{
367
 $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
368
 if (!$user_entity) {
369
	 return "User was not found. Please try a different GUID, username, or email address";
370
 }
371
 if (!$user_entity instanceof ElggUser) {
372
	 return "Invalid user. Please try a different GUID, username, or email address";
373
 }
374
 if (!elgg_is_logged_in()) {
375
	 login($user_entity);
376
 }
377
378
 $group = get_entity($guid);
379
 if (!$group) {
380
	 return "Group was not found. Please try a different GUID";
381
 }
382
 if (!$group instanceof ElggGroup) {
383
	 return "Invalid group. Please try a different GUID";
384
 }
385
386
 $all_blog_posts = elgg_list_entities(array(
387
	 'type' => 'object',
388
	 'subtype' => 'blog',
389
	 'container_guid' => $guid,
390
	 'limit' => $limit,
391
	 'offset' => $offset,
392
	 'order_by' => 'e.last_action desc'
393
 ));
394
395
 $blog_posts = json_decode($all_blog_posts);
396
397
 $blogs_final = foreach_blogs($blog_posts, $user_entity, $lang);
398
399
 return $blogs_final;
400
}
401
402
function get_blog_edit($user, $guid, $lang)
403
{
404
 $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
405
 if (!$user_entity) {
406
	 return "User was not found. Please try a different GUID, username, or email address";
407
 }
408
 if (!$user_entity instanceof ElggUser) {
409
	 return "Invalid user. Please try a different GUID, username, or email address";
410
 }
411
412
 $entity = get_entity($guid);
413
 if (!isset($entity)) {
414
	 return "Blog was not found. Please try a different GUID";
415
 }
416
417
 if (!elgg_is_logged_in()) {
418
	 login($user_entity);
419
 }
420
421
 $blog_posts = elgg_list_entities(array(
422
	 'type' => 'object',
423
	 'subtype' => 'blog',
424
	 'guid' => $guid
425
 ));
426
 $blog_post = json_decode($blog_posts)[0];
427
428
 $blog_post->title = json_decode($blog_post->title);
429
 //$blog_post->excerpt = json_decode($blog_post->excerpt); //not correct
430
 $blog_post->description = json_decode($blog_post->description);
431
432
 $container = get_entity($blog_post->container_guid);
433
 if ($container instanceof ElggGroup){
434
	 $blog_post->group->public = $container->isPublicMembership();
435
	 if (!$blog_post->group->public && !$container->isMember($user_entity)){
436
		return elgg_echo('discussion:error:permissions');
437
	 }
438
 }
439
440
 if (is_callable(array($group, 'getURL'))) {
441
	 $blog_post->groupURL = $group->getURL();
0 ignored issues
show
Bug introduced by
The variable $group does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
442
 }
443
444
 return $blog_post;
445
}
446
447
function save_blog($user, $title, $excerpt, $body, $container_guid, $blog_guid, $comments, $access, $status, $lang)
448
{
449
 $user_entity = is_numeric($user) ? get_user($user) : (strpos($user, '@') !== false ? get_user_by_email($user)[0] : get_user_by_username($user));
450
	 if (!$user_entity) {
451
		 return "User was not found. Please try a different GUID, username, or email address";
452
	 }
453
	 if (!$user_entity instanceof ElggUser) {
454
		 return "Invalid user. Please try a different GUID, username, or email address";
455
	 }
456
	 if (!elgg_is_logged_in()) {
457
		 login($user_entity);
458
	 }
459
	 $error = FALSE;
460
	 //check required fields being not empty
461
	 $titles = json_decode($title);
462
	 $bodies = json_decode($body);
463
	 $excerpts = json_decode($excerpt);
464
	 //Check Required
465
	 if (!$titles->en && !$titles->fr) { return elgg_echo("blog:error:missing:title"); }
466
	 if (!$bodies->en && !$bodies->fr) { return elgg_echo("blog:error:missing:description");  }
467 View Code Duplication
	 if (!($titles->en && $bodies->en) && !($titles->fr && $bodies->fr)) { return "require-same-lang"; }
468
	 //Default any Missing or faulty
469
	 if (!$titles->en) { $titles->en = ''; }
470
	 if (!$titles->fr) { $titles->fr = ''; }
471
	 if (!$bodies->en) { $bodies->en = ''; }
472
	 if (!$bodies->fr) { $bodies->fr = ''; }
473
	 if (!$excerpts->en) { $excerpts->en = ''; }
474
	 if (!$excerpts->fr) { $excerpts->fr = ''; }
475
	 if ($comments != 0 && $comments != 1) { $comments = 1; }
476
	 if ($access != 0 && $access != 1 && $access != -2 && $access !=2 ) { $access = 1; }
477
	 if ($status != 0 && $status != 1) { $status = 0; }
478
479
	 // if there is a container_guid, .: group, and access is set to group only, set access to proper group only
480
	 if (!empty($container_guid) && $access == 2){
481
		 $container = get_entity($container_guid);
482
		 //validate container and ability to write to it
483
		 if (!$container || !$container->canWriteToContainer(0, 'object', 'blog')) {
484
 			return elgg_echo('blog:error:cannot_write_to_container');
485
 		} else {
486
			$access = $container->group_acl;
487
		}
488
		 //If no group container, use user guid.
489
	 } else if ($container_guid=='') { $container_guid = $user_entity->guid; }
490
491
	 //Set int variables to correct
492
	 if ($status == 1) { $status = 'published'; } else { $status = 'draft'; }
493
	 if ($comments == 1) { $comments = 'On'; } else { $comments = 'Off'; }
494
	 if ($status == 'draft') { $access = 0; }
495
	 $titles->en = htmlspecialchars($titles->en, ENT_QUOTES, 'UTF-8');
496
	 $titles->fr = htmlspecialchars($titles->fr, ENT_QUOTES, 'UTF-8');
497
	 $excerpts->en = elgg_get_excerpt($excerpts->en);
498
	 $excerpts->fr = elgg_get_excerpt($excerpts->fr);
499
500
	 $values = array(
501
		 'title' => JSON_encode($titles),
502
		 'title2' => '',
503
		 //'title3' => '',
504
		 'description' => JSON_encode($bodies),
505
		 'description2' => '',
506
		 'description3' => '',
507
		 'status' => $status,
508
		 'access_id' => $access,
509
		 'comments_on' => $comments,
510
		 'excerpt' => JSON_encode($excerpts),
511
		 'excerpt2' => '',
512
		 'excerpt3' => '',
513
		 'tags' => '',
514
		 'publication_date' => '',
515
		 'expiration_date' => '',
516
		 'show_owner' => 'no'
517
	 );
518
519
	 $blog = new stdClass();
520
	 $revision_text = '';
521
	 if ($blog_guid){
522
		 $entity = get_entity($blog_guid);
523 View Code Duplication
		 if (elgg_instanceof($entity, 'object', 'blog') && $entity->canEdit()) {
524
			 	$blog = $entity;
525
		 } else {
526
			 return elgg_echo('blog:error:post_not_found');
527
		 }
528
		 $revision_text = $blog->description;
529
		 $new_post = $blog->new_post; //what?
530
	 } else {
531
		 //Create blog
532
		 $blog = new ElggBlog();
533
		 $blog->subtype = 'blog';
534
		 $blog->container_guid = $container_guid;
535
		 $new_post = TRUE;
536
	 }
537
538
	 $old_status = $blog->status;
539
540
	 // assign values to the entity, stopping on error.
541 View Code Duplication
	 if (!$error) {
542
		 foreach ($values as $name => $value) {
543
			 if (($name != 'title2') && ($name != 'description2') &&  ($name != 'excerpt2')){ // remove input 2 in metastring table
544
			 $blog->$name = $value;
545
			 }
546
		 }
547
	 }
548
549
	 if (!$error){
550
		 if ($blog->save()){
551
552
				 $icon_file = get_resized_image_from_uploaded_file("icon", 100, 100);
553
				 $icon_sizes = elgg_get_config("icon_sizes");
554
555 View Code Duplication
				 if (!empty($icon_file) && !empty($icon_sizes)) {
556
					 // create icon
557
					 $prefix = "blogs/" . $blog->getGUID();
558
559
					 $fh = new ElggFile();
560
					 $fh->owner_guid = $blog->getOwnerGUID();
561
562
					 foreach ($icon_sizes as $icon_name => $icon_info) {
563
						 $icon_file = get_resized_image_from_uploaded_file("icon", $icon_info["w"], $icon_info["h"], $icon_info["square"], $icon_info["upscale"]);
564
						 if (!empty($icon_file)) {
565
							 $fh->setFilename($prefix . $icon_name . ".jpg");
566
567
							 if ($fh->open("write")) {
568
								 $fh->write($icon_file);
569
								 $fh->close();
570
							 }
571
						 }
572
					 }
573
574
					 $blog->icontime = time();
575
			 }
576
577
			 // remove autosave draft if exists
578
			 $blog->deleteAnnotations('blog_auto_save');
579
			 // no longer a brand new post.
580
			 $blog->deleteMetadata('new_post');
581
			 if (!$new_post && $revision_text) {
582
				 $blog->annotate('blog_revision', $revision_text);
583
			 }
584
585
			 $status = $blog->status;
586
				 // add to river if changing status or published, regardless of new post
587
				 // because we remove it for drafts.
588
				 if (($new_post || $old_status == 'draft' ||  $old_status == 'published') && $status == 'published') {
589
					 elgg_create_river_item(array(
590
						 'view' => 'river/object/blog/create',
591
						 'action_type' => 'create',
592
						 'subject_guid' => $blog->owner_guid,
593
						 'object_guid' => $blog->getGUID(),
594
					 ));
595
					 // we only want notifications sent when post published
596
					 elgg_trigger_event('publish', 'object', $blog);
0 ignored issues
show
Documentation introduced by
$blog is of type object<ElggEntity>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
597
598
					 // reset the creation time for posts that move from draft to published
599
					 if ($guid) {
0 ignored issues
show
Bug introduced by
The variable $guid does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
600
						 $blog->time_created = time();
601
						 $blog->save();
602
					 }
603
				 } elseif ($old_status == 'published' && $status == 'draft') {
604
					 elgg_delete_river(array(
605
						 'object_guid' => $blog->guid,
606
						 'action_type' => 'create',
607
					 ));
608
				 }
609
				 if ($blog->status == 'published' || $save == false) {
0 ignored issues
show
Bug introduced by
The variable $save does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
610
					 return ($blog->getURL());
611
				 } else {
612
					 return ("blog/edit/$blog->guid");
613
				 }
614
615
		 } else {
616
			 return elgg_echo('blog:error:cannot_save');
617
		 }
618
	 }
619
}
620