<?php
-
/**
* @file include/items.php
*/
-
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/Photo.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']) {
* 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);
} else {
return $body;
}
-}}
+}
function title_is_body($title, $body) {
$preview = str_replace(array("[", "]"), array("[", "]"), 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)
- if (($data["images"][0]["width"] >= 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."'";
* @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'])) {
* 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']));
}
}
* @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"])));
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;
}
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']),
);
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
'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))) {
$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();
}
}
/// @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);
}
- 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']) {
* 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
// 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));
}
function posted_date_widget($url, $uid, $wall) {
$o = '';
- if (! feature_enabled($uid, 'archives')) {
+ if (! Feature::isEnabled($uid, 'archives')) {
return $o;
}