From: Roland Häder Date: Tue, 13 Dec 2016 10:00:44 +0000 (+0100) Subject: Merge branch 'rewrites/dbm_is_result' of github.com:Quix0r/friendica into rewrites... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=63610c7b73fcaf862adbf880d4968dd2b1678d9b;p=friendica.git Merge branch 'rewrites/dbm_is_result' of github.com:Quix0r/friendica into rewrites/dbm_is_result Signed-off-by: Roland Häder Conflicts: include/Photo.php include/api.php include/cache.php include/dbstructure.php include/enotify.php include/items.php include/onepoll.php include/queue_fn.php include/session.php include/text.php mod/contacts.php mod/dfrn_request.php mod/display.php mod/events.php mod/item.php mod/message.php mod/msearch.php mod/photos.php mod/poco.php mod/profile.php mod/proxy.php mod/videos.php update.php view/theme/diabook/theme.php view/theme/vier/theme.php --- 63610c7b73fcaf862adbf880d4968dd2b1678d9b diff --cc include/api.php index 24120018bd,521354edc1..f627955cf4 --- a/include/api.php +++ b/include/api.php @@@ -3943,72 -3879,6 +3943,71 @@@ } 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 diff --cc include/dbstructure.php index 94e8da4a44,0da209a366..cd80a0865d --- a/include/dbstructure.php +++ b/include/dbstructure.php @@@ -178,8 -157,8 +187,8 @@@ function update_structure($verbose, $ac $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; diff --cc include/queue_fn.php index 241b0bb364,a253aa2fb2..df9ab6b4cb --- a/include/queue_fn.php +++ b/include/queue_fn.php @@@ -15,20 -15,16 +15,25 @@@ function remove_queue_item($id) ); } +/** + * @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) ); diff --cc include/session.php index 31024060f3,fe8e0848ef..8aca6cb53d --- a/include/session.php +++ b/include/session.php @@@ -7,30 -6,18 +7,30 @@@ require_once('include/cache.php') $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 { diff --cc mod/dfrn_request.php index 66c891ef08,9b7dede2e2..8bca431dd2 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@@ -370,8 -368,7 +370,8 @@@ function dfrn_request_post(&$a) $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; } diff --cc mod/display.php index 293156cf19,cf7700a145..8d1a44e4be --- a/mod/display.php +++ b/mod/display.php @@@ -316,16 -316,16 +316,16 @@@ function display_content(&$a, $update } } - $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; } diff --cc mod/events.php index 4a201f43e4,e579d3530d..a5380c8369 --- a/mod/events.php +++ b/mod/events.php @@@ -344,9 -344,9 +344,10 @@@ function events_content(&$a) $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(); diff --cc mod/msearch.php index 1370b63bf2,fd46cc1e1b..8fae1177fe --- a/mod/msearch.php +++ b/mod/msearch.php @@@ -22,7 -25,6 +25,8 @@@ function msearch_post(&$a) intval($perpage) ); + $results = array(); ++ if(dbm::is_result($r)) { foreach($r as $rr) $results[] = array( diff --cc mod/photos.php index a4d5544ef2,328be50b27..e93fb261b8 --- a/mod/photos.php +++ b/mod/photos.php @@@ -254,11 -268,12 +254,11 @@@ function photos_post(&$a) 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 } @@@ -393,9 -409,9 +393,9 @@@ 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); @@@ -1188,8 -1210,8 +1188,8 @@@ function photos_content(&$a) 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); } @@@ -1243,10 -1267,10 +1243,10 @@@ $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'; @@@ -1611,9 -1638,9 +1611,9 @@@ // 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); } @@@ -1794,8 -1824,8 +1794,8 @@@ 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); } @@@ -1812,14 -1842,14 +1812,14 @@@ $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';