]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #5813 from MrPetovan/task/update-composer
[friendica.git] / include / items.php
index 0d447f2b40bcd1723701c78c150ac8958e216f54..9fd557a77885838ee1cd7b415eacac99b67a75d0 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Item;
@@ -28,6 +29,10 @@ function add_page_info_data(array $data, $no_photos = false)
 {
        Addon::callHooks('page_info_data', $data);
 
+       if (empty($data['type'])) {
+               return '';
+       }
+
        // It maybe is a rich content, but if it does have everything that a link has,
        // then treat it that way
        if (($data["type"] == "rich") && is_string($data["title"]) &&
@@ -67,7 +72,8 @@ function add_page_info_data(array $data, $no_photos = false)
                $text .= " title='".$data["title"]."'";
        }
 
-       if (!empty($data["images"])) {
+       // Only embedd a picture link when it seems to be a valid picture ("width" is set)
+       if (!empty($data["images"]) && !empty($data["images"][0]["width"])) {
                $preview = str_replace(["[", "]"], ["[", "]"], htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false));
                // if the preview picture is larger than 500 pixels then show it in a larger mode
                // But only, if the picture isn't higher than large (To prevent huge posts)
@@ -150,7 +156,11 @@ function add_page_info($url, $no_photos = false, $photo = "", $keywords = false,
 {
        $data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
 
-       $text = add_page_info_data($data, $no_photos);
+       $text = '';
+
+       if (is_array($data)) {
+               $text = add_page_info_data($data, $no_photos);
+       }
 
        return $text;
 }
@@ -236,7 +246,7 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false)
  */
 function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0, $pass = 0)
 {
-       if ($contact['network'] === NETWORK_OSTATUS) {
+       if ($contact['network'] === Protocol::OSTATUS) {
                if ($pass < 2) {
                        // Test - remove before flight
                        //$tempfile = tempnam(get_temppath(), "ostatus2");
@@ -248,7 +258,7 @@ function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0
                return;
        }
 
-       if ($contact['network'] === NETWORK_FEED) {
+       if ($contact['network'] === Protocol::FEED) {
                if ($pass < 2) {
                        logger("Consume feeds", LOGGER_DEBUG);
                        Feed::import($xml, $importer, $contact, $hub);
@@ -257,25 +267,12 @@ function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0
                return;
        }
 
-       if ($contact['network'] === NETWORK_DFRN) {
+       if ($contact['network'] === Protocol::DFRN) {
                logger("Consume DFRN messages", LOGGER_DEBUG);
-
-               $r = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`,
-                                       `contact`.`pubkey` AS `cpubkey`,
-                                       `contact`.`prvkey` AS `cprvkey`,
-                                       `contact`.`thumb` AS `thumb`,
-                                       `contact`.`url` as `url`,
-                                       `contact`.`name` as `senderName`,
-                                       `user`.*
-                       FROM `contact`
-                       LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
-                       WHERE `contact`.`id` = %d AND `user`.`uid` = %d",
-                       DBA::escape($contact["id"]), DBA::escape($importer["uid"])
-               );
-
-               if (DBA::isResult($r)) {
+               $dfrn_importer = DFRN::getImporter($contact["id"], $importer["uid"]);
+               if (!empty($dfrn_importer)) {
                        logger("Now import the DFRN feed");
-                       DFRN::import($xml, $r[0], true);
+                       DFRN::import($xml, $dfrn_importer, true);
                        return;
                }
        }
@@ -283,25 +280,30 @@ function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0
 
 function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'subscribe')
 {
-       $a = BaseObject::getApp();
-       $r = null;
-
-       if (!empty($importer)) {
-               $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
-                       intval($importer['uid'])
-               );
-       }
-
        /*
         * Diaspora has different message-ids in feeds than they do
         * through the direct Diaspora protocol. If we try and use
         * the feed, we'll get duplicates. So don't.
         */
-       if ((!DBA::isResult($r)) || $contact['network'] === NETWORK_DIASPORA) {
+       if ($contact['network'] === Protocol::DIASPORA) {
+               return;
+       }
+
+       // Without an importer we don't have a user id - so we quit
+       if (empty($importer)) {
+               return;
+       }
+
+       $a = BaseObject::getApp();
+
+       $user = DBA::selectFirst('user', ['nickname'], ['uid' => $importer['uid']]);
+
+       // No user, no nickname, we quit
+       if (!DBA::isResult($user)) {
                return;
        }
 
-       $push_url = System::baseUrl() . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
+       $push_url = System::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
 
        // Use a single verify token, even if multiple hubs
        $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
@@ -374,7 +376,7 @@ function drop_item($id)
 
        if ((local_user() == $item['uid']) || $contact_id) {
                // Check if we should do HTML-based delete confirmation
-               if ($_REQUEST['confirm']) {
+               if (!empty($_REQUEST['confirm'])) {
                        // <form> can't take arguments in its "action" parameter
                        // so add any arguments as hidden inputs
                        $query = explode_querystring($a->query_string);
@@ -398,7 +400,7 @@ function drop_item($id)
                        ]);
                }
                // Now check how the user responded to the confirmation query
-               if ($_REQUEST['canceled']) {
+               if (!empty($_REQUEST['canceled'])) {
                        goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
                }