]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Use short form array syntax everywhere
[friendica.git] / mod / item.php
index 16c3ce442a6851b2d9005b8a18130f8276fd2986..0ff5eb4fef1afed07707ed6ba972517451dff8b7 100644 (file)
@@ -13,9 +13,6 @@
  *
  * All of these become an "item" which is our basic unit of
  * information.
- *
- * Posts that originate externally or do not fall into the above
- * posting categories go through item_store() instead of this function.
  */
 use Friendica\App;
 use Friendica\Core\Config;
@@ -24,6 +21,7 @@ use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\GContact;
+use Friendica\Model\Item;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
@@ -31,13 +29,11 @@ use Friendica\Util\Emailer;
 
 require_once 'include/enotify.php';
 require_once 'include/tags.php';
-require_once 'include/files.php';
 require_once 'include/threads.php';
 require_once 'include/text.php';
 require_once 'include/items.php';
 
 function item_post(App $a) {
-
        if (!local_user() && !remote_user() && !x($_REQUEST, 'commenter')) {
                return;
        }
@@ -49,7 +45,7 @@ function item_post(App $a) {
        if (x($_REQUEST, 'dropitems')) {
                $arr_drop = explode(',', $_REQUEST['dropitems']);
                drop_items($arr_drop);
-               $json = array('success' => 1);
+               $json = ['success' => 1];
                echo json_encode($json);
                killme();
        }
@@ -58,12 +54,12 @@ function item_post(App $a) {
        // logger('postinput ' . file_get_contents('php://input'));
        logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA);
 
-       $api_source = ((x($_REQUEST, 'api_source') && $_REQUEST['api_source']) ? true : false);
+       $api_source = x($_REQUEST, 'api_source') && $_REQUEST['api_source'];
 
        $message_id = ((x($_REQUEST, 'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : '');
 
-       $return_path = ((x($_REQUEST, 'return')) ? $_REQUEST['return'] : '');
-       $preview = ((x($_REQUEST, 'preview')) ? intval($_REQUEST['preview']) : 0);
+       $return_path = (x($_REQUEST, 'return') ? $_REQUEST['return'] : '');
+       $preview = (x($_REQUEST, 'preview') ? intval($_REQUEST['preview']) : 0);
 
        /*
         * Check for doubly-submitted posts, and reject duplicates
@@ -85,7 +81,6 @@ function item_post(App $a) {
 
        $parent_item = null;
        $parent_contact = null;
-       $thr_parent = '';
        $parid = 0;
        $r = false;
        $objecttype = null;
@@ -94,7 +89,7 @@ function item_post(App $a) {
 
                $objecttype = ACTIVITY_OBJ_COMMENT;
 
-               if (! x($_REQUEST, 'type')) {
+               if (!x($_REQUEST, 'type')) {
                        $_REQUEST['type'] = 'net-comment';
                }
 
@@ -108,44 +103,39 @@ function item_post(App $a) {
                                dbesc($parent_uri),
                                intval(local_user())
                        );
-               }
 
-               // if this isn't the real parent of the conversation, find it
-               if (DBM::is_result($r)) {
-                       $parid = $r[0]['parent'];
-                       $parent_uri = $r[0]['uri'];
-                       if ($r[0]['id'] != $r[0]['parent']) {
-                               $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
-                                       intval($parid)
-                               );
+                       // if this isn't the real parent of the conversation, find it
+                       if (DBM::is_result($r)) {
+                               $parid = $r[0]['parent'];
+                               if ($r[0]['id'] != $r[0]['parent']) {
+                                       $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1",
+                                               intval($parid)
+                                       );
+                               }
                        }
                }
 
                if (!DBM::is_result($r)) {
-                       notice( t('Unable to locate original post.') . EOL);
+                       notice(t('Unable to locate original post.') . EOL);
                        if (x($_REQUEST, 'return')) {
                                goaway($return_path);
                        }
                        killme();
                }
                $parent_item = $r[0];
-               $parent = $r[0]['id'];
-
-               // multi-level threading - preserve the info but re-parent to our single level threading
-               //if(($parid) && ($parid != $parent))
-               $thr_parent = $parent_uri;
+               $parent = $parent_item['id'];
+               $parent_uri = $parent_item['uri'];
 
-               if ($parent_item['contact-id'] && $uid) {
-                       $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                               intval($parent_item['contact-id']),
-                               intval($uid)
+               if ($parent_item['contact-id']) {
+                       $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
+                               intval($parent_item['contact-id'])
                        );
                        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));
+                       $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($parent_uri));
                        if (DBM::is_result($thrparent) && ($thrparent[0]["network"] === NETWORK_OSTATUS)
                                && (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
                                $parent_contact = Contact::getDetailsByURL($thrparent[0]["author-link"]);
@@ -175,11 +165,11 @@ function item_post(App $a) {
                logger('mod_item: item_post parent=' . $parent);
        }
 
-       $profile_uid = ((x($_REQUEST, 'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0);
-       $post_id     = ((x($_REQUEST, 'post_id'))     ? intval($_REQUEST['post_id'])     : 0);
-       $app         = ((x($_REQUEST, 'source'))      ? strip_tags($_REQUEST['source'])  : '');
-       $extid       = ((x($_REQUEST, 'extid'))       ? strip_tags($_REQUEST['extid'])   : '');
-       $object      = ((x($_REQUEST, 'object'))      ? $_REQUEST['object']              : '');
+       $profile_uid = (x($_REQUEST, 'profile_uid') ? intval($_REQUEST['profile_uid']) : 0);
+       $post_id     = (x($_REQUEST, 'post_id')     ? intval($_REQUEST['post_id'])     : 0);
+       $app         = (x($_REQUEST, 'source')      ? strip_tags($_REQUEST['source'])  : '');
+       $extid       = (x($_REQUEST, 'extid')       ? strip_tags($_REQUEST['extid'])   : '');
+       $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 != '') && ($profile_uid != 0)) {
@@ -233,7 +223,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];
@@ -276,11 +266,11 @@ function item_post(App $a) {
                 * been supplied via a form.
                 */
                /// @TODO use x($_REQUEST, 'foo') here
-               if (($api_source)
-                       && (! array_key_exists('contact_allow', $_REQUEST))
-                       && (! array_key_exists('group_allow', $_REQUEST))
-                       && (! array_key_exists('contact_deny', $_REQUEST))
-                       && (! array_key_exists('group_deny', $_REQUEST))) {
+               if ($api_source
+                       && !array_key_exists('contact_allow', $_REQUEST)
+                       && !array_key_exists('group_allow', $_REQUEST)
+                       && !array_key_exists('contact_deny', $_REQUEST)
+                       && !array_key_exists('group_deny', $_REQUEST)) {
                        $str_group_allow   = $user['allow_gid'];
                        $str_contact_allow = $user['allow_cid'];
                        $str_group_deny    = $user['deny_gid'];
@@ -331,13 +321,13 @@ function item_post(App $a) {
                        $private           = $parent_item['private'];
                }
 
-               $pubmail_enable    = ((x($_REQUEST, 'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && (! $private)) ? 1 : 0);
+               $pubmail_enable    = ((x($_REQUEST, 'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && !$private) ? 1 : 0);
 
                // 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') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1);
-                       if (! $mail_disabled) {
+               if ($api_source && $profile_uid && $profile_uid == local_user() && !$private) {
+                       $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())
@@ -348,11 +338,11 @@ function item_post(App $a) {
                        }
                }
 
-               if (! strlen($body)) {
+               if (!strlen($body)) {
                        if ($preview) {
                                killme();
                        }
-                       info(t('Empty post discarded.') . EOL );
+                       info(t('Empty post discarded.') . EOL);
                        if (x($_REQUEST, 'return')) {
                                goaway($return_path);
                        }
@@ -465,11 +455,11 @@ function item_post(App $a) {
                }
        }
 
-       $tagged = array();
+       $tagged = [];
 
        $private_forum = false;
        $only_to_forum = false;
-       $forum_contact = array();
+       $forum_contact = [];
 
        if (count($tags)) {
                foreach ($tags as $tag) {
@@ -485,7 +475,7 @@ function item_post(App $a) {
                         * 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?
+                       /// @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;
@@ -496,7 +486,7 @@ function item_post(App $a) {
                                continue;
                        }
 
-                       $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network);
+                       $success = handle_tag($a, $body, $inform, $str_tags, local_user() ? local_user() : $profile_uid, $tag, $network);
                        if ($success['replaced']) {
                                $tagged[] = $tag;
                        }
@@ -571,7 +561,7 @@ function item_post(App $a) {
                                        intval($profile_uid)
                                );
 
-                               if (! DBM::is_result($r)) {
+                               if (!DBM::is_result($r)) {
                                        continue;
                                }
 
@@ -595,7 +585,7 @@ function item_post(App $a) {
         */
        $match = false;
 
-       if ((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) {
+       if (!$preview && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) {
                $attaches = $match[1];
                if (count($attaches)) {
                        foreach ($attaches as $attach) {
@@ -676,31 +666,31 @@ function item_post(App $a) {
                $wall = 1;
        }
 
-       if (! strlen($verb)) {
-               $verb = ACTIVITY_POST ;
+       if (!strlen($verb)) {
+               $verb = ACTIVITY_POST;
        }
 
        if ($network == "") {
                $network = NETWORK_DFRN;
        }
 
-       $gravity = (($parent) ? 6 : 0 );
+       $gravity = ($parent ? 6 : 0);
 
        // even if the post arrived via API we are considering that it
        // originated on this site by default for determining relayability.
 
-       $origin = ((x($_REQUEST, 'origin')) ? intval($_REQUEST['origin']) : 1);
+       $origin = (x($_REQUEST, 'origin') ? intval($_REQUEST['origin']) : 1);
 
-       $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
+       $notify_type = ($parent ? 'comment-new' : 'wall-new');
 
-       $uri = (($message_id) ? $message_id : item_new_uri($a->get_hostname(),$profile_uid, $guid));
+       $uri = ($message_id ? $message_id : item_new_uri($a->get_hostname(), $profile_uid, $guid));
 
-       // Fallback so that we alway have a thr-parent
-       if (!$thr_parent) {
-               $thr_parent = $uri;
+       // Fallback so that we alway have a parent uri
+       if (!$parent_uri || !$parent) {
+               $parent_uri = $uri;
        }
 
-       $datarray = array();
+       $datarray = [];
        $datarray['uid']           = $profile_uid;
        $datarray['type']          = $post_type;
        $datarray['wall']          = $wall;
@@ -741,13 +731,14 @@ function item_post(App $a) {
        $datarray['pubmail']       = $pubmail_enable;
        $datarray['attach']        = $attachments;
        $datarray['bookmark']      = intval($bookmark);
-       $datarray['thr-parent']    = $thr_parent;
+       $datarray['parent-uri']    = $parent_uri;
        $datarray['postopts']      = $postopts;
        $datarray['origin']        = $origin;
        $datarray['moderated']     = $allow_moderated;
-       $datarray['gcontact-id']   = GContact::getId(array("url" => $datarray['author-link'], "network" => $datarray['network'],
-                                                       "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']));
+       $datarray['gcontact-id']   = GContact::getId(["url" => $datarray['author-link'], "network" => $datarray['network'],
+                                                       "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']]);
        $datarray['object']        = $object;
+       $datarray['last-child'] = 1;
 
        /*
         * These fields are for the convenience of plugins...
@@ -756,16 +747,11 @@ function item_post(App $a) {
         */
        $datarray['parent']        = $parent;
        $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'] = System::baseUrl() . '/display/' . urlencode($datarray['guid']);
-       $datarray['last-child'] = 1;
-       $datarray['visible'] = 1;
-
+       // This field is for storing the raw conversation data
        $datarray['protocol'] = PROTOCOL_DFRN;
 
        $r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $datarray['parent-uri']);
@@ -791,9 +777,9 @@ function item_post(App $a) {
                // 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);
+               $o = conversation($a,[array_merge($contact_record,$datarray)],'search', false, true);
                logger('preview: ' . $o);
-               echo json_encode(array('preview' => $o));
+               echo json_encode(['preview' => $o]);
                killme();
        }
 
@@ -805,7 +791,7 @@ function item_post(App $a) {
                        goaway($return_path);
                }
 
-               $json = array('cancel' => 1);
+               $json = ['cancel' => 1];
                if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) {
                        $json['reload'] = System::baseUrl() . '/' . $_REQUEST['jsreload'];
                }
@@ -814,35 +800,29 @@ function item_post(App $a) {
                killme();
        }
 
-       // Fill the cache field
-       put_item_in_cache($datarray);
+       if ($orig_post) {
 
-       $datarray = store_conversation($datarray);
+               // Fill the cache field
+               // This could be done in Item::update as well - but we have to check for the existance of some fields.
+               put_item_in_cache($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']),
-                       dbesc($datarray['body']),
-                       dbesc($datarray['tag']),
-                       dbesc($datarray['attach']),
-                       dbesc($datarray['file']),
-                       dbesc($datarray['rendered-html']),
-                       dbesc($datarray['rendered-hash']),
-                       dbesc(datetime_convert()),
-                       dbesc(datetime_convert()),
-                       intval($post_id),
-                       intval($profile_uid)
-               );
+               $fields = [
+                       'title' => $datarray['title'],
+                       'body' => $datarray['body'],
+                       'tag' => $datarray['tag'],
+                       'attach' => $datarray['attach'],
+                       'file' => $datarray['file'],
+                       'rendered-html' => $datarray['rendered-html'],
+                       'rendered-hash' => $datarray['rendered-hash'],
+                       'edited' => datetime_convert(),
+                       'changed' => datetime_convert()];
 
-               create_tags_from_item($post_id);
-               create_files_from_item($post_id);
-               update_thread($post_id);
+               Item::update($fields, ['id' => $post_id]);
 
                // update filetags in pconfig
                file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
 
-               Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $post_id);
-               if ((x($_REQUEST, 'return')) && strlen($return_path)) {
+               if (x($_REQUEST, 'return') && strlen($return_path)) {
                        logger('return: ' . $return_path);
                        goaway($return_path);
                }
@@ -851,125 +831,21 @@ function item_post(App $a) {
                $post_id = 0;
        }
 
-       dba::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`,
-                                       `created`, `edited`, `commented`, `received`, `changed`,
-                                       `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`,
-                                       `tag`, `inform`, `verb`, `object-type`, `postopts`,
-                                       `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`,
-                                       `pubmail`, `attach`, `bookmark`,`origin`, `moderated`, `file`,
-                                       `rendered-html`, `rendered-hash`, `gcontact-id`, `object`,
-                                       `parent`, `parent-uri`, `plink`, `last-child`, `visible`)
-               VALUES('%s', '%s', %d, '%s', %d, %d, '%s', %d,
-                       '%s', '%s', '%s', %d,
-                       '%s', '%s', '%s', %d,
-                       '%s', '%s', '%s', '%s', '%s',
-                       '%s', '%s', '%s', '%s', '%s', '%s', '%s',
-                       '%s', '%s', '%s', '%s', '%s',
-                       '%s', '%s', '%s', '%s', %d,
-                       %d, '%s', %d, %d, %d, '%s',
-                       '%s', '%s', %d, '%s',
-                       %d, '%s', '%s', %d, %d)",
-               dbesc($datarray['guid']),
-               dbesc($datarray['extid']),
-               intval($datarray['uid']),
-               dbesc($datarray['type']),
-               intval($datarray['wall']),
-               intval($datarray['gravity']),
-               dbesc($datarray['network']),
-               intval($datarray['contact-id']),
-               dbesc($datarray['owner-name']),
-               dbesc($datarray['owner-link']),
-               dbesc($datarray['owner-avatar']),
-               intval($datarray['owner-id']),
-               dbesc($datarray['author-name']),
-               dbesc($datarray['author-link']),
-               dbesc($datarray['author-avatar']),
-               intval($datarray['author-id']),
-               dbesc($datarray['created']),
-               dbesc($datarray['edited']),
-               dbesc($datarray['commented']),
-               dbesc($datarray['received']),
-               dbesc($datarray['changed']),
-               dbesc($datarray['uri']),
-               dbesc($datarray['thr-parent']),
-               dbesc($datarray['title']),
-               dbesc($datarray['body']),
-               dbesc($datarray['app']),
-               dbesc($datarray['location']),
-               dbesc($datarray['coord']),
-               dbesc($datarray['tag']),
-               dbesc($datarray['inform']),
-               dbesc($datarray['verb']),
-               dbesc($datarray['object-type']),
-               dbesc($datarray['postopts']),
-               dbesc($datarray['allow_cid']),
-               dbesc($datarray['allow_gid']),
-               dbesc($datarray['deny_cid']),
-               dbesc($datarray['deny_gid']),
-               intval($datarray['private']),
-               intval($datarray['pubmail']),
-               dbesc($datarray['attach']),
-               intval($datarray['bookmark']),
-               intval($datarray['origin']),
-               intval($datarray['moderated']),
-               dbesc($datarray['file']),
-               dbesc($datarray['rendered-html']),
-               dbesc($datarray['rendered-hash']),
-               intval($datarray['gcontact-id']),
-               dbesc($datarray['object']),
-               intval($datarray['parent']),
-               dbesc($datarray['parent-uri']),
-               dbesc($datarray['plink']),
-               intval($datarray['last-child']),
-               intval($datarray['visible'])
-       );
+       unset($datarray['edit']);
+       unset($datarray['self']);
+       unset($datarray['api_source']);
 
-       if (DBM::is_result($r)) {
-               $post_id = dba::lastInsertId();
-       } else {
-               logger('mod_item: unable to create post.');
-               $post_id = 0;
-       }
-
-       if ($post_id == 0) {
-               dba::commit();
-               logger('mod_item: unable to retrieve post that was just stored.');
-               notice(t('System error. Post not saved.') . EOL);
-               goaway($return_path);
-               // NOTREACHED
-       }
-
-       logger('mod_item: saved item ' . $post_id);
+       $post_id = item_store($datarray);
 
        $datarray["id"] = $post_id;
 
-       item_set_last_item($datarray);
-
        // update filetags in pconfig
-       file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
+       file_tag_update_pconfig($uid, $categories_old, $categories_new, 'category');
 
+       // These notifications are sent if someone else is commenting other your wall
        if ($parent) {
-
-               // This item is the last leaf and gets the comment box, clear any ancestors
-               $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d AND `last-child` AND `id` != %d",
-                       dbesc(datetime_convert()),
-                       intval($parent),
-                       intval($post_id)
-               );
-
-               // update the commented timestamp on the parent
-               q("UPDATE `item` SET `visible` = 1, `commented` = '%s', `changed` = '%s' WHERE `id` = %d",
-                       dbesc(datetime_convert()),
-                       dbesc(datetime_convert()),
-                       intval($parent)
-               );
-
                if ($contact_record != $author) {
-                       notification(array(
+                       notification([
                                'type'         => NOTIFY_COMMENT,
                                'notify_flags' => $user['notify-flags'],
                                'language'     => $user['language'],
@@ -985,23 +861,14 @@ function item_post(App $a) {
                                'otype'        => 'item',
                                'parent'       => $parent,
                                'parent_uri'   => $parent_item['uri']
-                       ));
-
+                       ]);
                }
 
-
                // Store the comment signature information in case we need to relay to Diaspora
                Diaspora::storeCommentSignature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
-
        } else {
-               $parent = $post_id;
-
-               $r = q("UPDATE `item` SET `parent` = %d WHERE `id` = %d",
-                       intval($parent),
-                       intval($post_id));
-
                if (($contact_record != $author) && !count($forum_contact)) {
-                       notification(array(
+                       notification([
                                'type'         => NOTIFY_WALL,
                                'notify_flags' => $user['notify-flags'],
                                'language'     => $user['language'],
@@ -1015,7 +882,7 @@ function item_post(App $a) {
                                'source_photo' => $datarray['author-avatar'],
                                'verb'         => ACTIVITY_POST,
                                'otype'        => 'item'
-                       ));
+                       ]);
                }
        }
 
@@ -1026,23 +893,23 @@ function item_post(App $a) {
                if (count($erecips)) {
                        foreach ($erecips as $recip) {
                                $addr = trim($recip);
-                               if (! strlen($addr)) {
+                               if (!strlen($addr)) {
                                        continue;
                                }
-                               $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username'])
+                               $disclaimer = '<hr />' . sprintf(t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username'])
                                        . '<br />';
-                               $disclaimer .= sprintf( t('You may visit them online at %s'), System::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::encodeHeader($datarray['title'], 'UTF-8');
                                } else {
-                                       $subject = Email::encodeHeader('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8');
+                                       $subject = Email::encodeHeader('[Friendica]' . ' ' . sprintf(t('%s posted an update.'), $a->user['username']), 'UTF-8');
                                }
                                $link = '<a href="' . System::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
                                $html    = prepare_body($datarray);
                                $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
                                include_once 'include/html2plain.php';
-                               $params = array (
+                               $params =  [
                                        'fromName' => $a->user['username'],
                                        'fromEmail' => $a->user['email'],
                                        'toEmail' => $addr,
@@ -1050,28 +917,17 @@ function item_post(App $a) {
                                        'messageSubject' => $subject,
                                        'htmlVersion' => $message,
                                        'textVersion' => html2plain($html.$disclaimer)
-                               );
+                               ];
                                Emailer::send($params);
                        }
                }
        }
 
-       if ($post_id == $parent) {
-               add_thread($post_id);
-       } else {
-               update_thread($parent, true);
-       }
-
-       dba::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
-       Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "CreateShadowEntry", $post_id);
+       Worker::add(['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);
@@ -1093,7 +949,7 @@ function item_post_return($baseurl, $api_source, $return_path) {
                goaway($return_path);
        }
 
-       $json = array('success' => 1);
+       $json = ['success' => 1];
        if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) {
                $json['reload'] = $baseurl . '/' . $_REQUEST['jsreload'];
        }
@@ -1108,7 +964,7 @@ function item_post_return($baseurl, $api_source, $return_path) {
 
 function item_content(App $a) {
 
-       if ((! local_user()) && (! remote_user())) {
+       if (!local_user() && !remote_user()) {
                return;
        }
 
@@ -1119,7 +975,7 @@ function item_content(App $a) {
                $o = drop_item($a->argv[2], !is_ajax());
                if (is_ajax()) {
                        // ajax return: [<item id>, 0 (no perm) | <owner id>]
-                       echo json_encode(array(intval($a->argv[2]), intval($o)));
+                       echo json_encode([intval($a->argv[2]), intval($o)]);
                        killme();
                }
        }
@@ -1264,7 +1120,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) && ($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),
@@ -1282,7 +1138,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),
@@ -1291,7 +1147,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)
@@ -1327,7 +1183,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                        $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 .= ',';
                                }
@@ -1340,7 +1196,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                         */
                        if (strlen($alias)) {
                                $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
-                               if (! stristr($str_tags, $newtag)) {
+                               if (!stristr($str_tags, $newtag)) {
                                        if (strlen($str_tags)) {
                                                $str_tags .= ',';
                                        }
@@ -1350,5 +1206,5 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                }
        }
 
-       return array('replaced' => $replaced, 'contact' => $r[0]);
+       return ['replaced' => $replaced, 'contact' => $r[0]];
 }