X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fitem.php;h=587bd90cedfab81203ed028c5880d490dc53c635;hb=9e99066fd70a9dd9a291a523afba1a390f0e3a0b;hp=7f0f48c05c2edc1c13f73dddb9c7f62d95a695f8;hpb=07a0d300c34e46e12b4bcd6312797bdedeb8557b;p=friendica.git diff --git a/mod/item.php b/mod/item.php index 7f0f48c05c..587bd90ced 100644 --- a/mod/item.php +++ b/mod/item.php @@ -15,6 +15,14 @@ * posting categories go through item_store() instead of this function. */ +use Friendica\App; +use Friendica\Core\Config; +use Friendica\Core\System; +use Friendica\Core\Worker; +use Friendica\Database\DBM; +use Friendica\Network\Probe; +use Friendica\Protocol\Diaspora; + require_once 'include/crypto.php'; require_once 'include/enotify.php'; require_once 'include/email.php'; @@ -23,8 +31,6 @@ require_once 'include/files.php'; require_once 'include/threads.php'; require_once 'include/text.php'; require_once 'include/items.php'; -require_once 'include/Scrape.php'; -require_once 'include/diaspora.php'; require_once 'include/Contact.php'; function item_post(App $a) { @@ -64,7 +70,7 @@ function item_post(App $a) { if (!$preview && x($_REQUEST, 'post_id_random')) { if (x($_SESSION, 'post-random') && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { logger("item post: duplicate post", LOGGER_DEBUG); - item_post_return(App::get_baseurl(), $api_source, $return_path); + item_post_return(System::baseUrl(), $api_source, $return_path); } else { $_SESSION['post-random'] = $_REQUEST['post_id_random']; } @@ -102,7 +108,7 @@ function item_post(App $a) { } // if this isn't the real parent of the conversation, find it - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { $parid = $r[0]['parent']; $parent_uri = $r[0]['uri']; if ($r[0]['id'] != $r[0]['parent']) { @@ -112,7 +118,7 @@ function item_post(App $a) { } } - if (! dbm::is_result($r)) { + if (! DBM::is_result($r)) { notice( t('Unable to locate original post.') . EOL); if (x($_REQUEST, 'return')) { goaway($return_path); @@ -131,19 +137,18 @@ function item_post(App $a) { intval($parent_item['contact-id']), intval($uid) ); - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { $parent_contact = $r[0]; } // If the contact id doesn't fit with the contact, then set the contact to null $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); - if (dbm::is_result($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS) - AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { + if (DBM::is_result($thrparent) && ($thrparent[0]["network"] === NETWORK_OSTATUS) + && (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) { $parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]); if (!isset($parent_contact["nick"])) { - require_once 'include/Scrape.php'; - $probed_contact = probe_url($thrparent[0]["author-link"]); + $probed_contact = Probe::uri($thrparent[0]["author-link"]); if ($probed_contact["network"] != NETWORK_FEED) { $parent_contact = $probed_contact; $parent_contact["nurl"] = normalise_link($probed_contact["url"]); @@ -174,13 +179,13 @@ function item_post(App $a) { $object = ((x($_REQUEST, 'object')) ? $_REQUEST['object'] : ''); // Check for multiple posts with the same message id (when the post was created via API) - if (($message_id != '') AND ($profile_uid != 0)) { + if (($message_id != '') && ($profile_uid != 0)) { $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($message_id), intval($profile_uid) ); - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { logger("Message with URI ".$message_id." already exists for user ".$profile_uid, LOGGER_DEBUG); return; } @@ -222,7 +227,7 @@ function item_post(App $a) { intval($profile_uid), intval($post_id) ); - if (! dbm::is_result($i)) { + if (! DBM::is_result($i)) { killme(); } $orig_post = $i[0]; @@ -233,7 +238,7 @@ function item_post(App $a) { $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($profile_uid) ); - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { $user = $r[0]; } @@ -308,8 +313,8 @@ function item_post(App $a) { // for non native networks use the network of the original post as network of the item if (($parent_item['network'] != NETWORK_DIASPORA) - AND ($parent_item['network'] != NETWORK_OSTATUS) - AND ($network == "")) { + && ($parent_item['network'] != NETWORK_OSTATUS) + && ($network == "")) { $network = $parent_item['network']; } @@ -325,12 +330,13 @@ function item_post(App $a) { // if using the API, we won't see pubmail_enable - figure out if it should be set if ($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) { - $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); + $mail_disabled = ((function_exists('imap_open') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1); if (! $mail_disabled) { + /// @TODO Check if only pubmail is loaded, * loads all columns $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); - if (dbm::is_result($r) && intval($r[0]['pubmail'])) { + if (DBM::is_result($r) && intval($r[0]['pubmail'])) { $pubmail_enabled = true; } } @@ -372,7 +378,7 @@ function item_post(App $a) { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); } elseif(remote_user()) { - if (is_array($_SESSION['remote'])) { + if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) { foreach ($_SESSION['remote'] as $v) { if ($v['uid'] == $profile_uid) { $contact_id = $v['cid']; @@ -387,7 +393,7 @@ function item_post(App $a) { } } - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { $author = $r[0]; $contact_id = $author['id']; } @@ -400,7 +406,7 @@ function item_post(App $a) { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($profile_uid) ); - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { $contact_record = $r[0]; } } @@ -434,7 +440,7 @@ function item_post(App $a) { $objecttype = ACTIVITY_OBJ_IMAGE; foreach ($images as $image) { - if (! stristr($image,App::get_baseurl() . '/photo/')) { + if (! stristr($image,System::baseUrl() . '/photo/')) { continue; } $image_uri = substr($image,strrpos($image,'/') + 1); @@ -451,7 +457,7 @@ function item_post(App $a) { intval($profile_uid) ); - if (! dbm::is_result($r)) { + if (! DBM::is_result($r)) { continue; } @@ -483,7 +489,7 @@ function item_post(App $a) { intval($profile_uid), intval($attach) ); - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc($str_contact_allow), @@ -502,7 +508,7 @@ function item_post(App $a) { $bookmark = 0; $data = get_attachment_data($body); - if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) OR isset($data["type"])) { + if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"])) { $objecttype = ACTIVITY_OBJ_BOOKMARK; $bookmark = 1; } @@ -541,10 +547,10 @@ function item_post(App $a) { * add a statusnet style reply tag if the original post was from there * and we are replying, and there isn't one already */ - if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) { + if ($parent && ($parent_contact['network'] == NETWORK_OSTATUS)) { $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; - if (!in_array($contact,$tags)) { + if (!in_array($contact, $tags)) { $body = $contact . ' ' . $body; $tags[] = $contact; } @@ -553,8 +559,12 @@ function item_post(App $a) { $toplevel_parent = q("SELECT `contact`.* FROM `contact` INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `contact`.`url` = `item`.`author-link` WHERE `item`.`id` = `item`.`parent` AND `item`.`parent` = %d", intval($parent)); - if (dbm::is_result($toplevel_parent)) { - $toplevel_contact = '@' . $toplevel_parent[0]['nick'] . '+' . $toplevel_parent[0]['id']; + if (DBM::is_result($toplevel_parent)) { + if (!empty($toplevel_parent[0]['addr'])) { + $toplevel_contact = '@' . $toplevel_parent[0]['addr']; + } else { + $toplevel_contact = '@' . $toplevel_parent[0]['nick'] . '+' . $toplevel_parent[0]['id']; + } } else { $toplevel_parent = q("SELECT `author-link`, `author-name` FROM `item` WHERE `id` = `parent` AND `parent` = %d", intval($parent)); $toplevel_contact = '@[url=' . $toplevel_parent[0]['author-link'] . ']' . $toplevel_parent[0]['author-name'] . '[/url]'; @@ -568,11 +578,15 @@ function item_post(App $a) { $tagged = array(); $private_forum = false; + $only_to_forum = false; + $forum_contact = array(); if (count($tags)) { foreach ($tags as $tag) { - if (strpos($tag, '#') === 0) { + $tag_type = substr($tag, 0, 1); + + if ($tag_type == '#') { continue; } @@ -596,18 +610,37 @@ function item_post(App $a) { if ($success['replaced']) { $tagged[] = $tag; } - if (is_array($success['contact']) && intval($success['contact']['prv'])) { - $private_forum = true; + // When the forum is private or the forum is addressed with a "!" make the post private + if (is_array($success['contact']) && ($success['contact']['prv'] || ($tag_type == '!'))) { + $private_forum = $success['contact']['prv']; + $only_to_forum = ($tag_type == '!'); + $private_id = $success['contact']['id']; + $forum_contact = $success['contact']; + } elseif (is_array($success['contact']) && $success['contact']['forum'] && + ($str_contact_allow == '<' . $success['contact']['id'] . '>')) { + $private_forum = false; + $only_to_forum = true; $private_id = $success['contact']['id']; + $forum_contact = $success['contact']; } } } - if (($private_forum) && (! $parent) && (! $private)) { - // we tagged a private forum in a top level post and the message was public. - // Restrict it. - $private = 1; - $str_contact_allow = '<' . $private_id . '>'; + if (!$parent && count($forum_contact) && ($private_forum || $only_to_forum)) { + // we tagged a forum in a top level post. Now we change the post + $private = $private_forum; + + $str_group_allow = ''; + $str_contact_deny = ''; + $str_group_deny = ''; + if ($private_forum) { + $str_contact_allow = '<' . $private_id . '>'; + } else { + $str_contact_allow = ''; + } + $contact_id = $private_id; + $contact_record = $forum_contact; + $_REQUEST['origin'] = false; } $attachments = ''; @@ -619,11 +652,11 @@ function item_post(App $a) { intval($profile_uid), intval($mtch) ); - if (dbm::is_result($r)) { + if (DBM::is_result($r)) { if (strlen($attachments)) { $attachments .= ','; } - $attachments .= '[attach]href="' . App::get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]'; + $attachments .= '[attach]href="' . System::baseUrl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]'; } $body = str_replace($match[1],'',$body); } @@ -631,7 +664,7 @@ function item_post(App $a) { $wall = 0; - if ($post_type === 'wall' || $post_type === 'wall-comment') { + if (($post_type === 'wall' || $post_type === 'wall-comment') && !count($forum_contact)) { $wall = 1; } @@ -717,11 +750,26 @@ function item_post(App $a) { $datarray['self'] = $self; // $datarray['prvnets'] = $user['prvnets']; + // This triggers posts via API and the mirror functions + $datarray['api_source'] = $api_source; + $datarray['parent-uri'] = ($parent == 0) ? $uri : $parent_item['uri']; - $datarray['plink'] = App::get_baseurl() . '/display/' . urlencode($datarray['guid']); + $datarray['plink'] = System::baseUrl() . '/display/' . urlencode($datarray['guid']); $datarray['last-child'] = 1; $datarray['visible'] = 1; + $datarray['protocol'] = PROTOCOL_DFRN; + + $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $datarray['parent-uri']); + if (DBM::is_result($r)) { + if ($r['conversation-uri'] != '') { + $datarray['conversation-uri'] = $r['conversation-uri']; + } + if ($r['conversation-href'] != '') { + $datarray['conversation-href'] = $r['conversation-href']; + } + } + if ($orig_post) { $datarray['edit'] = true; } @@ -751,7 +799,7 @@ function item_post(App $a) { $json = array('cancel' => 1); if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) { - $json['reload'] = App::get_baseurl() . '/' . $_REQUEST['jsreload']; + $json['reload'] = System::baseUrl() . '/' . $_REQUEST['jsreload']; } echo json_encode($json); @@ -761,6 +809,8 @@ function item_post(App $a) { // Fill the cache field put_item_in_cache($datarray); + $datarray = store_conversation($datarray); + if ($orig_post) { $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($datarray['title']), @@ -783,7 +833,7 @@ function item_post(App $a) { // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); - proc_run(PRIORITY_HIGH, "include/notifier.php", 'edit_post', $post_id); + Worker::add(PRIORITY_HIGH, "notifier", 'edit_post', $post_id); if ((x($_REQUEST, 'return')) && strlen($return_path)) { logger('return: ' . $return_path); goaway($return_path); @@ -793,8 +843,7 @@ function item_post(App $a) { $post_id = 0; } - q("COMMIT"); - q("START TRANSACTION;"); + dba::transaction(); $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`, `owner-name`,`owner-link`,`owner-avatar`, `owner-id`, @@ -871,20 +920,15 @@ function item_post(App $a) { intval($datarray['visible']) ); - if (dbm::is_result($r)) { - $r = q("SELECT LAST_INSERT_ID() AS `item-id`"); - if (dbm::is_result($r)) { - $post_id = $r[0]['item-id']; - } else { - $post_id = 0; - } + if (DBM::is_result($r)) { + $post_id = dba::lastInsertId(); } else { logger('mod_item: unable to create post.'); $post_id = 0; } if ($post_id == 0) { - q("COMMIT"); + dba::commit(); logger('mod_item: unable to retrieve post that was just stored.'); notice(t('System error. Post not saved.') . EOL); goaway($return_path); @@ -925,7 +969,7 @@ function item_post(App $a) { 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $datarray, - 'link' => App::get_baseurl().'/display/'.urlencode($datarray['guid']), + 'link' => System::baseUrl().'/display/'.urlencode($datarray['guid']), 'source_name' => $datarray['author-name'], 'source_link' => $datarray['author-link'], 'source_photo' => $datarray['author-avatar'], @@ -948,7 +992,7 @@ function item_post(App $a) { intval($parent), intval($post_id)); - if ($contact_record != $author) { + if (($contact_record != $author) && !count($forum_contact)) { notification(array( 'type' => NOTIFY_WALL, 'notify_flags' => $user['notify-flags'], @@ -957,7 +1001,7 @@ function item_post(App $a) { 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $datarray, - 'link' => App::get_baseurl().'/display/'.urlencode($datarray['guid']), + 'link' => System::baseUrl().'/display/'.urlencode($datarray['guid']), 'source_name' => $datarray['author-name'], 'source_link' => $datarray['author-link'], 'source_photo' => $datarray['author-avatar'], @@ -979,14 +1023,14 @@ function item_post(App $a) { } $disclaimer = '
' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username']) . '
'; - $disclaimer .= sprintf( t('You may visit them online at %s'), App::get_baseurl() . '/profile/' . $a->user['nickname']) . EOL; + $disclaimer .= sprintf( t('You may visit them online at %s'), System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; if (!$datarray['title']=='') { $subject = email_header_encode($datarray['title'], 'UTF-8'); } else { $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); } - $link = '' . $a->user['username'] . '

'; + $link = '' . $a->user['username'] . '

'; $html = prepare_body($datarray); $message = '' . $link . $html . $disclaimer . ''; include_once 'include/html2plain.php'; @@ -1010,7 +1054,7 @@ function item_post(App $a) { update_thread($parent, true); } - q("COMMIT"); + dba::commit(); create_tags_from_item($post_id); create_files_from_item($post_id); @@ -1019,14 +1063,14 @@ function item_post(App $a) { // We now do it in the background to save some time. // This is important in interactive environments like the frontend or the API. // We don't fork a new process since this is done anyway with the following command - proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id); + Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "create_shadowentry", $post_id); // Call the background process that is delivering the item to the receivers - proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $post_id); + Worker::add(PRIORITY_HIGH, "notifier", $notify_type, $post_id); logger('post_complete'); - item_post_return(App::get_baseurl(), $api_source, $return_path); + item_post_return(System::baseUrl(), $api_source, $return_path); // NOTREACHED } @@ -1089,14 +1133,15 @@ function item_content(App $a) { * @return boolean true if replaced, false if not replaced */ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") { - require_once 'include/Scrape.php'; require_once 'include/socgraph.php'; $replaced = false; $r = null; + $tag_type = '@'; //is it a person tag? - if (strpos($tag, '@') === 0) { + if ((strpos($tag, '@') === 0) || (strpos($tag, '!') === 0)) { + $tag_type = substr($tag, 0, 1); //is it already replaced? if (strpos($tag, '[url=')) { //append tag to str_tags @@ -1108,19 +1153,19 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } // Checking for the alias that is used for OStatus - $pattern = "/@\[url\=(.*?)\](.*?)\[\/url\]/ism"; + $pattern = "/[@!]\[url\=(.*?)\](.*?)\[\/url\]/ism"; if (preg_match($pattern, $tag, $matches)) { $r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0", normalise_link($matches[1])); - if (!dbm::is_result($r)) { + 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)) { + if (DBM::is_result($r)) { $data = $r[0]; } else { - $data = probe_url($matches[1]); + $data = Probe::uri($matches[1]); } if ($data["alias"] != "") { @@ -1150,7 +1195,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n // Is it in format @user@domain.tld or @http://domain.tld/...? // First check the contact table for the address - $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact` + $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify`, `forum`, `prv` FROM `contact` WHERE `addr` = '%s' AND `uid` = %d AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) LIMIT 1", @@ -1160,8 +1205,8 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n ); // Then check in the contact table for the url - if (!dbm::is_result($r)) { - $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact` + 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", @@ -1172,7 +1217,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } // Then check in the global contacts for the address - if (!dbm::is_result($r)) { + 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", @@ -1182,7 +1227,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } // Then check in the global contacts for the url - if (!dbm::is_result($r)) { + 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", @@ -1191,8 +1236,8 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n ); } - if (!dbm::is_result($r)) { - $probed = probe_url($name); + if (!DBM::is_result($r)) { + $probed = Probe::uri($name); if ($result['network'] != NETWORK_PHANTOM) { update_gcontact($probed); $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", @@ -1201,9 +1246,9 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } } else { $r = false; - if (strrpos($name,'+')) { + if (strrpos($name, '+')) { // Is it in format @nick+number? - $tagcid = intval(substr($name,strrpos($name,'+') + 1)); + $tagcid = intval(substr($name, strrpos($name, '+') + 1)); $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($tagcid), @@ -1212,7 +1257,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } // select someone by attag or nick and the name passed in the current network - if(!dbm::is_result($r) AND ($network != "")) + if(!DBM::is_result($r) && ($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", dbesc($name), dbesc($name), @@ -1221,7 +1266,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n ); //select someone from this user's contacts by name in the current network - if (!dbm::is_result($r) AND ($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), @@ -1230,7 +1275,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } // select someone by attag or nick and the name passed in - if(!dbm::is_result($r)) { + if(!DBM::is_result($r)) { $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", dbesc($name), dbesc($name), @@ -1239,7 +1284,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } // select someone from this user's contacts by name - if(!dbm::is_result($r)) { + if(!DBM::is_result($r)) { $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($name), intval($profile_uid) @@ -1247,8 +1292,8 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } } - if (dbm::is_result($r)) { - if (strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) { + if (DBM::is_result($r)) { + if (strlen($inform) && (isset($r[0]["notify"]) || isset($r[0]["id"]))) { $inform .= ','; } @@ -1261,33 +1306,34 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n $profile = $r[0]["url"]; $alias = $r[0]["alias"]; $newname = $r[0]["nick"]; - if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER) - AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) { + if (($newname == "") || (($r[0]["network"] != NETWORK_OSTATUS) && ($r[0]["network"] != NETWORK_TWITTER) + && ($r[0]["network"] != NETWORK_STATUSNET) && ($r[0]["network"] != NETWORK_APPNET))) { $newname = $r[0]["name"]; } } //if there is an url for this persons profile - if (isset($profile) AND ($newname != "")) { - + if (isset($profile) && ($newname != "")) { $replaced = true; // create profile link - $profile = str_replace(',','%2c',$profile); - $newtag = '@[url='.$profile.']'.$newname.'[/url]'; - $body = str_replace('@'.$name, $newtag, $body); + $profile = str_replace(',', '%2c', $profile); + $newtag = $tag_type.'[url=' . $profile . ']' . $newname . '[/url]'; + $body = str_replace($tag_type . $name, $newtag, $body); // append tag to str_tags - if (! stristr($str_tags,$newtag)) { + if (! stristr($str_tags, $newtag)) { if (strlen($str_tags)) { $str_tags .= ','; } $str_tags .= $newtag; } - // Status.Net seems to require the numeric ID URL in a mention if the person isn't - // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both. + /* + * Status.Net seems to require the numeric ID URL in a mention if the person isn't + * subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both. + */ if (strlen($alias)) { - $newtag = '@[url='.$alias.']'.$newname.'[/url]'; - if (! stristr($str_tags,$newtag)) { + $newtag = '@[url=' . $alias . ']' . $newname . '[/url]'; + if (! stristr($str_tags, $newtag)) { if (strlen($str_tags)) { $str_tags .= ','; }