X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=08bd835f3bf9bc5fa7f47d5c2534da135e3119bd;hb=8e12b159d947fb27ad6bdd5e06e3a90c1713687e;hp=df62abd8e6dab1398506b8f7f13d5903251ff451;hpb=dac1dbd3e963be0606d8bc29ad6b3085f1c83105;p=friendica.git diff --git a/include/api.php b/include/api.php index df62abd8e6..08bd835f3b 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(); @@ -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"; @@ -349,6 +352,7 @@ } } } + logger('API call not implemented: '.$a->query_string); throw new NotImplementedException(); } catch (HTTPException $e) { header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}"); @@ -404,7 +408,7 @@ * @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( @@ -444,7 +448,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 +627,7 @@ // count friends $r = q("SELECT count(*) as `count` FROM `contact` WHERE `uid` = %d AND `rel` IN ( %d, %d ) - AND `self`=0 AND NOT `blocked` AND `hidden`=0", + AND `self`=0 AND NOT `blocked` AND NOT `pending` AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND) @@ -632,7 +636,7 @@ $r = q("SELECT count(*) as `count` FROM `contact` WHERE `uid` = %d AND `rel` IN ( %d, %d ) - AND `self`=0 AND NOT `blocked` AND `hidden`=0", + AND `self`=0 AND NOT `blocked` AND NOT `pending` AND `hidden`=0", intval($uinfo[0]['uid']), intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND) @@ -712,7 +716,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"]); @@ -1683,20 +1687,16 @@ ); if ($r[0]['body'] != "") { - if (!intval(get_config('system','old_share'))) { - if (strpos($r[0]['body'], "[/share]") !== false) { - $pos = strpos($r[0]['body'], "[share"); - $post = substr($r[0]['body'], $pos); - } else { - $post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); - - $post .= $r[0]['body']; - $post .= "[/share]"; - } - $_REQUEST['body'] = $post; - } else - $_REQUEST['body'] = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body']; + if (strpos($r[0]['body'], "[/share]") !== false) { + $pos = strpos($r[0]['body'], "[share"); + $post = substr($r[0]['body'], $pos); + } else { + $post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); + $post .= $r[0]['body']; + $post .= "[/share]"; + } + $_REQUEST['body'] = $post; $_REQUEST['profile_uid'] = api_user(); $_REQUEST['type'] = 'wall'; $_REQUEST['api_source'] = true; @@ -2344,6 +2344,9 @@ * dislikes => int count */ function api_format_items_activities(&$item, $type = "json") { + + $a = get_app(); + $activities = array( 'like' => array(), 'dislike' => array(), @@ -2451,7 +2454,7 @@ 'homepage' => $profile['homepage'], 'users' => null); return $profile; - } + } } /** @@ -2521,9 +2524,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"]) { @@ -2693,11 +2696,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( @@ -2726,6 +2729,7 @@ return api_format_data('version', $type, array('version' => $fake_statusnet_version)); } + api_register_func('api/gnusocial/version','api_statusnet_version',false); api_register_func('api/statusnet/version','api_statusnet_version',false); /** @@ -2874,14 +2878,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 +2897,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 +3072,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']; @@ -3218,7 +3222,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; } @@ -3860,7 +3864,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 +3873,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) { @@ -3921,7 +3925,7 @@ // message if nothing was found if (!dbm::is_result($r)) $success = array('success' => false, 'search_results' => 'problem with query'); - else if (count($r) == 0) + else if (count($r) == 0) $success = array('success' => false, 'search_results' => 'nothing found'); else { $ret = Array();