1
0
Fork 0

Merge pull request #4307 from annando/mod-item-cleaning

Some clean up for mod/item.php
This commit is contained in:
Hypolite Petovan 2018-01-22 17:15:10 -05:00 committed by GitHub
commit b34e8e0193
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -346,14 +346,14 @@ function item_post(App $a) {
if ($parent) { if ($parent) {
if ($thr_parent_contact['network'] == NETWORK_OSTATUS) { if ($thr_parent_contact['network'] == NETWORK_OSTATUS) {
$contact = '@[url=' . $thr_parent_contact['url'] . ']' . $thr_parent_contact['nick'] . '[/url]'; $contact = '@[url=' . $thr_parent_contact['url'] . ']' . $thr_parent_contact['nick'] . '[/url]';
if (!in_array($contact, $tags)) { if (!stripos(implode($tags), '[url=' . $thr_parent_contact['url'] . ']')) {
$tags[] = $contact; $tags[] = $contact;
} }
} }
if ($parent_contact['network'] == NETWORK_OSTATUS) { if ($parent_contact['network'] == NETWORK_OSTATUS) {
$contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]';
if (!in_array($contact, $tags)) { if (!stripos(implode($tags), '[url=' . $parent_contact['url'] . ']')) {
$tags[] = $contact; $tags[] = $contact;
} }
} }
@ -367,7 +367,6 @@ function item_post(App $a) {
if (count($tags)) { if (count($tags)) {
foreach ($tags as $tag) { foreach ($tags as $tag) {
$tag_type = substr($tag, 0, 1); $tag_type = substr($tag, 0, 1);
if ($tag_type == '#') { if ($tag_type == '#') {
@ -926,22 +925,10 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
// Checking for the alias that is used for OStatus // Checking for the alias that is used for OStatus
$pattern = "/[@!]\[url\=(.*?)\](.*?)\[\/url\]/ism"; $pattern = "/[@!]\[url\=(.*?)\](.*?)\[\/url\]/ism";
if (preg_match($pattern, $tag, $matches)) { if (preg_match($pattern, $tag, $matches)) {
$data = Contact::getDetailsByURL($matches[1]);
$r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0",
normalise_link($matches[1]));
if (!DBM::is_result($r)) {
$r = q("SELECT `alias`, `name` FROM `gcontact` WHERE `nurl` = '%s' AND `alias` != ''",
normalise_link($matches[1]));
}
if (DBM::is_result($r)) {
$data = $r[0];
} else {
$data = Probe::uri($matches[1]);
}
if ($data["alias"] != "") { if ($data["alias"] != "") {
$newtag = '@[url=' . $data["alias"] . ']' . $data["name"] . '[/url]'; $newtag = '@[url=' . $data["alias"] . ']' . $data["nick"] . '[/url]';
if (!stristr($str_tags, $newtag)) { if (!stripos($str_tags, '[url=' . $data["alias"] . ']')) {
if (strlen($str_tags)) { if (strlen($str_tags)) {
$str_tags .= ','; $str_tags .= ',';
} }
@ -962,124 +949,68 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
$name = $nameparts[0]; $name = $nameparts[0];
// Try to detect the contact in various ways // Try to detect the contact in various ways
if ((strpos($name, '@')) || (strpos($name, 'http://'))) { if (strpos($name, 'http://')) {
// Is it in format @user@domain.tld or @http://domain.tld/...? // At first we have to ensure that the contact exists
Contact::getIdForURL($name);
// First check the contact table for the address // Now we should have something
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify`, `forum`, `prv` FROM `contact` $contact = Contact::getDetailsByURL($name);
WHERE `addr` = '%s' AND `uid` = %d AND } elseif (strpos($name, '@')) {
(`network` != '%s' OR (`notify` != '' AND `alias` != '')) // This function automatically probes when no entry was found
LIMIT 1", $contact = Contact::getDetailsByAddr($name);
dbesc($name),
intval($profile_uid),
dbesc(NETWORK_OSTATUS)
);
// Then check in the contact table for the url
if (!DBM::is_result($r)) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify`, `forum`, `prv` FROM `contact`
WHERE `nurl` = '%s' AND `uid` = %d AND
(`network` != '%s' OR (`notify` != '' AND `alias` != ''))
LIMIT 1",
dbesc(normalise_link($name)),
intval($profile_uid),
dbesc(NETWORK_OSTATUS)
);
}
// Then check in the global contacts for the address
if (!DBM::is_result($r)) {
$r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact`
WHERE `addr` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
LIMIT 1",
dbesc($name),
dbesc(NETWORK_OSTATUS)
);
}
// Then check in the global contacts for the url
if (!DBM::is_result($r)) {
$r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact`
WHERE `nurl` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
LIMIT 1",
dbesc(normalise_link($name)),
dbesc(NETWORK_OSTATUS)
);
}
if (!DBM::is_result($r)) {
$probed = Probe::uri($name);
if ($result['network'] != NETWORK_PHANTOM) {
GContact::update($probed);
$r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($probed["url"])));
}
}
} else { } else {
$r = false; $contact = false;
$fields = ['id', 'url', 'nick', 'name', 'alias', 'network'];
if (strrpos($name, '+')) { if (strrpos($name, '+')) {
// Is it in format @nick+number? // Is it in format @nick+number?
$tagcid = intval(substr($name, strrpos($name, '+') + 1)); $tagcid = intval(substr($name, strrpos($name, '+') + 1));
$contact = dba::selectFirst('contact', $fields, ['id' => $tagcid, 'uid' => $profile_uid]);
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($tagcid),
intval($profile_uid)
);
} }
// select someone by attag or nick and the name passed in the current network // select someone by nick or attag in the current network
if (!DBM::is_result($r) && ($network != "")) if (!DBM::is_result($contact) && ($network != "")) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", $condition = ["(`nick` = ? OR `attag` = ?) AND `network` = ? AND `uid` = ?",
dbesc($name), $name, $name, $network, $profile_uid];
dbesc($name), $contact = dba::selectFirst('contact', $fields, $condition);
dbesc($network),
intval($profile_uid)
);
//select someone from this user's contacts by name in the current network
if (!DBM::is_result($r) && ($network != "")) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1",
dbesc($name),
dbesc($network),
intval($profile_uid)
);
} }
// select someone by attag or nick and the name passed in //select someone by name in the current network
if (!DBM::is_result($r)) { if (!DBM::is_result($contact) && ($network != "")) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", $condition = ['name' => $name, 'network' => $network, 'uid' => $profile_uid];
dbesc($name), $contact = dba::selectFirst('contact', $fields, $condition);
dbesc($name),
intval($profile_uid)
);
} }
// select someone from this user's contacts by name // select someone by nick or attag in any network
if (!DBM::is_result($r)) { if (!DBM::is_result($contact)) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", $condition = ["(`nick` = ? OR `attag` = ?) AND `uid` = ?", $name, $name, $profile_uid];
dbesc($name), $contact = dba::selectFirst('contact', $fields, $condition);
intval($profile_uid) }
);
// select someone by name in any network
if (!DBM::is_result($contact)) {
$condition = ['name' => $name, 'uid' => $profile_uid];
$contact = dba::selectFirst('contact', $fields, $condition);
} }
} }
if (DBM::is_result($r)) { if ($contact) {
if (strlen($inform) && (isset($r[0]["notify"]) || isset($r[0]["id"]))) { if (strlen($inform) && (isset($contact["notify"]) || isset($contact["id"]))) {
$inform .= ','; $inform .= ',';
} }
if (isset($r[0]["id"])) { if (isset($contact["id"])) {
$inform .= 'cid:' . $r[0]["id"]; $inform .= 'cid:' . $contact["id"];
} elseif (isset($r[0]["notify"])) { } elseif (isset($contact["notify"])) {
$inform .= $r[0]["notify"]; $inform .= $contact["notify"];
} }
$profile = $r[0]["url"]; $profile = $contact["url"];
$alias = $r[0]["alias"]; $alias = $contact["alias"];
$newname = $r[0]["nick"]; $newname = $contact["nick"];
if (($newname == "") || (($r[0]["network"] != NETWORK_OSTATUS) && ($r[0]["network"] != NETWORK_TWITTER) if (($newname == "") || (($contact["network"] != NETWORK_OSTATUS) && ($contact["network"] != NETWORK_TWITTER)
&& ($r[0]["network"] != NETWORK_STATUSNET) && ($r[0]["network"] != NETWORK_APPNET))) { && ($contact["network"] != NETWORK_STATUSNET) && ($contact["network"] != NETWORK_APPNET))) {
$newname = $r[0]["name"]; $newname = $contact["name"];
} }
} }
@ -1104,7 +1035,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
*/ */
if (strlen($alias)) { if (strlen($alias)) {
$newtag = '@[url=' . $alias . ']' . $newname . '[/url]'; $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
if (!stristr($str_tags, $newtag)) { if (!stripos($str_tags, '[url=' . $alias . ']')) {
if (strlen($str_tags)) { if (strlen($str_tags)) {
$str_tags .= ','; $str_tags .= ',';
} }