X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fenotify.php;h=54b59857c2cdb5f72872c7644cb082962a51ddbe;hb=16ef9f49408050aab2b6a180f7df9103145f0c03;hp=9ca9d79703cde42b32f73e4bfbb5ade232afc21d;hpb=db2e20eb2e94b7faf7e52c249eefeffc246ef829;p=friendica.git diff --git a/include/enotify.php b/include/enotify.php index 9ca9d79703..54b59857c2 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -20,14 +20,26 @@ function notification($params) { $siteurl = $a->get_baseurl(true); $thanks = t('Thank You,'); $sitename = $a->config['sitename']; - $site_admin = sprintf( t('%s Administrator'), $sitename); + if (!x($a->config['admin_name'])) { + $site_admin = sprintf( t('%s Administrator'), $sitename); + } else { + $site_admin = sprintf( t('%1$s, %2$s Administrator'), $a->config['admin_name'], $sitename); + } + $nickname = ""; - $sender_name = $product; + $sender_name = $sitename; $hostname = $a->get_hostname(); if(strpos($hostname,':')) $hostname = substr($hostname,0,strpos($hostname,':')); - $sender_email = t('noreply') . '@' . $hostname; + $sender_email = $a->config['sender_email']; + if (empty($sender_email)) { + $sender_email = t('noreply') . '@' . $hostname; + } + + $user = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($params['uid'])); + if ($user) + $nickname = $user[0]["nickname"]; // with $params['show_in_notification_page'] == false, the notification isn't inserted into // the database, and an email is sent if applicable. @@ -37,6 +49,7 @@ function notification($params) { $additional_mail_header = ""; $additional_mail_header .= "Precedence: list\n"; $additional_mail_header .= "X-Friendica-Host: ".$hostname."\n"; + $additional_mail_header .= "X-Friendica-Account: <".$nickname."@".$hostname.">\n"; $additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n"; $additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n"; $additional_mail_header .= "List-ID: \n"; @@ -54,6 +67,16 @@ function notification($params) { // e.g. "your post", "David's photo", etc. $possess_desc = t('%s '); + if (isset($params['item']['id'])) + $item_id = $params['item']['id']; + else + $item_id = 0; + + if (isset($params['parent'])) + $parent_id = $params['parent']; + else + $parent_id = 0; + if($params['type'] == NOTIFY_MAIL) { $subject = sprintf( t('[Friendica:Notify] New mail received at %s'),$sitename); @@ -69,7 +92,7 @@ function notification($params) { if($params['type'] == NOTIFY_COMMENT) { // logger("notification: params = " . print_r($params, true), LOGGER_DEBUG); - $parent_id = $params['parent']; + //$parent_id = $params['parent']; $p = q("SELECT `ignored` FROM `thread` WHERE `iid` = %d AND `uid` = %d LIMIT 1", intval($parent_id), @@ -278,7 +301,7 @@ function notification($params) { if($params['type'] == NOTIFY_CONFIRM) { if ($params['verb'] == ACTIVITY_FRIEND ){ // mutual connection $subject = sprintf( t('[Friendica:Notify] Connection accepted')); - $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename); + $preamble = sprintf( t('\'%1$s\' has accepted your connection request at %2$s'), $params['source_name'], $sitename); $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'), $itemlink, '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]'); @@ -291,7 +314,7 @@ function notification($params) { $itemlink = $params['link']; } else { // ACTIVITY_FOLLOW $subject = sprintf( t('[Friendica:Notify] Connection accepted')); - $preamble = sprintf( t('\'%1$s\' has acepted your connection request at %2$s'), $params['source_name'], $sitename); + $preamble = sprintf( t('\'%1$s\' has accepted your connection request at %2$s'), $params['source_name'], $sitename); $epreamble = sprintf( t('%2$s has accepted your [url=%1$s]connection request[/url].'), $itemlink, '[url=' . $params['source_link'] . ']' . $params['source_name'] . '[/url]'); @@ -320,7 +343,7 @@ function notification($params) { $sitelink = t('Please visit %s to approve or reject the request.'); $tsitelink = sprintf( $sitelink, $params['link'] ); - $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $hsitelink = sprintf( $sitelink, '' . $sitename . '

