X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=275052c1fdb73deab8337c78b2b840f8168994ad;hb=ecde6e456da2b30ca4cf0413e8162719ac512439;hp=ed2204f608db4a79197f6a0c783ebf966f742e58;hpb=8cd21269ff7b0ca48537b59496a85b06049453aa;p=friendica.git diff --git a/include/items.php b/include/items.php index ed2204f608..275052c1fd 100644 --- a/include/items.php +++ b/include/items.php @@ -1,37 +1,34 @@ = 500) && ($data["images"][0]["width"] >= $data["images"][0]["height"])) { + if (!Config::get('system', 'always_show_preview') && ($data["images"][0]["width"] >= 500) + && ($data["images"][0]["width"] >= $data["images"][0]["height"])) { $text .= " image='".$preview."'"; } else { $text .= " preview='".$preview."'"; @@ -426,7 +423,7 @@ function uri_to_guid($uri, $host = "") { * @return array Item array with removed conversation data */ function store_conversation($arr) { - if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { + if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)) && !empty($arr['uri'])) { $conversation = array('item-uri' => $arr['uri'], 'received' => DBM::date()); if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) { @@ -718,12 +715,12 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f * This is done only for comments (See below explanation at "gcontact-id") */ if ($arr['parent-uri'] != $arr['uri']) { - $arr["contact-id"] = get_contact($arr['author-link'], $uid); + $arr["contact-id"] = Contact::getIdForURL($arr['author-link'], $uid); } // If not present then maybe the owner was found if ($arr["contact-id"] == 0) { - $arr["contact-id"] = get_contact($arr['owner-link'], $uid); + $arr["contact-id"] = Contact::getIdForURL($arr['owner-link'], $uid); } // Still missing? Then use the "self" contact of the current user @@ -745,28 +742,28 @@ 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'])); } } if ($arr["author-id"] == 0) { - $arr["author-id"] = get_contact($arr["author-link"], 0); + $arr["author-id"] = Contact::getIdForURL($arr["author-link"], 0); } - if (blockedContact($arr["author-id"])) { + if (Contact::isBlocked($arr["author-id"])) { logger('Contact '.$arr["author-id"].' is blocked, item '.$arr["uri"].' will not be stored'); return 0; } if ($arr["owner-id"] == 0) { - $arr["owner-id"] = get_contact($arr["owner-link"], 0); + $arr["owner-id"] = Contact::getIdForURL($arr["owner-link"], 0); } - if (blockedContact($arr["owner-id"])) { + if (Contact::isBlocked($arr["owner-id"])) { logger('Contact '.$arr["owner-id"].' is blocked, item '.$arr["uri"].' will not be stored'); return 0; } @@ -1154,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"]))); @@ -1540,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; } @@ -1682,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']), @@ -1691,7 +1701,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { ); if (DBM::is_result($r)) { $contact_record = $r[0]; - update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true); + Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true); } /// @TODO Encapsulate this into a function/method @@ -1710,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))) { @@ -1750,7 +1756,7 @@ function lose_follower($importer, $contact, array $datarray = array(), $item = " if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) { dba::update('contact', array('rel' => CONTACT_IS_SHARING), array('id' => $contact['id'])); } else { - contact_remove($contact['id']); + Contact::remove($contact['id']); } } @@ -1759,7 +1765,7 @@ function lose_sharer($importer, $contact, array $datarray = array(), $item = "") if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) { dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id'])); } else { - contact_remove($contact['id']); + Contact::remove($contact['id']); } } @@ -1877,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->is_valid()) { - $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(); } } @@ -1948,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); @@ -2122,7 +2128,7 @@ function drop_item($id, $interactive = true) { } - if ((local_user() == $item['uid']) || ($contact_id) || (! $interactive)) { + if ((local_user() == $item['uid']) || $contact_id || !$interactive) { // Check if we should do HTML-based delete confirmation if ($_REQUEST['confirm']) { @@ -2189,30 +2195,18 @@ function drop_item($id, $interactive = true) { * generate a resource-id and therefore aren't intimately linked to the item. */ if (strlen($item['resource-id'])) { - q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ", - dbesc($item['resource-id']), - intval($item['uid']) - ); - // ignore the result + dba::delete('photo', array('resource-id' => $item['resource-id'], 'uid' => $item['uid'])); } // If item is a link to an event, nuke the event record. if (intval($item['event-id'])) { - q("DELETE FROM `event` WHERE `id` = %d AND `uid` = %d", - intval($item['event-id']), - intval($item['uid']) - ); - // ignore the result + dba::delete('event', array('id' => $item['event-id'], 'uid' => $item['uid'])); } // If item has attachments, drop them foreach (explode(", ", $item['attach']) as $attach) { preg_match("|attach/(\d+)|", $attach, $matches); - q("DELETE FROM `attach` WHERE `id` = %d AND `uid` = %d", - intval($matches[1]), - local_user() - ); - // ignore the result + dba::delete('attach', array('id' => $matches[1], 'uid' => $item['uid'])); } // The new code splits the queries since the mysql optimizer really has bad problems with subqueries @@ -2235,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)); } @@ -2371,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; }