| Conditions | 42 |
| Paths | 2268 |
| Total Lines | 431 |
| Lines | 186 |
| Ratio | 43.16 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 164 | function create_digest($invoked_by, $subtype, $entity, $send_to, $entity_url = '') { |
||
| 165 | |||
| 166 | if (elgg_is_active_plugin('wet4')) elgg_load_library('GCconnex_display_in_language'); |
||
| 167 | elgg_load_library('elgg:gc_notification:functions'); |
||
| 168 | |||
| 169 | $digest = get_entity($send_to->cpn_newsletter); |
||
| 170 | $digest_collection = json_decode($digest->description,true); |
||
| 171 | |||
| 172 | // default title value |
||
| 173 | $content_title = $entity->title; |
||
| 174 | |||
| 175 | if (!$entity->title && ($subtype !== 'single_zip_file_upload' && $subtype !== 'multi_file_upload')) $entity = get_entity($entity->guid); |
||
| 176 | |||
| 177 | if ($entity instanceof ElggObject) { |
||
| 178 | $content_url = (!$entity_url) ? $entity->getURL() : $entity_url; |
||
| 179 | |||
| 180 | if (isJson($entity->title)) |
||
| 181 | { |
||
| 182 | $content_title = json_decode($entity->title, true); |
||
| 183 | |||
| 184 | } else { |
||
| 185 | |||
| 186 | if ($entity->title2) |
||
|
|
|||
| 187 | $content_title = array('en' => $entity->title, 'fr' => $entity->title2); |
||
| 188 | else |
||
| 189 | $content_title = array('en' => $entity->title, 'fr' => $entity->title); |
||
| 190 | |||
| 191 | } |
||
| 192 | |||
| 193 | $content_array = array( |
||
| 194 | 'content_title' => $content_title, |
||
| 195 | 'content_url' => $content_url."?utm_source=notification_digest&utm_medium=email", |
||
| 196 | 'subtype' => $entity->getSubtype(), |
||
| 197 | 'content_author_name' => $invoked_by->name, |
||
| 198 | 'content_author_url' => $invoked_by->getURL()."?utm_source=notification_digest&utm_medium=email" |
||
| 199 | ); |
||
| 200 | |||
| 201 | } else { |
||
| 202 | |||
| 203 | $content_array = array( |
||
| 204 | 'content_title' => 'colleague requests', |
||
| 205 | 'content_url' => $entity, |
||
| 206 | 'subtype' => $subtype |
||
| 207 | ); |
||
| 208 | |||
| 209 | } |
||
| 210 | |||
| 211 | if ($subtype === "hjforumcategory" || $subtype === "hjforum") return true; |
||
| 212 | |||
| 213 | |||
| 214 | switch ($subtype) { |
||
| 215 | |||
| 216 | View Code Duplication | case 'single_zip_file_upload': |
|
| 217 | $file_entity = get_entity($entity[0]); |
||
| 218 | $container = $file_entity->getContainerEntity(); |
||
| 219 | $file_count = 0; |
||
| 220 | |||
| 221 | $display_files = "<p><ol>"; |
||
| 222 | foreach ($entity as $file_num => $file) { |
||
| 223 | $file_count++; |
||
| 224 | $file_entity = get_entity($file); |
||
| 225 | $display_files .= "<li><a href='{$file_entity->getURL()}?utm_source=notification_digest&utm_medium=email'>{$file_entity->title}</a></li>"; |
||
| 226 | } |
||
| 227 | $display_files .= "</ol></p>"; |
||
| 228 | $content_array = array( |
||
| 229 | 'file_count' => $file_count, |
||
| 230 | 'content_title' => $display_files, |
||
| 231 | 'subtype' => 'file_upload', |
||
| 232 | 'content_author_name' => $file_entity->getOwnerEntity()->name, |
||
| 233 | 'content_author_url' => $file_entity->getOwnerEntity()->getURL() |
||
| 234 | ); |
||
| 235 | |||
| 236 | if ($container instanceof ElggUser) { |
||
| 237 | $entity_guid = $file_entity->getGUID(); |
||
| 238 | $user_guid = $send_to->getGUID(); |
||
| 239 | $entry_type = 'personal'; |
||
| 240 | $group_name = NULL; |
||
| 241 | $action_type = 'new_post'; |
||
| 242 | $notification_entry = json_encode($content_array); |
||
| 243 | } else { |
||
| 244 | $entity_guid = $file_entity->getGUID(); |
||
| 245 | $user_guid = $send_to->getGUID(); |
||
| 246 | $entry_type = 'group'; |
||
| 247 | $group_name = $container->name; |
||
| 248 | $action_type = 'new_post'; |
||
| 249 | $notification_entry = json_encode($content_array); |
||
| 250 | } |
||
| 251 | break; |
||
| 252 | |||
| 253 | View Code Duplication | case 'multi_file_upload': |
|
| 254 | |||
| 255 | $file_entity = get_entity($entity[0]); |
||
| 256 | $container = $file_entity->getContainerEntity(); |
||
| 257 | $file_count = 0; |
||
| 258 | |||
| 259 | $display_files = "<p><ol>"; |
||
| 260 | foreach ($entity as $file_num => $file) { |
||
| 261 | $file_count++; |
||
| 262 | $file_entity = get_entity($file); |
||
| 263 | $display_files .= "<li><a href='{$file_entity->getURL()}?utm_source=notification_digest&utm_medium=email'>{$file_entity->title}</a></li>"; |
||
| 264 | } |
||
| 265 | |||
| 266 | $display_files .= "</ol></p>"; |
||
| 267 | $content_array = array( |
||
| 268 | 'file_count' => $file_count, |
||
| 269 | 'content_title' => $display_files, |
||
| 270 | 'subtype' => 'file_upload', |
||
| 271 | 'content_author_name' => $file_entity->getOwnerEntity()->name, |
||
| 272 | 'content_author_url' => $file_entity->getOwnerEntity()->getURL() |
||
| 273 | ); |
||
| 274 | |||
| 275 | if ($container instanceof ElggUser) { |
||
| 276 | $entity_guid = $file_entity->getGUID(); |
||
| 277 | $user_guid = $send_to->getGUID(); |
||
| 278 | $entry_type = 'personal'; |
||
| 279 | $group_name = NULL; |
||
| 280 | $action_type = 'new_post'; |
||
| 281 | $notification_entry = json_encode($content_array); |
||
| 282 | } else { |
||
| 283 | $entity_guid = $file_entity->getGUID(); |
||
| 284 | $user_guid = $send_to->getGUID(); |
||
| 285 | $entry_type = 'group'; |
||
| 286 | $group_name = $container->name; |
||
| 287 | $action_type = 'new_post'; |
||
| 288 | $notification_entry = json_encode($content_array); |
||
| 289 | } |
||
| 290 | |||
| 291 | break; |
||
| 292 | |||
| 293 | case 'thewire': |
||
| 294 | $content_array = array( |
||
| 295 | 'content_description' => $entity->description, |
||
| 296 | 'content_url' => $content_url."?utm_source=notification_digest&utm_medium=email", |
||
| 297 | 'subtype' => $entity->getSubtype(), |
||
| 298 | 'content_author_name' => $invoked_by->name, |
||
| 299 | 'content_author_url' => $invoked_by->getURL(), |
||
| 300 | 'entity' => $entity |
||
| 301 | ); |
||
| 302 | |||
| 303 | $entity_guid = $entity->guid; |
||
| 304 | $user_guid = $send_to->getGUID(); |
||
| 305 | $entry_type = 'personal'; |
||
| 306 | $group_name = NULL; |
||
| 307 | $action_type = 'new_post'; |
||
| 308 | $notification_entry = json_encode($content_array); |
||
| 309 | break; |
||
| 310 | |||
| 311 | View Code Duplication | case 'mission': |
|
| 312 | |||
| 313 | $content_array = array( |
||
| 314 | 'content_title' => $entity->title, |
||
| 315 | 'content_author_name' => $entity->getOwnerEntity()->name, |
||
| 316 | 'content_url' => $entity->getURL()."?utm_source=notification_digest&utm_medium=email", |
||
| 317 | 'subtype' => $entity->job_type, |
||
| 318 | 'deadline' => $entity->deadline |
||
| 319 | ); |
||
| 320 | |||
| 321 | $entity_guid = $entity->guid; |
||
| 322 | $user_guid = $send_to->getGUID(); |
||
| 323 | $entry_type = 'mission'; |
||
| 324 | $group_name = NULL; |
||
| 325 | $action_type = 'new_post'; |
||
| 326 | $notification_entry = json_encode($content_array); |
||
| 327 | break; |
||
| 328 | |||
| 329 | case 'comment': |
||
| 330 | case 'discussion_reply': |
||
| 331 | |||
| 332 | |||
| 333 | View Code Duplication | if ($entity->getContainerEntity() instanceof ElggGroup) { |
|
| 334 | |||
| 335 | // string that will contain the url and the (json) string name of group |
||
| 336 | $group_html = json_encode(array($entity->getContainerEntity()->getURL(), $entity->getContainerEntity()->name)); |
||
| 337 | $entity_guid = $entity->guid; |
||
| 338 | $user_guid = $send_to->getGUID(); |
||
| 339 | $entry_type = 'group'; |
||
| 340 | $group_name = $group_html; |
||
| 341 | $action_type = 'response'; |
||
| 342 | $notification_entry = json_encode($content_array); |
||
| 343 | |||
| 344 | } else { |
||
| 345 | |||
| 346 | $entity_guid = $entity->guid; |
||
| 347 | $user_guid = $send_to->getGUID(); |
||
| 348 | $entry_type = 'personal'; |
||
| 349 | $group_name = NULL; |
||
| 350 | $action_type = 'response'; |
||
| 351 | $notification_entry = json_encode($content_array); |
||
| 352 | } |
||
| 353 | break; |
||
| 354 | |||
| 355 | View Code Duplication | case 'cp_friend_request': |
|
| 356 | |||
| 357 | $entity_guid = $invoked_by->guid; |
||
| 358 | $user_guid = $send_to->getGUID(); |
||
| 359 | $entry_type = 'personal'; |
||
| 360 | $group_name = NULL; |
||
| 361 | $action_type = 'friend_request'; |
||
| 362 | $notification_entry = json_encode($content_array); |
||
| 363 | |||
| 364 | break; |
||
| 365 | |||
| 366 | View Code Duplication | case 'cp_friend_approve': |
|
| 367 | |||
| 368 | $entity_guid = $invoked_by->guid; |
||
| 369 | $user_guid = $send_to->getGUID(); |
||
| 370 | $entry_type = 'personal'; |
||
| 371 | $group_name = NULL; |
||
| 372 | $action_type = 'friend_approved'; |
||
| 373 | $notification_entry = json_encode($content_array); |
||
| 374 | break; |
||
| 375 | |||
| 376 | case 'cp_hjtopic': |
||
| 377 | case 'cp_hjpost': |
||
| 378 | |||
| 379 | $group_html = json_encode(array(get_entity(get_forum_in_group($entity->guid, $entity->guid))->getURL(), get_entity(get_forum_in_group($entity->guid, $entity->guid))->name)); |
||
| 380 | |||
| 381 | if ($subtype === 'cp_hjtopic') { |
||
| 382 | |||
| 383 | $entity_guid = $entity->guid; |
||
| 384 | $user_guid = $send_to->getGUID(); |
||
| 385 | $entry_type = 'group'; |
||
| 386 | $group_name = $group_html; |
||
| 387 | $action_type = 'forum_topic'; |
||
| 388 | $notification_entry = json_encode($content_array); |
||
| 389 | |||
| 390 | } else { |
||
| 391 | |||
| 392 | $content_array = array( |
||
| 393 | 'content_title' => $entity->getContainerEntity()->title, |
||
| 394 | 'content_url' => $content_url."?utm_source=notification_digest&utm_medium=email", |
||
| 395 | 'subtype' => $entity->getSubtype(), |
||
| 396 | 'content_author' => $entity->getOwnerEntity()->guid |
||
| 397 | ); |
||
| 398 | |||
| 399 | $entity_guid = $entity->guid; |
||
| 400 | $user_guid = $send_to->getGUID(); |
||
| 401 | $entry_type = 'group'; |
||
| 402 | $group_name = $group_html; |
||
| 403 | $action_type = 'forum_reply'; |
||
| 404 | $notification_entry = json_encode($content_array); |
||
| 405 | |||
| 406 | } |
||
| 407 | break; |
||
| 408 | |||
| 409 | |||
| 410 | case 'like_comment': |
||
| 411 | case 'like_reply': |
||
| 412 | case 'post_likes': |
||
| 413 | |||
| 414 | if ($subtype === "like_comment" || $subtype === "like_reply") { |
||
| 415 | $content_title = $entity->getContainerEntity()->title; |
||
| 416 | $content_array = array( |
||
| 417 | 'content_title' => $content_title, |
||
| 418 | 'content_url' => $entity->getURL()."?utm_source=notification_digest&utm_medium=email", |
||
| 419 | 'subtype' => $entity->getSubtype(), |
||
| 420 | 'content_author_name' => $invoked_by->name, |
||
| 421 | 'content_author_url' => $invoked_by->getURL() |
||
| 422 | ); |
||
| 423 | |||
| 424 | |||
| 425 | } elseif ($entity->getSubtype() === 'thewire') { |
||
| 426 | |||
| 427 | $content_array = array( |
||
| 428 | 'content_title' => $entity->description, |
||
| 429 | 'content_url' => $entity->getURL()."?utm_source=notification_digest&utm_medium=email", |
||
| 430 | 'subtype' => $entity->getSubtype(), |
||
| 431 | 'content_author_name' => $invoked_by->name, |
||
| 432 | 'content_author_url' => $invoked_by->getURL() |
||
| 433 | ); |
||
| 434 | |||
| 435 | } else { |
||
| 436 | $entity_title = $entity->title; |
||
| 437 | if ($entity->title == '') |
||
| 438 | $entity_title = $entity->name; |
||
| 439 | |||
| 440 | $content_array = array( |
||
| 441 | 'content_title' => $entity_title, |
||
| 442 | 'content_url' => $entity->getURL()."?utm_source=notification_digest&utm_medium=email", |
||
| 443 | 'subtype' => $entity->getSubtype(), |
||
| 444 | 'content_author_name' => $invoked_by->name, |
||
| 445 | 'content_author_url' => $invoked_by->getURL() |
||
| 446 | ); |
||
| 447 | } |
||
| 448 | |||
| 449 | $entity_guid = $entity->guid; |
||
| 450 | $user_guid = $send_to->getGUID(); |
||
| 451 | $entry_type = 'personal'; |
||
| 452 | $group_name = NULL; |
||
| 453 | $action_type = 'likes'; |
||
| 454 | $notification_entry = json_encode($content_array); |
||
| 455 | break; |
||
| 456 | |||
| 457 | |||
| 458 | case 'content_revision': |
||
| 459 | |||
| 460 | $entity_guid = $entity->guid; |
||
| 461 | $user_guid = $send_to->getGUID(); |
||
| 462 | $entry_type = 'personal'; |
||
| 463 | $group_name = NULL; |
||
| 464 | $action_type = 'content_revision'; |
||
| 465 | $notification_entry = json_encode($content_array); |
||
| 466 | break; |
||
| 467 | |||
| 468 | case 'cp_wire_share': |
||
| 469 | |||
| 470 | $content_title = $entity->title; |
||
| 471 | if (!$entity->title) $content_title = $entity->description; |
||
| 472 | |||
| 473 | $content_array = array( |
||
| 474 | 'content_title' => $content_title, |
||
| 475 | 'content_url' => $entity->getURL()."?utm_source=notification_digest&utm_medium=email", |
||
| 476 | 'subtype' => $entity->getSubtype(), |
||
| 477 | 'content_author_name' => $invoked_by->name, |
||
| 478 | 'content_author_url' => $invoked_by->getURL() |
||
| 479 | ); |
||
| 480 | |||
| 481 | $entity_guid = $entity->guid; |
||
| 482 | $user_guid = $send_to->getGUID(); |
||
| 483 | $entry_type = 'personal'; |
||
| 484 | $group_name = NULL; |
||
| 485 | $action_type = 'cp_wire_share'; |
||
| 486 | $notification_entry = json_encode($content_array); |
||
| 487 | break; |
||
| 488 | |||
| 489 | View Code Duplication | case 'cp_wire_image': |
|
| 490 | |||
| 491 | $content_array = array( |
||
| 492 | 'content_description' => $entity->description, |
||
| 493 | 'content_url' => $content_url."?utm_source=notification_digest&utm_medium=email", |
||
| 494 | 'subtype' => $entity->getSubtype(), |
||
| 495 | 'content_author_name' => $invoked_by->name, |
||
| 496 | 'content_author_url' => $invoked_by->getURL(), |
||
| 497 | 'wire_image' => thewire_image_get_attachments($entity->guid), |
||
| 498 | ); |
||
| 499 | |||
| 500 | $entity_guid = $entity->guid; |
||
| 501 | $user_guid = $send_to->getGUID(); |
||
| 502 | $entry_type = 'personal'; |
||
| 503 | $group_name = NULL; |
||
| 504 | $action_type = 'new_post'; |
||
| 505 | $notification_entry = json_encode($content_array); |
||
| 506 | break; |
||
| 507 | |||
| 508 | case 'cp_wire_mention': |
||
| 509 | |||
| 510 | $content_array = array( |
||
| 511 | 'content_url' => $entity->getURL()."?utm_source=notification_digest&utm_medium=email", |
||
| 512 | 'subtype' => 'wire_mention', |
||
| 513 | 'content_author' => $invoked_by->name, |
||
| 514 | 'content_author_url' => $invoked_by->getURL(), |
||
| 515 | ); |
||
| 516 | |||
| 517 | $entity_guid = $entity->guid; |
||
| 518 | $user_guid = $send_to->getGUID(); |
||
| 519 | $entry_type = 'personal'; |
||
| 520 | $group_name = NULL; |
||
| 521 | $action_type = 'mention'; |
||
| 522 | $notification_entry = json_encode($content_array); |
||
| 523 | |||
| 524 | break; |
||
| 525 | |||
| 526 | View Code Duplication | case 'cp_mention': |
|
| 527 | |||
| 528 | $content_array = array( |
||
| 529 | 'content_title' => $entity->getContainerEntity()->title, |
||
| 530 | 'content_url' => $content_url."?utm_source=notification_digest&utm_medium=email", |
||
| 531 | 'subtype' => $entity->getContainerEntity()->getSubtype(), |
||
| 532 | 'content_author' => $invoked_by->name, |
||
| 533 | 'content_author_url' => $invoked_by->getURL() |
||
| 534 | ); |
||
| 535 | |||
| 536 | $entity_guid = $entity->guid; |
||
| 537 | $user_guid = $send_to->getGUID(); |
||
| 538 | $entry_type = 'personal'; |
||
| 539 | $group_name = NULL; |
||
| 540 | $action_type = 'mention'; |
||
| 541 | $notification_entry = json_encode($content_array); |
||
| 542 | break; |
||
| 543 | |||
| 544 | default: |
||
| 545 | |||
| 546 | $entity = get_entity($entity->guid); |
||
| 547 | |||
| 548 | View Code Duplication | if ($entity->getContainerEntity() instanceof ElggGroup) { |
|
| 549 | |||
| 550 | $group_title = $entity->getContainerEntity()->name; |
||
| 551 | $group_html = json_encode(array($entity->getContainerEntity()->getURL(), $group_title)); |
||
| 552 | |||
| 553 | $entity_guid = $entity->guid; |
||
| 554 | $user_guid = $send_to->getGUID(); |
||
| 555 | $entry_type = 'group'; |
||
| 556 | $group_name = $group_html;//"<a href='{$entity->getContainerEntity()->getURL()}?utm_source=notification_digest&utm_medium=email'>{$group_title}</a>"; |
||
| 557 | $action_type = 'new_post'; |
||
| 558 | $notification_entry = json_encode($content_array); |
||
| 559 | |||
| 560 | } |
||
| 561 | else { |
||
| 562 | $entity_guid = $entity->guid; |
||
| 563 | $user_guid = $send_to->getGUID(); |
||
| 564 | $entry_type = 'personal'; |
||
| 565 | $group_name = NULL; |
||
| 566 | $action_type = 'new_post'; |
||
| 567 | $notification_entry = json_encode($content_array); |
||
| 568 | } |
||
| 569 | |||
| 570 | break; |
||
| 571 | } |
||
| 572 | |||
| 573 | // this will fix up/sanitize strings that may contain quotes, or any other (reserved) special character |
||
| 574 | $group_name = base64_encode($group_name); |
||
| 575 | $notification_entry = base64_encode($notification_entry); |
||
| 576 | |||
| 577 | /// check if record exists already, if not then proceed. |
||
| 578 | $query = "SELECT 1 FROM notification_digest WHERE entity_guid = {$entity_guid} AND user_guid = {$user_guid} AND notification_entry = '{$notification_entry}' LIMIT 1"; |
||
| 579 | $count_row = get_data($query); |
||
| 580 | |||
| 581 | if (count($count_row) <= 0) { |
||
| 582 | /// save, then transform the information to the database (notification_digest table) |
||
| 583 | $user_guid = mysql_real_escape_string($user_guid); |
||
| 584 | $entry_type = mysql_real_escape_string($entry_type); |
||
| 585 | $action_type = mysql_real_escape_string($action_type); |
||
| 586 | |||
| 587 | $query = "INSERT INTO notification_digest ( entity_guid, user_guid, entry_type, group_name, action_type, notification_entry ) VALUES ( {$entity_guid}, '{$user_guid}', '{$entry_type}', '{$group_name}', '{$action_type}', '{$notification_entry}' )"; |
||
| 588 | |||
| 589 | $insert_row = insert_data($query); |
||
| 590 | } |
||
| 591 | |||
| 592 | |||
| 593 | return true; |
||
| 594 | } |
||
| 595 | |||
| 1005 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.