Continued with code convention:

- added more curly braces
- added space betweent if/foreach and brace
- added spaces for beautification
- converted some " to ' (mixed usage)

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-12-22 15:30:23 +01:00
parent 061bcd7d2f
commit 4011f244d6
4 changed files with 111 additions and 96 deletions

View file

@ -85,11 +85,12 @@ function contact_remove($id) {
function terminate_friendship($user,$self,$contact) { function terminate_friendship($user,$self,$contact) {
/// @TODO Get rid of this, include/datetime.php should care about by itself
$a = get_app(); $a = get_app();
require_once('include/datetime.php'); require_once('include/datetime.php');
if($contact['network'] === NETWORK_OSTATUS) { if ($contact['network'] === NETWORK_OSTATUS) {
require_once('include/ostatus.php'); require_once('include/ostatus.php');
@ -99,16 +100,14 @@ function terminate_friendship($user,$self,$contact) {
$item['follow'] = $contact["url"]; $item['follow'] = $contact["url"];
$slap = ostatus::salmon($item, $user); $slap = ostatus::salmon($item, $user);
if((x($contact,'notify')) && (strlen($contact['notify']))) { if ((x($contact,'notify')) && (strlen($contact['notify']))) {
require_once('include/salmon.php'); require_once('include/salmon.php');
slapper($user,$contact['notify'],$slap); slapper($user,$contact['notify'],$slap);
} }
} } elseif ($contact['network'] === NETWORK_DIASPORA) {
elseif($contact['network'] === NETWORK_DIASPORA) {
require_once('include/diaspora.php'); require_once('include/diaspora.php');
Diaspora::send_unshare($user,$contact); Diaspora::send_unshare($user,$contact);
} } elseif ($contact['network'] === NETWORK_DFRN) {
elseif($contact['network'] === NETWORK_DFRN) {
require_once('include/dfrn.php'); require_once('include/dfrn.php');
dfrn::deliver($user,$contact,'placeholder', 1); dfrn::deliver($user,$contact,'placeholder', 1);
} }

View file

@ -65,20 +65,24 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
$exclude = false; $exclude = false;
$size = 4; $size = 4;
if(is_array($options)) { if (is_array($options)) {
if(x($options,'size')) if (x($options,'size'))
$size = $options['size']; $size = $options['size'];
if(x($options,'mutual_friends')) if (x($options,'mutual_friends')) {
$mutual = true; $mutual = true;
if(x($options,'single')) }
if (x($options,'single')) {
$single = true; $single = true;
if(x($options,'multiple')) }
if (x($options,'multiple')) {
$single = false; $single = false;
if(x($options,'exclude')) }
if (x($options,'exclude')) {
$exclude = $options['exclude']; $exclude = $options['exclude'];
}
if(x($options,'networks')) { if (x($options,'networks')) {
switch($options['networks']) { switch($options['networks']) {
case 'DFRN_ONLY': case 'DFRN_ONLY':
$networks = array(NETWORK_DFRN); $networks = array(NETWORK_DFRN);
@ -146,10 +150,11 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
if((is_array($preselected)) && in_array($rr['id'], $preselected)) if ((is_array($preselected)) && in_array($rr['id'], $preselected)) {
$selected = " selected=\"selected\" "; $selected = " selected=\"selected\" ";
else } else {
$selected = ''; $selected = '';
}
$trimmed = mb_substr($rr['name'],0,20); $trimmed = mb_substr($rr['name'],0,20);
@ -231,8 +236,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
if ($privmail) { if ($privmail) {
$trimmed = GetProfileUsername($rr['url'], $rr['name'], false); $trimmed = GetProfileUsername($rr['url'], $rr['name'], false);
} } else {
else {
$trimmed = mb_substr($rr['name'],0,20); $trimmed = mb_substr($rr['name'],0,20);
} }
@ -260,16 +264,22 @@ function fixacl(&$item) {
function prune_deadguys($arr) { function prune_deadguys($arr) {
if(! $arr) if (! $arr) {
return $arr; return $arr;
}
$str = dbesc(implode(',',$arr)); $str = dbesc(implode(',',$arr));
$r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 "); $r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
if ($r) { if ($r) {
$ret = array(); $ret = array();
foreach($r as $rr) foreach ($r as $rr) {
$ret[] = intval($rr['id']); $ret[] = intval($rr['id']);
}
return $ret; return $ret;
} }
return array(); return array();
} }
@ -545,35 +555,33 @@ function acl_lookup(&$a, $out_type = 'json') {
dbesc(NETWORK_ZOT), dbesc(NETWORK_ZOT),
dbesc(NETWORK_DIASPORA) dbesc(NETWORK_DIASPORA)
); );
} } elseif ($type == 'a') {
elseif($type == 'a') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact` $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
WHERE `uid` = %d AND `pending` = 0 WHERE `uid` = %d AND `pending` = 0
$sql_extra2 $sql_extra2
ORDER BY `name` ASC ", ORDER BY `name` ASC ",
intval(local_user()) intval(local_user())
); );
} } elseif ($type == 'x') {
elseif($type == 'x') {
// autocomplete for global contact search (e.g. navbar search) // autocomplete for global contact search (e.g. navbar search)
$r = navbar_complete($a); $r = navbar_complete($a);
$contacts = array(); $contacts = array();
if ($r) { if ($r) {
foreach($r as $g) { foreach ($r as $g) {
$contacts[] = array( $contacts[] = array(
"photo" => proxy_url($g['photo'], false, PROXY_SIZE_MICRO), 'photo' => proxy_url($g['photo'], false, PROXY_SIZE_MICRO),
"name" => $g['name'], 'name' => $g['name'],
"nick" => (x($g['addr']) ? $g['addr'] : $g['url']), 'nick' => (x($g['addr']) ? $g['addr'] : $g['url']),
"network" => $g['network'], 'network' => $g['network'],
"link" => $g['url'], 'link' => $g['url'],
"forum" => (x($g['community']) ? 1 : 0), 'forum' => (x($g['community']) ? 1 : 0),
); );
} }
} }
$o = array( $o = array(
'start' => $start, 'start' => $start,
'count' => $count, 'count' => $count,
'items' => $contacts, 'items' => $contacts,
); );
echo json_encode($o); echo json_encode($o);
killme(); killme();
@ -583,16 +591,16 @@ function acl_lookup(&$a, $out_type = 'json') {
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
foreach($r as $g){ foreach ($r as $g){
$contacts[] = array( $contacts[] = array(
"type" => "c", 'type' => 'c',
"photo" => proxy_url($g['micro'], false, PROXY_SIZE_MICRO), 'photo' => proxy_url($g['micro'], false, PROXY_SIZE_MICRO),
"name" => htmlentities($g['name']), 'name' => htmlentities($g['name']),
"id" => intval($g['id']), 'id' => intval($g['id']),
"network" => $g['network'], 'network' => $g['network'],
"link" => $g['url'], 'link' => $g['url'],
"nick" => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']), 'nick' => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
"forum" => ((x($g['forum']) || x($g['prv'])) ? 1 : 0), 'forum' => ((x($g['forum']) || x($g['prv'])) ? 1 : 0),
); );
} }
} }
@ -618,7 +626,7 @@ function acl_lookup(&$a, $out_type = 'json') {
implode("','", $known_contacts) implode("','", $known_contacts)
); );
if (dbm::is_result($r)){ if (dbm::is_result($r)){
foreach($r as $row) { foreach ($r as $row) {
// nickname.. // nickname..
$up = parse_url($row['author-link']); $up = parse_url($row['author-link']);
$nick = explode("/",$up['path']); $nick = explode("/",$up['path']);
@ -626,14 +634,14 @@ function acl_lookup(&$a, $out_type = 'json') {
$nick .= "@".$up['host']; $nick .= "@".$up['host'];
// /nickname // /nickname
$unknow_contacts[] = array( $unknow_contacts[] = array(
"type" => "c", 'type' => 'c',
"photo" => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO), 'photo' => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO),
"name" => htmlentities($row['author-name']), 'name' => htmlentities($row['author-name']),
"id" => '', 'id' => '',
"network" => "unknown", 'network' => 'unknown',
"link" => $row['author-link'], 'link' => $row['author-link'],
"nick" => htmlentities($nick), 'nick' => htmlentities($nick),
"forum" => false 'forum' => false
); );
} }
} }
@ -643,34 +651,34 @@ function acl_lookup(&$a, $out_type = 'json') {
} }
$results = array( $results = array(
"tot" => $tot, 'tot' => $tot,
"start" => $start, 'start' => $start,
"count" => $count, 'count' => $count,
"groups" => $groups, 'groups' => $groups,
"contacts" => $contacts, 'contacts' => $contacts,
"items" => $items, 'items' => $items,
"type" => $type, 'type' => $type,
"search" => $search, 'search' => $search,
); );
call_hooks('acl_lookup_end', $results); call_hooks('acl_lookup_end', $results);
if($out_type === 'html') { if($out_type === 'html') {
$o = array( $o = array(
'tot' => $results["tot"], 'tot' => $results['tot'],
'start' => $results["start"], 'start' => $results['start'],
'count' => $results["count"], 'count' => $results['count'],
'groups' => $results["groups"], 'groups' => $results['groups'],
'contacts' => $results["contacts"], 'contacts' => $results['contacts'],
); );
return $o; return $o;
} }
$o = array( $o = array(
'tot' => $results["tot"], 'tot' => $results['tot'],
'start' => $results["start"], 'start' => $results['start'],
'count' => $results["count"], 'count' => $results['count'],
'items' => $results["items"], 'items' => $results['items'],
); );
echo json_encode($o); echo json_encode($o);
@ -687,7 +695,7 @@ function navbar_complete(App &$a) {
// logger('navbar_complete'); // logger('navbar_complete');
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
return; return;
} }
@ -698,28 +706,32 @@ function navbar_complete(App &$a) {
$mode = $_REQUEST['smode']; $mode = $_REQUEST['smode'];
// don't search if search term has less than 2 characters // don't search if search term has less than 2 characters
if(! $search || mb_strlen($search) < 2) if (! $search || mb_strlen($search) < 2) {
return array(); return array();
}
if(substr($search,0,1) === '@') if (substr($search,0,1) === '@') {
$search = substr($search,1); $search = substr($search,1);
}
if($localsearch) { if ($localsearch) {
$x = DirSearch::global_search_by_name($search, $mode); $x = DirSearch::global_search_by_name($search, $mode);
return $x; return $x;
} }
if(! $localsearch) { if (! $localsearch) {
$p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
$x = z_fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); $x = z_fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
if($x['success']) { if ($x['success']) {
$t = 0; $t = 0;
$j = json_decode($x['body'],true); $j = json_decode($x['body'],true);
if($j && $j['results']) { if ($j && $j['results']) {
return $j['results']; return $j['results'];
} }
} }
} }
/// @TODO Not needed here?
return; return;
} }

View file

@ -93,19 +93,19 @@ function fbrowser_content(App &$a){
$tpl = get_markup_template($template_file); $tpl = get_markup_template($template_file);
$o = replace_macros($tpl, array( $o = replace_macros($tpl, array(
'$type' => 'image', '$type' => 'image',
'$baseurl' => App::get_baseurl(), '$baseurl' => App::get_baseurl(),
'$path' => $path, '$path' => $path,
'$folders' => $albums, '$folders' => $albums,
'$files' =>$files, '$files' => $files,
'$cancel' => t('Cancel'), '$cancel' => t('Cancel'),
'$nickname' => $a->user['nickname'], '$nickname' => $a->user['nickname'],
)); ));
break; break;
case "file": case "file":
if ($a->argc==2){ if ($a->argc==2) {
$files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ", $files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
intval(local_user()) intval(local_user())
); );
@ -115,10 +115,9 @@ function fbrowser_content(App &$a){
list($m1,$m2) = explode("/",$rr['filetype']); list($m1,$m2) = explode("/",$rr['filetype']);
$filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip"); $filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");
if($a->theme['template_engine'] === 'internal') { if ($a->theme['template_engine'] === 'internal') {
$filename_e = template_escape($rr['filename']); $filename_e = template_escape($rr['filename']);
} } else {
else {
$filename_e = $rr['filename']; $filename_e = $rr['filename'];
} }
@ -129,12 +128,12 @@ function fbrowser_content(App &$a){
$tpl = get_markup_template($template_file); $tpl = get_markup_template($template_file);
$o = replace_macros($tpl, array( $o = replace_macros($tpl, array(
'$type' => 'file', '$type' => 'file',
'$baseurl' => App::get_baseurl(), '$baseurl' => App::get_baseurl(),
'$path' => array( array( "", t("Files")) ), '$path' => array( array( "", t("Files")) ),
'$folders' => false, '$folders' => false,
'$files' =>$files, '$files' =>$files,
'$cancel' => t('Cancel'), '$cancel' => t('Cancel'),
'$nickname' => $a->user['nickname'], '$nickname' => $a->user['nickname'],
)); ));

View file

@ -21,21 +21,24 @@ function ostatus_subscribe_content(App &$a) {
if (get_pconfig($uid, "ostatus", "legacy_friends") == "") { if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
if ($_REQUEST["url"] == "") if ($_REQUEST["url"] == "") {
return $o.t("No contact provided."); return $o.t("No contact provided.");
}
$contact = probe_url($_REQUEST["url"]); $contact = probe_url($_REQUEST["url"]);
if (!$contact) if (!$contact) {
return $o.t("Couldn't fetch information for contact."); return $o.t("Couldn't fetch information for contact.");
}
$api = $contact["baseurl"]."/api/"; $api = $contact["baseurl"]."/api/";
// Fetching friends // Fetching friends
$data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]); $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
if (!$data["success"]) if (!$data["success"]) {
return $o.t("Couldn't fetch friends for contact."); return $o.t("Couldn't fetch friends for contact.");
}
set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]); set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
} }
@ -61,12 +64,14 @@ function ostatus_subscribe_content(App &$a) {
$data = probe_url($url); $data = probe_url($url);
if ($data["network"] == NETWORK_OSTATUS) { if ($data["network"] == NETWORK_OSTATUS) {
$result = new_contact($uid,$url,true); $result = new_contact($uid,$url,true);
if ($result["success"]) if ($result["success"]) {
$o .= " - ".t("success"); $o .= " - ".t("success");
else } else {
$o .= " - ".t("failed"); $o .= " - ".t("failed");
} else }
} else {
$o .= " - ".t("ignored"); $o .= " - ".t("ignored");
}
$o .= "</p>"; $o .= "</p>";