}
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
+ *
+ * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
+ * @return string
+ */
+ function api_friendica_profile_show($type){
+ $a = get_app();
+
+ if (api_user()===false) throw new ForbiddenException();
+
+ // input params
+ $profileid = (x($_REQUEST,'profile_id') ? $_REQUEST['profile_id'] : 0);
+
+ // retrieve general information about profiles for user
+ $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
+ 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 (!dbm::is_result($r))
+ throw new BadRequestException("profile_id not available");
+ }
+ 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) {
+ $profile = api_format_items_profiles($rr, $type);
+
+ // select all users from contact table, loop and prepare standard return for user data
+ $users = array();
+ $r = q("SELECT `id`, `nurl` FROM `contact` WHERE `uid`= %d AND `profile-id` = %d",
+ intval(api_user()),
+ intval($rr['profile_id']));
+
+ foreach ($r as $rr) {
+ $user = api_get_user($a, $rr['nurl']);
+ ($type == "xml") ? $users[$k++.":user"] = $user : $users[] = $user;
+ }
+ $profile['users'] = $users;
+
+ // add prepared profile data to array for final return
+ if ($type == "xml") {
+ $profiles[$k++.":profile"] = $profile;
+ } else {
+ $profiles[] = $profile;
+ }
+ }
+
+ // return settings, authenticated user and profiles data
+ $result = array('multi_profiles' => $multi_profiles ? true : false,
+ 'global_dir' => $directory,
+ 'friendica_owner' => api_get_user($a, intval(api_user())),
+ 'profiles' => $profiles);
+ return api_format_data("friendica_profiles", $type, array('$result' => $result));
+ }
+ api_register_func('api/friendica/profile/show', 'api_friendica_profile_show', true, API_METHOD_GET);
+
/*
To.Do:
[pagename] => api/1.1/statuses/lookup.json
$is_new_table = False;
$sql3="";
if (!isset($database[$name])) {
- $r = db_create_table($name, $structure["fields"], $verbose, $action, $structure['indexes']);
+ $r = db_create_table($name, $structure["fields"], $charset, $verbose, $action, $structure['indexes']);
- if(false === $r) {
+ if(!dbm::is_result($r)) {
$errors .= t('Errors encountered creating database tables.').$name.EOL;
}
$is_new_table = True;
);
}
+/**
+ * @brief Checks if the communication with a given contact had problems recently
+ *
+ * @param int $cid Contact id
+ *
+ * @return bool The communication with this contact has currently problems
+ */
function was_recently_delayed($cid) {
- $was_delayed = false;
+ $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d
+ and last > UTC_TIMESTAMP() - interval 15 minute limit 1",
+ intval($cid)
+ );
+ if(dbm::is_result($r))
+ return true;
- $r = q("select `term-date` from contact where id = %d and `term-date` != '' and `term-date` != '0000-00-00 00:00:00' limit 1",
+ // Are there queue entries that were recently added?
+ $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d
+ AND `last` > UTC_TIMESTAMP() - interval 15 minute LIMIT 1",
intval($cid)
);
$session_exists = 0;
$session_expire = 180000;
-if(! function_exists('ref_session_open')) {
-function ref_session_open ($s,$n) {
+function ref_session_open($s, $n) {
return true;
-}}
+}
-if(! function_exists('ref_session_read')) {
-function ref_session_read ($id) {
+function ref_session_read($id) {
global $session_exists;
- if(x($id))
- $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
+
+ if (!x($id)) {
+ return '';
+ }
+
+ $memcache = cache::memcache();
+ if (is_object($memcache)) {
+ $data = $memcache->get(get_app()->get_hostname().":session:".$id);
+ if (!is_bool($data)) {
+ return $data;
+ }
+ logger("no data for session $id", LOGGER_TRACE);
+ return '';
+ }
+
+ $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
- if (dbm::is_result($r)) {
+ if(dbm::is_result($r)) {
$session_exists = true;
return $r[0]['data'];
} else {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
intval($uid)
);
- if(! dbm::is_result($r)) {
+
+ if(! dbm::is_result($r)) {
notice( t('This account has not been configured for email. Request failed.') . EOL);
return;
}
}
}
- $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
+ $r = qu("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
intval($a->profile['uid'])
);
- if (dbm::is_result($r)) {
- if(dbm::is_result($r))
++ if(dbm::is_result($r)) {
$a->page_contact = $r[0];
-
+ }
$is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
- if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
- notice( t('Access to this profile has been restricted.') . EOL);
+ if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
+ notice(t('Access to this profile has been restricted.') . EOL);
return;
}
$events=array();
// transform the event in a usable array
- if(dbm::is_result($r))
+ if(dbm::is_result($r)) {
$r = sort_by_date($r);
$events = process_events($r);
++ }
if ($a->argv[1] === 'json'){
echo json_encode($events); killme();
intval($perpage)
);
+ $results = array();
++
if(dbm::is_result($r)) {
foreach($r as $rr)
$results[] = array(
dbesc($album)
);
}
- if (dbm::is_result($r)) {
- foreach ($r as $rr) {
+ if(dbm::is_result($r)) {
+ foreach($r as $rr) {
$res[] = "'" . dbesc($rr['rid']) . "'" ;
}
- }
- else {
+ } else {
goaway($_SESSION['photo_return']);
return; // NOTREACHED
}
dbesc($resource_id),
intval($page_owner_uid)
);
- if (dbm::is_result($r)) {
+ if(dbm::is_result($r)) {
$ph = new Photo($r[0]['data'], $r[0]['type']);
- if($ph->is_valid()) {
+ if ($ph->is_valid()) {
$rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
$ph->rotate($rotate_deg);
intval($owner_uid),
dbesc($album)
);
- if (dbm::is_result($r)) {
+ if(dbm::is_result($r)) {
- $a->set_pager_total(dbm::is_result($r));
+ $a->set_pager_total(count($r));
$a->set_pager_itemspage(20);
}
$photos = array();
- if (dbm::is_result($r))
+ if(dbm::is_result($r))
$twist = 'rotright';
- foreach($r as $rr) {
- if($twist == 'rotright')
+ foreach ($r as $rr) {
+ if ($twist == 'rotright')
$twist = 'rotleft';
else
$twist = 'rotright';
// display comments
- if (dbm::is_result($r)) {
+ if(dbm::is_result($r)) {
- foreach($r as $item) {
+ foreach ($r as $item) {
builtin_activity_puller($item, $conv_responses);
}
dbesc('Contact Photos'),
dbesc( t('Contact Photos'))
);
- if (dbm::is_result($r)) {
+ if(dbm::is_result($r)) {
- $a->set_pager_total(dbm::is_result($r));
+ $a->set_pager_total(count($r));
$a->set_pager_itemspage(20);
}
$photos = array();
- if (dbm::is_result($r)) {
+ if(dbm::is_result($r)) {
$twist = 'rotright';
- foreach($r as $rr) {
+ foreach ($r as $rr) {
//hide profile photos to others
- if((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
+ if ((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
continue;
-
- if($twist == 'rotright')
+
+ if ($twist == 'rotright')
$twist = 'rotleft';
else
$twist = 'rotright';