'); $itemlink = $params['link']; break; case "SYSTEM_DB_UPDATE_FAIL": @@ -336,11 +359,6 @@ function notification($params) { // add a notification to the user, with could be inexistent) $subject = $params['subject']; $preamble = $params['preamble']; - if (x($params,'epreamble')){ - $epreamble = $params['epreamble']; - } else { - $epreamble = str_replace("\n","
\n",$preamble); - } $body = $params['body']; $sitelink = ""; $tsitelink = ""; @@ -349,7 +367,7 @@ function notification($params) { $show_in_notification_page = false; } - + $subject .= " (".$nickname."@".$hostname.")"; $h = array( 'params' => $params, @@ -396,6 +414,7 @@ function notification($params) { $datarray['date'] = datetime_convert(); $datarray['uid'] = $params['uid']; $datarray['link'] = $itemlink; + $datarray['iid'] = $item_id; $datarray['parent'] = $parent_id; $datarray['type'] = $params['type']; $datarray['verb'] = $params['verb']; @@ -411,8 +430,8 @@ function notification($params) { // create notification entry in DB - $r = q("insert into notify (hash,name,url,photo,date,uid,link,parent,type,verb,otype) - values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,'%s','%s')", + $r = q("insert into notify (hash,name,url,photo,date,uid,link,iid,parent,type,verb,otype) + values('%s','%s','%s','%s','%s',%d,'%s',%d,%d,%d,'%s','%s')", dbesc($datarray['hash']), dbesc($datarray['name']), dbesc($datarray['url']), @@ -420,6 +439,7 @@ function notification($params) { dbesc($datarray['date']), intval($datarray['uid']), dbesc($datarray['link']), + intval($datarray['iid']), intval($datarray['parent']), intval($datarray['type']), dbesc($datarray['verb']), @@ -547,14 +567,15 @@ function notification($params) { call_hooks('enotify_mail', $datarray); // check whether sending post content in email notifications is allowed - $content_allowed = !get_config('system','enotify_no_content'); + // always true for "SYSTEM_EMAIL" + $content_allowed = ((!get_config('system','enotify_no_content')) || ($params['type'] == "SYSTEM_EMAIL")); // load the template for private message notifications $tpl = get_markup_template('email_notify_html.tpl'); $email_html_body = replace_macros($tpl,array( '$banner' => $datarray['banner'], '$product' => $datarray['product'], - '$preamble' => $datarray['preamble'], + '$preamble' => str_replace("\n","
\n",$datarray['preamble']), '$sitename' => $datarray['sitename'], '$siteurl' => $datarray['siteurl'], '$source_name' => $datarray['source_name'], @@ -595,7 +616,8 @@ function notification($params) { // use the Emailer class to send the message - Emailer::send(array( + return Emailer::send(array( + 'uid' => $params['uid'], 'fromName' => $sender_name, 'fromEmail' => $sender_email, 'replyTo' => $sender_email, @@ -605,11 +627,135 @@ function notification($params) { 'textVersion' => $email_text_body, 'additionalMailHeader' => $datarray['headers'], )); - return True; } return False; } +/** + * @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 str $defaulttype (Optional) Forces a notification with this type. + */ +function check_item_notification($itemid, $uid, $defaulttype = "") { + + $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` 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; + + $profiles[] = $owner[0]["url"]; + + $profiles2 = array(); + + foreach ($profiles AS $profile) { + $profiles2[] = normalise_link($profile); + $profiles2[] = str_replace("http://", "https://", normalise_link($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) + ); + $send_notification = count($r); + + if (!$send_notification) { + $tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d", + intval(TERM_OBJ_POST), intval($itemid), intval(TERM_MENTION), intval($uid)); + + if (count($tags)) { + foreach ($tags AS $tag) { + $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `notify_new_posts`", + normalise_link($tag["url"]), intval($uid)); + if (count($r)) + $send_notification = true; + } + } + } + + if ($send_notification) { + $params["type"] = NOTIFY_SHARE; + $params["verb"] = ACTIVITY_TAG; + } + } + + // Is the user mentioned in this post? + $tagged = false; + + foreach ($profiles AS $profile) { + if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]")) + $tagged = true; + } + + if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) { + $params["type"] = NOTIFY_TAGSELF; + $params["verb"] = ACTIVITY_TAG; + } + + // Is it a post that the user had started or where he interacted? + $parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid` + WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND + (`thread`.`mention` OR `item`.`author-link` IN ($profile_list)) + LIMIT 1", + intval($item[0]["parent"]), intval($uid)); + + if ($parent AND !isset($params["type"])) { + $params["type"] = NOTIFY_COMMENT; + $params["verb"] = ACTIVITY_POST; + } + + if (isset($params["type"])) + notification($params); +} ?>