X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fenotify.php;h=bcb2ebe7ca35fe5d1e8a841083aee3e55f59f7bc;hb=8e50254bb994592b28e04299a4bfc11f4c8c979a;hp=bed00c5eaf95ac1969855d1ed8190a04dbf19c4c;hpb=8ec424325375aa923c7d2d78ac8ddcc352f09cff;p=friendica.git diff --git a/include/enotify.php b/include/enotify.php index bed00c5eaf..bcb2ebe7ca 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -49,7 +49,7 @@ function notification($params) { // with $params['show_in_notification_page'] == false, the notification isn't inserted into // the database, and an email is sent if applicable. // default, if not specified: true - $show_in_notification_page = ((x($params, 'show_in_notification_page')) ? $params['show_in_notification_page']:True); + $show_in_notification_page = ((x($params, 'show_in_notification_page')) ? $params['show_in_notification_page']:true); $additional_mail_header = ""; $additional_mail_header .= "Precedence: list\n"; @@ -418,6 +418,7 @@ function notification($params) { $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,7 +440,7 @@ 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`) + $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')", dbesc($datarray['hash']), dbesc($datarray['name']), @@ -452,7 +453,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", @@ -494,8 +496,10 @@ function notification($params) { $itemlink = $a->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']) ); @@ -778,4 +782,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; +} \ No newline at end of file