}
-function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
+function permissions_sql($owner_id, $remote_verified = false, $groups = null) {
$local_user = local_user();
$remote_user = remote_user();
*
* default permissions - anonymous user
*/
-
$sql = " AND allow_cid = ''
AND allow_gid = ''
AND deny_cid = ''
if (($local_user) && ($local_user == $owner_id)) {
$sql = '';
- }
-
- /**
- * Authenticated visitor. Unless pre-verified,
- * check that the contact belongs to this $owner_id
- * and load the groups the visitor belongs to.
- * If pre-verified, the caller is expected to have already
- * done this and passed the groups into this function.
- */
-
- elseif ($remote_user) {
+ } elseif ($remote_user) {
+ /*
+ * Authenticated visitor. Unless pre-verified,
+ * check that the contact belongs to this $owner_id
+ * and load the groups the visitor belongs to.
+ * If pre-verified, the caller is expected to have already
+ * done this and passed the groups into this function.
+ */
if (! $remote_verified) {
$r = q("SELECT id FROM contact WHERE id = %d AND uid = %d AND blocked = 0 LIMIT 1",
$gs .= '|<' . intval($g) . '>';
}
- /*$sql = sprintf(
+ /*
+ * @TODO old-lost code found?
+ $sql = sprintf(
" AND ( allow_cid = '' OR allow_cid REGEXP '<%d>' )
AND ( deny_cid = '' OR NOT deny_cid REGEXP '<%d>' )
AND ( allow_gid = '' OR allow_gid REGEXP '%s' )
intval($remote_user),
dbesc($gs),
dbesc($gs)
- );*/
+ );
+ */
$sql = sprintf(
" AND ( NOT (deny_cid REGEXP '<%d>' OR deny_gid REGEXP '%s')
AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = '') )
}
-function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) {
+function item_permissions_sql($owner_id, $remote_verified = false, $groups = null) {
$local_user = local_user();
$remote_user = remote_user();
*
* default permissions - anonymous user
*/
-
$sql = " AND `item`.allow_cid = ''
AND `item`.allow_gid = ''
AND `item`.deny_cid = ''
/**
* Profile owner - everything is visible
*/
-
if ($local_user && ($local_user == $owner_id)) {
$sql = '';
- }
-
- /**
- * Authenticated visitor. Unless pre-verified,
- * check that the contact belongs to this $owner_id
- * and load the groups the visitor belongs to.
- * If pre-verified, the caller is expected to have already
- * done this and passed the groups into this function.
- */
-
- elseif ($remote_user) {
-
+ } elseif ($remote_user) {
+ /*
+ * Authenticated visitor. Unless pre-verified,
+ * check that the contact belongs to this $owner_id
+ * and load the groups the visitor belongs to.
+ * If pre-verified, the caller is expected to have already
+ * done this and passed the groups into this function.
+ */
if (! $remote_verified) {
$r = q("SELECT id FROM contact WHERE id = %d AND uid = %d AND blocked = 0 LIMIT 1",
intval($remote_user),
$gs = '<<>>'; // should be impossible to match
if (is_array($groups) && count($groups)) {
- foreach ($groups as $g)
+ foreach ($groups as $g) {
$gs .= '|<' . intval($g) . '>';
+ }
}
$sql = sprintf(
}
function check_form_security_token($typename = '', $formname = 'form_security_token') {
- if (!x($_REQUEST, $formname)) return false;
+ if (!x($_REQUEST, $formname)) {
+ return false;
+ }
+
+ /// @TODO Careful, not secured!
$hash = $_REQUEST[$formname];
$max_livetime = 10800; // 3 hours
$a = get_app();
$x = explode('.', $hash);
- if (time() > (IntVal($x[0]) + $max_livetime)) return false;
+ if (time() > (IntVal($x[0]) + $max_livetime)) {
+ return false;
+ }
$sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $x[0] . $typename);
}
function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'form_security_token') {
if (!check_form_security_token($typename, $formname)) {
- $a = get_app();
+ $a = get_app();
logger('check_form_security_token failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
logger('check_form_security_token failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
header('HTTP/1.1 403 Forbidden');
$uid = $r[0]['uid'];
}
}
- if (! $uid)
+ if (! $uid) {
return;
+ }
}
- if (! $url)
+ if (! $url) {
return;
+ }
$url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation') ;
logger('poco_load: return code: ' . $a->get_curl_code(), LOGGER_DEBUG);
- if (($a->get_curl_code() > 299) || (! $s))
+ if (($a->get_curl_code() > 299) || (! $s)) {
return;
+ }
$j = json_decode($s);
logger('poco_load: json: ' . print_r($j,true),LOGGER_DATA);
- if (! isset($j->entry))
+ if (! isset($j->entry)) {
return;
+ }
$total = 0;
foreach ($j->entry as $entry) {
}
}
- if (isset($entry->contactType) && ($entry->contactType >= 0))
+ if (isset($entry->contactType) && ($entry->contactType >= 0)) {
$contact_type = $entry->contactType;
+ }
$gcontact = array("url" => $profile_url,
"name" => $name,
dbesc(normalise_link($gcontact['url']))
);
- if (count($x)) {
+ if (dbm::is_result($x)) {
if (!isset($gcontact['network']) && ($x[0]["network"] != NETWORK_STATUSNET)) {
$gcontact['network'] = $x[0]["network"];
}
if ($alternate && ($gcontact['network'] == NETWORK_OSTATUS)) {
// Delete the old entry - if it exists
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($orig_profile)));
- if ($r) {
+ if (dbm::is_result($r)) {
q("DELETE FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($orig_profile)));
q("DELETE FROM `glink` WHERE `gcid` = %d", intval($r[0]["id"]));
}
intval($gcid),
intval($zcid)
);
+
if (!dbm::is_result($r)) {
q("INSERT INTO `glink` (`cid`, `uid`, `gcid`, `zcid`, `updated`) VALUES (%d, %d, %d, %d, '%s') ",
intval($cid),
function poco_do_update($created, $updated, $last_failure, $last_contact) {
$now = strtotime(datetime_convert());
- if ($updated > $last_contact)
+ if ($updated > $last_contact) {
$contact_time = strtotime($updated);
- else
+ } else {
$contact_time = strtotime($last_contact);
+ }
$failure_time = strtotime($last_failure);
$created_time = strtotime($created);
// If there is no "created" time then use the current time
- if ($created_time <= 0)
+ if ($created_time <= 0) {
$created_time = $now;
+ }
// If the last contact was less than 24 hours then don't update
- if (($now - $contact_time) < (60 * 60 * 24))
+ if (($now - $contact_time) < (60 * 60 * 24)) {
return false;
+ }
// If the last failure was less than 24 hours then don't update
- if (($now - $failure_time) < (60 * 60 * 24))
+ if (($now - $failure_time) < (60 * 60 * 24)) {
return false;
+ }
// If the last contact was less than a week ago and the last failure is older than a week then don't update
//if ((($now - $contact_time) < (60 * 60 * 24 * 7)) && ($contact_time > $failure_time))
// return false;
// If the last contact time was more than a week ago and the contact was created more than a week ago, then only try once a week
- if ((($now - $contact_time) > (60 * 60 * 24 * 7)) && (($now - $created_time) > (60 * 60 * 24 * 7)) && (($now - $failure_time) < (60 * 60 * 24 * 7)))
+ if ((($now - $contact_time) > (60 * 60 * 24 * 7)) && (($now - $created_time) > (60 * 60 * 24 * 7)) && (($now - $failure_time) < (60 * 60 * 24 * 7))) {
return false;
+ }
// If the last contact time was more than a month ago and the contact was created more than a month ago, then only try once a month
- if ((($now - $contact_time) > (60 * 60 * 24 * 30)) && (($now - $created_time) > (60 * 60 * 24 * 30)) && (($now - $failure_time) < (60 * 60 * 24 * 30)))
+ if ((($now - $contact_time) > (60 * 60 * 24 * 30)) && (($now - $created_time) > (60 * 60 * 24 * 30)) && (($now - $failure_time) < (60 * 60 * 24 * 30))) {
return false;
+ }
return true;
}
function poco_to_boolean($val) {
- if (($val == "true") || ($val == 1))
- return(true);
- if (($val == "false") || ($val == 0))
- return(false);
+ if (($val == "true") || ($val == 1)) {
+ return true;
+ } elseif (($val == "false") || ($val == 0)) {
+ return false;
+ }
- return ($val);
+ return $val;
}
/**
$attr[$attribute->name] = $attribute->value;
}
}
- if ($attr['property'] == 'generator') {
- if (in_array($attr['content'], array("hubzilla", "BlaBlaNet"))) {
- $server = array();
- $server["platform"] = $attr['content'];
- $server["version"] = "";
- $server["network"] = NETWORK_DIASPORA;
- }
+ if ($attr['property'] == 'generator' && in_array($attr['content'], array("hubzilla", "BlaBlaNet"))) {
+ $server = array();
+ $server["platform"] = $attr['content'];
+ $server["version"] = "";
+ $server["network"] = NETWORK_DIASPORA;
}
}
}
$server_url = trim($server_url, "/");
$server_url = str_replace("/index.php", "", $server_url);
- if ($server_url == "")
+ if ($server_url == "") {
return false;
+ }
$servers = q("SELECT * FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
if (dbm::is_result($servers)) {
$poco = $servers[0]["poco"];
$noscrape = $servers[0]["noscrape"];
- if ($network == "")
+ if ($network == "") {
$network = $servers[0]["network"];
+ }
$last_contact = $servers[0]["last_contact"];
$last_failure = $servers[0]["last_failure"];
if (($last_contact <= $last_failure) && !$failure) {
logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
- } else if (($last_contact >= $last_failure) && $failure) {
+ } elseif (($last_contact >= $last_failure) && $failure) {
logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
}
dbesc(datetime_convert())
);
}
- logger("End discovery for server ".$server_url, LOGGER_DEBUG);
+ logger("End discovery for server " . $server_url, LOGGER_DEBUG);
return !$failure;
}
-function count_common_friends($uid,$cid) {
+function count_common_friends($uid, $cid) {
$r = q("SELECT count(*) as `total`
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
intval($cid)
);
-// logger("count_common_friends: $uid $cid {$r[0]['total']}");
- if (dbm::is_result($r))
+ // logger("count_common_friends: $uid $cid {$r[0]['total']}");
+ if (dbm::is_result($r)) {
return $r[0]['total'];
+ }
return 0;
}
-function common_friends($uid,$cid,$start = 0,$limit=9999,$shuffle = false) {
+function common_friends($uid, $cid, $start = 0, $limit = 9999, $shuffle = false) {
if ($shuffle) {
$sql_extra = " order by rand() ";
}
-function count_common_friends_zcid($uid,$zcid) {
+function count_common_friends_zcid($uid, $zcid) {
$r = q("SELECT count(*) as `total`
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
intval($uid)
);
- if (dbm::is_result($r))
+ if (dbm::is_result($r)) {
return $r[0]['total'];
+ }
return 0;
}
-function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = false) {
+function common_friends_zcid($uid, $zcid, $start = 0, $limit = 9999, $shuffle = false) {
- if ($shuffle)
+ if ($shuffle) {
$sql_extra = " order by rand() ";
- else
+ } else {
$sql_extra = " order by `gcontact`.`name` asc ";
+ }
$r = q("SELECT `gcontact`.*
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
}
-function count_all_friends($uid,$cid) {
+function count_all_friends($uid, $cid) {
$r = q("SELECT count(*) as `total`
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
}
-function all_friends($uid,$cid,$start = 0, $limit = 80) {
+function all_friends($uid, $cid, $start = 0, $limit = 80) {
$r = q("SELECT `gcontact`.*, `contact`.`id` AS `cid`
FROM `glink`
return array();
}
-// Uncommented because the result of the queries are to big to store it in the cache.
-// We need to decide if we want to change the db column type or if we want to delete it.
-// $list = Cache::get("suggestion_query:".$uid.":".$start.":".$limit);
-// if (!is_null($list)) {
-// return $list;
-// }
+ /*
+ * Uncommented because the result of the queries are to big to store it in the cache.
+ * We need to decide if we want to change the db column type or if we want to delete it.
+ */
+ //$list = Cache::get("suggestion_query:".$uid.":".$start.":".$limit);
+ //if (!is_null($list)) {
+ // return $list;
+ //}
$network = array(NETWORK_DFRN);
);
if (dbm::is_result($r) && count($r) >= ($limit -1)) {
-// Uncommented because the result of the queries are to big to store it in the cache.
-// We need to decide if we want to change the db column type or if we want to delete it.
-// Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES);
+ /*
+ * Uncommented because the result of the queries are to big to store it in the cache.
+ * We need to decide if we want to change the db column type or if we want to delete it.
+ */
+ //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES);
return $r;
}
array_pop($list);
}
-// Uncommented because the result of the queries are to big to store it in the cache.
-// We need to decide if we want to change the db column type or if we want to delete it.
-// Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, CACHE_FIVE_MINUTES);
+ /*
+ * Uncommented because the result of the queries are to big to store it in the cache.
+ * We need to decide if we want to change the db column type or if we want to delete it.
+ */
+ //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, CACHE_FIVE_MINUTES);
return $list;
}
$done = array();
/// @TODO Check if it is really neccessary to poll the own server
- poco_load(0,0,0,App::get_baseurl() . '/poco');
+ poco_load(0, 0, 0, App::get_baseurl() . '/poco');
$done[] = App::get_baseurl() . '/poco';
"country-name" => $r[0]["country-name"]));
// The "addr" field was added in 3.4.3 so it can be empty for older users
- if ($r[0]["addr"] != "")
+ if ($r[0]["addr"] != "") {
$addr = $r[0]["nickname"].'@'.str_replace(array("http://", "https://"), "", App::get_baseurl());
- else
+ } else {
$addr = $r[0]["addr"];
+ }
$gcontact = array("name" => $r[0]["name"], "location" => $location, "about" => $r[0]["about"],
"gender" => $r[0]["gender"], "keywords" => $r[0]["pub_keywords"],
$url = $server."/main/statistics";
$result = z_fetch_url($url);
- if (!$result["success"])
+ if (!$result["success"]) {
return false;
+ }
$statistics = json_decode($result["body"]);
if (is_object($statistics->config)) {
- if ($statistics->config->instance_with_ssl)
+ if ($statistics->config->instance_with_ssl) {
$server = "https://";
- else
+ } else {
$server = "http://";
+ }
$server .= $statistics->config->instance_address;
$hostname = $statistics->config->instance_address;
} else {
- if ($statistics->instance_with_ssl)
+ /// @TODO is_object() above means here no object, still $statistics is being used as object
+ if ($statistics->instance_with_ssl) {
$server = "https://";
- else
+ } else {
$server = "http://";
+ }
$server .= $statistics->instance_address;
"photo" => App::get_baseurl()."/images/person-175.jpg");
get_gcontact_id($contact);
}
+ }
}
/**
$r = q("SELECT `nurl`, `url` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `network` = '%s' AND `last_poco_query` < '%s' ORDER BY RAND() LIMIT 5",
dbesc(NETWORK_OSTATUS), dbesc($last_update));
- if (!$r)
+ if (!dbm::is_result($r)) {
return;
+ }
foreach ($r AS $server) {
gs_fetch_users($server["url"]);
if (!dbm::is_result($r)) {
return false;
}
+
return $r;
}