]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #4079 from MrPetovan/task/4069-add-pagination-to-statuses-api
[friendica.git] / include / items.php
index d446d2773d4c8d4bc0d6bcf24c55d8a33d124d85..275052c1fdb73deab8337c78b2b840f8168994ad 100644 (file)
@@ -4,31 +4,31 @@
  */
 use Friendica\App;
 use Friendica\ParseUrl;
+use Friendica\Content\Feature;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Core\Worker;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
-use Friendica\Model\GlobalContact;
-use Friendica\Object\Contact;
+use Friendica\Model\Contact;
+use Friendica\Model\GContact;
+use Friendica\Model\Group;
+use Friendica\Model\User;
+use Friendica\Object\Image;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\OStatus;
-use Friendica\Util\Lock;
+use Friendica\Protocol\Feed;
 
 require_once 'include/bbcode.php';
 require_once 'include/oembed.php';
-require_once 'include/salmon.php';
 require_once 'include/crypto.php';
 require_once 'include/tags.php';
 require_once 'include/files.php';
 require_once 'include/text.php';
-require_once 'include/email.php';
 require_once 'include/threads.php';
 require_once 'include/plaintext.php';
-require_once 'include/feed.php';
 require_once 'mod/share.php';
 require_once 'include/enotify.php';
-require_once 'include/group.php';
 
 function construct_verb($item) {
        if ($item['verb']) {
@@ -42,7 +42,6 @@ function construct_verb($item) {
  *             The purpose of this function is to apply system message length limits to
  *             imported messages without including any embedded photos in the length
  */
-if (! function_exists('limit_body_size')) {
 function limit_body_size($body) {
 
 //     logger('limit_body_size: start', LOGGER_DEBUG);
@@ -125,7 +124,7 @@ function limit_body_size($body) {
        } else {
                return $body;
        }
-}}
+}
 
 function title_is_body($title, $body) {
 
@@ -743,10 +742,10 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
                 * On comments the author is the better choice.
                 */
                if ($arr['parent-uri'] === $arr['uri']) {
-                       $arr["gcontact-id"] = GlobalContact::getId(array("url" => $arr['owner-link'], "network" => $arr['network'],
+                       $arr["gcontact-id"] = GContact::getId(array("url" => $arr['owner-link'], "network" => $arr['network'],
                                                                 "photo" => $arr['owner-avatar'], "name" => $arr['owner-name']));
                } else {
-                       $arr["gcontact-id"] = GlobalContact::getId(array("url" => $arr['author-link'], "network" => $arr['network'],
+                       $arr["gcontact-id"] = GContact::getId(array("url" => $arr['author-link'], "network" => $arr['network'],
                                                                 "photo" => $arr['author-avatar'], "name" => $arr['author-name']));
                }
        }
@@ -1152,6 +1151,19 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
  * @param array $arr Contains the just posted item record
  */
 function item_set_last_item($arr) {
+       // Unarchive the author
+       $contact = dba::select('contact', [], ['id' => $arr["author-link"]], ['limit' => 1]);
+       if ($contact['term-date'] > NULL_DATE) {
+                Contact::unmarkForArchival($contact);
+       }
+
+       // Unarchive the contact if it is a toplevel posting
+       if ($arr["parent-uri"] === $arr["uri"]) {
+               $contact = dba::select('contact', [], ['id' => $arr["contact-id"]], ['limit' => 1]);
+               if ($contact['term-date'] > NULL_DATE) {
+                        Contact::unmarkForArchival($contact);
+               }
+       }
 
        $update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
 
@@ -1538,7 +1550,7 @@ function consume_feed($xml, $importer, &$contact, &$hub, $datedir = 0, $pass = 0
        if ($contact['network'] === NETWORK_FEED) {
                if ($pass < 2) {
                        logger("Consume feeds", LOGGER_DEBUG);
-                       feed_import($xml, $importer, $contact, $hub);
+                       Feed::import($xml, $importer, $contact, $hub);
                }
                return;
        }
@@ -1680,8 +1692,8 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
                        dbesc($name),
                        dbesc($nick),
                        dbesc($photo),
-                       dbesc(($sharing) ? NETWORK_ZOT : NETWORK_OSTATUS),
-                       intval(($sharing) ? CONTACT_IS_SHARING : CONTACT_IS_FOLLOWER)
+                       dbesc(NETWORK_OSTATUS),
+                       intval(CONTACT_IS_FOLLOWER)
                );
                $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
                                intval($importer['uid']),
@@ -1708,11 +1720,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
                                                        'hash' => $hash, 'datetime' => datetime_convert()));
                        }
 
-                       $def_gid = get_default_group($importer['uid'], $contact_record["network"]);
-
-                       if (intval($def_gid)) {
-                               group_add_member($importer['uid'], '', $contact_record['id'], $def_gid);
-                       }
+                       Group::addMember(User::getDefaultGroup($importer['uid'], $contact_record["network"]), $contact_record['id']);
 
                        if (($r[0]['notify-flags'] & NOTIFY_INTRO) &&
                                in_array($r[0]['page-flags'], array(PAGE_NORMAL))) {
@@ -1875,11 +1883,11 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) {
                                                        $width = intval($match[1]);
                                                        $height = intval($match[2]);
 
-                                                       $ph = new Photo($data, $type);
-                                                       if ($ph->isValid()) {
-                                                               $ph->scaleImage(max($width, $height));
-                                                               $data = $ph->imageString();
-                                                               $type = $ph->getType();
+                                                       $Image = new Image($data, $type);
+                                                       if ($Image->isValid()) {
+                                                               $Image->scaleDown(max($width, $height));
+                                                               $data = $Image->asString();
+                                                               $type = $Image->getType();
                                                        }
                                                }
 
@@ -1946,9 +1954,9 @@ function compare_permissions($obj1, $obj2) {
 /// @TODO type-hint is array
 function enumerate_permissions($obj) {
        $allow_people = expand_acl($obj['allow_cid']);
-       $allow_groups = expand_groups(expand_acl($obj['allow_gid']));
+       $allow_groups = Group::expand(expand_acl($obj['allow_gid']));
        $deny_people  = expand_acl($obj['deny_cid']);
-       $deny_groups  = expand_groups(expand_acl($obj['deny_gid']));
+       $deny_groups  = Group::expand(expand_acl($obj['deny_gid']));
        $recipients   = array_unique(array_merge($allow_people, $allow_groups));
        $deny         = array_unique(array_merge($deny_people, $deny_groups));
        $recipients   = array_diff($recipients, $deny);
@@ -2221,7 +2229,6 @@ function drop_item($id, $interactive = true) {
 
                // Now delete them
                if ($parentid != "") {
-                       $r = q("DELETE FROM `item_id` WHERE `iid` IN (%s)", dbesc($parentid));
                        $r = q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
                }
 
@@ -2357,7 +2364,7 @@ function posted_dates($uid, $wall) {
 function posted_date_widget($url, $uid, $wall) {
        $o = '';
 
-       if (! feature_enabled($uid, 'archives')) {
+       if (! Feature::isEnabled($uid, 'archives')) {
                return $o;
        }