]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Merge remote-tracking branch 'upstream/develop' into 1612-unused-indexes
[friendica.git] / mod / item.php
index 864aa18e5161cf2d086c56f23b5d0cd32ed0f1df..1c7a970c2da2eda04026e624bbdc35494ab826ad 100644 (file)
@@ -59,13 +59,14 @@ function item_post(App &$a) {
        // Check for doubly-submitted posts, and reject duplicates
        // Note that we have to ignore previews, otherwise nothing will post
        // after it's been previewed
-       if(!$preview && x($_REQUEST['post_id_random'])) {
-               if(x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
+       if (!$preview && x($_REQUEST['post_id_random'])) {
+               if (x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
                        logger("item post: duplicate post", LOGGER_DEBUG);
                        item_post_return(App::get_baseurl(), $api_source, $return_path);
                }
-               else
+               else {
                        $_SESSION['post-random'] = $_REQUEST['post_id_random'];
+               }
        }
 
        /**
@@ -82,18 +83,19 @@ function item_post(App &$a) {
        $r = false;
        $objecttype = null;
 
-       if($parent || $parent_uri) {
+       if ($parent || $parent_uri) {
 
                $objecttype = ACTIVITY_OBJ_COMMENT;
 
-               if(! x($_REQUEST,'type'))
+               if (! x($_REQUEST,'type')) {
                        $_REQUEST['type'] = 'net-comment';
+               }
 
-               if($parent) {
+               if ($parent) {
                        $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
                                intval($parent)
                        );
-               } elseif($parent_uri && local_user()) {
+               } elseif ($parent_uri && local_user()) {
                        // This is coming from an API source, and we are logged in
                        $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                                dbesc($parent_uri),
@@ -105,7 +107,7 @@ function item_post(App &$a) {
                if (dbm::is_result($r)) {
                        $parid = $r[0]['parent'];
                        $parent_uri = $r[0]['uri'];
-                       if($r[0]['id'] != $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)
                                );
@@ -114,8 +116,9 @@ function item_post(App &$a) {
 
                if (! dbm::is_result($r)) {
                        notice( t('Unable to locate original post.') . EOL);
-                       if(x($_REQUEST,'return'))
+                       if (x($_REQUEST,'return')) {
                                goaway($return_path);
+                       }
                        killme();
                }
                $parent_item = $r[0];
@@ -125,7 +128,7 @@ function item_post(App &$a) {
                //if(($parid) && ($parid != $parent))
                $thr_parent = $parent_uri;
 
-               if($parent_item['contact-id'] && $uid) {
+               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)
@@ -135,18 +138,9 @@ 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 (count($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
+                       if (dbm::is_result($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
                                AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
-                               $parent_contact = null;
-
-                               $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
-                                       dbesc(normalise_link($thrparent[0]["author-link"])));
-                               if (dbm::is_result($r)) {
-                                       $parent_contact = $r[0];
-                                       $parent_contact["thumb"] = $parent_contact["photo"];
-                                       $parent_contact["micro"] = $parent_contact["photo"];
-                                       unset($parent_contact["id"]);
-                               }
+                               $parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]);
 
                                if (!isset($parent_contact["nick"])) {
                                        require_once("include/Scrape.php");
@@ -449,13 +443,15 @@ function item_post(App &$a) {
 
                        $objecttype = ACTIVITY_OBJ_IMAGE;
 
-                       foreach($images as $image) {
-                               if(! stristr($image,App::get_baseurl() . '/photo/'))
+                       foreach ($images as $image) {
+                               if (! stristr($image,App::get_baseurl() . '/photo/')) {
                                        continue;
+                               }
                                $image_uri = substr($image,strrpos($image,'/') + 1);
                                $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
-                               if(! strlen($image_uri))
+                               if (! strlen($image_uri)) {
                                        continue;
+                               }
                                $srch = '<' . intval($contact_id) . '>';
 
                                $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
@@ -563,12 +559,8 @@ 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_contact['id'] != "")
-                       $contact = '@'.$parent_contact['nick'].'+'.$parent_contact['id'];
-               else
-                       $contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]';
+       if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) {
+               $contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]';
 
                if (!in_array($contact,$tags)) {
                        $body = $contact.' '.$body;
@@ -614,16 +606,17 @@ function item_post(App &$a) {
                                continue;
 
                        $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network);
-                       if($success['replaced'])
+                       if ($success['replaced']) {
                                $tagged[] = $tag;
-                       if(is_array($success['contact']) && intval($success['contact']['prv'])) {
+                       }
+                       if (is_array($success['contact']) && intval($success['contact']['prv'])) {
                                $private_forum = true;
                                $private_id = $success['contact']['id'];
                        }
                }
        }
 
-       if(($private_forum) && (! $parent) && (! $private)) {
+       if (($private_forum) && (! $parent) && (! $private)) {
                // we tagged a private forum in a top level post and the message was public.
                // Restrict it.
                $private = 1;
@@ -633,15 +626,16 @@ function item_post(App &$a) {
        $attachments = '';
        $match = false;
 
-       if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
-               foreach($match[2] as $mtch) {
+       if (preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
+               foreach ($match[2] as $mtch) {
                        $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
                                intval($profile_uid),
                                intval($mtch)
                        );
                        if (dbm::is_result($r)) {
-                               if(strlen($attachments))
+                               if (strlen($attachments)) {
                                        $attachments .= ',';
+                               }
                                $attachments .= '[attach]href="' . App::get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]';
                        }
                        $body = str_replace($match[1],'',$body);
@@ -650,14 +644,17 @@ function item_post(App &$a) {
 
        $wall = 0;
 
-       if($post_type === 'wall' || $post_type === 'wall-comment')
+       if ($post_type === 'wall' || $post_type === 'wall-comment') {
                $wall = 1;
+       }
 
-       if(! strlen($verb))
+       if (! strlen($verb)) {
                $verb = ACTIVITY_POST ;
+       }
 
-       if ($network == "")
+       if ($network == "") {
                $network = NETWORK_DFRN;
+       }
 
        $gravity = (($parent) ? 6 : 0 );
 
@@ -671,8 +668,9 @@ function item_post(App &$a) {
        $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)
+       if (!$thr_parent) {
                $thr_parent = $uri;
+       }
 
        $datarray = array();
        $datarray['uid']           = $profile_uid;
@@ -955,7 +953,7 @@ function item_post(App &$a) {
 
 
                // Store the comment signature information in case we need to relay to Diaspora
-               diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
+               Diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
 
        } else {
                $parent = $post_id;