* @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\Term;
+use Friendica\Model\User;
+use Friendica\Object\Image;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus;
-use Friendica\Util\Lock;
+use Friendica\Protocol\Feed;
+use Friendica\Util\ParseUrl;
require_once 'include/bbcode.php';
-require_once 'include/oembed.php';
-require_once 'include/crypto.php';
require_once 'include/tags.php';
-require_once 'include/files.php';
require_once 'include/text.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']) {
/* limit_body_size()
*
- * 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);
+/**
+ * The purpose of this function is to apply system message length limits to
+ * imported messages without including any embedded photos in the length
+ *
+ * @brief Truncates imported message body string length to max_import_size
+ * @param string $body
+ * @return string
+ */
+function limit_body_size($body)
+{
$maxlen = get_max_import_size();
// If the length of the body, including the embedded images, is smaller
$orig_body = $body;
$new_body = '';
$textlen = 0;
- $max_found = false;
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
if ($textlen < $maxlen) {
logger('limit_body_size: the limit happens after the end of the last image', LOGGER_DEBUG);
$new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
- $textlen = $maxlen;
}
} else {
logger('limit_body_size: the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
$new_body = $new_body . $orig_body;
- $textlen += strlen($orig_body);
}
return $new_body;
} else {
return $body;
}
-}}
+}
function title_is_body($title, $body) {
return "";
}
- if (sizeof($data["images"]) > 0) {
- $preview = $data["images"][0];
- } else {
- $preview = "";
- }
-
// Escape some bad characters
$data["url"] = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["url"], ENT_QUOTES, 'UTF-8', false));
$data["title"] = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false));
* @return array Item array with removed conversation data
*/
function store_conversation($arr) {
- if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)) && !empty($arr['uri'])) {
+ if (in_array(defaults($arr, 'network', NETWORK_PHANTOM), 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'])) {
}
/// @TODO add type-hint array
-function item_store($arr, $force_parent = false, $notify = false, $dontcache = false) {
-
+function item_store($arr, $force_parent = false, $notify = false, $dontcache = false)
+{
$a = get_app();
// If it is a posting where users should get notifications, then define it as wall posting
$arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname());
}
}
+ } else {
+ $arr['network'] = trim(defaults($arr, 'network', NETWORK_PHANTOM));
}
if ($notify) {
// check for create date and expire time
$expire_interval = Config::get('system', 'dbclean-expire-days', 0);
- $r = dba::select('user', array('expire'), array('uid' => $uid), array("limit" => 1));
- if (DBM::is_result($r) && ($r['expire'] > 0) && (($r['expire'] < $expire_interval) || ($expire_interval == 0))) {
- $expire_interval = $r['expire'];
+ $user = dba::selectFirst('user', ['expire'], ['uid' => $uid]);
+ if (DBM::is_result($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) {
+ $expire_interval = $user['expire'];
}
if (($expire_interval > 0) && !empty($arr['created'])) {
* We have to check several networks since Friendica posts could be repeated
* via OStatus (maybe Diasporsa as well)
*/
- if (in_array(trim($arr['network']), array(NETWORK_DIASPORA, NETWORK_DFRN, NETWORK_OSTATUS, ""))) {
+ if (in_array($arr['network'], array(NETWORK_DIASPORA, NETWORK_DFRN, NETWORK_OSTATUS, ""))) {
$r = q("SELECT `id`, `network` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` IN ('%s', '%s', '%s') LIMIT 1",
dbesc(trim($arr['uri'])),
intval($uid),
$arr['attach'] = ((x($arr, 'attach')) ? notags(trim($arr['attach'])) : '');
$arr['app'] = ((x($arr, 'app')) ? notags(trim($arr['app'])) : '');
$arr['origin'] = ((x($arr, 'origin')) ? intval($arr['origin']) : 0 );
- $arr['network'] = ((x($arr, 'network')) ? trim($arr['network']) : '');
$arr['postopts'] = ((x($arr, 'postopts')) ? trim($arr['postopts']) : '');
$arr['resource-id'] = ((x($arr, 'resource-id')) ? trim($arr['resource-id']) : '');
$arr['event-id'] = ((x($arr, 'event-id')) ? intval($arr['event-id']) : 0 );
$arr['plink'] = System::baseUrl() . '/display/' . urlencode($arr['guid']);
}
- if ($arr['network'] == "") {
+ if ($arr['network'] == NETWORK_PHANTOM) {
$r = q("SELECT `network` FROM `contact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' AND `uid` = %d LIMIT 1",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
dbesc(normalise_link($arr['author-link'])),
intval($arr['uid'])
);
- if (!DBM::is_result($r))
+ if (!DBM::is_result($r)) {
$r = q("SELECT `network` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' LIMIT 1",
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
dbesc(normalise_link($arr['author-link']))
);
+ }
if (!DBM::is_result($r)) {
$r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
logger("Contact-id was missing for post ".$arr["guid"]." from user id ".$uid." - now set to ".$arr["contact-id"], LOGGER_DEBUG);
}
- if ($arr["gcontact-id"] == 0) {
+ if (!x($arr, "gcontact-id")) {
/*
* The gcontact should mostly behave like the contact. But is is supposed to be global for the system.
* This means that wall posts, repeated posts, etc. should have the gcontact id of the owner.
* 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']));
}
}
logger("item_store: Checking if parent ".$parent_id." has to be tagged as mention for user ".$arr['uid'], LOGGER_DEBUG);
$u = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($arr['uid']));
if (DBM::is_result($u)) {
- $a = get_app();
$self = normalise_link(System::baseUrl() . '/profile/' . $u[0]['nickname']);
logger("item_store: 'myself' is ".$self." for parent ".$parent_id." checking against ".$arr['author-link']." and ".$arr['owner-link'], LOGGER_DEBUG);
if ((normalise_link($arr['author-link']) == $self) || (normalise_link($arr['owner-link']) == $self)) {
}
// Set parent id
- $r = dba::update('item', array('parent' => $parent_id), array('id' => $current_post));
+ dba::update('item', array('parent' => $parent_id), array('id' => $current_post));
$arr['id'] = $current_post;
$arr['parent'] = $parent_id;
* This is not perfect - but a workable solution until we found the reason for the problem.
*/
create_tags_from_item($current_post);
- create_files_from_item($current_post);
+ Term::createFromItem($current_post);
/*
* If this is now the last-child, force all _other_ children of this parent to *not* be last-child
* It is done after the transaction to avoid dead locks.
*/
if ($arr['last-child']) {
- $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
+ q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
dbesc($arr['uri']),
intval($arr['uid']),
intval($current_post)
add_shadow_entry($current_post);
}
- check_item_notification($current_post, $uid);
+ check_user_notification($current_post);
if ($notify) {
Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "Notifier", $notify_type, $current_post);
* @param array $arr Contains the just posted item record
*/
function item_set_last_item($arr) {
+ // Unarchive the author
+ $contact = dba::selectFirst('contact', [], ['id' => $arr["author-link"]]);
+ 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::selectFirst('contact', [], ['id' => $arr["contact-id"]]);
+ if ($contact['term-date'] > NULL_DATE) {
+ Contact::unmarkForArchival($contact);
+ }
+ }
$update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
if ($update) {
dba::update('contact', array('success_update' => $arr['received'], 'last-item' => $arr['received']),
array('id' => $arr['contact-id']));
- $contact = dba::select('contact', [], ['id' => $arr['contact-id']], ['limit' => 1]);
- if ($contact['term-date'] > NULL_DATE) {
- Contact::unmarkForArchival($contact);
- }
}
// Now do the same for the system wide contacts with uid=0
if (!$arr['private']) {
// Otherwise there could be problems with hashtags like #test and #test2
rsort($tags);
- $a = get_app();
-
$URLSearchString = "^\[\]";
// All hashtags should point to the home server if "local_tags" is activated
foreach ($contacts as $contact) {
if ($contact['id'] == $item['contact-id']) {
return $contact;
- break; // NOTREACHED
}
}
return false;
* @param int $item_id
* @return bool true if item was deleted, else false
*/
-function tag_deliver($uid, $item_id) {
-
- $a = get_app();
-
+function tag_deliver($uid, $item_id)
+{
$mention = false;
$u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
-
if (! DBM::is_result($u)) {
return;
}
$community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
$prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false);
-
$i = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($item_id),
intval($uid)
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;
}
if (is_array($contact)) {
if (($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
|| ($sharing && $contact['rel'] == CONTACT_IS_FOLLOWER)) {
- $r = dba::update('contact', array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
+ dba::update('contact', array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
array('id' => $contact['id'], 'uid' => $importer['uid']));
}
// send email notification to owner?
} else {
-
// create contact record
-
- $r = q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
+ q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
`blocked`, `readonly`, `pending`, `writable`)
VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, 1)",
intval($importer['uid']),
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']),
dbesc($url)
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($importer['uid'])
);
-
if (DBM::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) {
-
// create notification
$hash = random_string();
'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))) {
}
} elseif (DBM::is_result($r) && in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) {
- $r = q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
+ q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
intval($importer['uid']),
dbesc($url)
);
logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
- $r = dba::update('contact', array('hub-verify' => $verify_token), array('id' => $contact['id']));
+ dba::update('contact', array('hub-verify' => $verify_token), array('id' => $contact['id']));
}
post_url($url, $params);
}
-function fix_private_photos($s, $uid, $item = null, $cid = 0) {
-
- if (Config::get('system','disable_embedded')) {
+/**
+ *
+ * @param string $s
+ * @param int $uid
+ * @param array $item
+ * @param int $cid
+ * @return string
+ */
+function fix_private_photos($s, $uid, $item = null, $cid = 0)
+{
+ if (Config::get('system', 'disable_embedded')) {
return $s;
}
- $a = get_app();
-
logger('fix_private_photos: check for photos', LOGGER_DEBUG);
- $site = substr(System::baseUrl(),strpos(System::baseUrl(),'://'));
+ $site = substr(System::baseUrl(), strpos(System::baseUrl(), '://'));
$orig_body = $s;
$new_body = '';
$img_start = strpos($orig_body, '[img');
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
$img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false);
- while ( ($img_st_close !== false) && ($img_len !== false) ) {
+ while (($img_st_close !== false) && ($img_len !== false)) {
$img_st_close++; // make it point to AFTER the closing bracket
$image = substr($orig_body, $img_start + $img_st_close, $img_len);
logger('fix_private_photos: found photo ' . $image, LOGGER_DEBUG);
-
- if (stristr($image , $site . '/photo/')) {
+ if (stristr($image, $site . '/photo/')) {
// Only embed locally hosted photos
$replace = false;
$i = basename($image);
- $i = str_replace(array('.jpg', '.png', '.gif'),array('', '',''), $i);
+ $i = str_replace(array('.jpg', '.png', '.gif'), array('', '', ''), $i);
$x = strpos($i, '-');
if ($x) {
dbesc($i),
intval($res),
intval($uid)
-
);
if (DBM::is_result($r)) {
/*
$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();
}
}
/// @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);
logger('delete item: ' . $item['id'], LOGGER_DEBUG);
// delete the item
- $r = dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
+ dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
'edited' => datetime_convert(), 'changed' => datetime_convert()),
array('id' => $item['id']));
create_tags_from_item($item['id']);
- create_files_from_item($item['id']);
+ Term::createFromItem($item['id']);
delete_thread($item['id'], $item['parent-uri']);
// clean up categories and tags so they don't end up as orphans
// 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));
+ q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
}
// If it's the parent of a comment thread, kill all the kids
if ($item['uri'] == $item['parent-uri']) {
- $r = dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
+ dba::update('item', array('deleted' => true, 'title' => '', 'body' => '',
'edited' => datetime_convert(), 'changed' => datetime_convert()),
array('parent-uri' => $item['parent-uri'], 'uid' => $item['uid']));
create_tags_from_itemuri($item['parent-uri'], $item['uid']);
- create_files_from_itemuri($item['parent-uri'], $item['uid']);
+ Term::createFromItemURI($item['parent-uri'], $item['uid']);
delete_thread_uri($item['parent-uri'], $item['uid']);
// ignore the result
} else {
function posted_date_widget($url, $uid, $wall) {
$o = '';
- if (! feature_enabled($uid, 'archives')) {
+ if (! Feature::isEnabled($uid, 'archives')) {
return $o;
}