-class enotify {
- /**
- * Send a multipart/alternative message with Text and HTML versions
- *
- * @param fromName name of the sender
- * @param fromEmail email fo the sender
- * @param replyTo replyTo address to direct responses
- * @param toEmail destination email address
- * @param messageSubject subject of the message
- * @param htmlVersion html version of the message
- * @param textVersion text only version of the message
- * @param additionalMailHeader additions to the smtp mail header
- */
- static public function send($params) {
-
- $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
- $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
-
- // generate a mime boundary
- $mimeBoundary =rand(0,9)."-"
- .rand(10000000000,9999999999)."-"
- .rand(10000000000,9999999999)."=:"
- .rand(10000,99999);
-
- // generate a multipart/alternative message header
- $messageHeader =
- $params['additionalMailHeader'] .
- "From: $fromName <{$params['fromEmail']}>\n" .
- "Reply-To: $fromName <{$params['replyTo']}>\n" .
- "MIME-Version: 1.0\n" .
- "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
-
- // assemble the final multipart message body with the text and html types included
- $textBody = chunk_split(base64_encode($params['textVersion']));
- $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
- $multipartMessageBody =
- "--" . $mimeBoundary . "\n" . // plain text section
- "Content-Type: text/plain; charset=UTF-8\n" .
- "Content-Transfer-Encoding: base64\n\n" .
- $textBody . "\n" .
- "--" . $mimeBoundary . "\n" . // text/html section
- "Content-Type: text/html; charset=UTF-8\n" .
- "Content-Transfer-Encoding: base64\n\n" .
- $htmlBody . "\n" .
- "--" . $mimeBoundary . "--\n"; // message ending
-
- // send the message
- $res = mail(
- $params['toEmail'], // send to address
- $messageSubject, // subject
- $multipartMessageBody, // message body
- $messageHeader // message headers
+ $notification_data = array("uid" => $uid, "profiles" => array());
+ call_hooks('check_item_notification', $notification_data);
+
+ $profiles = $notification_data["profiles"];
+
+ $user = q("SELECT `notify-flags`, `language`, `username`, `email`, `nickname` FROM `user` WHERE `uid` = %d", intval($uid));
+ if (!$user)
+ return false;
+
+ $owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid));
+ if (!$owner)
+ return false;
+
+ // This is our regular URL format
+ $profiles[] = $owner[0]["url"];
+
+ // Notifications from Diaspora are often with an URL in the Diaspora format
+ $profiles[] = App::get_baseurl()."/u/".$user[0]["nickname"];
+
+ $profiles2 = array();
+
+ foreach ($profiles AS $profile) {
+ // Check for invalid profile urls. 13 should be the shortest possible profile length:
+ // http://a.bc/d
+ // Additionally check for invalid urls that would return the normalised value "http:"
+ if ((strlen($profile) >= 13) AND (normalise_link($profile) != "http:")) {
+ if (!in_array($profile, $profiles2))
+ $profiles2[] = $profile;
+
+ $profile = normalise_link($profile);
+ if (!in_array($profile, $profiles2))
+ $profiles2[] = $profile;
+
+ $profile = str_replace("http://", "https://", $profile);
+ if (!in_array($profile, $profiles2))
+ $profiles2[] = $profile;
+ }
+ }
+
+ $profiles = $profiles2;
+
+ $profile_list = "";
+
+ foreach ($profiles AS $profile) {
+ if ($profile_list != "")
+ $profile_list .= "', '";
+
+ $profile_list .= dbesc($profile);
+ }
+
+ $profile_list = "'".$profile_list."'";
+
+ // Only act if it is a "real" post
+ // We need the additional check for the "local_profile" because of mixed situations on connector networks
+ $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`,
+ `parent-uri`, `uri`, `contact-id`
+ FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
+ NOT (`author-link` IN ($profile_list)) LIMIT 1",
+ intval($itemid), dbesc(ACTIVITY_POST));
+ if (!$item)
+ return false;
+
+ // Generate the notification array
+ $params = array();
+ $params["uid"] = $uid;
+ $params["notify_flags"] = $user[0]["notify-flags"];
+ $params["language"] = $user[0]["language"];
+ $params["to_name"] = $user[0]["username"];
+ $params["to_email"] = $user[0]["email"];
+ $params["item"] = $item[0];
+ $params["parent"] = $item[0]["parent"];
+ $params["link"] = App::get_baseurl().'/display/'.urlencode($item[0]["guid"]);
+ $params["otype"] = 'item';
+ $params["source_name"] = $item[0]["author-name"];
+ $params["source_link"] = $item[0]["author-link"];
+ $params["source_photo"] = $item[0]["author-avatar"];
+
+ if ($item[0]["parent-uri"] === $item[0]["uri"]) {
+ // Send a notification for every new post?
+ $r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1",
+ intval($item[0]['contact-id']),
+ intval($uid)