]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Standards and a new function to fetch content
[friendica.git] / include / items.php
index 456853d80d516f614300830cc398bf9517a1ced5..ee514c8fc414c37e2f86c1fd21ac3ceab0080297 100644 (file)
@@ -19,7 +19,6 @@ use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
 use Friendica\Util\Temporal;
 
-require_once 'include/bbcode.php';
 require_once 'include/text.php';
 require_once 'mod/share.php';
 require_once 'include/enotify.php';
@@ -30,7 +29,7 @@ function add_page_info_data($data, $no_photos = false) {
        // 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"]) &&
-               is_string($data["text"]) && (sizeof($data["images"]) > 0)) {
+               is_string($data["text"]) && !empty($data["images"])) {
                $data["type"] = "link";
        }
 
@@ -64,7 +63,7 @@ function add_page_info_data($data, $no_photos = false) {
                $text .= " title='".$data["title"]."'";
        }
 
-       if (sizeof($data["images"]) > 0) {
+       if (!empty($data["images"])) {
                $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)
@@ -229,7 +228,7 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
  *
  * @TODO find proper type-hints
  */
-function consume_feed($xml, $importer, &$contact, &$hub, $datedir = 0, $pass = 0) {
+function consume_feed($xml, $importer, $contact, &$hub, $datedir = 0, $pass = 0) {
        if ($contact['network'] === NETWORK_OSTATUS) {
                if ($pass < 2) {
                        // Test - remove before flight
@@ -275,6 +274,7 @@ function consume_feed($xml, $importer, &$contact, &$hub, $datedir = 0, $pass = 0
 function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
 
        $a = get_app();
+       $r = null;
 
        if (is_array($importer)) {
                $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
@@ -291,7 +291,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
                return;
        }
 
-       $push_url = Config::get('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
+       $push_url = System::baseUrl() . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
 
        // Use a single verify token, even if multiple hubs
        $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
@@ -322,7 +322,7 @@ function drop_items($items) {
 
        if (count($items)) {
                foreach ($items as $item) {
-                       $owner = Item::deleteById($item);
+                       $owner = Item::deleteForUser(['id' => $item], local_user());
                        if ($owner && !$uid)
                                $uid = $owner;
                }
@@ -335,17 +335,14 @@ function drop_item($id) {
 
        // locate item to be deleted
 
-       $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
-               intval($id)
-       );
+       $fields = ['id', 'uid', 'contact-id', 'deleted'];
+       $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]);
 
-       if (!DBM::is_result($r)) {
+       if (!DBM::is_result($item)) {
                notice(L10n::t('Item not found.') . EOL);
                goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
        }
 
-       $item = $r[0];
-
        if ($item['deleted']) {
                return 0;
        }
@@ -364,7 +361,6 @@ function drop_item($id) {
        }
 
        if ((local_user() == $item['uid']) || $contact_id) {
-
                // Check if we should do HTML-based delete confirmation
                if ($_REQUEST['confirm']) {
                        // <form> can't take arguments in its "action" parameter
@@ -394,7 +390,7 @@ function drop_item($id) {
                }
 
                // delete the item
-               Item::deleteById($item['id']);
+               Item::deleteForUser(['id' => $item['id']], local_user());
 
                goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
                //NOTREACHED