X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fenotify.php;h=39665d14d4c994ca267127ef135b1e5962e03393;hb=0cd9db9cb7f4c96f597e37590a536eaae123238d;hp=4973bedc24c4270053b606d289ab7d8ab354e571;hpb=2d450abd3bc4e9f6462ebe5c94b6ad874066c791;p=friendica.git diff --git a/include/enotify.php b/include/enotify.php index 4973bedc24..39665d14d4 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -1,4 +1,7 @@ get_baseurl(true); + $siteurl = App::get_baseurl(true); $thanks = t('Thank You,'); $sitename = $a->config['sitename']; if (!x($a->config['admin_name'])) @@ -58,7 +61,7 @@ function notification($params) { $additional_mail_header .= "X-Friendica-Platform: ".FRIENDICA_PLATFORM."\n"; $additional_mail_header .= "X-Friendica-Version: ".FRIENDICA_VERSION."\n"; $additional_mail_header .= "List-ID: \n"; - $additional_mail_header .= "List-Archive: <".$a->get_baseurl()."/notifications/system>\n"; + $additional_mail_header .= "List-Archive: <".App::get_baseurl()."/notifications/system>\n"; if (array_key_exists('item', $params)) { $title = $params['item']['title']; @@ -96,7 +99,7 @@ function notification($params) { intval($parent_id), intval($params['uid']) ); - if ($p AND count($p) AND ($p[0]["ignored"])) { + if ($p && count($p) && ($p[0]["ignored"])) { logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG); return; } @@ -105,14 +108,14 @@ function notification($params) { // If so don't create a second notification $p = null; - $p = q("SELECT `id` FROM `notify` WHERE (`type` = %d OR `type` = %d OR `type` = %d) AND `link` = '%s' AND `uid` = %d LIMIT 1", + $p = q("SELECT `id` FROM `notify` WHERE `type` IN (%d, %d, %d) AND `link` = '%s' AND `uid` = %d LIMIT 1", intval(NOTIFY_TAGSELF), intval(NOTIFY_COMMENT), intval(NOTIFY_SHARE), dbesc($params['link']), intval($params['uid']) ); - if ($p and count($p)) { + if ($p && count($p)) { pop_lang(); return; } @@ -411,13 +414,16 @@ function notification($params) { $hash = random_string(); $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", dbesc($hash)); - if (count($r)) + if (dbm::is_result($r)) { $dups = true; - } while($dups == true); + } + } while ($dups == true); + /// @TODO One statement is enough $datarray = array(); $datarray['hash'] = $hash; $datarray['name'] = $params['source_name']; + $datarray['name_cache'] = strip_tags(bbcode($params['source_name'])); $datarray['url'] = $params['source_link']; $datarray['photo'] = $params['source_photo']; $datarray['date'] = datetime_convert(); @@ -439,8 +445,8 @@ function notification($params) { // create notification entry in DB - $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')", + $r = 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']), @@ -452,7 +458,8 @@ function notification($params) { intval($datarray['parent']), intval($datarray['type']), dbesc($datarray['verb']), - dbesc($datarray['otype']) + dbesc($datarray['otype']), + dbesc($datarray["name_cache"]) ); $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' AND `uid` = %d LIMIT 1", @@ -470,7 +477,7 @@ function notification($params) { // After we've stored everything, look again to see if there are any duplicates and if so remove them $p = null; - $p = q("SELECT `id` FROM `notify` WHERE (`type` = %d OR `type` = %d) AND `link` = '%s' AND `uid` = %d ORDER BY `id`", + $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']), @@ -478,9 +485,7 @@ function notification($params) { ); if ($p && (count($p) > 1)) { for ($d = 1; $d < count($p); $d ++) { - q("DELETE FROM `notify` WHERE `id` = %d", - intval($p[$d]['id']) - ); + dba::delete('notify', array('id' => $p[$d]['id'])); } // only continue on if we stored the first one @@ -492,10 +497,12 @@ function notification($params) { } - $itemlink = $a->get_baseurl().'/notify/view/'.$notify_id; + $itemlink = App::get_baseurl().'/notify/view/'.$notify_id; $msg = replace_macros($epreamble, array('$itemlink' => $itemlink)); - $r = q("UPDATE `notify` SET `msg` = '%s' WHERE `id` = %d AND `uid` = %d", + $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(bbcode($msg))); + $r = q("UPDATE `notify` SET `msg` = '%s', `msg_cache` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($msg), + dbesc($msg_cache), intval($notify_id), intval($params['uid']) ); @@ -508,7 +515,7 @@ function notification($params) { logger('sending notification email'); - if (isset($params['parent']) AND (intval($params['parent']) != 0)) { + if (isset($params['parent']) && (intval($params['parent']) != 0)) { $id_for_parent = $params['parent']."@".$hostname; // Is this the first email notification for this parent item and user? @@ -644,7 +651,6 @@ function notification($params) { * @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); @@ -670,7 +676,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { // 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 ((strlen($profile) >= 13) && (normalise_link($profile) != "http:")) { if (!in_array($profile, $profiles2)) $profiles2[] = $profile; @@ -728,17 +734,17 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { intval($item[0]['contact-id']), intval($uid) ); - $send_notification = count($r); + $send_notification = dbm::is_result($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)) { + if (dbm::is_result($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)) + if (dbm::is_result($r)) $send_notification = true; } } @@ -754,11 +760,11 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { $tagged = false; foreach ($profiles AS $profile) { - if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]")) + if (strpos($item[0]["tag"], "=".$profile."]") || strpos($item[0]["body"], "=".$profile."]")) $tagged = true; } - if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) { + if ($item[0]["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) { $params["type"] = NOTIFY_TAGSELF; $params["verb"] = ACTIVITY_TAG; } @@ -770,7 +776,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { LIMIT 1", intval($item[0]["parent"]), intval($uid)); - if ($parent AND !isset($params["type"])) { + if ($parent && !isset($params["type"])) { $params["type"] = NOTIFY_COMMENT; $params["verb"] = ACTIVITY_POST; } @@ -778,4 +784,27 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { if (isset($params["type"])) notification($params); } -?> + +/** + * @brief Formats a notification message with the notification author + * + * Replace the name with {0} but ensure to make that only once. The {0} is used + * later and prints the name in bold. + * + * @param string $name + * @param string $message + * @return string Formatted message + */ +function format_notification_message($name, $message) { + if ($name != '') { + $pos = strpos($message, $name); + } else { + $pos = false; + } + + if ($pos !== false) { + $message = substr_replace($message, '{0}', $pos, strlen($name)); + } + + return $message; +}