]> git.mxchange.org Git - friendica.git/blobdiff - include/enotify.php
Issue 6603: Events are now fetchable via AP
[friendica.git] / include / enotify.php
index f0b3dd7c0eb6786e6e26570c3b703f8251c73603..58e1a75f00a830c64de414c5ca5c13f8c9d0f7b2 100644 (file)
@@ -11,8 +11,8 @@ use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
-use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\User;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
 use Friendica\Util\Strings;
@@ -21,10 +21,12 @@ use Friendica\Util\Strings;
  * @brief Creates a notification entry and possibly sends a mail
  *
  * @param array $params Array with the elements:
- *                     uid, item, parent, type, otype, verb, event,
- *                     link, subject, body, to_name, to_email, source_name,
- *                     source_link, activity, preamble, notify_flags,
- *                     language, show_in_notification_page
+ *                      uid, item, parent, type, otype, verb, event,
+ *                      link, subject, body, to_name, to_email, source_name,
+ *                      source_link, activity, preamble, notify_flags,
+ *                      language, show_in_notification_page
+ * @return bool
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function notification($params)
 {
@@ -41,7 +43,7 @@ function notification($params)
 
        if (!DBA::isResult($user)) {
                Logger::log('Unknown user ' . $params['uid']);
-               return;
+               return false;
        }
 
        $params['notify_flags'] = defaults($params, 'notify_flags', $user['notify-flags']);
@@ -76,8 +78,8 @@ function notification($params)
                        ['uid' => $params['uid']]);
 
                // There is no need to create notifications for forum accounts
-               if (!DBA::isResult($user) || in_array($user["page-flags"], [Contact::PAGE_COMMUNITY, Contact::PAGE_PRVGROUP])) {
-                       return;
+               if (!DBA::isResult($user) || in_array($user["page-flags"], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) {
+                       return false;
                }
                $nickname = $user["nickname"];
        } else {
@@ -118,6 +120,12 @@ function notification($params)
        }
 
        $epreamble = '';
+       $preamble  = '';
+       $subject   = '';
+       $sitelink  = '';
+       $tsitelink = '';
+       $hsitelink = '';
+       $itemlink  = '';
 
        if ($params['type'] == NOTIFY_MAIL) {
                $itemlink = $siteurl.'/message/'.$params['item']['id'];
@@ -138,7 +146,7 @@ function notification($params)
                if (DBA::isResult($thread) && $thread['ignored']) {
                        Logger::log('Thread ' . $parent_id . ' will be ignored', Logger::DEBUG);
                        L10n::popLang();
-                       return;
+                       return false;
                }
 
                // Check to see if there was already a tag notify or comment notify for this post.
@@ -147,7 +155,7 @@ function notification($params)
                        'link' => $params['link'], 'uid' => $params['uid']];
                if (DBA::exists('notify', $condition)) {
                        L10n::popLang();
-                       return;
+                       return false;
                }
 
                // if it's a post figure out who's post it is.
@@ -451,10 +459,6 @@ function notification($params)
 
                $body =  $params['body'];
 
-               $sitelink = "";
-               $tsitelink = "";
-               $hsitelink = "";
-               $itemlink =  "";
                $show_in_notification_page = false;
        }
 
@@ -485,6 +489,8 @@ function notification($params)
        $hsitelink = $h['hsitelink'];
        $itemlink  = $h['itemlink'];
 
+       $notify_id = 0;
+
        if ($show_in_notification_page) {
                Logger::log("adding notification entry", Logger::DEBUG);
                do {
@@ -516,7 +522,7 @@ function notification($params)
 
                if ($datarray['abort']) {
                        L10n::popLang();
-                       return False;
+                       return false;
                }
 
                // create notification entry in DB
@@ -665,8 +671,7 @@ function notification($params)
 
                L10n::popLang();
                // use the Emailer class to send the message
-               return Emailer::send(
-                       [
+               return Emailer::send([
                        'uid' => $params['uid'],
                        'fromName' => $sender_name,
                        'fromEmail' => $sender_email,
@@ -675,8 +680,8 @@ function notification($params)
                        'messageSubject' => $datarray['subject'],
                        'htmlVersion' => $email_html_body,
                        'textVersion' => $email_text_body,
-                       'additionalMailHeader' => $datarray['headers']]
-               );
+                       'additionalMailHeader' => $datarray['headers']
+               ]);
        }
 
        L10n::popLang();
@@ -687,6 +692,7 @@ function notification($params)
  * @brief Checks for users who should be notified
  *
  * @param int $itemid ID of the item for which the check should be done
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function check_user_notification($itemid) {
        // fetch all users in the thread
@@ -702,9 +708,11 @@ function check_user_notification($itemid) {
 /**
  * @brief Checks for item related notifications and sends them
  *
- * @param int $itemid ID of the item for which the check should be done
- * @param int $uid User ID
+ * @param int    $itemid      ID of the item for which the check should be done
+ * @param int    $uid         User ID
  * @param string $defaulttype (Optional) Forces a notification with this type.
+ * @return bool
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
  */
 function check_item_notification($itemid, $uid, $defaulttype = "") {
        $notification_data = ["uid" => $uid, "profiles" => []];
@@ -769,7 +777,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
        $item = Item::selectFirst($fields, $condition);
        if (!DBA::isResult($item) || in_array($item['author-id'], $contacts)) {
-               return;
+               return false;
        }
 
        // Generate the notification array