From 2a77e426f9a26a2584da78c90daf8ec1d49fcc00 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 27 Jan 2017 17:00:34 +0000 Subject: [PATCH 01/55] Split poco discovery in smaller function calls --- include/socgraph.php | 124 ++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 54 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 32c151c04..b787452b8 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1260,6 +1260,71 @@ function poco_discover_federation() { set_config('poco','last_federation_discovery', time()); } +function poco_discover_single_server($id) { + $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id)); + if (!dbm::is_result($r)) { + return false; + } + + $server = $r[0]; + + if (!poco_check_server($server["url"], $server["network"])) { + // The server is not reachable? Okay, then we will try it later + q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + return false; + } + + // Fetch all users from the other server + $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; + + logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG); + + $retdata = z_fetch_url($url); + if ($retdata["success"]) { + $data = json_decode($retdata["body"]); + + poco_discover_server($data, 2); + + if (get_config('system','poco_discovery') > 1) { + + $timeframe = get_config('system','poco_discovery_since'); + if ($timeframe == 0) { + $timeframe = 30; + } + + $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400); + + // Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3) + $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; + + $success = false; + + $retdata = z_fetch_url($url); + if ($retdata["success"]) { + logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); + $success = poco_discover_server(json_decode($retdata["body"])); + } + + if (!$success AND (get_config('system','poco_discovery') > 2)) { + logger("Fetch contacts from users of the server ".$server["nurl"], LOGGER_DEBUG); + poco_discover_server_users($data, $server); + } + } + + q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + + return true; + } else { + // If the server hadn't replied correctly, then force a sanity check + poco_check_server($server["url"], $server["network"], true); + + // If we couldn't reach the server, we will try it some time later + q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + + return false; + } +} + function poco_discover($complete = false) { // Update the server list @@ -1274,63 +1339,14 @@ function poco_discover($complete = false) { $last_update = date("c", time() - (60 * 60 * 24 * $requery_days)); - $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update)); - if ($r) + $r = q("SELECT `id` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update)); + if (dbm::is_result($r)) { foreach ($r AS $server) { - - if (!poco_check_server($server["url"], $server["network"])) { - // The server is not reachable? Okay, then we will try it later - q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); - continue; - } - - // Fetch all users from the other server - $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - - logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG); - - $retdata = z_fetch_url($url); - if ($retdata["success"]) { - $data = json_decode($retdata["body"]); - - poco_discover_server($data, 2); - - if (get_config('system','poco_discovery') > 1) { - - $timeframe = get_config('system','poco_discovery_since'); - if ($timeframe == 0) - $timeframe = 30; - - $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400); - - // Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3) - $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - - $success = false; - - $retdata = z_fetch_url($url); - if ($retdata["success"]) { - logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); - $success = poco_discover_server(json_decode($retdata["body"])); - } - - if (!$success AND (get_config('system','poco_discovery') > 2)) { - logger("Fetch contacts from users of the server ".$server["nurl"], LOGGER_DEBUG); - poco_discover_server_users($data, $server); - } - } - - q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); - if (!$complete AND (--$no_of_queries == 0)) - break; - } else { - // If the server hadn't replied correctly, then force a sanity check - poco_check_server($server["url"], $server["network"], true); - - // If we couldn't reach the server, we will try it some time later - q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + if (poco_discover_single_server($server['id']) AND !$complete AND (--$no_of_queries == 0)) { + break; } } + } } function poco_discover_server_users($data, $server) { From 1c6535c0b45c32ccbb0e2bd49e5bb7a6d5435d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 09:44:53 +0100 Subject: [PATCH 02/55] applied coding convention: - replaced space -> tab (code indenting) - added curly braces - used dbm::is_result() if $r is no result (may happen) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/settings.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 32ccaf541..94b93f9b9 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -381,13 +381,15 @@ function settings_post(App $a) { $err = true; } - // check if the old password was supplied correctly before - // changing it to the new value - $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); - if( $oldpass != $r[0]['password'] ) { - notice( t('Wrong password.') . EOL); - $err = true; - } + // check if the old password was supplied correctly before + // changing it to the new value + $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); + if (!dbm::is_result($r)) { + killme(); + } elseif ( $oldpass != $r[0]['password'] ) { + notice( t('Wrong password.') . EOL); + $err = true; + } if(! $err) { $password = hash('whirlpool',$newpass); @@ -395,10 +397,11 @@ function settings_post(App $a) { dbesc($password), intval(local_user()) ); - if($r) + if($r) { info( t('Password changed.') . EOL); - else + } else { notice( t('Password update failed. Please try again.') . EOL); + } } } From 63e4750b4abfd0ce80caf65b20d73d9ec9ef756f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 09:50:25 +0100 Subject: [PATCH 03/55] more coding convention applied: - added curly braces - added spaces where needed - $r only needs to be tested with dbm::is_result() - made SQL keywords all uper-case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/contacts.php | 18 +++++++++++------- mod/crepair.php | 18 +++++++++++------- mod/message.php | 3 ++- mod/profiles.php | 10 ++++++---- mod/settings.php | 7 ++++--- mod/wall_upload.php | 8 ++++---- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/mod/contacts.php b/mod/contacts.php index a2a77e2a5..70f4b7350 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -136,8 +136,7 @@ function contacts_batch_actions(App $a) { if (x($_SESSION,'return_url')) { goaway('' . $_SESSION['return_url']); - } - else { + } else { goaway('contacts'); } @@ -194,8 +193,10 @@ function contacts_post(App $a) { $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist'])); $priority = intval($_POST['poll']); - if($priority > 5 || $priority < 0) + + if ($priority > 5 || $priority < 0) { $priority = 0; + } $info = escape_tags(trim($_POST['info'])); @@ -212,17 +213,20 @@ function contacts_post(App $a) { intval($contact_id), intval(local_user()) ); - if($r) + if ($r) { info( t('Contact updated.') . EOL); - else + } else { notice( t('Failed to update contact record.') . EOL); + } - $r = q("select * from contact where id = %d and uid = %d limit 1", + $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval(local_user()) ); - if($r && dbm::is_result($r)) + + if (dbm::is_result($r)) { $a->data['contact'] = $r[0]; + } return; diff --git a/mod/crepair.php b/mod/crepair.php index 902a12930..ef7908661 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -20,10 +20,11 @@ function crepair_init(App $a) { } } - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) { $a->page['aside'] = ''; + } - if($contact_id) { + if ($contact_id) { $a->data['contact'] = $r[0]; $contact = $r[0]; profile_load($a, "", 0, get_contact_details_by_url($contact["url"])); @@ -35,9 +36,12 @@ function crepair_post(App $a) { return; } + // Init $r here if $cid is not set + $r = false; + $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if($cid) { + if ($cid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($cid), intval(local_user()) @@ -78,18 +82,18 @@ function crepair_post(App $a) { local_user() ); - if($photo) { + if ($photo) { logger('mod-crepair: updating photo from ' . $photo); require_once("include/Photo.php"); update_contact_avatar($photo,local_user(),$contact['id']); } - if($r) + if ($r) { info( t('Contact settings applied.') . EOL); - else + } else { notice( t('Contact update failed.') . EOL); - + } return; } diff --git a/mod/message.php b/mod/message.php index 9e9669146..df5b4709b 100644 --- a/mod/message.php +++ b/mod/message.php @@ -251,8 +251,9 @@ function message_content(App $a) { // ); //} - if($r) + if ($r) { info( t('Conversation removed.') . EOL ); + } } //goaway(App::get_baseurl(true) . '/message' ); goaway($_SESSION['return_url']); diff --git a/mod/profiles.php b/mod/profiles.php index 4c6ff926b..e359e9efb 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -34,8 +34,9 @@ function profiles_init(App $a) { intval($a->argv[2]), intval(local_user()) ); - if($r) + if ($r) { info(t('Profile deleted.').EOL); + } goaway('profiles'); return; // NOTREACHED @@ -473,11 +474,12 @@ function profiles_post(App $a) { intval(local_user()) ); - if($r) + if ($r) { info( t('Profile updated.') . EOL); + } - if($namechanged && $is_default) { + if ($namechanged && $is_default) { $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), @@ -489,7 +491,7 @@ function profiles_post(App $a) { ); } - if($is_default) { + if ($is_default) { $location = formatted_location(array("locality" => $locality, "region" => $region, "country-name" => $country_name)); q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d", diff --git a/mod/settings.php b/mod/settings.php index 94b93f9b9..b77b1336d 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -397,7 +397,7 @@ function settings_post(App $a) { dbesc($password), intval(local_user()) ); - if($r) { + if ($r) { info( t('Password changed.') . EOL); } else { notice( t('Password update failed. Please try again.') . EOL); @@ -602,8 +602,9 @@ function settings_post(App $a) { dbesc($language), intval(local_user()) ); - if($r) + if ($r) { info( t('Settings updated.') . EOL); + } // clear session language unset($_SESSION['language']); @@ -622,7 +623,7 @@ function settings_post(App $a) { ); - if($name_change) { + if ($name_change) { q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self`", dbesc($username), dbesc(datetime_convert()), diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 1f71f36b6..fa30a8ad3 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -228,14 +228,14 @@ function wall_upload_post(App $a, $desktopmode = true) { if($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm); - if($r) + if ($r) $smallest = 1; } - if($width > 320 || $height > 320) { + if ($width > 320 || $height > 320) { $ph->scaleImage(320); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm); - if($r AND ($smallest == 0)) + if ($r AND ($smallest == 0)) $smallest = 2; } @@ -244,7 +244,7 @@ function wall_upload_post(App $a, $desktopmode = true) { if (!$desktopmode) { $r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` WHERE `resource-id` = '%s' ORDER BY `width` DESC LIMIT 1", $hash); - if (!$r){ + if (!dbm::is_result($r)) { if ($r_json) { echo json_encode(array('error'=>'')); killme(); From 0b6336edb0fc44b14ba9836ed63015d7d763841a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 10:14:48 +0100 Subject: [PATCH 04/55] unified most db upgrades: - common way is to check on result ($r mostly) of db upgrade - on success, return UPDATE_SUCCESS - on failure, return UPDATE_FAILED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 344 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 214 insertions(+), 130 deletions(-) diff --git a/update.php b/update.php index 64259bbb1..242fd1454 100644 --- a/update.php +++ b/update.php @@ -37,7 +37,7 @@ define('UPDATE_VERSION' , 1215); */ - +/// @TODO These old updates need to have UPDATE_SUCCESS returned on success? function update_1000() { q("ALTER TABLE `item` DROP `like`, DROP `dislike` "); @@ -308,7 +308,7 @@ function update_1030() { function update_1031() { // Repair any bad links that slipped into the item table $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); - if($r && dbm::is_result($r)) { + if (dbm::is_result($r)) { foreach ($r as $rr) { if(strstr($rr['object'],'type="http')) { q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", @@ -368,13 +368,11 @@ function update_1036() { } function update_1037() { - q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL "); - } function update_1038() { - q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); + q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); } function update_1039() { @@ -532,8 +530,10 @@ function update_1065() { function update_1066() { $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` "); - if($r) + + if ($r) { q("ALTER TABLE `item` ADD INDEX ( `received` ) "); + } $r = q("UPDATE `item` SET `received` = `edited` WHERE 1"); } @@ -567,6 +567,7 @@ function update_1069() { q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` "); } +/// @TODO Still meeded? // mail body needs to accomodate private photos function update_1070() { @@ -614,8 +615,9 @@ function update_1075() { $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", dbesc($guid) ); - if(! count($x)) + if (!dbm::is_result($x)) { $found = false; + } } while ($found == true ); q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d", @@ -684,14 +686,19 @@ function update_1082() { q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`, ADD INDEX ( `guid` ) "); // make certain the following code is only executed once - $r = q("select `id` from `photo` where `guid` != '' limit 1"); - if (dbm::is_result($r)) + + $r = q("SELECT `id` FROM `photo` WHERE `guid` != '' LIMIT 1"); + + if (dbm::is_result($r)) { return; + } + $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`"); + if (dbm::is_result($r)) { foreach ($r as $rr) { $guid = get_guid(); - q("update `photo` set `guid` = '%s' where `resource-id` = '%s'", + q("UPDATE `photo` SET `guid` = '%s' WHERE `resource-id` = '%s'", dbesc($guid), dbesc($rr['resource-id']) ); @@ -736,11 +743,13 @@ function update_1087() { $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1", intval($rr['id']) ); - if(count($x)) + + if (dbm::is_result($x)) { q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d", dbesc($x[0]['cdate']), intval($rr['id']) ); + } } } } @@ -849,14 +858,14 @@ function update_1099() { function update_1100() { q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` "); - q("alter table contact add index (`nurl`) "); + q("ALTER TABLE `contact` ADD INDEX (`nurl`) "); require_once('include/text.php'); - $r = q("select id, url from contact where url != '' and nurl = '' "); + $r = q("SELECT `id`, `url` FROM `contact` WHERE `url` != '' AND `nurl` = '' "); if (dbm::is_result($r)) { foreach ($r as $rr) { - q("update contact set nurl = '%s' where id = %d", + q("UPDATE `contact` SET `nurl` = '%s' WHERE `id` = %d", dbesc(normalise_link($rr['url'])), intval($rr['id']) ); @@ -886,6 +895,7 @@ function update_1102() { function update_1103() { +/// @TODO Comented out: // q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); @@ -1031,9 +1041,11 @@ function update_1120() { $r = q("describe item"); if (dbm::is_result($r)) { - foreach($r as $rr) - if($rr['Field'] == 'spam') + foreach($r as $rr) { + if ($rr['Field'] == 'spam') { return; + } + } } q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) "); @@ -1067,16 +1079,16 @@ function update_1121() { } function update_1122() { -q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , + q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `hash` ) "); } function update_1123() { -set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); + set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); } function update_1124() { -q("alter table item add index (`author-name`) "); + q("ALTER TABLE `item` ADD INDEX (`author-name`) "); } function update_1125() { @@ -1112,7 +1124,7 @@ function update_1127() { function update_1128() { - q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` "); + q("ALTER TABLE `spam` ADD `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` "); } function update_1129() { @@ -1138,9 +1150,9 @@ INDEX ( `username` ) } function update_1133() { -q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); -q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); -q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); + q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); + q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); + q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); } function update_1134() { @@ -1167,38 +1179,38 @@ function update_1136() { // order in reverse so that we save the newest entry - $r = q("select * from config where 1 order by id desc"); + $r = q("SELECT * FROM `config` WHERE 1 ORDER BY `id` DESC"); if (dbm::is_result($r)) { foreach ($r as $rr) { $found = false; - foreach($arr as $x) { - if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { + foreach ($arr as $x) { + if ($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { $found = true; - q("delete from config where id = %d", + q("DELETE FROM `config` WHERE `id` = %d", intval($rr['id']) ); } } - if(! $found) { + if (! $found) { $arr[] = $rr; } } } $arr = array(); - $r = q("select * from pconfig where 1 order by id desc"); + $r = q("SELECT * FROM `pconfig` WHERE 1 ORDER BY `id` DESC"); if (dbm::is_result($r)) { foreach ($r as $rr) { $found = false; - foreach($arr as $x) { - if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { + foreach ($arr as $x) { + if ($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { $found = true; - q("delete from pconfig where id = %d", + q("DELETE FROM `pconfig` WHERE `id` = %d", intval($rr['id']) ); } } - if(! $found) { + if (! $found) { $arr[] = $rr; } } @@ -1210,102 +1222,138 @@ function update_1136() { function update_1137() { - q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); - q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) "); + q("ALTER TABLE `item_id` DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); + q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , ADD INDEX (`sid`), ADD INDEX ( `service`) "); } function update_1138() { - q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)"); + q("ALTER TABLE `contact` ADD `archive` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hidden`, ADD INDEX (`archive`)"); } function update_1139() { - $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `user` ADD `account_removed` TINYINT(1) NOT NULL DEFAULT '0' AFTER `expire`, ADD INDEX(`account_removed`)"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1140() { - $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `addon` ADD `hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `installed`, ADD INDEX(`hidden`) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1141() { - $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `glink` ADD `zcid` INT(11) NOT NULL AFTER `gcid`, ADD INDEX(`zcid`) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1142() { - $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `user` ADD `service_class` CHAR(32) NOT NULL AFTER `expire_notification_sent`, ADD INDEX(`service_class`) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1143() { - $r = q("alter table user add def_gid int(11) not null default '0' after service_class"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `user` ADD `def_gid` INT(11) NOT NULL DEFAULT '0' AFTER `service_class`"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1144() { - $r = q("alter table contact add prv tinyint(1) not null default '0' after forum"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `contact` ADD `prv` TINYINT(1) NOT NULL DEFAULT '0' AFTER `forum`"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1145() { - $r = q("alter table profile add howlong datetime not null default '0000-00-00 00:00:00' after `with`"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `profile` ADD `howlong` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `with`"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1146() { - $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1147() { $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'"); $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`"); $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )"); - if((! $r1) || (! $r2) || (! $r3)) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + + if ($r1 && $r2 && $r3) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1148() { $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1149() { $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords"); $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes"); - if (! ($r1 && $r2)) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r1 && $r2) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1150() { $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) "); - if(! $r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } @@ -1315,9 +1363,12 @@ function update_1151() { name CHAR( 128 ) NOT NULL , locked TINYINT( 1 ) NOT NULL DEFAULT '0' ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1152() { @@ -1333,23 +1384,32 @@ function update_1152() { KEY `type` ( `type` ), KEY `term` ( `term` ) ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1153() { $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'"); - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1154() { $r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )"); - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1155() { @@ -1357,8 +1417,9 @@ function update_1155() { $r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); $r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) "); - if($r1 && $r2 && $r3) + if ($r1 && $r2 && $r3) { return UPDATE_SUCCESS; + } return UPDATE_FAILED; } @@ -1367,12 +1428,15 @@ function update_1156() { $r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` , ADD INDEX ( `datasize` ) "); - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1157() { - $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( + $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `uid` int(11) NOT NULL, `msg` mediumtext NOT NULL, @@ -1381,8 +1445,11 @@ function update_1157() { ) ENGINE=MyISAM DEFAULT CHARSET=utf8" ); - if($r) + if ($r) { return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1158() { @@ -1395,8 +1462,9 @@ function update_1158() { $r = q("CREATE INDEX event_id ON item(`event-id`)"); set_config('system', 'maintenance', 0); - if($r) + if ($r) { return UPDATE_SUCCESS; + } return UPDATE_FAILED; } @@ -1407,10 +1475,11 @@ function update_1159() { ADD INDEX (`uid`), ADD INDEX (`aid`)"); - if(!$r) - return UPDATE_FAILED; + if ($r) { + return UPDATE_SUCCESS; + } - return UPDATE_SUCCESS; + return UPDATE_FAILED; } function update_1160() { @@ -1423,19 +1492,21 @@ function update_1160() { $r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)"); set_config('system', 'maintenance', 0); - if(!$r) - return UPDATE_FAILED; + if ($r) { + return UPDATE_SUCCESS; + } - return UPDATE_SUCCESS; + return UPDATE_FAILED; } function update_1161() { $r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)"); - if(!$r) - return UPDATE_FAILED; + if ($r) { + return UPDATE_SUCCESS; + } - return UPDATE_SUCCESS; + return UPDATE_FAILED; } function update_1162() { @@ -1451,14 +1522,17 @@ function update_1163() { $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL"); set_config('system', 'maintenance', 0); - if(!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1164() { set_config('system', 'maintenance', 1); + /// @TODO If one update fails, should it continue? $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '' AND `contact`.`uid` = `item`.`uid`)", NETWORK_DFRN); @@ -1511,19 +1585,21 @@ function update_1164() { function update_1165() { $r = q("CREATE TABLE IF NOT EXISTS `push_subscriber` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `uid` INT NOT NULL, - `callback_url` CHAR( 255 ) NOT NULL, - `topic` CHAR( 255 ) NOT NULL, - `nickname` CHAR( 255 ) NOT NULL, - `push` INT NOT NULL, - `last_update` DATETIME NOT NULL, - `secret` CHAR( 255 ) NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + `uid` INT NOT NULL, + `callback_url` CHAR( 255 ) NOT NULL, + `topic` CHAR( 255 ) NOT NULL, + `nickname` CHAR( 255 ) NOT NULL, + `push` INT NOT NULL, + `last_update` DATETIME NOT NULL, + `secret` CHAR( 255 ) NOT NULL + ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1166() { @@ -1535,26 +1611,32 @@ function update_1166() { `avatar` CHAR(255) NOT NULL, INDEX (`url`) ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1167() { $r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1168() { $r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1169() { @@ -1592,8 +1674,10 @@ function update_1169() { KEY `uid_created` (`uid`,`created`), KEY `uid_commented` (`uid`,`commented`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - if (!$r) + + if (!$r) { return UPDATE_FAILED; + } proc_run(PRIORITY_LOW, "include/threadupdate.php"); From 4adf74b06c0a96c3169c59b3cc66b4212930d3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 10:27:05 +0100 Subject: [PATCH 05/55] more coding convention applied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/update.php b/update.php index 242fd1454..fd6548d9a 100644 --- a/update.php +++ b/update.php @@ -1302,7 +1302,7 @@ function update_1145() { } function update_1146() { - $r = q("ALTER TABLE profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); + $r = q("ALTER TABLE `profile` ADD `hometown` CHAR(255) NOT NULL AFTER `country-name`, ADD INDEX ( `hometown` ) "); if ($r) { return UPDATE_SUCCESS ; @@ -1324,7 +1324,7 @@ function update_1147() { } function update_1148() { - $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename"); + $r = q("ALTER TABLE `photo` ADD `type` CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER `filename`"); if ($r) { return UPDATE_SUCCESS ; @@ -1335,8 +1335,8 @@ function update_1148() { function update_1149() { - $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords"); - $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes"); + $r1 = q("ALTER TABLE `profile` ADD `likes` TEXT NOT NULL AFTER `prv_keywords`"); + $r2 = q("ALTER TABLE `profile` ADD `dislikes` TEXT NOT NULL AFTER `likes`"); if ($r1 && $r2) { return UPDATE_SUCCESS; @@ -1347,7 +1347,7 @@ function update_1149() { function update_1150() { - $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) "); + $r = q("ALTER TABLE `event` ADD `summary` TEXT NOT NULL AFTER `finish`, ADD INDEX ( `uid` ), ADD INDEX ( `cid` ), ADD INDEX ( `uri` ), ADD INDEX ( `start` ), ADD INDEX ( `finish` ), ADD INDEX ( `type` ), ADD INDEX ( `adjust` ) "); if ($r) { return UPDATE_SUCCESS ; @@ -1358,10 +1358,10 @@ function update_1150() { function update_1151() { - $r = q("CREATE TABLE IF NOT EXISTS locks ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - name CHAR( 128 ) NOT NULL , - locked TINYINT( 1 ) NOT NULL DEFAULT '0' + $r = q("CREATE TABLE IF NOT EXISTS `locks` ( + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `name` CHAR( 128 ) NOT NULL , + `locked` TINYINT( 1 ) NOT NULL DEFAULT '0' ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); if ($r) { From 92901d86269903ddab993b85bab2d6ec075630d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 10:49:08 +0100 Subject: [PATCH 06/55] more curly braces added + dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 100 +++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 2c4b677a5..3e285a783 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -104,24 +104,29 @@ class ostatus { // $contact["poll"] = $value; $value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["alias"] = $value; + } $value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["name"] = $value; + } $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["nick"] = $value; + } $value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["about"] = html2bbcode($value); + } $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["location"] = $value; + } if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["alias"] != $r[0]["alias"]) OR ($contact["location"] != $r[0]["location"])) { @@ -179,8 +184,9 @@ class ostatus { */ public static function salmon_author($xml, $importer) { - if ($xml == "") + if ($xml == "") { return; + } $doc = new DOMDocument(); @$doc->loadXML($xml); @@ -217,8 +223,9 @@ class ostatus { logger("Import OStatus message", LOGGER_DEBUG); - if ($xml == "") + if ($xml == "") { return; + } //$tempfile = tempnam(get_temppath(), "import"); //file_put_contents($tempfile, $xml); @@ -238,12 +245,14 @@ class ostatus { $gub = ""; $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; - if (is_object($hub_attributes)) - foreach($hub_attributes AS $hub_attribute) + if (is_object($hub_attributes)) { + foreach($hub_attributes AS $hub_attribute) { if ($hub_attribute->name == "href") { $hub = $hub_attribute->textContent; logger("Found hub ".$hub, LOGGER_DEBUG); } + } + } $header = array(); $header["uid"] = $importer["uid"]; @@ -257,10 +266,11 @@ class ostatus { // depending on that, the first node is different $first_child = $doc->firstChild->tagName; - if ($first_child == "feed") + if ($first_child == "feed") { $entries = $xpath->query('/atom:feed/atom:entry'); - else + } else { $entries = $xpath->query('/atom:entry'); + } $conversation = ""; $conversationlist = array(); @@ -277,16 +287,18 @@ class ostatus { $mention = false; // fetch the author - if ($first_child == "feed") + if ($first_child == "feed") { $author = self::fetchauthor($xpath, $doc->firstChild, $importer, $contact, false); - else + } else { $author = self::fetchauthor($xpath, $entry, $importer, $contact, false); + } $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $nickname = $value; - else + } else { $nickname = $author["author-name"]; + } $item = array_merge($header, $author); @@ -295,7 +307,7 @@ class ostatus { $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["uri"])); - if ($r) { + if (dbm::is_result($r)) { logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); continue; } @@ -306,8 +318,9 @@ class ostatus { if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; $item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue; - } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) + } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; + } $item["object"] = $xml; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; @@ -352,8 +365,9 @@ class ostatus { } // http://activitystrea.ms/schema/1.0/rsvp-yes - if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) + if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) { logger("Unhandled verb ".$item["verb"]." ".print_r($item, true)); + } $item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; $item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; @@ -364,10 +378,12 @@ class ostatus { $inreplyto = $xpath->query('thr:in-reply-to', $entry); if (is_object($inreplyto->item(0))) { foreach($inreplyto->item(0)->attributes AS $attributes) { - if ($attributes->name == "ref") + if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; - if ($attributes->name == "href") + } + if ($attributes->name == "href") { $related = $attributes->textContent; + } } } @@ -411,7 +427,7 @@ class ostatus { if ($attributes->name == "title") $title = $attributes->textContent; } - if (($rel != "") AND ($href != "")) + if (($rel != "") AND ($href != "")) { switch($rel) { case "alternate": $item["plink"] = $href; @@ -448,6 +464,7 @@ class ostatus { $mention = true; break; } + } } } @@ -457,12 +474,15 @@ class ostatus { $notice_info = $xpath->query('statusnet:notice_info', $entry); if ($notice_info AND ($notice_info->length > 0)) { foreach($notice_info->item(0)->attributes AS $attributes) { - if ($attributes->name == "source") + if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); - if ($attributes->name == "local_id") + } + if ($attributes->name == "local_id") { $local_id = $attributes->textContent; - if ($attributes->name == "repeat_of") + } + if ($attributes->name == "repeat_of") { $repeat_of = $attributes->textContent; + } } } @@ -473,24 +493,32 @@ class ostatus { if (is_object($activityobjects)) { $orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue; - if (!isset($orig_uri)) + if (!isset($orig_uri)) { $orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue; + } $orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects); - if ($orig_links AND ($orig_links->length > 0)) - foreach($orig_links->item(0)->attributes AS $attributes) - if ($attributes->name == "href") + if ($orig_links AND ($orig_links->length > 0)) { + foreach ($orig_links->item(0)->attributes AS $attributes) { + if ($attributes->name == "href") { $orig_link = $attributes->textContent; + } + } + } - if (!isset($orig_link)) + if (!isset($orig_link)) { $orig_link = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue; + } - if (!isset($orig_link)) + if (!isset($orig_link)) { $orig_link = self::convert_href($orig_uri); + } $orig_body = $xpath->query('activity:object/atom:content/text()', $activityobjects)->item(0)->nodeValue; - if (!isset($orig_body)) + + if (!isset($orig_body)) { $orig_body = $xpath->query('atom:content/text()', $activityobjects)->item(0)->nodeValue; + } $orig_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue; $orig_edited = $xpath->query('atom:updated/text()', $activityobjects)->item(0)->nodeValue; @@ -511,8 +539,10 @@ class ostatus { $item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue; $item["object-type"] = $xpath->query('activity:object/activity:object-type/text()', $activityobjects)->item(0)->nodeValue; - if (!isset($item["object-type"])) + + if (!isset($item["object-type"])) { $item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue; + } } } @@ -540,12 +570,14 @@ class ostatus { intval($importer["uid"]), dbesc($item["parent-uri"])); } } - if ($r) { + + if (dbm::is_result($r)) { $item["type"] = 'remote-comment'; $item["gravity"] = GRAVITY_COMMENT; } - } else + } else { $item["parent-uri"] = $item["uri"]; + } $item_id = self::completion($conversation, $importer["uid"], $item, $self); From 5471dd79e89821909649b37e4f88d42f897e27a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jan 2017 17:50:49 +0100 Subject: [PATCH 07/55] added missing curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/wall_upload.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mod/wall_upload.php b/mod/wall_upload.php index fa30a8ad3..b793c9e40 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -215,7 +215,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); - if(! $r) { + if (! $r) { $msg = t('Image upload failed.'); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -225,18 +225,20 @@ function wall_upload_post(App $a, $desktopmode = true) { killme(); } - if($width > 640 || $height > 640) { + if ($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm); - if ($r) + if ($r) { $smallest = 1; + } } if ($width > 320 || $height > 320) { $ph->scaleImage(320); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm); - if ($r AND ($smallest == 0)) + if ($r AND ($smallest == 0)) { $smallest = 2; + } } $basename = basename($filename); From 108a2ccbd52942919cc4575ecaf7cdf91406d3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jan 2017 17:55:31 +0100 Subject: [PATCH 08/55] added more spaces/curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/update.php b/update.php index fd6548d9a..8f581559d 100644 --- a/update.php +++ b/update.php @@ -567,7 +567,6 @@ function update_1069() { q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` "); } -/// @TODO Still meeded? // mail body needs to accomodate private photos function update_1070() { @@ -596,7 +595,7 @@ function update_1074() { q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` "); $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1"); if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d", intval($rr['uid']) ); @@ -895,7 +894,7 @@ function update_1102() { function update_1103() { -/// @TODO Comented out: +/// @TODO Commented out: // q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); @@ -1041,7 +1040,7 @@ function update_1120() { $r = q("describe item"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if ($rr['Field'] == 'spam') { return; } From 55e2411f07cba19b3e9c38497ff5be7e49e3412f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jan 2017 17:57:45 +0100 Subject: [PATCH 09/55] even more added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/update.php b/update.php index 8f581559d..61410e89e 100644 --- a/update.php +++ b/update.php @@ -157,14 +157,15 @@ function update_1014() { $r = q("SELECT * FROM `contact` WHERE 1"); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(stristr($rr['thumb'],'avatar')) + if (stristr($rr['thumb'],'avatar')) { q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('avatar','micro',$rr['thumb'])), intval($rr['id'])); - else + } else { q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])), intval($rr['id'])); + } } } } @@ -595,10 +596,11 @@ function update_1074() { q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` "); $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1"); if (dbm::is_result($r)) { - foreach ($r as $rr) + foreach ($r as $rr) { q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d", intval($rr['uid']) ); + } } q("ALTER TABLE `profile` DROP `hidewall`"); } @@ -1782,19 +1784,22 @@ function update_1190() { $key = $rr['k']; $value = $rr['v']; - if ($key === 'randomise') + if ($key === 'randomise') { del_pconfig($uid,$family,$key); + } if ($key === 'show_on_profile') { - if ($value) + if ($value) { set_pconfig($uid,feature,forumlist_profile,$value); + } del_pconfig($uid,$family,$key); } if ($key === 'show_on_network') { - if ($value) + if ($value) { set_pconfig($uid,feature,forumlist_widget,$value); + } del_pconfig($uid,$family,$key); } From 3849e7c9ff8d3cbe097714e4811ed4c92a780f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 25 Jan 2017 15:59:27 +0100 Subject: [PATCH 10/55] added more curly braces + a bit more usage of dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 235 +++++++++++++++++++++++++++---------------- mod/dfrn_confirm.php | 13 +-- mod/profiles.php | 5 +- update.php | 2 +- util/po2php.php | 2 +- 5 files changed, 160 insertions(+), 97 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 39372aef1..cd1fef904 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -637,18 +637,24 @@ class dfrn { $entry = $doc->createElement($element); $r = parse_xml_string($activity, false); - if(!$r) + if (!$r) { return false; - if($r->type) + } + if ($r->type) { xml::add_element($doc, $entry, "activity:object-type", $r->type); - if($r->id) + } + if ($r->id) { xml::add_element($doc, $entry, "id", $r->id); - if($r->title) + } + if ($r->title) { xml::add_element($doc, $entry, "title", $r->title); - if($r->link) { - if(substr($r->link,0,1) == '<') { - if(strstr($r->link,'&') && (! strstr($r->link,'&'))) + } + + if ($r->link) { + if (substr($r->link,0,1) == '<') { + if (strstr($r->link,'&') && (! strstr($r->link,'&'))) { $r->link = str_replace('&','&', $r->link); + } $r->link = preg_replace('/\/','',$r->link); @@ -657,8 +663,9 @@ class dfrn { if (is_object($data)) { foreach ($data->link AS $link) { $attributes = array(); - foreach ($link->attributes() AS $parameter => $value) + foreach ($link->attributes() AS $parameter => $value) { $attributes[$parameter] = $value; + } xml::add_element($doc, $entry, "link", "", $attributes); } } @@ -667,8 +674,9 @@ class dfrn { xml::add_element($doc, $entry, "link", "", $attributes); } } - if($r->content) + if ($r->content) { xml::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html")); + } return $entry; } @@ -687,20 +695,22 @@ class dfrn { */ private static function get_attachment($doc, $root, $item) { $arr = explode('[/attach],',$item['attach']); - if(count($arr)) { - foreach($arr as $r) { + if (count($arr)) { + foreach ($arr as $r) { $matches = false; $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); - if($cnt) { + if ($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); - if(intval($matches[2])) + if (intval($matches[2])) { $attributes["length"] = intval($matches[2]); + } - if(trim($matches[4]) != "") + if (trim($matches[4]) != "") { $attributes["title"] = trim($matches[4]); + } xml::add_element($doc, $root, "link", "", $attributes); } @@ -724,20 +734,22 @@ class dfrn { $mentioned = array(); - if(!$item['parent']) + if (!$item['parent']) { return; + } - if($item['deleted']) { + if ($item['deleted']) { $attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)); return xml::create_element($doc, "at:deleted-entry", "", $attributes); } $entry = $doc->createElement("entry"); - if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) + if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); - else + } else { $body = $item['body']; + } // Remove the abstract element. It is only locally important. $body = remove_abstract($body); @@ -745,8 +757,9 @@ class dfrn { if ($type == 'html') { $htmlbody = $body; - if ($item['title'] != "") + if ($item['title'] != "") { $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; + } $htmlbody = bbcode($htmlbody, false, false, 7); } @@ -757,7 +770,7 @@ class dfrn { $dfrnowner = self::add_entry_author($doc, "dfrn:owner", $item["owner-link"], $item); $entry->appendChild($dfrnowner); - if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { + if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $attributes = array("ref" => $parent_item, "type" => "text/html", @@ -785,26 +798,33 @@ class dfrn { // "comment-allow" is some old fashioned stuff for old Friendica versions. // It is included in the rewritten code for completeness - if ($comment) + if ($comment) { xml::add_element($doc, $entry, "dfrn:comment-allow", intval($item['last-child'])); + } - if($item['location']) + if ($item['location']) { xml::add_element($doc, $entry, "dfrn:location", $item['location']); + } - if($item['coord']) + if ($item['coord']) { xml::add_element($doc, $entry, "georss:point", $item['coord']); + } - if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) + if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { xml::add_element($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1)); + } - if($item['extid']) + if ($item['extid']) { xml::add_element($doc, $entry, "dfrn:extid", $item['extid']); + } - if($item['bookmark']) + if ($item['bookmark']) { xml::add_element($doc, $entry, "dfrn:bookmark", "true"); + } - if($item['app']) + if ($item['app']) { xml::add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app'])); + } xml::add_element($doc, $entry, "dfrn:diaspora_guid", $item["guid"]); @@ -817,46 +837,56 @@ class dfrn { xml::add_element($doc, $entry, "activity:verb", construct_verb($item)); - if ($item['object-type'] != "") + if ($item['object-type'] != "") { xml::add_element($doc, $entry, "activity:object-type", $item['object-type']); - elseif ($item['id'] == $item['parent']) + } elseif ($item['id'] == $item['parent']) { xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); - else + } else { xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT); + } $actobj = self::create_activity($doc, "activity:object", $item['object']); - if ($actobj) + if ($actobj) { $entry->appendChild($actobj); + } $actarg = self::create_activity($doc, "activity:target", $item['target']); - if ($actarg) + if ($actarg) { $entry->appendChild($actarg); + } $tags = item_getfeedtags($item); - if(count($tags)) { - foreach($tags as $t) - if (($type != 'html') OR ($t[0] != "@")) + if( count($tags)) { + foreach ($tags as $t) { + if (($type != 'html') OR ($t[0] != "@")) { xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2])); + } + } } - if(count($tags)) - foreach($tags as $t) - if ($t[0] == "@") + if (count($tags)) { + foreach($tags as $t) { + if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; + } + } + } foreach ($mentioned AS $mention) { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); - if ($r[0]["forum"] OR $r[0]["prv"]) + + if ($r[0]["forum"] OR $r[0]["prv"]) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); - else + } else { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); + } } self::get_attachment($doc, $entry, $item); @@ -880,16 +910,20 @@ class dfrn { $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); - if($contact['duplex'] && $contact['dfrn-id']) + if ($contact['duplex'] && $contact['dfrn-id']) { $idtosend = '0:' . $orig_id; - if($contact['duplex'] && $contact['issued-id']) + } + if ($contact['duplex'] && $contact['issued-id']) { $idtosend = '1:' . $orig_id; - + } $rino = get_config('system','rino_encrypt'); $rino = intval($rino); + // use RINO1 if mcrypt isn't installed and RINO2 was selected - if ($rino==2 and !function_exists('mcrypt_create_iv')) $rino=1; + if ($rino==2 and !function_exists('mcrypt_create_iv')) { + $rino=1; + } logger("Local rino version: ". $rino, LOGGER_DEBUG); @@ -928,10 +962,11 @@ class dfrn { logger('dfrn_deliver: ' . $xml, LOGGER_DATA); - if(! $xml) + if (! $xml) { return 3; + } - if(strpos($xml,'status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) + if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { return (($res->status) ? $res->status : 3); + } $postvars = array(); $sent_dfrn_id = hex2bin((string) $res->dfrn_id); @@ -952,13 +988,14 @@ class dfrn { logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG); - if($owner['page-flags'] == PAGE_PRVGROUP) + if ($owner['page-flags'] == PAGE_PRVGROUP) { $page = 2; + } $final_dfrn_id = ''; - if($perm) { - if((($perm == 'rw') && (! intval($contact['writable']))) + if ($perm) { + if ((($perm == 'rw') && (! intval($contact['writable']))) || (($perm == 'r') && (intval($contact['writable'])))) { q("update contact set writable = %d where id = %d", intval(($perm == 'rw') ? 1 : 0), @@ -968,7 +1005,7 @@ class dfrn { } } - if(($contact['duplex'] && strlen($contact['pubkey'])) + if (($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']); @@ -980,10 +1017,11 @@ class dfrn { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if(strpos($final_dfrn_id,':') == 1) + if (strpos($final_dfrn_id,':') == 1) { $final_dfrn_id = substr($final_dfrn_id,2); + } - if($final_dfrn_id != $orig_id) { + if ($final_dfrn_id != $orig_id) { logger('dfrn_deliver: wrong dfrn_id.'); // did not decode properly - cannot trust this site return 3; @@ -991,11 +1029,12 @@ class dfrn { $postvars['dfrn_id'] = $idtosend; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; - if($dissolve) + if ($dissolve) { $postvars['dissolve'] = '1'; + } - if((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { + if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { $postvars['data'] = $atom; $postvars['perm'] = 'rw'; } else { @@ -1005,11 +1044,12 @@ class dfrn { $postvars['ssl_policy'] = $ssl_policy; - if($page) + if ($page) { $postvars['page'] = $page; + } - if($rino>0 && $rino_remote_version>0 && (! $dissolve)) { + if ($rino>0 && $rino_remote_version>0 && (! $dissolve)) { logger('rino version: '. $rino_remote_version); switch($rino_remote_version) { @@ -1047,23 +1087,25 @@ class dfrn { $postvars['rino'] = $rino_remote_version; $postvars['data'] = bin2hex($data); - #logger('rino: sent key = ' . $key, LOGGER_DEBUG); + //logger('rino: sent key = ' . $key, LOGGER_DEBUG); - if($dfrn_version >= 2.1) { - if(($contact['duplex'] && strlen($contact['pubkey'])) + if ($dfrn_version >= 2.1) { + if (($contact['duplex'] && strlen($contact['pubkey'])) { || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); - else + } else { openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); + } } else { - if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) + if (($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); - else + } else { openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); + } } @@ -1088,13 +1130,13 @@ class dfrn { return -10; } - if(strpos($xml,'attributes AS $attributes) { - if ($attributes->name == "href") + if ($attributes->name == "href") { $href = $attributes->textContent; - if ($attributes->name == "width") + } + if ($attributes->name == "width") { $width = $attributes->textContent; - if ($attributes->name == "updated") + } + if ($attributes->name == "updated") { $contact["avatar-date"] = $attributes->textContent; + } } - if (($width > 0) AND ($href != "")) + if (($width > 0) AND ($href != "")) { $avatarlist[$width] = $href; + } } if (count($avatarlist) > 0) { krsort($avatarlist); @@ -1208,40 +1255,50 @@ class dfrn { // When was the last change to name or uri? $name_element = $xpath->query($element."/atom:name", $context)->item(0); - foreach($name_element->attributes AS $attributes) - if ($attributes->name == "updated") + foreach ($name_element->attributes AS $attributes) { + if ($attributes->name == "updated") { $poco["name-date"] = $attributes->textContent; + } + } $link_element = $xpath->query($element."/atom:link", $context)->item(0); - foreach($link_element->attributes AS $attributes) - if ($attributes->name == "updated") + foreach ($link_element->attributes AS $attributes) { + if ($attributes->name == "updated") { $poco["uri-date"] = $attributes->textContent; + } + } // Update contact data $value = $xpath->evaluate($element."/dfrn:handle/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["addr"] = $value; + } $value = $xpath->evaluate($element."/poco:displayName/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["name"] = $value; + } $value = $xpath->evaluate($element."/poco:preferredUsername/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["nick"] = $value; + } $value = $xpath->evaluate($element."/poco:note/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["about"] = $value; + } $value = $xpath->evaluate($element."/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["location"] = $value; + } /// @todo Only search for elements with "poco:type" = "xmpp" $value = $xpath->evaluate($element."/poco:ims/poco:value/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["xmpp"] = $value; + } /// @todo Add support for the following fields that we don't support by now in the contact table: /// - poco:utcOffset @@ -1257,17 +1314,20 @@ class dfrn { // If the contact isn't searchable then set the contact to "hidden". // Problem: This can be manually overridden by the user. - if ($hide) + if ($hide) { $contact["hidden"] = true; + } // Save the keywords into the contact table $tags = array(); $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); - foreach($tagelements AS $tag) + foreach ($tagelements AS $tag) { $tags[$tag->nodeValue] = $tag->nodeValue; + } - if (count($tags)) + if (count($tags)) { $poco["keywords"] = implode(", ", $tags); + } // "dfrn:birthday" contains the birthday converted to UTC $old_bdyear = $contact["bdyear"]; @@ -1297,13 +1357,15 @@ class dfrn { $contact = array_merge($contact, $poco); - if ($old_bdyear != $contact["bdyear"]) + if ($old_bdyear != $contact["bdyear"]) { self::birthday_event($contact, $birthday); + } // Get all field names $fields = array(); - foreach ($r[0] AS $field => $data) + foreach ($r[0] AS $field => $data) { $fields[$field] = $data; + } unset($fields["id"]); unset($fields["uid"]); @@ -1368,8 +1430,9 @@ class dfrn { * @return string XML string */ private static function transform_activity($xpath, $activity, $element) { - if (!is_object($activity)) + if (!is_object($activity)) { return ""; + } $obj_doc = new DOMDocument("1.0", "utf-8"); $obj_doc->formatOutput = true; diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index e2ce80627..7e14610e3 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -586,17 +586,18 @@ function dfrn_confirm_post(App $a, $handsfree = null) { dbesc($decrypted_source_url), intval($local_uid) ); - if(! count($ret)) { - if(strstr($decrypted_source_url,'http:')) + if (!dbm::is_result($ret)) { + if (strstr($decrypted_source_url,'http:')) { $newurl = str_replace('http:','https:',$decrypted_source_url); - else + } else { $newurl = str_replace('https:','http:',$decrypted_source_url); + } $ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($newurl), intval($local_uid) ); - if(! count($ret)) { + if (!dbm::is_result($ret)) { // this is either a bogus confirmation (?) or we deleted the original introduction. $message = t('Contact record was not found for you on our site.'); xml_status(3,$message); @@ -611,7 +612,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $foreign_pubkey = $ret[0]['site-pubkey']; $dfrn_record = $ret[0]['id']; - if(! $foreign_pubkey) { + if (! $foreign_pubkey) { $message = sprintf( t('Site public key not available in contact record for URL %s.'), $newurl); xml_status(3,$message); } @@ -619,7 +620,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $decrypted_dfrn_id = ""; openssl_public_decrypt($dfrn_id,$decrypted_dfrn_id,$foreign_pubkey); - if(strlen($aes_key)) { + if (strlen($aes_key)) { $decrypted_aes_key = ""; openssl_private_decrypt($aes_key,$decrypted_aes_key,$my_prvkey); $dfrn_pubkey = openssl_decrypt($public_key,'AES-256-CBC',$decrypted_aes_key); diff --git a/mod/profiles.php b/mod/profiles.php index e359e9efb..282217208 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -264,13 +264,12 @@ function profiles_post(App $a) { } else { $newname = $lookup; -/* if(strstr($lookup,' ')) { +/* if (strstr($lookup,' ')) { $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval(local_user()) ); - } - else { + } else { $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", dbesc($lookup), intval(local_user()) diff --git a/update.php b/update.php index 61410e89e..bc0e17b8b 100644 --- a/update.php +++ b/update.php @@ -311,7 +311,7 @@ function update_1031() { $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(strstr($rr['object'],'type="http')) { + if (strstr($rr['object'],'type="http')) { q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", dbesc(str_replace('type="http','href="http',$rr['object'])), intval($rr['id']) diff --git a/util/po2php.php b/util/po2php.php index 30d77342b..5d3429796 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -12,7 +12,7 @@ function po2php_run(&$argv, &$argc) { $pofile = $argv[1]; $outfile = dirname($pofile)."/strings.php"; - if(strstr($outfile,'util')) + if (strstr($outfile,'util')) $lang = 'en'; else $lang = str_replace('-','_',basename(dirname($pofile))); From 6a171a96aa818acf38262a866b6ce2f24140ae53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 25 Jan 2017 16:02:02 +0100 Subject: [PATCH 11/55] Opps ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index cd1fef904..301735751 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1091,9 +1091,9 @@ class dfrn { if ($dfrn_version >= 2.1) { - if (($contact['duplex'] && strlen($contact['pubkey'])) { + if (($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) - || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) + || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); } else { From c6ef84a964839a41c03ba27afff7ce82da23be48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 09:38:52 +0100 Subject: [PATCH 12/55] Continued: - added missing space/curly braces - added TODOs for later adding a lot type-hints, without these (and they are long time around in PHP) anything can be handled over to the method/function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 435 ++++++++++++++++++++++++++++++----------------- 1 file changed, 281 insertions(+), 154 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 301735751..0c88d22c4 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -41,6 +41,7 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN entries + * @todo Add type-hints */ public static function entries($items,$owner) { @@ -49,10 +50,11 @@ class dfrn { $root = self::add_header($doc, $owner, "dfrn:owner", "", false); - if(! count($items)) + if (! count($items)) { return trim($doc->saveXML()); + } - foreach($items as $item) { + foreach ($items as $item) { $entry = self::entry($doc, "text", $item, $owner, $item["entry:comment-allow"], $item["entry:cid"]); $root->appendChild($entry); } @@ -82,14 +84,17 @@ class dfrn { $starred = false; // not yet implemented, possible security issues $converse = false; - if($public_feed && $a->argc > 2) { - for($x = 2; $x < $a->argc; $x++) { - if($a->argv[$x] == 'converse') + if ($public_feed && $a->argc > 2) { + for ($x = 2; $x < $a->argc; $x++) { + if ($a->argv[$x] == 'converse') { $converse = true; - if($a->argv[$x] == 'starred') + } + if ($a->argv[$x] == 'starred') { $starred = true; - if($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1])) + } + if ($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1])) { $category = $a->argv[$x+1]; + } } } @@ -115,7 +120,7 @@ class dfrn { $sql_post_table = ""; - if(! $public_feed) { + if (! $public_feed) { $sql_extra = ''; switch($direction) { @@ -148,12 +153,13 @@ class dfrn { require_once('include/security.php'); $groups = init_groups_visitor($contact['id']); - if(count($groups)) { - for($x = 0; $x < count($groups); $x ++) + if (count($groups)) { + for ($x = 0; $x < count($groups); $x ++) $groups[$x] = '<' . intval($groups[$x]) . '>' ; $gs = implode('|', $groups); - } else + } else { $gs = '<<>>' ; // Impossible to match + } $sql_extra = sprintf(" AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) @@ -168,23 +174,26 @@ class dfrn { ); } - if($public_feed) + if ($public_feed) { $sort = 'DESC'; - else + } else { $sort = 'ASC'; + } - if(! strlen($last_update)) + if (! strlen($last_update)) { $last_update = 'now -30 days'; + } - if(isset($category)) { + if (isset($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($owner_id)); //$sql_extra .= file_tag_file_query('item',$category,'category'); } - if($public_feed) { - if(! $converse) + if ($public_feed) { + if (! $converse) { $sql_extra .= " AND `contact`.`self` = 1 "; + } } $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); @@ -207,6 +216,11 @@ class dfrn { dbesc($sort) ); + if (!dbm::is_result($r)) { + /// @TODO Some logging? + killme(); + } + // Will check further below if this actually returned results. // We will provide an empty feed if that is the case. @@ -217,13 +231,15 @@ class dfrn { $alternatelink = $owner['url']; - if(isset($category)) + if (isset($category)) { $alternatelink .= "/category/".$category; + } - if ($public_feed) + if ($public_feed) { $author = "dfrn:owner"; - else + } else { $author = "author"; + } $root = self::add_header($doc, $owner, $author, $alternatelink, true); @@ -238,21 +254,24 @@ class dfrn { return $atom; } - foreach($items as $item) { + foreach ($items as $item) { // prevent private email from leaking. - if($item['network'] == NETWORK_MAIL) + if ($item['network'] == NETWORK_MAIL) { continue; + } // public feeds get html, our own nodes use bbcode - if($public_feed) { + if ($public_feed) { $type = 'html'; // catch any email that's in a public conversation and make sure it doesn't leak - if($item['private']) + if ($item['private']) { continue; - } else + } + } else { $type = 'text'; + } $entry = self::entry($doc, $type, $item, $owner, true); $root->appendChild($entry); @@ -273,6 +292,7 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN mail + * @todo Add type-hints */ public static function mail($item, $owner) { $doc = new DOMDocument('1.0', 'utf-8'); @@ -307,6 +327,7 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN suggestions + * @todo Add type-hints */ public static function fsuggest($item, $owner) { $doc = new DOMDocument('1.0', 'utf-8'); @@ -334,12 +355,13 @@ class dfrn { * @param int $uid User ID * * @return string DFRN relocations + * @todo Add type-hints */ public static function relocate($owner, $uid) { /* get site pubkey. this could be a new installation with no site keys*/ $pubkey = get_config('system','site_pubkey'); - if(! $pubkey) { + if (! $pubkey) { $res = new_keypair(1024); set_config('system','site_prvkey', $res['prvkey']); set_config('system','site_pubkey', $res['pubkey']); @@ -350,8 +372,9 @@ class dfrn { $photos = array(); $ext = Photo::supportedTypes(); - foreach($rp as $p) + foreach ($rp as $p) { $photos[$p['scale']] = app::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']]; + } unset($rp, $ext); @@ -390,11 +413,13 @@ class dfrn { * @param bool $public Is it a header for public posts? * * @return object XML root object + * @todo Add type-hints */ private static function add_header($doc, $owner, $authorelement, $alternatelink = "", $public = false) { - if ($alternatelink == "") + if ($alternatelink == "") { $alternatelink = $owner['url']; + } $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed'); $doc->appendChild($root); @@ -437,8 +462,9 @@ class dfrn { } // For backward compatibility we keep this element - if ($owner['page-flags'] == PAGE_COMMUNITY) + if ($owner['page-flags'] == PAGE_COMMUNITY) { xml::add_element($doc, $root, "dfrn:community", 1); + } // The former element is replaced by this one xml::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]); @@ -461,6 +487,7 @@ class dfrn { * @param string $authorelement Element name for the author * * @return object XML author object + * @todo Add type-hints */ private static function add_author($doc, $owner, $authorelement, $public) { @@ -468,10 +495,11 @@ class dfrn { $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE (`hidewall` OR NOT `net-publish`) AND `user`.`uid` = %d", intval($owner['uid'])); - if ($r) + if (dbm::is_result($r)) { $hidewall = true; - else + } else { $hidewall = false; + } $author = $doc->createElement($authorelement); @@ -479,10 +507,11 @@ class dfrn { $uridate = datetime_convert('UTC', 'UTC', $owner['uri-date'].'+00:00', ATOM_TIME); $picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME); - if (!$public OR !$hidewall) + $attributes = array(); + + if (!$public OR !$hidewall) { $attributes = array("dfrn:updated" => $namdate); - else - $attributes = array(); + } xml::add_element($doc, $author, "name", $owner["name"], $attributes); xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes); @@ -491,20 +520,23 @@ class dfrn { $attributes = array("rel" => "photo", "type" => "image/jpeg", "media:width" => 175, "media:height" => 175, "href" => $owner['photo']); - if (!$public OR !$hidewall) + if (!$public OR !$hidewall) { $attributes["dfrn:updated"] = $picdate; + } xml::add_element($doc, $author, "link", "", $attributes); $attributes["rel"] = "avatar"; xml::add_element($doc, $author, "link", "", $attributes); - if ($hidewall) + if ($hidewall) { xml::add_element($doc, $author, "dfrn:hide", "true"); + } // The following fields will only be generated if the data isn't meant for a public feed - if ($public) + if ($public) { return $author; + } $birthday = feed_birthday($owner['uid'], $owner['timezone']); @@ -519,7 +551,7 @@ class dfrn { INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `profile`.`is-default` AND NOT `user`.`hidewall` AND `user`.`uid` = %d", intval($owner['uid'])); - if ($r) { + if (dbm::is_result($r)) { $profile = $r[0]; xml::add_element($doc, $author, "poco:displayName", $profile["name"]); @@ -547,8 +579,9 @@ class dfrn { if (trim($profile["pub_keywords"]) != "") { $keywords = explode(",", $profile["pub_keywords"]); - foreach ($keywords AS $keyword) + foreach ($keywords AS $keyword) { xml::add_element($doc, $author, "poco:tags", trim($keyword)); + } } @@ -565,14 +598,17 @@ class dfrn { xml::add_element($doc, $element, "poco:formatted", formatted_location($profile)); - if (trim($profile["locality"]) != "") + if (trim($profile["locality"]) != "") { xml::add_element($doc, $element, "poco:locality", $profile["locality"]); + } - if (trim($profile["region"]) != "") + if (trim($profile["region"]) != "") { xml::add_element($doc, $element, "poco:region", $profile["region"]); + } - if (trim($profile["country-name"]) != "") + if (trim($profile["country-name"]) != "") { xml::add_element($doc, $element, "poco:country", $profile["country-name"]); + } $author->appendChild($element); } @@ -590,6 +626,7 @@ class dfrn { * @param array $items Item elements * * @return object XML author object + * @todo Add type-hints */ private static function add_entry_author($doc, $element, $contact_url, $item) { @@ -630,10 +667,11 @@ class dfrn { * @param string $activity activity value * * @return object XML activity object + * @todo Add type-hints */ private static function create_activity($doc, $element, $activity) { - if($activity) { + if ($activity) { $entry = $doc->createElement($element); $r = parse_xml_string($activity, false); @@ -692,6 +730,7 @@ class dfrn { * @param array $item Item element * * @return object XML attachment object + * @todo Add type-hints */ private static function get_attachment($doc, $root, $item) { $arr = explode('[/attach],',$item['attach']); @@ -729,6 +768,7 @@ class dfrn { * @param int $cid Contact ID of the recipient * * @return object XML entry object + * @todo Add type-hints */ private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) { @@ -857,7 +897,7 @@ class dfrn { $tags = item_getfeedtags($item); - if( count($tags)) { + if (count($tags)) { foreach ($tags as $t) { if (($type != 'html') OR ($t[0] != "@")) { xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2])); @@ -866,7 +906,7 @@ class dfrn { } if (count($tags)) { - foreach($tags as $t) { + foreach ($tags as $t) { if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; } @@ -878,6 +918,11 @@ class dfrn { intval($owner["uid"]), dbesc(normalise_link($mention))); + if (!dbm::is_result($r)) { + /// @TODO Maybe some logging? + killme(); + } + if ($r[0]["forum"] OR $r[0]["prv"]) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, @@ -903,6 +948,7 @@ class dfrn { * @param bool $dissolve (to be documented) * * @return int Deliver status. -1 means an error. + * @todo Add array type-hint for $owner, $contact */ public static function deliver($owner,$contact,$atom, $dissolve = false) { @@ -1152,7 +1198,7 @@ class dfrn { * * @param array $contact Contact record * @param string $birthday Birthday of the contact - * + * @todo Add array type-hint for $contact */ private static function birthday_event($contact, $birthday) { @@ -1196,6 +1242,7 @@ class dfrn { * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well * * @return Returns an array with relevant data of the author + * @todo Find good type-hints for all parameter */ private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") { @@ -1213,8 +1260,9 @@ class dfrn { $author["contact-id"] = $r[0]["id"]; $author["network"] = $r[0]["network"]; } else { - if (!$onlyfetch) + if (!$onlyfetch) { logger("Contact ".$author["link"]." wasn't found for user ".$importer["uid"]." XML: ".$xml, LOGGER_DEBUG); + } $author["contact-id"] = $importer["id"]; $author["network"] = $importer["network"]; @@ -1225,10 +1273,11 @@ class dfrn { $avatarlist = array(); /// @todo check if "avatar" or "photo" would be the best field in the specification $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context); - foreach($avatars AS $avatar) { + foreach ($avatars AS $avatar) { $href = ""; $width = 0; - foreach($avatar->attributes AS $attributes) { + foreach ($avatar->attributes AS $attributes) { + /// @TODO Rewrite these similar if() to one switch if ($attributes->name == "href") { $href = $attributes->textContent; } @@ -1248,7 +1297,7 @@ class dfrn { $author["avatar"] = current($avatarlist); } - if ($r AND !$onlyfetch) { + if (dbm::is_result($r) AND !$onlyfetch) { logger("Check if contact details for contact ".$r[0]["id"]." (".$r[0]["nick"].") have to be updated.", LOGGER_DEBUG); $poco = array("url" => $contact["url"]); @@ -1376,17 +1425,19 @@ class dfrn { // Update check for this field has to be done differently $datefields = array("name-date", "uri-date"); - foreach ($datefields AS $field) + foreach ($datefields AS $field) { if (strtotime($contact[$field]) > strtotime($r[0][$field])) { logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } + } - foreach ($fields AS $field => $data) + foreach ($fields AS $field => $data) { if ($contact[$field] != $r[0][$field]) { logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } + } if ($update) { logger("Update contact data for contact ".$contact["id"]." (".$contact["nick"].")", LOGGER_DEBUG); @@ -1428,6 +1479,7 @@ class dfrn { * @param text $element element name * * @return string XML string + * @todo Find good type-hints for all parameter */ private static function transform_activity($xpath, $activity, $element) { if (!is_object($activity)) { @@ -1443,21 +1495,26 @@ class dfrn { xml::add_element($obj_doc, $obj_element, "type", $activity_type); $id = $xpath->query("atom:id", $activity)->item(0); - if (is_object($id)) + if (is_object($id)) { $obj_element->appendChild($obj_doc->importNode($id, true)); + } $title = $xpath->query("atom:title", $activity)->item(0); - if (is_object($title)) + if (is_object($title)) { $obj_element->appendChild($obj_doc->importNode($title, true)); + } $links = $xpath->query("atom:link", $activity); - if (is_object($links)) - foreach ($links AS $link) + if (is_object($links)) { + foreach ($links AS $link) { $obj_element->appendChild($obj_doc->importNode($link, true)); + } + } $content = $xpath->query("atom:content", $activity)->item(0); - if (is_object($content)) + if (is_object($content)) { $obj_element->appendChild($obj_doc->importNode($content, true)); + } $obj_doc->appendChild($obj_element); @@ -1474,11 +1531,13 @@ class dfrn { * @param object $xpath XPath object * @param object $mail mail elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Find good type-hints for all parameter */ private static function process_mail($xpath, $mail, $importer) { logger("Processing mails"); + /// @TODO Rewrite this to one statement $msg = array(); $msg["uid"] = $importer["importer_uid"]; $msg["from-name"] = $xpath->query("dfrn:sender/dfrn:name/text()", $mail)->item(0)->nodeValue; @@ -1498,7 +1557,7 @@ class dfrn { $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES (".implode(", ", array_values($msg)).")"); // send notifications. - + /// @TODO Arange this mess $notif_params = array( "type" => NOTIFY_MAIL, "notify_flags" => $importer["notify-flags"], @@ -1525,12 +1584,14 @@ class dfrn { * @param object $xpath XPath object * @param object $suggestion suggestion elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Find good type-hints for all parameter */ private static function process_suggestion($xpath, $suggestion, $importer) { $a = get_app(); logger("Processing suggestions"); + /// @TODO Rewrite this to one statement $suggest = array(); $suggest["uid"] = $importer["importer_uid"]; $suggest["cid"] = $importer["id"]; @@ -1547,8 +1608,10 @@ class dfrn { dbesc(normalise_link($suggest["url"])), intval($suggest["uid"]) ); - if (dbm::is_result($r)) + /// @TODO Really abort on valid result??? Maybe missed ! here? + if (dbm::is_result($r)) { return false; + } // Do we already have an fcontact record for this person? @@ -1566,10 +1629,12 @@ class dfrn { intval($suggest["uid"]), intval($fid) ); - if (dbm::is_result($r)) + /// @TODO Really abort on valid result??? Maybe missed ! here? + if (dbm::is_result($r)) { return false; + } } - if(!$fid) + if (!$fid) $r = q("INSERT INTO `fcontact` (`name`,`url`,`photo`,`request`) VALUES ('%s', '%s', '%s', '%s')", dbesc($suggest["name"]), dbesc($suggest["url"]), @@ -1581,11 +1646,12 @@ class dfrn { dbesc($suggest["name"]), dbesc($suggest["request"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $fid = $r[0]["id"]; - else + } else { // database record did not get created. Quietly give up. - return false; + killme(); + } $hash = random_string(); @@ -1627,11 +1693,13 @@ class dfrn { * @param object $xpath XPath object * @param object $relocation relocation elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Find good type-hints for all parameter */ private static function process_relocation($xpath, $relocation, $importer) { logger("Processing relocations"); + /// @TODO Rewrite this to one statement $relocate = array(); $relocate["uid"] = $importer["importer_uid"]; $relocate["cid"] = $importer["id"]; @@ -1648,18 +1716,22 @@ class dfrn { $relocate["poll"] = $xpath->query("dfrn:poll/text()", $relocation)->item(0)->nodeValue; $relocate["sitepubkey"] = $xpath->query("dfrn:sitepubkey/text()", $relocation)->item(0)->nodeValue; - if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) + if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) { $relocate["avatar"] = $relocate["photo"]; + } - if ($relocate["addr"] == "") + if ($relocate["addr"] == "") { $relocate["addr"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$3@$2", $relocate["url"]); + } // update contact $r = q("SELECT `photo`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d;", intval($importer["id"]), intval($importer["importer_uid"])); - if (!$r) - return false; + + if (!dbm::is_result($r)) { + killme(); + } $old = $r[0]; @@ -1715,8 +1787,9 @@ class dfrn { update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true); - if ($x === false) + if ($x === false) { return false; + } // update items /// @todo This is an extreme performance killer @@ -1731,7 +1804,7 @@ class dfrn { $n, dbesc($f[0]), intval($importer["importer_uid"])); - if ($r) { + if (dbm::is_result($r)) { $x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d", $n, dbesc($f[1]), $n, dbesc($f[0]), @@ -1780,12 +1853,13 @@ class dfrn { $changed = true; - if ($entrytype == DFRN_REPLY_RC) + if ($entrytype == DFRN_REPLY_RC) { proc_run(PRIORITY_HIGH, "include/notifier.php","comment-import", $current["id"]); + } } // update last-child if it changes - if($item["last-child"] AND ($item["last-child"] != $current["last-child"])) { + if ($item["last-child"] AND ($item["last-child"] != $current["last-child"])) { $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc(datetime_convert()), dbesc($item["parent-uri"]), @@ -1817,8 +1891,9 @@ class dfrn { $sql_extra = ""; $community = true; logger("possible community action"); - } else + } else { $sql_extra = " AND `contact`.`self` AND `item`.`wall` "; + } // was the top-level post for this action written by somebody on this site? // Specifically, the recipient? @@ -1842,8 +1917,9 @@ class dfrn { dbesc($r[0]["parent-uri"]), intval($importer["importer_uid"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $is_a_remote_action = true; + } } // Does this have the characteristics of a community or private group action? @@ -1851,20 +1927,22 @@ class dfrn { // valid community action. Also forum_mode makes it valid for sure. // If neither, it's not. - if($is_a_remote_action && $community) { - if((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { + if ($is_a_remote_action && $community) { + if ((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { $is_a_remote_action = false; logger("not a community action"); } } - if ($is_a_remote_action) + if ($is_a_remote_action) { return DFRN_REPLY_RC; - else + } else { return DFRN_REPLY; + } - } else + } else { return DFRN_TOP_LEVEL; + } } @@ -1877,14 +1955,15 @@ class dfrn { */ private static function do_poke($item, $importer, $posted_id) { $verb = urldecode(substr($item["verb"],strpos($item["verb"], "#")+1)); - if(!$verb) + if (!$verb) { return; + } $xo = parse_xml_string($item["object"],false); - if(($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { + if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? - foreach($xo->link as $l) { + foreach ($xo->link as $l) { $atts = $l->attributes(); switch($atts["rel"]) { case "alternate": @@ -1943,22 +2022,22 @@ class dfrn { // Big question: Do we need these functions? They were part of the "consume_feed" function. // This function once was responsible for DFRN and OStatus. - if(activity_match($item["verb"],ACTIVITY_FOLLOW)) { + if (activity_match($item["verb"],ACTIVITY_FOLLOW)) { logger("New follower"); new_follower($importer, $contact, $item, $nickname); return false; } - if(activity_match($item["verb"],ACTIVITY_UNFOLLOW)) { + if (activity_match($item["verb"],ACTIVITY_UNFOLLOW)) { logger("Lost follower"); lose_follower($importer, $contact, $item); return false; } - if(activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) { + if (activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) { logger("New friend request"); new_follower($importer, $contact, $item, $nickname, true); return false; } - if(activity_match($item["verb"],ACTIVITY_UNFRIEND)) { + if (activity_match($item["verb"],ACTIVITY_UNFRIEND)) { logger("Lost sharer"); lose_sharer($importer, $contact, $item); return false; @@ -1980,8 +2059,9 @@ class dfrn { dbesc($item["verb"]), dbesc($item["parent-uri"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { return false; + } $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1", intval($item["uid"]), @@ -1989,28 +2069,31 @@ class dfrn { dbesc($item["verb"]), dbesc($item["parent-uri"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { return false; - } else + } + } else { $is_like = false; + } - if(($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { + if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { $xo = parse_xml_string($item["object"],false); $xt = parse_xml_string($item["target"],false); - if($xt->type == ACTIVITY_OBJ_NOTE) { + if ($xt->type == ACTIVITY_OBJ_NOTE) { $r = q("SELECT `id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($xt->id), intval($importer["importer_uid"]) ); - if (!dbm::is_result($r)) - return false; + if (!dbm::is_result($r)) { + killme(); + } // extract tag, if not duplicate, add to parent item - if($xo->content) { - if(!(stristr($r[0]["tag"],trim($xo->content)))) { + if ($xo->content) { + if (!(stristr($r[0]["tag"],trim($xo->content)))) { q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", dbesc($r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'), intval($r[0]["id"]) @@ -2029,6 +2112,7 @@ class dfrn { * * @param object $links link elements * @param array $item the item record + * @todo Add type-hints */ private static function parse_links($links, &$item) { $rel = ""; @@ -2037,17 +2121,23 @@ class dfrn { $length = "0"; $title = ""; foreach ($links AS $link) { - foreach($link->attributes AS $attributes) { - if ($attributes->name == "href") + foreach ($link->attributes AS $attributes) { + /// @TODO Rewrite these repeated (same) if() statements to a switch() + if ($attributes->name == "href") { $href = $attributes->textContent; - if ($attributes->name == "rel") + } + if ($attributes->name == "rel") { $rel = $attributes->textContent; - if ($attributes->name == "type") + } + if ($attributes->name == "type") { $type = $attributes->textContent; - if ($attributes->name == "length") + } + if ($attributes->name == "length") { $length = $attributes->textContent; - if ($attributes->name == "title") + } + if ($attributes->name == "title") { $title = $attributes->textContent; + } } if (($rel != "") AND ($href != "")) switch($rel) { @@ -2056,8 +2146,9 @@ class dfrn { break; case "enclosure": $enclosure = $href; - if(strlen($item["attach"])) + if (strlen($item["attach"])) { $item["attach"] .= ","; + } $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; break; @@ -2072,6 +2163,7 @@ class dfrn { * @param object $xpath XPath object * @param object $entry entry elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Add type-hints */ private static function process_entry($header, $xpath, $entry, $importer) { @@ -2122,7 +2214,7 @@ class dfrn { $item["body"] = limit_body_size($item["body"]); /// @todo Do we really need this check for HTML elements? (It was copied from the old function) - if((strpos($item['body'],'<') !== false) && (strpos($item['body'],'>') !== false)) { + if ((strpos($item['body'],'<') !== false) && (strpos($item['body'],'>') !== false)) { $item['body'] = reltoabs($item['body'],$base_url); @@ -2151,21 +2243,24 @@ class dfrn { $item["location"] = $xpath->query("dfrn:location/text()", $entry)->item(0)->nodeValue; $georsspoint = $xpath->query("georss:point", $entry); - if ($georsspoint) + if ($georsspoint) { $item["coord"] = $georsspoint->item(0)->nodeValue; + } $item["private"] = $xpath->query("dfrn:private/text()", $entry)->item(0)->nodeValue; $item["extid"] = $xpath->query("dfrn:extid/text()", $entry)->item(0)->nodeValue; - if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") + if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") { $item["bookmark"] = true; + } $notice_info = $xpath->query("statusnet:notice_info", $entry); if ($notice_info AND ($notice_info->length > 0)) { - foreach($notice_info->item(0)->attributes AS $attributes) { - if ($attributes->name == "source") + foreach ($notice_info->item(0)->attributes AS $attributes) { + if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); + } } } @@ -2173,21 +2268,24 @@ class dfrn { // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "item_store" $dsprsig = unxmlify($xpath->query("dfrn:diaspora_signature/text()", $entry)->item(0)->nodeValue); - if ($dsprsig != "") + if ($dsprsig != "") { $item["dsprsig"] = $dsprsig; + } $item["verb"] = $xpath->query("activity:verb/text()", $entry)->item(0)->nodeValue; - if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") + if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") { $item["object-type"] = $xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue; + } $object = $xpath->query("activity:object", $entry)->item(0); $item["object"] = self::transform_activity($xpath, $object, "object"); if (trim($item["object"]) != "") { $r = parse_xml_string($item["object"], false); - if (isset($r->type)) + if (isset($r->type)) { $item["object-type"] = $r->type; + } } $target = $xpath->query("activity:target", $entry)->item(0); @@ -2198,12 +2296,14 @@ class dfrn { foreach ($categories AS $category) { $term = ""; $scheme = ""; - foreach($category->attributes AS $attributes) { - if ($attributes->name == "term") + foreach ($category->attributes AS $attributes) { + if ($attributes->name == "term") { $term = $attributes->textContent; + } - if ($attributes->name == "scheme") + if ($attributes->name == "scheme") { $scheme = $attributes->textContent; + } } if (($term != "") AND ($scheme != "")) { @@ -2212,8 +2312,9 @@ class dfrn { $termhash = array_shift($parts); $termurl = implode(":", $parts); - if(strlen($item["tag"])) + if (strlen($item["tag"])) { $item["tag"] .= ","; + } $item["tag"] .= $termhash."[url=".$termurl."]".$term."[/url]"; } @@ -2224,37 +2325,46 @@ class dfrn { $enclosure = ""; $links = $xpath->query("atom:link", $entry); - if ($links) + if ($links) { self::parse_links($links, $item); + } // Is it a reply or a top level posting? $item["parent-uri"] = $item["uri"]; $inreplyto = $xpath->query("thr:in-reply-to", $entry); - if (is_object($inreplyto->item(0))) - foreach($inreplyto->item(0)->attributes AS $attributes) - if ($attributes->name == "ref") + if (is_object($inreplyto->item(0))) { + foreach ($inreplyto->item(0)->attributes AS $attributes) { + if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; + } + } + } // Get the type of the item (Top level post, reply or remote reply) $entrytype = self::get_entry_type($importer, $item); // Now assign the rest of the values that depend on the type of the message if (in_array($entrytype, array(DFRN_REPLY, DFRN_REPLY_RC))) { - if (!isset($item["object-type"])) + if (!isset($item["object-type"])) { $item["object-type"] = ACTIVITY_OBJ_COMMENT; + } - if ($item["contact-id"] != $owner["contact-id"]) + if ($item["contact-id"] != $owner["contact-id"]) { $item["contact-id"] = $owner["contact-id"]; + } - if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) + if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) { $item["network"] = $owner["network"]; + } - if ($item["contact-id"] != $author["contact-id"]) + if ($item["contact-id"] != $author["contact-id"]) { $item["contact-id"] = $author["contact-id"]; + } - if (($item["network"] != $author["network"]) AND ($author["network"] != "")) + if (($item["network"] != $author["network"]) AND ($author["network"] != "")) { $item["network"] = $author["network"]; + } // This code was taken from the old DFRN code // When activated, forums don't work. @@ -2270,14 +2380,15 @@ class dfrn { $item["type"] = "remote-comment"; $item["wall"] = 1; } elseif ($entrytype == DFRN_TOP_LEVEL) { - if (!isset($item["object-type"])) + if (!isset($item["object-type"])) { $item["object-type"] = ACTIVITY_OBJ_NOTE; + } // Is it an event? if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { logger("Item ".$item["uri"]." seems to contain an event.", LOGGER_DEBUG); $ev = bbtoevent($item["body"]); - if((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { + if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG); $ev["cid"] = $importer["id"]; $ev["uid"] = $importer["uid"]; @@ -2290,8 +2401,9 @@ class dfrn { dbesc($item["uri"]), intval($importer["uid"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $ev["id"] = $r[0]["id"]; + } $event_id = event_store($ev); logger("Event ".$event_id." was stored", LOGGER_DEBUG); @@ -2309,8 +2421,9 @@ class dfrn { if (dbm::is_result($current)) { if (self::update_content($r[0], $item, $importer, $entrytype)) logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG); - else + } else { logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG); + } return; } @@ -2318,7 +2431,7 @@ class dfrn { $posted_id = item_store($item); $parent = 0; - if($posted_id) { + if ($posted_id) { logger("Reply from contact ".$item["contact-id"]." was stored with id ".$posted_id, LOGGER_DEBUG); @@ -2333,7 +2446,7 @@ class dfrn { $parent_uri = $r[0]["parent-uri"]; } - if(!$is_like) { + if (!$is_like) { $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d", dbesc(datetime_convert()), intval($importer["importer_uid"]), @@ -2347,7 +2460,7 @@ class dfrn { ); } - if($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) { + if ($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) { logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG); proc_run(PRIORITY_HIGH, "include/notifier.php", "comment-import", $posted_id); } @@ -2355,7 +2468,7 @@ class dfrn { return true; } } else { // $entrytype == DFRN_TOP_LEVEL - if(!link_compare($item["owner-link"],$importer["url"])) { + if (!link_compare($item["owner-link"],$importer["url"])) { // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, // but otherwise there's a possible data mixup on the sender's system. // the tgroup delivery code called from item_store will correct it if it's a forum, @@ -2366,7 +2479,7 @@ class dfrn { $item["owner-avatar"] = $importer["thumb"]; } - if(($importer["rel"] == CONTACT_IS_FOLLOWER) && (!tgroup_check($importer["importer_uid"], $item))) { + if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!tgroup_check($importer["importer_uid"], $item))) { logger("Contact ".$importer["id"]." is only follower and tgroup check was negative.", LOGGER_DEBUG); return; } @@ -2395,19 +2508,23 @@ class dfrn { logger("Processing deletions"); - foreach($deletion->attributes AS $attributes) { - if ($attributes->name == "ref") + foreach ($deletion->attributes AS $attributes) { + if ($attributes->name == "ref") { $uri = $attributes->textContent; - if ($attributes->name == "when") + } + if ($attributes->name == "when") { $when = $attributes->textContent; + } } - if ($when) + if ($when) { $when = datetime_convert("UTC", "UTC", $when, "Y-m-d H:i:s"); - else + } else { $when = datetime_convert("UTC", "UTC", "now", "Y-m-d H:i:s"); + } - if (!$uri OR !$importer["id"]) + if (!$uri OR !$importer["id"]) { return false; + } /// @todo Only select the used fields $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` @@ -2425,22 +2542,23 @@ class dfrn { $entrytype = self::get_entry_type($importer, $item); - if(!$item["deleted"]) + if (!$item["deleted"]) { logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG); - else + } else { return; + } - if($item["object-type"] == ACTIVITY_OBJ_EVENT) { + if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { logger("Deleting event ".$item["event-id"], LOGGER_DEBUG); event_delete($item["event-id"]); } - if(($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { + if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { $xo = parse_xml_string($item["object"],false); $xt = parse_xml_string($item["target"],false); - if($xt->type == ACTIVITY_OBJ_NOTE) { + if ($xt->type == ACTIVITY_OBJ_NOTE) { $i = q("SELECT `id`, `contact-id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($xt->id), intval($importer["importer_uid"]) @@ -2453,15 +2571,18 @@ class dfrn { $author_remove = (($item["origin"] && $item["self"]) ? true : false); $author_copy = (($item["origin"]) ? true : false); - if($owner_remove && $author_copy) + if ($owner_remove && $author_copy) { return; - if($author_remove || $owner_remove) { + } + if ($author_remove || $owner_remove) { $tags = explode(',',$i[0]["tag"]); $newtags = array(); - if(count($tags)) { - foreach($tags as $tag) - if(trim($tag) !== trim($xo->body)) + if (count($tags)) { + foreach ($tags as $tag) { + if (trim($tag) !== trim($xo->body)) { $newtags[] = trim($tag); + } + } } q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", dbesc(implode(',',$newtags)), @@ -2602,25 +2723,30 @@ class dfrn { ); $mails = $xpath->query("/atom:feed/dfrn:mail"); - foreach ($mails AS $mail) + foreach ($mails AS $mail) { self::process_mail($xpath, $mail, $importer); + } $suggestions = $xpath->query("/atom:feed/dfrn:suggest"); - foreach ($suggestions AS $suggestion) + foreach ($suggestions AS $suggestion) { self::process_suggestion($xpath, $suggestion, $importer); + } $relocations = $xpath->query("/atom:feed/dfrn:relocate"); - foreach ($relocations AS $relocation) + foreach ($relocations AS $relocation) { self::process_relocation($xpath, $relocation, $importer); + } $deletions = $xpath->query("/atom:feed/at:deleted-entry"); - foreach ($deletions AS $deletion) + foreach ($deletions AS $deletion) { self::process_deletion($xpath, $deletion, $importer); + } if (!$sort_by_date) { $entries = $xpath->query("/atom:feed/atom:entry"); - foreach ($entries AS $entry) + foreach ($entries AS $entry) { self::process_entry($header, $xpath, $entry, $importer); + } } else { $newentries = array(); $entries = $xpath->query("/atom:feed/atom:entry"); @@ -2632,8 +2758,9 @@ class dfrn { // Now sort after the publishing date ksort($newentries); - foreach ($newentries AS $entry) + foreach ($newentries AS $entry) { self::process_entry($header, $xpath, $entry, $importer); + } } logger("Import done for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG); } From 3ad0fd442e6dd580a85d0595d643add0312e5e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:01:15 +0100 Subject: [PATCH 13/55] Continued: - added missing spaces/curly braces - some more usage of dbm::is_result() - 2 oppsite if() statements can be mored to else - added more TODOs for type-hinting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 361 +++++++++++++++++++++++++++++--------------- 1 file changed, 237 insertions(+), 124 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 3e285a783..0337e9a27 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -37,9 +37,11 @@ class ostatus { * @param bool $onlyfetch Only fetch the header without updating the contact entries * * @return array Array of author related entries for the item + * @todo Add type-hints */ private function fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) { + /// @TODO One statment is enough ... $author = array(); $author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue; @@ -47,33 +49,41 @@ class ostatus { $aliaslink = $author["author-link"]; $alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes; - if (is_object($alternate)) - foreach($alternate AS $attributes) - if ($attributes->name == "href") + if (is_object($alternate)) { + /// @TODO foreach() may only later work on objects that have iterator interface implemented, please check this + foreach ($alternate AS $attributes) { + if ($attributes->name == "href") { $author["author-link"] = $attributes->textContent; + } + } + } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", intval($importer["uid"]), dbesc(normalise_link($author["author-link"])), dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET)); - if ($r) { + if (dbm::is_result($r)) { $contact = $r[0]; $author["contact-id"] = $r[0]["id"]; - } else + } else { $author["contact-id"] = $contact["id"]; + } $avatarlist = array(); $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context); - foreach($avatars AS $avatar) { + foreach ($avatars AS $avatar) { $href = ""; $width = 0; - foreach($avatar->attributes AS $attributes) { - if ($attributes->name == "href") + foreach ($avatar->attributes AS $attributes) { + if ($attributes->name == "href") { $href = $attributes->textContent; - if ($attributes->name == "width") + } + if ($attributes->name == "width") { $width = $attributes->textContent; + } } - if (($width > 0) AND ($href != "")) + if (($width > 0) AND ($href != "")) { $avatarlist[$width] = $href; + } } if (count($avatarlist) > 0) { krsort($avatarlist); @@ -81,15 +91,16 @@ class ostatus { } $displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($displayname != "") + if ($displayname != "") { $author["author-name"] = $displayname; + } $author["owner-name"] = $author["author-name"]; $author["owner-link"] = $author["author-link"]; $author["owner-avatar"] = $author["author-avatar"]; // Only update the contacts if it is an OStatus contact - if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { + if (dbm::is_result($r) AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { // Update contact data @@ -181,6 +192,7 @@ class ostatus { * @param array $importer user record of the importing user * * @return array Array of author related entries for the item + * @todo add type-hints */ public static function salmon_author($xml, $importer) { @@ -189,7 +201,7 @@ class ostatus { } $doc = new DOMDocument(); - @$doc->loadXML($xml); + $doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', NAMESPACE_ATOM1); @@ -217,6 +229,7 @@ class ostatus { * @param array $importer user record of the importing user * @param $contact * @param array $hub Called by reference, returns the fetched hub data + * @todo Add missing-type hint + determine type for $contact */ public static function import($xml,$importer,&$contact, &$hub) { /// @todo this function is too long. It has to be split in many parts @@ -231,7 +244,7 @@ class ostatus { //file_put_contents($tempfile, $xml); $doc = new DOMDocument(); - @$doc->loadXML($xml); + $doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', NAMESPACE_ATOM1); @@ -246,7 +259,7 @@ class ostatus { $gub = ""; $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; if (is_object($hub_attributes)) { - foreach($hub_attributes AS $hub_attribute) { + foreach ($hub_attributes AS $hub_attribute) { if ($hub_attribute->name == "href") { $hub = $hub_attribute->textContent; logger("Found hub ".$hub, LOGGER_DEBUG); @@ -254,6 +267,7 @@ class ostatus { } } + /// @TODO One statement is enough ... $header = array(); $header["uid"] = $importer["uid"]; $header["network"] = NETWORK_OSTATUS; @@ -377,7 +391,7 @@ class ostatus { $inreplyto = $xpath->query('thr:in-reply-to', $entry); if (is_object($inreplyto->item(0))) { - foreach($inreplyto->item(0)->attributes AS $attributes) { + foreach ($inreplyto->item(0)->attributes AS $attributes) { if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; } @@ -394,7 +408,7 @@ class ostatus { $categories = $xpath->query('atom:category', $entry); if ($categories) { foreach ($categories AS $category) { - foreach($category->attributes AS $attributes) + foreach ($category->attributes AS $attributes) if ($attributes->name == "term") { $term = $attributes->textContent; if(strlen($item["tag"])) @@ -415,7 +429,7 @@ class ostatus { $length = "0"; $title = ""; foreach ($links AS $link) { - foreach($link->attributes AS $attributes) { + foreach ($link->attributes AS $attributes) { if ($attributes->name == "href") $href = $attributes->textContent; if ($attributes->name == "rel") @@ -473,7 +487,7 @@ class ostatus { $notice_info = $xpath->query('statusnet:notice_info', $entry); if ($notice_info AND ($notice_info->length > 0)) { - foreach($notice_info->item(0)->attributes AS $attributes) { + foreach ($notice_info->item(0)->attributes AS $attributes) { if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); } @@ -600,22 +614,26 @@ class ostatus { public static function convert_href($href) { $elements = explode(":",$href); - if ((count($elements) <= 2) OR ($elements[0] != "tag")) + if ((count($elements) <= 2) OR ($elements[0] != "tag")) { return $href; + } $server = explode(",", $elements[1]); $conversation = explode("=", $elements[2]); - if ((count($elements) == 4) AND ($elements[2] == "post")) + if ((count($elements) == 4) AND ($elements[2] == "post")) { return "http://".$server[0]."/notice/".$elements[3]; + } - if ((count($conversation) != 2) OR ($conversation[1] =="")) + if ((count($conversation) != 2) OR ($conversation[1] =="")) { return $href; + } - if ($elements[3] == "objectType=thread") + if ($elements[3] == "objectType=thread") { return "http://".$server[0]."/conversation/".$conversation[1]; - else + } else { return "http://".$server[0]."/notice/".$conversation[1]; + } return $href; } @@ -688,42 +706,53 @@ class ostatus { * @brief Updates the gcontact table with actor data from the conversation * * @param object $actor The actor object that contains the contact data + * @todo Add type-hint */ private function conv_fetch_actor($actor) { // We set the generation to "3" since the data here is not as reliable as the data we get on other occasions $contact = array("network" => NETWORK_OSTATUS, "generation" => 3); - if (isset($actor->url)) + if (isset($actor->url)) { $contact["url"] = $actor->url; + } - if (isset($actor->displayName)) + if (isset($actor->displayName)) { $contact["name"] = $actor->displayName; + } - if (isset($actor->portablecontacts_net->displayName)) + if (isset($actor->portablecontacts_net->displayName)) { $contact["name"] = $actor->portablecontacts_net->displayName; + } - if (isset($actor->portablecontacts_net->preferredUsername)) + if (isset($actor->portablecontacts_net->preferredUsername)) { $contact["nick"] = $actor->portablecontacts_net->preferredUsername; + } - if (isset($actor->id)) + if (isset($actor->id)) { $contact["alias"] = $actor->id; + } - if (isset($actor->summary)) + if (isset($actor->summary)) { $contact["about"] = $actor->summary; + } - if (isset($actor->portablecontacts_net->note)) + if (isset($actor->portablecontacts_net->note)) { $contact["about"] = $actor->portablecontacts_net->note; + } - if (isset($actor->portablecontacts_net->addresses->formatted)) + if (isset($actor->portablecontacts_net->addresses->formatted)) { $contact["location"] = $actor->portablecontacts_net->addresses->formatted; + } - if (isset($actor->image->url)) + if (isset($actor->image->url)) { $contact["photo"] = $actor->image->url; + } - if (isset($actor->image->width)) + if (isset($actor->image->width)) { $avatarwidth = $actor->image->width; + } if (is_array($actor->status_net->avatarLinks)) foreach ($actor->status_net->avatarLinks AS $avatar) { @@ -750,22 +779,26 @@ class ostatus { if ($conversation_id != "") { $elements = explode(":", $conversation_id); - if ((count($elements) <= 2) OR ($elements[0] != "tag")) + if ((count($elements) <= 2) OR ($elements[0] != "tag")) { return $conversation_id; + } } - if ($self == "") + if ($self == "") { return ""; + } $json = str_replace(".atom", ".json", $self); $raw = fetch_url($json); - if ($raw == "") + if ($raw == "") { return ""; + } $data = json_decode($raw); - if (!is_object($data)) + if (!is_object($data)) { return ""; + } $conversation_id = $data->statusnet_conversation_id; @@ -791,11 +824,12 @@ class ostatus { $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", $uid, normalise_link($actor), NETWORK_STATUSNET); - if (!$contact) + if (!dbm::is_result($contact)) { $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `alias` IN ('%s', '%s') AND `network` != '%s'", $uid, $actor, normalise_link($actor), NETWORK_STATUSNET); + } - if ($contact) { + if (dbm::is_resul($contact)) { logger("Found contact for url ".$actor, LOGGER_DEBUG); $details["contact_id"] = $contact[0]["id"]; $details["network"] = $contact[0]["network"]; @@ -827,6 +861,7 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return integer The item id of the posted item array + * @todo Add type-hints */ private function completion($conversation_url, $uid, $item = array(), $self = "") { @@ -859,9 +894,9 @@ class ostatus { (SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))", intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url)); */ - if ($parents) + if (dbm::is_result($parents)) { $parent = $parents[0]; - elseif (count($item) > 0) { + } elseif (count($item) > 0) { $parent = $item; $parent["type"] = "remote"; $parent["verb"] = ACTIVITY_POST; @@ -869,9 +904,11 @@ class ostatus { } else { // Preset the parent $r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid`=%d", $uid); - if (!$r) + if (!dbm::is_result($r)) { return(-2); + } + /// @TODO one statement is enough ... $parent = array(); $parent["id"] = 0; $parent["parent"] = 0; @@ -898,20 +935,24 @@ class ostatus { } elseif (!$conv_arr["success"] AND (substr($conv, 0, 8) == "https://")) { $conv = str_replace("https://", "http://", $conv); $conv_as = fetch_url($conv."?page=".$pageno); - } else + } else { $conv_as = $conv_arr["body"]; + } $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = json_decode($conv_as); $no_of_items = sizeof($items); - if (@is_array($conv_as->items)) - foreach ($conv_as->items AS $single_item) + if (is_array($conv_as->items)) { + foreach ($conv_as->items AS $single_item) { $items[$single_item->id] = $single_item; + } + } - if ($no_of_items == sizeof($items)) + if ($no_of_items == sizeof($items)) { break; + } $pageno++; @@ -929,13 +970,19 @@ class ostatus { } return($item_stored); - } else + } else { return(-3); + } } $items = array_reverse($items); $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); + + if (!dbm::is_result($r)) { + killme(); + } + $importer = $r[0]; $new_parent = true; @@ -951,15 +998,18 @@ class ostatus { $mention = false; - if (isset($single_conv->object->id)) + if (isset($single_conv->object->id)) { $single_conv->id = $single_conv->object->id; + } $plink = self::convert_href($single_conv->id); - if (isset($single_conv->object->url)) + if (isset($single_conv->object->url)) { $plink = self::convert_href($single_conv->object->url); + } - if (@!$single_conv->id) + if (!isset($single_conv->id)) { continue; + } logger("Got id ".$single_conv->id, LOGGER_DEBUG); @@ -978,7 +1028,7 @@ class ostatus { (SELECT `parent` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1", intval($uid), dbesc($first_id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if ($new_parents) { + if (dbm::is_result($new_parents)) { if ($new_parents[0]["parent"] == $parent["parent"]) { // Option 2: This post is already present inside our thread - but not as thread starter logger("Option 2: uri present in our thread: ".$first_id, LOGGER_DEBUG); @@ -1009,16 +1059,18 @@ class ostatus { if (isset($single_conv->context->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->context->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if ($parent_exists) + if (dbm::is_result($parent_exists)) { $parent_uri = $single_conv->context->inReplyTo->id; + } } // This is the current way if (isset($single_conv->object->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->object->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if ($parent_exists) + if (dbm::is_result($parent_exists)) { $parent_uri = $single_conv->object->inReplyTo->id; + } } $message_exists = q("SELECT `id`, `parent`, `uri` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", @@ -1065,14 +1117,18 @@ class ostatus { continue; } - if (is_array($single_conv->to)) - foreach($single_conv->to AS $to) - if ($importer["nurl"] == normalise_link($to->id)) + if (is_array($single_conv->to)) { + foreach ($single_conv->to AS $to) { + if ($importer["nurl"] == normalise_link($to->id)) { $mention = true; + } + } + } $actor = $single_conv->actor->id; - if (isset($single_conv->actor->url)) + if (isset($single_conv->actor->url)) { $actor = $single_conv->actor->url; + } $details = self::get_actor_details($actor, $uid, $parent["contact-id"]); @@ -1082,6 +1138,7 @@ class ostatus { continue; } + /// @TODO One statment is okay (until if() ) $arr = array(); $arr["network"] = $details["network"]; $arr["uri"] = $single_conv->id; @@ -1092,10 +1149,12 @@ class ostatus { $arr["created"] = $single_conv->published; $arr["edited"] = $single_conv->published; $arr["owner-name"] = $single_conv->actor->displayName; - if ($arr["owner-name"] == '') + if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->contact->displayName; - if ($arr["owner-name"] == '') + } + if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName; + } $arr["owner-link"] = $actor; $arr["owner-avatar"] = $single_conv->actor->image->url; @@ -1104,15 +1163,15 @@ class ostatus { $arr["author-avatar"] = $single_conv->actor->image->url; $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content)); - if (isset($single_conv->status_net->notice_info->source)) + if (isset($single_conv->status_net->notice_info->source)) { $arr["app"] = strip_tags($single_conv->status_net->notice_info->source); - elseif (isset($single_conv->statusnet->notice_info->source)) + } elseif (isset($single_conv->statusnet->notice_info->source)) { $arr["app"] = strip_tags($single_conv->statusnet->notice_info->source); - elseif (isset($single_conv->statusnet_notice_info->source)) + } elseif (isset($single_conv->statusnet_notice_info->source)) { $arr["app"] = strip_tags($single_conv->statusnet_notice_info->source); - elseif (isset($single_conv->provider->displayName)) + } elseif (isset($single_conv->provider->displayName)) { $arr["app"] = $single_conv->provider->displayName; - else + } else { $arr["app"] = "OStatus"; @@ -1131,20 +1190,23 @@ class ostatus { // $single_conv->object->context->conversation; - if (isset($single_conv->object->object->id)) + if (isset($single_conv->object->object->id)) { $arr["uri"] = $single_conv->object->object->id; - else + } else { $arr["uri"] = $single_conv->object->id; + } - if (isset($single_conv->object->object->url)) + if (isset($single_conv->object->object->url)) { $plink = self::convert_href($single_conv->object->object->url); - else + } else { $plink = self::convert_href($single_conv->object->url); + } - if (isset($single_conv->object->object->content)) + if (isset($single_conv->object->object->content)) { $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->object->content)); - else + } else { $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->content)); + } $arr["plink"] = $plink; @@ -1152,8 +1214,9 @@ class ostatus { $arr["edited"] = $single_conv->object->published; $arr["author-name"] = $single_conv->object->actor->displayName; - if ($arr["owner-name"] == '') + if ($arr["owner-name"] == '') { $arr["author-name"] = $single_conv->object->actor->contact->displayName; + } $arr["author-link"] = $single_conv->object->actor->url; $arr["author-avatar"] = $single_conv->object->actor->image->url; @@ -1165,20 +1228,24 @@ class ostatus { $arr["coord"] = trim($single_conv->object->location->lat." ".$single_conv->object->location->lon); } - if ($arr["location"] == "") + if ($arr["location"] == "") { unset($arr["location"]); + } - if ($arr["coord"] == "") + if ($arr["coord"] == "") { unset($arr["coord"]); + } // Copy fields from given item array if (isset($item["uri"]) AND (($item["uri"] == $arr["uri"]) OR ($item["uri"] == $single_conv->id))) { $copy_fields = array("owner-name", "owner-link", "owner-avatar", "author-name", "author-link", "author-avatar", "gravity", "body", "object-type", "object", "verb", "created", "edited", "coord", "tag", "title", "attach", "app", "type", "location", "contact-id", "uri"); - foreach ($copy_fields AS $field) - if (isset($item[$field])) - $arr[$field] = $item[$field]; + foreach ($copy_fields AS $field) { + if (isset($item[$field])) { + $arr[$field] = $item[$field]; { + } + } } @@ -1204,8 +1271,9 @@ class ostatus { logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($uid), intval($newitem)); - if ($new_parents) + if ($new_parents) { $parent = $new_parents[0]; + } } } @@ -1240,8 +1308,9 @@ class ostatus { $conversation_url = self::convert_href($conversation_url); $messages = q("SELECT `uid`, `parent`, `created`, `received`, `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); - if (!$messages) + if (!dbm::is_result($messages)) { return; + } $message = $messages[0]; // Store conversation url if not done before @@ -1262,32 +1331,38 @@ class ostatus { * @param array $item The item array of thw post * * @return string The guid if the post is a reshare + * @todo Add type-hints */ private function get_reshared_guid($item) { $body = trim($item["body"]); // Skip if it isn't a pure repeated messages // Does it start with a share? - if (strpos($body, "[share") > 0) + if (strpos($body, "[share") > 0) { return(""); + } // Does it end with a share? - if (strlen($body) > (strrpos($body, "[/share]") + 8)) + if (strlen($body) > (strrpos($body, "[/share]") + 8)) { return(""); + } $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body); // Skip if there is no shared message in there - if ($body == $attributes) + if ($body == $attributes) { return(false); + } $guid = ""; preg_match("/guid='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if ($matches[1] != "") { $guid = $matches[1]; + } preg_match('/guid="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if ($matches[1] != "") { $guid = $matches[1]; + } return $guid; } @@ -1303,10 +1378,11 @@ class ostatus { $siteinfo = get_attached_data($body); if (($siteinfo["type"] == "photo")) { - if (isset($siteinfo["preview"])) + if (isset($siteinfo["preview"])) { $preview = $siteinfo["preview"]; - else + } else { $preview = $siteinfo["image"]; + } // Is it a remote picture? Then make a smaller preview here $preview = proxy_url($preview, false, PROXY_SIZE_SMALL); @@ -1315,10 +1391,11 @@ class ostatus { $preview = str_replace(array("-0.jpg", "-0.png"), array("-2.jpg", "-2.png"), $preview); $preview = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $preview); - if (isset($siteinfo["url"])) + if (isset($siteinfo["url"])) { $url = $siteinfo["url"]; - else + } else { $url = $siteinfo["image"]; + } $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]"; } @@ -1333,6 +1410,7 @@ class ostatus { * @param array $owner Contact data of the poster * * @return object header root element + * @todo Add type-hints */ private function add_header($doc, $owner) { @@ -1392,20 +1470,23 @@ class ostatus { * * @param object $doc XML document * @param object $root XML root element where the hub links are added + * @todo Add type-hints */ public static function hublinks($doc, $root) { $hub = get_config('system','huburl'); $hubxml = ''; - if(strlen($hub)) { + if (strlen($hub)) { $hubs = explode(',', $hub); - if(count($hubs)) { - foreach($hubs as $h) { + if (count($hubs)) { + foreach ($hubs as $h) { $h = trim($h); - if(! strlen($h)) + if (! strlen($h)) { continue; - if ($h === '[internal]') + } + if ($h === '[internal]') { $h = App::get_baseurl() . '/pubsubhubbub'; + } xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub")); } } @@ -1418,6 +1499,7 @@ class ostatus { * @param object $doc XML document * @param object $root XML root element where the hub links are added * @param array $item Data of the item that is to be posted + * @todo Add type-hints */ private function get_attachment($doc, $root, $item) { $o = ""; @@ -1461,20 +1543,22 @@ class ostatus { $arr = explode('[/attach],',$item['attach']); - if(count($arr)) { - foreach($arr as $r) { + if (count($arr)) { + foreach ($arr as $r) { $matches = false; $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); - if($cnt) { + if ($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); - if(intval($matches[2])) + if (intval($matches[2])) { $attributes["length"] = intval($matches[2]); + } - if(trim($matches[4]) != "") + if (trim($matches[4]) != "") { $attributes["title"] = trim($matches[4]); + } xml::add_element($doc, $root, "link", "", $attributes); } @@ -1489,12 +1573,15 @@ class ostatus { * @param array $owner Contact data of the poster * * @return object author element + * @todo Add type-hints */ private function add_author($doc, $owner) { + $profile = null; $r = q("SELECT `homepage` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"])); - if ($r) + if (dbm::is_result($r)) { $profile = $r[0]; + } $author = $doc->createElement("author"); xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON); @@ -1562,10 +1649,12 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return string activity + * @todo Add type-hints */ function construct_verb($item) { - if ($item['verb']) + if ($item['verb']) { return $item['verb']; + } return ACTIVITY_POST; } @@ -1575,10 +1664,12 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return string Object type + * @todo Add type-hints */ function construct_objecttype($item) { - if (in_array($item['object-type'], array(ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT))) + if (in_array($item['object-type'], array(ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT))) { return $item['object-type']; + }; return ACTIVITY_OBJ_NOTE; } @@ -1616,6 +1707,7 @@ class ostatus { * @param array $contact Array of the contact that is added * * @return object Source element + * @todo Add type-hints */ private function source_entry($doc, $contact) { $source = $doc->createElement("source"); @@ -1640,39 +1732,41 @@ class ostatus { * @param array $owner Contact data of the poster * * @return array Contact array + * @todo Add array type-hint for $owner */ private function contact_entry($url, $owner) { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1", dbesc(normalise_link($url)), intval($owner["uid"])); - if ($r) { + if (dbm::is_result($r)) { $contact = $r[0]; $contact["uid"] = -1; - } - - if (!$r) { + } else { $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url))); - if ($r) { + if (dbm::is_result($r)) { $contact = $r[0]; $contact["uid"] = -1; $contact["success_update"] = $contact["updated"]; } } - if (!$r) - $contact = owner; + if (!dbm::is_result($r)) { + $contact = $owner; + } if (!isset($contact["poll"])) { $data = probe_url($url); $contact["poll"] = $data["poll"]; - if (!$contact["alias"]) + if (!$contact["alias"]) { $contact["alias"] = $data["alias"]; + } } - if (!isset($contact["alias"])) + if (!isset($contact["alias"])) { $contact["alias"] = $contact["url"]; + } return $contact; } @@ -1687,6 +1781,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element + * @todo Add type-hints */ private function reshare_entry($doc, $item, $owner, $repeated_guid, $toplevel) { @@ -1699,10 +1794,12 @@ class ostatus { $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' AND NOT `private` AND `network` IN ('%s', '%s', '%s') LIMIT 1", intval($owner["uid"]), dbesc($repeated_guid), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); - if ($r) - $repeated_item = $r[0]; - else + + if (!dbm::is_result($r)) { return false; + } + + $repeated_item = $r[0]; $contact = self::contact_entry($repeated_item['author-link'], $owner); @@ -1753,6 +1850,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element with "like" + * @todo Add type-hints */ private function like_entry($doc, $item, $owner, $toplevel) { @@ -1790,6 +1888,7 @@ class ostatus { * @param array $contact Contact data of the target * * @return object author element + * @todo Add type-hints */ private function add_person_object($doc, $owner, $contact) { @@ -1836,6 +1935,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element + * @todo Add type-hints */ private function follow_entry($doc, $item, $owner, $toplevel) { @@ -1898,6 +1998,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element + * @todo Add type-hints */ private function note_entry($doc, $item, $owner, $toplevel) { @@ -1925,6 +2026,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return string The title for the element + * @todo Add type-hints */ private function entry_header($doc, &$entry, $owner, $toplevel) { /// @todo Check if this title stuff is really needed (I guess not) @@ -1960,19 +2062,22 @@ class ostatus { * @param string $title Title for the post * @param string $verb The activity verb * @param bool $complete Add the "status_net" element? + * @todo Add type-hints */ private function entry_content($doc, $entry, $item, $owner, $title, $verb = "", $complete = true) { - if ($verb == "") + if ($verb == "") { $verb = self::construct_verb($item); + } xml::add_element($doc, $entry, "id", $item["uri"]); xml::add_element($doc, $entry, "title", $title); $body = self::format_picture_post($item['body']); - if ($item['title'] != "") + if ($item['title'] != "") { $body = "[b]".$item['title']."[/b]\n\n".$body; + } $body = bbcode($body, false, false, 7); @@ -1998,6 +2103,7 @@ class ostatus { * @param array $item Data of the item that is to be posted * @param array $owner Contact data of the poster * @param $complete + * @todo Add type-hints */ private function entry_footer($doc, $entry, $item, $owner, $complete = true) { @@ -2024,7 +2130,7 @@ class ostatus { $thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($owner["uid"]), dbesc($parent_item)); - if ($thrparent) { + if (dbm::is_result($thrparent)) { $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"]; $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"]; } @@ -2038,10 +2144,13 @@ class ostatus { $tags = item_getfeedtags($item); - if(count($tags)) - foreach($tags as $t) - if ($t[0] == "@") + if (count($tags)) { + foreach ($tags as $t) { + if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; + } + } + } // Make sure that mentions are accepted (GNU Social has problems with mixing HTTP and HTTPS) $newmentions = array(); @@ -2055,14 +2164,15 @@ class ostatus { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); - if ($r[0]["forum"] OR $r[0]["prv"]) + if ($r[0]["forum"] OR $r[0]["prv"]) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); - else + } else { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); + } } if (!$item["private"]) { @@ -2073,10 +2183,13 @@ class ostatus { "href" => "http://activityschema.org/collection/public")); } - if(count($tags)) - foreach($tags as $t) - if ($t[0] != "@") + if (count($tags)) { + foreach ($tags as $t) { + if ($t[0] != "@") { xml::add_element($doc, $entry, "category", "", array("term" => $t[2])); + } + } + } self::get_attachment($doc, $entry, $item); From 6a3dc8b2862e29612d18a73e85c50ce312075696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:04:37 +0100 Subject: [PATCH 14/55] added more curly braces + fixed one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 0337e9a27..2aca1c07d 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1149,6 +1149,7 @@ class ostatus { $arr["created"] = $single_conv->published; $arr["edited"] = $single_conv->published; $arr["owner-name"] = $single_conv->actor->displayName; + if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->contact->displayName; } @@ -1173,7 +1174,7 @@ class ostatus { $arr["app"] = $single_conv->provider->displayName; } else { $arr["app"] = "OStatus"; - + } $arr["object"] = json_encode($single_conv); $arr["verb"] = $parent["verb"]; @@ -1183,8 +1184,9 @@ class ostatus { // Is it a reshared item? if (isset($single_conv->verb) AND ($single_conv->verb == "share") AND isset($single_conv->object)) { - if (is_array($single_conv->object)) + if (is_array($single_conv->object)) { $single_conv->object = $single_conv->object[0]; + } logger("Found reshared item ".$single_conv->object->id); @@ -1271,7 +1273,7 @@ class ostatus { logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($uid), intval($newitem)); - if ($new_parents) { + if (dbm::is_result($new_parents)) { $parent = $new_parents[0]; } } @@ -1308,16 +1310,18 @@ class ostatus { $conversation_url = self::convert_href($conversation_url); $messages = q("SELECT `uid`, `parent`, `created`, `received`, `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + if (!dbm::is_result($messages)) { return; } + $message = $messages[0]; // Store conversation url if not done before $conversation = q("SELECT `url` FROM `term` WHERE `uid` = %d AND `oid` = %d AND `otype` = %d AND `type` = %d", intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION)); - if (!$conversation) { + if (!dbm::is_result($conversation)) { $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `created`, `received`, `guid`) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($message["created"]), dbesc($conversation_url), dbesc($message["created"]), dbesc($message["received"]), dbesc($message["guid"])); From cc83e9d72a004c1f033f6587eb6d6a38bf8ada2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:07:12 +0100 Subject: [PATCH 15/55] fixed curly brace (opps) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 2aca1c07d..d20e4cb4f 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1245,7 +1245,7 @@ class ostatus { "title", "attach", "app", "type", "location", "contact-id", "uri"); foreach ($copy_fields AS $field) { if (isset($item[$field])) { - $arr[$field] = $item[$field]; { + $arr[$field] = $item[$field]; } } From 958c24e9f3417ace9283362256d08013a8350ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:09:54 +0100 Subject: [PATCH 16/55] spaces -> tab + added spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index b77b1336d..6f57bc0a8 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -364,22 +364,22 @@ function settings_post(App $a) { call_hooks('settings_post', $_POST); - if((x($_POST,'password')) || (x($_POST,'confirm'))) { + if ((x($_POST,'password')) || (x($_POST,'confirm'))) { $newpass = $_POST['password']; $confirm = $_POST['confirm']; $oldpass = hash('whirlpool', $_POST['opassword']); $err = false; - if($newpass != $confirm ) { + if ($newpass != $confirm ) { notice( t('Passwords do not match. Password unchanged.') . EOL); $err = true; } - if((! x($newpass)) || (! x($confirm))) { + if ((! x($newpass)) || (! x($confirm))) { notice( t('Empty passwords are not allowed. Password unchanged.') . EOL); $err = true; - } + } // check if the old password was supplied correctly before // changing it to the new value From 5f71da586274cf09d2df0b1e67ae432598bb7799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:12:54 +0100 Subject: [PATCH 17/55] added more curly braces + spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/settings.php | 74 +++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 6f57bc0a8..4d23621cb 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -391,7 +391,7 @@ function settings_post(App $a) { $err = true; } - if(! $err) { + if (! $err) { $password = hash('whirlpool',$newpass); $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d", dbesc($password), @@ -445,32 +445,41 @@ function settings_post(App $a) { $notify = 0; - if(x($_POST,'notify1')) + if (x($_POST,'notify1')) { $notify += intval($_POST['notify1']); - if(x($_POST,'notify2')) + } + if (x($_POST,'notify2')) { $notify += intval($_POST['notify2']); - if(x($_POST,'notify3')) + } + if (x($_POST,'notify3')) { $notify += intval($_POST['notify3']); - if(x($_POST,'notify4')) + } + if (x($_POST,'notify4')) { $notify += intval($_POST['notify4']); - if(x($_POST,'notify5')) + } + if (x($_POST,'notify5')) { $notify += intval($_POST['notify5']); - if(x($_POST,'notify6')) + } + if (x($_POST,'notify6')) { $notify += intval($_POST['notify6']); - if(x($_POST,'notify7')) + } + if (x($_POST,'notify7')) { $notify += intval($_POST['notify7']); - if(x($_POST,'notify8')) + } + if (x($_POST,'notify8')) { $notify += intval($_POST['notify8']); + } // Adjust the page flag if the account type doesn't fit to the page flag. - if (($account_type == ACCOUNT_TYPE_PERSON) AND !in_array($page_flags, array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) + if (($account_type == ACCOUNT_TYPE_PERSON) AND !in_array($page_flags, array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) { $page_flags = PAGE_NORMAL; - elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) AND !in_array($page_flags, array(PAGE_SOAPBOX))) + } elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) AND !in_array($page_flags, array(PAGE_SOAPBOX))) { $page_flags = PAGE_SOAPBOX; - elseif (($account_type == ACCOUNT_TYPE_NEWS) AND !in_array($page_flags, array(PAGE_SOAPBOX))) + } elseif (($account_type == ACCOUNT_TYPE_NEWS) AND !in_array($page_flags, array(PAGE_SOAPBOX))) { $page_flags = PAGE_SOAPBOX; - elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) AND !in_array($page_flags, array(PAGE_COMMUNITY, PAGE_PRVGROUP))) + } elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) AND !in_array($page_flags, array(PAGE_COMMUNITY, PAGE_PRVGROUP))) { $page_flags = PAGE_COMMUNITY; + } $email_changed = false; @@ -480,13 +489,15 @@ function settings_post(App $a) { if($username != $a->user['username']) { $name_change = true; - if(strlen($username) > 40) + if (strlen($username) > 40) { $err .= t(' Please use a shorter name.'); - if(strlen($username) < 3) + } + if (strlen($username) < 3) { $err .= t(' Name too short.'); + } } - if($email != $a->user['email']) { + if ($email != $a->user['email']) { $email_changed = true; // check for the correct password $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); @@ -496,11 +507,12 @@ function settings_post(App $a) { $email = $a->user['email']; } // check the email is valid - if(! valid_email($email)) + if (! valid_email($email)) { $err .= t(' Not valid email.'); + } // ensure new email is not the admin mail //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { - if(x($a->config,'admin_email')) { + if (x($a->config,'admin_email')) { $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); if (in_array(strtolower($email), $adminlist)) { $err .= t(' Cannot change to that email.'); @@ -509,14 +521,13 @@ function settings_post(App $a) { } } - if(strlen($err)) { + if (strlen($err)) { notice($err . EOL); return; } - if($timezone != $a->user['timezone']) { - if(strlen($timezone)) - date_default_timezone_set($timezone); + if ($timezone != $a->user['timezone'] && strlen($timezone)) { + date_default_timezone_set($timezone); } $str_group_allow = perms2str($_POST['group_allow']); @@ -529,17 +540,17 @@ function settings_post(App $a) { // If openid has changed or if there's an openid but no openidserver, try and discover it. - if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) { + if ($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) { $tmp_str = $openid; - if(strlen($tmp_str) && validate_url($tmp_str)) { + if (strlen($tmp_str) && validate_url($tmp_str)) { logger('updating openidserver'); require_once('library/openid.php'); $open_id_obj = new LightOpenID; $open_id_obj->identity = $openid; $openidserver = $open_id_obj->discover($open_id_obj->identity); - } - else + } else { $openidserver = ''; + } } set_pconfig(local_user(),'expire','items', $expire_items); @@ -555,14 +566,13 @@ function settings_post(App $a) { set_pconfig(local_user(),'system','email_textonly', $email_textonly); - if($page_flags == PAGE_PRVGROUP) { + if ($page_flags == PAGE_PRVGROUP) { $hidewall = 1; - if((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { - if($def_gid) { + if ((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { + if ($def_gid) { info( t('Private forum has no privacy permissions. Using default privacy group.'). EOL); $str_group_allow = '<' . $def_gid . '>'; - } - else { + } else { notice( t('Private forum has no privacy permissions and no default privacy group.') . EOL); } } @@ -673,8 +683,6 @@ function settings_content(App $a) { return; } - - if (($a->argc > 1) && ($a->argv[1] === 'oauth')) { if (($a->argc > 2) && ($a->argv[2] === 'add')) { From 9cb100228a431fbc31ff063b57418a8746b3dd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:13:53 +0100 Subject: [PATCH 18/55] addec curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- util/po2php.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 5d3429796..60736bf4a 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -12,10 +12,11 @@ function po2php_run(&$argv, &$argc) { $pofile = $argv[1]; $outfile = dirname($pofile)."/strings.php"; - if (strstr($outfile,'util')) + if (strstr($outfile,'util')) { $lang = 'en'; - else + } else { $lang = str_replace('-','_',basename(dirname($pofile))); + } From 15c77beee29ccda758b72fd30a59eca8951459f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 14:28:43 +0100 Subject: [PATCH 19/55] added missing spaces/curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- boot.php | 457 +++++++++++++++++++++++++++++---------------------- index.php | 87 +++++----- testargs.php | 5 +- update.php | 4 +- 4 files changed, 316 insertions(+), 237 deletions(-) diff --git a/boot.php b/boot.php index 72c2e45aa..af11d8476 100644 --- a/boot.php +++ b/boot.php @@ -553,12 +553,12 @@ class App { * beyond are used. */ public $theme = array( - 'sourcename' => '', - 'videowidth' => 425, - 'videoheight' => 350, + 'sourcename' => '', + 'videowidth' => 425, + 'videoheight' => 350, 'force_max_items' => 0, - 'thread_allow' => true, - 'stylesheet' => '', + 'thread_allow' => true, + 'stylesheet' => '', 'template_engine' => 'smarty3', ); @@ -647,7 +647,7 @@ class App { $this->scheme = 'http'; - if((x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) || + if ((x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) || (x($_SERVER['HTTP_FORWARDED']) && preg_match("/proto=https/", $_SERVER['HTTP_FORWARDED'])) || (x($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || (x($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') || @@ -655,12 +655,12 @@ class App { (x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much? ) { $this->scheme = 'https'; - } + } - if(x($_SERVER,'SERVER_NAME')) { + if (x($_SERVER,'SERVER_NAME')) { $this->hostname = $_SERVER['SERVER_NAME']; - if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) + if (x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) $this->hostname .= ':' . $_SERVER['SERVER_PORT']; /* * Figure out if we are running at the top of a domain @@ -668,7 +668,7 @@ class App { */ $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\'); - if(isset($path) && strlen($path) && ($path != $this->path)) + if (isset($path) && strlen($path) && ($path != $this->path)) $this->path = $path; } @@ -704,7 +704,6 @@ class App { // fix query_string $this->query_string = str_replace($this->cmd."&",$this->cmd."?", $this->query_string); - // unix style "homedir" if (substr($this->cmd,0,1) === '~') { @@ -735,11 +734,10 @@ class App { $this->argv = explode('/',$this->cmd); $this->argc = count($this->argv); - if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) { + if ((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) { $this->module = str_replace(".", "_", $this->argv[0]); $this->module = str_replace("-", "_", $this->module); - } - else { + } else { $this->argc = 1; $this->argv = array('home'); $this->module = 'home'; @@ -753,8 +751,9 @@ class App { $this->pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1); $this->pager['itemspage'] = 50; $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; - if($this->pager['start'] < 0) + if ($this->pager['start'] < 0) { $this->pager['start'] = 0; + } $this->pager['total'] = 0; /* @@ -786,14 +785,17 @@ class App { $basepath = get_config("system", "basepath"); - if ($basepath == "") + if ($basepath == "") { $basepath = dirname(__FILE__); + } - if ($basepath == "") + if ($basepath == "") { $basepath = $_SERVER["DOCUMENT_ROOT"]; + } - if ($basepath == "") + if ($basepath == "") { $basepath = $_SERVER["PWD"]; + } return($basepath); } @@ -857,7 +859,7 @@ class App { function set_baseurl($url) { $parsed = @parse_url($url); - if($parsed) { + if ($parsed) { $this->scheme = $parsed['scheme']; $hostname = $parsed['host']; @@ -869,7 +871,7 @@ class App { } if (file_exists(".htpreconfig.php")) { - @include(".htpreconfig.php"); + include(".htpreconfig.php"); } if (get_config('config', 'hostname') != '') { @@ -883,8 +885,9 @@ class App { } function get_hostname() { - if (get_config('config','hostname') != "") + if (get_config('config','hostname') != "") { $this->hostname = get_config('config','hostname'); + } return $this->hostname; } @@ -919,44 +922,49 @@ class App { $interval = ((local_user()) ? get_pconfig(local_user(),'system','update_interval') : 40000); // If the update is "deactivated" set it to the highest integer number (~24 days) - if ($interval < 0) + if ($interval < 0) { $interval = 2147483647; + } - if($interval < 10000) + if ($interval < 10000) { $interval = 40000; + } // compose the page title from the sitename and the // current module called - if (!$this->module=='') - { - $this->page['title'] = $this->config['sitename'].' ('.$this->module.')'; + if (!$this->module=='') { + $this->page['title'] = $this->config['sitename'].' ('.$this->module.')'; } else { - $this->page['title'] = $this->config['sitename']; + $this->page['title'] = $this->config['sitename']; } /* put the head template at the beginning of page['htmlhead'] * since the code added by the modules frequently depends on it * being first */ - if(!isset($this->page['htmlhead'])) + if (!isset($this->page['htmlhead'])) { $this->page['htmlhead'] = ''; + } // If we're using Smarty, then doing replace_macros() will replace // any unrecognized variables with a blank string. Since we delay // replacing $stylesheet until later, we need to replace it now // with another variable name - if($this->theme['template_engine'] === 'smarty3') + if ($this->theme['template_engine'] === 'smarty3') { $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3'); - else + } else { $stylesheet = '$stylesheet'; + } $shortcut_icon = get_config("system", "shortcut_icon"); - if ($shortcut_icon == "") + if ($shortcut_icon == "") { $shortcut_icon = "images/friendica-32.png"; + } $touch_icon = get_config("system", "touch_icon"); - if ($touch_icon == "") + if ($touch_icon == "") { $touch_icon = "images/friendica-128.png"; + } // get data wich is needed for infinite scroll on the network page $invinite_scroll = infinite_scroll_data($this->module); @@ -978,8 +986,9 @@ class App { } function init_page_end() { - if(!isset($this->page['end'])) + if (!isset($this->page['end'])) { $this->page['end'] = ''; + } $tpl = get_markup_template('end.tpl'); $this->page['end'] = replace_macros($tpl,array( '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!! @@ -1015,13 +1024,13 @@ class App { // The following code is deactivated. It doesn't seem to make any sense and it slows down the system. /* - if($this->cached_profile_image[$avatar_image]) + if ($this->cached_profile_image[$avatar_image]) return $this->cached_profile_image[$avatar_image]; $path_parts = explode("/",$avatar_image); $common_filename = $path_parts[count($path_parts)-1]; - if($this->cached_profile_picdate[$common_filename]){ + if ($this->cached_profile_picdate[$common_filename]){ $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename]; } else { $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'", @@ -1076,7 +1085,7 @@ class App { function register_template_engine($class, $name = '') { if ($name===""){ $v = get_class_vars( $class ); - if(x($v,"name")) $name = $v['name']; + if (x($v,"name")) $name = $v['name']; } if ($name===""){ echo "template engine $class cannot be registered without a name.\n"; @@ -1105,7 +1114,7 @@ class App { } if (isset($this->template_engines[$template_engine])){ - if(isset($this->template_engine_instance[$template_engine])){ + if (isset($this->template_engine_instance[$template_engine])){ return $this->template_engine_instance[$template_engine]; } else { $class = $this->template_engines[$template_engine]; @@ -1134,7 +1143,7 @@ class App { switch($engine) { case 'smarty3': - if(is_writable('view/smarty3/')) + if (is_writable('view/smarty3/')) $this->theme['template_engine'] = 'smarty3'; break; default: @@ -1152,8 +1161,9 @@ class App { } function save_timestamp($stamp, $value) { - if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) + if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) { return; + } $duration = (float)(microtime(true)-$stamp); @@ -1235,8 +1245,9 @@ class App { array_shift($trace); $callstack = array(); - foreach ($trace AS $func) + foreach ($trace AS $func) { $callstack[] = $func["function"]; + } return implode(", ", $callstack); } @@ -1258,31 +1269,33 @@ class App { * @return bool Is it a known backend? */ function is_backend() { - $backend = array(); - $backend[] = "_well_known"; - $backend[] = "api"; - $backend[] = "dfrn_notify"; - $backend[] = "fetch"; - $backend[] = "hcard"; - $backend[] = "hostxrd"; - $backend[] = "nodeinfo"; - $backend[] = "noscrape"; - $backend[] = "p"; - $backend[] = "poco"; - $backend[] = "post"; - $backend[] = "proxy"; - $backend[] = "pubsub"; - $backend[] = "pubsubhubbub"; - $backend[] = "receive"; - $backend[] = "rsd_xml"; - $backend[] = "salmon"; - $backend[] = "statistics_json"; - $backend[] = "xrd"; + static $backend = array( + "_well_known", + "api", + "dfrn_notify", + "fetch", + "hcard", + "hostxrd", + "nodeinfo", + "noscrape", + "p", + "poco", + "post", + "proxy", + "pubsub", + "pubsubhubbub", + "receive", + "rsd_xml", + "salmon", + "statistics_json", + "xrd", + ); - if (in_array($this->module, $backend)) + if (in_array($this->module, $backend)) { return(true); - else + } else { return($this->backend); + } } /** @@ -1295,13 +1308,15 @@ class App { if ($this->is_backend()) { $process = "backend"; $max_processes = get_config('system', 'max_processes_backend'); - if (intval($max_processes) == 0) + if (intval($max_processes) == 0) { $max_processes = 5; + } } else { $process = "frontend"; $max_processes = get_config('system', 'max_processes_frontend'); - if (intval($max_processes) == 0) + if (intval($max_processes) == 0) { $max_processes = 20; + } } $processlist = dbm::processlist(); @@ -1326,13 +1341,15 @@ class App { if ($this->is_backend()) { $process = "backend"; $maxsysload = intval(get_config('system', 'maxloadavg')); - if ($maxsysload < 1) + if ($maxsysload < 1) { $maxsysload = 50; + } } else { $process = "frontend"; $maxsysload = intval(get_config('system','maxloadavg_frontend')); - if ($maxsysload < 1) + if ($maxsysload < 1) { $maxsysload = 50; + } } $load = current_load(); @@ -1368,16 +1385,17 @@ class App { // add baseurl to args. cli scripts can't construct it $args[] = $this->get_baseurl(); - for($x = 0; $x < count($args); $x ++) + for ($x = 0; $x < count($args); $x ++) { $args[$x] = escapeshellarg($args[$x]); + } $cmdline = implode($args," "); - if(get_config('system','proc_windows')) + if (get_config('system','proc_windows')) { proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__))); - else + } else { proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); - + } } /** @@ -1454,17 +1472,17 @@ function get_app() { * @return bool|int */ function x($s,$k = NULL) { - if($k != NULL) { - if((is_array($s)) && (array_key_exists($k,$s))) { - if($s[$k]) + if ($k != NULL) { + if ((is_array($s)) && (array_key_exists($k,$s))) { + if ($s[$k]) { return (int) 1; + } return (int) 0; - } + } return false; - } - else { - if(isset($s)) { - if($s) { + } else { + if (isset($s)) { + if ($s) { return (int) 1; } return (int) 0; @@ -1492,8 +1510,9 @@ function clean_urls() { function z_path() { $base = App::get_baseurl(); - if(! clean_urls()) + if (! clean_urls()) { $base .= '/?q='; + } return $base; } @@ -1518,8 +1537,9 @@ function z_root() { * @return string */ function absurl($path) { - if(strpos($path,'/') === 0) + if (strpos($path,'/') === 0) { return z_path() . $path; + } return $path; } @@ -1535,12 +1555,13 @@ function is_ajax() { function check_db() { $build = get_config('system','build'); - if(! x($build)) { + if (! x($build)) { set_config('system','build',DB_UPDATE_VERSION); $build = DB_UPDATE_VERSION; } - if($build != DB_UPDATE_VERSION) + if ($build != DB_UPDATE_VERSION) { proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php'); + } } @@ -1559,10 +1580,12 @@ function check_url(App $a) { // and www.example.com vs example.com. // We will only change the url to an ip address if there is no existing setting - if(! x($url)) + if (! x($url)) { $url = set_config('system','url',App::get_baseurl()); - if((! link_compare($url,App::get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) + } + if ((! link_compare($url,App::get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) { $url = set_config('system','url',App::get_baseurl()); + } return; } @@ -1573,13 +1596,14 @@ function check_url(App $a) { */ function update_db(App $a) { $build = get_config('system','build'); - if(! x($build)) + if (! x($build)) { $build = set_config('system','build',DB_UPDATE_VERSION); + } - if($build != DB_UPDATE_VERSION) { + if ($build != DB_UPDATE_VERSION) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); - if($stored < $current) { + if ($stored < $current) { Config::load('database'); // We're reporting a different version than what is currently installed. @@ -1589,12 +1613,13 @@ function update_db(App $a) { // updating right this very second and the correct version of the update.php // file may not be here yet. This can happen on a very busy site. - if(DB_UPDATE_VERSION == UPDATE_VERSION) { + if (DB_UPDATE_VERSION == UPDATE_VERSION) { // Compare the current structure with the defined structure $t = get_config('database','dbupdate_'.DB_UPDATE_VERSION); - if($t !== false) + if ($t !== false) { return; + } set_config('database','dbupdate_'.DB_UPDATE_VERSION, time()); @@ -1602,15 +1627,18 @@ function update_db(App $a) { // conflits with new routine) for ($x = $stored; $x < NEW_UPDATE_ROUTINE_VERSION; $x++) { $r = run_update_function($x); - if (!$r) break; + if (!$r) { + break; + } + } + if ($stored < NEW_UPDATE_ROUTINE_VERSION) { + $stored = NEW_UPDATE_ROUTINE_VERSION; } - if ($stored < NEW_UPDATE_ROUTINE_VERSION) $stored = NEW_UPDATE_ROUTINE_VERSION; - // run new update routine // it update the structure in one call $retval = update_structure(false, true); - if($retval) { + if ($retval) { update_fail( DB_UPDATE_VERSION, $retval @@ -1621,9 +1649,11 @@ function update_db(App $a) { } // run any left update_nnnn functions in update.php - for($x = $stored; $x < $current; $x ++) { + for ($x = $stored; $x < $current; $x ++) { $r = run_update_function($x); - if (!$r) break; + if (!$r) { + break; + } } } } @@ -1633,7 +1663,7 @@ function update_db(App $a) { } function run_update_function($x) { - if(function_exists('update_' . $x)) { + if (function_exists('update_' . $x)) { // There could be a lot of processes running or about to run. // We want exactly one process to run the update command. @@ -1644,8 +1674,9 @@ function run_update_function($x) { // delete the config entry to try again. $t = get_config('database','update_' . $x); - if($t !== false) + if ($t !== false) { return false; + } set_config('database','update_' . $x, time()); // call the specific update @@ -1653,7 +1684,7 @@ function run_update_function($x) { $func = 'update_' . $x; $retval = $func(); - if($retval) { + if ($retval) { //send the administrator an e-mail update_fail( $x, @@ -1686,39 +1717,40 @@ function run_update_function($x) { * * @param App $a * - */ + */ function check_plugins(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $installed = $r; - else + } else { $installed = array(); + } $plugins = get_config('system','addon'); $plugins_arr = array(); - if($plugins) + if ($plugins) { $plugins_arr = explode(',',str_replace(' ', '',$plugins)); + } $a->plugins = $plugins_arr; $installed_arr = array(); - if(count($installed)) { - foreach($installed as $i) { - if(! in_array($i['name'],$plugins_arr)) { + if (count($installed)) { + foreach ($installed as $i) { + if (! in_array($i['name'],$plugins_arr)) { uninstall_plugin($i['name']); - } - else { + } else { $installed_arr[] = $i['name']; } } } - if(count($plugins_arr)) { - foreach($plugins_arr as $p) { - if(! in_array($p,$installed_arr)) { + if (count($plugins_arr)) { + foreach ($plugins_arr as $p) { + if (! in_array($p,$installed_arr)) { install_plugin($p); } } @@ -1778,10 +1810,9 @@ function login($register = false, $hiddens=false) { $dest_url = $a->query_string; - if(local_user()) { + if (local_user()) { $tpl = get_markup_template("logout.tpl"); - } - else { + } else { $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array( '$baseurl' => $a->get_baseurl(true) )); @@ -1793,29 +1824,29 @@ function login($register = false, $hiddens=false) { $o .= replace_macros($tpl, array( - '$dest_url' => $dest_url, - '$logout' => t('Logout'), - '$login' => t('Login'), + '$dest_url' => $dest_url, + '$logout' => t('Logout'), + '$login' => t('Login'), - '$lname' => array('username', t('Nickname or Email: ') , '', ''), - '$lpassword' => array('password', t('Password: '), '', ''), - '$lremember' => array('remember', t('Remember me'), 0, ''), + '$lname' => array('username', t('Nickname or Email: ') , '', ''), + '$lpassword' => array('password', t('Password: '), '', ''), + '$lremember' => array('remember', t('Remember me'), 0, ''), - '$openid' => !$noid, - '$lopenid' => array('openid_url', t('Or login using OpenID: '),'',''), + '$openid' => !$noid, + '$lopenid' => array('openid_url', t('Or login using OpenID: '),'',''), - '$hiddens' => $hiddens, + '$hiddens' => $hiddens, - '$register' => $reg, + '$register' => $reg, '$lostpass' => t('Forgot your password?'), '$lostlink' => t('Password Reset'), - '$tostitle' => t('Website Terms of Service'), - '$toslink' => t('terms of service'), + '$tostitle' => t('Website Terms of Service'), + '$toslink' => t('terms of service'), - '$privacytitle' => t('Website Privacy Policy'), - '$privacylink' => t('privacy policy'), + '$privacytitle' => t('Website Privacy Policy'), + '$privacylink' => t('privacy policy'), )); @@ -1829,8 +1860,9 @@ function login($register = false, $hiddens=false) { */ function killme() { - if (!get_app()->is_backend()) + if (!get_app()->is_backend()) { session_write_close(); + } exit; } @@ -1839,8 +1871,9 @@ function killme() { * @brief Redirect to another URL and terminate this process. */ function goaway($s) { - if (!strstr(normalise_link($s), "http://")) + if (!strstr(normalise_link($s), "http://")) { $s = App::get_baseurl()."/".$s; + } header("Location: $s"); killme(); @@ -1888,8 +1921,9 @@ function public_contact() { * @return int|bool visitor_id or false */ function remote_user() { - if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) + if ((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) { return intval($_SESSION['visitor_id']); + } return false; } @@ -1902,9 +1936,12 @@ function remote_user() { */ function notice($s) { $a = get_app(); - if(! x($_SESSION,'sysmsg')) $_SESSION['sysmsg'] = array(); - if($a->interactive) + if (! x($_SESSION,'sysmsg')) { + $_SESSION['sysmsg'] = array(); + } + if ($a->interactive) { $_SESSION['sysmsg'][] = $s; + } } /** @@ -1917,12 +1954,16 @@ function notice($s) { function info($s) { $a = get_app(); - if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) + if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) { return; + } - if(! x($_SESSION,'sysmsg_info')) $_SESSION['sysmsg_info'] = array(); - if($a->interactive) + if (! x($_SESSION,'sysmsg_info')) { + $_SESSION['sysmsg_info'] = array(); + } + if ($a->interactive) { $_SESSION['sysmsg_info'][] = $s; + } } @@ -1984,8 +2025,9 @@ function proc_run($cmd){ $arr = array('args' => $args, 'run_cmd' => true); call_hooks("proc_run", $arr); - if (!$arr['run_cmd'] OR !count($args)) + if (!$arr['run_cmd'] OR !count($args)) { return; + } $priority = PRIORITY_MEDIUM; $dont_fork = get_config("system", "worker_dont_fork"); @@ -2008,12 +2050,13 @@ function proc_run($cmd){ $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'", dbesc($parameters)); - if (!$found) + if (!dbm::is_result($found)) { q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`) VALUES ('%s', '%s', %d)", dbesc($parameters), dbesc(datetime_convert()), intval($priority)); + } // Should we quit and wait for the poller to be called as a cronjob? if ($dont_fork) { @@ -2026,12 +2069,14 @@ function proc_run($cmd){ // Get number of allowed number of worker threads $queues = intval(get_config("system", "worker_queues")); - if ($queues == 0) + if ($queues == 0) { $queues = 4; + } // If there are already enough workers running, don't fork another one - if ($workers[0]["workers"] >= $queues) + if ($workers[0]["workers"] >= $queues) { return; + } // Now call the poller to execute the jobs that we just added to the queue $args = array("include/poller.php", "no_cron"); @@ -2048,20 +2093,22 @@ function current_theme(){ // Find the theme that belongs to the user whose stuff we are looking at - if($a->profile_uid && ($a->profile_uid != local_user())) { + if ($a->profile_uid && ($a->profile_uid != local_user())) { $r = q("select theme from user where uid = %d limit 1", intval($a->profile_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $page_theme = $r[0]['theme']; + } } // Allow folks to over-rule user themes and always use their own on their own site. // This works only if the user is on the same server - if($page_theme && local_user() && (local_user() != $a->profile_uid)) { - if(get_pconfig(local_user(),'system','always_my_theme')) + if ($page_theme && local_user() && (local_user() != $a->profile_uid)) { + if (get_pconfig(local_user(),'system','always_my_theme')) { $page_theme = null; + } } // $mobile_detect = new Mobile_Detect(); @@ -2082,38 +2129,44 @@ function current_theme(){ } $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme); - if($theme_name === '---') { + if ($theme_name === '---') { // user has selected to have the mobile theme be the same as the normal one $system_theme = $standard_system_theme; $theme_name = $standard_theme_name; - if($page_theme) + if ($page_theme) { $theme_name = $page_theme; + } } } - } - else { + } else { $system_theme = $standard_system_theme; $theme_name = $standard_theme_name; - if($page_theme) + if ($page_theme) { $theme_name = $page_theme; + } } - if($theme_name && + if ($theme_name && (file_exists('view/theme/' . $theme_name . '/style.css') || - file_exists('view/theme/' . $theme_name . '/style.php'))) + file_exists('view/theme/' . $theme_name . '/style.php'))) { return($theme_name); + } - foreach($app_base_themes as $t) { - if(file_exists('view/theme/' . $t . '/style.css')|| - file_exists('view/theme/' . $t . '/style.php')) + foreach ($app_base_themes as $t) { + if (file_exists('view/theme/' . $t . '/style.css') || + file_exists('view/theme/' . $t . '/style.php')) { return($t); + } } $fallback = array_merge(glob('view/theme/*/style.css'),glob('view/theme/*/style.php')); - if(count($fallback)) + if (count($fallback)) { return (str_replace('view/theme/','', substr($fallback[0],0,-10))); + } + + /// @TODO No final return statement? } @@ -2130,8 +2183,9 @@ function current_theme_url() { $t = current_theme(); $opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : ''); - if (file_exists('view/theme/' . $t . '/style.php')) + if (file_exists('view/theme/' . $t . '/style.php')) { return('view/theme/'.$t.'/style.pcss'.$opts); + } return('view/theme/'.$t.'/style.css'); } @@ -2160,8 +2214,9 @@ function feed_birthday($uid,$tz) { $birthday = ''; - if(! strlen($tz)) + if (! strlen($tz)) { $tz = 'UTC'; + } $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval($uid) @@ -2169,13 +2224,14 @@ function feed_birthday($uid,$tz) { if (dbm::is_result($p)) { $tmp_dob = substr($p[0]['dob'],5); - if(intval($tmp_dob)) { + if (intval($tmp_dob)) { $y = datetime_convert($tz,$tz,'now','Y'); $bd = $y . '-' . $tmp_dob . ' 00:00'; $t_dob = strtotime($bd); $now = strtotime(datetime_convert($tz,$tz,'now')); - if($t_dob < $now) + if ($t_dob < $now) { $bd = $y + 1 . '-' . $tmp_dob . ' 00:00'; + } $birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME); } } @@ -2193,8 +2249,8 @@ function is_site_admin() { $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); - //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) - if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) + //if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) + if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) return true; return false; } @@ -2209,16 +2265,16 @@ function is_site_admin() { */ function build_querystring($params, $name=null) { $ret = ""; - foreach($params as $key=>$val) { - if(is_array($val)) { - if($name==null) { + foreach ($params as $key=>$val) { + if (is_array($val)) { + if ($name==null) { $ret .= build_querystring($val, $key); } else { $ret .= build_querystring($val, $name."[$key]"); } } else { $val = urlencode($val); - if($name!=null) { + if ($name!=null) { $ret.=$name."[$key]"."=$val&"; } else { $ret.= "$key=$val&"; @@ -2230,7 +2286,7 @@ function build_querystring($params, $name=null) { function explode_querystring($query) { $arg_st = strpos($query, '?'); - if($arg_st !== false) { + if ($arg_st !== false) { $base = substr($query, 0, $arg_st); $arg_st += 1; } else { @@ -2239,13 +2295,14 @@ function explode_querystring($query) { } $args = explode('&', substr($query, $arg_st)); - foreach($args as $k=>$arg) { - if($arg === '') + foreach ($args as $k=>$arg) { + if ($arg === '') { unset($args[$k]); + } } $args = array_values($args); - if(!$base) { + if (!$base) { $base = $args[0]; unset($args[0]); $args = array_values($args); @@ -2264,7 +2321,9 @@ function explode_querystring($query) { */ function curPageURL() { $pageURL = 'http'; - if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} + if ($_SERVER["HTTPS"] == "on") { + $pageURL .= "s"; + } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; @@ -2276,7 +2335,7 @@ function curPageURL() { function random_digits($digits) { $rn = ''; - for($i = 0; $i < $digits; $i++) { + for ($i = 0; $i < $digits; $i++) { $rn .= rand(0,9); } return $rn; @@ -2285,8 +2344,9 @@ function random_digits($digits) { function get_server() { $server = get_config("system", "directory"); - if ($server == "") + if ($server == "") { $server = "http://dir.friendi.ca"; + } return($server); } @@ -2294,8 +2354,9 @@ function get_server() { function get_cachefile($file, $writemode = true) { $cache = get_itemcachepath(); - if ((! $cache) || (! is_dir($cache))) + if ((! $cache) || (! is_dir($cache))) { return(""); + } $subfolder = $cache."/".substr($file, 0, 2); @@ -2317,24 +2378,29 @@ function clear_cache($basepath = "", $path = "") { $path = $basepath; } - if (($path == "") OR (!is_dir($path))) + if (($path == "") OR (!is_dir($path))) { return; + } - if (substr(realpath($path), 0, strlen($basepath)) != $basepath) + if (substr(realpath($path), 0, strlen($basepath)) != $basepath) { return; + } $cachetime = (int)get_config('system','itemcache_duration'); - if ($cachetime == 0) + if ($cachetime == 0) { $cachetime = 86400; + } if (is_writable($path)){ if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { $fullpath = $path."/".$file; - if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) + if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) { clear_cache($basepath, $fullpath); - if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) + } + if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) { unlink($fullpath); + } } closedir($dh); } @@ -2344,8 +2410,9 @@ function clear_cache($basepath = "", $path = "") { function get_itemcachepath() { // Checking, if the cache is deactivated $cachetime = (int)get_config('system','itemcache_duration'); - if ($cachetime < 0) + if ($cachetime < 0) { return ""; + } $itemcache = get_config('system','itemcache'); if (($itemcache != "") AND App::directory_usable($itemcache)) { @@ -2356,7 +2423,7 @@ function get_itemcachepath() { if ($temppath != "") { $itemcache = $temppath."/itemcache"; - if(!file_exists($itemcache) && !is_dir($itemcache)) { + if (!file_exists($itemcache) && !is_dir($itemcache)) { mkdir($itemcache); } @@ -2448,7 +2515,7 @@ function set_template_engine(App $a, $engine = 'internal') { $a->set_template_engine($engine); } -if(!function_exists('exif_imagetype')) { +if (!function_exists('exif_imagetype')) { function exif_imagetype($file) { $size = getimagesize($file); return($size[2]); @@ -2460,37 +2527,42 @@ function validate_include(&$file) { $file = realpath($file); - if (strpos($file, getcwd()) !== 0) + if (strpos($file, getcwd()) !== 0) { return false; + } $file = str_replace(getcwd()."/", "", $file, $count); - if ($count != 1) + if ($count != 1) { return false; + } - if ($orig_file !== $file) + if ($orig_file !== $file) { return false; + } $valid = false; - if (strpos($file, "include/") === 0) + if (strpos($file, "include/") === 0) { $valid = true; + } - if (strpos($file, "addon/") === 0) + if (strpos($file, "addon/") === 0) { $valid = true; + } - if (!$valid) - return false; - - return true; + // Simply return flag + return ($valid); } function current_load() { - if (!function_exists('sys_getloadavg')) + if (!function_exists('sys_getloadavg')) { return false; + } $load_arr = sys_getloadavg(); - if (!is_array($load_arr)) + if (!is_array($load_arr)) { return false; + } return max($load_arr[0], $load_arr[1]); } @@ -2511,8 +2583,9 @@ function argc() { * @return string Value of the argv key */ function argv($x) { - if(array_key_exists($x,get_app()->argv)) + if (array_key_exists($x,get_app()->argv)) { return get_app()->argv[$x]; + } return ''; } diff --git a/index.php b/index.php index 7408f495c..d3310ba1a 100644 --- a/index.php +++ b/index.php @@ -28,17 +28,17 @@ $a->backend = false; /** * * Load the configuration file which contains our DB credentials. - * Ignore errors. If the file doesn't exist or is empty, we are running in installation mode. + * Ignore errors. If the file doesn't exist or is empty, we are running in + * installation mode. * */ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true); -@include(".htconfig.php"); - - - - +// Only load config if found, don't surpress errors +if (!$install) { + include(".htconfig.php"); +} /** * @@ -48,7 +48,7 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false require_once("include/dba.php"); -if(!$install) { +if (!$install) { $db = new dba($db_host, $db_user, $db_pass, $db_data, $install); unset($db_host, $db_user, $db_pass, $db_data); @@ -117,12 +117,12 @@ if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) { if (dbm::is_result($r)) $_SESSION['language'] = $r[0]['language']; } -if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { +if ((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { $lang = $_SESSION['language']; load_translation_table($lang); } -if((x($_GET,'zrl')) && (!$install && !$maintenance)) { +if ((x($_GET,'zrl')) && (!$install && !$maintenance)) { // Only continue when the given profile link seems valid // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") AND @@ -223,7 +223,7 @@ if ((local_user()) || (! $privateapps === "1")) { * further processing. */ -if(strlen($a->module)) { +if (strlen($a->module)) { /** * @@ -233,12 +233,14 @@ if(strlen($a->module)) { */ // Compatibility with the Android Diaspora client - if ($a->module == "stream") + if ($a->module == "stream") { $a->module = "network"; + } // Compatibility with the Firefox App - if (($a->module == "users") AND ($a->cmd == "users/sign_in")) + if (($a->module == "users") AND ($a->cmd == "users/sign_in")) { $a->module = "login"; + } $privateapps = get_config('config','private_addons'); @@ -246,11 +248,11 @@ if(strlen($a->module)) { //Check if module is an app and if public access to apps is allowed or not if ((!local_user()) && plugin_is_app($a->module) && $privateapps === "1") { info( t("You must be logged in to use addons. ")); - } - else { + } else { include_once("addon/{$a->module}/{$a->module}.php"); - if(function_exists($a->module . '_module')) + if (function_exists($a->module . '_module')) { $a->module_loaded = true; + } } } @@ -320,29 +322,29 @@ if (!$install && !$maintenance) { * Call module functions */ -if($a->module_loaded) { +if ($a->module_loaded) { $a->page['page_title'] = $a->module; $placeholder = ''; - if(function_exists($a->module . '_init')) { + if (function_exists($a->module . '_init')) { call_hooks($a->module . '_mod_init', $placeholder); $func = $a->module . '_init'; $func($a); } - if(function_exists(str_replace('-','_',current_theme()) . '_init')) { + if (function_exists(str_replace('-','_',current_theme()) . '_init')) { $func = str_replace('-','_',current_theme()) . '_init'; $func($a); } // elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/theme.php")) { // require_once("view/theme/".$a->theme_info["extends"]."/theme.php"); -// if(function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_init')) { +// if (function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_init')) { // $func = str_replace('-','_',$a->theme_info["extends"]) . '_init'; // $func($a); // } // } - if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) + if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) && (function_exists($a->module . '_post')) && (! x($_POST,'auth-params'))) { call_hooks($a->module . '_mod_post', $_POST); @@ -350,13 +352,13 @@ if($a->module_loaded) { $func($a); } - if((! $a->error) && (function_exists($a->module . '_afterpost'))) { + if ((! $a->error) && (function_exists($a->module . '_afterpost'))) { call_hooks($a->module . '_mod_afterpost',$placeholder); $func = $a->module . '_afterpost'; $func($a); } - if((! $a->error) && (function_exists($a->module . '_content'))) { + if ((! $a->error) && (function_exists($a->module . '_content'))) { $arr = array('content' => $a->page['content']); call_hooks($a->module . '_mod_content', $arr); $a->page['content'] = $arr['content']; @@ -366,7 +368,7 @@ if($a->module_loaded) { $a->page['content'] .= $arr['content']; } - if(function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) { + if (function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) { $func = str_replace('-','_',current_theme()) . '_content_loaded'; $func($a); } @@ -392,18 +394,20 @@ $a->init_page_end(); // If you're just visiting, let javascript take you home -if(x($_SESSION,'visitor_home')) +if (x($_SESSION,'visitor_home')) { $homebase = $_SESSION['visitor_home']; -elseif(local_user()) +} elseif (local_user()) { $homebase = 'profile/' . $a->user['nickname']; +} -if(isset($homebase)) +if (isset($homebase)) { $a->page['content'] .= ''; +} // now that we've been through the module content, see if the page reported // a permission problem and if so, a 403 response would seem to be in order. -if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { +if (stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.')); } @@ -413,13 +417,13 @@ if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { * */ -/*if(x($_SESSION,'sysmsg')) { +/*if (x($_SESSION,'sysmsg')) { $a->page['content'] = "
{$_SESSION['sysmsg']}
\r\n" . ((x($a->page,'content')) ? $a->page['content'] : ''); $_SESSION['sysmsg']=""; unset($_SESSION['sysmsg']); } -if(x($_SESSION,'sysmsg_info')) { +if (x($_SESSION,'sysmsg_info')) { $a->page['content'] = "
{$_SESSION['sysmsg_info']}
\r\n" . ((x($a->page,'content')) ? $a->page['content'] : ''); $_SESSION['sysmsg_info']=""; @@ -437,7 +441,7 @@ call_hooks('page_end', $a->page['content']); * */ -if($a->module != 'install' && $a->module != 'maintenance') { +if ($a->module != 'install' && $a->module != 'maintenance') { nav($a); } @@ -445,27 +449,27 @@ if($a->module != 'install' && $a->module != 'maintenance') { * Add a "toggle mobile" link if we're using a mobile device */ -if($a->is_mobile || $a->is_tablet) { - if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { +if ($a->is_mobile || $a->is_tablet) { + if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { $link = 'toggle_mobile?address=' . curPageURL(); - } - else { + } else { $link = 'toggle_mobile?off=1&address=' . curPageURL(); } $a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array( - '$toggle_link' => $link, - '$toggle_text' => t('toggle mobile') - )); + '$toggle_link' => $link, + '$toggle_text' => t('toggle mobile') + )); } /** * Build the page - now that we have all the components */ -if(!$a->theme['stylesheet']) +if (!$a->theme['stylesheet']) { $stylesheet = current_theme_url(); -else +} else { $stylesheet = $a->theme['stylesheet']; +} $a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']); //$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet)); @@ -499,8 +503,9 @@ if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) { echo substr($target->saveHTML(), 6, -8); - if (!$a->is_backend()) + if (!$a->is_backend()) { session_write_close(); + } exit; } @@ -519,7 +524,7 @@ if (isset($_GET["mode"])) { } // If there is no page template use the default page template -if(!$template) { +if (!$template) { $template = theme_include("default.php"); } diff --git a/testargs.php b/testargs.php index a6042f8eb..a0ddea345 100644 --- a/testargs.php +++ b/testargs.php @@ -15,7 +15,8 @@ */ -if(($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) +if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) { echo $_SERVER["argv"][1]; -else +} else { echo ''; +} diff --git a/update.php b/update.php index bc0e17b8b..7c3b32e2d 100644 --- a/update.php +++ b/update.php @@ -148,7 +148,7 @@ function update_1014() { if (dbm::is_result($r)) { foreach ($r as $rr) { $ph = new Photo($rr['data']); - if($ph->is_valid()) { + if ($ph->is_valid()) { $ph->scaleImage(48); $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0)); } @@ -1756,7 +1756,7 @@ function update_1190() { $plugins = get_config('system','addon'); $plugins_arr = array(); - if($plugins) { + if ($plugins) { $plugins_arr = explode(",",str_replace(" ", "",$plugins)); $idx = array_search($plugin, $plugins_arr); From 720e7d6034abf216a444bf44b3965db067a3ef49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 14:44:46 +0100 Subject: [PATCH 20/55] curly braces + spaces added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- util/db_update.php | 2 +- util/docblox_errorchecker.php | 24 ++++----- util/extract.php | 27 +++++----- util/maintenance.php | 8 +-- util/php2po.php | 8 +-- util/po2php.php | 56 ++++++++++++++------- util/typo.php | 93 +++++++++++++++++------------------ 7 files changed, 121 insertions(+), 97 deletions(-) diff --git a/util/db_update.php b/util/db_update.php index 32b44e6d0..7718162f6 100644 --- a/util/db_update.php +++ b/util/db_update.php @@ -24,7 +24,7 @@ echo "Old DB VERSION: " . $build . "\n"; echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n"; -if($build != DB_UPDATE_VERSION) { +if ($build != DB_UPDATE_VERSION) { echo "Updating database..."; check_db($a); echo "Done\n"; diff --git a/util/docblox_errorchecker.php b/util/docblox_errorchecker.php index af4c76444..a7d1ecce1 100644 --- a/util/docblox_errorchecker.php +++ b/util/docblox_errorchecker.php @@ -33,7 +33,7 @@ */ function namesList($fileset) { $fsparam=""; - foreach($fileset as $file) { + foreach ($fileset as $file) { $fsparam=$fsparam.",".$file; } return $fsparam; @@ -50,7 +50,7 @@ function namesList($fileset) { function runs($fileset) { $fsParam=namesList($fileset); exec('docblox -t phpdoc_out -f '.$fsParam); - if(file_exists("phpdoc_out/index.html")) { + if (file_exists("phpdoc_out/index.html")) { echo "\n Subset ".$fsParam." is okay. \n"; exec('rm -r phpdoc_out'); return true; @@ -79,7 +79,7 @@ function reduce($fileset, $ps) { //filter working subsets... $parts=array_filter($parts, "runs"); //melt remaining parts together - if(is_array($parts)) { + if (is_array($parts)) { return array_reduce($parts, "array_merge", array()); } return array(); @@ -94,17 +94,17 @@ $dirstack=array(); $filelist=array(); //loop over all files in $dir -while($dh=opendir($dir)) { - while($file=readdir($dh)) { - if(is_dir($dir."/".$file)) { +while ($dh=opendir($dir)) { + while ($file=readdir($dh)) { + if (is_dir($dir."/".$file)) { //add to directory stack - if($file!=".." && $file!=".") { + if ($file!=".." && $file!=".") { array_push($dirstack, $dir."/".$file); echo "dir ".$dir."/".$file."\n"; } } else { //test if it is a source file and add to filelist - if(substr($file, strlen($file)-4)==".php") { + if (substr($file, strlen($file)-4)==".php") { array_push($filelist, $dir."/".$file); echo $dir."/".$file."\n"; } @@ -115,7 +115,7 @@ while($dh=opendir($dir)) { } //check the entire set -if(runs($filelist)) { +if (runs($filelist)) { echo "I can not detect a problem. \n"; exit; } @@ -128,15 +128,15 @@ do { echo $i."/".count($fileset)." elements remaining. \n"; $res=reduce($res, count($res)/2); shuffle($res); -} while(count($res)<$i); +} while (count($res)<$i); //check one file after another $needed=array(); -while(count($res)!=0) { +while (count($res)!=0) { $file=array_pop($res); - if(runs(array_merge($res, $needed))) { + if (runs(array_merge($res, $needed))) { echo "needs: ".$file." and file count ".count($needed); array_push($needed, $file); } diff --git a/util/extract.php b/util/extract.php index 90127f3c1..3eb332d4f 100644 --- a/util/extract.php +++ b/util/extract.php @@ -6,7 +6,7 @@ $files = array_merge($files,glob('mod/*'),glob('include/*'),glob('addon/*/*')); - foreach($files as $file) { + foreach ($files as $file) { $str = file_get_contents($file); $pat = '| t\(([^\)]*)\)|'; @@ -16,14 +16,14 @@ preg_match_all($patt, $str, $matchestt); - if(count($matches)){ - foreach($matches[1] as $match) { - if(! in_array($match,$arr)) + if (count($matches)){ + foreach ($matches[1] as $match) { + if (! in_array($match,$arr)) $arr[] = $match; } } - if(count($matchestt)){ - foreach($matchestt[1] as $match) { + if (count($matchestt)){ + foreach ($matchestt[1] as $match) { $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|",$match); if (count($matchtkns)==3 && !in_array($matchtkns,$arr)){ $arr[] = $matchtkns; @@ -41,23 +41,26 @@ function string_plural_select($n){ '; - foreach($arr as $a) { + foreach ($arr as $a) { if (is_array($a)){ - if(substr($a[1],0,1) == '$') + if (substr($a[1],0,1) == '$') { continue; + } $s .= '$a->strings[' . $a[0] . "] = array(\n"; $s .= "\t0 => ". $a[0]. ",\n"; $s .= "\t1 => ". $a[1]. ",\n"; $s .= ");\n"; } else { - if(substr($a,0,1) == '$') - continue; + if (substr($a,0,1) == '$') { + continue; + } $s .= '$a->strings[' . $a . '] = '. $a . ';' . "\n"; } } $zones = timezone_identifiers_list(); - foreach($zones as $zone) + foreach ($zones as $zone) { $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; - + } + echo $s; \ No newline at end of file diff --git a/util/maintenance.php b/util/maintenance.php index 28f3a503a..17f64ecc7 100644 --- a/util/maintenance.php +++ b/util/maintenance.php @@ -17,14 +17,16 @@ unset($db_host, $db_user, $db_pass, $db_data); Config::load(); $maint_mode = 1; -if($argc > 1) +if ($argc > 1) { $maint_mode = intval($argv[1]); +} set_config('system', 'maintenance', $maint_mode); -if($maint_mode) +if ($maint_mode) { $mode_str = "maintenance mode"; -else +} else { $mode_str = "normal mode"; +} echo "\n\tSystem set in $mode_str\n\n"; echo "Usage:\n\n"; diff --git a/util/php2po.php b/util/php2po.php index 2e888008c..8bc4ce8c6 100644 --- a/util/php2po.php +++ b/util/php2po.php @@ -10,7 +10,7 @@ DEFINE("NORM_REGEXP", "|[\\\]|"); - if(! class_exists('App')) { + if (! class_exists('App')) { class TmpA { public $strings = Array(); } @@ -68,7 +68,7 @@ } $infile = file($phpfile); - foreach($infile as $l) { + foreach ($infile as $l) { $l = trim($l); if (startsWith($l, 'function string_plural_select_')) { $lang = str_replace( 'function string_plural_select_' , '', str_replace( '($n){','', $l) ); @@ -94,7 +94,7 @@ $norm_base_msgids = array(); $base_f = file("util/messages.po") or die("No base messages.po\n"); $_f = 0; $_mid = ""; $_mids = array(); - foreach( $base_f as $l) { + foreach ( $base_f as $l) { $l = trim($l); //~ print $l."\n"; @@ -165,7 +165,7 @@ } $warnings = ""; - foreach($a->strings as $key=>$str) { + foreach ($a->strings as $key=>$str) { $msgid = massage_string($key); if (preg_match("|%[sd0-9](\$[sn])*|", $msgid)) { diff --git a/util/po2php.php b/util/po2php.php index 60736bf4a..86c41236e 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -42,34 +42,45 @@ function po2php_run(&$argv, &$argc) { foreach ($infile as $l) { $l = str_replace('\"', DQ_ESCAPE, $l); $len = strlen($l); - if ($l[0]=="#") $l=""; - if (substr($l,0,15)=='"Plural-Forms: '){ + if ($l[0]=="#") { + $l=""; + } + if (substr($l,0,15) == '"Plural-Forms: '){ $match=Array(); preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match); $cond = str_replace('n','$n',$match[2]); // define plural select function if not already defined $fnname = 'string_plural_select_' . $lang; - $out .= 'if(! function_exists("'.$fnname.'")) {'."\n"; + $out .= 'if (! function_exists("'.$fnname.'")) {'."\n"; $out .= 'function '. $fnname . '($n){'."\n"; $out .= ' return '.$cond.';'."\n"; $out .= '}}'."\n"; } - - - - if ($k!="" && substr($l,0,7)=="msgstr "){ - if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } + if ($k!="" && substr($l,0,7) == "msgstr "){ + if ($ink) { + $ink = False; + $out .= '$a->strings["'.$k.'"] = '; + } + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } $v = substr($l,8,$len-10); $v = preg_replace_callback($escape_s_exp,'escape_s',$v); $inv = True; //$out .= $v; } - if ($k!="" && substr($l,0,7)=="msgstr["){ - if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } + if ($k!="" && substr($l,0,7) == "msgstr["){ + if ($ink) { + $ink = False; + $out .= '$a->strings["'.$k.'"] = '; + } + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } if (!$arr) { $arr=True; @@ -85,7 +96,6 @@ function po2php_run(&$argv, &$argc) { if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }; - if ($ink) { $k .= trim($l,"\"\r\n"); $k = preg_replace_callback($escape_s_exp,'escape_s',$k); @@ -93,9 +103,14 @@ function po2php_run(&$argv, &$argc) { } if (substr($l,0,6)=="msgid "){ - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } - if ($k!="") $out .= $arr?");\n":";\n"; - $arr=False; + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } + if ($k != "") { + $out .= $arr?");\n":";\n"; + } + $arr = False; $k = str_replace("msgid ","",$l); if ($k != '""' ) { $k = trim($k,"\"\r\n"); @@ -116,8 +131,13 @@ function po2php_run(&$argv, &$argc) { } - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } - if ($k!="") $out .= $arr?");\n":";\n"; + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } + if ($k!="") { + $out .= $arr?");\n":";\n"; + } $out = str_replace(DQ_ESCAPE, '\"', $out); file_put_contents($outfile, $out); diff --git a/util/typo.php b/util/typo.php index d68ac2ac9..c45be483c 100644 --- a/util/typo.php +++ b/util/typo.php @@ -1,59 +1,58 @@ config,'php_path')) - $phpath = $a->config['php_path']; - else - $phpath = 'php'; +if (x($a->config,'php_path')) { + $phpath = $a->config['php_path']; +} else { + $phpath = 'php'; +} +echo "Directory: mod\n"; +$files = glob('mod/*.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} - echo "Directory: mod\n"; - $files = glob('mod/*.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); +echo "Directory: include\n"; +$files = glob('include/*.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} + +echo "Directory: object\n"; +$files = glob('object/*.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} + +echo "Directory: addon\n"; +$dirs = glob('addon/*'); + +foreach ($dirs as $dir) { + $addon = basename($dir); + $files = glob($dir . '/' . $addon . '.php'); + foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); } +} - echo "Directory: include\n"; - $files = glob('include/*.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } +echo "String files\n"; - echo "Directory: object\n"; - $files = glob('object/*.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } +echo 'util/strings.php' . "\n"; +passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); - echo "Directory: addon\n"; - $dirs = glob('addon/*'); - - foreach($dirs as $dir) { - $addon = basename($dir); - $files = glob($dir . '/' . $addon . '.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } - } - - - echo "String files\n"; - - echo 'util/strings.php' . "\n"; - passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); - - $files = glob('view/lang/*/strings.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } +$files = glob('view/lang/*/strings.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} From 0cd241bcbe762e38e2eba0c58800eb60a2240e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 15:23:30 +0100 Subject: [PATCH 21/55] added spaces + some curly braces + some usage of dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/_well_known.php | 2 +- mod/acctlink.php | 4 +- mod/admin.php | 9 ++- mod/allfriends.php | 3 +- mod/api.php | 2 +- mod/apps.php | 22 +++--- mod/attach.php | 4 +- mod/babel.php | 4 +- mod/cal.php | 59 +++++++------- mod/common.php | 11 +-- mod/community.php | 13 ++-- mod/contactgroup.php | 19 ++--- mod/contacts.php | 60 +++++++------- mod/content.php | 155 ++++++++++++++++++------------------ mod/crepair.php | 4 +- mod/delegate.php | 41 ++++++---- mod/dfrn_confirm.php | 94 +++++++++++----------- mod/dfrn_notify.php | 38 +++++---- mod/dfrn_poll.php | 76 +++++++++--------- mod/dfrn_request.php | 60 +++++++------- mod/directory.php | 35 +++++---- mod/dirfind.php | 3 +- mod/editpost.php | 8 +- mod/events.php | 62 ++++++++------- mod/fbrowser.php | 5 +- mod/filer.php | 2 +- mod/friendica.php | 26 ++++--- mod/fsuggest.php | 5 +- mod/group.php | 48 ++++++------ mod/help.php | 21 +++-- mod/home.php | 4 +- mod/hostxrd.php | 2 +- mod/hovercard.php | 14 ++-- mod/ignored.php | 7 +- mod/install.php | 20 ++--- mod/invite.php | 2 +- mod/item.php | 177 +++++++++++++++++++++++------------------- mod/like.php | 18 +++-- mod/localtime.php | 15 ++-- mod/lockview.php | 38 +++++---- mod/login.php | 9 ++- mod/lostpass.php | 7 +- mod/manage.php | 32 ++++---- mod/match.php | 14 ++-- mod/message.php | 97 ++++++++++++----------- mod/modexp.php | 2 +- mod/mood.php | 14 ++-- mod/msearch.php | 4 +- mod/network.php | 124 +++++++++++++++-------------- mod/newmember.php | 5 +- mod/nodeinfo.php | 6 +- mod/noscrape.php | 7 +- mod/notes.php | 5 +- mod/notifications.php | 27 +++---- mod/openid.php | 12 +-- mod/parse_url.php | 4 +- mod/photo.php | 25 +++--- mod/photos.php | 5 +- mod/ping.php | 4 +- mod/poco.php | 35 +++++---- mod/poke.php | 12 +-- mod/post.php | 9 ++- mod/pretheme.php | 7 +- mod/probe.php | 2 +- mod/profile.php | 28 +++---- mod/profile_photo.php | 24 +++--- mod/profiles.php | 103 ++++++++++++------------ mod/profperm.php | 30 +++---- mod/pubsub.php | 15 ++-- mod/pubsubhubbub.php | 4 +- mod/qsearch.php | 14 ++-- mod/receive.php | 12 +-- mod/redir.php | 12 +-- mod/register.php | 42 +++++----- mod/regmod.php | 5 +- mod/salmon.php | 28 +++---- mod/search.php | 32 ++++---- mod/settings.php | 40 +++++----- mod/share.php | 4 +- mod/smilies.php | 5 +- mod/subthread.php | 8 +- mod/tagger.php | 30 +++---- mod/uexport.php | 12 +-- mod/videos.php | 65 ++++++++-------- mod/view.php | 3 +- mod/viewcontacts.php | 13 ++-- mod/viewsrc.php | 4 +- mod/wall_attach.php | 24 +++--- mod/wall_upload.php | 32 ++++---- mod/wallmessage.php | 21 ++--- mod/webfinger.php | 2 +- mod/xrd.php | 5 +- 92 files changed, 1190 insertions(+), 1087 deletions(-) diff --git a/mod/_well_known.php b/mod/_well_known.php index 622d7fd93..9c862af71 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -54,7 +54,7 @@ function wk_social_relay(App $a) { } $taglist = array(); - foreach($tags AS $tag) { + foreach ($tags AS $tag) { $taglist[] = $tag; } diff --git a/mod/acctlink.php b/mod/acctlink.php index 892b59655..715f251fa 100644 --- a/mod/acctlink.php +++ b/mod/acctlink.php @@ -4,11 +4,11 @@ require_once('include/Scrape.php'); function acctlink_init(App $a) { - if(x($_GET,'addr')) { + if (x($_GET,'addr')) { $addr = trim($_GET['addr']); $res = probe_url($addr); //logger('acctlink: ' . print_r($res,true)); - if($res['url']) { + if ($res['url']) { goaway($res['url']); killme(); } diff --git a/mod/admin.php b/mod/admin.php index b1bc8de5f..8227252c6 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -861,6 +861,7 @@ function admin_page_site(App $a) { foreach ($files as $file) { if (intval(file_exists($file.'/unsupported'))) continue; + } $f = basename($file); @@ -1274,7 +1275,7 @@ function admin_page_users(App $a) { if ($a->argc>2) { $uid = $a->argv[3]; $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid)); - if (count($user) == 0) { + if (!dbm::is_result($user)) { notice('User not found'.EOL); goaway('admin/users'); return ''; // NOTREACHED @@ -1609,7 +1610,7 @@ function admin_page_plugins(App $a) { * @param int $result */ function toggle_theme(&$themes,$th,&$result) { - for($x = 0; $x < count($themes); $x ++) { + for ($x = 0; $x < count($themes); $x ++) { if ($themes[$x]['name'] === $th) { if ($themes[$x]['allowed']) { $themes[$x]['allowed'] = 0; @@ -1629,7 +1630,7 @@ function toggle_theme(&$themes,$th,&$result) { * @return int */ function theme_status($themes,$th) { - for($x = 0; $x < count($themes); $x ++) { + for ($x = 0; $x < count($themes); $x ++) { if ($themes[$x]['name'] === $th) { if ($themes[$x]['allowed']) { return 1; @@ -1761,7 +1762,7 @@ function admin_page_themes(App $a) { $status="off"; $action= t("Enable"); } - $readme = Null; + $readme = null; if (is_file("view/theme/$theme/README.md")) { $readme = file_get_contents("view/theme/$theme/README.md"); $readme = Markdown($readme); diff --git a/mod/allfriends.php b/mod/allfriends.php index f51070bbe..893cf6a5f 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -37,8 +37,9 @@ function allfriends_content(App $a) { $total = count_all_friends(local_user(), $cid); - if(count($total)) + if (count($total)) { $a->set_pager_total($total); + } $r = all_friends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']); diff --git a/mod/api.php b/mod/api.php index 3916636cf..e44fcc493 100644 --- a/mod/api.php +++ b/mod/api.php @@ -27,7 +27,7 @@ function api_post(App $a) { return; } - if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) { + if (count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/apps.php b/mod/apps.php index 199ce0f91..fea548367 100644 --- a/mod/apps.php +++ b/mod/apps.php @@ -1,25 +1,23 @@ apps)==0) + if (count($a->apps) == 0) { notice( t('No installed applications.') . EOL); - + } $tpl = get_markup_template("apps.tpl"); return replace_macros($tpl, array( '$title' => $title, '$apps' => $a->apps, )); - - - } diff --git a/mod/attach.php b/mod/attach.php index dd7154dfe..80a2222bc 100644 --- a/mod/attach.php +++ b/mod/attach.php @@ -4,7 +4,7 @@ require_once('include/security.php'); function attach_init(App $a) { - if($a->argc != 2) { + if ($a->argc != 2) { notice( t('Item not available.') . EOL); return; } @@ -38,7 +38,7 @@ function attach_init(App $a) { // error in Chrome for filenames with commas in them header('Content-type: ' . $r[0]['filetype']); header('Content-length: ' . $r[0]['filesize']); - if(isset($_GET['attachment']) && $_GET['attachment'] === '0') + if (isset($_GET['attachment']) && $_GET['attachment'] === '0') header('Content-disposition: filename="' . $r[0]['filename'] . '"'); else header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"'); diff --git a/mod/babel.php b/mod/babel.php index e8ea11c94..f65920d78 100644 --- a/mod/babel.php +++ b/mod/babel.php @@ -25,7 +25,7 @@ function babel_content(App $a) { $o .= '

'; - if(x($_REQUEST,'text')) { + if (x($_REQUEST,'text')) { $text = trim($_REQUEST['text']); $o .= "

" . t("Source input: ") . "

" . EOL. EOL; @@ -63,7 +63,7 @@ function babel_content(App $a) { } - if(x($_REQUEST,'d2bbtext')) { + if (x($_REQUEST,'d2bbtext')) { $d2bbtext = trim($_REQUEST['d2bbtext']); $o .= "

" . t("Source input (Diaspora format): ") . "

" . EOL. EOL; diff --git a/mod/cal.php b/mod/cal.php index f43a4e8a7..97a6a9d8b 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -10,10 +10,10 @@ require_once('include/event.php'); require_once('include/redir.php'); function cal_init(App $a) { - if($a->argc > 1) + if ($a->argc > 1) auto_redir($a, $a->argv[1]); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } @@ -21,13 +21,13 @@ function cal_init(App $a) { $o = ''; - if($a->argc > 1) { + if ($a->argc > 1) { $nick = $a->argv[1]; $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); - if(! count($user)) + if (! count($user)) return; $a->data['user'] = $user[0]; @@ -54,7 +54,7 @@ function cal_init(App $a) { $cal_widget = widget_events(); - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) $a->page['aside'] = ''; $a->page['aside'] .= $vcard_widget; @@ -69,6 +69,7 @@ function cal_content(App $a) { // First day of the week (0 = Sunday) $firstDay = get_pconfig(local_user(),'system','first_day_of_week'); + /// @TODO Convert all these to with curly braces if ($firstDay === false) $firstDay=0; // get the translation strings for the callendar @@ -94,8 +95,9 @@ function cal_content(App $a) { $m = 0; $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0); - if($a->argc == 4) { - if($a->argv[2] == 'export') { + /// @TODO Convert to one if() statement + if ($a->argc == 4) { + if ($a->argv[2] == 'export') { $mode = 'export'; $format = $a->argv[3]; } @@ -112,15 +114,15 @@ function cal_content(App $a) { $owner_uid = $a->data['user']['uid']; $nick = $a->data['user']['nickname']; - 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), @@ -131,15 +133,15 @@ function cal_content(App $a) { $remote_contact = true; } } - if(! $remote_contact) { - if(local_user()) { + if (! $remote_contact) { + if (local_user()) { $contact_id = $_SESSION['cid']; $contact = $a->contact; } } $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; } @@ -153,33 +155,33 @@ function cal_content(App $a) { $tabs .= profile_tabs($a,false, $a->data['user']['nickname']); // The view mode part is similiar to /mod/events.php - if($mode == 'view') { + if ($mode == 'view') { $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); - if(! $y) + if (! $y) $y = intval($thisyear); - if(! $m) + if (! $m) $m = intval($thismonth); // Put some limits on dates. The PHP date functions don't seem to do so well before 1900. // An upper limit was chosen to keep search engines from exploring links millions of years in the future. - if($y < 1901) + if ($y < 1901) $y = 1900; - if($y > 2099) + if ($y > 2099) $y = 2100; $nextyear = $y; $nextmonth = $m + 1; - if($nextmonth > 12) { + if ($nextmonth > 12) { $nextmonth = 1; $nextyear ++; } $prevyear = $y; - if($m > 1) + if ($m > 1) $prevmonth = $m - 1; else { $prevmonth = 12; @@ -235,9 +237,10 @@ function cal_content(App $a) { $events=array(); // transform the event in a usable array - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $r = sort_by_date($r); $events = process_events($r); + } if ($a->argv[2] === 'json'){ echo json_encode($events); killme(); @@ -255,9 +258,9 @@ function cal_content(App $a) { } // Get rid of dashes in key names, Smarty3 can't handle them - foreach($events as $key => $event) { + foreach ($events as $key => $event) { $event_item = array(); - foreach($event['item'] as $k => $v) { + foreach ($event['item'] as $k => $v) { $k = str_replace('-','_',$k); $event_item[$k] = $v; } @@ -287,15 +290,15 @@ function cal_content(App $a) { return $o; } - if($mode == 'export') { - if(! (intval($owner_uid))) { + if ($mode == 'export') { + if (! (intval($owner_uid))) { notice( t('User not found')); return; } // Test permissions // Respect the export feature setting for all other /cal pages if it's not the own profile - if( ((local_user() !== intval($owner_uid))) && ! feature_enabled($owner_uid, "export_calendar")) { + if ( ((local_user() !== intval($owner_uid))) && ! feature_enabled($owner_uid, "export_calendar")) { notice( t('Permission denied.') . EOL); goaway('cal/' . $nick); } @@ -304,7 +307,7 @@ function cal_content(App $a) { $evexport = event_export($owner_uid, $format); if (!$evexport["success"]) { - if($evexport["content"]) + if ($evexport["content"]) notice( t('This calendar format is not supported') ); else notice( t('No exportable data found')); diff --git a/mod/common.php b/mod/common.php index 5a40663f9..d18389559 100644 --- a/mod/common.php +++ b/mod/common.php @@ -57,20 +57,21 @@ function common_content(App $a) { return; } - if(! $cid) { - if(get_my_url()) { + if (! $cid) { + if (get_my_url()) { $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", dbesc(normalise_link(get_my_url())), intval($profile_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $cid = $r[0]['id']; - else { + } else { $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link(get_my_url())) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $zcid = $r[0]['id']; + } } } } diff --git a/mod/community.php b/mod/community.php index 174330401..2f48c985c 100644 --- a/mod/community.php +++ b/mod/community.php @@ -18,12 +18,12 @@ function community_content(App $a, $update = 0) { if ($update) return; - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } - if(get_config('system','community_page_style') == CP_NO_COMMUNITY_PAGE) { + if (get_config('system','community_page_style') == CP_NO_COMMUNITY_PAGE) { notice( t('Not available.') . EOL); return; } @@ -34,11 +34,11 @@ function community_content(App $a, $update = 0) { $o .= '

' . t('Community') . '

'; - if(! $update) { + if (! $update) { nav_set_selected('community'); } - if(x($a->data,'search')) + if (x($a->data,'search')) $search = notags(trim($a->data['search'])); else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); @@ -79,14 +79,15 @@ function community_content(App $a, $update = 0) { $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']); } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0)); - } else + } else { $s = $r; + } // we behave the same in message lists as the search module $o .= conversation($a, $s, 'community', $update); - $o .= alt_pager($a, count($r)); + $o .= alt_pager($a, count($r)); return $o; } diff --git a/mod/contactgroup.php b/mod/contactgroup.php index 5c4cd7986..b2ddc8735 100644 --- a/mod/contactgroup.php +++ b/mod/contactgroup.php @@ -9,16 +9,17 @@ function contactgroup_content(App $a) { killme(); } - if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { + if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1", intval($a->argv[2]), intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $change = intval($a->argv[2]); + } } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", intval($a->argv[1]), @@ -31,16 +32,16 @@ function contactgroup_content(App $a) { $group = $r[0]; $members = group_get_members($group['id']); $preselected = array(); - if(count($members)) { - foreach($members as $member) + if (count($members)) { + foreach ($members as $member) { $preselected[] = $member['id']; + } } - if($change) { - if(in_array($change,$preselected)) { + if ($change) { + if (in_array($change,$preselected)) { group_rmv_member(local_user(),$group['name'],$change); - } - else { + } else { group_add_member(local_user(),$group['name'],$change); } } diff --git a/mod/contacts.php b/mod/contacts.php index 70f4b7350..11a83f0a0 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -14,7 +14,7 @@ function contacts_init(App $a) { $contact_id = 0; - if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) { + if ((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) { $contact_id = intval($a->argv[1]); $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1", intval(local_user()), @@ -107,7 +107,7 @@ function contacts_batch_actions(App $a) { ); $count_actions=0; - foreach($orig_records as $orig_record) { + foreach ($orig_records as $orig_record) { $contact_id = $orig_record['id']; if (x($_POST, 'contacts_batch_update')) { _contact_update($contact_id); @@ -281,7 +281,7 @@ function _contact_update_profile($contact_id) { $update["subhub"] = true; } - foreach($updatefields AS $field) + foreach ($updatefields AS $field) if (isset($data[$field]) AND ($data[$field] != "")) $update[$field] = $data[$field]; @@ -292,7 +292,7 @@ function _contact_update_profile($contact_id) { if (isset($data["priority"]) AND ($data["priority"] != 0)) $query = "`priority` = ".intval($data["priority"]); - foreach($update AS $key => $value) { + foreach ($update AS $key => $value) { if ($query != "") $query .= ", "; @@ -365,10 +365,10 @@ function contacts_content(App $a) { return; } - if($a->argc == 3) { + if ($a->argc == 3) { $contact_id = intval($a->argv[1]); - if(! $contact_id) + if (! $contact_id) return; $cmd = $a->argv[2]; @@ -378,25 +378,25 @@ function contacts_content(App $a) { intval(local_user()) ); - if(! count($orig_record)) { + if (! count($orig_record)) { notice( t('Could not access contact record.') . EOL); goaway('contacts'); return; // NOTREACHED } - if($cmd === 'update') { + if ($cmd === 'update') { _contact_update($contact_id); goaway('contacts/' . $contact_id); // NOTREACHED } - if($cmd === 'updateprofile') { + if ($cmd === 'updateprofile') { _contact_update_profile($contact_id); goaway('crepair/' . $contact_id); // NOTREACHED } - if($cmd === 'block') { + if ($cmd === 'block') { $r = _contact_block($contact_id, $orig_record[0]); if ($r) { $blocked = (($orig_record[0]['blocked']) ? 0 : 1); @@ -407,7 +407,7 @@ function contacts_content(App $a) { return; // NOTREACHED } - if($cmd === 'ignore') { + if ($cmd === 'ignore') { $r = _contact_ignore($contact_id, $orig_record[0]); if ($r) { $readonly = (($orig_record[0]['readonly']) ? 0 : 1); @@ -419,7 +419,7 @@ function contacts_content(App $a) { } - if($cmd === 'archive') { + if ($cmd === 'archive') { $r = _contact_archive($contact_id, $orig_record[0]); if ($r) { $archived = (($orig_record[0]['archive']) ? 0 : 1); @@ -430,16 +430,16 @@ function contacts_content(App $a) { return; // NOTREACHED } - if($cmd === 'drop') { + if ($cmd === 'drop') { // Check if we should do HTML-based delete confirmation - if($_REQUEST['confirm']) { + if ($_REQUEST['confirm']) { //
can't take arguments in its "action" parameter // so add any arguments as hidden inputs $query = explode_querystring($a->query_string); $inputs = array(); - foreach($query['args'] as $arg) { - if(strpos($arg, 'confirm=') === false) { + foreach ($query['args'] as $arg) { + if (strpos($arg, 'confirm=') === false) { $arg_parts = explode('=', $arg); $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]); } @@ -488,7 +488,7 @@ function contacts_content(App $a) { $_SESSION['return_url'] = $a->query_string; - if((x($a->data,'contact')) && (is_array($a->data['contact']))) { + if ((x($a->data,'contact')) && (is_array($a->data['contact']))) { $contact_id = $a->data['contact']['id']; $contact = $a->data['contact']; @@ -522,12 +522,12 @@ function contacts_content(App $a) { break; } - if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) + if (!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) $relation_text = ""; $relation_text = sprintf($relation_text,htmlentities($contact['name'])); - if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) { + if (($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) { $url = "redir/{$contact['id']}"; $sparkle = ' class="sparkle" '; } @@ -542,7 +542,7 @@ function contacts_content(App $a) { ? t('Never') : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A')); - if($contact['last-update'] !== '0000-00-00 00:00:00') + if ($contact['last-update'] !== '0000-00-00 00:00:00') $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29")); $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : ''); @@ -665,23 +665,23 @@ function contacts_content(App $a) { $ignored = false; $all = false; - if(($a->argc == 2) && ($a->argv[1] === 'all')) { + if (($a->argc == 2) && ($a->argv[1] === 'all')) { $sql_extra = ''; $all = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) { $sql_extra = " AND `blocked` = 1 "; $blocked = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) { $sql_extra = " AND `hidden` = 1 "; $hidden = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) { $sql_extra = " AND `readonly` = 1 "; $ignored = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) { $sql_extra = " AND `archive` = 1 "; $archived = true; } @@ -761,14 +761,14 @@ function contacts_content(App $a) { $searching = false; - if($search) { + if ($search) { $search_hdr = $search; $search_txt = dbesc(protect_sprintf(preg_quote($search))); $searching = true; } $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : ""); - if($nets) + if ($nets) $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets)); $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); @@ -929,7 +929,7 @@ function _contact_detail_for_template($rr){ default: break; } - if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) { + if (($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) { $url = "redir/{$rr['id']}"; $sparkle = ' class="sparkle" '; } @@ -971,7 +971,7 @@ function contact_actions($contact) { $contact_action = array(); // Provide friend suggestion only for Friendica contacts - if($contact['network'] === NETWORK_DFRN) { + if ($contact['network'] === NETWORK_DFRN) { $contact_actions['suggest'] = array( 'label' => t('Suggest friends'), 'url' => 'fsuggest/' . $contact['id'], @@ -981,7 +981,7 @@ function contact_actions($contact) { ); } - if($poll_enabled) { + if ($poll_enabled) { $contact_actions['update'] = array( 'label' => t('Update now'), 'url' => 'contacts/' . $contact['id'] . '/update', diff --git a/mod/content.php b/mod/content.php index 43f3fc2ba..e7e8ca65e 100644 --- a/mod/content.php +++ b/mod/content.php @@ -38,20 +38,18 @@ function content_content(App $a, $update = 0) { $nouveau = false; - if($a->argc > 1) { - for($x = 1; $x < $a->argc; $x ++) { - if(is_a_date_arg($a->argv[$x])) { - if($datequery) + if ($a->argc > 1) { + for ($x = 1; $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]); $_GET['order'] = 'post'; } - } - elseif($a->argv[$x] === 'new') { + } elseif ($a->argv[$x] === 'new') { $nouveau = true; - } - elseif(intval($a->argv[$x])) { + } elseif (intval($a->argv[$x])) { $group = intval($a->argv[$x]); $def_acl = array('allow_gid' => '<' . $group . '>'); } @@ -81,12 +79,12 @@ function content_content(App $a, $update = 0) { - if(x($_GET,'search') || x($_GET,'file')) + if (x($_GET,'search') || x($_GET,'file')) $nouveau = true; - if($cid) + if ($cid) $def_acl = array('allow_cid' => '<' . intval($cid) . '>'); - if($nets) { + if ($nets) { $r = q("select id from contact where uid = %d and network = '%s' and self = 0", intval(local_user()), dbesc($nets) @@ -94,9 +92,9 @@ function content_content(App $a, $update = 0) { $str = ''; if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $str .= '<' . $rr['id'] . '>'; - if(strlen($str)) + if (strlen($str)) $def_acl = array('allow_cid' => $str); } @@ -108,13 +106,13 @@ function content_content(App $a, $update = 0) { $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) "; - if($group) { + if ($group) { $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($group), intval($_SESSION['uid']) ); if (! dbm::is_result($r)) { - if($update) + if ($update) killme(); notice( t('No such group') . EOL ); goaway(App::get_baseurl(true) . '/network'); @@ -122,7 +120,7 @@ function content_content(App $a, $update = 0) { } $contacts = expand_groups(array($group)); - if((is_array($contacts)) && count($contacts)) { + if ((is_array($contacts)) && count($contacts)) { $contact_str = implode(',',$contacts); } else { @@ -135,7 +133,7 @@ function content_content(App $a, $update = 0) { '$title' => sprintf( t('Group: %s'), $r[0]['name']) )) . $o; } - elseif($cid) { + elseif ($cid) { $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d AND `blocked` = 0 AND `pending` = 0 LIMIT 1", @@ -153,10 +151,10 @@ function content_content(App $a, $update = 0) { $sql_extra3 = ''; - if($datequery) { + if ($datequery) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); } - if($datequery2) { + if ($datequery2) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } @@ -164,10 +162,10 @@ function content_content(App $a, $update = 0) { $sql_extra3 = (($nouveau) ? '' : $sql_extra3); $sql_table = "`item`"; - if(x($_GET,'search')) { + if (x($_GET,'search')) { $search = escape_tags($_GET['search']); - if(strpos($search,'#') === 0) { + if (strpos($search,'#') === 0) { $tag = true; $search = substr($search,1); } @@ -175,7 +173,7 @@ function content_content(App $a, $update = 0) { if (get_config('system','only_tag_search')) $tag = true; - if($tag) { + if ($tag) { //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; @@ -192,11 +190,11 @@ function content_content(App $a, $update = 0) { } } - if(strlen($file)) { + if (strlen($file)) { $sql_extra .= file_tag_file_query('item',unxmlify($file)); } - if($conv) { + if ($conv) { $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname']; $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace('www.','',$myurl); @@ -211,7 +209,7 @@ function content_content(App $a, $update = 0) { $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - if($nouveau) { + if ($nouveau) { // "New Item View" - show all items unthreaded in reverse created date order $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, @@ -234,7 +232,7 @@ function content_content(App $a, $update = 0) { // Normal conversation view - if($order === 'post') + if ($order === 'post') $ordering = "`created`"; else $ordering = "`commented`"; @@ -260,8 +258,8 @@ function content_content(App $a, $update = 0) { $parents_str = ''; if (dbm::is_result($r)) { - foreach($r as $rr) - if(! in_array($rr['item_id'],$parents_arr)) + foreach ($r as $rr) + if (! in_array($rr['item_id'],$parents_arr)) $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); @@ -328,32 +326,32 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { ); } - if($mode === 'network') { + if ($mode === 'network') { $profile_owner = local_user(); $page_writeable = true; } - if($mode === 'profile') { + if ($mode === 'profile') { $profile_owner = $a->profile['profile_uid']; $page_writeable = can_write_wall($a,$profile_owner); } - if($mode === 'notes') { + if ($mode === 'notes') { $profile_owner = local_user(); $page_writeable = true; } - if($mode === 'display') { + if ($mode === 'display') { $profile_owner = $a->profile['uid']; $page_writeable = can_write_wall($a,$profile_owner); } - if($mode === 'community') { + if ($mode === 'community') { $profile_owner = 0; $page_writeable = false; } - if($update) + if ($update) $return_url = $_SESSION['return_url']; else $return_url = $_SESSION['return_url'] = $a->query_string; @@ -378,9 +376,9 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $threads = array(); $threadsid = -1; - if($items && count($items)) { + if ($items && count($items)) { - if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -388,7 +386,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { //$tpl = get_markup_template('search_item.tpl'); $tpl = 'search_item.tpl'; - foreach($items as $item) { + foreach ($items as $item) { $threadsid++; $comment = ''; @@ -397,8 +395,8 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $owner_name = ''; $sparkle = ''; - if($mode === 'search' || $mode === 'community') { - if(((activity_match($item['verb'],ACTIVITY_LIKE)) + if ($mode === 'search' || $mode === 'community') { + if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)) || activity_match($item['verb'],ACTIVITY_ATTEND) || activity_match($item['verb'],ACTIVITY_ATTENDNO) @@ -411,20 +409,20 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $nickname = $a->user['nickname']; // prevent private email from leaking. - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) + if ($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; $sp = false; $profile_link = best_link_url($item,$sp); - if($profile_link === 'mailbox') + if ($profile_link === 'mailbox') $profile_link = ''; - if($sp) + if ($sp) $sparkle = ' sparkle'; else $profile_link = zrl($profile_link); @@ -442,7 +440,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); localize_item($item); - if($mode === 'network-new') + if ($mode === 'network-new') $dropping = true; else $dropping = false; @@ -463,7 +461,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $body = prepare_body($item,true); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $name_e = template_escape($profile_name); $title_e = template_escape($item['title']); $body_e = template_escape($body); @@ -534,20 +532,20 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // Store the result in the $comments array $comments = array(); - foreach($items as $item) { - if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) { - if(! x($comments,$item['parent'])) + foreach ($items as $item) { + if ((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) { + if (! x($comments,$item['parent'])) $comments[$item['parent']] = 1; else $comments[$item['parent']] += 1; - } elseif(! x($comments,$item['parent'])) + } elseif (! x($comments,$item['parent'])) $comments[$item['parent']] = 0; // avoid notices later on } // map all the like/dislike/attendance activities for each parent item // Store these in the $alike and $dlike arrays - foreach($items as $item) { + foreach ($items as $item) { builtin_activity_puller($item, $conv_responses); } @@ -559,7 +557,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $blowhard_count = 0; - foreach($items as $item) { + foreach ($items as $item) { $comment = ''; $template = $tpl; @@ -569,7 +567,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // We've already parsed out like/dislike for special treatment. We can ignore them now - if(((activity_match($item['verb'],ACTIVITY_LIKE)) + if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE) || activity_match($item['verb'],ACTIVITY_ATTEND) || activity_match($item['verb'],ACTIVITY_ATTENDNO) @@ -585,7 +583,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // If a single author has more than 3 consecutive top-level posts, squash the remaining ones. // If there are more than two comments, squash all but the last 2. - if($toplevelpost) { + if ($toplevelpost) { $item_writeable = (($item['writable'] || $item['self']) ? true : false); @@ -603,7 +601,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { else { // prevent private email reply to public conversation from leaking. - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; $comments_seen ++; @@ -615,7 +613,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false); - if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) { + if (($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) { if (!$comments_collapsed){ $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] ); @@ -626,7 +624,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $comment_firstcollapsed = true; } } - if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) { + if (($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) { $comment_lastcollapsed = true; } @@ -644,9 +642,9 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $osparkle = ''; - if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) { + if (($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) { - if($item['wall']) { + if ($item['wall']) { // On the network page, I am the owner. On the display page it will be the profile owner. // This will have been stored in $a->page_contact by our calling page. @@ -659,12 +657,12 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $commentww = 'ww'; } - if((! $item['wall']) && $item['owner-link']) { + if ((! $item['wall']) && $item['owner-link']) { $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); - if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { + if ((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { // The author url doesn't match the owner (typically the contact) // and also doesn't match the contact alias. @@ -682,7 +680,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $template = $wallwall; $commentww = 'ww'; // If it is our contact, use a friendly redirect link - if((link_compare($item['owner-link'],$item['url'])) + if ((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === NETWORK_DFRN)) { $owner_url = $redirect_url; $osparkle = ' sparkle'; @@ -696,8 +694,8 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $likebuttons = ''; $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); - if($page_writeable) { -/* if($toplevelpost) { */ + if ($page_writeable) { +/* if ($toplevelpost) { */ $likebuttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), @@ -707,12 +705,12 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $qc = $qcomment = null; - if(in_array('qcomment',$a->plugins)) { + if (in_array('qcomment',$a->plugins)) { $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); $qcomment = (($qc) ? explode("\n",$qc) : null); } - if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) { + if (($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) { $comment = replace_macros($cmnt_tpl,array( '$return_path' => '', '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''), @@ -751,7 +749,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $drop = ''; $dropping = false; - if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user())) + if ((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user())) $dropping = true; $drop = array( @@ -815,7 +813,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) + if ($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; $sp = false; @@ -842,13 +840,14 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // process action responses - e.g. like/dislike/attend/agree/whatever $response_verbs = array('like'); - if(feature_enabled($profile_owner,'dislike')) + if (feature_enabled($profile_owner,'dislike')) { $response_verbs[] = 'dislike'; - if($item['object-type'] === ACTIVITY_OBJ_EVENT) { + } + if ($item['object-type'] === ACTIVITY_OBJ_EVENT) { $response_verbs[] = 'attendyes'; $response_verbs[] = 'attendno'; $response_verbs[] = 'attendmaybe'; - if($page_writeable) { + if ($page_writeable) { $isevent = true; $attend = array( t('I will attend'), t('I will not attend'), t('I might attend')); } @@ -863,17 +862,20 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $indent = (($toplevelpost) ? '' : ' comment'); $shiny = ""; - if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) + if (strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) { $shiny = 'shiny'; + } // localize_item($item); $tags=array(); - foreach(explode(',',$item['tag']) as $tag){ + foreach (explode(',',$item['tag']) as $tag){ $tag = trim($tag); - if ($tag!="") $tags[] = bbcode($tag); + if ($tag!="") { + $tags[] = bbcode($tag); + } } // Build the HTML @@ -881,15 +883,14 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $body = prepare_body($item,true); //$tmp_item = replace_macros($template, - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $body_e = template_escape($body); $text_e = strip_tags(template_escape($body)); $name_e = template_escape($profile_name); $title_e = template_escape($item['title']); $location_e = template_escape($location); $owner_name_e = template_escape($owner_name); - } - else { + } else { $body_e = $body; $text_e = strip_tags($body); $name_e = $profile_name; diff --git a/mod/crepair.php b/mod/crepair.php index ef7908661..c5b4983d5 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -9,7 +9,7 @@ function crepair_init(App $a) { $contact_id = 0; - if(($a->argc == 2) && intval($a->argv[1])) { + if (($a->argc == 2) && intval($a->argv[1])) { $contact_id = intval($a->argv[1]); $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1", intval(local_user()), @@ -109,7 +109,7 @@ function crepair_content(App $a) { $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if($cid) { + if ($cid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($cid), intval(local_user()) diff --git a/mod/delegate.php b/mod/delegate.php index 4212ec9b1..f8a0dcb59 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -23,16 +23,16 @@ function delegate_content(App $a) { $id = $a->argv[2]; - $r = q("select `nickname` from user where uid = %d limit 1", + $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1", intval($id) ); if (dbm::is_result($r)) { - $r = q("select id from contact where uid = %d and nurl = '%s' limit 1", + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", intval(local_user()), dbesc(normalise_link(App::get_baseurl() . '/profile/' . $r[0]['nickname'])) ); if (dbm::is_result($r)) { - q("insert into manage ( uid, mid ) values ( %d , %d ) ", + q("INSERT INTO `manage` ( `uid`, `mid` ) VALUES ( %d , %d ) ", intval($a->argv[2]), intval(local_user()) ); @@ -64,34 +64,40 @@ function delegate_content(App $a) { dbesc($a->user['email']), dbesc($a->user['password']) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $full_managers = $r; + } $delegates = array(); // find everybody that currently has delegated management to this account/page - $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ", + $r = q("SELECT * FROM `user` WHERE `uid` IN ( SELECT `uid` FROM `manage` WHERE `mid` = %d ) ", intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $delegates = $r; + } $uids = array(); - if(count($full_managers)) - foreach($full_managers as $rr) + if (count($full_managers)) { + foreach ($full_managers as $rr) { $uids[] = $rr['uid']; + } + } - if(count($delegates)) - foreach($delegates as $rr) + if (count($delegates)) { + foreach ($delegates as $rr) { $uids[] = $rr['uid']; + } + } // find every contact who might be a candidate for delegation - $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s' - and contact.uid = %d and contact.self = 0 and network = '%s' ", + $r = q("SELECT `nurl` FROM `contact` WHERE SUBSTRING_INDEX(`contact`.`nurl`,'/',3) = '%s' + AND `contact`.`uid` = %d AND `contact`.`self` = 0 AND `network` = '%s' ", dbesc(normalise_link(App::get_baseurl())), intval(local_user()), dbesc(NETWORK_DFRN) @@ -116,12 +122,15 @@ function delegate_content(App $a) { // get user records for all potential page delegates who are not already delegates or managers - $r = q("select `uid`, `username`, `nickname` from user where nickname in ( $nicks )"); + $r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `nickname` IN ( $nicks )"); - if (dbm::is_result($r)) - foreach($r as $rr) - if(! in_array($rr['uid'],$uids)) + if (dbm::is_result($r)) { + foreach ($r as $rr) { + if (! in_array($rr['uid'],$uids)) { $potentials[] = $rr; + } + } + } require_once("mod/settings.php"); settings_init($a); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 7e14610e3..9dd38df34 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -24,7 +24,7 @@ require_once('include/Probe.php'); function dfrn_confirm_post(App $a, $handsfree = null) { - if(is_array($handsfree)) { + if (is_array($handsfree)) { /* * We were called directly from dfrn_request due to automatic friend acceptance. @@ -37,7 +37,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { } else { - if($a->argc > 1) + if ($a->argc > 1) $node = $a->argv[1]; } @@ -53,11 +53,11 @@ function dfrn_confirm_post(App $a, $handsfree = null) { * */ - if(! x($_POST,'source_url')) { + if (! x($_POST,'source_url')) { $uid = ((is_array($handsfree)) ? $handsfree['uid'] : local_user()); - if(! $uid) { + if (! $uid) { notice( t('Permission denied.') . EOL ); return; } @@ -66,7 +66,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { intval($uid) ); - if(! $user) { + if (! $user) { notice( t('Profile not found.') . EOL ); return; } @@ -74,7 +74,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { // These data elements may come from either the friend request notification form or $handsfree array. - if(is_array($handsfree)) { + if (is_array($handsfree)) { logger('Confirm in handsfree mode'); $dfrn_id = $handsfree['dfrn_id']; $intro_id = $handsfree['intro_id']; @@ -99,11 +99,11 @@ function dfrn_confirm_post(App $a, $handsfree = null) { * */ - if(strlen($dfrn_id)) + if (strlen($dfrn_id)) $cid = 0; logger('Confirming request for dfrn_id (issued) ' . $dfrn_id); - if($cid) + if ($cid) logger('Confirming follower with contact_id: ' . $cid); @@ -138,10 +138,10 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $network = ((strlen($contact['issued-id'])) ? NETWORK_DFRN : NETWORK_OSTATUS); - if($contact['network']) + if ($contact['network']) $network = $contact['network']; - if($network === NETWORK_DFRN) { + if ($network === NETWORK_DFRN) { /* * @@ -199,19 +199,19 @@ function dfrn_confirm_post(App $a, $handsfree = null) { openssl_public_encrypt($my_url, $params['source_url'], $site_pubkey); $params['source_url'] = bin2hex($params['source_url']); - if($aes_allow && function_exists('openssl_encrypt')) { + if ($aes_allow && function_exists('openssl_encrypt')) { openssl_public_encrypt($src_aes_key, $params['aes_key'], $site_pubkey); $params['aes_key'] = bin2hex($params['aes_key']); $params['public_key'] = bin2hex(openssl_encrypt($public_key,'AES-256-CBC',$src_aes_key)); } $params['dfrn_version'] = DFRN_PROTOCOL_VERSION ; - if($duplex == 1) + if ($duplex == 1) $params['duplex'] = 1; - if($user[0]['page-flags'] == PAGE_COMMUNITY) + if ($user[0]['page-flags'] == PAGE_COMMUNITY) $params['page'] = 1; - if($user[0]['page-flags'] == PAGE_PRVGROUP) + if ($user[0]['page-flags'] == PAGE_PRVGROUP) $params['page'] = 2; logger('Confirm: posting data to ' . $dfrn_confirm . ': ' . print_r($params,true), LOGGER_DATA); @@ -234,7 +234,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $leading_junk = substr($res,0,strpos($res,' NOTIFY_CONFIRM, @@ -743,12 +742,12 @@ function dfrn_confirm_post(App $a, $handsfree = null) { // Send a new friend post if we are allowed to... - if($page && intval(get_pconfig($local_uid,'system','post_joingroup'))) { + if ($page && intval(get_pconfig($local_uid,'system','post_joingroup'))) { $r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", intval($local_uid) ); - if((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0)) { + if ((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0)) { require_once('include/items.php'); @@ -756,7 +755,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { intval($local_uid) ); - if(count($self)) { + if (dbm::is_result($self)) { $arr = array(); $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $local_uid); @@ -793,8 +792,9 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $arr['deny_gid'] = $user[0]['deny_gid']; $i = item_store($arr); - if($i) + if ($i) { proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i); + } } } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index d34c959f1..63978386e 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -28,12 +28,12 @@ function dfrn_notify_post(App $a) { $prv = (($page == 2) ? 1 : 0); $writable = (-1); - if($dfrn_version >= 2.21) { + if ($dfrn_version >= 2.21) { $writable = (($perm === 'rw') ? 1 : 0); } $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -100,14 +100,14 @@ function dfrn_notify_post(App $a) { logger("Remote rino version: ".$rino_remote." for ".$importer["url"], LOGGER_DEBUG); - if((($writable != (-1)) && ($writable != $importer['writable'])) || ($importer['forum'] != $forum) || ($importer['prv'] != $prv)) { + if ((($writable != (-1)) && ($writable != $importer['writable'])) || ($importer['forum'] != $forum) || ($importer['prv'] != $prv)) { q("UPDATE `contact` SET `writable` = %d, forum = %d, prv = %d WHERE `id` = %d", intval(($writable == (-1)) ? $importer['writable'] : $writable), intval($forum), intval($prv), intval($importer['id']) ); - if($writable != (-1)) + if ($writable != (-1)) $importer['writable'] = $writable; $importer['forum'] = $page; } @@ -120,7 +120,7 @@ function dfrn_notify_post(App $a) { logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); logger('dfrn_notify: data: ' . $data, LOGGER_DATA); - if($dissolve == 1) { + if ($dissolve == 1) { /* * Relationship is dissolved permanently @@ -137,7 +137,7 @@ function dfrn_notify_post(App $a) { // If we are setup as a soapbox we aren't accepting input from this person // This behaviour is deactivated since it really doesn't make sense to even disallow comments // The check if someone is a friend or simply a follower is done in a later place so it needn't to be done here - //if($importer['page-flags'] == PAGE_SOAPBOX) + //if ($importer['page-flags'] == PAGE_SOAPBOX) // xml_status(0); $rino = get_config('system','rino_encrypt'); @@ -147,7 +147,7 @@ function dfrn_notify_post(App $a) { logger("Local rino version: ". $rino, LOGGER_DEBUG); - if(strlen($key)) { + if (strlen($key)) { // if local rino is lower than remote rino, abort: should not happen! // but only for $remote_rino > 1, because old code did't send rino version @@ -160,8 +160,8 @@ function dfrn_notify_post(App $a) { logger('rino: md5 raw key: ' . md5($rawkey)); $final_key = ''; - if($dfrn_version >= 2.1) { - if((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { + if ($dfrn_version >= 2.1) { + if ((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']); } else { @@ -169,7 +169,7 @@ function dfrn_notify_post(App $a) { } } else { - if((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { + if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']); } else { @@ -223,7 +223,7 @@ function dfrn_notify_post(App $a) { function dfrn_notify_content(App $a) { - if(x($_GET,'dfrn_id')) { + if (x($_GET,'dfrn_id')) { // initial communication from external contact, $direction is their direction. // If this is a duplex communication, ours will be the opposite. @@ -237,7 +237,7 @@ function dfrn_notify_content(App $a) { logger('dfrn_notify: new notification dfrn_id=' . $dfrn_id); $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -298,16 +298,15 @@ function dfrn_notify_content(App $a) { $pub_key = trim($r[0]['pubkey']); $dplx = intval($r[0]['duplex']); - if((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) { + if ((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) { openssl_private_encrypt($hash,$challenge,$prv_key); openssl_private_encrypt($id_str,$encrypted_id,$prv_key); - } - elseif(strlen($pub_key)) { + } elseif (strlen($pub_key)) { openssl_public_encrypt($hash,$challenge,$pub_key); openssl_public_encrypt($id_str,$encrypted_id,$pub_key); - } - else + } else { $status = 1; + } $challenge = bin2hex($challenge); $encrypted_id = bin2hex($encrypted_id); @@ -324,10 +323,9 @@ function dfrn_notify_content(App $a) { // if requested rino is higher than enabled local rino, reply with local rino if ($rino_remote < $rino) $rino = $rino_remote; - if((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { + if ((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { $perm = 'rw'; - } - else { + } else { $perm = 'r'; } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 506f9f162..13d443341 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -20,20 +20,20 @@ function dfrn_poll_init(App $a) { $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } $hidewall = false; - if(($dfrn_id === '') && (! x($_POST,'dfrn_id'))) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if (($dfrn_id === '') && (! x($_POST,'dfrn_id'))) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { http_status_exit(403); } $user = ''; - if($a->argc > 1) { + if ($a->argc > 1) { $r = q("SELECT `hidewall`,`nickname` FROM `user` WHERE `user`.`nickname` = '%s' LIMIT 1", dbesc($a->argv[1]) ); @@ -51,7 +51,7 @@ function dfrn_poll_init(App $a) { killme(); } - if(($type === 'profile') && (! strlen($sec))) { + if (($type === 'profile') && (! strlen($sec))) { $sql_extra = ''; switch($direction) { @@ -85,13 +85,13 @@ function dfrn_poll_init(App $a) { logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); - if(strlen($s)) { + if (strlen($s)) { $xml = parse_xml_string($s); - if((int) $xml->status == 1) { + if ((int) $xml->status == 1) { $_SESSION['authenticated'] = 1; - if(! x($_SESSION,'remote')) + if (! x($_SESSION,'remote')) $_SESSION['remote'] = array(); $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']); @@ -100,7 +100,7 @@ function dfrn_poll_init(App $a) { $_SESSION['visitor_home'] = $r[0]['url']; $_SESSION['visitor_handle'] = $r[0]['addr']; $_SESSION['visitor_visiting'] = $r[0]['uid']; - if(!$quiet) + if (!$quiet) info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL); // Visitors get 1 day session. $session_id = session_id(); @@ -118,9 +118,9 @@ function dfrn_poll_init(App $a) { } - if($type === 'profile-check' && $dfrn_version < 2.2 ) { + if ($type === 'profile-check' && $dfrn_version < 2.2 ) { - if((strlen($challenge)) && (strlen($sec))) { + if ((strlen($challenge)) && (strlen($sec))) { q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time())); $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1", @@ -131,7 +131,7 @@ function dfrn_poll_init(App $a) { // NOTREACHED } $orig_id = $r[0]['dfrn_id']; - if(strpos($orig_id, ':')) + if (strpos($orig_id, ':')) $orig_id = substr($orig_id,2); $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", @@ -147,7 +147,7 @@ function dfrn_poll_init(App $a) { $final_dfrn_id = ''; - if(($contact['duplex']) && strlen($contact['prvkey'])) { + if (($contact['duplex']) && strlen($contact['prvkey'])) { openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']); openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']); } @@ -158,10 +158,10 @@ function dfrn_poll_init(App $a) { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if(strpos($final_dfrn_id,':') == 1) + if (strpos($final_dfrn_id,':') == 1) $final_dfrn_id = substr($final_dfrn_id,2); - if($final_dfrn_id != $orig_id) { + if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site xml_status(3, 'Bad decryption'); @@ -213,9 +213,9 @@ function dfrn_poll_post(App $a) { $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version'] : 2.0); $perm = ((x($_POST,'perm')) ? $_POST['perm'] : 'r'); - if($ptype === 'profile-check') { + if ($ptype === 'profile-check') { - if((strlen($challenge)) && (strlen($sec))) { + if ((strlen($challenge)) && (strlen($sec))) { logger('dfrn_poll: POST: profile-check'); @@ -228,7 +228,7 @@ function dfrn_poll_post(App $a) { // NOTREACHED } $orig_id = $r[0]['dfrn_id']; - if(strpos($orig_id, ':')) + if (strpos($orig_id, ':')) $orig_id = substr($orig_id,2); $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", @@ -244,7 +244,7 @@ function dfrn_poll_post(App $a) { $final_dfrn_id = ''; - if(($contact['duplex']) && strlen($contact['prvkey'])) { + if (($contact['duplex']) && strlen($contact['prvkey'])) { openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']); openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']); } @@ -255,10 +255,10 @@ function dfrn_poll_post(App $a) { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if(strpos($final_dfrn_id,':') == 1) + if (strpos($final_dfrn_id,':') == 1) $final_dfrn_id = substr($final_dfrn_id,2); - if($final_dfrn_id != $orig_id) { + if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site xml_status(3, 'Bad decryption'); @@ -273,7 +273,7 @@ function dfrn_poll_post(App $a) { } $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -329,7 +329,7 @@ function dfrn_poll_post(App $a) { $contact_id = $r[0]['id']; - if($type === 'reputation' && strlen($url)) { + if ($type === 'reputation' && strlen($url)) { $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($url), intval($owner_uid) @@ -341,7 +341,7 @@ function dfrn_poll_post(App $a) { $reputation = $r[0]['rating']; $text = $r[0]['reason']; - if($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed + if ($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed $reputation = 0; $text = ''; } @@ -361,13 +361,13 @@ function dfrn_poll_post(App $a) { // Update the writable flag if it changed logger('dfrn_poll: post request feed: ' . print_r($_POST,true),LOGGER_DATA); - if($dfrn_version >= 2.21) { - if($perm === 'rw') + if ($dfrn_version >= 2.21) { + if ($perm === 'rw') $writable = 1; else $writable = 0; - if($writable != $contact['writable']) { + if ($writable != $contact['writable']) { q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d", intval($writable), intval($contact_id) @@ -395,13 +395,13 @@ function dfrn_poll_content(App $a) { $quiet = ((x($_GET,'quiet')) ? true : false); $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } - if($dfrn_id != '') { + if ($dfrn_id != '') { // initial communication from external contact $hash = random_string(); @@ -409,7 +409,7 @@ function dfrn_poll_content(App $a) { $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time())); - if($type !== 'profile') { + if ($type !== 'profile') { $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` ) VALUES( '%s', '%s', '%s', '%s', '%s' ) ", dbesc($hash), @@ -422,7 +422,7 @@ function dfrn_poll_content(App $a) { $sql_extra = ''; switch($direction) { case (-1): - if($type === 'profile') + if ($type === 'profile') $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id),dbesc($dfrn_id)); else $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id)); @@ -456,7 +456,7 @@ function dfrn_poll_content(App $a) { $encrypted_id = ''; $id_str = $my_id . '.' . mt_rand(1000,9999); - if(($r[0]['duplex'] && strlen($r[0]['pubkey'])) || (! strlen($r[0]['prvkey']))) { + if (($r[0]['duplex'] && strlen($r[0]['pubkey'])) || (! strlen($r[0]['prvkey']))) { openssl_public_encrypt($hash,$challenge,$r[0]['pubkey']); openssl_public_encrypt($id_str,$encrypted_id,$r[0]['pubkey']); } @@ -474,11 +474,11 @@ function dfrn_poll_content(App $a) { $encrypted_id = ''; } - if(($type === 'profile') && (strlen($sec))) { + if (($type === 'profile') && (strlen($sec))) { // URL reply - if($dfrn_version < 2.2) { + if ($dfrn_version < 2.2) { $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' @@ -517,7 +517,7 @@ function dfrn_poll_content(App $a) { logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA); - if(strlen($s) && strstr($s,'sec . ' expecting ' . $sec); - if(((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) { + if (((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) { $_SESSION['authenticated'] = 1; - if(! x($_SESSION,'remote')) + if (! x($_SESSION,'remote')) $_SESSION['remote'] = array(); $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']); $_SESSION['visitor_id'] = $r[0]['id']; $_SESSION['visitor_home'] = $r[0]['url']; $_SESSION['visitor_visiting'] = $r[0]['uid']; - if(!$quiet) + if (!$quiet) info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL); // Visitors get 1 day session. $session_id = session_id(); diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 52b5eb9f9..a11ea1d9e 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -19,7 +19,7 @@ require_once('include/group.php'); function dfrn_request_init(App $a) { - if($a->argc > 1) + if ($a->argc > 1) $which = $a->argv[1]; profile_load($a,$which); @@ -44,13 +44,13 @@ function dfrn_request_init(App $a) { */ function dfrn_request_post(App $a) { - if(($a->argc != 2) || (! count($a->profile))) { + if (($a->argc != 2) || (! count($a->profile))) { logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile)); return; } - if(x($_POST, 'cancel')) { + if (x($_POST, 'cancel')) { goaway(z_root()); } @@ -63,13 +63,13 @@ function dfrn_request_post(App $a) { * */ - if((x($_POST,'localconfirm')) && ($_POST['localconfirm'] == 1)) { + if ((x($_POST,'localconfirm')) && ($_POST['localconfirm'] == 1)) { /* * Ensure this is a valid request */ - if(local_user() && ($a->user['nickname'] == $a->argv[1]) && (x($_POST,'dfrn_url'))) { + if (local_user() && ($a->user['nickname'] == $a->argv[1]) && (x($_POST,'dfrn_url'))) { $dfrn_url = notags(trim($_POST['dfrn_url'])); @@ -80,7 +80,7 @@ function dfrn_request_post(App $a) { $blocked = 1; $pending = 1; - if(x($dfrn_url)) { + if (x($dfrn_url)) { /* * Lookup the contact based on their URL (which is the only unique thing we have at the moment) @@ -92,7 +92,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { - if(strlen($r[0]['dfrn-id'])) { + if (strlen($r[0]['dfrn-id'])) { /* * We don't need to be here. It has already happened. @@ -105,7 +105,7 @@ function dfrn_request_post(App $a) { $contact_record = $r[0]; } - if(is_array($contact_record)) { + if (is_array($contact_record)) { $r = q("UPDATE `contact` SET `ret-aes` = %d, hidden = %d WHERE `id` = %d", intval($aes_allow), intval($hidden), @@ -187,7 +187,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { $def_gid = get_default_group(local_user(), $r[0]["network"]); - if(intval($def_gid)) + if (intval($def_gid)) group_add_member(local_user(), '', $r[0]['id'], $def_gid); if (isset($photo)) @@ -249,7 +249,7 @@ function dfrn_request_post(App $a) { * */ - if(! (is_array($a->profile) && count($a->profile))) { + if (! (is_array($a->profile) && count($a->profile))) { notice( t('Profile unavailable.') . EOL); return; } @@ -265,13 +265,13 @@ function dfrn_request_post(App $a) { $pending = 1; - if( x($_POST,'dfrn_url')) { + if ( x($_POST,'dfrn_url')) { /* * Block friend request spam */ - if($maxreq) { + if ($maxreq) { $r = q("SELECT * FROM `intro` WHERE `datetime` > '%s' AND `uid` = %d", dbesc(datetime_convert('UTC','UTC','now - 24 hours')), intval($uid) @@ -300,7 +300,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(! $rr['rel']) { + if (! $rr['rel']) { q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", intval($rr['cid']) ); @@ -325,7 +325,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(! $rr['rel']) { + if (! $rr['rel']) { q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", intval($rr['cid']) ); @@ -340,16 +340,16 @@ function dfrn_request_post(App $a) { $real_name = (x($_POST,'realname') ? notags(trim($_POST['realname'])) : ''); $url = trim($_POST['dfrn_url']); - if(! strlen($url)) { + if (! strlen($url)) { notice( t("Invalid locator") . EOL ); return; } $hcard = ''; - if($email_follow) { + if ($email_follow) { - if(! validate_email($url)) { + if (! validate_email($url)) { notice( t('Invalid email address.') . EOL); return; } @@ -365,10 +365,10 @@ function dfrn_request_post(App $a) { $rel = CONTACT_IS_FOLLOWER; $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(get_config('system','dfrn_only')) + if (get_config('system','dfrn_only')) $mail_disabled = 1; - if(! $mail_disabled) { + if (! $mail_disabled) { $failed = false; $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval($uid) @@ -470,18 +470,18 @@ function dfrn_request_post(App $a) { logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG); - if($network === NETWORK_DFRN) { + if ($network === NETWORK_DFRN) { $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1", intval($uid), dbesc($url) ); if (dbm::is_result($ret)) { - if(strlen($ret[0]['issued-id'])) { + if (strlen($ret[0]['issued-id'])) { notice( t('You have already introduced yourself here.') . EOL ); return; } - elseif($ret[0]['rel'] == CONTACT_IS_FRIEND) { + elseif ($ret[0]['rel'] == CONTACT_IS_FRIEND) { notice( sprintf( t('Apparently you are already friends with %s.'), $a->profile['name']) . EOL); return; } @@ -493,7 +493,7 @@ function dfrn_request_post(App $a) { $issued_id = random_string(); - if(is_array($contact_record)) { + if (is_array($contact_record)) { // There is a contact record but no issued-id, so this // is a reciprocal introduction from a known contact $r = q("UPDATE `contact` SET `issued-id` = '%s' WHERE `id` = %d", @@ -718,7 +718,7 @@ function dfrn_request_content(App $a) { return $o; } - elseif((x($_GET,'confirm_key')) && strlen($_GET['confirm_key'])) { + elseif ((x($_GET,'confirm_key')) && strlen($_GET['confirm_key'])) { // we are the requestee and it is now safe to send our user their introduction, // We could just unblock it, but first we have to jump through a few hoops to @@ -738,10 +738,10 @@ function dfrn_request_content(App $a) { $auto_confirm = false; if (dbm::is_result($r)) { - if(($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP)) + if (($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP)) $auto_confirm = true; - if(! $auto_confirm) { + if (! $auto_confirm) { notification(array( 'type' => NOTIFY_INTRO, @@ -759,7 +759,7 @@ function dfrn_request_content(App $a) { )); } - if($auto_confirm) { + if ($auto_confirm) { require_once('mod/dfrn_confirm.php'); $handsfree = array( 'uid' => $r[0]['uid'], @@ -774,7 +774,7 @@ function dfrn_request_content(App $a) { } - if(! $auto_confirm) { + if (! $auto_confirm) { // If we are auto_confirming, this record will have already been nuked // in dfrn_confirm_post() @@ -794,8 +794,8 @@ function dfrn_request_content(App $a) { * Normal web request. Display our user's introduction form. */ - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { - if(! get_config('system','local_block')) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if (! get_config('system','local_block')) { notice( t('Public access denied.') . EOL); return; } diff --git a/mod/directory.php b/mod/directory.php index ba48bb392..e49e718a5 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -3,7 +3,7 @@ function directory_init(App $a) { $a->set_pager_itemspage(60); - if(local_user()) { + if (local_user()) { require_once('include/contact_widgets.php'); $a->page['aside'] .= findpeople_widget(); @@ -21,7 +21,7 @@ function directory_init(App $a) { function directory_post(App $a) { - if(x($_POST,'search')) + if (x($_POST,'search')) $a->data['search'] = $_POST['search']; } @@ -32,7 +32,7 @@ function directory_content(App $a) { require_once("mod/proxy.php"); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || (get_config('system','block_local_dir')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; @@ -41,18 +41,18 @@ function directory_content(App $a) { $o = ''; nav_set_selected('directory'); - if(x($a->data,'search')) + if (x($a->data,'search')) $search = notags(trim($a->data['search'])); else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); $gdirpath = ''; $dirurl = get_config('system','directory'); - if(strlen($dirurl)) { + if (strlen($dirurl)) { $gdirpath = zrl($dirurl,true); } - if($search) { + if ($search) { $search = dbesc($search); $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR @@ -110,28 +110,28 @@ function directory_content(App $a) { $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '
' : ''); $details = ''; - if(strlen($rr['locality'])) + if (strlen($rr['locality'])) $details .= $rr['locality']; - if(strlen($rr['region'])) { - if(strlen($rr['locality'])) + if (strlen($rr['region'])) { + if (strlen($rr['locality'])) $details .= ', '; $details .= $rr['region']; } - if(strlen($rr['country-name'])) { - if(strlen($details)) + if (strlen($rr['country-name'])) { + if (strlen($details)) $details .= ', '; $details .= $rr['country-name']; } -// if(strlen($rr['dob'])) { -// if(($years = age($rr['dob'],$rr['timezone'],'')) != 0) +// if (strlen($rr['dob'])) { +// if (($years = age($rr['dob'],$rr['timezone'],'')) != 0) // $details .= '
' . t('Age: ') . $years ; // } -// if(strlen($rr['gender'])) +// if (strlen($rr['gender'])) // $details .= '
' . t('Gender: ') . $rr['gender']; $profile = $rr; - if((x($profile,'address') == 1) + if ((x($profile,'address') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) || (x($profile,'postal-code') == 1) @@ -146,7 +146,7 @@ function directory_content(App $a) { $about = ((x($profile,'about') == 1) ? t('About:') : False); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $location_e = template_escape($location); } else { @@ -185,8 +185,9 @@ function directory_content(App $a) { unset($profile); unset($location); - if(! $arr['entry']) + if (! $arr['entry']) { continue; + } $entries[] = $arr['entry']; diff --git a/mod/dirfind.php b/mod/dirfind.php index 1b19ad92c..0e5f8a90d 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -166,8 +166,9 @@ function dirfind_content(App $a, $prefix = "") { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - if(strlen(get_config('system','directory'))) + if (strlen(get_config('system','directory'))) { $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + } $j = json_decode($x); } diff --git a/mod/editpost.php b/mod/editpost.php index f3746317a..5dc5ec508 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -51,7 +51,7 @@ function editpost_content(App $a) { $tpl = get_markup_template("jot.tpl"); - if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) + if (($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) $lockstate = 'lock'; else $lockstate = 'unlock'; @@ -64,13 +64,13 @@ function editpost_content(App $a) { $mail_enabled = false; $pubmail_enabled = false; - if(! $mail_disabled) { + if (! $mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); if (dbm::is_result($r)) { $mail_enabled = true; - if(intval($r[0]['pubmail'])) + if (intval($r[0]['pubmail'])) $pubmail_enabled = true; } } @@ -78,7 +78,7 @@ function editpost_content(App $a) { // I don't think there's any need for the $jotnets when editing the post, // and including them makes it difficult for the JS-free theme, so let's // disable them -/* if($mail_enabled) { +/* if ($mail_enabled) { $selected = (($pubmail_enabled) ? ' checked="checked" ' : ''); $jotnets .= '
' . t("Post to Email") . '
'; diff --git a/mod/events.php b/mod/events.php index ac0c444cb..2dd79a029 100644 --- a/mod/events.php +++ b/mod/events.php @@ -105,9 +105,9 @@ function events_post(App $a) { goaway($onerror_url); } - if((! $summary) || (! $start)) { + if ((! $summary) || (! $start)) { notice( t('Event title and start time are required.') . EOL); - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { echo( t('Event title and start time are required.')); killme(); } @@ -119,27 +119,27 @@ function events_post(App $a) { $c = q("select id from contact where uid = %d and self = 1 limit 1", intval(local_user()) ); - if(count($c)) + if (count($c)) $self = $c[0]['id']; else $self = 0; - if($share) { + if ($share) { $str_group_allow = perms2str($_POST['group_allow']); $str_contact_allow = perms2str($_POST['contact_allow']); $str_group_deny = perms2str($_POST['group_deny']); $str_contact_deny = perms2str($_POST['contact_deny']); // Undo the pseudo-contact of self, since there are real contacts now - if( strpos($str_contact_allow, '<' . $self . '>') !== false ) + if ( strpos($str_contact_allow, '<' . $self . '>') !== false ) { $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow); } // Make sure to set the `private` field as true. This is necessary to // have the posts show up correctly in Diaspora if an event is created // as visible only to self at first, but then edited to display to others. - if( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) ) + if ( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) ) { $private_event = true; } @@ -173,7 +173,7 @@ function events_post(App $a) { $datarray['created'] = $created; $datarray['edited'] = $edited; - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { $html = format_event_html($datarray); echo $html; killme(); @@ -181,7 +181,7 @@ function events_post(App $a) { $item_id = event_store($datarray); - if(! $cid) + if (! $cid) proc_run(PRIORITY_HIGH, "include/notifier.php", "event", $item_id); goaway($_SESSION['return_url']); @@ -248,7 +248,7 @@ function events_content(App $a) { $m = 0; $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0); - if($a->argc > 1) { + if ($a->argc > 1) { if ($a->argc > 2 && $a->argv[1] == 'event') { $mode = 'edit'; $event_id = intval($a->argv[2]); @@ -289,13 +289,13 @@ function events_content(App $a) { $nextyear = $y; $nextmonth = $m + 1; - if($nextmonth > 12) { + if ($nextmonth > 12) { $nextmonth = 1; $nextyear ++; } $prevyear = $y; - if($m > 1) + if ($m > 1) $prevmonth = $m - 1; else { $prevmonth = 12; @@ -371,9 +371,9 @@ function events_content(App $a) { } // Get rid of dashes in key names, Smarty3 can't handle them - foreach($events as $key => $event) { + foreach ($events as $key => $event) { $event_item = array(); - foreach($event['item'] as $k => $v) { + foreach ($event['item'] as $k => $v) { $k = str_replace('-','_',$k); $event_item[$k] = $v; } @@ -405,7 +405,7 @@ function events_content(App $a) { } - if($mode === 'edit' && $event_id) { + if ($mode === 'edit' && $event_id) { $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()) @@ -415,19 +415,19 @@ function events_content(App $a) { } // Passed parameters overrides anything found in the DB - if($mode === 'edit' || $mode === 'new') { - if(!x($orig_event)) $orig_event = array(); + if ($mode === 'edit' || $mode === 'new') { + if (!x($orig_event)) $orig_event = array(); // In case of an error the browser is redirected back here, with these parameters filled in with the previous values - if(x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; - if(x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; - if(x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; - if(x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; - if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; - if(x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; - if(x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; + if (x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; + if (x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; + if (x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; + if (x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; + if (x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; + if (x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; + if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; } - if($mode === 'edit' || $mode === 'new') { + if ($mode === 'edit' || $mode === 'new') { $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); @@ -439,21 +439,24 @@ function events_content(App $a) { $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); - if(! x($orig_event)) + if (! x($orig_event)) { $sh_checked = ''; - else + } else { $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' ); + } - if($cid OR ($mode !== 'new')) + if ($cid OR ($mode !== 'new')) { $sh_checked .= ' disabled="disabled" '; + } $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); $tz = date_default_timezone_get(); - if(x($orig_event)) + if (x($orig_event)) { $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); + } $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); @@ -470,8 +473,9 @@ function events_content(App $a) { $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0); $f = get_config('system','event_input_format'); - if(! $f) + if (! $f) { $f = 'ymd'; + } require_once('include/acl_selectors.php'); diff --git a/mod/fbrowser.php b/mod/fbrowser.php index 9a0e9244c..ae62ce9a3 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -66,10 +66,9 @@ function fbrowser_content(App $a) { $types = Photo::supportedTypes(); $ext = $types[$rr['type']]; - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $filename_e = template_escape($rr['filename']); - } - else { + } else { $filename_e = $rr['filename']; } diff --git a/mod/filer.php b/mod/filer.php index 47c4aa5e4..d2df7f24c 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -16,7 +16,7 @@ function filer_content(App $a) { logger('filer: tag ' . $term . ' item ' . $item_id); - if($item_id && strlen($term)){ + if ($item_id && strlen($term)){ // file item file_tag_save_file(local_user(),$item_id,$term); } else { diff --git a/mod/friendica.php b/mod/friendica.php index f613dfd39..f1f0a6a0f 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -7,7 +7,7 @@ function friendica_init(App $a) { $register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'); $sql_extra = ''; - if(x($a->config,'admin_nickname')) { + if (x($a->config,'admin_nickname')) { $sql_extra = sprintf(" AND nickname = '%s' ",dbesc($a->config['admin_nickname'])); } if (isset($a->config['admin_email']) && $a->config['admin_email']!=''){ @@ -24,18 +24,18 @@ function friendica_init(App $a) { } $visible_plugins = array(); - if(is_array($a->plugins) && count($a->plugins)) { + if (is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $visible_plugins[] = $rr['name']; } Config::load('feature_lock'); $locked_features = array(); - if(is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) { - foreach($a->config['feature_lock'] as $k => $v) { - if($k === 'config_loaded') + if (is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) { + foreach ($a->config['feature_lock'] as $k => $v) { + if ($k === 'config_loaded') continue; $locked_features[$k] = intval($v); } @@ -80,22 +80,24 @@ function friendica_content(App $a) { $o .= '

'; $visible_plugins = array(); - if(is_array($a->plugins) && count($a->plugins)) { + if (is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $visible_plugins[] = $rr['name']; } - if(count($visible_plugins)) { + if (count($visible_plugins)) { $o .= '

' . t('Installed plugins/addons/apps:') . '

'; $sorted = $visible_plugins; $s = ''; sort($sorted); - foreach($sorted as $p) { - if(strlen($p)) { - if(strlen($s)) $s .= ', '; + foreach ($sorted as $p) { + if (strlen($p)) { + if (strlen($s)) { + $s .= ', '; + } $s .= $p; } } diff --git a/mod/fsuggest.php b/mod/fsuggest.php index b3d543971..2cd91ea57 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -29,7 +29,7 @@ function fsuggest_post(App $a) { $note = escape_tags(trim($_POST['note'])); - if($new_contact) { + if ($new_contact) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($new_contact), intval(local_user()) @@ -80,8 +80,9 @@ function fsuggest_content(App $a) { return; } - if($a->argc != 2) + if ($a->argc != 2) { return; + } $contact_id = intval($a->argv[1]); diff --git a/mod/group.php b/mod/group.php index 2b332e401..640fa7e60 100644 --- a/mod/group.php +++ b/mod/group.php @@ -5,7 +5,7 @@ function validate_members(&$item) { } function group_init(App $a) { - if(local_user()) { + if (local_user()) { require_once('include/group.php'); $a->page['aside'] = group_side('contacts','group','extended',(($a->argc > 1) ? intval($a->argv[1]) : 0)); } @@ -20,7 +20,7 @@ function group_post(App $a) { return; } - if(($a->argc == 2) && ($a->argv[1] === 'new')) { + if (($a->argc == 2) && ($a->argv[1] === 'new')) { check_form_security_token_redirectOnErr('/group/new', 'group_edit'); $name = notags(trim($_POST['groupname'])); @@ -80,10 +80,12 @@ function group_content(App $a) { // Switch to text mode interface if we have more than 'n' contacts or group members $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit'); - if($switchtotext === false) + if ($switchtotext === false) { $switchtotext = get_config('system','groupedit_image_limit'); - if($switchtotext === false) + } + if ($switchtotext === false) { $switchtotext = 400; + } $tpl = get_markup_template('group_edit.tpl'); @@ -99,8 +101,6 @@ function group_content(App $a) { '$gid' => 'new', '$form_security_token' => get_form_security_token("group_edit"), )); - - } if (($a->argc == 3) && ($a->argv[1] === 'drop')) { @@ -135,8 +135,9 @@ function group_content(App $a) { intval($a->argv[2]), intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $change = intval($a->argv[2]); + } } if (($a->argc > 1) && (intval($a->argv[1]))) { @@ -153,23 +154,23 @@ function group_content(App $a) { $group = $r[0]; $members = group_get_members($group['id']); $preselected = array(); - if(count($members)) { - foreach($members as $member) + if (count($members)) { + foreach ($members as $member) { $preselected[] = $member['id']; + } } - if($change) { - if(in_array($change,$preselected)) { + if ($change) { + if (in_array($change,$preselected)) { group_rmv_member(local_user(),$group['name'],$change); - } - else { + } else { group_add_member(local_user(),$group['name'],$change); } $members = group_get_members($group['id']); $preselected = array(); - if(count($members)) { - foreach($members as $member) + if (count($members)) { + foreach ($members as $member) $preselected[] = $member['id']; } } @@ -193,8 +194,9 @@ function group_content(App $a) { } - if(! isset($group)) + if (! isset($group)) { return; + } $groupeditor = array( 'label_members' => t('Members'), @@ -206,13 +208,13 @@ function group_content(App $a) { $sec_token = addslashes(get_form_security_token('group_member_change')); $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); - foreach($members as $member) { - if($member['url']) { + foreach ($members as $member) { + if ($member['url']) { $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode); - } - else + } else { group_rmv_member(local_user(),$group['name'],$member['id']); + } } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC", @@ -221,8 +223,8 @@ function group_content(App $a) { if (dbm::is_result($r)) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); - foreach($r as $member) { - if(! in_array($member['id'],$preselected)) { + foreach ($r as $member) { + if (! in_array($member['id'],$preselected)) { $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode); } @@ -232,7 +234,7 @@ function group_content(App $a) { $context['$groupeditor'] = $groupeditor; $context['$desc'] = t('Click on a contact to add or remove.'); - if($change) { + if ($change) { $tpl = get_markup_template('groupeditor.tpl'); echo replace_macros($tpl, $context); killme(); diff --git a/mod/help.php b/mod/help.php index c380aa391..602653eea 100644 --- a/mod/help.php +++ b/mod/help.php @@ -30,9 +30,10 @@ function help_content(App $a) { $path = ''; // looping through the argv keys bigger than 0 to build // a path relative to /help - for($x = 1; $x < argc(); $x ++) { - if(strlen($path)) + for ($x = 1; $x < argc(); $x ++) { + if (strlen($path)) { $path .= '/'; + } $path .= argv($x); } $title = basename($path); @@ -65,16 +66,22 @@ function help_content(App $a) { $toc="

TOC