X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=24eb1b30fb7b97c823238d2a2989b9d9413b589e;hb=4812f4c0f93915c20e4b3a9727fe0535a9d72721;hp=e91c7088ab297da633a1546b8dc88cc7f09d1564;hpb=8b7d5d0efc3e28b2f7a5407f6583c8232739aa71;p=friendica.git diff --git a/include/items.php b/include/items.php index e91c7088ab..24eb1b30fb 100644 --- a/include/items.php +++ b/include/items.php @@ -704,7 +704,7 @@ 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(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); @@ -820,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); @@ -829,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; @@ -857,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; } @@ -953,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']) { @@ -994,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; } @@ -1188,19 +1196,22 @@ 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]; @@ -1257,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 @@ -1266,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']), @@ -1289,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 @@ -1298,12 +1308,13 @@ 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); @@ -1318,7 +1329,7 @@ function tgroup_check($uid,$item) { $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]); @@ -1326,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)); } /* @@ -1344,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); } /** @@ -2227,7 +2238,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;