X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fitem.php;h=0deade41811fb4e0811f0063736c0df47c664403;hb=13150c09a56de662677ee17a1614a2ee55931890;hp=4b23b219b79be431ecc749618925c2168d534925;hpb=8cab3b55924f084261564636da9211e615bf52e8;p=friendica.git diff --git a/mod/item.php b/mod/item.php index 4b23b219b7..0deade4181 100644 --- a/mod/item.php +++ b/mod/item.php @@ -115,7 +115,7 @@ function item_post(&$a) { if(($r === false) || (! count($r))) { notice( t('Unable to locate original post.') . EOL); if(x($_REQUEST,'return')) - goaway($a->get_baseurl() . "/" . $return_path ); + goaway($return_path); killme(); } $parent_item = $r[0]; @@ -130,7 +130,7 @@ function item_post(&$a) { intval($parent_item['contact-id']), intval($uid) ); - if(count($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 @@ -175,6 +175,19 @@ function item_post(&$a) { $app = ((x($_REQUEST,'source')) ? strip_tags($_REQUEST['source']) : ''); $extid = ((x($_REQUEST,'extid')) ? strip_tags($_REQUEST['extid']) : ''); + // Check for multiple posts with the same message id (when the post was created via API) + if (($message_id != '') AND ($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)) { + logger("Message with URI ".$message_id." already exists for user ".$profile_uid, LOGGER_DEBUG); + return; + } + } + $allow_moderated = false; // here is where we are going to check for permission to post a moderated comment. @@ -184,7 +197,7 @@ function item_post(&$a) { if((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) { notice( t('Permission denied.') . EOL) ; if(x($_REQUEST,'return')) - goaway($a->get_baseurl() . "/" . $return_path ); + goaway($return_path); killme(); } @@ -196,7 +209,7 @@ function item_post(&$a) { if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) { notice( t('Permission denied.') . EOL) ; if(x($_REQUEST,'return')) - goaway($a->get_baseurl() . "/" . $return_path ); + goaway($return_path); killme(); } @@ -220,7 +233,7 @@ function item_post(&$a) { $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($profile_uid) ); - if(count($r)) + if (dbm::is_result($r)) $user = $r[0]; if($orig_post) { @@ -326,7 +339,7 @@ function item_post(&$a) { killme(); info( t('Empty post discarded.') . EOL ); if(x($_REQUEST,'return')) - goaway($a->get_baseurl() . "/" . $return_path ); + goaway($return_path); killme(); } } @@ -385,7 +398,7 @@ function item_post(&$a) { } } - if(count($r)) { + if (dbm::is_result($r)) { $author = $r[0]; $contact_id = $author['id']; } @@ -399,7 +412,7 @@ function item_post(&$a) { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($profile_uid) ); - if(count($r)) + if (dbm::is_result($r)) $contact_record = $r[0]; } @@ -482,7 +495,7 @@ function item_post(&$a) { intval($profile_uid), intval($attach) ); - if(count($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), @@ -623,7 +636,7 @@ function item_post(&$a) { intval($profile_uid), intval($mtch) ); - if(count($r)) { + if (dbm::is_result($r)) { if(strlen($attachments)) $attachments .= ','; $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]'; @@ -731,6 +744,9 @@ function item_post(&$a) { if($preview) { require_once('include/conversation.php'); + // We set the datarray ID to -1 because in preview mode the dataray + // doesn't have an ID. + $datarray["id"] = -1; $o = conversation($a,array(array_merge($contact_record,$datarray)),'search', false, true); logger('preview: ' . $o); echo json_encode(array('preview' => $o)); @@ -743,7 +759,7 @@ function item_post(&$a) { if(x($datarray,'cancel')) { logger('mod_item: post cancelled by plugin.'); if($return_path) { - goaway($a->get_baseurl() . "/" . $return_path); + goaway($return_path); } $json = array('cancel' => 1); @@ -782,7 +798,7 @@ function item_post(&$a) { proc_run(PRIORITY_HIGH, "include/notifier.php", 'edit_post', $post_id); if((x($_REQUEST,'return')) && strlen($return_path)) { logger('return: ' . $return_path); - goaway($a->get_baseurl() . "/" . $return_path ); + goaway($return_path); } killme(); } else @@ -864,17 +880,26 @@ function item_post(&$a) { intval($datarray['visible']) ); - $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", - dbesc($datarray['uri'])); - if(!count($r)) { + 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; + } + } else { + logger('mod_item: unable to create post.'); + $post_id = 0; + } + + if ($post_id == 0) { q("COMMIT"); logger('mod_item: unable to retrieve post that was just stored.'); - notice( t('System error. Post not saved.') . EOL); - goaway($a->get_baseurl() . "/" . $return_path ); + notice(t('System error. Post not saved.') . EOL); + goaway($return_path); // NOTREACHED } - $post_id = $r[0]['id']; logger('mod_item: saved item ' . $post_id); $datarray["id"] = $post_id; @@ -987,42 +1012,24 @@ function item_post(&$a) { } } - create_tags_from_item($post_id); - create_files_from_item($post_id); - if ($post_id == $parent) { add_thread($post_id); - q("COMMIT"); - - add_shadow_thread($post_id); } else { update_thread($parent, true); - q("COMMIT"); - - // Insert an item entry for UID=0 for global entries - // We have to remove or change some data before that, - // so that the post appear like a regular received post. - unset($datarray['self']); - unset($datarray['wall']); - unset($datarray['origin']); + } - if (in_array($datarray['type'], array("net-comment", "wall-comment"))) - $datarray['type'] = 'remote-comment'; - elseif ($datarray['type'] == 'wall') - $datarray['type'] = 'remote'; + q("COMMIT"); - add_shadow_entry($datarray); - } + create_tags_from_item($post_id); + create_files_from_item($post_id); - // This is a real juggling act on shared hosting services which kill your processes - // e.g. dreamhost. We used to start delivery to our native delivery agents in the background - // and then run our plugin delivery from the foreground. We're now doing plugin delivery first, - // because as soon as you start loading up a bunch of remote delivey processes, *this* page is - // likely to get killed off. If you end up looking at an /item URL and a blank page, - // it's very likely the delivery got killed before all your friends could be notified. - // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting, - // or cut back on plugins which do remote deliveries. + // Insert an item entry for UID=0 for global entries. + // 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); + // Call the background process that is delivering the item to the receivers proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $post_id); logger('post_complete'); @@ -1038,7 +1045,7 @@ function item_post_return($baseurl, $api_source, $return_path) { return; if($return_path) { - goaway($baseurl . "/" . $return_path); + goaway($return_path); } $json = array('success' => 1);