]> git.mxchange.org Git - friendica.git/blobdiff - include/enotify.php
Fix missing $prv and $nxt variables in mod/photos
[friendica.git] / include / enotify.php
index 1990f2ef9c2242e2db20592b55f03f02c79d1ecd..6d27aa8897136fecf5f9e0ea76563d7a21ad2acf 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
@@ -26,6 +27,11 @@ function notification($params)
 {
        $a = get_app();
 
+       // Temporary logging for finding the origin
+       if (!isset($params['language']) || !isset($params['uid'])) {
+               logger('Missing parameters.' . System::callstack());
+       }
+
        // from here on everything is in the recipients language
        L10n::pushLang($params['language']);
 
@@ -53,11 +59,13 @@ function notification($params)
                        ['uid' => $params['uid']]);
 
                // There is no need to create notifications for forum accounts
-               if (!DBA::is_result($user) || in_array($user["page-flags"], [PAGE_COMMUNITY, PAGE_PRVGROUP])) {
+               if (!DBA::isResult($user) || in_array($user["page-flags"], [Contact::PAGE_COMMUNITY, Contact::PAGE_PRVGROUP])) {
                        return;
                }
+               $nickname = $user["nickname"];
+       } else {
+               $nickname = '';
        }
-       $nickname = $user["nickname"];
 
        // with $params['show_in_notification_page'] == false, the notification isn't inserted into
        // the database, and an email is sent if applicable.
@@ -92,8 +100,11 @@ function notification($params)
                $parent_id = 0;
        }
 
+       $epreamble = '';
+
        if ($params['type'] == NOTIFY_MAIL) {
                $itemlink = $siteurl.'/message/'.$params['item']['id'];
+               $params["link"] = $itemlink;
 
                $subject = L10n::t('[Friendica:Notify] New mail received at %s', $sitename);
 
@@ -107,7 +118,7 @@ function notification($params)
 
        if ($params['type'] == NOTIFY_COMMENT) {
                $thread = DBA::selectFirst('thread', ['ignored'], ['iid' => $parent_id]);
-               if (DBA::is_result($thread) && $thread["ignored"]) {
+               if (DBA::isResult($thread) && $thread["ignored"]) {
                        logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
                        return;
                }
@@ -118,7 +129,7 @@ function notification($params)
                        intval(NOTIFY_TAGSELF),
                        intval(NOTIFY_COMMENT),
                        intval(NOTIFY_SHARE),
-                       dbesc($params['link']),
+                       DBA::escape($params['link']),
                        intval($params['uid'])
                );
                if ($p && count($p)) {
@@ -155,7 +166,7 @@ function notification($params)
                }
 
                // "your post"
-               if (DBA::is_result($item) && $item['owner-id'] == $item['author-id'] && $item['wall']) {
+               if (DBA::isResult($item) && $item['owner-id'] == $item['author-id'] && $item['wall']) {
                        $dest_str = L10n::t('%1$s commented on [url=%2$s]your %3$s[/url]',
                                '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
                                $itemlink,
@@ -436,8 +447,8 @@ function notification($params)
                        $dups = false;
                        $hash = random_string();
                        $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
-                               dbesc($hash));
-                       if (DBA::is_result($r)) {
+                               DBA::escape($hash));
+                       if (DBA::isResult($r)) {
                                $dups = true;
                        }
                } while ($dups == true);
@@ -469,23 +480,23 @@ function notification($params)
                // create notification entry in DB
                q("INSERT INTO `notify` (`hash`, `name`, `url`, `photo`, `date`, `uid`, `link`, `iid`, `parent`, `type`, `verb`, `otype`, `name_cache`)
                        values('%s', '%s', '%s', '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s')",
-                       dbesc($datarray['hash']),
-                       dbesc($datarray['name']),
-                       dbesc($datarray['url']),
-                       dbesc($datarray['photo']),
-                       dbesc($datarray['date']),
+                       DBA::escape($datarray['hash']),
+                       DBA::escape($datarray['name']),
+                       DBA::escape($datarray['url']),
+                       DBA::escape($datarray['photo']),
+                       DBA::escape($datarray['date']),
                        intval($datarray['uid']),
-                       dbesc($datarray['link']),
+                       DBA::escape($datarray['link']),
                        intval($datarray['iid']),
                        intval($datarray['parent']),
                        intval($datarray['type']),
-                       dbesc($datarray['verb']),
-                       dbesc($datarray['otype']),
-                       dbesc($datarray["name_cache"])
+                       DBA::escape($datarray['verb']),
+                       DBA::escape($datarray['otype']),
+                       DBA::escape($datarray["name_cache"])
                );
 
                $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' AND `uid` = %d LIMIT 1",
-                       dbesc($hash),
+                       DBA::escape($hash),
                        intval($params['uid'])
                );
                if ($r) {
@@ -500,7 +511,7 @@ function notification($params)
                $p = q("SELECT `id` FROM `notify` WHERE `type` IN (%d, %d) AND `link` = '%s' AND `uid` = %d ORDER BY `id`",
                        intval(NOTIFY_TAGSELF),
                        intval(NOTIFY_COMMENT),
-                       dbesc($params['link']),
+                       DBA::escape($params['link']),
                        intval($params['uid'])
                );
                if ($p && (count($p) > 1)) {
@@ -519,15 +530,15 @@ function notification($params)
                $msg = replace_macros($epreamble, ['$itemlink' => $itemlink]);
                $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg)));
                q("UPDATE `notify` SET `msg` = '%s', `msg_cache` = '%s' WHERE `id` = %d AND `uid` = %d",
-                       dbesc($msg),
-                       dbesc($msg_cache),
+                       DBA::escape($msg),
+                       DBA::escape($msg_cache),
                        intval($notify_id),
                        intval($params['uid'])
                );
        }
 
        // send email notification if notification preferences permit
