*/
use Friendica\App;
-use Friendica\Core\System;
use Friendica\ParseUrl;
-use Friendica\Util\Lock;
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\Protocol\DFRN;
+use Friendica\Protocol\OStatus;
+use Friendica\Util\Lock;
require_once 'include/bbcode.php';
require_once 'include/oembed.php';
require_once 'include/text.php';
require_once 'include/email.php';
require_once 'include/threads.php';
-require_once 'include/socgraph.php';
require_once 'include/plaintext.php';
-require_once 'include/ostatus.php';
require_once 'include/feed.php';
require_once 'include/Contact.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
-require_once 'include/dfrn.php';
require_once 'include/group.php';
-/// @TODO one day with composer autoloader no more needed
-require_once 'library/defuse/php-encryption-1.2.1/Crypto.php';
-
function construct_verb($item) {
if ($item['verb']) {
return $item['verb'];
$postopts = "";
}
- require_once('library/langdet/Text/LanguageDetect.php');
-
$naked_body = preg_replace('/\[(.+?)\]/','', $arr['body']);
$l = new Text_LanguageDetect();
- //$lng = $l->detectConfidence($naked_body);
- //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
$lng = $l->detect($naked_body, 3);
if (sizeof($lng) > 0) {
// We have to avoid that different routines could accidentally create the same value
$parsed = parse_url($uri);
+ // When the hostname isn't given, we take it from the uri
if ($host == "") {
- $host = $parsed["host"];
+ // Is it in the format data@host.tld?
+ if ((count($parsed) == 1) && strstr($uri, '@')) {
+ $mailparts = explode('@', $uri);
+ $host = array_pop($mailparts);
+ } else {
+ $host = $parsed["host"];
+ }
}
+ // We use a hash of the hostname as prefix for the guid
$guid_prefix = hash("crc32", $host);
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
unset($parsed["scheme"]);
+ // Glue it together to be able to make a hash from it
$host_id = implode("/", $parsed);
// We could use any hash algorithm since it isn't a security issue
*/
function store_conversation($arr) {
if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
- $conversation = array('item-uri' => $arr['uri'], 'received' => dbm::date());
+ $conversation = array('item-uri' => $arr['uri'], 'received' => DBM::date());
if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
$conversation['reply-to-uri'] = $arr['parent-uri'];
$old_conv = dba::fetch_first("SELECT `item-uri`, `reply-to-uri`, `conversation-uri`, `conversation-href`, `protocol`, `source`
FROM `conversation` WHERE `item-uri` = ?", $conversation['item-uri']);
- if (dbm::is_result($old_conv)) {
+ if (DBM::is_result($old_conv)) {
// Don't update when only the source has changed.
// Only do this when there had been no source before.
if ($old_conv['source'] != '') {
}
// Converting the plink
+ /// @todo Check if this is really still needed
if ($arr['network'] == NETWORK_OSTATUS) {
if (isset($arr['plink'])) {
- $arr['plink'] = ostatus::convert_href($arr['plink']);
+ $arr['plink'] = OStatus::convertHref($arr['plink']);
} elseif (isset($arr['uri'])) {
- $arr['plink'] = ostatus::convert_href($arr['uri']);
+ $arr['plink'] = OStatus::convertHref($arr['uri']);
}
}
$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)) {
+ if (DBM::is_result($r) && ($r['expire'] > 0) && (($r['expire'] < $expire_interval) || ($expire_interval == 0))) {
$expire_interval = $r['expire'];
}
dbesc(NETWORK_DFRN),
dbesc(NETWORK_OSTATUS)
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives
if ($uid != 0) {
logger("Item with uri ".$arr['uri']." already existed for user ".$uid." with id ".$r[0]["id"]." target network ".$r[0]["network"]." - new network: ".$arr['network']);
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)) {
+ if (!DBM::is_result($r)) {
$r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($arr['contact-id']),
intval($arr['uid'])
);
}
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$arr['network'] = $r[0]["network"];
}
if ($arr["contact-id"] == 0) {
$r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid` = %d", intval($uid));
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$arr["contact-id"] = $r[0]["id"];
}
}
* On comments the author is the better choice.
*/
if ($arr['parent-uri'] === $arr['uri']) {
- $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['owner-link'], "network" => $arr['network'],
+ $arr["gcontact-id"] = GlobalContact::getId(array("url" => $arr['owner-link'], "network" => $arr['network'],
"photo" => $arr['owner-avatar'], "name" => $arr['owner-name']));
} else {
- $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['author-link'], "network" => $arr['network'],
+ $arr["gcontact-id"] = GlobalContact::getId(array("url" => $arr['author-link'], "network" => $arr['network'],
"photo" => $arr['author-avatar'], "name" => $arr['author-name']));
}
}
$arr["author-id"] = get_contact($arr["author-link"], 0);
}
+ if (blockedContact($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);
}
+ if (blockedContact($arr["owner-id"])) {
+ logger('Contact '.$arr["owner-id"].' is blocked, item '.$arr["uri"].' will not be stored');
+ return 0;
+ }
+
if ($arr['guid'] != "") {
// Checking if there is already an item with the same guid
logger('checking for an item for user '.$arr['uid'].' on network '.$arr['network'].' with the guid '.$arr['guid'], LOGGER_DEBUG);
$r = q("SELECT `guid` FROM `item` WHERE `guid` = '%s' AND `network` = '%s' AND `uid` = '%d' LIMIT 1",
dbesc($arr['guid']), dbesc($arr['network']), intval($arr['uid']));
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
logger('found item with guid '.$arr['guid'].' for user '.$arr['uid'].' on network '.$arr['network'], LOGGER_DEBUG);
return 0;
}
intval($arr['uid'])
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
// is the new message multi-level threaded?
// even though we don't support it now, preserve the info
intval($arr['uid'])
);
- if (dbm::is_result($z)) {
+ if (DBM::is_result($z)) {
$r = $z;
}
}
* The original author commented, but as this is a comment, the permissions
* weren't fixed up so it will still show the comment as private unless we fix it here.
*/
- if ((intval($r[0]['forum_mode']) == 1) && (! $r[0]['private'])) {
+ if ((intval($r[0]['forum_mode']) == 1) && $r[0]['private']) {
$arr['private'] = 0;
}
// If its a post from myself then tag the thread as "mention"
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)) {
+ 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);
dbesc(NETWORK_DFRN),
intval($arr['uid'])
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
logger('duplicated item with the same uri found. '.print_r($arr,true));
return 0;
}
dbesc($arr['guid']),
intval($arr['uid'])
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
logger('duplicated item with the same guid found. '.print_r($arr,true));
return 0;
}
intval($arr['contact-id']),
intval($arr['uid'])
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
logger('duplicated item with the same body found. '.print_r($arr,true));
return 0;
}
} else {
$isglobal = q("SELECT `global` FROM `item` WHERE `uid` = 0 AND `uri` = '%s'", dbesc($arr["uri"]));
- $arr["global"] = (dbm::is_result($isglobal) && count($isglobal) > 0);
+ $arr["global"] = (DBM::is_result($isglobal) && count($isglobal) > 0);
}
// ACL settings
call_hooks('post_remote', $arr);
}
+ // This array field is used to trigger some automatic reactions
+ // It is mainly used in the "post_local" hook.
+ unset($arr['api_source']);
+
if (x($arr, 'cancel')) {
logger('item_store: post cancelled by plugin.');
return 0;
* An unique index would help - but the limitations of MySQL (maximum size of index values) prevent this.
*/
if ($arr["uid"] == 0) {
- $r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1", dbesc(trim($arr['uri'])));
- if (dbm::is_result($r)) {
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1", dbesc(trim($arr['uri'])));
+ if (DBM::is_result($r)) {
logger('Global item already stored. URI: '.$arr['uri'].' on network '.$arr['network'], LOGGER_DEBUG);
return 0;
}
$r = dba::insert('item', $arr);
// When the item was successfully stored we fetch the ID of the item.
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$current_post = dba::lastInsertId();
} else {
// This can happen - for example - if there are locking timeouts.
dbesc($arr['network'])
);
- if (!dbm::is_result($r)) {
+ if (!DBM::is_result($r)) {
// This shouldn't happen, since COUNT always works when the database connection is there.
logger("We couldn't count the stored entries. Very strange ...");
dba::rollback();
// update the commented timestamp on the parent
// Only update "commented" if it is really a comment
- if (($arr['verb'] == ACTIVITY_POST) || !get_config("system", "like_no_comment")) {
+ if (($arr['verb'] == ACTIVITY_POST) || !Config::get("system", "like_no_comment")) {
dba::update('item', array('commented' => datetime_convert(), 'changed' => datetime_convert()), array('id' => $parent_id));
} else {
dba::update('item', array('changed' => datetime_convert()), array('id' => $parent_id));
if (!$deleted && !$dontcache) {
$r = q('SELECT * FROM `item` WHERE `id` = %d', intval($current_post));
- if ((dbm::is_result($r)) && (count($r) == 1)) {
+ if ((DBM::is_result($r)) && (count($r) == 1)) {
if ($notify) {
call_hooks('post_local_end', $r[0]);
} else {
check_item_notification($current_post, $uid);
if ($notify) {
- proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/notifier.php", $notify_type, $current_post);
+ Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "Notifier", $notify_type, $current_post);
}
return $current_post;
if (!$update && ($arr["network"] == NETWORK_DFRN) && ($arr["parent-uri"] === $arr["uri"])) {
$isforum = q("SELECT `forum` FROM `contact` WHERE `id` = %d AND `forum`",
intval($arr['contact-id']));
- if (dbm::is_result($isforum)) {
+ if (DBM::is_result($isforum)) {
$update = true;
}
}
function get_item_guid($id) {
$r = q("SELECT `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($id));
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
return $r[0]["guid"];
} else {
/// @TODO This else-block can be elimited again
$r = q("SELECT `item`.`id`, `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0
AND `item`.`guid` = '%s' AND `item`.`uid` = %d", dbesc($guid), intval($uid));
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$id = $r[0]["id"];
$nick = $r[0]["nickname"];
}
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND `item`.`private` = 0 AND `item`.`wall` = 1
AND `item`.`guid` = '%s'", dbesc($guid));
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$id = $r[0]["id"];
$nick = $r[0]["nickname"];
}
intval($uid)
);
- if (! dbm::is_result($u)) {
+ if (! DBM::is_result($u)) {
return;
}
intval($item_id),
intval($uid)
);
- if (! dbm::is_result($i)) {
+ if (! DBM::is_result($i)) {
return;
}
$c = q("SELECT `name`, `url`, `thumb` FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($u[0]['uid'])
);
- if (! dbm::is_result($c)) {
+ if (! DBM::is_result($c)) {
return;
}
);
update_thread($item_id);
- proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), 'include/notifier.php', 'tgroup', $item_id);
+ Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), 'Notifier', 'tgroup', $item_id);
}
$u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
- if (! dbm::is_result($u)) {
+ if (! DBM::is_result($u)) {
return false;
}
//$tempfile = tempnam(get_temppath(), "ostatus2");
//file_put_contents($tempfile, $xml);
logger("Consume OStatus messages ", LOGGER_DEBUG);
- ostatus::import($xml, $importer, $contact, $hub);
+ OStatus::import($xml, $importer, $contact, $hub);
}
return;
}
WHERE `contact`.`id` = %d AND `user`.`uid` = %d",
dbesc($contact["id"]), dbesc($importer["uid"])
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
logger("Now import the DFRN feed");
- dfrn::import($xml, $r[0], true);
+ DFRN::import($xml, $r[0], true);
return;
}
}
if ($contact['remote_self'] == 2) {
$r = q("SELECT `id`,`url`,`name`,`thumb` FROM `contact` WHERE `uid` = %d AND `self`",
intval($contact['uid']));
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$datarray['contact-id'] = $r[0]["id"];
$datarray['owner-name'] = $r[0]["name"];
$datarray["app"] = "Feed";
}
+ // Trigger automatic reactions for addons
+ $datarray['api_source'] = true;
+
+ // We have to tell the hooks who we are - this really should be improved
+ $_SESSION["authenticated"] = true;
+ $_SESSION["uid"] = $contact['uid'];
+
return true;
}
intval($importer['uid']),
dbesc($url)
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
$contact_record = $r[0];
update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true);
}
intval($importer['uid'])
);
- if (dbm::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
+ if (DBM::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY))) {
// create notification
$hash = random_string();
));
}
- } elseif (dbm::is_result($r) && in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
+ } 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",
intval($importer['uid']),
dbesc($url)
* through the direct Diaspora protocol. If we try and use
* the feed, we'll get duplicates. So don't.
*/
- if ((! dbm::is_result($r)) || $contact['network'] === NETWORK_DIASPORA) {
+ if ((! DBM::is_result($r)) || $contact['network'] === NETWORK_DIASPORA) {
return;
}
- $push_url = get_config('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
+ $push_url = Config::get('system','url') . '/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());
function fix_private_photos($s, $uid, $item = null, $cid = 0) {
- if (get_config('system','disable_embedded')) {
+ if (Config::get('system','disable_embedded')) {
return $s;
}
intval($uid)
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
/*
* Check to see if we should replace this photo link with an embedded image
* 1. No need to do so if the photo is public
* $expire_network_only = save your own wall posts
* and just expire conversations started by others
*/
- $expire_network_only = get_pconfig($uid,'expire', 'network_only');
+ $expire_network_only = PConfig::get($uid,'expire', 'network_only');
$sql_extra = ((intval($expire_network_only)) ? " AND wall = 0 " : "");
if ($network != "") {
intval($days)
);
- if (! dbm::is_result($r)) {
+ if (! DBM::is_result($r)) {
return;
}
- $expire_items = get_pconfig($uid, 'expire', 'items');
- $expire_items = (($expire_items === false) ? 1 : intval($expire_items)); // default if not set: 1
+ $expire_items = PConfig::get($uid, 'expire', 'items', 1);
// Forcing expiring of items - but not notes and marked items
if ($force) {
$expire_items = true;
}
- $expire_notes = get_pconfig($uid, 'expire', 'notes');
- $expire_notes = (($expire_notes === false) ? 1 : intval($expire_notes)); // default if not set: 1
-
- $expire_starred = get_pconfig($uid, 'expire', 'starred');
- $expire_starred = (($expire_starred === false) ? 1 : intval($expire_starred)); // default if not set: 1
-
- $expire_photos = get_pconfig($uid, 'expire', 'photos');
- $expire_photos = (($expire_photos === false) ? 0 : intval($expire_photos)); // default if not set: 0
+ $expire_notes = PConfig::get($uid, 'expire', 'notes', 1);
+ $expire_starred = PConfig::get($uid, 'expire', 'starred', 1);
+ $expire_photos = PConfig::get($uid, 'expire', 'photos', 0);
logger('User '.$uid.': expire: # items=' . count($r). "; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
drop_item($item['id'], false);
}
- proc_run(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "include/notifier.php", "expire", $uid);
-
+ Worker::add(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "Notifier", "expire", $uid);
}
/// @TODO type-hint is array
// multiple threads may have been deleted, send an expire notification
if ($uid) {
- proc_run(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "include/notifier.php", "expire", $uid);
+ Worker::add(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "Notifier", "expire", $uid);
}
}
intval($id)
);
- if (! dbm::is_result($r)) {
+ if (! DBM::is_result($r)) {
if (! $interactive) {
return 0;
}
dbesc($item['parent-uri']),
intval($item['uid'])
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
dba::update('item', array('last-child' => true), array('id' => $r[0]['id']));
}
}
$drop_id = intval($item['id']);
$priority = ($interactive ? PRIORITY_HIGH : PRIORITY_LOW);
- proc_run(array('priority' => $priority, 'dont_fork' => true), "include/notifier.php", "drop", $drop_id);
+ Worker::add(array('priority' => $priority, 'dont_fork' => true), "Notifier", "drop", $drop_id);
if (! $interactive) {
return $owner;
intval($uid),
intval($wall ? 1 : 0)
);
- if (dbm::is_result($r)) {
+ if (DBM::is_result($r)) {
// logger('first_post_date: ' . $r[0]['id'] . ' ' . $r[0]['created'], LOGGER_DATA);
return substr(datetime_convert('',date_default_timezone_get(), $r[0]['created']),0,10);
}
// For former Facebook folks that left because of "timeline"
/*
* @TODO old-lost code?
- if ($wall && intval(get_pconfig($uid, 'system', 'no_wall_archive_widget')))
+ if ($wall && intval(PConfig::get($uid, 'system', 'no_wall_archive_widget')))
return $o;
*/
- $visible_years = get_pconfig($uid,'system','archive_visible_years');
+ $visible_years = PConfig::get($uid,'system','archive_visible_years');
if (! $visible_years) {
$visible_years = 5;
}
$ret = list_post_dates($uid, $wall);
- if (! dbm::is_result($ret)) {
+ if (! DBM::is_result($ret)) {
return $o;
}