]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #5418 from MrPetovan/task/5410-move-dba-to-src
[friendica.git] / include / items.php
index 83b3484d0d4e9b65fbaef6b3a4a26a3b6b63f288..14a74c8e51ea5afa0ff7e91cda3cd9aead2419b3 100644 (file)
@@ -9,40 +9,33 @@ use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
-use Friendica\Core\Worker;
+use Friendica\Database\dba;
 use Friendica\Database\DBM;
-use Friendica\Model\Contact;
-use Friendica\Model\Conversation;
-use Friendica\Model\GContact;
-use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\Term;
-use Friendica\Model\User;
-use Friendica\Object\Image;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\Feed;
-use Friendica\Util\Network;
 use Friendica\Protocol\OStatus;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
 use Friendica\Util\Temporal;
 
-require_once 'include/bbcode.php';
-require_once 'include/tags.php';
 require_once 'include/text.php';
-require_once 'include/threads.php';
 require_once 'mod/share.php';
 require_once 'include/enotify.php';
 
-function add_page_info_data($data) {
+function add_page_info_data($data, $no_photos = false) {
        Addon::callHooks('page_info_data', $data);
 
        // 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";
        }
 
+       $data["title"] = defaults($data, "title", "");
+
        if ((($data["type"] != "link") && ($data["type"] != "video") && ($data["type"] != "photo")) || ($data["title"] == $data["url"])) {
                return "";
        }
@@ -57,23 +50,23 @@ function add_page_info_data($data) {
 
        $text = "[attachment type='".$data["type"]."'";
 
-       if ($data["text"] == "") {
+       if (empty($data["text"])) {
                $data["text"] = $data["title"];
        }
 
-       if ($data["text"] == "") {
+       if (empty($data["text"])) {
                $data["text"] = $data["url"];
        }
 
-       if ($data["url"] != "") {
+       if (!empty($data["url"])) {
                $text .= " url='".$data["url"]."'";
        }
 
-       if ($data["title"] != "") {
+       if (!empty($data["title"])) {
                $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)
@@ -101,7 +94,7 @@ function add_page_info_data($data) {
        return "\n".$text.$hashtags;
 }
 
-function query_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
+function query_page_info($url, $photo = "", $keywords = false, $keyword_blacklist = "") {
 
        $data = ParseUrl::getSiteinfoCached($url, true);
 
@@ -129,8 +122,8 @@ function query_page_info($url, $no_photos = false, $photo = "", $keywords = fals
        return $data;
 }
 
-function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
-       $data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist);
+function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blacklist = "") {
+       $data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
 
        $tags = "";
        if (isset($data["keywords"]) && count($data["keywords"])) {
@@ -150,9 +143,9 @@ function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = fa
 }
 
 function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
-       $data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist);
+       $data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
 
-       $text = add_page_info_data($data);
+       $text = add_page_info_data($data, $no_photos);
 
        return $text;
 }
@@ -238,7 +231,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
@@ -284,6 +277,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",
@@ -300,7 +294,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());
@@ -331,7 +325,7 @@ function drop_items($items) {
 
        if (count($items)) {
                foreach ($items as $item) {
-                       $owner = Item::delete($item);
+                       $owner = Item::deleteForUser(['id' => $item], local_user());
                        if ($owner && !$uid)
                                $uid = $owner;
                }
@@ -344,17 +338,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;
        }
@@ -373,7 +364,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
@@ -403,7 +393,7 @@ function drop_item($id) {
                }
 
                // delete the item
-               Item::delete($item['id']);
+               Item::deleteForUser(['id' => $item['id']], local_user());
 
                goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
                //NOTREACHED
@@ -416,7 +406,7 @@ function drop_item($id) {
 
 /* arrange the list in years */
 function list_post_dates($uid, $wall) {
-       $dnow = Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y-m-d');
+       $dnow = DateTimeFormat::localNow('Y-m-d');
 
        $dthen = Item::firstPostDate($uid, $wall);
        if (!$dthen) {
@@ -436,15 +426,17 @@ function list_post_dates($uid, $wall) {
        while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
                $dyear = intval(substr($dnow, 0, 4));
                $dstart = substr($dnow, 0, 8) . '01';
-               $dend = substr($dnow, 0, 8) . get_dim(intval($dnow), intval(substr($dnow, 5)));
-               $start_month = Temporal::utc($dstart, 'Y-m-d');
-               $end_month = Temporal::utc($dend, 'Y-m-d');
-               $str = day_translate(Temporal::utc($dnow, 'F'));
-               if (!$ret[$dyear]) {
+               $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5)));
+               $start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
+               $end_month = DateTimeFormat::utc($dend, 'Y-m-d');
+               $str = day_translate(DateTimeFormat::utc($dnow, 'F'));
+
+               if (empty($ret[$dyear])) {
                        $ret[$dyear] = [];
                }
+
                $ret[$dyear][] = [$str, $end_month, $start_month];
-               $dnow = Temporal::utc($dnow . ' -1 month', 'Y-m-d');
+               $dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d');
        }
        return $ret;
 }
@@ -474,7 +466,7 @@ function posted_date_widget($url, $uid, $wall) {
                return $o;
        }
 
-       $cutoff_year = intval(Temporal::convert('now', date_default_timezone_get(), 'UTC', 'Y')) - $visible_years;
+       $cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
        $cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
 
        $o = replace_macros(get_markup_template('posted_date_widget.tpl'),[