X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=c2b3d7d1f5c0c50038a628b10be7a2db0f05cd5c;hb=8bdc906013461464b475c4f10918adff8730dea6;hp=da9147faddddd4da00cc2d7050b74cfe6c2d7dd2;hpb=7141ce91635e071a54ec57b2971f9c745a996fc0;p=friendica.git diff --git a/include/items.php b/include/items.php index da9147fadd..c2b3d7d1f5 100644 --- a/include/items.php +++ b/include/items.php @@ -208,13 +208,12 @@ function add_page_info_data($data) { $hashtags = ""; if (isset($data["keywords"]) AND count($data["keywords"])) { - $a = get_app(); $hashtags = "\n"; foreach ($data["keywords"] AS $keyword) { /// @todo make a positive list of allowed characters $hashtag = str_replace(array(" ", "+", "/", ".", "#", "'", "’", "`", "(", ")", "„", "“"), array("","", "", "", "", "", "", "", "", "", "", ""), $keyword); - $hashtags .= "#[url=".$a->get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url] "; + $hashtags .= "#[url=".App::get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url] "; } } @@ -251,7 +250,6 @@ function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = fa $tags = ""; if (isset($data["keywords"]) AND count($data["keywords"])) { - $a = get_app(); foreach ($data["keywords"] AS $keyword) { $hashtag = str_replace(array(" ", "+", "/", ".", "#", "'"), array("","", "", "", "", ""), $keyword); @@ -259,7 +257,7 @@ function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = fa if ($tags != "") $tags .= ","; - $tags .= "#[url=".$a->get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url]"; + $tags .= "#[url=".App::get_baseurl()."/search?tag=".rawurlencode($hashtag)."]".$hashtag."[/url]"; } } @@ -557,8 +555,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa logger("Both author-link and owner-link are empty. Called by: ".App::callstack(), LOGGER_DEBUG); if ($arr['plink'] == "") { - $a = get_app(); - $arr['plink'] = $a->get_baseurl().'/display/'.urlencode($arr['guid']); + $arr['plink'] = App::get_baseurl().'/display/'.urlencode($arr['guid']); } if ($arr['network'] == "") { @@ -707,9 +704,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // 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 (count($u)) { + if (dbm::is_result($u)) { $a = get_app(); - $self = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']); + $self = normalise_link(App::get_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) OR (normalise_link($arr['owner-link']) == $self)) { q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($parent_id)); @@ -823,7 +820,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // Store the unescaped version $unescaped = $arr; - dbesc_array($arr); + dbm::esc_array($arr, true); logger('item_store: ' . print_r($arr,true), LOGGER_DATA); @@ -832,9 +829,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $r = dbq("INSERT INTO `item` (`" . implode("`, `", array_keys($arr)) - . "`) VALUES ('" - . implode("', '", array_values($arr)) - . "')"); + . "`) VALUES (" + . implode(", ", array_values($arr)) + . ")"); // And restore it $arr = $unescaped; @@ -860,10 +857,15 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } // Now we store the data in the spool directory - $file = 'item-'.round(microtime(true) * 10000).".msg"; - $spool = get_spoolpath().'/'.$file; - file_put_contents($spool, json_encode($arr)); - logger("Item wasn't stored - Item was spooled into file ".$file, LOGGER_DEBUG); + // We use "microtime" to keep the arrival order and "mt_rand" to avoid duplicates + $file = 'item-'.round(microtime(true) * 10000).'-'.mt_rand().'.msg'; + + $spoolpath = get_spoolpath(); + if ($spoolpath != "") { + $spool = $spoolpath.'/'.$file; + file_put_contents($spool, json_encode($arr)); + logger("Item wasn't stored - Item was spooled into file ".$file, LOGGER_DEBUG); + } return 0; } @@ -956,14 +958,16 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // in it. if (!$deleted AND !$dontcache) { - $r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post)); - if (count($r) == 1) { - if ($notify) + $r = q('SELECT * FROM `item` WHERE `id` = %d', intval($current_post)); + if ((dbm::is_result($r)) && (count($r) == 1)) { + if ($notify) { call_hooks('post_local_end', $r[0]); - else + } else { call_hooks('post_remote_end', $r[0]); - } else + } + } else { logger('item_store: new item not found in DB, id ' . $current_post); + } } if ($arr['parent-uri'] === $arr['uri']) { @@ -997,8 +1001,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa check_item_notification($current_post, $uid); - if ($notify) + if ($notify) { proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $current_post); + } return $current_post; } @@ -1068,10 +1073,10 @@ function item_body_set_hashtags(&$item) { // All hashtags should point to the home server //$item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", - // "#[url=".$a->get_baseurl()."/search?tag=$2]$2[/url]", $item["body"]); + // "#[url=".App::get_baseurl()."/search?tag=$2]$2[/url]", $item["body"]); //$item["tag"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", - // "#[url=".$a->get_baseurl()."/search?tag=$2]$2[/url]", $item["tag"]); + // "#[url=".App::get_baseurl()."/search?tag=$2]$2[/url]", $item["tag"]); // mask hashtags inside of url, bookmarks and attachments to avoid urls in urls $item["body"] = preg_replace_callback("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", @@ -1103,7 +1108,7 @@ function item_body_set_hashtags(&$item) { $basetag = str_replace('_',' ',substr($tag,1)); - $newtag = '#[url='.$a->get_baseurl().'/search?tag='.rawurlencode($basetag).']'.$basetag.'[/url]'; + $newtag = '#[url='.App::get_baseurl().'/search?tag='.rawurlencode($basetag).']'.$basetag.'[/url]'; $item["body"] = str_replace($tag, $newtag, $item["body"]); @@ -1191,28 +1196,31 @@ function tag_deliver($uid,$item_id) { $u = q("select * from user where uid = %d limit 1", intval($uid) ); - if (! count($u)) + + 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", + $i = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item_id), intval($uid) ); - if (! count($i)) + if (! dbm::is_result($i)) { return; + } $item = $i[0]; - $link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']); + $link = normalise_link(App::get_baseurl() . '/profile/' . $u[0]['nickname']); // Diaspora uses their own hardwired link URL in @-tags // instead of the one we supply with webfinger - $dlink = normalise_link($a->get_baseurl() . '/u/' . $u[0]['nickname']); + $dlink = normalise_link(App::get_baseurl() . '/u/' . $u[0]['nickname']); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER); if ($cnt) { @@ -1260,8 +1268,9 @@ function tag_deliver($uid,$item_id) { $c = q("select name, url, thumb from contact where self = 1 and uid = %d limit 1", intval($u[0]['uid']) ); - if (! count($c)) + if (! dbm::is_result($c)) { return; + } // also reset all the privacy bits to the forum default permissions @@ -1269,8 +1278,8 @@ function tag_deliver($uid,$item_id) { $forum_mode = (($prvgroup) ? 2 : 1); - q("update item set wall = 1, origin = 1, forum_mode = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s', - `private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' where id = %d", + q("UPDATE `item` SET `wall` = 1, `origin` = 1, `forum_mode` = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s', + `private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `id` = %d", intval($forum_mode), dbesc($c[0]['name']), dbesc($c[0]['url']), @@ -1292,8 +1301,6 @@ function tag_deliver($uid,$item_id) { function tgroup_check($uid,$item) { - $a = get_app(); - $mention = false; // check that the message originated elsewhere and is a top-level post @@ -1301,27 +1308,28 @@ function tgroup_check($uid,$item) { if (($item['wall']) || ($item['origin']) || ($item['uri'] != $item['parent-uri'])) return false; - - $u = q("select * from user where uid = %d limit 1", + /// @TODO Encapsulate this or find it encapsulated and replace all occurrances + $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid) ); - if (! count($u)) + if (! dbm::is_result($u)) { return false; + } $community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); $prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false); - $link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']); + $link = normalise_link(App::get_baseurl() . '/profile/' . $u[0]['nickname']); // Diaspora uses their own hardwired link URL in @-tags // instead of the one we supply with webfinger - $dlink = normalise_link($a->get_baseurl() . '/u/' . $u[0]['nickname']); + $dlink = normalise_link(App::get_baseurl() . '/u/' . $u[0]['nickname']); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER); if ($cnt) { - foreach($matches as $mtch) { + foreach ($matches as $mtch) { if (link_compare($link,$mtch[1]) || link_compare($dlink,$mtch[1])) { $mention = true; logger('tgroup_check: mention found: ' . $mtch[2]); @@ -1329,13 +1337,12 @@ function tgroup_check($uid,$item) { } } - if (! $mention) - return false; - - if ((! $community_page) && (! $prvgroup)) + if (! $mention) { return false; + } - return true; + /// @TODO Combines both return statements into one + return (($community_page) || ($prvgroup)); } /* @@ -1347,15 +1354,16 @@ function tgroup_check($uid,$item) { assumes the update has been seen before and should be ignored. */ function edited_timestamp_is_newer($existing, $update) { - if (!x($existing,'edited') || !$existing['edited']) { - return true; - } - if (!x($update,'edited') || !$update['edited']) { - return false; - } - $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']); - $update_edited = datetime_convert('UTC', 'UTC', $update['edited']); - return (strcmp($existing_edited, $update_edited) < 0); + if (!x($existing,'edited') || !$existing['edited']) { + return true; + } + if (!x($update,'edited') || !$update['edited']) { + return false; + } + + $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']); + $update_edited = datetime_convert('UTC', 'UTC', $update['edited']); + return (strcmp($existing_edited, $update_edited) < 0); } /** @@ -1488,17 +1496,19 @@ function item_is_remote_self($contact, &$datarray) { return true; } -function new_follower($importer,$contact,$datarray,$item,$sharing = false) { +function new_follower($importer, $contact, $datarray, $item, $sharing = false) { $url = notags(trim($datarray['author-link'])); $name = notags(trim($datarray['author-name'])); $photo = notags(trim($datarray['author-avatar'])); if (is_object($item)) { $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor'); - if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) + if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) { $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']; - } else + } + } else { $nick = $item; + } if (is_array($contact)) { if (($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING) @@ -1536,11 +1546,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true); } - $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer['uid']) ); - $a = get_app(); if (dbm::is_result($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { @@ -1559,8 +1567,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { $def_gid = get_default_group($importer['uid'], $contact_record["network"]); - if (intval($def_gid)) - group_add_member($importer['uid'],'',$contact_record['id'],$def_gid); + if (intval($def_gid)) { + group_add_member($importer['uid'], '', $contact_record['id'], $def_gid); + } if (($r[0]['notify-flags'] & NOTIFY_INTRO) && in_array($r[0]['page-flags'], array(PAGE_NORMAL))) { @@ -1572,7 +1581,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { 'to_name' => $r[0]['username'], 'to_email' => $r[0]['email'], 'uid' => $r[0]['uid'], - 'link' => $a->get_baseurl() . '/notifications/intro', + 'link' => App::get_baseurl() . '/notifications/intro', 'source_name' => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : t('[Name Withheld]')), 'source_link' => $contact_record['url'], 'source_photo' => $contact_record['photo'], @@ -1591,7 +1600,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { } } -function lose_follower($importer,$contact,$datarray = array(),$item = "") { +function lose_follower($importer, $contact, array $datarray = array(), $item = "") { if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) { q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d", @@ -1603,7 +1612,7 @@ function lose_follower($importer,$contact,$datarray = array(),$item = "") { } } -function lose_sharer($importer,$contact,$datarray = array(),$item = "") { +function lose_sharer($importer, $contact, array $datarray = array(), $item = "") { if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) { q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d", @@ -1615,7 +1624,7 @@ function lose_sharer($importer,$contact,$datarray = array(),$item = "") { } } -function subscribe_to_hub($url,$importer,$contact,$hubmode = 'subscribe') { +function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { $a = get_app(); @@ -1665,7 +1674,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) { $a = get_app(); logger('fix_private_photos: check for photos', LOGGER_DEBUG); - $site = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')); + $site = substr(App::get_baseurl(),strpos(App::get_baseurl(),'://')); $orig_body = $s; $new_body = ''; @@ -1929,7 +1938,7 @@ function drop_item($id,$interactive = true) { if (! $interactive) return 0; notice( t('Item not found.') . EOL); - goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); } $item = $r[0]; @@ -1977,7 +1986,7 @@ function drop_item($id,$interactive = true) { } // Now check how the user responded to the confirmation query if ($_REQUEST['canceled']) { - goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); } logger('delete item: ' . $item['id'], LOGGER_DEBUG); @@ -2127,13 +2136,13 @@ function drop_item($id,$interactive = true) { if (! $interactive) return $owner; - goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); //NOTREACHED } else { if (! $interactive) return 0; notice( t('Permission denied.') . EOL); - goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); //NOTREACHED } @@ -2230,7 +2239,7 @@ function posted_date_widget($url,$uid,$wall) { $ret = list_post_dates($uid,$wall); - if (! count($ret)) + if (! dbm::is_result($ret)) return $o; $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years;