X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=f1ce70d46bade40dc26ae731fa837944488c74e7;hb=de227e305e4ffe35a8d99601e6b3a94d7adebdff;hp=b028fcc38e2b4822d2fafb049662993d474145a6;hpb=fc55a4b9c05123b806d30c228997397ca7897a11;p=friendica.git diff --git a/include/items.php b/include/items.php index b028fcc38e..f1ce70d46b 100644 --- a/include/items.php +++ b/include/items.php @@ -3,7 +3,6 @@ * @file include/items.php */ use Friendica\App; -use Friendica\ParseUrl; use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; @@ -13,21 +12,19 @@ use Friendica\Database\DBM; 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\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'; @@ -40,13 +37,20 @@ function construct_verb($item) { /* 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 + * + * */ -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 @@ -58,7 +62,6 @@ function limit_body_size($body) { $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); @@ -113,12 +116,10 @@ function limit_body_size($body) { 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; @@ -172,12 +173,6 @@ function add_page_info_data($data) { 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)); @@ -424,7 +419,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)) && !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'])) { @@ -482,8 +477,8 @@ function store_conversation($arr) { } /// @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 @@ -505,6 +500,8 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f $arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname()); } } + } else { + $arr['network'] = trim(defaults($arr, 'network', NETWORK_PHANTOM)); } if ($notify) { @@ -565,9 +562,9 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f // 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'])) { @@ -584,7 +581,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f * 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), @@ -647,7 +644,6 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f $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 ); @@ -677,18 +673,19 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f $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", @@ -736,7 +733,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f 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. @@ -855,7 +852,6 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f 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)) { @@ -1052,7 +1048,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f } // 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; @@ -1113,14 +1109,14 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f * 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) @@ -1133,7 +1129,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f 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); @@ -1153,14 +1149,14 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f */ function item_set_last_item($arr) { // Unarchive the author - $contact = dba::select('contact', [], ['id' => $arr["author-link"]], ['limit' => 1]); + $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::select('contact', [], ['id' => $arr["contact-id"]], ['limit' => 1]); + $contact = dba::selectFirst('contact', [], ['id' => $arr["contact-id"]]); if ($contact['term-date'] > NULL_DATE) { Contact::unmarkForArchival($contact); } @@ -1206,8 +1202,6 @@ function item_body_set_hashtags(&$item) { // 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 @@ -1316,7 +1310,6 @@ function get_item_contact($item, $contacts) { foreach ($contacts as $contact) { if ($contact['id'] == $item['contact-id']) { return $contact; - break; // NOTREACHED } } return false; @@ -1328,16 +1321,13 @@ function get_item_contact($item, $contacts) { * @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; } @@ -1345,7 +1335,6 @@ function tag_deliver($uid, $item_id) { $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) @@ -1675,15 +1664,13 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { 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']), @@ -1696,6 +1683,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { 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) @@ -1709,9 +1697,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { $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(); @@ -1743,7 +1729,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { } } 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) ); @@ -1799,7 +1785,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { 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); @@ -1810,16 +1796,22 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { } -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 = ''; @@ -1827,19 +1819,18 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) { $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) { @@ -1849,7 +1840,6 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) { dbesc($i), intval($res), intval($uid) - ); if (DBM::is_result($r)) { /* @@ -2162,12 +2152,12 @@ function drop_item($id, $interactive = true) { 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 @@ -2230,17 +2220,17 @@ function drop_item($id, $interactive = true) { // Now delete them if ($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 {