Merge branch '1702-detect-server' of github.com:annando/friendica into 1702-detect-server
This commit is contained in:
commit
88a69b93d5
5 changed files with 341 additions and 255 deletions
|
@ -123,6 +123,8 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
update_contact_birthdays();
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
|
||||
|
||||
set_config('system','last_expire_day',$d2);
|
||||
|
|
|
@ -35,6 +35,7 @@ function discover_poco_run(&$argv, &$argc){
|
|||
- checkcontact: Updates gcontact entries
|
||||
- suggestions: Discover other servers for their contacts.
|
||||
- server <poco url>: Searches for the poco server list. "poco url" is base64 encoded.
|
||||
- update_server: Frequently check the first 250 servers for vitality.
|
||||
*/
|
||||
|
||||
if(($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
|
@ -46,6 +47,8 @@ function discover_poco_run(&$argv, &$argc){
|
|||
$mode = 3;
|
||||
} elseif(($argc == 3) && ($argv[1] == "server")) {
|
||||
$mode = 4;
|
||||
} elseif(($argc == 2) && ($argv[1] == "update_server")) {
|
||||
$mode = 5;
|
||||
} elseif ($argc == 1) {
|
||||
$search = "";
|
||||
$mode = 0;
|
||||
|
@ -64,7 +67,9 @@ function discover_poco_run(&$argv, &$argc){
|
|||
|
||||
logger('start '.$search);
|
||||
|
||||
if ($mode == 4) {
|
||||
if ($mode == 5) {
|
||||
update_server();
|
||||
} elseif ($mode == 4) {
|
||||
$server_url = base64_decode($argv[2]);
|
||||
if ($server_url == "") {
|
||||
return;
|
||||
|
@ -102,6 +107,33 @@ function discover_poco_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the first 250 servers
|
||||
*
|
||||
*/
|
||||
function update_server() {
|
||||
$r = q("SELECT `url`, `created`, `last_failure`, `last_contact` FROM `gserver` ORDER BY rand()");
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$updated = 0;
|
||||
|
||||
foreach ($r AS $server) {
|
||||
if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) {
|
||||
continue;
|
||||
}
|
||||
logger('Update server status for server '.$server["url"], LOGGER_DEBUG);
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server["url"]));
|
||||
|
||||
if (++$updated > 250) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function discover_users() {
|
||||
logger("Discover users", LOGGER_DEBUG);
|
||||
|
||||
|
|
|
@ -72,8 +72,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
|
|||
$a = get_app();
|
||||
|
||||
$ch = @curl_init($url);
|
||||
if(($redirects > 8) || (! $ch))
|
||||
return false;
|
||||
if(($redirects > 8) || (! $ch)) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
|
|
132
mod/admin.php
132
mod/admin.php
|
@ -60,7 +60,9 @@ function admin_post(App $a) {
|
|||
break;
|
||||
case 'themes':
|
||||
if ($a->argc < 2) {
|
||||
if(is_ajax()) return;
|
||||
if (is_ajax()) {
|
||||
return;
|
||||
}
|
||||
goaway('admin/');
|
||||
return;
|
||||
}
|
||||
|
@ -77,7 +79,9 @@ function admin_post(App $a) {
|
|||
|
||||
|
||||
$init = $theme."_init";
|
||||
if(function_exists($init)) $init($a);
|
||||
if (function_exists($init)) {
|
||||
$init($a);
|
||||
}
|
||||
if (function_exists("theme_admin_post")) {
|
||||
$admin_form = theme_admin_post($a);
|
||||
}
|
||||
|
@ -90,8 +94,9 @@ function admin_post(App $a) {
|
|||
__call_theme_admin_post($a, $theme);
|
||||
}
|
||||
info(t('Theme settings updated.'));
|
||||
if(is_ajax()) return;
|
||||
|
||||
if (is_ajax()) {
|
||||
return;
|
||||
}
|
||||
goaway('admin/themes/'.$theme);
|
||||
return;
|
||||
break;
|
||||
|
@ -317,13 +322,15 @@ function admin_page_federation(App $a) {
|
|||
$newVC = $vv['total'];
|
||||
$newVV = $vv['version'];
|
||||
$posDash = strpos($newVV, '-');
|
||||
if($posDash)
|
||||
if ($posDash) {
|
||||
$newVV = substr($newVV, 0, $posDash);
|
||||
if(isset($newV[$newVV]))
|
||||
}
|
||||
if (isset($newV[$newVV])) {
|
||||
$newV[$newVV] += $newVC;
|
||||
else
|
||||
} else {
|
||||
$newV[$newVV] = $newVC;
|
||||
}
|
||||
}
|
||||
foreach ($newV as $key => $value) {
|
||||
array_push($newVv, array('total'=>$value, 'version'=>$key));
|
||||
}
|
||||
|
@ -341,13 +348,15 @@ function admin_page_federation(App $a) {
|
|||
$newVV = $vv['version'];
|
||||
$lastDot = strrpos($newVV,'.');
|
||||
$len = strlen($newVV)-1;
|
||||
if(($lastDot == $len-4) && (!strrpos($newVV,'-rc')==$len-3))
|
||||
if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) {
|
||||
$newVV = substr($newVV, 0, $lastDot);
|
||||
if(isset($newV[$newVV]))
|
||||
}
|
||||
if (isset($newV[$newVV])) {
|
||||
$newV[$newVV] += $newVC;
|
||||
else
|
||||
} else {
|
||||
$newV[$newVV] = $newVC;
|
||||
}
|
||||
}
|
||||
foreach ($newV as $key => $value) {
|
||||
array_push($newVv, array('total'=>$value, 'version'=>$key));
|
||||
}
|
||||
|
@ -455,7 +464,10 @@ function admin_page_summary(App $a) {
|
|||
);
|
||||
|
||||
$users=0;
|
||||
foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
|
||||
foreach ($r as $u) {
|
||||
$accounts[$u['page-flags']][1] = $u['count'];
|
||||
$users+= $u['count'];
|
||||
}
|
||||
|
||||
logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
|
||||
|
||||
|
@ -669,12 +681,12 @@ function admin_page_site_post(App $a) {
|
|||
$worker_fastlane = ((x($_POST,'worker_fastlane')) ? True : False);
|
||||
$worker_frontend = ((x($_POST,'worker_frontend')) ? True : False);
|
||||
|
||||
if($a->get_path() != "")
|
||||
if ($a->get_path() != "") {
|
||||
$diaspora_enabled = false;
|
||||
|
||||
if(!$thread_allow)
|
||||
}
|
||||
if (!$thread_allow) {
|
||||
$ostatus_disabled = true;
|
||||
|
||||
}
|
||||
if ($ssl_policy != intval(get_config('system','ssl_policy'))) {
|
||||
if ($ssl_policy == SSL_POLICY_FULL) {
|
||||
q("UPDATE `contact` SET
|
||||
|
@ -694,8 +706,7 @@ function admin_page_site_post(App $a) {
|
|||
`thumb` = REPLACE(`thumb` , 'http:' , 'https:')
|
||||
WHERE 1 "
|
||||
);
|
||||
}
|
||||
elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
|
||||
} elseif ($ssl_policy == SSL_POLICY_SELFSIGN) {
|
||||
q("UPDATE `contact` SET
|
||||
`url` = REPLACE(`url` , 'https:' , 'http:'),
|
||||
`photo` = REPLACE(`photo` , 'https:' , 'http:'),
|
||||
|
@ -817,7 +828,7 @@ function admin_page_site_post(App $a) {
|
|||
set_config('system','worker_fastlane', $worker_fastlane);
|
||||
set_config('system','frontend_worker', $worker_frontend);
|
||||
|
||||
if($rino==2 and !function_exists('mcrypt_create_iv')) {
|
||||
if (($rino == 2) and !function_exists('mcrypt_create_iv')) {
|
||||
notice(t("RINO2 needs mcrypt php extension to work."));
|
||||
} else {
|
||||
set_config('system','rino_encrypt', $rino);
|
||||
|
@ -922,8 +933,9 @@ function admin_page_site(App $a) {
|
|||
|
||||
/* Banner */
|
||||
$banner = get_config('system','banner');
|
||||
if($banner == false)
|
||||
if ($banner == false) {
|
||||
$banner = '<a href="http://friendica.com"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendica.com">Friendica</a></span>';
|
||||
}
|
||||
$banner = htmlspecialchars($banner);
|
||||
$info = get_config('config','info');
|
||||
$info = htmlspecialchars($info);
|
||||
|
@ -948,9 +960,9 @@ function admin_page_site(App $a) {
|
|||
SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
|
||||
);
|
||||
|
||||
if($a->config['hostname'] == "")
|
||||
if ($a->config['hostname'] == "") {
|
||||
$a->config['hostname'] = $a->get_hostname();
|
||||
|
||||
}
|
||||
$diaspora_able = ($a->get_path() == "");
|
||||
|
||||
$optimize_max_tablesize = Config::get('system','optimize_max_tablesize', 100);
|
||||
|
@ -1091,8 +1103,9 @@ function admin_page_dbsync(App $a) {
|
|||
if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
|
||||
set_config('database', 'update_'.intval($a->argv[3]), 'success');
|
||||
$curr = get_config('system','build');
|
||||
if(intval($curr) == intval($a->argv[3]))
|
||||
if (intval($curr) == intval($a->argv[3])) {
|
||||
set_config('system','build',intval($curr) + 1);
|
||||
}
|
||||
info(t('Update has been marked successful').EOL);
|
||||
goaway('admin/dbsync');
|
||||
}
|
||||
|
@ -1103,12 +1116,14 @@ function admin_page_dbsync(App $a) {
|
|||
if (!$retval) {
|
||||
$o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."<br />";
|
||||
set_config('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success');
|
||||
} else
|
||||
} else {
|
||||
$o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
|
||||
DB_UPDATE_VERSION, $retval)."<br />";
|
||||
if($a->argv[2] === 'check')
|
||||
}
|
||||
if ($a->argv[2] === 'check') {
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
|
||||
if ($a->argc > 2 && intval($a->argv[2])) {
|
||||
require_once('update.php');
|
||||
|
@ -1121,9 +1136,9 @@ function admin_page_dbsync(App $a) {
|
|||
elseif ($retval === UPDATE_SUCCESS) {
|
||||
$o .= sprintf(t('Update %s was successfully applied.', $func));
|
||||
set_config('database',$func, 'success');
|
||||
}
|
||||
else
|
||||
} else {
|
||||
$o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func);
|
||||
}
|
||||
} else {
|
||||
$o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."<br />";
|
||||
set_config('database',$func, 'success');
|
||||
|
@ -1136,8 +1151,9 @@ function admin_page_dbsync(App $a) {
|
|||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
$upd = intval(substr($rr['k'],7));
|
||||
if($upd < 1139 || $rr['v'] === 'success')
|
||||
if ($upd < 1139 || $rr['v'] === 'success') {
|
||||
continue;
|
||||
}
|
||||
$failed[] = $upd;
|
||||
}
|
||||
}
|
||||
|
@ -1282,22 +1298,22 @@ function admin_page_users(App $a) {
|
|||
return ''; // NOTREACHED
|
||||
}
|
||||
switch($a->argv[2]) {
|
||||
case "delete":{
|
||||
case "delete":
|
||||
check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
|
||||
// delete user
|
||||
require_once("include/Contact.php");
|
||||
user_remove($uid);
|
||||
|
||||
notice(sprintf(t("User '%s' deleted"), $user[0]['username']).EOL);
|
||||
}; break;
|
||||
case "block":{
|
||||
break;
|
||||
case "block":
|
||||
check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
|
||||
q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
|
||||
intval(1-$user[0]['blocked']),
|
||||
intval($uid)
|
||||
);
|
||||
notice(sprintf(($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']).EOL);
|
||||
}; break;
|
||||
break;
|
||||
}
|
||||
goaway('admin/users');
|
||||
return ''; // NOTREACHED
|
||||
|
@ -1393,8 +1409,7 @@ function admin_page_users(App $a) {
|
|||
}
|
||||
if ($new_user['deleted']) {
|
||||
array_push($deleted, $new_user);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
array_push($tmp_users, $new_user);
|
||||
}
|
||||
}
|
||||
|
@ -1655,8 +1670,9 @@ function rebuild_theme_table($themes) {
|
|||
if (count($themes)) {
|
||||
foreach ($themes as $th) {
|
||||
if ($th['allowed']) {
|
||||
if(strlen($o))
|
||||
if (strlen($o)) {
|
||||
$o .= ',';
|
||||
}
|
||||
$o .= $th['name'];
|
||||
}
|
||||
}
|
||||
|
@ -1686,10 +1702,13 @@ function admin_page_themes(App $a) {
|
|||
$allowed_themes_str = get_config('system','allowed_themes');
|
||||
$allowed_themes_raw = explode(',',$allowed_themes_str);
|
||||
$allowed_themes = array();
|
||||
if(count($allowed_themes_raw))
|
||||
foreach($allowed_themes_raw as $x)
|
||||
if(strlen(trim($x)))
|
||||
if (count($allowed_themes_raw)) {
|
||||
foreach ($allowed_themes_raw as $x) {
|
||||
if (strlen(trim($x))) {
|
||||
$allowed_themes[] = trim($x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$themes = array();
|
||||
$files = glob('view/theme/*');
|
||||
|
@ -1709,10 +1728,11 @@ function admin_page_themes(App $a) {
|
|||
$is_supported = 1-(intval(file_exists($file.'/unsupported')));
|
||||
$is_allowed = intval(in_array($f,$allowed_themes));
|
||||
|
||||
if($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes"))
|
||||
if ($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes")) {
|
||||
$themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! count($themes)) {
|
||||
notice(t('No themes found.'));
|
||||
|
@ -1740,8 +1760,7 @@ function admin_page_themes(App $a) {
|
|||
if ($result) {
|
||||
install_theme($theme);
|
||||
info(sprintf('Theme %s enabled.',$theme));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uninstall_theme($theme);
|
||||
info(sprintf('Theme %s disabled.',$theme));
|
||||
}
|
||||
|
@ -1780,7 +1799,9 @@ function admin_page_themes(App $a) {
|
|||
|
||||
|
||||
$init = $theme."_init";
|
||||
if(function_exists($init)) $init($a);
|
||||
if (function_exists($init)) {
|
||||
$init($a);
|
||||
}
|
||||
if (function_exists("theme_admin")) {
|
||||
$admin_form = theme_admin($a);
|
||||
}
|
||||
|
@ -1794,9 +1815,9 @@ function admin_page_themes(App $a) {
|
|||
}
|
||||
|
||||
$screenshot = array(get_theme_screenshot($theme), t('Screenshot'));
|
||||
if(! stristr($screenshot[0],$theme))
|
||||
if (! stristr($screenshot[0],$theme)) {
|
||||
$screenshot = null;
|
||||
|
||||
}
|
||||
|
||||
$t = get_markup_template("admin_plugins_details.tpl");
|
||||
return replace_macros($t, array(
|
||||
|
@ -1969,25 +1990,25 @@ function admin_page_viewlogs(App $a) {
|
|||
|
||||
if (!file_exists($f)) {
|
||||
$data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is readable.");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$fp = fopen($f, 'r');
|
||||
if (!$fp) {
|
||||
$data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$fstat = fstat($fp);
|
||||
$size = $fstat['size'];
|
||||
if ($size != 0) {
|
||||
if($size > 5000000 || $size < 0)
|
||||
if ($size > 5000000 || $size < 0) {
|
||||
$size = 5000000;
|
||||
}
|
||||
$seek = fseek($fp,0-$size,SEEK_END);
|
||||
if ($seek === 0) {
|
||||
$data = escape_tags(fread($fp,$size));
|
||||
while(! feof($fp))
|
||||
while (! feof($fp)) {
|
||||
$data .= escape_tags(fread($fp,4096));
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
@ -2019,18 +2040,20 @@ function admin_page_features_post(App $a) {
|
|||
$feature_state = 'feature_'.$feature;
|
||||
$featurelock = 'featurelock_'.$feature;
|
||||
|
||||
if(x($_POST[$feature_state]))
|
||||
if (x($_POST[$feature_state])) {
|
||||
$val = intval($_POST['feature_'.$feature]);
|
||||
else
|
||||
} else {
|
||||
$val = 0;
|
||||
}
|
||||
set_config('feature',$feature,$val);
|
||||
|
||||
if(x($_POST[$featurelock]))
|
||||
if (x($_POST[$featurelock])) {
|
||||
set_config('feature_lock',$feature,$val);
|
||||
else
|
||||
} else {
|
||||
del_config('feature_lock',$feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
goaway('admin/features');
|
||||
return; // NOTREACHED
|
||||
|
@ -2062,8 +2085,9 @@ function admin_page_features(App $a) {
|
|||
foreach (array_slice($fdata,1) as $f) {
|
||||
|
||||
$set = get_config('feature',$f[0]);
|
||||
if($set === false)
|
||||
if ($set === false) {
|
||||
$set = $f[3];
|
||||
}
|
||||
$arr[$fname][1][] = array(
|
||||
array('feature_' .$f[0],$f[1],$set,$f[2],array(t('Off'),t('On'))),
|
||||
array('featurelock_' .$f[0],sprintf(t('Lock feature %s'),$f[1]),(($f[4] !== false) ? "1" : ''),'',array(t('Off'),t('On')))
|
||||
|
|
175
mod/poco.php
175
mod/poco.php
|
@ -7,9 +7,9 @@ function poco_init(App $a) {
|
|||
|
||||
$system_mode = false;
|
||||
|
||||
if(intval(get_config('system','block_public')) || (get_config('system','block_local_dir')))
|
||||
if (intval(get_config('system','block_public')) || (get_config('system','block_local_dir'))) {
|
||||
http_status_exit(401);
|
||||
|
||||
}
|
||||
|
||||
if ($a->argc > 1) {
|
||||
$user = notags(trim($a->argv[1]));
|
||||
|
@ -28,47 +28,54 @@ function poco_init(App $a) {
|
|||
$global = false;
|
||||
|
||||
if ($a->argc > 1 && $a->argv[1] === '@server') {
|
||||
// List of all servers that this server knows
|
||||
$ret = poco_serverlist();
|
||||
header('Content-type: application/json');
|
||||
echo json_encode($ret);
|
||||
killme();
|
||||
}
|
||||
if ($a->argc > 1 && $a->argv[1] === '@global') {
|
||||
// List of all profiles that this server recently had data from
|
||||
$global = true;
|
||||
$update_limit = date("Y-m-d H:i:s", time() - 30 * 86400);
|
||||
}
|
||||
if($a->argc > 2 && $a->argv[2] === '@me')
|
||||
if ($a->argc > 2 && $a->argv[2] === '@me') {
|
||||
$justme = true;
|
||||
if($a->argc > 3 && $a->argv[3] === '@all')
|
||||
}
|
||||
if ($a->argc > 3 && $a->argv[3] === '@all') {
|
||||
$justme = false;
|
||||
if($a->argc > 3 && $a->argv[3] === '@self')
|
||||
}
|
||||
if ($a->argc > 3 && $a->argv[3] === '@self') {
|
||||
$justme = true;
|
||||
if($a->argc > 4 && intval($a->argv[4]) && $justme == false)
|
||||
}
|
||||
if ($a->argc > 4 && intval($a->argv[4]) && $justme == false) {
|
||||
$cid = intval($a->argv[4]);
|
||||
|
||||
}
|
||||
|
||||
if (!$system_mode AND !$global) {
|
||||
$r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
|
||||
where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
|
||||
dbesc($user)
|
||||
);
|
||||
if(! dbm::is_result($r) || $r[0]['hidewall'] || $r[0]['hide-friends'])
|
||||
if (! dbm::is_result($r) || $r[0]['hidewall'] || $r[0]['hide-friends']) {
|
||||
http_status_exit(404);
|
||||
}
|
||||
|
||||
$user = $r[0];
|
||||
}
|
||||
|
||||
if($justme)
|
||||
if ($justme) {
|
||||
$sql_extra = " AND `contact`.`self` = 1 ";
|
||||
}
|
||||
// else
|
||||
// $sql_extra = " AND `contact`.`self` = 0 ";
|
||||
|
||||
if($cid)
|
||||
if ($cid) {
|
||||
$sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid));
|
||||
|
||||
if(x($_GET,'updatedSince'))
|
||||
}
|
||||
if (x($_GET,'updatedSince')) {
|
||||
$update_limit = date("Y-m-d H:i:s",strtotime($_GET['updatedSince']));
|
||||
|
||||
}
|
||||
if ($global) {
|
||||
$r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND NOT `hide` AND `network` IN ('%s', '%s', '%s')",
|
||||
dbesc($update_limit),
|
||||
|
@ -90,14 +97,15 @@ function poco_init(App $a) {
|
|||
dbesc(NETWORK_STATUSNET)
|
||||
);
|
||||
}
|
||||
if (dbm::is_result($r))
|
||||
if (dbm::is_result($r)) {
|
||||
$totalResults = intval($r[0]['total']);
|
||||
else
|
||||
} else {
|
||||
$totalResults = 0;
|
||||
|
||||
}
|
||||
$startIndex = intval($_GET['startIndex']);
|
||||
if(! $startIndex)
|
||||
if (! $startIndex) {
|
||||
$startIndex = 0;
|
||||
}
|
||||
$itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults);
|
||||
|
||||
if ($global) {
|
||||
|
@ -140,13 +148,15 @@ function poco_init(App $a) {
|
|||
logger("Query done", LOGGER_DEBUG);
|
||||
|
||||
$ret = array();
|
||||
if(x($_GET,'sorted'))
|
||||
if (x($_GET,'sorted')) {
|
||||
$ret['sorted'] = false;
|
||||
if(x($_GET,'filtered'))
|
||||
}
|
||||
if (x($_GET,'filtered')) {
|
||||
$ret['filtered'] = false;
|
||||
if(x($_GET,'updatedSince') AND !$global)
|
||||
}
|
||||
if (x($_GET,'updatedSince') AND !$global) {
|
||||
$ret['updatedSince'] = false;
|
||||
|
||||
}
|
||||
$ret['startIndex'] = (int) $startIndex;
|
||||
$ret['itemsPerPage'] = (int) $itemsPerPage;
|
||||
$ret['totalResults'] = (int) $totalResults;
|
||||
|
@ -170,58 +180,61 @@ function poco_init(App $a) {
|
|||
'generation' => false
|
||||
);
|
||||
|
||||
if((! x($_GET,'fields')) || ($_GET['fields'] === '@all'))
|
||||
foreach($fields_ret as $k => $v)
|
||||
if ((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) {
|
||||
foreach ($fields_ret as $k => $v) {
|
||||
$fields_ret[$k] = true;
|
||||
else {
|
||||
}
|
||||
} else {
|
||||
$fields_req = explode(',',$_GET['fields']);
|
||||
foreach($fields_req as $f)
|
||||
foreach ($fields_req as $f) {
|
||||
$fields_ret[trim($f)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($r)) {
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
if (!isset($rr['generation'])) {
|
||||
if ($global)
|
||||
if ($global) {
|
||||
$rr['generation'] = 3;
|
||||
elseif ($system_mode)
|
||||
} elseif ($system_mode) {
|
||||
$rr['generation'] = 1;
|
||||
else
|
||||
} else {
|
||||
$rr['generation'] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (($rr['about'] == "") AND isset($rr['pabout']))
|
||||
if (($rr['about'] == "") AND isset($rr['pabout'])) {
|
||||
$rr['about'] = $rr['pabout'];
|
||||
|
||||
}
|
||||
if ($rr['location'] == "") {
|
||||
if (isset($rr['plocation']))
|
||||
if (isset($rr['plocation'])) {
|
||||
$rr['location'] = $rr['plocation'];
|
||||
|
||||
}
|
||||
if (isset($rr['pregion']) AND ($rr['pregion'] != "")) {
|
||||
if ($rr['location'] != "")
|
||||
if ($rr['location'] != "") {
|
||||
$rr['location'] .= ", ";
|
||||
|
||||
}
|
||||
$rr['location'] .= $rr['pregion'];
|
||||
}
|
||||
|
||||
if (isset($rr['pcountry']) AND ($rr['pcountry'] != "")) {
|
||||
if ($rr['location'] != "")
|
||||
if ($rr['location'] != "") {
|
||||
$rr['location'] .= ", ";
|
||||
|
||||
}
|
||||
$rr['location'] .= $rr['pcountry'];
|
||||
}
|
||||
}
|
||||
|
||||
if (($rr['gender'] == "") AND isset($rr['pgender']))
|
||||
if (($rr['gender'] == "") AND isset($rr['pgender'])) {
|
||||
$rr['gender'] = $rr['pgender'];
|
||||
|
||||
if (($rr['keywords'] == "") AND isset($rr['pub_keywords']))
|
||||
}
|
||||
if (($rr['keywords'] == "") AND isset($rr['pub_keywords'])) {
|
||||
$rr['keywords'] = $rr['pub_keywords'];
|
||||
|
||||
if (isset($rr['account-type']))
|
||||
}
|
||||
if (isset($rr['account-type'])) {
|
||||
$rr['contact-type'] = $rr['account-type'];
|
||||
|
||||
}
|
||||
$about = Cache::get("about:".$rr['updated'].":".$rr['nurl']);
|
||||
if (is_null($about)) {
|
||||
$about = bbcode($rr['about'], false, false);
|
||||
|
@ -236,51 +249,63 @@ function poco_init(App $a) {
|
|||
}
|
||||
|
||||
$entry = array();
|
||||
if($fields_ret['id'])
|
||||
if ($fields_ret['id']) {
|
||||
$entry['id'] = (int)$rr['id'];
|
||||
if($fields_ret['displayName'])
|
||||
}
|
||||
if ($fields_ret['displayName']) {
|
||||
$entry['displayName'] = $rr['name'];
|
||||
if($fields_ret['aboutMe'])
|
||||
}
|
||||
if ($fields_ret['aboutMe']) {
|
||||
$entry['aboutMe'] = $about;
|
||||
if($fields_ret['currentLocation'])
|
||||
}
|
||||
if ($fields_ret['currentLocation']) {
|
||||
$entry['currentLocation'] = $rr['location'];
|
||||
if($fields_ret['gender'])
|
||||
}
|
||||
if ($fields_ret['gender']) {
|
||||
$entry['gender'] = $rr['gender'];
|
||||
if($fields_ret['generation'])
|
||||
}
|
||||
if ($fields_ret['generation']) {
|
||||
$entry['generation'] = (int)$rr['generation'];
|
||||
}
|
||||
if ($fields_ret['urls']) {
|
||||
$entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile'));
|
||||
if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL))
|
||||
if ($rr['addr'] && ($rr['network'] !== NETWORK_MAIL)) {
|
||||
$entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger');
|
||||
}
|
||||
if($fields_ret['preferredUsername'])
|
||||
}
|
||||
if ($fields_ret['preferredUsername']) {
|
||||
$entry['preferredUsername'] = $rr['nick'];
|
||||
}
|
||||
if ($fields_ret['updated']) {
|
||||
if (!$global) {
|
||||
$entry['updated'] = $rr['success_update'];
|
||||
|
||||
if ($rr['name-date'] > $entry['updated'])
|
||||
if ($rr['name-date'] > $entry['updated']) {
|
||||
$entry['updated'] = $rr['name-date'];
|
||||
|
||||
if ($rr['uri-date'] > $entry['updated'])
|
||||
}
|
||||
if ($rr['uri-date'] > $entry['updated']) {
|
||||
$entry['updated'] = $rr['uri-date'];
|
||||
|
||||
if ($rr['avatar-date'] > $entry['updated'])
|
||||
}
|
||||
if ($rr['avatar-date'] > $entry['updated']) {
|
||||
$entry['updated'] = $rr['avatar-date'];
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
$entry['updated'] = $rr['updated'];
|
||||
|
||||
}
|
||||
$entry['updated'] = date("c", strtotime($entry['updated']));
|
||||
}
|
||||
if($fields_ret['photos'])
|
||||
if ($fields_ret['photos']) {
|
||||
$entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile'));
|
||||
}
|
||||
if ($fields_ret['network']) {
|
||||
$entry['network'] = $rr['network'];
|
||||
if ($entry['network'] == NETWORK_STATUSNET)
|
||||
if ($entry['network'] == NETWORK_STATUSNET) {
|
||||
$entry['network'] = NETWORK_OSTATUS;
|
||||
if (($entry['network'] == "") AND ($rr['self']))
|
||||
}
|
||||
if (($entry['network'] == "") AND ($rr['self'])) {
|
||||
$entry['network'] = NETWORK_DFRN;
|
||||
}
|
||||
}
|
||||
if ($fields_ret['tags']) {
|
||||
$tags = str_replace(","," ",$rr['keywords']);
|
||||
$tags = explode(" ", $tags);
|
||||
|
@ -288,9 +313,10 @@ function poco_init(App $a) {
|
|||
$cleaned = array();
|
||||
foreach ($tags as $tag) {
|
||||
$tag = trim(strtolower($tag));
|
||||
if ($tag != "")
|
||||
if ($tag != "") {
|
||||
$cleaned[] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
$entry['tags'] = array($cleaned);
|
||||
}
|
||||
|
@ -301,30 +327,32 @@ function poco_init(App $a) {
|
|||
//if (isset($rr['paddress']))
|
||||
// $entry['address']['streetAddress'] = $rr['paddress'];
|
||||
|
||||
if (isset($rr['plocation']))
|
||||
if (isset($rr['plocation'])) {
|
||||
$entry['address']['locality'] = $rr['plocation'];
|
||||
|
||||
if (isset($rr['pregion']))
|
||||
}
|
||||
if (isset($rr['pregion'])) {
|
||||
$entry['address']['region'] = $rr['pregion'];
|
||||
|
||||
}
|
||||
// See above
|
||||
//if (isset($rr['ppostalcode']))
|
||||
// $entry['address']['postalCode'] = $rr['ppostalcode'];
|
||||
|
||||
if (isset($rr['pcountry']))
|
||||
if (isset($rr['pcountry'])) {
|
||||
$entry['address']['country'] = $rr['pcountry'];
|
||||
}
|
||||
}
|
||||
|
||||
if($fields_ret['contactType'])
|
||||
if ($fields_ret['contactType']) {
|
||||
$entry['contactType'] = intval($rr['contact-type']);
|
||||
|
||||
}
|
||||
$ret['entry'][] = $entry;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
$ret['entry'][] = array();
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
http_status_exit(500);
|
||||
|
||||
}
|
||||
logger("End of poco", LOGGER_DEBUG);
|
||||
|
||||
if ($format === 'xml') {
|
||||
|
@ -336,8 +364,7 @@ function poco_init(App $a) {
|
|||
header('Content-type: application/json');
|
||||
echo json_encode($ret);
|
||||
killme();
|
||||
} else
|
||||
} else {
|
||||
http_status_exit(500);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue