]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Fix for: empty posts and comments that hadn't been transmitted to Diaspora
[friendica.git] / mod / item.php
index 7a5a8aab48bdcc5a679312b6895d97567c76ca36..be9fa09c478985c2496525ede78ca73fa2c03ce7 100644 (file)
@@ -24,16 +24,13 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
-use Friendica\Model\GContact;
 use Friendica\Model\Item;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
-use Friendica\Util\Temporal;
 
 require_once 'include/enotify.php';
-require_once 'include/tags.php';
-require_once 'include/threads.php';
 require_once 'include/text.php';
 require_once 'include/items.php';
 
@@ -96,9 +93,9 @@ function item_post(App $a) {
 
        if ($thr_parent || $thr_parent_uri) {
                if ($thr_parent) {
-                       $parent_item = dba::selectFirst('item', [], ['id' => $thr_parent]);
+                       $parent_item = Item::selectFirst([], ['id' => $thr_parent]);
                } elseif ($thr_parent_uri) {
-                       $parent_item = dba::selectFirst('item', [], ['uri' => $thr_parent_uri, 'uid' => $profile_uid]);
+                       $parent_item = Item::selectFirst([], ['uri' => $thr_parent_uri, 'uid' => $profile_uid]);
                }
 
                // if this isn't the real parent of the conversation, find it
@@ -232,7 +229,7 @@ function item_post(App $a) {
                $verb              = notags(trim($_REQUEST['verb']));
                $emailcc           = notags(trim($_REQUEST['emailcc']));
                $body              = escape_tags(trim($_REQUEST['body']));
-               $network           = notags(trim($_REQUEST['network']));
+               $network           = notags(trim(defaults($_REQUEST, 'network', NETWORK_DFRN)));
                $guid              = get_guid(32);
 
                $postopts = defaults($_REQUEST, 'postopts', '');
@@ -570,7 +567,7 @@ function item_post(App $a) {
                $network = NETWORK_DFRN;
        }
 
-       $gravity = ($parent ? 6 : 0);
+       $gravity = ($parent ? GRAVITY_COMMENT : GRAVITY_PARENT);
 
        // even if the post arrived via API we are considering that it
        // originated on this site by default for determining relayability.
@@ -579,7 +576,7 @@ function item_post(App $a) {
 
        $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::newURI($profile_uid, $guid));
 
        // Fallback so that we alway have a parent uri
        if (!$thr_parent_uri || !$parent) {
@@ -596,16 +593,16 @@ 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']      = Contact::getIdForURL($datarray['owner-link'], 0);
+       $datarray['owner-id']      = Contact::getIdForURL($datarray['owner-link']);
        $datarray['author-name']   = $author['name'];
        $datarray['author-link']   = $author['url'];
        $datarray['author-avatar'] = $author['thumb'];
-       $datarray['author-id']     = Contact::getIdForURL($datarray['author-link'], 0);
-       $datarray['created']       = Temporal::convert();
-       $datarray['edited']        = Temporal::convert();
-       $datarray['commented']     = Temporal::convert();
-       $datarray['received']      = Temporal::convert();
-       $datarray['changed']       = Temporal::convert();
+       $datarray['author-id']     = Contact::getIdForURL($datarray['author-link']);
+       $datarray['created']       = DateTimeFormat::utcNow();
+       $datarray['edited']        = DateTimeFormat::utcNow();
+       $datarray['commented']     = DateTimeFormat::utcNow();
+       $datarray['received']      = DateTimeFormat::utcNow();
+       $datarray['changed']       = DateTimeFormat::utcNow();
        $datarray['extid']         = $extid;
        $datarray['guid']          = $guid;
        $datarray['uri']           = $uri;
@@ -634,8 +631,6 @@ function item_post(App $a) {
        $datarray['postopts']      = $postopts;
        $datarray['origin']        = $origin;
        $datarray['moderated']     = false;
-       $datarray['gcontact-id']   = GContact::getId(["url" => $datarray['author-link'], "network" => $datarray['network'],
-                                                       "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']]);
        $datarray['object']        = $object;
 
        /*
@@ -652,13 +647,13 @@ function item_post(App $a) {
        // 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']);
-       if (DBM::is_result($r)) {
+       $conversation = dba::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $datarray['parent-uri']]);
+       if (DBM::is_result($conversation)) {
                if ($r['conversation-uri'] != '') {
-                       $datarray['conversation-uri'] = $r['conversation-uri'];
+                       $datarray['conversation-uri'] = $conversation['conversation-uri'];
                }
                if ($r['conversation-href'] != '') {
-                       $datarray['conversation-href'] = $r['conversation-href'];
+                       $datarray['conversation-href'] = $conversation['conversation-href'];
                }
        }
 
@@ -666,6 +661,11 @@ function item_post(App $a) {
                $datarray['edit'] = true;
        }
 
+       // Check for hashtags in the body and repair or add hashtag links
+       if ($preview || $orig_post) {
+               Item::setHashtags($datarray);
+       }
+
        // preview mode - prepare the body for display and send it via json
        if ($preview) {
                require_once 'include/conversation.php';
@@ -709,8 +709,8 @@ function item_post(App $a) {
                        'file' => $datarray['file'],
                        'rendered-html' => $datarray['rendered-html'],
                        'rendered-hash' => $datarray['rendered-hash'],
-                       'edited' => Temporal::convert(),
-                       'changed' => Temporal::convert()];
+                       'edited' => DateTimeFormat::utcNow(),
+                       'changed' => DateTimeFormat::utcNow()];
 
                Item::update($fields, ['id' => $post_id]);
 
@@ -737,7 +737,7 @@ function item_post(App $a) {
                goaway($return_path);
        }
 
-       $datarray = dba::selectFirst('item', [], ['id' => $post_id]);
+       $datarray = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
 
        if (!DBM::is_result($datarray)) {
                logger("Item with id ".$post_id." couldn't be fetched.");
@@ -813,7 +813,6 @@ function item_post(App $a) {
                                $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 =  [
                                        'fromName' => $a->user['username'],
                                        'fromEmail' => $a->user['email'],
@@ -821,7 +820,7 @@ function item_post(App $a) {
                                        'replyTo' => $a->user['email'],
                                        'messageSubject' => $subject,
                                        'htmlVersion' => $message,
-                                       'textVersion' => html2plain($html.$disclaimer)
+                                       'textVersion' => Friendica\Content\Text\HTML::toPlaintext($html.$disclaimer)
                                ];
                                Emailer::send($params);
                        }
@@ -878,7 +877,7 @@ function item_content(App $a) {
        $o = '';
        if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
                if (is_ajax()) {
-                       $o = Item::delete($a->argv[2]);
+                       $o = Item::deleteForUser(['id' => $a->argv[2]], local_user());
                } else {
                        $o = drop_item($a->argv[2]);
                }