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];
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();
}
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();
}
killme();
info( t('Empty post discarded.') . EOL );
if(x($_REQUEST,'return'))
- goaway($a->get_baseurl() . "/" . $return_path );
+ goaway($return_path);
killme();
}
}
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));
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);
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
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;
}
}
- 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.
- // 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');
return;
if($return_path) {
- goaway($baseurl . "/" . $return_path);
+ goaway($return_path);
}
$json = array('success' => 1);