From d82ed5d1b4a3af4d0a4782b809837e3b22d1211d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?=
Date: Thu, 22 Dec 2016 15:30:23 +0100
Subject: [PATCH 1/4] Continued with code convention: - added more curly braces
- added space betweent if/foreach and brace - added spaces for beautification
- converted some " to ' (mixed usage)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Roland Häder
---
include/Contact.php | 11 ++-
include/acl_selectors.php | 148 ++++++++++++++++++++------------------
mod/fbrowser.php | 31 ++++----
mod/ostatus_subscribe.php | 17 +++--
4 files changed, 111 insertions(+), 96 deletions(-)
diff --git a/include/Contact.php b/include/Contact.php
index 5cf40a9f0..b1f63cbdf 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -85,11 +85,12 @@ function contact_remove($id) {
function terminate_friendship($user,$self,$contact) {
+ /// @TODO Get rid of this, include/datetime.php should care about by itself
$a = get_app();
require_once('include/datetime.php');
- if($contact['network'] === NETWORK_OSTATUS) {
+ if ($contact['network'] === NETWORK_OSTATUS) {
require_once('include/ostatus.php');
@@ -99,16 +100,14 @@ function terminate_friendship($user,$self,$contact) {
$item['follow'] = $contact["url"];
$slap = ostatus::salmon($item, $user);
- if((x($contact,'notify')) && (strlen($contact['notify']))) {
+ if ((x($contact,'notify')) && (strlen($contact['notify']))) {
require_once('include/salmon.php');
slapper($user,$contact['notify'],$slap);
}
- }
- elseif($contact['network'] === NETWORK_DIASPORA) {
+ } elseif ($contact['network'] === NETWORK_DIASPORA) {
require_once('include/diaspora.php');
Diaspora::send_unshare($user,$contact);
- }
- elseif($contact['network'] === NETWORK_DFRN) {
+ } elseif ($contact['network'] === NETWORK_DFRN) {
require_once('include/dfrn.php');
dfrn::deliver($user,$contact,'placeholder', 1);
}
diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index dc86ba034..a20775379 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -65,20 +65,24 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
$exclude = false;
$size = 4;
- if(is_array($options)) {
- if(x($options,'size'))
+ if (is_array($options)) {
+ if (x($options,'size'))
$size = $options['size'];
- if(x($options,'mutual_friends'))
+ if (x($options,'mutual_friends')) {
$mutual = true;
- if(x($options,'single'))
+ }
+ if (x($options,'single')) {
$single = true;
- if(x($options,'multiple'))
+ }
+ if (x($options,'multiple')) {
$single = false;
- if(x($options,'exclude'))
+ }
+ if (x($options,'exclude')) {
$exclude = $options['exclude'];
+ }
- if(x($options,'networks')) {
+ if (x($options,'networks')) {
switch($options['networks']) {
case 'DFRN_ONLY':
$networks = array(NETWORK_DFRN);
@@ -146,10 +150,11 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
if (dbm::is_result($r)) {
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\" ";
- else
+ } else {
$selected = '';
+ }
$trimmed = mb_substr($rr['name'],0,20);
@@ -231,8 +236,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
if ($privmail) {
$trimmed = GetProfileUsername($rr['url'], $rr['name'], false);
- }
- else {
+ } else {
$trimmed = mb_substr($rr['name'],0,20);
}
@@ -260,16 +264,22 @@ function fixacl(&$item) {
function prune_deadguys($arr) {
- if(! $arr)
+ if (! $arr) {
return $arr;
+ }
+
$str = dbesc(implode(',',$arr));
+
$r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
+
if ($r) {
$ret = array();
- foreach($r as $rr)
+ foreach ($r as $rr) {
$ret[] = intval($rr['id']);
+ }
return $ret;
}
+
return array();
}
@@ -545,35 +555,33 @@ function acl_lookup(&$a, $out_type = 'json') {
dbesc(NETWORK_ZOT),
dbesc(NETWORK_DIASPORA)
);
- }
- elseif($type == 'a') {
+ } elseif ($type == 'a') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
WHERE `uid` = %d AND `pending` = 0
$sql_extra2
ORDER BY `name` ASC ",
intval(local_user())
);
- }
- elseif($type == 'x') {
+ } elseif ($type == 'x') {
// autocomplete for global contact search (e.g. navbar search)
$r = navbar_complete($a);
$contacts = array();
if ($r) {
- foreach($r as $g) {
+ foreach ($r as $g) {
$contacts[] = array(
- "photo" => proxy_url($g['photo'], false, PROXY_SIZE_MICRO),
- "name" => $g['name'],
- "nick" => (x($g['addr']) ? $g['addr'] : $g['url']),
- "network" => $g['network'],
- "link" => $g['url'],
- "forum" => (x($g['community']) ? 1 : 0),
+ 'photo' => proxy_url($g['photo'], false, PROXY_SIZE_MICRO),
+ 'name' => $g['name'],
+ 'nick' => (x($g['addr']) ? $g['addr'] : $g['url']),
+ 'network' => $g['network'],
+ 'link' => $g['url'],
+ 'forum' => (x($g['community']) ? 1 : 0),
);
}
}
$o = array(
'start' => $start,
- 'count' => $count,
- 'items' => $contacts,
+ 'count' => $count,
+ 'items' => $contacts,
);
echo json_encode($o);
killme();
@@ -583,16 +591,16 @@ function acl_lookup(&$a, $out_type = 'json') {
if (dbm::is_result($r)) {
- foreach($r as $g){
+ foreach ($r as $g){
$contacts[] = array(
- "type" => "c",
- "photo" => proxy_url($g['micro'], false, PROXY_SIZE_MICRO),
- "name" => htmlentities($g['name']),
- "id" => intval($g['id']),
- "network" => $g['network'],
- "link" => $g['url'],
- "nick" => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
- "forum" => ((x($g['forum']) || x($g['prv'])) ? 1 : 0),
+ 'type' => 'c',
+ 'photo' => proxy_url($g['micro'], false, PROXY_SIZE_MICRO),
+ 'name' => htmlentities($g['name']),
+ 'id' => intval($g['id']),
+ 'network' => $g['network'],
+ 'link' => $g['url'],
+ 'nick' => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
+ 'forum' => ((x($g['forum']) || x($g['prv'])) ? 1 : 0),
);
}
}
@@ -618,7 +626,7 @@ function acl_lookup(&$a, $out_type = 'json') {
implode("','", $known_contacts)
);
if (dbm::is_result($r)){
- foreach($r as $row) {
+ foreach ($r as $row) {
// nickname..
$up = parse_url($row['author-link']);
$nick = explode("/",$up['path']);
@@ -626,14 +634,14 @@ function acl_lookup(&$a, $out_type = 'json') {
$nick .= "@".$up['host'];
// /nickname
$unknow_contacts[] = array(
- "type" => "c",
- "photo" => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO),
- "name" => htmlentities($row['author-name']),
- "id" => '',
- "network" => "unknown",
- "link" => $row['author-link'],
- "nick" => htmlentities($nick),
- "forum" => false
+ 'type' => 'c',
+ 'photo' => proxy_url($row['author-avatar'], false, PROXY_SIZE_MICRO),
+ 'name' => htmlentities($row['author-name']),
+ 'id' => '',
+ 'network' => 'unknown',
+ 'link' => $row['author-link'],
+ 'nick' => htmlentities($nick),
+ 'forum' => false
);
}
}
@@ -643,34 +651,34 @@ function acl_lookup(&$a, $out_type = 'json') {
}
$results = array(
- "tot" => $tot,
- "start" => $start,
- "count" => $count,
- "groups" => $groups,
- "contacts" => $contacts,
- "items" => $items,
- "type" => $type,
- "search" => $search,
+ 'tot' => $tot,
+ 'start' => $start,
+ 'count' => $count,
+ 'groups' => $groups,
+ 'contacts' => $contacts,
+ 'items' => $items,
+ 'type' => $type,
+ 'search' => $search,
);
call_hooks('acl_lookup_end', $results);
if($out_type === 'html') {
$o = array(
- 'tot' => $results["tot"],
- 'start' => $results["start"],
- 'count' => $results["count"],
- 'groups' => $results["groups"],
- 'contacts' => $results["contacts"],
+ 'tot' => $results['tot'],
+ 'start' => $results['start'],
+ 'count' => $results['count'],
+ 'groups' => $results['groups'],
+ 'contacts' => $results['contacts'],
);
return $o;
}
$o = array(
- 'tot' => $results["tot"],
- 'start' => $results["start"],
- 'count' => $results["count"],
- 'items' => $results["items"],
+ 'tot' => $results['tot'],
+ 'start' => $results['start'],
+ 'count' => $results['count'],
+ 'items' => $results['items'],
);
echo json_encode($o);
@@ -687,7 +695,7 @@ function navbar_complete(&$a) {
// logger('navbar_complete');
- if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+ if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
return;
}
@@ -698,28 +706,32 @@ function navbar_complete(&$a) {
$mode = $_REQUEST['smode'];
// 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();
+ }
- if(substr($search,0,1) === '@')
+ if (substr($search,0,1) === '@') {
$search = substr($search,1);
+ }
- if($localsearch) {
+ if ($localsearch) {
$x = DirSearch::global_search_by_name($search, $mode);
return $x;
}
- if(! $localsearch) {
+ if (! $localsearch) {
$p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
$x = z_fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
- if($x['success']) {
+ if ($x['success']) {
$t = 0;
$j = json_decode($x['body'],true);
- if($j && $j['results']) {
+ if ($j && $j['results']) {
return $j['results'];
}
}
}
+
+ /// @TODO Not needed here?
return;
}
diff --git a/mod/fbrowser.php b/mod/fbrowser.php
index 6af97368f..9c1d43cd8 100644
--- a/mod/fbrowser.php
+++ b/mod/fbrowser.php
@@ -94,19 +94,19 @@ function fbrowser_content($a){
$tpl = get_markup_template($template_file);
$o = replace_macros($tpl, array(
- '$type' => 'image',
- '$baseurl' => App::get_baseurl(),
- '$path' => $path,
- '$folders' => $albums,
- '$files' =>$files,
- '$cancel' => t('Cancel'),
+ '$type' => 'image',
+ '$baseurl' => App::get_baseurl(),
+ '$path' => $path,
+ '$folders' => $albums,
+ '$files' => $files,
+ '$cancel' => t('Cancel'),
'$nickname' => $a->user['nickname'],
));
break;
case "file":
- if ($a->argc==2){
+ if ($a->argc==2) {
$files = q("SELECT `id`, `filename`, `filetype` FROM `attach` WHERE `uid` = %d ",
intval(local_user())
);
@@ -116,10 +116,9 @@ function fbrowser_content($a){
list($m1,$m2) = explode("/",$rr['filetype']);
$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']);
- }
- else {
+ } else {
$filename_e = $rr['filename'];
}
@@ -130,12 +129,12 @@ function fbrowser_content($a){
$tpl = get_markup_template($template_file);
$o = replace_macros($tpl, array(
- '$type' => 'file',
- '$baseurl' => App::get_baseurl(),
- '$path' => array( array( "", t("Files")) ),
- '$folders' => false,
- '$files' =>$files,
- '$cancel' => t('Cancel'),
+ '$type' => 'file',
+ '$baseurl' => App::get_baseurl(),
+ '$path' => array( array( "", t("Files")) ),
+ '$folders' => false,
+ '$files' =>$files,
+ '$cancel' => t('Cancel'),
'$nickname' => $a->user['nickname'],
));
diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php
index 963f43693..04c8d7bde 100644
--- a/mod/ostatus_subscribe.php
+++ b/mod/ostatus_subscribe.php
@@ -21,21 +21,24 @@ function ostatus_subscribe_content(&$a) {
if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
- if ($_REQUEST["url"] == "")
+ if ($_REQUEST["url"] == "") {
return $o.t("No contact provided.");
+ }
$contact = probe_url($_REQUEST["url"]);
- if (!$contact)
+ if (!$contact) {
return $o.t("Couldn't fetch information for contact.");
+ }
$api = $contact["baseurl"]."/api/";
// Fetching friends
$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.");
+ }
set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
}
@@ -61,12 +64,14 @@ function ostatus_subscribe_content(&$a) {
$data = probe_url($url);
if ($data["network"] == NETWORK_OSTATUS) {
$result = new_contact($uid,$url,true);
- if ($result["success"])
+ if ($result["success"]) {
$o .= " - ".t("success");
- else
+ } else {
$o .= " - ".t("failed");
- } else
+ }
+ } else {
$o .= " - ".t("ignored");
+ }
$o .= "
";
From 2325d81048a4f4eeb90d08da6066cf939e15d3d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?=
Date: Thu, 22 Dec 2016 16:50:40 +0100
Subject: [PATCH 2/4] Code style changed: - added more curly braces - made SQL
keywords all-uppercase - added spaces between if/foreach and brace - // Is
for single-line comments *only*, please don't abuse it for multiple line
comments, use /* */ instead and a asterisk in front of every line.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Roland Häder
---
include/dbstructure.php | 91 ++++++++++++++++++++++++-----------------
1 file changed, 54 insertions(+), 37 deletions(-)
diff --git a/include/dbstructure.php b/include/dbstructure.php
index be1158eab..50c2856ab 100644
--- a/include/dbstructure.php
+++ b/include/dbstructure.php
@@ -26,7 +26,6 @@ function update_fail($update_id, $error_message){
}
// every admin could had different language
-
foreach ($adminlist as $admin) {
$lang = (($admin['language'])?$admin['language']:'en');
push_lang($lang);
@@ -83,8 +82,9 @@ function table_structure($table) {
if (dbm::is_result($indexes))
foreach ($indexes AS $index) {
- if ($index["Index_type"] == "FULLTEXT")
+ if ($index["Index_type"] == "FULLTEXT") {
continue;
+ }
if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
$indexdata[$index["Key_name"]] = array('UNIQUE');
@@ -95,26 +95,31 @@ function table_structure($table) {
// To avoid the need to add this to every index definition we just ignore it here.
// Exception are primary indexes
// Since there are some combindex primary indexes we use the limit of 180 here.
- if (($index["Sub_part"] != "") AND (($index["Sub_part"] < 180) OR ($index["Key_name"] == "PRIMARY")))
+ if (($index["Sub_part"] != "") AND (($index["Sub_part"] < 180) OR ($index["Key_name"] == "PRIMARY"))) {
$column .= "(".$index["Sub_part"].")";
+ }
$indexdata[$index["Key_name"]][] = $column;
}
if (dbm::is_result($structures)) {
- foreach($structures AS $field) {
+ foreach ($structures AS $field) {
$fielddata[$field["Field"]]["type"] = $field["Type"];
- if ($field["Null"] == "NO")
+ if ($field["Null"] == "NO") {
$fielddata[$field["Field"]]["not null"] = true;
+ }
- if (isset($field["Default"]))
+ if (isset($field["Default"])) {
$fielddata[$field["Field"]]["default"] = $field["Default"];
+ }
- if ($field["Extra"] != "")
+ if ($field["Extra"] != "") {
$fielddata[$field["Field"]]["extra"] = $field["Extra"];
+ }
- if ($field["Key"] == "PRI")
+ if ($field["Key"] == "PRI") {
$fielddata[$field["Field"]]["primary"] = true;
+ }
}
}
return(array("fields"=>$fielddata, "indexes"=>$indexdata));
@@ -138,13 +143,15 @@ function print_structure($database, $charset) {
function update_structure($verbose, $action, $tables=null, $definition=null) {
global $a, $db;
- if ($action)
+ if ($action) {
set_config('system', 'maintenance', 1);
+ }
- if (isset($a->config["system"]["db_charset"]))
+ if (isset($a->config["system"]["db_charset"])) {
$charset = $a->config["system"]["db_charset"];
- else
+ } else {
$charset = "utf8";
+ }
$errors = false;
@@ -153,8 +160,9 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
// Get the current structure
$database = array();
- if (is_null($tables))
- $tables = q("show tables");
+ if (is_null($tables)) {
+ $tables = q("SHOW TABLES");
+ }
foreach ($tables AS $table) {
$table = current($table);
@@ -164,21 +172,24 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
}
// Get the definition
- if (is_null($definition))
+ if (is_null($definition)) {
$definition = db_definition($charset);
+ }
// Ensure index conversion to unique removes duplicates
$sql_config = "SET session old_alter_table=1;";
- if ($verbose)
+ if ($verbose) {
echo $sql_config."\n";
- if ($action)
- @$db->q($sql_config);
+ }
+ if ($action) {
+ $db->q($sql_config);
+ }
// MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
!(strpos($db->server_info(), 'MariaDB') !== false)) {
$ignore = '';
- }else {
+ } else {
$ignore = ' IGNORE';
}
@@ -193,10 +204,12 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
}
$is_new_table = True;
} else {
- // Drop the index if it isn't present in the definition
- // or the definition differ from current status
- // and index name doesn't start with "local_"
- foreach ($database[$name]["indexes"] AS $indexname => $fieldnames) {
+ /*
+ * Drop the index if it isn't present in the definition
+ * or the definition differ from current status
+ * and index name doesn't start with "local_"
+ */
+ foreach ($database[$name]["indexes"] as $indexname => $fieldnames) {
$current_index_definition = implode(",",$fieldnames);
if (isset($structure["indexes"][$indexname])) {
$new_index_definition = implode(",",$structure["indexes"][$indexname]);
@@ -205,39 +218,44 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
}
if ($current_index_definition != $new_index_definition && substr($indexname, 0, 6) != 'local_') {
$sql2=db_drop_index($indexname);
- if ($sql3 == "")
+ if ($sql3 == "") {
$sql3 = "ALTER".$ignore." TABLE `".$name."` ".$sql2;
- else
+ } else {
$sql3 .= ", ".$sql2;
+ }
}
}
// Compare the field structure field by field
foreach ($structure["fields"] AS $fieldname => $parameters) {
if (!isset($database[$name]["fields"][$fieldname])) {
$sql2=db_add_table_field($fieldname, $parameters);
- if ($sql3 == "")
+ if ($sql3 == "") {
$sql3 = "ALTER TABLE `".$name."` ".$sql2;
- else
+ } else {
$sql3 .= ", ".$sql2;
+ }
} else {
// Compare the field definition
$current_field_definition = implode(",",$database[$name]["fields"][$fieldname]);
$new_field_definition = implode(",",$parameters);
if ($current_field_definition != $new_field_definition) {
$sql2=db_modify_table_field($fieldname, $parameters);
- if ($sql3 == "")
+ if ($sql3 == "") {
$sql3 = "ALTER TABLE `".$name."` ".$sql2;
- else
+ } else {
$sql3 .= ", ".$sql2;
+ }
}
}
}
}
- // Create the index if the index don't exists in database
- // or the definition differ from the current status.
- // Don't create keys if table is new
+ /*
+ * Create the index if the index don't exists in database
+ * or the definition differ from the current status.
+ * Don't create keys if table is new
+ */
if (!$is_new_table) {
foreach ($structure["indexes"] AS $indexname => $fieldnames) {
if (isset($database[$name]["indexes"][$indexname])) {
@@ -367,10 +385,11 @@ function db_create_index($indexname, $fieldnames, $method="ADD") {
if ($names != "")
$names .= ",";
- if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches))
+ if (preg_match('|(.+)\((\d+)\)|', $fieldname, $matches)) {
$names .= "`".dbesc($matches[1])."`(".intval($matches[2]).")";
- else
+ } else {
$names .= "`".dbesc($fieldname)."`";
+ }
}
if ($indexname == "PRIMARY") {
@@ -383,8 +402,9 @@ function db_create_index($indexname, $fieldnames, $method="ADD") {
}
function db_index_suffix($charset, $reduce = 0) {
- if ($charset != "utf8mb4")
+ if ($charset != "utf8mb4") {
return "";
+ }
// On utf8mb4 indexes can only have a length of 191
$indexlength = 191 - $reduce;
@@ -1573,9 +1593,6 @@ function dbstructure_run(&$argv, &$argc) {
echo "dumpsql dump database schema\n";
return;
-
-
-
}
if (array_search(__file__,get_included_files())===0){
From 9c81b4948eeb22a51b28dbe67896b7e019809544 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?=
Date: Thu, 22 Dec 2016 16:58:50 +0100
Subject: [PATCH 3/4] Coding convention applied: - added curly braces - added
space between if/foreach and brace - avoided 2 return statements (true/false)
by replacing them with just one - added TODO for applying above to all
findings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Roland Häder
---
include/items.php | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/include/items.php b/include/items.php
index e91c7088a..10afc28c0 100644
--- a/include/items.php
+++ b/include/items.php
@@ -1257,8 +1257,9 @@ function tag_deliver($uid,$item_id) {
$c = q("select name, url, thumb from contact where self = 1 and uid = %d limit 1",
intval($u[0]['uid'])
);
- if (! count($c))
+ if (! count($c)) {
return;
+ }
// also reset all the privacy bits to the forum default permissions
@@ -1266,8 +1267,8 @@ function tag_deliver($uid,$item_id) {
$forum_mode = (($prvgroup) ? 2 : 1);
- q("update item set wall = 1, origin = 1, forum_mode = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s',
- `private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' where id = %d",
+ q("UPDATE `item` SET `wall` = 1, `origin` = 1, `forum_mode` = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s',
+ `private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `id` = %d",
intval($forum_mode),
dbesc($c[0]['name']),
dbesc($c[0]['url']),
@@ -1318,7 +1319,7 @@ function tgroup_check($uid,$item) {
$cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER);
if ($cnt) {
- foreach($matches as $mtch) {
+ foreach ($matches as $mtch) {
if (link_compare($link,$mtch[1]) || link_compare($dlink,$mtch[1])) {
$mention = true;
logger('tgroup_check: mention found: ' . $mtch[2]);
@@ -1326,13 +1327,12 @@ function tgroup_check($uid,$item) {
}
}
- if (! $mention)
+ if (! $mention) {
return false;
+ }
- if ((! $community_page) && (! $prvgroup))
- return false;
-
- return true;
+ /// @TODO Combines both return statements into one
+ return (($community_page) || ($prvgroup));
}
/*
@@ -1344,15 +1344,16 @@ function tgroup_check($uid,$item) {
assumes the update has been seen before and should be ignored.
*/
function edited_timestamp_is_newer($existing, $update) {
- if (!x($existing,'edited') || !$existing['edited']) {
- return true;
- }
- if (!x($update,'edited') || !$update['edited']) {
- return false;
- }
- $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']);
- $update_edited = datetime_convert('UTC', 'UTC', $update['edited']);
- return (strcmp($existing_edited, $update_edited) < 0);
+ if (!x($existing,'edited') || !$existing['edited']) {
+ return true;
+ }
+ if (!x($update,'edited') || !$update['edited']) {
+ return false;
+ }
+
+ $existing_edited = datetime_convert('UTC', 'UTC', $existing['edited']);
+ $update_edited = datetime_convert('UTC', 'UTC', $update['edited']);
+ return (strcmp($existing_edited, $update_edited) < 0);
}
/**
From 31cd3fb33c088573a1b240a2b982c781197bab79 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?=
Date: Thu, 22 Dec 2016 17:12:34 +0100
Subject: [PATCH 4/4] Coding convention continued: - added curly braces - added
spaces between if/foreach and brace - made code block look nicer (spaces
added, tabs replaced by space) - added TODO
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Roland Häder
---
mod/common.php | 71 +++++++++++++++++++++++++++-----------------------
1 file changed, 39 insertions(+), 32 deletions(-)
diff --git a/mod/common.php b/mod/common.php
index 0be8f1d14..9657ac36d 100644
--- a/mod/common.php
+++ b/mod/common.php
@@ -19,23 +19,27 @@ function common_content(&$a) {
return;
}
- if($cmd !== 'loc' && $cmd != 'rem')
+ if ($cmd !== 'loc' && $cmd != 'rem') {
return;
+ }
- if(! $uid)
+ if (! $uid) {
return;
+ }
- if($cmd === 'loc' && $cid) {
+ if ($cmd === 'loc' && $cid) {
$c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval($uid)
);
+ /// @TODO Handle $c with dbm::is_result()
$a->page['aside'] = "";
profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"]));
} else {
$c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
intval($uid)
);
+ /// @TODO Handle $c with dbm::is_result()
$vcard_widget .= replace_macros(get_markup_template("vcard-widget.tpl"),array(
'$name' => htmlentities($c[0]['name']),
@@ -43,8 +47,9 @@ function common_content(&$a) {
'url' => 'contacts/' . $cid
));
- if(! x($a->page,'aside'))
+ if (! x($a->page,'aside')) {
$a->page['aside'] = '';
+ }
$a->page['aside'] .= $vcard_widget;
}
@@ -69,29 +74,29 @@ function common_content(&$a) {
}
}
-
-
- if($cid == 0 && $zcid == 0)
+ if ($cid == 0 && $zcid == 0) {
return;
+ }
-
- if($cid)
+ if ($cid) {
$t = count_common_friends($uid, $cid);
- else
+ } else {
$t = count_common_friends_zcid($uid, $zcid);
+ }
- if(count($t))
+ if (count($t)) {
$a->set_pager_total($t);
- else {
+ } else {
notice( t('No contacts in common.') . EOL);
return $o;
}
- if($cid)
+ if ($cid) {
$r = common_friends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
- else
+ } else {
$r = common_friends_zcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
+ }
if (! dbm::is_result($r)) {
@@ -105,39 +110,41 @@ function common_content(&$a) {
//get further details of the contact
$contact_details = get_contact_details_by_url($rr['url'], $uid);
- // $rr[id] is needed to use contact_photo_menu()
- $rr[id] = $rr[cid];
+ // $rr['id'] is needed to use contact_photo_menu()
+ /// @TODO Adding '/" here avoids E_NOTICE on missing constants
+ $rr['id'] = $rr['cid'];
$photo_menu = '';
$photo_menu = contact_photo_menu($rr);
$entry = array(
- 'url' => $rr['url'],
- 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
- 'name' => $contact_details['name'],
- 'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
- 'img_hover' => htmlentities($contact_details['name']),
- 'details' => $contact_details['location'],
- 'tags' => $contact_details['keywords'],
- 'about' => $contact_details['about'],
- 'account_type' => account_type($contact_details),
- 'network' => network_to_name($contact_details['network'], $contact_details['url']),
- 'photo_menu' => $photo_menu,
- 'id' => ++$id,
+ 'url' => $rr['url'],
+ 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
+ 'name' => $contact_details['name'],
+ 'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
+ 'img_hover' => htmlentities($contact_details['name']),
+ 'details' => $contact_details['location'],
+ 'tags' => $contact_details['keywords'],
+ 'about' => $contact_details['about'],
+ 'account_type' => account_type($contact_details),
+ 'network' => network_to_name($contact_details['network'], $contact_details['url']),
+ 'photo_menu' => $photo_menu,
+ 'id' => ++$id,
);
$entries[] = $entry;
}
- if($cmd === 'loc' && $cid && $uid == local_user()) {
+ if ($cmd === 'loc' && $cid && $uid == local_user()) {
$tab_str = contacts_tab($a, $cid, 4);
- } else
+ } else {
$title = t('Common Friends');
+ }
$tpl = get_markup_template('viewcontact_template.tpl');
$o .= replace_macros($tpl,array(
- '$title' => $title,
- '$tab_str' => $tab_str,
+ '$title' => $title,
+ '$tab_str' => $tab_str,
'$contacts' => $entries,
'$paginate' => paginate($a),
));