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;
{
$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']);
['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.
$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);
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;
}
intval(NOTIFY_TAGSELF),
intval(NOTIFY_COMMENT),
intval(NOTIFY_SHARE),
- dbesc($params['link']),
+ DBA::escape($params['link']),
intval($params['uid'])
);
if ($p && count($p)) {
}
// "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,
$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);
// 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) {
$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)) {
$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) {
$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>';
$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;
}
'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;
}
$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);