X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fitem.php;h=0deade41811fb4e0811f0063736c0df47c664403;hb=3cb93240727d8c6958e5626655e352152c74ce31;hp=5befa8c01a5722e9f21a0c7023f19db8570bf71e;hpb=75a996c4e41a6739693195d362e300f0690d8418;p=friendica.git diff --git a/mod/item.php b/mod/item.php index 5befa8c01a..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]; @@ -197,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(); } @@ -209,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(); } @@ -339,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(); } } @@ -744,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)); @@ -756,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); @@ -795,12 +798,15 @@ 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 $post_id = 0; + q("COMMIT"); + q("START TRANSACTION;"); + $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`, `owner-name`,`owner-link`,`owner-avatar`, `owner-id`, `author-name`, `author-link`, `author-avatar`, `author-id`, @@ -874,20 +880,32 @@ 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; + item_set_last_item($datarray); + // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); @@ -994,57 +1012,24 @@ function item_post(&$a) { } } - create_tags_from_item($post_id); - create_files_from_item($post_id); - - if ($post_id == $parent) + if ($post_id == $parent) { add_thread($post_id); - else { + } else { update_thread($parent, true); - - // 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. - // Additionally there is some data that isn't a database field. - $arr = $datarray; - - $arr['app'] = $arr['source']; - unset($arr['source']); - - unset($arr['self']); - unset($arr['wall']); - unset($arr['origin']); - unset($arr['api_source']); - unset($arr['message_id']); - unset($arr['profile_uid']); - unset($arr['post_id']); - unset($arr['dropitems']); - unset($arr['commenter']); - unset($arr['return']); - unset($arr['preview']); - unset($arr['post_id_random']); - unset($arr['emailcc']); - unset($arr['pubmail_enable']); - unset($arr['category']); - unset($arr['jsreload']); - - if (in_array($arr['type'], array("net-comment", "wall-comment"))) { - $arr['type'] = 'remote-comment'; - } elseif ($arr['type'] == 'wall') { - $arr['type'] = 'remote'; - } - add_shadow_entry($arr); } - // 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. + q("COMMIT"); + + create_tags_from_item($post_id); + create_files_from_item($post_id); + + // 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'); @@ -1060,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);