X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fitem.php;h=fbedcd86ba55199d04d4a2f8126c86e3a9624127;hb=de4a2e6fd03cd0aab94a256eba92ed593931534b;hp=5f5a96d5e9ab9d724c0728c0c4a8e7058fed34ad;hpb=2de457489ff1087b217d1c3e18350d4576a2a376;p=friendica.git diff --git a/mod/item.php b/mod/item.php index 5f5a96d5e9..fbedcd86ba 100644 --- a/mod/item.php +++ b/mod/item.php @@ -22,7 +22,9 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\GlobalContact; use Friendica\Network\Probe; +use Friendica\Object\Contact; use Friendica\Protocol\Diaspora; +use Friendica\Util\Emailer; require_once 'include/crypto.php'; require_once 'include/enotify.php'; @@ -32,7 +34,6 @@ require_once 'include/files.php'; require_once 'include/threads.php'; require_once 'include/text.php'; require_once 'include/items.php'; -require_once 'include/Contact.php'; function item_post(App $a) { @@ -146,7 +147,7 @@ function item_post(App $a) { $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); 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"]); + $parent_contact = Contact::getDetailsByURL($thrparent[0]["author-link"]); if (!isset($parent_contact["nick"])) { $probed_contact = Probe::uri($thrparent[0]["author-link"]); @@ -422,6 +423,114 @@ function item_post(App $a) { } } + // Look for any tags and linkify them + $str_tags = ''; + $inform = ''; + + $tags = get_tags($body); + + /* + * 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 && ($parent_contact['network'] == NETWORK_OSTATUS)) { + $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; + + if (!in_array($contact, $tags)) { + $body = $contact . ' ' . $body; + $tags[] = $contact; + } + + $toplevel_contact = ""; + $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)) { + 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]'; + } + + if (!in_array($toplevel_contact, $tags)) { + $tags[] = $toplevel_contact; + } + } + + $tagged = array(); + + $private_forum = false; + $only_to_forum = false; + $forum_contact = array(); + + if (count($tags)) { + foreach ($tags as $tag) { + + $tag_type = substr($tag, 0, 1); + + if ($tag_type == '#') { + continue; + } + + /* + * If we already tagged 'Robert Johnson', don't try and tag 'Robert'. + * Robert Johnson should be first in the $tags array + */ + $fullnametagged = false; + /// @TODO $tagged is initialized above if() block and is not filled, maybe old-lost code? + foreach ($tagged as $nextTag) { + if (stristr($nextTag, $tag . ' ')) { + $fullnametagged = true; + break; + } + } + if ($fullnametagged) { + continue; + } + + $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network); + if ($success['replaced']) { + $tagged[] = $tag; + } + // 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']; + } + } + } + + $original_contact_id = $contact_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; + } + /* * When a photo was uploaded into the message using the (profile wall) ajax * uploader, The permissions are initially set to disallow anybody but the @@ -434,22 +543,22 @@ function item_post(App $a) { $match = null; - if ((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) { + if (!$preview && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) { $images = $match[2]; if (count($images)) { $objecttype = ACTIVITY_OBJ_IMAGE; foreach ($images as $image) { - if (! stristr($image,System::baseUrl() . '/photo/')) { + if (!stristr($image, System::baseUrl() . '/photo/')) { continue; } $image_uri = substr($image,strrpos($image,'/') + 1); $image_uri = substr($image_uri,0, strpos($image_uri,'-')); - if (! strlen($image_uri)) { + if (!strlen($image_uri)) { continue; } - $srch = '<' . intval($contact_id) . '>'; + $srch = '<' . intval($original_contact_id) . '>'; $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' AND `resource-id` = '%s' AND `uid` = %d LIMIT 1", @@ -470,7 +579,7 @@ function item_post(App $a) { dbesc($str_group_deny), dbesc($image_uri), intval($profile_uid), - dbesc( t('Wall Photos')) + dbesc(t('Wall Photos')) ); } } @@ -528,122 +637,16 @@ function item_post(App $a) { require_once 'include/plaintext.php'; $objectdata = get_attached_data($body); - if ($post["type"] == "link") { + if ($objectdata["type"] == "link") { $objecttype = ACTIVITY_OBJ_BOOKMARK; - } elseif ($post["type"] == "video") { + } elseif ($objectdata["type"] == "video") { $objecttype = ACTIVITY_OBJ_VIDEO; - } elseif ($post["type"] == "photo") { + } elseif ($objectdata["type"] == "photo") { $objecttype = ACTIVITY_OBJ_IMAGE; } } - // Look for any tags and linkify them - $str_tags = ''; - $inform = ''; - - $tags = get_tags($body); - - /* - * 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 && ($parent_contact['network'] == NETWORK_OSTATUS)) { - $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; - - if (!in_array($contact, $tags)) { - $body = $contact . ' ' . $body; - $tags[] = $contact; - } - - $toplevel_contact = ""; - $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)) { - 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]'; - } - - if (!in_array($toplevel_contact, $tags)) { - $tags[] = $toplevel_contact; - } - } - - $tagged = array(); - - $private_forum = false; - $only_to_forum = false; - $forum_contact = array(); - - if (count($tags)) { - foreach ($tags as $tag) { - - $tag_type = substr($tag, 0, 1); - - if ($tag_type == '#') { - continue; - } - - /* - * If we already tagged 'Robert Johnson', don't try and tag 'Robert'. - * Robert Johnson should be first in the $tags array - */ - $fullnametagged = false; - /// @TODO $tagged is initialized above if() block and is not filled, maybe old-lost code? - foreach ($tagged as $nextTag) { - if (stristr($nextTag, $tag . ' ')) { - $fullnametagged = true; - break; - } - } - if ($fullnametagged) { - continue; - } - - $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network); - if ($success['replaced']) { - $tagged[] = $tag; - } - // 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 (!$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 = ''; $match = false; @@ -703,11 +706,11 @@ function item_post(App $a) { $datarray['owner-name'] = $contact_record['name']; $datarray['owner-link'] = $contact_record['url']; $datarray['owner-avatar'] = $contact_record['thumb']; - $datarray['owner-id'] = get_contact($datarray['owner-link'], 0); + $datarray['owner-id'] = Contact::getIdForURL($datarray['owner-link'], 0); $datarray['author-name'] = $author['name']; $datarray['author-link'] = $author['url']; $datarray['author-avatar'] = $author['thumb']; - $datarray['author-id'] = get_contact($datarray['author-link'], 0); + $datarray['author-id'] = Contact::getIdForURL($datarray['author-link'], 0); $datarray['created'] = datetime_convert(); $datarray['edited'] = datetime_convert(); $datarray['commented'] = datetime_convert(); @@ -834,7 +837,7 @@ function item_post(App $a) { // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); - Worker::add(PRIORITY_HIGH, "notifier", '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); @@ -984,7 +987,7 @@ function item_post(App $a) { // Store the comment signature information in case we need to relay to Diaspora - Diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id); + Diaspora::storeCommentSignature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id); } else { $parent = $post_id; @@ -1036,13 +1039,13 @@ function item_post(App $a) { $message = '' . $link . $html . $disclaimer . ''; include_once 'include/html2plain.php'; $params = array ( - 'fromName' => $a->user['username'], - 'fromEmail' => $a->user['email'], - 'toEmail' => $addr, - 'replyTo' => $a->user['email'], - 'messageSubject' => $subject, - 'htmlVersion' => $message, - 'textVersion' => html2plain($html.$disclaimer), + 'fromName' => $a->user['username'], + 'fromEmail' => $a->user['email'], + 'toEmail' => $addr, + 'replyTo' => $a->user['email'], + 'messageSubject' => $subject, + 'htmlVersion' => $message, + 'textVersion' => html2plain($html.$disclaimer) ); Emailer::send($params); } @@ -1064,10 +1067,10 @@ 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 - Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "CreateShadowentry", $post_id); + Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "CreateShadowEntry", $post_id); // Call the background process that is delivering the item to the receivers - Worker::add(PRIORITY_HIGH, "notifier", $notify_type, $post_id); + Worker::add(PRIORITY_HIGH, "Notifier", $notify_type, $post_id); logger('post_complete');