define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.1-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
-define ( 'DB_UPDATE_VERSION', 1206 );
+define ( 'DB_UPDATE_VERSION', 1207 );
/**
* @brief Constant with a HTML line break.
`seen` tinyint(1) NOT NULL DEFAULT 0,
`verb` varchar(255) NOT NULL DEFAULT '',
`otype` varchar(16) NOT NULL DEFAULT '',
+ `name_cache` tinytext,
+ `msg_name` mediumtext,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8mb4;
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
+ "name_cache" => array("type" => "tinytext"),
+ "msg_cache" => array("type" => "mediumtext")
),
"indexes" => array(
"PRIMARY" => array("id"),
$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();
// 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']),
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",
$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'])
);
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
killme();
}
+/**
+ * @brief Retrieves the notifications array for the given user ID
+ *
+ * @param int $uid
+ * @return array
+ */
function ping_get_notifications($uid) {
$result = array();
$seensql = "";
$order = "DESC";
$offset = 0;
- } elseif (!$r)
+ } elseif (!$r) {
$quit = true;
- else
+ } else {
$offset += 50;
-
+ }
foreach ($r AS $notification) {
- if (is_null($notification["visible"]))
+ if (is_null($notification["visible"])) {
$notification["visible"] = true;
+ }
- if (is_null($notification["spam"]))
+ if (is_null($notification["spam"])) {
$notification["spam"] = 0;
+ }
- if (is_null($notification["deleted"]))
+ if (is_null($notification["deleted"])) {
$notification["deleted"] = 0;
+ }
- $notification["message"] = strip_tags(bbcode($notification["msg"]));
- $notification["name"] = strip_tags(bbcode($notification["name"]));
-
- // Replace the name with {0} but ensure to make that only once
- // The {0} is used later and prints the name in bold.
-
- if ($notification['name'] != "")
- $pos = strpos($notification["message"],$notification['name']);
- else
- $pos = false;
-
- if ($pos !== false)
- $notification["message"] = substr_replace($notification["message"],"{0}",$pos,strlen($notification["name"]));
+ if ($notification["msg_cache"]) {
+ $notification["name"] = $notification["name_cache"];
+ $notification["message"] = $notification["msg_cache"];
+ } else {
+ $notification["name"] = strip_tags(bbcode($notification["name"]));
+ $notification["message"] = format_notification_message($notification["name"], strip_tags(bbcode($notification["msg"])));
+
+ q("UPDATE `notify` SET `name_cache` = '%s', `msg_cache` = '%s' WHERE `id` = %d",
+ dbesc($notification["name"]),
+ dbesc($notification["message"]),
+ intval($notification["id"])
+ );
+ }
- $notification['href'] = $a->get_baseurl() . '/notify/view/' . $notification['id'];
+ $notification["href"] = $a->get_baseurl() . "/notify/view/" . $notification["id"];
if ($notification["visible"] AND !$notification["spam"] AND
!$notification["deleted"] AND !is_array($result[$notification["parent"]])) {
$result[$notification["parent"]] = $notification;
}
}
-
} while ((count($result) < 50) AND !$quit);
-
return($result);
}
<?php
-define('UPDATE_VERSION' , 1206);
+define('UPDATE_VERSION' , 1207);
/**
*