-       if ((intval($params['notify_flags']) & intval($params['type']))
+       if ((!empty($params['notify_flags']) & intval($params['type']))
                || $params['type'] == NOTIFY_SYSTEM
                || $params['type'] == SYSTEM_EMAIL) {
 
@@ -575,11 +586,11 @@ function notification($params)
                $datarray['siteurl'] = $siteurl;
                $datarray['type'] = $params['type'];
                $datarray['parent'] = $parent_id;
-               $datarray['source_name'] = $params['source_name'];
-               $datarray['source_link'] = $params['source_link'];
-               $datarray['source_photo'] = $params['source_photo'];
+               $datarray['source_name'] = defaults($params, 'source_name', '');
+               $datarray['source_link'] = defaults($params, 'source_link', '');
+               $datarray['source_photo'] = defaults($params, 'source_photo', '');
                $datarray['uid'] = $params['uid'];
-               $datarray['username'] = $params['to_name'];
+               $datarray['username'] = defaults($params, 'to_name', '');
                $datarray['hsitelink'] = $hsitelink;
                $datarray['tsitelink'] = $tsitelink;
                $datarray['hitemlink'] = '<a href="'.$itemlink.'">'.$itemlink.'</a>';
@@ -689,12 +700,12 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
 
        $fields = ['notify-flags', 'language', 'username', 'email', 'nickname'];
        $user = DBA::selectFirst('user', $fields, ['uid' => $uid]);
-       if (!DBA::is_result($user)) {
+       if (!DBA::isResult($user)) {
                return false;
        }
 
        $owner = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
-       if (!DBA::is_result($owner)) {
+       if (!DBA::isResult($owner)) {
                return false;
        }
 
@@ -745,7 +756,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
                'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
        $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
        $item = Item::selectFirst($fields, $condition);
-       if (!DBA::is_result($item) || in_array($item['author-id'], $contacts)) {
+       if (!DBA::isResult($item) || in_array($item['author-id'], $contacts)) {
                return;
        }
 
@@ -772,7 +783,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
                        $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 (DBA::is_result($tags)) {
+                       if (DBA::isResult($tags)) {
                                foreach ($tags AS $tag) {
                                        $condition = ['nurl' => normalise_link($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true];
                                        $r = DBA::exists('contact', $condition);