X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=ce7610312947b171a2787831ecad2a979d891a68;hb=95bb8d38e87d8b09ef37404c4b23c08b6feb9da4;hp=7518d4c0c4ebbb0b34f61506787e3e34e6215746;hpb=9894f7cea776512666626b869776e7bf6894be5b;p=friendica.git diff --git a/include/api.php b/include/api.php index 7518d4c0c4..ce76103129 100644 --- a/include/api.php +++ b/include/api.php @@ -5,6 +5,9 @@ * * @todo Automatically detect if incoming data is HTML or BBCode */ + +use \Friendica\Core\Config; + require_once('include/HTTPExceptions.php'); require_once('include/bbcode.php'); @@ -133,7 +136,7 @@ * @hook 'logged_in' * array $user logged user record */ - function api_login(&$a){ + function api_login(App $a){ // login with oauth try{ $oauth = new FKOAuth1(); @@ -208,7 +211,7 @@ dbesc(trim($user)), dbesc($encrypted) ); - if(count($r)) + if (dbm::is_result($r)) $record = $r[0]; } @@ -251,8 +254,8 @@ * @param App $a * @return string API call result */ - function api_call(&$a){ - GLOBAL $API, $called_api; + function api_call(App $a){ + global $API, $called_api; $type="json"; if (strpos($a->query_string, ".xml")>0) $type="xml"; @@ -404,17 +407,17 @@ * @param array $user_info * @return array */ - function api_rss_extra(&$a, $arr, $user_info){ + function api_rss_extra(App $a, $arr, $user_info){ if (is_null($user_info)) $user_info = api_get_user($a); $arr['$user'] = $user_info; $arr['$rss'] = array( - 'alternate' => $user_info['url'], - 'self' => App::get_baseurl(). "/". $a->query_string, - 'base' => App::get_baseurl(), - 'updated' => api_date(null), + 'alternate' => $user_info['url'], + 'self' => App::get_baseurl(). "/". $a->query_string, + 'base' => App::get_baseurl(), + 'updated' => api_date(null), 'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME), - 'language' => $user_info['language'], - 'logo' => App::get_baseurl()."/images/friendica-32.png", + 'language' => $user_info['language'], + 'logo' => App::get_baseurl()."/images/friendica-32.png", ); return $arr; @@ -444,7 +447,7 @@ * @param int|string $contact_id Contact ID or URL * @param string $type Return type (for errors) */ - function api_get_user(&$a, $contact_id = Null, $type = "json"){ + function api_get_user(App $a, $contact_id = Null, $type = "json"){ global $called_api; $user = null; $extra_query = ""; @@ -623,7 +626,7 @@ // count friends $r = q("SELECT count(*) as `count` FROM `contact` WHERE `uid` = %d AND `rel` IN ( %d, %d ) - AND `self`=0 AND `blocked`=0 AND `hidden`=0", + AND `self`=0 AND NOT `blocked` AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND) @@ -632,7 +635,7 @@ $r = q("SELECT count(*) as `count` FROM `contact` WHERE `uid` = %d AND `rel` IN ( %d, %d ) - AND `self`=0 AND `blocked`=0 AND `hidden`=0", + AND `self`=0 AND NOT `blocked` AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND) @@ -712,7 +715,7 @@ * @param array $item : item from db * @return array(array:author, array:owner) */ - function api_item_get_user(&$a, $item) { + function api_item_get_user(App $a, $item) { $status_user = api_get_user($a, $item["author-link"]); @@ -1326,10 +1329,10 @@ if (isset($_GET["q"])) { $r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", dbesc($_GET["q"])); - if (!count($r)) + if (!dbm::is_result($r)) $r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", dbesc($_GET["q"])); - if (count($r)) { + if (dbm::is_result($r)) { $k = 0; foreach ($r AS $user) { $user_info = api_get_user($a, $user["id"], "json"); @@ -1399,7 +1402,7 @@ `contact`.`id` AS `cid` FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` $sql_extra @@ -1476,7 +1479,7 @@ `user`.`nickname`, `user`.`hidewall` FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` AND NOT `user`.`hidewall` WHERE `verb` = '%s' AND `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` @@ -1543,7 +1546,7 @@ `contact`.`id` AS `cid` FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` AND `item`.`uid` = %d AND `item`.`verb` = '%s' $sql_extra", @@ -1619,7 +1622,7 @@ `contact`.`id` AS `cid` FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`parent` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` AND `item`.`uid` = %d AND `item`.`verb` = '%s' @@ -1673,7 +1676,7 @@ `contact`.`id` AS `cid` FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` AND NOT `item`.`private` AND `item`.`allow_cid` = '' AND `item`.`allow`.`gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' @@ -1792,7 +1795,7 @@ `contact`.`id` AS `cid` FROM `item` FORCE INDEX (`uid_id`) STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`uid` = %d AND `verb` = '%s' AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s')) AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` @@ -1866,7 +1869,7 @@ `contact`.`id` AS `cid` FROM `item` FORCE INDEX (`uid_contactid_id`) STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`contact-id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted` @@ -2002,7 +2005,7 @@ AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0 AND `item`.`starred` = 1 AND `contact`.`id` = `item`.`contact-id` - AND NOT `contact`.`blocked` + AND (NOT `contact`.`blocked` OR `contact`.`pending`) $sql_extra AND `item`.`id`>%d ORDER BY `item`.`id` DESC LIMIT %d ,%d ", @@ -2344,6 +2347,9 @@ * dislikes => int count */ function api_format_items_activities(&$item, $type = "json") { + + $a = get_app(); + $activities = array( 'like' => array(), 'dislike' => array(), @@ -2451,7 +2457,7 @@ 'homepage' => $profile['homepage'], 'users' => null); return $profile; - } + } } /** @@ -2521,9 +2527,9 @@ // Retweets are only valid for top postings // It doesn't work reliable with the link if its a feed - #$IsRetweet = ($item['owner-link'] != $item['author-link']); - #if ($IsRetweet) - # $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar'])); + //$IsRetweet = ($item['owner-link'] != $item['author-link']); + //if ($IsRetweet) + // $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar'])); if ($item["id"] == $item["parent"]) { @@ -2648,7 +2654,7 @@ if ($user_info['self'] == 0) $sql_extra = " AND false "; - $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `blocked` $sql_extra", + $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND NOT `self` AND (NOT `blocked` OR `pending`) $sql_extra", intval(api_user()) ); @@ -2693,11 +2699,11 @@ $logo = App::get_baseurl() . '/images/friendica-64.png'; $email = $a->config['admin_email']; $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false'); - $private = (($a->config['system']['block_public']) ? 'true' : 'false'); + $private = ((Config::get('system', 'block_public')) ? 'true' : 'false'); $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000); if($a->config['api_import_size']) $texlimit = string($a->config['api_import_size']); - $ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false'); + $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false'); $sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : ''); $config = array( @@ -2755,7 +2761,7 @@ intval(api_user()) ); - if(!dbm::is_result($r)) + if (!dbm::is_result($r)) return; $ids = array(); @@ -2874,14 +2880,14 @@ // BadRequestException if no id specified (for clients using Twitter API) if ($id == 0) throw new BadRequestException('Message id not specified'); - // add parent-uri to sql command if specified by calling app + // add parent-uri to sql command if specified by calling app $sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . dbesc($parenturi) . "'" : ""); // get data of the specified message id $r = q("SELECT `id` FROM `mail` WHERE `uid` = %d AND `id` = %d" . $sql_extra, - intval($uid), + intval($uid), intval($id)); - + // error message if specified id is not in database if (!dbm::is_result($r)) { if ($verbose == "true") { @@ -2893,8 +2899,8 @@ } // delete message - $result = q("DELETE FROM `mail` WHERE `uid` = %d AND `id` = %d" . $sql_extra, - intval($uid), + $result = q("DELETE FROM `mail` WHERE `uid` = %d AND `id` = %d" . $sql_extra, + intval($uid), intval($id)); if ($verbose == "true") { @@ -3068,8 +3074,8 @@ 'image/gif' => 'gif' ); $data = array('photo'=>array()); - if($r) { - foreach($r as $rr) { + if ($r) { + foreach ($r as $rr) { $photo = array(); $photo['id'] = $rr['resource-id']; $photo['album'] = $rr['album']; @@ -3174,7 +3180,7 @@ intval(api_user()) ); - if ((! count($r)) || ($r[0]['network'] !== NETWORK_DFRN)) + if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) throw new BadRequestException("Unknown contact"); $cid = $r[0]['id']; @@ -3218,7 +3224,7 @@ function api_share_as_retweet(&$item) { $body = trim($item["body"]); - if (diaspora::is_reshare($body, false)===false) { + if (Diaspora::is_reshare($body, false)===false) { return false; } @@ -3526,7 +3532,7 @@ intval($uid), intval($gid)); // error message if specified gid is not in database - if (count($r) == 0) + if (!dbm::is_result($r)) throw new BadRequestException("gid not available"); } else @@ -3581,7 +3587,7 @@ intval($uid), intval($gid)); // error message if specified gid is not in database - if (count($r) == 0) + if (!dbm::is_result($r)) throw new BadRequestException('gid not available'); // get data of the specified group id and group name @@ -3590,7 +3596,7 @@ intval($gid), dbesc($name)); // error message if specified gid is not in database - if (count($rname) == 0) + if (!dbm::is_result($rname)) throw new BadRequestException('wrong group name'); // delete group @@ -3629,7 +3635,7 @@ intval($uid), dbesc($name)); // error message if specified group name already exists - if (count($rname) != 0) + if (dbm::is_result($rname)) throw new BadRequestException('group name already exists'); // check if specified group name is a deleted group @@ -3637,7 +3643,7 @@ intval($uid), dbesc($name)); // error message if specified group name already exists - if (count($rname) != 0) + if (dbm::is_result($rname)) $reactivate_group = true; // create group @@ -3860,7 +3866,7 @@ // get data of the specified message id $r = q("SELECT `id` FROM `mail` WHERE `id` = %d AND `uid` = %d", - intval($id), + intval($id), intval($uid)); // error message if specified id is not in database if (!dbm::is_result($r)) { @@ -3869,8 +3875,8 @@ } // update seen indicator - $result = q("UPDATE `mail` SET `seen` = 1 WHERE `id` = %d AND `uid` = %d", - intval($id), + $result = q("UPDATE `mail` SET `seen` = 1 WHERE `id` = %d AND `uid` = %d", + intval($id), intval($uid)); if ($result) { @@ -3919,7 +3925,9 @@ $profile_url = $user_info["url"]; // message if nothing was found - if (count($r) == 0) + if (!dbm::is_result($r)) + $success = array('success' => false, 'search_results' => 'problem with query'); + else if (count($r) == 0) $success = array('success' => false, 'search_results' => 'nothing found'); else { $ret = Array(); @@ -3941,7 +3949,6 @@ } api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true); - /** * @brief return data of all the profiles a user has to the client * @@ -3966,7 +3973,7 @@ intval(api_user()), intval($profileid)); // error message if specified gid is not in database - if (count($r) == 0) + if (!dbm::is_result($r)) throw new BadRequestException("profile_id not available"); } else