]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
We got rid of two workerqueue queries, yeah!
[friendica.git] / mod / item.php
index 7f0f48c05c2edc1c13f73dddb9c7f62d95a695f8..7e6d092711e31e705eaf0f59ec931ba7c928156c 100644 (file)
@@ -15,6 +15,8 @@
  * posting categories go through item_store() instead of this function.
  */
 
+use Friendica\App;
+
 require_once 'include/crypto.php';
 require_once 'include/enotify.php';
 require_once 'include/email.php';
@@ -23,7 +25,7 @@ require_once 'include/files.php';
 require_once 'include/threads.php';
 require_once 'include/text.php';
 require_once 'include/items.php';
-require_once 'include/Scrape.php';
+require_once 'include/probe.php';
 require_once 'include/diaspora.php';
 require_once 'include/Contact.php';
 
@@ -137,12 +139,11 @@ function item_post(App $a) {
 
                        // 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));
-                       if (dbm::is_result($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
-                               AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
+                       if (dbm::is_result($thrparent) && ($thrparent[0]["network"] === NETWORK_OSTATUS)
+                               && (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
                                $parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]);
 
                                if (!isset($parent_contact["nick"])) {
-                                       require_once 'include/Scrape.php';
                                        $probed_contact = probe_url($thrparent[0]["author-link"]);
                                        if ($probed_contact["network"] != NETWORK_FEED) {
                                                $parent_contact = $probed_contact;
@@ -174,7 +175,7 @@ function item_post(App $a) {
        $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 != '') AND ($profile_uid != 0)) {
+       if (($message_id != '') && ($profile_uid != 0)) {
                $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                        dbesc($message_id),
                        intval($profile_uid)
@@ -308,8 +309,8 @@ function item_post(App $a) {
 
                        // for non native networks use the network of the original post as network of the item
                        if (($parent_item['network'] != NETWORK_DIASPORA)
-                               AND ($parent_item['network'] != NETWORK_OSTATUS)
-                               AND ($network == "")) {
+                               && ($parent_item['network'] != NETWORK_OSTATUS)
+                               && ($network == "")) {
                                $network = $parent_item['network'];
                        }
 
@@ -325,8 +326,9 @@ function item_post(App $a) {
                // 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') && (! get_config('system','imap_disabled'))) ? 0 : 1);
+                       $mail_disabled = ((function_exists('imap_open') && (! get_config('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())
                                );
@@ -372,7 +374,7 @@ function item_post(App $a) {
                $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
                        intval($_SESSION['uid']));
        } elseif(remote_user()) {
-               if (is_array($_SESSION['remote'])) {
+               if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
                        foreach ($_SESSION['remote'] as $v) {
                                if ($v['uid'] == $profile_uid) {
                                        $contact_id = $v['cid'];
@@ -502,7 +504,7 @@ function item_post(App $a) {
 
        $bookmark = 0;
        $data = get_attachment_data($body);
-       if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) OR isset($data["type"])) {
+       if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"])) {
                $objecttype = ACTIVITY_OBJ_BOOKMARK;
                $bookmark = 1;
        }
@@ -541,10 +543,10 @@ function item_post(App $a) {
         * add a statusnet style reply tag if the original post was from there
         * and we are replying, and there isn't one already
         */
-       if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) {
+       if ($parent && ($parent_contact['network'] == NETWORK_OSTATUS)) {
                $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]';
 
-               if (!in_array($contact,$tags)) {
+               if (!in_array($contact, $tags)) {
                        $body = $contact . ' ' . $body;
                        $tags[] = $contact;
                }
@@ -722,6 +724,18 @@ function item_post(App $a) {
        $datarray['last-child'] = 1;
        $datarray['visible'] = 1;
 
+       $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)) {
+               if ($r['conversation-uri'] != '') {
+                       $datarray['conversation-uri'] = $r['conversation-uri'];
+               }
+               if ($r['conversation-href'] != '') {
+                       $datarray['conversation-href'] = $r['conversation-href'];
+               }
+       }
+
        if ($orig_post) {
                $datarray['edit'] = true;
        }
@@ -761,6 +775,8 @@ function item_post(App $a) {
        // Fill the cache field
        put_item_in_cache($datarray);
 
+       $datarray = store_conversation($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']),
@@ -793,8 +809,7 @@ function item_post(App $a) {
                $post_id = 0;
        }
 
-       q("COMMIT");
-       q("START TRANSACTION;");
+       dba::transaction();
 
        $r = q("INSERT INTO `item` (`guid`, `extid`, `uid`,`type`,`wall`,`gravity`, `network`, `contact-id`,
                                        `owner-name`,`owner-link`,`owner-avatar`, `owner-id`,
@@ -884,7 +899,7 @@ function item_post(App $a) {
        }
 
        if ($post_id == 0) {
-               q("COMMIT");
+               dba::commit();
                logger('mod_item: unable to retrieve post that was just stored.');
                notice(t('System error. Post not saved.') . EOL);
                goaway($return_path);
@@ -1010,7 +1025,7 @@ function item_post(App $a) {
                update_thread($parent, true);
        }
 
-       q("COMMIT");
+       dba::commit();
 
        create_tags_from_item($post_id);
        create_files_from_item($post_id);
@@ -1089,7 +1104,6 @@ function item_content(App $a) {
  * @return boolean true if replaced, false if not replaced
  */
 function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") {
-       require_once 'include/Scrape.php';
        require_once 'include/socgraph.php';
 
        $replaced = false;
@@ -1201,9 +1215,9 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                        }
                } else {
                        $r = false;
-                       if (strrpos($name,'+')) {
+                       if (strrpos($name, '+')) {
                                // Is it in format @nick+number?
-                               $tagcid = intval(substr($name,strrpos($name,'+') + 1));
+                               $tagcid = intval(substr($name, strrpos($name, '+') + 1));
 
                                $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                                intval($tagcid),
@@ -1212,7 +1226,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) AND ($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),
@@ -1221,7 +1235,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                                );
 
                        //select someone from this user's contacts by name in the current network
-                       if (!dbm::is_result($r) AND ($network != "")) {
+                       if (!dbm::is_result($r) && ($network != "")) {
                                $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1",
                                                dbesc($name),
                                                dbesc($network),
@@ -1248,7 +1262,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                }
 
                if (dbm::is_result($r)) {
-                       if (strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) {
+                       if (strlen($inform) && (isset($r[0]["notify"]) || isset($r[0]["id"]))) {
                                $inform .= ',';
                        }
 
@@ -1261,33 +1275,35 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                        $profile = $r[0]["url"];
                        $alias   = $r[0]["alias"];
                        $newname = $r[0]["nick"];
-                       if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER)
-                               AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) {
+                       if (($newname == "") || (($r[0]["network"] != NETWORK_OSTATUS) && ($r[0]["network"] != NETWORK_TWITTER)
+                               && ($r[0]["network"] != NETWORK_STATUSNET) && ($r[0]["network"] != NETWORK_APPNET))) {
                                $newname = $r[0]["name"];
                        }
                }
 
                //if there is an url for this persons profile
-               if (isset($profile) AND ($newname != "")) {
+               if (isset($profile) && ($newname != "")) {
 
                        $replaced = true;
                        // create profile link
-                       $profile = str_replace(',','%2c',$profile);
-                       $newtag = '@[url='.$profile.']'.$newname.'[/url]';
-                       $body = str_replace('@'.$name, $newtag, $body);
+                       $profile = str_replace(',', '%2c', $profile);
+                       $newtag = '@[url=' . $profile . ']' . $newname . '[/url]';
+                       $body = str_replace('@' . $name, $newtag, $body);
                        // append tag to str_tags
-                       if (! stristr($str_tags,$newtag)) {
+                       if (! stristr($str_tags, $newtag)) {
                                if (strlen($str_tags)) {
                                        $str_tags .= ',';
                                }
                                $str_tags .= $newtag;
                        }
 
-                       // Status.Net seems to require the numeric ID URL in a mention if the person isn't
-                       // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
+                       /*
+                        * Status.Net seems to require the numeric ID URL in a mention if the person isn't
+                        * subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
+                        */
                        if (strlen($alias)) {
-                               $newtag = '@[url='.$alias.']'.$newname.'[/url]';
-                               if (! stristr($str_tags,$newtag)) {
+                               $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
+                               if (! stristr($str_tags, $newtag)) {
                                        if (strlen($str_tags)) {
                                                $str_tags .= ',';
                                        }