`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`global` boolean NOT NULL DEFAULT '0' COMMENT '',
- `aid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
PRIMARY KEY(`tid`),
INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`(32)),
// Only act if it is a "real" post
// We need the additional check for the "local_profile" because of mixed situations on connector networks
- $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`,
- `parent-uri`, `uri`, `contact-id`, `network`
- FROM `item` WHERE `id` = %d AND `gravity` IN (%d, %d) AND
- NOT (`author-id` IN ($contact_list)) LIMIT 1",
- intval($itemid), intval(GRAVITY_PARENT), intval(GRAVITY_COMMENT));
- if (!$item)
- return false;
-
- if ($item[0]['network'] != NETWORK_FEED) {
- $author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
- } else {
- $author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['contact-id']]);
+ $fields = ['id', 'mention', 'tag', 'parent', 'title', 'body',
+ 'author-link', 'author-name', 'author-avatar', 'author-id',
+ 'guid', 'parent-uri', 'uri', 'contact-id', 'network'];
+ $condition = ['id' => $itemid, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
+ $item = Item::selectFirst($fields, $condition);
+ if (!DBM::is_result($item) || in_array($item['author-id'], $contacts)) {
+ return;
}
// Generate the notification array
$params["language"] = $user["language"];
$params["to_name"] = $user["username"];
$params["to_email"] = $user["email"];
- $params["item"] = $item[0];
- $params["parent"] = $item[0]["parent"];
- $params["link"] = System::baseUrl().'/display/'.urlencode($item[0]["guid"]);
+ $params["item"] = $item;
+ $params["parent"] = $item["parent"];
+ $params["link"] = System::baseUrl().'/display/'.urlencode($item["guid"]);
$params["otype"] = 'item';
- $params["source_name"] = $author["name"];
- $params["source_link"] = $author["url"];
- $params["source_photo"] = $author["thumb"];
+ $params["source_name"] = $item["author-name"];
+ $params["source_link"] = $item["author-link"];
+ $params["source_photo"] = $item["author-avatar"];
- if ($item[0]["parent-uri"] === $item[0]["uri"]) {
+ if ($item["parent-uri"] === $item["uri"]) {
// Send a notification for every new post?
- $send_notification = dba::exists('contact', ['id' => $item[0]['contact-id'], 'notify_new_posts' => true]);
+ $send_notification = dba::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true]);
if (!$send_notification) {
$tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d",
$tagged = false;
foreach ($profiles AS $profile) {
- if (strpos($item[0]["tag"], "=".$profile."]") || strpos($item[0]["body"], "=".$profile."]"))
+ if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
$tagged = true;
}
- if ($item[0]["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
+ if ($item["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
$params["type"] = NOTIFY_TAGSELF;
$params["verb"] = ACTIVITY_TAG;
}
WHERE `thread`.`iid` = %d AND NOT `thread`.`ignored` AND
(`thread`.`mention` OR `item`.`author-id` IN ($contact_list))
LIMIT 1",
- intval($item[0]["parent"]));
+ intval($item["parent"]));
if ($parent && !isset($params["type"])) {
$params["type"] = NOTIFY_COMMENT;
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
"received" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
"global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
- "aid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
],
"indexes" => [
}
}
+ // Build the tag string out of the term entries
+ if (isset($row['id']) && isset($row['tag'])) {
+ $row['tag'] = Term::tagTextFromItemId($row['id']);
+ }
+
// We can always comment on posts from these networks
if (isset($row['writable']) && !empty($row['network']) &&
in_array($row['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
*/
private static function constructSelectFields($fields, $selected)
{
+ // To be able to fetch the tags we need the item id
+ if (in_array('tag', $selected) && !in_array('id', $selected)) {
+ $selected[] = 'id';
+ }
+
$selection = [];
foreach ($fields as $table => $table_fields) {
foreach ($table_fields as $field => $select) {
$content_fields['plink'] = $item['plink'];
}
self::updateContent($content_fields, ['uri' => $item['uri']]);
- Term::insertFromTagFieldByItemId($item['id']);
- Term::insertFromFileFieldByItemId($item['id']);
+
+ if (array_key_exists('tag', $fields)) {
+ Term::insertFromTagFieldByItemId($item['id']);
+ }
+
+ if (array_key_exists('file', $fields)) {
+ Term::insertFromFileFieldByItemId($item['id']);
+ }
+
self::updateThread($item['id']);
// We only need to notfiy others when it is an original entry from us.
* Due to deadlock issues with the "term" table we are doing these steps after the commit.
* This is not perfect - but a workable solution until we found the reason for the problem.
*/
- Term::insertFromTagFieldByItemId($current_post);
- Term::insertFromFileFieldByItemId($current_post);
+ if (array_key_exists('tag', $item)) {
+ Term::insertFromTagFieldByItemId($current_post);
+ }
+
+ if (array_key_exists('file', $item)) {
+ Term::insertFromFileFieldByItemId($current_post);
+ }
if ($item['parent-uri'] === $item['uri']) {
self::addShadow($current_post);
class Term
{
+ public static function tagTextFromItemId($itemid)
+ {
+ $tag_text = '';
+ $condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]];
+ $tags = dba::select('term', [], $condition);
+ while ($tag = dba::fetch($tags)) {
+ if ($tag_text != '') {
+ $tag_text .= ',';
+ }
+
+ if ($tag['type'] == 1) {
+ $tag_text .= '#';
+ } else {
+ $tag_text .= '@';
+ }
+ $tag_text .= '[url=' . $tag['url'] . ']' . $tag['term'] . '[/url]';
+ }
+ return $tag_text;
+ }
+
public static function insertFromTagFieldByItemId($itemid)
{
$profile_base = System::baseUrl();
$pattern = '/\W\#([^\[].*?)[\s\'".,:;\?!\[\]\/]/ism';
if (preg_match_all($pattern, $data, $matches)) {
foreach ($matches[1] as $match) {
- $tags['#' . strtolower($match)] = '';
+ $tags['#' . $match] = '';
}
}
$pattern = '/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism';
if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
- $tags[$match[1] . strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2];
+ $tags[$match[1] . trim($match[3], ',.:;[]/\"?!')] = $match[2];
}
}
while ($tag = dba::fetch($taglist)) {
if ($tag["url"] == "") {
- $tag["url"] = $searchpath . strtolower($tag["term"]);
+ $tag["url"] = $searchpath . $tag["term"];
}
$orig_tag = $tag["url"];