*
* @todo Automatically detect if incoming data is HTML or BBCode
*/
+
+use \Friendica\Core\Config;
+
require_once('include/HTTPExceptions.php');
require_once('include/bbcode.php');
* @hook 'logged_in'
* array $user logged user record
*/
- function api_login(&$a){
+ function api_login(App $a){
// login with oauth
try{
$oauth = new FKOAuth1();
dbesc(trim($user)),
dbesc($encrypted)
);
- if(count($r))
+ if (dbm::is_result($r))
$record = $r[0];
}
* @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";
}
}
}
+ logger('API call not implemented: '.$a->query_string);
throw new NotImplementedException();
} catch (HTTPException $e) {
header("HTTP/1.1 {$e->httpcode} {$e->httpdesc}");
* @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' => $a->get_baseurl(). "/". $a->query_string,
- 'base' => $a->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' => $a->get_baseurl()."/images/friendica-32.png",
+ 'language' => $user_info['language'],
+ 'logo' => App::get_baseurl()."/images/friendica-32.png",
);
return $arr;
* @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 = "";
// 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)
$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)
'follow_request_sent' => false,
'statusnet_blocking' => false,
'notifications' => false,
- //'statusnet_profile_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
+ //'statusnet_profile_url' => App::get_baseurl()."/contacts/".$uinfo[0]['cid'],
'statusnet_profile_url' => $uinfo[0]['url'],
'uid' => intval($uinfo[0]['uid']),
'cid' => intval($uinfo[0]['cid']),
* @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"]);
if ($r) {
$phototypes = Photo::supportedTypes();
$ext = $phototypes[$r[0]['type']];
- $_REQUEST['body'] .= "\n\n".'[url='.$a->get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
- $_REQUEST['body'] .= '[img]'.$a->get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
+ $_REQUEST['body'] .= "\n\n".'[url='.App::get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
+ $_REQUEST['body'] .= '[img]'.App::get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
}
}
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");
);
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;
$start = $page*$count;
// Ugly code - should be changed
- $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
+ $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname'];
$myurl = substr($myurl,strpos($myurl,'://')+3);
//$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
$myurl = str_replace('www.','',$myurl);
$text = preg_replace_callback(
"|data:image/([^;]+)[^=]+=*|m",
function($match) use ($item) {
- return $a->get_baseurl()."/display/".$item['guid'];
+ return App::get_baseurl()."/display/".$item['guid'];
},
$text);
return $text;
* dislikes => int count
*/
function api_format_items_activities(&$item, $type = "json") {
+
+ $a = get_app();
+
$activities = array(
'like' => array(),
'dislike' => array(),
'homepage' => $profile['homepage'],
'users' => null);
return $profile;
- }
+ }
}
/**
// 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"]) {
$name = $a->config['sitename'];
$server = $a->get_hostname();
- $logo = $a->get_baseurl() . '/images/friendica-64.png';
+ $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');
- $sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
+ $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false');
+ $sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
$config = array(
'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
return api_format_data('config', $type, array('config' => $config));
}
+ api_register_func('api/gnusocial/config','api_statusnet_config',false);
api_register_func('api/statusnet/config','api_statusnet_config',false);
function api_statusnet_version($type) {
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);
/**
intval(api_user())
);
- if(!dbm::is_result($r))
+ if (!dbm::is_result($r))
return;
$ids = array();
// 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") {
}
// 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") {
'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'];
$photo['filename'] = $rr['filename'];
$photo['type'] = $rr['type'];
- $thumb = $a->get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
+ $thumb = App::get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
if ($type == "xml")
$data['photo'][] = array("@attributes" => $photo, "1" => $thumb);
for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++)
$data['photo']['links'][$k.":link"]["@attributes"] = array("type" => $data['photo']['type'],
"scale" => $k,
- "href" => $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
+ "href" => App::get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
} else {
$data['photo']['link'] = array();
for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++) {
- $data['photo']['link'][$k] = $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
+ $data['photo']['link'][$k] = App::get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
}
}
unset($data['photo']['resource-id']);
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'];
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;
}
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
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
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
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
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
// 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)) {
}
// 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) {
$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();
}
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
*
$multi_profiles = feature_enabled(api_user(),'multi_profiles');
$directory = get_config('system', 'directory');
-// get data of the specified profile id or all profiles of the user if not specified
+ // get data of the specified profile id or all profiles of the user if not specified
if ($profileid != 0) {
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d",
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
+ } else {
$r = q("SELECT * FROM `profile` WHERE `uid` = %d",
intval(api_user()));
-
+ }
// loop through all returned profiles and retrieve data and users
$k = 0;
foreach ($r as $rr) {
}
// return settings, authenticated user and profiles data
+ $self = q("SELECT `nurl` FROM `contact` WHERE `uid`= %d AND `self` LIMIT 1", intval(api_user()));
+
$result = array('multi_profiles' => $multi_profiles ? true : false,
'global_dir' => $directory,
- 'friendica_owner' => api_get_user($a, intval(api_user())),
+ 'friendica_owner' => api_get_user($a, $self[0]['nurl']),
'profiles' => $profiles);
return api_format_data("friendica_profiles", $type, array('$result' => $result));
}