From c9194b038145a5f4efa272052ad194e679c29611 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 01/19] 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 28a692541..c86d6e7f8 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 b2e66c98f..4c0b610d4 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(App &$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(App &$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 8c54a47ba..9c8d2169b 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -93,19 +93,19 @@ function fbrowser_content(App &$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()) ); @@ -115,10 +115,9 @@ function fbrowser_content(App &$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']; } @@ -129,12 +128,12 @@ function fbrowser_content(App &$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 ba17e28b7..b2f536e6d 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -21,21 +21,24 @@ function ostatus_subscribe_content(App &$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(App &$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 30642756e5a5fa30941e6e23e09b90d8092aef8c 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 02/19] 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 8db0be09b844a49e096110fb856cf847d6bff9a2 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 03/19] 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 c75bc768c..327096341 100644 --- a/include/items.php +++ b/include/items.php @@ -1260,8 +1260,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 @@ -1269,8 +1270,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']), @@ -1322,7 +1323,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]); @@ -1330,13 +1331,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)); } /* @@ -1348,15 +1348,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 5547bc2cc254d27c78bcdd15123a024b52e0a99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 17:03:00 +0100 Subject: [PATCH 04/19] Continued rewriting a bit: - more usage of dbm::is_result() - nicer look of code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/items.php | 4 +--- mod/allfriends.php | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/items.php b/include/items.php index 327096341..8d95c3552 100644 --- a/include/items.php +++ b/include/items.php @@ -1260,7 +1260,7 @@ 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 (! dbm::is_result($c)) { return; } @@ -1293,8 +1293,6 @@ function tag_deliver($uid,$item_id) { function tgroup_check($uid,$item) { - $a = get_app(); - $mention = false; // check that the message originated elsewhere and is a top-level post diff --git a/mod/allfriends.php b/mod/allfriends.php index 9e14a67d2..7a134a7be 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -28,7 +28,7 @@ function allfriends_content(App &$a) { intval(local_user()) ); - if (! count($c)) { + if (! dbm::is_result($c)) { return; } @@ -71,20 +71,20 @@ function allfriends_content(App &$a) { } $entry = array( - 'url' => $rr['url'], - 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), - 'name' => htmlentities($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, - 'conntxt' => t('Connect'), - 'connlnk' => $connlnk, - 'id' => ++$id, + 'url' => $rr['url'], + 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']), + 'name' => htmlentities($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, + 'conntxt' => t('Connect'), + 'connlnk' => $connlnk, + 'id' => ++$id, ); $entries[] = $entry; } From 13b57d4d5091531284ece6a39fc74a0a2642efb1 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 05/19] 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 ab27dc667..26ef7e48b 100644 --- a/mod/common.php +++ b/mod/common.php @@ -19,23 +19,27 @@ function common_content(App &$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(App &$a) { 'url' => 'contacts/' . $cid )); - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) { $a->page['aside'] = ''; + } $a->page['aside'] .= $vcard_widget; } @@ -70,29 +75,29 @@ function common_content(App &$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)) { @@ -106,39 +111,41 @@ function common_content(App &$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), )); From 97c507e76392cb9aac982ddd494961bab62d81cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 10:10:33 +0100 Subject: [PATCH 06/19] Coding convention applied: - space between "if" and brace - curly braces on conditional blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/like.php | 3 ++- mod/subthread.php | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/like.php b/include/like.php index 893047da3..210bde690 100644 --- a/include/like.php +++ b/include/like.php @@ -112,8 +112,9 @@ function do_like($item_id, $verb) { intval($_SESSION['visitor_id']), intval($owner_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $contact = $r[0]; + } } if (! $contact) { return false; diff --git a/mod/subthread.php b/mod/subthread.php index a00196825..c689f7f6c 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -71,8 +71,7 @@ function subthread_content(App &$a) { if ((local_user()) && (local_user() == $owner_uid)) { $contact = $owner; - } - else { + } else { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($_SESSION['visitor_id']), intval($owner_uid) From f8a213e23be1c43a00dea6079f78100f6df99d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 19 Dec 2016 14:26:13 +0100 Subject: [PATCH 07/19] *much* more usage of App::get_baseurl() instead of $a->get_baseurl() (coding convention applied) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/Contact.php | 2 +- include/contact_widgets.php | 10 ++-- include/follow.php | 61 +++++++++---------- include/identity.php | 94 +++++++++++++++++++++--------- include/network.php | 53 +++++++++-------- include/plugin.php | 43 +++++++------- include/socgraph.php | 3 +- mod/admin.php | 8 +-- mod/delegate.php | 4 +- mod/dfrn_request.php | 23 ++++---- mod/events.php | 2 +- mod/group.php | 5 +- mod/hcard.php | 1 - mod/invite.php | 2 +- mod/item.php | 13 +++-- mod/profile.php | 63 +++++++++----------- mod/profile_photo.php | 15 ++--- mod/videos.php | 4 +- view/theme/duepuntozero/config.php | 16 ++--- 19 files changed, 226 insertions(+), 196 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index c86d6e7f8..5d8ccc452 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -85,7 +85,7 @@ function contact_remove($id) { function terminate_friendship($user,$self,$contact) { - /// @TODO Get rid of this, include/datetime.php should care about by itself + /// @TODO Get rid of this, include/datetime.php should care about it by itself $a = get_app(); require_once('include/datetime.php'); diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 36675da87..fee569e94 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -135,8 +135,8 @@ function fileas_widget($baseurl,$selected = '') { $matches = false; $terms = array(); - $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER); - if($cnt) { + $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER); + if ($cnt) { foreach($matches as $mtch) { $unescaped = xmlify(file_tag_decode($mtch[1])); $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : '')); @@ -158,12 +158,14 @@ function categories_widget($baseurl,$selected = '') { $a = get_app(); - if(! feature_enabled($a->profile['profile_uid'],'categories')) + if (! feature_enabled($a->profile['profile_uid'],'categories')) { return ''; + } $saved = get_pconfig($a->profile['profile_uid'],'system','filetags'); - if(! strlen($saved)) + if (! strlen($saved)) { return; + } $matches = false; $terms = array(); diff --git a/include/follow.php b/include/follow.php index e7693822a..8d80538e0 100644 --- a/include/follow.php +++ b/include/follow.php @@ -102,8 +102,7 @@ function new_contact($uid,$url,$interactive = false) { if ($interactive) { if (strlen($a->path)) { $myaddr = bin2hex(App::get_baseurl() . '/profile/' . $a->user['nickname']); - } - else { + } else { $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); } @@ -111,53 +110,45 @@ function new_contact($uid,$url,$interactive = false) { // NOTREACHED } - } - else { - if(get_config('system','dfrn_only')) { + } else { + if (get_config('system','dfrn_only')) { $result['message'] = t('This site is not configured to allow communications with other networks.') . EOL; $result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL; return $result; } } - - - - - // This extra param just confuses things, remove it - if($ret['network'] === NETWORK_DIASPORA) + if ($ret['network'] === NETWORK_DIASPORA) { $ret['url'] = str_replace('?absolute=true','',$ret['url']); - + } // do we have enough information? - if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) { + if (! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) { $result['message'] .= t('The profile address specified does not provide adequate information.') . EOL; - if(! x($ret,'poll')) + if (! x($ret,'poll')) { $result['message'] .= t('No compatible communication protocols or feeds were discovered.') . EOL; - if(! x($ret,'name')) + } + if (! x($ret,'name')) { $result['message'] .= t('An author or name was not found.') . EOL; - if(! x($ret,'url')) + } + if (! x($ret,'url')) { $result['message'] .= t('No browser URL could be matched to this address.') . EOL; - if(strpos($url,'@') !== false) { + } + if (strpos($url,'@') !== false) { $result['message'] .= t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL; $result['message'] .= t('Use mailto: in front of address to force email check.') . EOL; } return $result; } - if($ret['network'] === NETWORK_OSTATUS && get_config('system','ostatus_disabled')) { + if ($ret['network'] === NETWORK_OSTATUS && get_config('system','ostatus_disabled')) { $result['message'] .= t('The profile address specified belongs to a network which has been disabled on this site.') . EOL; $ret['notify'] = ''; } - - - - - - if(! $ret['notify']) { + if (! $ret['notify']) { $result['message'] .= t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL; } @@ -167,8 +158,9 @@ function new_contact($uid,$url,$interactive = false) { $hidden = (($ret['network'] === NETWORK_MAIL) ? 1 : 0); - if(in_array($ret['network'], array(NETWORK_MAIL, NETWORK_DIASPORA))) + if (in_array($ret['network'], array(NETWORK_MAIL, NETWORK_DIASPORA))) { $writeable = 1; + } // check if we already have a contact // the poll url is more reliable than the profile url, as we may have @@ -188,7 +180,7 @@ function new_contact($uid,$url,$interactive = false) { if (dbm::is_result($r)) { // update contact - if($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) { + if ($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) { q("UPDATE `contact` SET `rel` = %d , `subhub` = %d, `readonly` = 0 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($subhub), @@ -197,29 +189,28 @@ function new_contact($uid,$url,$interactive = false) { ); } } else { - - // check service class limits - $r = q("select count(*) as total from contact where uid = %d and pending = 0 and self = 0", + $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `pending` = 0 AND `self` = 0", intval($uid) ); if (dbm::is_result($r)) $total_contacts = $r[0]['total']; - if(! service_class_allows($uid,'total_contacts',$total_contacts)) { + if (! service_class_allows($uid,'total_contacts',$total_contacts)) { $result['message'] .= upgrade_message(); return $result; } - $r = q("select count(network) as total from contact where uid = %d and network = '%s' and pending = 0 and self = 0", + $r = q("SELECT COUNT(`network`) AS `total` FROM `contact` WHERE `uid` = %d AND `network` = '%s' AND `pending` = 0 AND `self` = 0", intval($uid), dbesc($network) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $total_network = $r[0]['total']; + } - if(! service_class_allows($uid,'total_contacts_' . $network,$total_network)) { + if (! service_class_allows($uid,'total_contacts_' . $network,$total_network)) { $result['message'] .= upgrade_message(); return $result; } @@ -268,8 +259,9 @@ function new_contact($uid,$url,$interactive = false) { $result['cid'] = $contact_id; $def_gid = get_default_group($uid, $contact["network"]); - if (intval($def_gid)) + if (intval($def_gid)) { group_add_member($uid, '', $contact_id, $def_gid); + } // Update the avatar update_contact_avatar($ret['photo'],$uid,$contact_id); @@ -285,7 +277,6 @@ function new_contact($uid,$url,$interactive = false) { if (dbm::is_result($r)) { if (($contact['network'] == NETWORK_OSTATUS) && (strlen($contact['notify']))) { - // create a follow slap $item = array(); $item['verb'] = ACTIVITY_FOLLOW; diff --git a/include/identity.php b/include/identity.php index 35516efbe..a302dc34c 100644 --- a/include/identity.php +++ b/include/identity.php @@ -231,8 +231,7 @@ function profile_sidebar($profile, $block = 0) { if ($connect AND local_user()) { if (isset($profile["url"])) { $profile_url = normalise_link($profile["url"]); - } - else { + } else { $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]); } @@ -638,50 +637,87 @@ function advanced_profile(App &$a) { if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']); - - if($a->profile['with']) $profile['marital']['with'] = $a->profile['with']; - - if(strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') { - $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s')); + /// @TODO Maybe use x() here, plus below? + if ($a->profile['with']) { + $profile['marital']['with'] = $a->profile['with']; } - if($a->profile['sexual']) $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] ); + if (strlen($a->profile['howlong']) && $a->profile['howlong'] !== '0000-00-00 00:00:00') { + $profile['howlong'] = relative_date($a->profile['howlong'], t('for %1$d %2$s')); + } - if($a->profile['homepage']) $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) ); + if ($a->profile['sexual']) { + $profile['sexual'] = array( t('Sexual Preference:'), $a->profile['sexual'] ); + } - if($a->profile['hometown']) $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) ); + if ($a->profile['homepage']) { + $profile['homepage'] = array( t('Homepage:'), linkify($a->profile['homepage']) ); + } - if($a->profile['pub_keywords']) $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']); + if ($a->profile['hometown']) { + $profile['hometown'] = array( t('Hometown:'), linkify($a->profile['hometown']) ); + } - if($a->profile['politic']) $profile['politic'] = array( t('Political Views:'), $a->profile['politic']); + if ($a->profile['pub_keywords']) { + $profile['pub_keywords'] = array( t('Tags:'), $a->profile['pub_keywords']); + } - if($a->profile['religion']) $profile['religion'] = array( t('Religion:'), $a->profile['religion']); + if ($a->profile['politic']) { + $profile['politic'] = array( t('Political Views:'), $a->profile['politic']); + } - if($txt = prepare_text($a->profile['about'])) $profile['about'] = array( t('About:'), $txt ); + if ($a->profile['religion']) { + $profile['religion'] = array( t('Religion:'), $a->profile['religion']); + } - if($txt = prepare_text($a->profile['interest'])) $profile['interest'] = array( t('Hobbies/Interests:'), $txt); + if ($txt = prepare_text($a->profile['about'])) { + $profile['about'] = array( t('About:'), $txt ); + } - if($txt = prepare_text($a->profile['likes'])) $profile['likes'] = array( t('Likes:'), $txt); + if ($txt = prepare_text($a->profile['interest'])) { + $profile['interest'] = array( t('Hobbies/Interests:'), $txt); + } - if($txt = prepare_text($a->profile['dislikes'])) $profile['dislikes'] = array( t('Dislikes:'), $txt); + if ($txt = prepare_text($a->profile['likes'])) { + $profile['likes'] = array( t('Likes:'), $txt); + } + if ($txt = prepare_text($a->profile['dislikes'])) { + $profile['dislikes'] = array( t('Dislikes:'), $txt); + } - if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt); + if ($txt = prepare_text($a->profile['contact'])) { + $profile['contact'] = array( t('Contact information and Social Networks:'), $txt); + } - if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt); + if ($txt = prepare_text($a->profile['music'])) { + $profile['music'] = array( t('Musical interests:'), $txt); + } - if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt); + if ($txt = prepare_text($a->profile['book'])) { + $profile['book'] = array( t('Books, literature:'), $txt); + } - if($txt = prepare_text($a->profile['tv'])) $profile['tv'] = array( t('Television:'), $txt); + if ($txt = prepare_text($a->profile['tv'])) { + $profile['tv'] = array( t('Television:'), $txt); + } - if($txt = prepare_text($a->profile['film'])) $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt); + if ($txt = prepare_text($a->profile['film'])) { + $profile['film'] = array( t('Film/dance/culture/entertainment:'), $txt); + } - if($txt = prepare_text($a->profile['romance'])) $profile['romance'] = array( t('Love/Romance:'), $txt); + if ($txt = prepare_text($a->profile['romance'])) { + $profile['romance'] = array( t('Love/Romance:'), $txt); + } - if($txt = prepare_text($a->profile['work'])) $profile['work'] = array( t('Work/employment:'), $txt); + if ($txt = prepare_text($a->profile['work'])) { + $profile['work'] = array( t('Work/employment:'), $txt); + } + + if ($txt = prepare_text($a->profile['education'])) { + $profile['education'] = array( t('School/education:'), $txt ); + } - if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt ); - //show subcribed forum if it is enabled in the usersettings if (feature_enabled($uid,'forumlist_profile')) { $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid)); @@ -705,11 +741,13 @@ function advanced_profile(App &$a) { function profile_tabs($a, $is_owner=False, $nickname=Null){ //echo "
"; var_dump($a->user); killme();
 
-	if (is_null($nickname))
+	if (is_null($nickname)) {
 		$nickname  = $a->user['nickname'];
+	}
 
-	if(x($_GET,'tab'))
+	if (x($_GET,'tab')) {
 		$tab = notags(trim($_GET['tab']));
+	}
 
 	$url = App::get_baseurl() . '/profile/' . $nickname;
 
diff --git a/include/network.php b/include/network.php
index 7a662e4cb..969f58382 100644
--- a/include/network.php
+++ b/include/network.php
@@ -541,10 +541,11 @@ function parse_xml_string($s,$strict = true) {
 	libxml_use_internal_errors(true);
 
 	$x = @simplexml_load_string($s2);
-	if(! $x) {
+	if (! $x) {
 		logger('libxml: parse: error: ' . $s2, LOGGER_DATA);
-		foreach(libxml_get_errors() as $err)
+		foreach (libxml_get_errors() as $err) {
 			logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
+		}
 		libxml_clear_errors();
 	}
 	return $x;
@@ -553,8 +554,9 @@ function parse_xml_string($s,$strict = true) {
 function scale_external_images($srctext, $include_link = true, $scale_replace = false) {
 
 	// Suppress "view full size"
-	if (intval(get_config('system','no_view_full_size')))
+	if (intval(get_config('system','no_view_full_size'))) {
 		$include_link = false;
+	}
 
 	$a = get_app();
 
@@ -563,38 +565,41 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
 
 	$matches = null;
 	$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
-	if($c) {
+	if ($c) {
 		require_once('include/Photo.php');
-		foreach($matches as $mtch) {
+		foreach ($matches as $mtch) {
 			logger('scale_external_image: ' . $mtch[1]);
 
 			$hostname = str_replace('www.','',substr(App::get_baseurl(),strpos(App::get_baseurl(),'://')+3));
-			if(stristr($mtch[1],$hostname))
+			if (stristr($mtch[1],$hostname)) {
 				continue;
+			}
 
 			// $scale_replace, if passed, is an array of two elements. The
 			// first is the name of the full-size image. The second is the
 			// name of a remote, scaled-down version of the full size image.
 			// This allows Friendica to display the smaller remote image if
 			// one exists, while still linking to the full-size image
-			if($scale_replace)
+			if ($scale_replace) {
 				$scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]);
-			else
+			} else {
 				$scaled = $mtch[1];
-			$i = @fetch_url($scaled);
-			if(! $i)
+			}
+			$i = fetch_url($scaled);
+			if (! $i) {
 				return $srctext;
+			}
 
 			// guess mimetype from headers or filename
 			$type = guess_image_type($mtch[1],true);
 
-			if($i) {
+			if ($i) {
 				$ph = new Photo($i, $type);
-				if($ph->is_valid()) {
+				if ($ph->is_valid()) {
 					$orig_width = $ph->getWidth();
 					$orig_height = $ph->getHeight();
 
-					if($orig_width > 640 || $orig_height > 640) {
+					if ($orig_width > 640 || $orig_height > 640) {
 
 						$ph->scaleImage(640);
 						$new_width = $ph->getWidth();
@@ -620,7 +625,7 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
 function fix_contact_ssl_policy(&$contact,$new_policy) {
 
 	$ssl_changed = false;
-	if((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'],'https:')) {
+	if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'],'https:')) {
 		$ssl_changed = true;
 		$contact['url']     = 	str_replace('https:','http:',$contact['url']);
 		$contact['request'] = 	str_replace('https:','http:',$contact['request']);
@@ -630,7 +635,7 @@ function fix_contact_ssl_policy(&$contact,$new_policy) {
 		$contact['poco']    = 	str_replace('https:','http:',$contact['poco']);
 	}
 
-	if((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'],'http:')) {
+	if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'],'http:')) {
 		$ssl_changed = true;
 		$contact['url']     = 	str_replace('http:','https:',$contact['url']);
 		$contact['request'] = 	str_replace('http:','https:',$contact['request']);
@@ -640,15 +645,15 @@ function fix_contact_ssl_policy(&$contact,$new_policy) {
 		$contact['poco']    = 	str_replace('http:','https:',$contact['poco']);
 	}
 
-	if($ssl_changed) {
-		q("update contact set
-			url = '%s',
-			request = '%s',
-			notify = '%s',
-			poll = '%s',
-			confirm = '%s',
-			poco = '%s'
-			where id = %d limit 1",
+	if ($ssl_changed) {
+		q("UPDATE `contact` SET
+			`url` = '%s',
+			`request` = '%s',
+			`notify` = '%s',
+			`poll` = '%s',
+			`confirm` = '%s',
+			`poco` = '%s'
+			WHERE `id` = %d LIMIT 1",
 			dbesc($contact['url']),
 			dbesc($contact['request']),
 			dbesc($contact['notify']),
diff --git a/include/plugin.php b/include/plugin.php
index 0b9c0166a..8cb2783ee 100644
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -413,7 +413,7 @@ function get_theme_info($theme){
 function get_theme_screenshot($theme) {
 	$exts = array('.png','.jpg');
 	foreach($exts as $ext) {
-		if(file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
+		if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
 			return(App::get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext);
 		}
 	}
@@ -425,8 +425,8 @@ if (! function_exists('uninstall_theme')){
 function uninstall_theme($theme){
 	logger("Addons: uninstalling theme " . $theme);
 
-	@include_once("view/theme/$theme/theme.php");
-	if(function_exists("{$theme}_uninstall")) {
+	include_once("view/theme/$theme/theme.php");
+	if (function_exists("{$theme}_uninstall")) {
 		$func = "{$theme}_uninstall";
 		$func();
 	}
@@ -436,19 +436,19 @@ if (! function_exists('install_theme')){
 function install_theme($theme) {
 	// silently fail if theme was removed
 
-	if(! file_exists("view/theme/$theme/theme.php"))
+	if (! file_exists("view/theme/$theme/theme.php")) {
 		return false;
+	}
 
 	logger("Addons: installing theme $theme");
 
-	@include_once("view/theme/$theme/theme.php");
+	include_once("view/theme/$theme/theme.php");
 
-	if(function_exists("{$theme}_install")) {
+	if (function_exists("{$theme}_install")) {
 		$func = "{$theme}_install";
 		$func();
 		return true;
-	}
-	else {
+	} else {
 		logger("Addons: FAILED installing theme $theme");
 		return false;
 	}
@@ -467,10 +467,9 @@ function install_theme($theme) {
 
 function service_class_allows($uid,$property,$usage = false) {
 
-	if($uid == local_user()) {
+	if ($uid == local_user()) {
 		$service_class = $a->user['service_class'];
-	}
-	else {
+	} else {
 		$r = q("SELECT `service_class` FROM `user` WHERE `uid` = %d LIMIT 1",
 			intval($uid)
 		);
@@ -478,18 +477,23 @@ function service_class_allows($uid,$property,$usage = false) {
 			$service_class = $r[0]['service_class'];
 		}
 	}
-	if(! x($service_class))
-		return true; // everything is allowed
+
+	if (! x($service_class)) [
+		// everything is allowed
+		return true;
+	}
 
 	$arr = get_config('service_class',$service_class);
-	if(! is_array($arr) || (! count($arr)))
+	if (! is_array($arr) || (! count($arr))) {
 		return true;
+	}
 
-	if($usage === false)
+	if ($usage === false) {
 		return ((x($arr[$property])) ? (bool) $arr['property'] : true);
-	else {
-		if(! array_key_exists($property,$arr))
+	} else {
+		if (! array_key_exists($property,$arr)) {
 			return true;
+		}
 		return (((intval($usage)) < intval($arr[$property])) ? true : false);
 	}
 }
@@ -497,10 +501,9 @@ function service_class_allows($uid,$property,$usage = false) {
 
 function service_class_fetch($uid,$property) {
 
-	if($uid == local_user()) {
+	if ($uid == local_user()) {
 		$service_class = $a->user['service_class'];
-	}
-	else {
+	} else {
 		$r = q("SELECT `service_class` FROM `user` WHERE `uid` = %d LIMIT 1",
 			intval($uid)
 		);
diff --git a/include/socgraph.php b/include/socgraph.php
index 7c70a22a5..e55643e6d 100644
--- a/include/socgraph.php
+++ b/include/socgraph.php
@@ -220,8 +220,9 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
 	$r = q("SELECT `network` FROM `contact` WHERE `nurl` = '%s' AND `network` != '' AND `network` != '%s' LIMIT 1",
 		dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET)
 	);
-	if (dbm::is_result($r))
+	if (dbm::is_result($r)) {
 		$network = $r[0]["network"];
+	}
 
 	if (($network == "") OR ($network == NETWORK_OSTATUS)) {
 		$r = q("SELECT `network`, `url` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `network` != '' AND `network` != '%s' LIMIT 1",
diff --git a/mod/admin.php b/mod/admin.php
index c502e36fc..48320fb36 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -1851,12 +1851,12 @@ function admin_page_themes(App &$a){
  * @param App $a
  */
 function admin_page_logs_post(App &$a) {
-	if(x($_POST,"page_logs")) {
+	if (x($_POST,"page_logs")) {
 		check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
 
-		$logfile 	=	((x($_POST,'logfile'))		? notags(trim($_POST['logfile']))	: '');
-		$debugging	=	((x($_POST,'debugging'))	? true					: false);
-		$loglevel 	=	((x($_POST,'loglevel'))		? intval(trim($_POST['loglevel']))	: 0);
+		$logfile   = (x($_POST,'logfile'))    ? notags(trim($_POST['logfile']))	: '');
+		$debugging = ((x($_POST,'debugging')) ? true					: false);
+		$loglevel  = ((x($_POST,'loglevel'))  ? intval(trim($_POST['loglevel']))	: 0);
 
 		set_config('system','logfile', $logfile);
 		set_config('system','debugging',  $debugging);
diff --git a/mod/delegate.php b/mod/delegate.php
index 40618eb32..6930a5943 100644
--- a/mod/delegate.php
+++ b/mod/delegate.php
@@ -21,7 +21,6 @@ function delegate_content(App &$a) {
 			goaway(App::get_baseurl() . '/delegate');
 		}
 
-
 		$id = $a->argv[2];
 
 		$r = q("select `nickname` from user where uid = %d limit 1",
@@ -45,12 +44,11 @@ function delegate_content(App &$a) {
 	if ($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) {
 
 		// delegated admins can view but not change delegation permissions
-
 		if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) {
 			goaway(App::get_baseurl() . '/delegate');
 		}
 
-		q("delete from manage where uid = %d and mid = %d limit 1",
+		q("DELETE FROM `manage` WHERE `uid` = %d AND `mid` = %d LIMIT 1",
 			intval($a->argv[2]),
 			intval(local_user())
 		);
diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php
index b9c1b6744..353f8fdc9 100644
--- a/mod/dfrn_request.php
+++ b/mod/dfrn_request.php
@@ -810,19 +810,17 @@ function dfrn_request_content(App &$a) {
 
 		// At first look if an address was provided
 		// Otherwise take the local address
-		if (x($_GET,'addr') AND ($_GET['addr'] != ""))
+		if (x($_GET,'addr') AND ($_GET['addr'] != "")) {
 			$myaddr = hex2bin($_GET['addr']);
-		elseif (x($_GET,'address') AND ($_GET['address'] != ""))
+		} elseif (x($_GET,'address') AND ($_GET['address'] != "")) {
 			$myaddr = $_GET['address'];
-		elseif (local_user()) {
+		} elseif (local_user()) {
 			if (strlen($a->path)) {
 				$myaddr = App::get_baseurl() . '/profile/' . $a->user['nickname'];
-			}
-			else {
+			} else {
 				$myaddr = $a->user['nickname'] . '@' . substr(z_root(), strpos(z_root(),'://') + 3 );
 			}
-		}
-		else {
+		} else {
 			// last, try a zrl
 			$myaddr = get_my_url();
 		}
@@ -840,8 +838,7 @@ function dfrn_request_content(App &$a) {
 
 		if ($a->profile['page-flags'] == PAGE_NORMAL) {
 			$tpl = get_markup_template('dfrn_request.tpl');
-		}
-		else {
+		} else {
 			$tpl = get_markup_template('auto_request.tpl');
 		}
 
@@ -850,10 +847,12 @@ function dfrn_request_content(App &$a) {
 		// see if we are allowed to have NETWORK_MAIL2 contacts
 
 		$mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
-		if(get_config('system','dfrn_only'))
-			$mail_disabled = 1;
 
-		if(! $mail_disabled) {
+		if (get_config('system','dfrn_only')) {
+			$mail_disabled = 1;
+		}
+
+		if (! $mail_disabled) {
 			$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
 				intval($a->profile['uid'])
 			);
diff --git a/mod/events.php b/mod/events.php
index 1ed04deb0..8281a9766 100644
--- a/mod/events.php
+++ b/mod/events.php
@@ -354,7 +354,7 @@ function events_content(App &$a) {
 			}
 		}
 
-		$events=array();
+		$events = array();
 
 		// transform the event in a usable array
 		if (dbm::is_result($r)) {
diff --git a/mod/group.php b/mod/group.php
index bf9009ae0..681bc88cc 100644
--- a/mod/group.php
+++ b/mod/group.php
@@ -31,8 +31,7 @@ function group_post(App &$a) {
 			if ($r) {
 				goaway(App::get_baseurl() . '/group/' . $r);
 			}
-		}
-		else {
+		} else {
 			notice( t('Could not create group.') . EOL );
 		}
 		goaway(App::get_baseurl() . '/group');
@@ -92,7 +91,7 @@ function group_content(App &$a) {
 			'$submit' => t('Save Group'),
 	);
 
-	if(($a->argc == 2) && ($a->argv[1] === 'new')) {
+	if (($a->argc == 2) && ($a->argv[1] === 'new')) {
 
 		return replace_macros($tpl, $context + array(
 			'$title' => t('Create a group of contacts/friends.'),
diff --git a/mod/hcard.php b/mod/hcard.php
index 50721720d..d53405009 100644
--- a/mod/hcard.php
+++ b/mod/hcard.php
@@ -52,4 +52,3 @@ function hcard_init(App &$a) {
 	}
 
 }
-
diff --git a/mod/invite.php b/mod/invite.php
index f7f48290c..a7739fc77 100644
--- a/mod/invite.php
+++ b/mod/invite.php
@@ -120,7 +120,7 @@ function invite_content(App &$a) {
 	if (strlen($dirloc)) {
 		if ($a->config['register_policy'] == REGISTER_CLOSED) {
 			$linktxt = sprintf( t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.'), $dirloc . '/siteinfo');
-		} elseif($a->config['register_policy'] != REGISTER_CLOSED) {
+		} elseif ($a->config['register_policy'] != REGISTER_CLOSED) {
 			$linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), App::get_baseurl())
 			. "\r\n" . "\r\n" . sprintf( t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.'),$dirloc . '/siteinfo');
 		}
diff --git a/mod/item.php b/mod/item.php
index bf3aa4c98..0746f0ada 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -454,7 +454,7 @@ function item_post(App &$a) {
 			$objecttype = ACTIVITY_OBJ_IMAGE;
 
 			foreach ($images as $image) {
-				if (! stristr($image,App::get_baseurl() . '/photo/')) {
+				if (! stristr($image,App::get_baseurl() . '/photo/'))
 					continue;
 				}
 				$image_uri = substr($image,strrpos($image,'/') + 1);
@@ -620,16 +620,17 @@ function item_post(App &$a) {
 				continue;
 
 			$success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network);
-			if($success['replaced'])
+			if ($success['replaced']) {
 				$tagged[] = $tag;
-			if(is_array($success['contact']) && intval($success['contact']['prv'])) {
+			}
+			if (is_array($success['contact']) && intval($success['contact']['prv'])) {
 				$private_forum = true;
 				$private_id = $success['contact']['id'];
 			}
 		}
 	}
 
-	if(($private_forum) && (! $parent) && (! $private)) {
+	if (($private_forum) && (! $parent) && (! $private)) {
 		// we tagged a private forum in a top level post and the message was public.
 		// Restrict it.
 		$private = 1;
@@ -639,8 +640,8 @@ function item_post(App &$a) {
 	$attachments = '';
 	$match = false;
 
-	if(preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
-		foreach($match[2] as $mtch) {
+	if (preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
+		foreach ($match[2] as $mtch) {
 			$r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1",
 				intval($profile_uid),
 				intval($mtch)
diff --git a/mod/profile.php b/mod/profile.php
index 52ffe8c47..8519f7e82 100644
--- a/mod/profile.php
+++ b/mod/profile.php
@@ -74,24 +74,24 @@ function profile_content(&$a, $update = 0) {
 
 	$category = $datequery = $datequery2 = '';
 
-	if($a->argc > 2) {
-		for($x = 2; $x < $a->argc; $x ++) {
-			if(is_a_date_arg($a->argv[$x])) {
-				if($datequery)
+	if ($a->argc > 2) {
+		for ($x = 2; $x < $a->argc; $x ++) {
+			if (is_a_date_arg($a->argv[$x])) {
+				if ($datequery) {
 					$datequery2 = escape_tags($a->argv[$x]);
-				else
+				} else {
 					$datequery = escape_tags($a->argv[$x]);
-			}
-			else
+			} else {
 				$category = $a->argv[$x];
+			}
 		}
 	}
 
-	if(! x($category)) {
+	if (! x($category)) {
 		$category = ((x($_GET,'category')) ? $_GET['category'] : '');
 	}
 
-	if(get_config('system','block_public') && (! local_user()) && (! remote_user())) {
+	if (get_config('system','block_public') && (! local_user()) && (! remote_user())) {
 		return login();
 	}
 
@@ -106,32 +106,30 @@ function profile_content(&$a, $update = 0) {
 	$tab = 'posts';
 	$o = '';
 
-	if($update) {
+	if ($update) {
 		// Ensure we've got a profile owner if updating.
 		$a->profile['profile_uid'] = $update;
-	}
-	else {
-		if($a->profile['profile_uid'] == local_user()) {
+	} else {
+		if ($a->profile['profile_uid'] == local_user()) {
 			nav_set_selected('home');
 		}
 	}
 
-
 	$contact = null;
 	$remote_contact = false;
 
 	$contact_id = 0;
 
-	if(is_array($_SESSION['remote'])) {
-		foreach($_SESSION['remote'] as $v) {
-			if($v['uid'] == $a->profile['profile_uid']) {
+	if (is_array($_SESSION['remote'])) {
+		foreach ($_SESSION['remote'] as $v) {
+			if ($v['uid'] == $a->profile['profile_uid']) {
 				$contact_id = $v['cid'];
 				break;
 			}
 		}
 	}
 
-	if($contact_id) {
+	if ($contact_id) {
 		$groups = init_groups_visitor($contact_id);
 		$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
 			intval($contact_id),
@@ -143,8 +141,8 @@ function profile_content(&$a, $update = 0) {
 		}
 	}
 
-	if(! $remote_contact) {
-		if(local_user()) {
+	if (! $remote_contact) {
+		if (local_user()) {
 			$contact_id = $_SESSION['cid'];
 			$contact = $a->contact;
 		}
@@ -152,32 +150,29 @@ function profile_content(&$a, $update = 0) {
 
 	$is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
 
-	if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
+	if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
 		notice( t('Access to this profile has been restricted.') . EOL);
 		return;
 	}
 
-	if(! $update) {
-
-
-		if(x($_GET,'tab'))
+	if (! $update) {
+		if (x($_GET,'tab'))
 			$tab = notags(trim($_GET['tab']));
 
 		$o.=profile_tabs($a, $is_owner, $a->profile['nickname']);
 
 
-		if($tab === 'profile') {
+		if ($tab === 'profile') {
 			$o .= advanced_profile($a);
 			call_hooks('profile_advanced',$o);
 			return $o;
 		}
 
-
 		$o .= common_friends_visitor_widget($a->profile['profile_uid']);
 
-
-		if(x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner)
+		if (x($_SESSION,'new_member') && $_SESSION['new_member'] && $is_owner) {
 			$o .= '' . t('Tips for New Members') . '' . EOL;
+		}
 
 		$commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
 		$commvisitor = (($commpage && $remote_contact == true) ? true : false);
@@ -185,7 +180,7 @@ function profile_content(&$a, $update = 0) {
 		$a->page['aside'] .= posted_date_widget(App::get_baseurl(true) . '/profile/' . $a->profile['nickname'],$a->profile['profile_uid'],true);
 		$a->page['aside'] .= categories_widget(App::get_baseurl(true) . '/profile/' . $a->profile['nickname'],(x($category) ? xmlify($category) : ''));
 
-		if(can_write_wall($a,$a->profile['profile_uid'])) {
+		if (can_write_wall($a,$a->profile['profile_uid'])) {
 
 			$x = array(
 				'is_owner' => $is_owner,
@@ -215,7 +210,7 @@ function profile_content(&$a, $update = 0) {
 	$sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups);
 
 
-	if($update) {
+	if ($update) {
 
 		$r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`
 			FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
@@ -234,16 +229,16 @@ function profile_content(&$a, $update = 0) {
 	} else {
 		$sql_post_table = "";
 
-		if(x($category)) {
+		if (x($category)) {
 			$sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
 				dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
 			//$sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category'));
 		}
 
-		if($datequery) {
+		if ($datequery) {
 			$sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
 		}
-		if($datequery2) {
+		if ($datequery2) {
 			$sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
 		}
 
diff --git a/mod/profile_photo.php b/mod/profile_photo.php
index 9b1ff8adb..c600dd1f8 100644
--- a/mod/profile_photo.php
+++ b/mod/profile_photo.php
@@ -133,9 +133,9 @@ function profile_photo_post(App &$a) {
 
 				require_once('include/profile_update.php');
 				profile_change();
-			}
-			else
+			} else {
 				notice( t('Unable to process image') . EOL);
+			}
 		}
 
 		goaway(App::get_baseurl() . '/profiles');
@@ -146,11 +146,13 @@ function profile_photo_post(App &$a) {
 	$filename = basename($_FILES['userfile']['name']);
 	$filesize = intval($_FILES['userfile']['size']);
 	$filetype = $_FILES['userfile']['type'];
-    if ($filetype=="") $filetype=guess_image_type($filename);
-    
+	if ($filetype == "") {
+		$filetype = guess_image_type($filename);
+	}
+
 	$maximagesize = get_config('system','maximagesize');
 
-	if(($maximagesize) && ($filesize > $maximagesize)) {
+	if (($maximagesize) && ($filesize > $maximagesize)) {
 		notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
 		@unlink($src);
 		return;
@@ -159,7 +161,7 @@ function profile_photo_post(App &$a) {
 	$imagedata = @file_get_contents($src);
 	$ph = new Photo($imagedata, $filetype);
 
-	if(! $ph->is_valid()) {
+	if (! $ph->is_valid()) {
 		notice( t('Unable to process image.') . EOL );
 		@unlink($src);
 		return;
@@ -168,7 +170,6 @@ function profile_photo_post(App &$a) {
 	$ph->orient($src);
 	@unlink($src);
 	return profile_photo_crop_ui_head($a, $ph);
-	
 }
 
 
diff --git a/mod/videos.php b/mod/videos.php
index 64838998f..433ce5fc6 100644
--- a/mod/videos.php
+++ b/mod/videos.php
@@ -113,7 +113,7 @@ function videos_post(App &$a) {
 	if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
 
 		// Check if we should do HTML-based delete confirmation
-		if(!x($_REQUEST,'confirm')) {
+		if (!x($_REQUEST,'confirm')) {
 			if (x($_REQUEST,'canceled')) {
 				goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
 			}
@@ -138,7 +138,6 @@ function videos_post(App &$a) {
 
 		$video_id = $_POST['id'];
 
-
 		$r = q("SELECT `id`  FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
 			intval(local_user()),
 			dbesc($video_id)
@@ -409,4 +408,3 @@ function videos_content(App &$a) {
 	$o .= paginate($a);
 	return $o;
 }
-
diff --git a/view/theme/duepuntozero/config.php b/view/theme/duepuntozero/config.php
index acea9947b..eec76d173 100644
--- a/view/theme/duepuntozero/config.php
+++ b/view/theme/duepuntozero/config.php
@@ -42,13 +42,13 @@ function theme_admin_post(App &$a){
 /// @TODO $a is no longer used
 function clean_form(&$a, &$colorset, $user){
 	$colorset = array(
-		'default'=>t('default'), 
-		'greenzero'=>t('greenzero'),
-		'purplezero'=>t('purplezero'),
-		'easterbunny'=>t('easterbunny'),
-		'darkzero'=>t('darkzero'),
-		'comix'=>t('comix'),
-		'slackr'=>t('slackr'),
+		'default'     =>t('default'), 
+		'greenzero'   =>t('greenzero'),
+		'purplezero'  =>t('purplezero'),
+		'easterbunny' =>t('easterbunny'),
+		'darkzero'    =>t('darkzero'),
+		'comix'       =>t('comix'),
+		'slackr'      =>t('slackr'),
 	);
 
 	if ($user) {
@@ -62,7 +62,7 @@ function clean_form(&$a, &$colorset, $user){
 	$o .= replace_macros($t, array(
 		'$submit'   => t('Submit'),
 		'$baseurl'  => App::get_baseurl(),
-		'$title'=> t("Theme settings"),
+		'$title'    => t("Theme settings"),
 		'$colorset' => array('duepuntozero_colorset', t('Variations'), $color, '', $colorset),
 	));
 

From 9b6ad2fc4754185708d00d3be4c4a2aebcb73e7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 10:39:06 +0100
Subject: [PATCH 08/19] Coding convention: - added curly braces - added space
 between "if" and brace - also added TODO (old-lost code?)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 mod/hcard.php    | 4 ++++
 mod/noscrape.php | 1 +
 mod/profile.php  | 4 ++++
 3 files changed, 9 insertions(+)

diff --git a/mod/hcard.php b/mod/hcard.php
index d53405009..8d79dd054 100644
--- a/mod/hcard.php
+++ b/mod/hcard.php
@@ -47,7 +47,11 @@ function hcard_init(App &$a) {
 	header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
 
 	$dfrn_pages = array('request', 'confirm', 'notify', 'poll');
+<<<<<<< upstream/develop
 	foreach ($dfrn_pages as $dfrn) {
+=======
+	foreach($dfrn_pages as $dfrn) {
+>>>>>>> HEAD~65
 		$a->page['htmlhead'] .= "\r\n";
 	}
 
diff --git a/mod/noscrape.php b/mod/noscrape.php
index 758ce8ba5..33255f0fa 100644
--- a/mod/noscrape.php
+++ b/mod/noscrape.php
@@ -26,6 +26,7 @@ function noscrape_init(App &$a) {
 	$keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
 	$keywords = explode(',', $keywords);
 
+	/// @TODO This query's result is not being used (see below), maybe old-lost code?
 	$r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d",
 		intval($a->profile['uid']));
 
diff --git a/mod/profile.php b/mod/profile.php
index 8519f7e82..28b508dc0 100644
--- a/mod/profile.php
+++ b/mod/profile.php
@@ -62,7 +62,11 @@ function profile_init(App &$a) {
 	header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
 
 	$dfrn_pages = array('request', 'confirm', 'notify', 'poll');
+<<<<<<< upstream/develop
 	foreach ($dfrn_pages as $dfrn) {
+=======
+	foreach($dfrn_pages as $dfrn) {
+>>>>>>> HEAD~65
 		$a->page['htmlhead'] .= "\r\n";
 	}
 	$a->page['htmlhead'] .= "\r\n";

From 9fad8109ffafa689ff5b230906d21dec18cd8725 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 10:58:55 +0100
Subject: [PATCH 09/19] changed to this: --------------------- function bla
 (App &$a) { 	$a->bla = 'stuff'; } ---------------------
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 mod/admin.php    | 14 +++++++-------
 mod/contacts.php | 13 ++++++++-----
 mod/hcard.php    |  4 ----
 mod/network.php  |  6 ++----
 mod/notify.php   |  2 --
 mod/profile.php  |  4 ----
 mod/suggest.php  |  1 -
 mod/uexport.php  |  1 +
 8 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/mod/admin.php b/mod/admin.php
index 48320fb36..e1ccf67ca 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -1156,21 +1156,21 @@ function admin_page_dbsync(App &$a) {
  * @param App $a
  */
 function admin_page_users_post(App &$a){
-	$pending     =	(x($_POST, 'pending')           ? $_POST['pending']           : array());
-	$users       =	(x($_POST, 'user')              ? $_POST['user']		      : array());
-	$nu_name     =	(x($_POST, 'new_user_name')     ? $_POST['new_user_name']     : '');
-	$nu_nickname =	(x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
-	$nu_email    =	(x($_POST, 'new_user_email')    ? $_POST['new_user_email']    : '');
+	$pending     = (x($_POST, 'pending')           ? $_POST['pending']           : array());
+	$users       = (x($_POST, 'user')              ? $_POST['user']		      : array());
+	$nu_name     = (x($_POST, 'new_user_name')     ? $_POST['new_user_name']     : '');
+	$nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : '');
+	$nu_email    = (x($_POST, 'new_user_email')    ? $_POST['new_user_email']    : '');
 	$nu_language = get_config('system', 'language');
 
 	check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
 
-	if(!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) {
+	if (!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) {
 		require_once('include/user.php');
 
 		$result = create_user(array('username'=>$nu_name, 'email'=>$nu_email, 
 			'nickname'=>$nu_nickname, 'verified'=>1, 'language'=>$nu_language));
-		if(! $result['success']) {
+		if (! $result['success']) {
 			notice($result['message']);
 			return;
 		}
diff --git a/mod/contacts.php b/mod/contacts.php
index f709f9d2f..26dfe0607 100644
--- a/mod/contacts.php
+++ b/mod/contacts.php
@@ -28,19 +28,22 @@ function contacts_init(App &$a) {
 	require_once('include/group.php');
 	require_once('include/contact_widgets.php');
 
-	if ($_GET['nets'] == "all")
-	$_GET['nets'] = "";
+	if ($_GET['nets'] == "all") {
+		$_GET['nets'] = "";
+	}
 
-	if(! x($a->page,'aside'))
+	if (! x($a->page,'aside')) {
 		$a->page['aside'] = '';
+	}
 
-	if($contact_id) {
+	if ($contact_id) {
 			$a->data['contact'] = $r[0];
 
 			if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
 				$networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
-			} else
+			} else {
 				$networkname = '';
+			}
 
 			$vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
 				'$name' => htmlentities($a->data['contact']['name']),
diff --git a/mod/hcard.php b/mod/hcard.php
index 8d79dd054..d53405009 100644
--- a/mod/hcard.php
+++ b/mod/hcard.php
@@ -47,11 +47,7 @@ function hcard_init(App &$a) {
 	header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
 
 	$dfrn_pages = array('request', 'confirm', 'notify', 'poll');
-<<<<<<< upstream/develop
 	foreach ($dfrn_pages as $dfrn) {
-=======
-	foreach($dfrn_pages as $dfrn) {
->>>>>>> HEAD~65
 		$a->page['htmlhead'] .= "\r\n";
 	}
 
diff --git a/mod/network.php b/mod/network.php
index f43327707..61df38fb1 100644
--- a/mod/network.php
+++ b/mod/network.php
@@ -25,7 +25,6 @@ function network_init(App &$a) {
 	parse_str($query_string, $query_array);
 	array_shift($query_array);
 
-
 	// fetch last used network view and redirect if needed
 	if (! $is_a_date_query) {
 		$sel_tabs = network_query_get_sel_tab($a);
@@ -42,10 +41,9 @@ function network_init(App &$a) {
 		$net_baseurl = '/network';
 		$net_args = array();
 
-		if($remember_group) {
+		if ($remember_group) {
 			$net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
-		}
-		else if($sel_groups !== false) {
+		} elseif($sel_groups !== false) {
 			$net_baseurl .= '/' . $sel_groups;
 		}
 
diff --git a/mod/notify.php b/mod/notify.php
index 2d34821de..2696afaad 100644
--- a/mod/notify.php
+++ b/mod/notify.php
@@ -1,12 +1,10 @@
 argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
diff --git a/mod/profile.php b/mod/profile.php
index 28b508dc0..8519f7e82 100644
--- a/mod/profile.php
+++ b/mod/profile.php
@@ -62,11 +62,7 @@ function profile_init(App &$a) {
 	header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
 
 	$dfrn_pages = array('request', 'confirm', 'notify', 'poll');
-<<<<<<< upstream/develop
 	foreach ($dfrn_pages as $dfrn) {
-=======
-	foreach($dfrn_pages as $dfrn) {
->>>>>>> HEAD~65
 		$a->page['htmlhead'] .= "\r\n";
 	}
 	$a->page['htmlhead'] .= "\r\n";
diff --git a/mod/suggest.php b/mod/suggest.php
index 6ded66286..a6c4b6e56 100644
--- a/mod/suggest.php
+++ b/mod/suggest.php
@@ -3,7 +3,6 @@
 require_once('include/socgraph.php');
 require_once('include/contact_widgets.php');
 
-
 function suggest_init(App &$a) {
 	if (! local_user()) {
 		return;
diff --git a/mod/uexport.php b/mod/uexport.php
index 7aa9724d5..1ca046d22 100644
--- a/mod/uexport.php
+++ b/mod/uexport.php
@@ -9,6 +9,7 @@ function uexport_init(App &$a){
 	settings_init($a);
 }
 
+/// @TODO Change space -> tab where wanted
 function uexport_content(App &$a){
 
     if ($a->argc > 1) {

From 820ef8e4c76c606e74f5ec1708bbd0e807faa44b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 10:59:06 +0100
Subject: [PATCH 10/19] changed to this: --------------------- function bla
 (App &$a) { 	$a->bla = 'stuff'; } ---------------------
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 view/theme/duepuntozero/config.php | 2 --
 view/theme/quattro/config.php      | 1 -
 2 files changed, 3 deletions(-)

diff --git a/view/theme/duepuntozero/config.php b/view/theme/duepuntozero/config.php
index eec76d173..48c9c8709 100644
--- a/view/theme/duepuntozero/config.php
+++ b/view/theme/duepuntozero/config.php
@@ -3,7 +3,6 @@
  * Theme settings
  */
 
-
 function theme_content(App &$a){
 	if (!local_user()) {
 		return;
@@ -25,7 +24,6 @@ function theme_post(App &$a){
 	}
 }
 
-
 function theme_admin(App &$a){
 	$colorset = get_config( 'duepuntozero', 'colorset');
 	$user = false;
diff --git a/view/theme/quattro/config.php b/view/theme/quattro/config.php
index 0c619569a..32f71db01 100644
--- a/view/theme/quattro/config.php
+++ b/view/theme/quattro/config.php
@@ -29,7 +29,6 @@ function theme_post(App &$a){
 	}
 }
 
-
 function theme_admin(App &$a){
 	$align = get_config('quattro', 'align' );
 	$color = get_config('quattro', 'color' );

From 8b8a45b7038f573a2e18e761eeff4f506185af0b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 11:27:40 +0100
Subject: [PATCH 11/19] added curly braces + space between "if" and brace
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 mod/notify.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mod/notify.php b/mod/notify.php
index 2696afaad..bd7a7faf4 100644
--- a/mod/notify.php
+++ b/mod/notify.php
@@ -5,6 +5,7 @@ function notify_init(App &$a) {
 	if (! local_user()) {
 		return;
 	}
+
 	$nm = new NotificationsManager();
 
 	if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {

From 8ce20f975c7fc1c27d1981234aefc93b0e7b662a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 12:45:16 +0100
Subject: [PATCH 12/19] Changed $a->get_baseurl() to App::get_baseurl()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 mod/filerm.php    | 5 +++++
 mod/subthread.php | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/mod/filerm.php b/mod/filerm.php
index 7dbfe2947..7662289ad 100644
--- a/mod/filerm.php
+++ b/mod/filerm.php
@@ -22,9 +22,14 @@ function filerm_content(App &$a) {
 		file_tag_unsave_file(local_user(),$item_id,$term, $category);
 	}
 
+<<<<<<< upstream/develop
 	if (x($_SESSION,'return_url')) {
 		goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
 	}
+=======
+	if(x($_SESSION,'return_url'))
+		goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
+>>>>>>> HEAD~33
 
 	killme();
 }
diff --git a/mod/subthread.php b/mod/subthread.php
index c689f7f6c..368619dec 100644
--- a/mod/subthread.php
+++ b/mod/subthread.php
@@ -86,7 +86,11 @@ function subthread_content(App &$a) {
 	$uri = item_new_uri($a->get_hostname(),$owner_uid);
 
 	$post_type = (($item['resource-id']) ? t('photo') : t('status'));
+<<<<<<< upstream/develop
 	$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
+=======
+	$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
+>>>>>>> HEAD~33
 	$link = xmlify('' . "\n") ;
 	$body = $item['body'];
 

From 3472191b055bdb9a912daceaea1ccd8516137091 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 12:45:16 +0100
Subject: [PATCH 13/19] Changed $a->get_baseurl() to App::get_baseurl()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 mod/filerm.php    | 5 -----
 mod/subthread.php | 3 +++
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/mod/filerm.php b/mod/filerm.php
index 7662289ad..7dbfe2947 100644
--- a/mod/filerm.php
+++ b/mod/filerm.php
@@ -22,14 +22,9 @@ function filerm_content(App &$a) {
 		file_tag_unsave_file(local_user(),$item_id,$term, $category);
 	}
 
-<<<<<<< upstream/develop
 	if (x($_SESSION,'return_url')) {
 		goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
 	}
-=======
-	if(x($_SESSION,'return_url'))
-		goaway(App::get_baseurl() . '/' . $_SESSION['return_url']);
->>>>>>> HEAD~33
 
 	killme();
 }
diff --git a/mod/subthread.php b/mod/subthread.php
index 368619dec..69b7f3a60 100644
--- a/mod/subthread.php
+++ b/mod/subthread.php
@@ -90,7 +90,10 @@ function subthread_content(App &$a) {
 	$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
 =======
 	$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
+<<<<<<< upstream/develop
 >>>>>>> HEAD~33
+=======
+>>>>>>> HEAD~32
 	$link = xmlify('' . "\n") ;
 	$body = $item['body'];
 

From 54905a3d81065915418af7f96953f957bf795300 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 17:43:46 +0100
Subject: [PATCH 14/19] added more curly braces + space between "if" and brace
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 mod/subthread.php | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/mod/subthread.php b/mod/subthread.php
index 69b7f3a60..c689f7f6c 100644
--- a/mod/subthread.php
+++ b/mod/subthread.php
@@ -86,14 +86,7 @@ function subthread_content(App &$a) {
 	$uri = item_new_uri($a->get_hostname(),$owner_uid);
 
 	$post_type = (($item['resource-id']) ? t('photo') : t('status'));
-<<<<<<< upstream/develop
 	$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
-=======
-	$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
-<<<<<<< upstream/develop
->>>>>>> HEAD~33
-=======
->>>>>>> HEAD~32
 	$link = xmlify('' . "\n") ;
 	$body = $item['body'];
 

From ca82678a6da703157a95a815d57649af5066397b Mon Sep 17 00:00:00 2001
From: Roland Haeder 
Date: Tue, 20 Dec 2016 21:13:50 +0100
Subject: [PATCH 15/19] Continued with coding convention: - added curly braces
 around conditional code blocks - added space between if/foreach/... and brace
 - rewrote a code block so if dbm::is_result() fails it will abort, else the
 id   is fetched from INSERT statement - made some SQL keywords upper-cased
 and added back-ticks to columns/table names

Signed-off-by: Roland Haeder 
---
 include/acl_selectors.php | 6 +++---
 include/message.php       | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index 4c0b610d4..f6c4f947e 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -272,7 +272,7 @@ function prune_deadguys($arr) {
 
 	$r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 ");
 
-	if ($r) {
+	if (dbm::is_result($r)) {
 		$ret = array();
 		foreach ($r as $rr) {
 			$ret[] = intval($rr['id']);
@@ -585,9 +585,9 @@ function acl_lookup(&$a, $out_type = 'json') {
 		);
 		echo json_encode($o);
 		killme();
-	}
-	else
+	} else {
 		$r = array();
+	}
 
 
 	if (dbm::is_result($r)) {
diff --git a/include/message.php b/include/message.php
index 3d5d4d33a..5bd611f22 100644
--- a/include/message.php
+++ b/include/message.php
@@ -153,7 +153,8 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
 	if ($post_id) {
 		proc_run(PRIORITY_HIGH, "include/notifier.php", "mail", $post_id);
 		return intval($post_id);
-	} else {
+	}
+	else {
 		return -3;
 	}
 

From c1b76e889e4b2ca50abe191c22f3a8bb7a9bfdaf Mon Sep 17 00:00:00 2001
From: Roland Haeder 
Date: Tue, 20 Dec 2016 21:15:53 +0100
Subject: [PATCH 16/19] Continued with coding convention: - added curly braces
 around conditional code blocks - added space between if/foreach/... and brace
 - rewrote a code block so if dbm::is_result() fails it will abort, else the
 id   is fetched from INSERT statement - made some SQL keywords upper-cased
 and added back-ticks to columns/table names

Signed-off-by: Roland Haeder 
---
 mod/install.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mod/install.php b/mod/install.php
index 9adeac604..f7329592e 100755
--- a/mod/install.php
+++ b/mod/install.php
@@ -538,7 +538,8 @@ function check_htaccess(&$checks) {
 			$help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
 		}
 		check_add($checks, t('Url rewrite is working'), $status, true, $help);
-	} else {
+	}
+	else {
 		// cannot check modrewrite if libcurl is not installed
 		/// @TODO Maybe issue warning here?
 	}

From 45dd1ccc7bcd8cf9d9218b373042df26dc8a2df4 Mon Sep 17 00:00:00 2001
From: Roland Haeder 
Date: Tue, 20 Dec 2016 21:15:53 +0100
Subject: [PATCH 17/19] Continued with coding convention: - added curly braces
 around conditional code blocks - added space between if/foreach/... and brace
 - rewrote a code block so if dbm::is_result() fails it will abort, else the
 id   is fetched from INSERT statement - made some SQL keywords upper-cased
 and added back-ticks to columns/table names

Signed-off-by: Roland Haeder 
---
 mod/item.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mod/item.php b/mod/item.php
index 0746f0ada..ee532bd99 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -454,7 +454,7 @@ function item_post(App &$a) {
 			$objecttype = ACTIVITY_OBJ_IMAGE;
 
 			foreach ($images as $image) {
-				if (! stristr($image,App::get_baseurl() . '/photo/'))
+				if (! stristr($image,App::get_baseurl() . '/photo/')) {
 					continue;
 				}
 				$image_uri = substr($image,strrpos($image,'/') + 1);

From 89319d9579bb052e0b105ab6a41d432d0df9b49f Mon Sep 17 00:00:00 2001
From: Roland Haeder 
Date: Tue, 20 Dec 2016 21:31:05 +0100
Subject: [PATCH 18/19] Continued with coding convention: - added curly braces
 around conditional code blocks - added space between if/foreach/... and brace
 - made some SQL keywords upper-cased and added back-ticks to columns/table
 names

Signed-off-by: Roland Haeder 
---
 mod/noscrape.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/mod/noscrape.php b/mod/noscrape.php
index 33255f0fa..758ce8ba5 100644
--- a/mod/noscrape.php
+++ b/mod/noscrape.php
@@ -26,7 +26,6 @@ function noscrape_init(App &$a) {
 	$keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
 	$keywords = explode(',', $keywords);
 
-	/// @TODO This query's result is not being used (see below), maybe old-lost code?
 	$r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d",
 		intval($a->profile['uid']));
 

From 3dbb92c0dcbf087bfded1f84a7aab500c1b4b0c1 Mon Sep 17 00:00:00 2001
From: Roland Haeder 
Date: Wed, 21 Dec 2016 23:04:09 +0100
Subject: [PATCH 19/19] added curly braces/spaces + replace spaces with tabs to
 fix code indending (or so?)

Signed-off-by: Roland Haeder 
---
 include/message.php | 3 +--
 mod/install.php     | 4 +---
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/message.php b/include/message.php
index 5bd611f22..3d5d4d33a 100644
--- a/include/message.php
+++ b/include/message.php
@@ -153,8 +153,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
 	if ($post_id) {
 		proc_run(PRIORITY_HIGH, "include/notifier.php", "mail", $post_id);
 		return intval($post_id);
-	}
-	else {
+	} else {
 		return -3;
 	}
 
diff --git a/mod/install.php b/mod/install.php
index f7329592e..382fcefd7 100755
--- a/mod/install.php
+++ b/mod/install.php
@@ -538,8 +538,7 @@ function check_htaccess(&$checks) {
 			$help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
 		}
 		check_add($checks, t('Url rewrite is working'), $status, true, $help);
-	}
-	else {
+	} else {
 		// cannot check modrewrite if libcurl is not installed
 		/// @TODO Maybe issue warning here?
 	}
@@ -582,7 +581,6 @@ function load_database_rem($v, $i){
 	}
 }
 
-
 function load_database($db) {
 
 	require_once("include/dbstructure.php");