From abff6372ddd09be7750b5f1af5a1f889cfeb9635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 10:10:33 +0100 Subject: [PATCH 01/41] Coding convention applied: - space between "if" and brace - curly braces on conditional blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder Conflicts: include/lock.php --- boot.php | 2 +- include/dfrn.php | 6 ++++-- include/follow.php | 2 +- include/group.php | 5 +++-- include/like.php | 3 ++- include/lock.php | 3 ++- include/notifier.php | 3 ++- include/onepoll.php | 3 ++- include/redir.php | 7 ++++--- include/socgraph.php | 2 +- include/text.php | 7 ++++--- mod/allfriends.php | 2 +- mod/attach.php | 4 ++-- mod/common.php | 2 +- mod/community.php | 2 +- mod/contactgroup.php | 2 +- mod/contacts.php | 4 ++-- mod/content.php | 2 +- mod/crepair.php | 7 ++++--- mod/delegate.php | 2 +- mod/dfrn_confirm.php | 6 +++--- mod/dfrn_notify.php | 7 ++++--- mod/dfrn_poll.php | 10 ++++++---- mod/dfrn_request.php | 5 +++-- mod/fsuggest.php | 4 ++-- mod/group.php | 4 ++-- mod/ignored.php | 3 ++- mod/item.php | 5 +++-- mod/lockview.php | 3 ++- mod/lostpass.php | 4 ++-- mod/manage.php | 3 ++- mod/match.php | 3 ++- mod/message.php | 2 +- mod/modexp.php | 3 ++- mod/network.php | 4 ++-- mod/poke.php | 2 +- mod/post.php | 3 ++- mod/profiles.php | 6 +++--- mod/profperm.php | 2 +- mod/pubsub.php | 9 +++++---- mod/receive.php | 3 ++- mod/salmon.php | 5 +++-- mod/search.php | 4 ++-- mod/settings.php | 5 +++-- mod/starred.php | 3 ++- mod/subthread.php | 3 ++- mod/suggest.php | 2 +- mod/tagrm.php | 6 ++++-- mod/viewcontacts.php | 3 ++- mod/wall_attach.php | 4 ++-- mod/wall_upload.php | 2 +- mod/wallmessage.php | 4 ++-- mod/xrd.php | 3 ++- 53 files changed, 118 insertions(+), 87 deletions(-) diff --git a/boot.php b/boot.php index b282f8d48e..c500468e5f 100644 --- a/boot.php +++ b/boot.php @@ -1028,7 +1028,7 @@ class App { } else { $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'", $common_filename); - if(! dbm::is_result($r)){ + if (! dbm::is_result($r)) { $this->cached_profile_image[$avatar_image] = $avatar_image; } else { $this->cached_profile_picdate[$common_filename] = "?rev=".urlencode($r[0]['picdate']); diff --git a/include/dfrn.php b/include/dfrn.php index 6451b8521b..689c5c2832 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -105,8 +105,9 @@ class dfrn { dbesc($owner_nick) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $owner = $r[0]; $owner_id = $owner['uid']; @@ -139,8 +140,9 @@ class dfrn { intval($owner_id) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $contact = $r[0]; require_once('include/security.php'); diff --git a/include/follow.php b/include/follow.php index d7066bcb55..e67beb84c2 100644 --- a/include/follow.php +++ b/include/follow.php @@ -254,7 +254,7 @@ function new_contact($uid,$url,$interactive = false) { intval($uid) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $result['message'] .= t('Unable to retrieve contact information.') . EOL; return $result; } diff --git a/include/group.php b/include/group.php index 2c90330686..67712aae7c 100644 --- a/include/group.php +++ b/include/group.php @@ -143,13 +143,14 @@ function group_add_member($uid,$name,$member,$gid = 0) { return true; // You might question this, but // we indicate success because the group member was in fact created // -- It was just created at another time - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { $r = q("INSERT INTO `group_member` (`uid`, `gid`, `contact-id`) VALUES( %d, %d, %d ) ", intval($uid), intval($gid), intval($member) - ); + ); + } return $r; } diff --git a/include/like.php b/include/like.php index 8239633e6a..8223cf3626 100644 --- a/include/like.php +++ b/include/like.php @@ -78,8 +78,9 @@ function do_like($item_id, $verb) { intval($item['contact-id']), intval($item['uid']) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return false; + } if(! $r[0]['self']) $remote_owner = $r[0]; } diff --git a/include/lock.php b/include/lock.php index 0c7b6acaa4..b3d488a357 100644 --- a/include/lock.php +++ b/include/lock.php @@ -23,7 +23,8 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { ); $got_lock = true; } - elseif(! dbm::is_result($r)) { // the Boolean value for count($r) should be equivalent to the Boolean value of $r + elseif (! dbm::is_result($r)) { + /// @TODO the Boolean value for count($r) should be equivalent to the Boolean value of $r q("INSERT INTO `locks` (`name`, `created`, `locked`) VALUES ('%s', '%s', 1)", dbesc($fn_name), dbesc(datetime_convert()) diff --git a/include/notifier.php b/include/notifier.php index c4e7df47ac..8823834c1d 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -210,8 +210,9 @@ function notifier_run(&$argv, &$argc){ intval($uid) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } $owner = $r[0]; diff --git a/include/onepoll.php b/include/onepoll.php index 2834036665..d92cb915b6 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -143,8 +143,9 @@ function onepoll_run(&$argv, &$argc){ $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1", intval($importer_uid) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } $importer = $r[0]; diff --git a/include/redir.php b/include/redir.php index 8d65089de7..d8bb764396 100644 --- a/include/redir.php +++ b/include/redir.php @@ -36,9 +36,9 @@ function auto_redir(&$a, $contact_nick) { dbesc($nurl) ); - if((! dbm::is_result($r)) || $r[0]['id'] == remote_user()) + if ((! dbm::is_result($r)) || $r[0]['id'] == remote_user()) { return; - + } $r = q("SELECT * FROM contact WHERE nick = '%s' AND network = '%s' AND uid = %d AND url LIKE '%%%s%%' LIMIT 1", @@ -48,8 +48,9 @@ function auto_redir(&$a, $contact_nick) { dbesc($baseurl) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } $cid = $r[0]['id']; diff --git a/include/socgraph.php b/include/socgraph.php index 8a95126546..6ad276cdda 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -330,7 +330,7 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca intval($gcid), intval($zcid) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { q("INSERT INTO `glink` (`cid`,`uid`,`gcid`,`zcid`, `updated`) VALUES (%d,%d,%d,%d, '%s') ", intval($cid), intval($uid), diff --git a/include/text.php b/include/text.php index a2c474d32e..05801d024c 100644 --- a/include/text.php +++ b/include/text.php @@ -2000,8 +2000,9 @@ function file_tag_unsave_file($uid,$item,$file,$cat = false) { intval($item), intval($uid) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return false; + } q("UPDATE `item` SET `file` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc(str_replace($pattern,'',$r[0]['file'])), @@ -2020,11 +2021,11 @@ function file_tag_unsave_file($uid,$item,$file,$cat = false) { //$r = q("select file from item where uid = %d and deleted = 0 " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')), //); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $saved = get_pconfig($uid,'system','filetags'); set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved)); - } + return true; } diff --git a/mod/allfriends.php b/mod/allfriends.php index 1f2c043ced..e4f067eaf7 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -39,7 +39,7 @@ function allfriends_content(&$a) { $r = all_friends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $o .= t('No friends to display.'); return $o; } diff --git a/mod/attach.php b/mod/attach.php index 274acfc2be..94cb75a386 100644 --- a/mod/attach.php +++ b/mod/attach.php @@ -16,7 +16,7 @@ function attach_init(&$a) { $r = q("SELECT * FROM `attach` WHERE `id` = %d LIMIT 1", intval($item_id) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Item was not found.'). EOL); return; } @@ -29,7 +29,7 @@ function attach_init(&$a) { dbesc($item_id) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/common.php b/mod/common.php index 9f9379be57..9781d1607c 100644 --- a/mod/common.php +++ b/mod/common.php @@ -94,7 +94,7 @@ function common_content(&$a) { $r = common_friends_zcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { return $o; } diff --git a/mod/community.php b/mod/community.php index 40d4016f33..c8f04d8bd6 100644 --- a/mod/community.php +++ b/mod/community.php @@ -71,7 +71,7 @@ function community_content(&$a, $update = 0) { $r = community_getitems($a->pager['start'], $a->pager['itemspage']); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { info( t('No results.') . EOL); return $o; } diff --git a/mod/contactgroup.php b/mod/contactgroup.php index 4456db2f53..0671ff42ae 100644 --- a/mod/contactgroup.php +++ b/mod/contactgroup.php @@ -24,7 +24,7 @@ function contactgroup_content(&$a) { intval($a->argv[1]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { killme(); } diff --git a/mod/contacts.php b/mod/contacts.php index 37cc09cab6..22e08b8c96 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -19,7 +19,7 @@ function contacts_init(&$a) { intval(local_user()), intval($contact_id) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $contact_id = 0; } } @@ -169,7 +169,7 @@ function contacts_post(&$a) { intval($profile_id), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Could not locate selected profile.') . EOL); return; } diff --git a/mod/content.php b/mod/content.php index bc98f7e51d..332a35f006 100644 --- a/mod/content.php +++ b/mod/content.php @@ -113,7 +113,7 @@ function content_content(&$a, $update = 0) { intval($group), intval($_SESSION['uid']) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { if($update) killme(); notice( t('No such group') . EOL ); diff --git a/mod/crepair.php b/mod/crepair.php index b4275f6baa..66faadb06a 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -14,7 +14,7 @@ function crepair_init(&$a) { intval(local_user()), intval($contact_id) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $contact_id = 0; } } @@ -43,8 +43,9 @@ function crepair_post(&$a) { ); } - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } $contact = $r[0]; @@ -110,7 +111,7 @@ function crepair_content(&$a) { ); } - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Contact not found.') . EOL); return; } diff --git a/mod/delegate.php b/mod/delegate.php index 343e1e3038..0ba5dd39c1 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -97,7 +97,7 @@ function delegate_content(&$a) { dbesc(NETWORK_DFRN) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('No potential page delegates located.') . EOL); return; } diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 7097b0117a..69d708f7fc 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -121,7 +121,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { intval($uid) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('Contact not found in DB.'); notice( t('Contact not found.') . EOL ); notice( t('This may occasionally happen if contact was requested by both persons and it has already been approved.') . EOL ); @@ -553,7 +553,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1", dbesc($node)); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $message = sprintf(t('No user record found for \'%s\' '), $node); xml_status(3,$message); // failure // NOTREACHED @@ -640,7 +640,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { dbesc($dfrn_pubkey), intval($dfrn_record) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $message = t('Unable to set your contact credentials on our system.'); xml_status(3,$message); } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index dfa2af18ce..ca12211583 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -42,7 +42,7 @@ function dfrn_notify_post(&$a) { dbesc($dfrn_id), dbesc($challenge) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); xml_status(3); } @@ -88,7 +88,7 @@ function dfrn_notify_post(&$a) { dbesc($a->argv[1]) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); xml_status(3); //NOTREACHED @@ -284,8 +284,9 @@ function dfrn_notify_content(&$a) { dbesc($a->argv[1]) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { $status = 1; + } logger("Remote rino version: ".$rino_remote." for ".$r[0]["url"], LOGGER_DEBUG); diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 7c3fced12f..0c55af2a89 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -126,7 +126,7 @@ function dfrn_poll_init(&$a) { $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1", dbesc($sec) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { xml_status(3, 'No ticket'); // NOTREACHED } @@ -223,7 +223,7 @@ function dfrn_poll_post(&$a) { $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1", dbesc($sec) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { xml_status(3, 'No ticket'); // NOTREACHED } @@ -284,8 +284,9 @@ function dfrn_poll_post(&$a) { dbesc($challenge) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $type = $r[0]['type']; $last_update = $r[0]['last_update']; @@ -319,8 +320,9 @@ function dfrn_poll_post(&$a) { $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 $sql_extra LIMIT 1"); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $contact = $r[0]; $owner_uid = $r[0]['uid']; diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 24a1dc0725..7a8021784d 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -371,7 +371,7 @@ function dfrn_request_post(&$a) { intval($uid) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('This account has not been configured for email. Request failed.') . EOL); return; } @@ -842,8 +842,9 @@ function dfrn_request_content(&$a) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval($a->profile['uid']) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { $mail_disabled = 1; + } } // "coming soon" is disabled for now diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 1d56f45736..4370952ca1 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -16,7 +16,7 @@ function fsuggest_post(&$a) { intval($contact_id), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Contact not found.') . EOL); return; } @@ -88,7 +88,7 @@ function fsuggest_content(&$a) { intval($contact_id), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Contact not found.') . EOL); return; } diff --git a/mod/group.php b/mod/group.php index 33b819ed5d..c4854a602d 100644 --- a/mod/group.php +++ b/mod/group.php @@ -43,7 +43,7 @@ function group_post(&$a) { intval($a->argv[1]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Group not found.') . EOL ); goaway(App::get_baseurl() . '/contacts'); return; // NOTREACHED @@ -136,7 +136,7 @@ function group_content(&$a) { intval($a->argv[1]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Group not found.') . EOL ); goaway(App::get_baseurl() . '/contacts'); } diff --git a/mod/ignored.php b/mod/ignored.php index eec204c708..4aeeb21e6b 100644 --- a/mod/ignored.php +++ b/mod/ignored.php @@ -16,8 +16,9 @@ function ignored_init(&$a) { intval(local_user()), intval($message_id) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } if(! intval($r[0]['ignored'])) $ignored = 1; diff --git a/mod/item.php b/mod/item.php index c741f16144..7bee5f3eae 100644 --- a/mod/item.php +++ b/mod/item.php @@ -112,7 +112,7 @@ function item_post(&$a) { } } - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Unable to locate original post.') . EOL); if(x($_REQUEST,'return')) goaway($return_path); @@ -464,8 +464,9 @@ function item_post(&$a) { intval($profile_uid) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { continue; + } $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ", diff --git a/mod/lockview.php b/mod/lockview.php index c806fc3175..68b5d30cfe 100644 --- a/mod/lockview.php +++ b/mod/lockview.php @@ -21,8 +21,9 @@ function lockview_content(&$a) { dbesc($type), intval($item_id) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $item = $r[0]; call_hooks('lockview_content', $item); diff --git a/mod/lostpass.php b/mod/lostpass.php index 122024d26b..92e64f7e2e 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -15,7 +15,7 @@ function lostpass_post(&$a) { dbesc($loginame) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('No valid account found.') . EOL); goaway(z_root()); } @@ -87,7 +87,7 @@ function lostpass_content(&$a) { $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1", dbesc($hash) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $o = t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed."); return $o; } diff --git a/mod/manage.php b/mod/manage.php index 4a4f0a9e37..2138595bee 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -56,8 +56,9 @@ function manage_post(&$a) { ); } - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } unset($_SESSION['authenticated']); unset($_SESSION['uid']); diff --git a/mod/match.php b/mod/match.php index f7fe325b38..69bf3c1101 100644 --- a/mod/match.php +++ b/mod/match.php @@ -27,8 +27,9 @@ function match_content(&$a) { $r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval(local_user()) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) { notice( t('No keywords to match. Please add keywords to your default profile.') . EOL); return; diff --git a/mod/message.php b/mod/message.php index 0a2c797b42..b0d0ba95ca 100644 --- a/mod/message.php +++ b/mod/message.php @@ -381,7 +381,7 @@ function message_content(&$a) { $r = get_messages(local_user(), $a->pager['start'], $a->pager['itemspage']); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { info( t('No messages.') . EOL); return $o; } diff --git a/mod/modexp.php b/mod/modexp.php index d1dabb101b..3729e3236c 100644 --- a/mod/modexp.php +++ b/mod/modexp.php @@ -12,8 +12,9 @@ function modexp_init(&$a) { dbesc($nick) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $lines = explode("\n",$r[0]['spubkey']); unset($lines[0]); diff --git a/mod/network.php b/mod/network.php index 057ef79145..c040a547a4 100644 --- a/mod/network.php +++ b/mod/network.php @@ -126,7 +126,7 @@ function network_init(&$a) { intval(local_user()), dbesc($search) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { q("INSERT INTO `search` ( `uid`,`term` ) VALUES ( %d, '%s') ", intval(local_user()), dbesc($search) @@ -463,7 +463,7 @@ function network_content(&$a, $update = 0) { intval($group), intval($_SESSION['uid']) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { if($update) killme(); notice( t('No such group') . EOL ); diff --git a/mod/poke.php b/mod/poke.php index 0619a34e07..fea5c0c0d8 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -52,7 +52,7 @@ function poke_init(&$a) { intval($uid) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('poke: no contact ' . $contact_id); return; } diff --git a/mod/post.php b/mod/post.php index 76282d29a5..a8d345ecb6 100644 --- a/mod/post.php +++ b/mod/post.php @@ -23,8 +23,9 @@ function post_post(&$a) { AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($nickname) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { http_status_exit(500); + } $importer = $r[0]; } diff --git a/mod/profiles.php b/mod/profiles.php index 1ea3c3f462..53372f83d2 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -15,7 +15,7 @@ function profiles_init(&$a) { intval($a->argv[2]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Profile not found.') . EOL); goaway('profiles'); return; // NOTREACHED @@ -130,7 +130,7 @@ function profiles_init(&$a) { intval($a->argv[1]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Profile not found.') . EOL); killme(); return; @@ -613,7 +613,7 @@ function profiles_content(&$a) { intval($a->argv[1]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Profile not found.') . EOL); return; } diff --git a/mod/profperm.php b/mod/profperm.php index 1c37f84ab2..aa610d3a93 100644 --- a/mod/profperm.php +++ b/mod/profperm.php @@ -52,7 +52,7 @@ function profperm_content(&$a) { intval($a->argv[1]), intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('Invalid profile identifier.') . EOL ); return; } diff --git a/mod/pubsub.php b/mod/pubsub.php index ddda7ec228..ea7e1000ba 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -47,7 +47,7 @@ function pubsub_init(&$a) { $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($nick) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('pubsub: local account not found: ' . $nick); hub_return(false, ''); } @@ -62,7 +62,7 @@ function pubsub_init(&$a) { intval($contact_id), intval($owner['uid']) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('pubsub: contact '.$contact_id.' not found.'); hub_return(false, ''); } @@ -117,8 +117,9 @@ function pubsub_post(&$a) { $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($nick) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { hub_post_return(); + } $importer = $r[0]; @@ -131,7 +132,7 @@ function pubsub_post(&$a) { dbesc(NETWORK_FEED) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('pubsub: no contact record for "'.$nick.' ('.$contact_id.')" - ignored. '.$xml); hub_post_return(); } diff --git a/mod/receive.php b/mod/receive.php index dd4e61ae4f..99e3648e91 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -34,8 +34,9 @@ function receive_post(&$a) { $r = q("SELECT * FROM `user` WHERE `guid` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($guid) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { http_status_exit(500); + } $importer = $r[0]; } diff --git a/mod/salmon.php b/mod/salmon.php index 78cdc09328..ff5856a946 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -31,8 +31,9 @@ function salmon_post(&$a) { $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($nick) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { http_status_exit(500); + } $importer = $r[0]; @@ -150,7 +151,7 @@ function salmon_post(&$a) { dbesc(normalise_link($author_link)), intval($importer['uid']) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('mod-salmon: Author unknown to us.'); if(get_pconfig($importer['uid'],'system','ostatus_autofriend')) { $result = new_contact($importer['uid'],$author_link); diff --git a/mod/search.php b/mod/search.php index d36cc8fcb7..c19bb27673 100644 --- a/mod/search.php +++ b/mod/search.php @@ -53,7 +53,7 @@ function search_init(&$a) { intval(local_user()), dbesc($search) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { q("INSERT INTO `search` (`uid`,`term`) VALUES ( %d, '%s')", intval(local_user()), dbesc($search) @@ -219,7 +219,7 @@ function search_content(&$a) { intval($a->pager['start']), intval($a->pager['itemspage'])); } - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { info( t('No results.') . EOL); return $o; } diff --git a/mod/settings.php b/mod/settings.php index 41783815e7..e7fd55e944 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -225,7 +225,7 @@ function settings_post(&$a) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user()) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { q("INSERT INTO `mailacct` (`uid`) VALUES (%d)", intval(local_user()) ); @@ -752,8 +752,9 @@ function settings_content(&$a) { $settings_addons = ""; $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' "); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { $settings_addons = t('No Plugin settings configured'); + } call_hooks('plugin_settings', $settings_addons); diff --git a/mod/starred.php b/mod/starred.php index 5acbb393ef..0e5e75d167 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -18,8 +18,9 @@ function starred_init(&$a) { intval(local_user()), intval($message_id) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } if(! intval($r[0]['starred'])) $starred = 1; diff --git a/mod/subthread.php b/mod/subthread.php index dc014047a0..66072bcc88 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -41,8 +41,9 @@ function subthread_content(&$a) { intval($item['contact-id']), intval($item['uid']) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } if(! $r[0]['self']) $remote_owner = $r[0]; } diff --git a/mod/suggest.php b/mod/suggest.php index 080decc71a..73f5ffe4b2 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -67,7 +67,7 @@ function suggest_content(&$a) { $r = suggestion_query(local_user()); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.'); return $o; } diff --git a/mod/tagrm.php b/mod/tagrm.php index 08d390a70b..d6e57d36a9 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -19,8 +19,9 @@ function tagrm_post(&$a) { intval(local_user()) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); + } $arr = explode(',', $r[0]['tag']); for($x = 0; $x < count($arr); $x ++) { @@ -68,8 +69,9 @@ function tagrm_content(&$a) { intval(local_user()) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); + } $arr = explode(',', $r[0]['tag']); diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php index c9f465676c..3fd5d79e1b 100644 --- a/mod/viewcontacts.php +++ b/mod/viewcontacts.php @@ -16,8 +16,9 @@ function viewcontacts_init(&$a) { dbesc($nick) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { return; + } $a->data['user'] = $r[0]; $a->profile_uid = $r[0]['uid']; diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 80fc1c6e79..525d3509c1 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -12,7 +12,7 @@ function wall_attach_post(&$a) { $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($nick) ); - if(! dbm::is_result($r)){ + if (! dbm::is_result($r)) { if ($r_json) { echo json_encode(array('error'=>t('Invalid request.'))); killme(); @@ -168,7 +168,7 @@ function wall_attach_post(&$a) { dbesc($hash) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { $msg = t('File upload failed.'); if ($r_json) { echo json_encode(array('error'=>$msg)); diff --git a/mod/wall_upload.php b/mod/wall_upload.php index e277290985..eb2a92323a 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -15,7 +15,7 @@ function wall_upload_post(&$a, $desktopmode = true) { dbesc($nick) ); - if(! dbm::is_result($r)){ + if (! dbm::is_result($r)) { if ($r_json) { echo json_encode(array('error'=>t('Invalid request.'))); killme(); diff --git a/mod/wallmessage.php b/mod/wallmessage.php index 03a0b7a16f..afe25cbe8b 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -22,7 +22,7 @@ function wallmessage_post(&$a) { dbesc($recipient) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { logger('wallmessage: no recipient'); return; } @@ -91,7 +91,7 @@ function wallmessage_content(&$a) { dbesc($recipient) ); - if(! dbm::is_result($r)) { + if (! dbm::is_result($r)) { notice( t('No recipient.') . EOL); logger('wallmessage: no recipient'); return; diff --git a/mod/xrd.php b/mod/xrd.php index 576ae9b38f..290c524a7d 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -21,8 +21,9 @@ function xrd_init(&$a) { $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1", dbesc($name) ); - if(! dbm::is_result($r)) + if (! dbm::is_result($r)) { killme(); + } $salmon_key = salmon_key($r[0]['spubkey']); From 65e1cd728c3ba70d166df0fee1f678b537c4805d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 10:35:28 +0100 Subject: [PATCH 02/41] Coding convention: - added curly braces - added space between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/identity.php | 10 +++++++--- include/plugin.php | 3 ++- mod/admin.php | 10 +++++----- mod/cal.php | 3 ++- mod/content.php | 23 ++++++++++++++--------- mod/delegate.php | 6 ++++-- mod/dfrn_confirm.php | 13 ++++++++----- mod/events.php | 3 ++- mod/removeme.php | 24 +++++++++++++++--------- mod/settings.php | 11 ++++++----- object/Item.php | 32 ++++++++++++++++++++------------ 11 files changed, 85 insertions(+), 53 deletions(-) diff --git a/include/identity.php b/include/identity.php index 1307b42b1b..5439b2cc10 100644 --- a/include/identity.php +++ b/include/identity.php @@ -229,13 +229,16 @@ function profile_sidebar($profile, $block = 0) { // Is the local user already connected to that user? if ($connect AND local_user()) { - if (isset($profile["url"])) + if (isset($profile["url"])) { $profile_url = normalise_link($profile["url"]); - else + } + else { $profile_url = normalise_link(App::get_baseurl()."/profile/".$profile["nickname"]); + } $r = q("SELECT * FROM `contact` WHERE NOT `pending` AND `uid` = %d AND `nurl` = '%s'", local_user(), $profile_url); + if (dbm::is_result($r)) $connect = false; } @@ -684,8 +687,9 @@ function advanced_profile(&$a) { $profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid)); } - if ($a->profile['uid'] == local_user()) + if ($a->profile['uid'] == local_user()) { $profile['edit'] = array(App::get_baseurl(). '/profiles/'.$a->profile['id'], t('Edit profile'),"", t('Edit profile')); + } return replace_macros($tpl, array( '$title' => t('Profile'), diff --git a/include/plugin.php b/include/plugin.php index 4242b730b0..c7c44e433d 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -412,8 +412,9 @@ function get_theme_info($theme){ function get_theme_screenshot($theme) { $exts = array('.png','.jpg'); foreach($exts as $ext) { - if(file_exists('view/theme/' . $theme . '/screenshot' . $ext)) + if(file_exists('view/theme/' . $theme . '/screenshot' . $ext)) { return(App::get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext); + } } return(App::get_baseurl() . '/images/blank.png'); } diff --git a/mod/admin.php b/mod/admin.php index 832ca470fe..b4495a1946 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -32,13 +32,12 @@ function admin_post(&$a){ // do not allow a page manager to access the admin panel at all. - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { return; - - + } // urls - if($a->argc > 1) { + if ($a->argc > 1) { switch ($a->argv[1]){ case 'site': admin_page_site_post($a); @@ -134,8 +133,9 @@ function admin_content(&$a) { return login(false); } - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { return ""; + } // APC deactivated, since there are problems with PHP 5.5 //if (function_exists("apc_delete")) { diff --git a/mod/cal.php b/mod/cal.php index 1899a9899a..8b8dbed958 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -231,8 +231,9 @@ function cal_content(&$a) { $r = sort_by_date($r); foreach($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); - if(! x($links,$j)) + if(! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; + } } } diff --git a/mod/content.php b/mod/content.php index 332a35f006..1a3fb10952 100644 --- a/mod/content.php +++ b/mod/content.php @@ -742,10 +742,11 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { } } - if(local_user() && link_compare($a->contact['url'],$item['author-link'])) + if (local_user() && link_compare($a->contact['url'],$item['author-link'])) { $edpost = array(App::get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit")); - else + } else { $edpost = false; + } $drop = ''; $dropping = false; @@ -764,7 +765,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $isstarred = "unstarred"; if ($profile_owner == local_user()) { - if($toplevelpost) { + if ($toplevelpost) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = array( @@ -782,6 +783,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { intval($item['uid']), intval($item['id']) ); + if (dbm::is_result($r)) { $ignore = array( 'do' => t("ignore thread"), @@ -793,7 +795,7 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { ); } $tagger = ''; - if(feature_enabled($profile_owner,'commtag')) { + if (feature_enabled($profile_owner,'commtag')) { $tagger = array( 'add' => t("add tag"), 'class' => "", @@ -818,19 +820,22 @@ function render_content(&$a, $items, $mode, $update, $preview = false) { $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 + } else { $profile_link = zrl($profile_link); + } // Don't rely on the author-avatar. It is better to use the data from the contact table $author_contact = get_contact_details_by_url($item['author-link'], $profile_owner); - if ($author_contact["thumb"]) + if ($author_contact["thumb"]) { $profile_avatar = $author_contact["thumb"]; - else + } else { $profile_avatar = $item['author-avatar']; + } $like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : ''); $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : ''); diff --git a/mod/delegate.php b/mod/delegate.php index 0ba5dd39c1..94e641068d 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -17,8 +17,9 @@ function delegate_content(&$a) { // delegated admins can view but not change delegation permissions - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { goaway(App::get_baseurl() . '/delegate'); + } $id = $a->argv[2]; @@ -45,8 +46,9 @@ function delegate_content(&$a) { // delegated admins can view but not change delegation permissions - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { goaway(App::get_baseurl() . '/delegate'); + } q("delete from manage where uid = %d and mid = %d limit 1", intval($a->argv[2]), diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 69d708f7fc..6d97899aff 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -661,10 +661,11 @@ function dfrn_confirm_post(&$a,$handsfree = null) { $r = q("SELECT `photo` FROM `contact` WHERE `id` = %d LIMIT 1", intval($dfrn_record)); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $photo = $r[0]['photo']; - else + } else { $photo = App::get_baseurl() . '/images/person-175.jpg'; + } require_once("include/Photo.php"); @@ -673,11 +674,13 @@ function dfrn_confirm_post(&$a,$handsfree = null) { logger('dfrn_confirm: request - photos imported'); $new_relation = CONTACT_IS_SHARING; - if(($relation == CONTACT_IS_FOLLOWER) || ($duplex)) + if (($relation == CONTACT_IS_FOLLOWER) || ($duplex)) { $new_relation = CONTACT_IS_FRIEND; + } - if(($relation == CONTACT_IS_FOLLOWER) && ($duplex)) + if (($relation == CONTACT_IS_FOLLOWER) && ($duplex)) { $duplex = 0; + } $r = q("UPDATE `contact` SET `rel` = %d, @@ -699,7 +702,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { dbesc(NETWORK_DFRN), intval($dfrn_record) ); - if($r === false) { // indicates schema is messed up or total db failure + if ($r === false) { // indicates schema is messed up or total db failure $message = t('Unable to update your contact profile details on our system'); xml_status(3,$message); } diff --git a/mod/events.php b/mod/events.php index 9dbf7efb53..bb9cc3c52e 100644 --- a/mod/events.php +++ b/mod/events.php @@ -336,8 +336,9 @@ function events_content(&$a) { $r = sort_by_date($r); foreach($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); - if(! x($links,$j)) + if(! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; + } } } diff --git a/mod/removeme.php b/mod/removeme.php index 904606fd57..b7043f37bb 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -2,24 +2,29 @@ function removeme_post(&$a) { - if(! local_user()) + if (! local_user()) { return; + } - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { return; + } - if((! x($_POST,'qxz_password')) || (! strlen(trim($_POST['qxz_password'])))) + if ((! x($_POST,'qxz_password')) || (! strlen(trim($_POST['qxz_password'])))) { return; + } - if((! x($_POST,'verify')) || (! strlen(trim($_POST['verify'])))) + if ((! x($_POST,'verify')) || (! strlen(trim($_POST['verify'])))) { return; + } - if($_POST['verify'] !== $_SESSION['remove_account_verify']) + if ($_POST['verify'] !== $_SESSION['remove_account_verify']) { return; + } $encrypted = hash('whirlpool',trim($_POST['qxz_password'])); - if((strlen($a->user['password'])) && ($encrypted === $a->user['password'])) { + if ((strlen($a->user['password'])) && ($encrypted === $a->user['password'])) { require_once('include/Contact.php'); user_remove($a->user['uid']); // NOTREACHED @@ -29,13 +34,14 @@ function removeme_post(&$a) { function removeme_content(&$a) { - if(! local_user()) + if (! local_user()) { goaway(z_root()); + } $hash = random_string(); - require_once("mod/settings.php"); - settings_init($a); + require_once("mod/settings.php"); + settings_init($a); $_SESSION['remove_account_verify'] = $hash; diff --git a/mod/settings.php b/mod/settings.php index e7fd55e944..3ea4d7acf8 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -121,17 +121,18 @@ function settings_post(&$a) { if(! local_user()) return; - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { 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; } $old_page_flags = $a->user['page-flags']; - if(($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')){ + if (($a->argc > 1) && ($a->argv[1] === 'oauth') && x($_POST,'remove')) { check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth'); $key = $_POST['remove']; @@ -142,7 +143,7 @@ function settings_post(&$a) { return; } - if(($a->argc > 2) && ($a->argv[1] === 'oauth') && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) { + if (($a->argc > 2) && ($a->argv[1] === 'oauth') && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST,'submit')) { check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth'); @@ -661,7 +662,7 @@ function settings_content(&$a) { return; } - if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { + if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { notice( t('Permission denied.') . EOL ); return; } diff --git a/object/Item.php b/object/Item.php index 45d2dba3ed..d14b5418cc 100644 --- a/object/Item.php +++ b/object/Item.php @@ -117,15 +117,19 @@ class Item extends BaseObject { ? t('Private Message') : false); $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); - if(local_user() && link_compare($a->contact['url'],$item['author-link'])) { - if ($item["event-id"] != 0) + if (local_user() && link_compare($a->contact['url'],$item['author-link'])) { + if ($item["event-id"] != 0) { $edpost = array("events/event/".$item['event-id'], t("Edit")); - else + } else { $edpost = array("editpost/".$item['id'], t("Edit")); - } else + } + } else { $edpost = false; - if(($this->get_data_value('uid') == local_user()) || $this->is_visiting()) + } + + if (($this->get_data_value('uid') == local_user()) || $this->is_visiting()) { $dropping = true; + } $drop = array( 'dropping' => $dropping, @@ -143,27 +147,31 @@ class Item extends BaseObject { $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 + } else { $profile_link = zrl($profile_link); + } if (!isset($item['author-thumb']) OR ($item['author-thumb'] == "")) { $author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner()); - if ($author_contact["thumb"]) + if ($author_contact["thumb"]) { $item['author-thumb'] = $author_contact["thumb"]; - else + } else { $item['author-thumb'] = $item['author-avatar']; + } } if (!isset($item['owner-thumb']) OR ($item['owner-thumb'] == "")) { $owner_contact = get_contact_details_by_url($item['owner-link'], $conv->get_profile_owner()); - if ($owner_contact["thumb"]) + if ($owner_contact["thumb"]) { $item['owner-thumb'] = $owner_contact["thumb"]; - else + } else { $item['owner-thumb'] = $item['owner-avatar']; + } } $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); From 4dfe64bd5a63ed09c64b087f49eaa5f68aea3edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 10:39:06 +0100 Subject: [PATCH 03/41] Coding convention: - added curly braces - added space between "if" and brace - also added TODO (old-lost code?) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/hcard.php | 5 +++-- mod/noscrape.php | 11 ++++++++--- mod/profile.php | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/mod/hcard.php b/mod/hcard.php index 1231d71e62..3669863447 100644 --- a/mod/hcard.php +++ b/mod/hcard.php @@ -42,10 +42,11 @@ function hcard_init(&$a) { $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : '')); $a->page['htmlhead'] .= '' . "\r\n"; header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); - + $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) + foreach($dfrn_pages as $dfrn) { $a->page['htmlhead'] .= "\r\n"; + } } diff --git a/mod/noscrape.php b/mod/noscrape.php index 289d0499e0..98d491bca6 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -26,6 +26,7 @@ function noscrape_init(&$a) { $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); $keywords = explode(',', $keywords); + /// @TODO This query's result is not being used (see below), maybe old-lost code? $r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d", intval($a->profile['uid'])); @@ -59,12 +60,16 @@ function noscrape_init(&$a) { //These are optional fields. $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'); - foreach($profile_fields as $field) - if(!empty($a->profile[$field])) $json_info["$field"] = $a->profile[$field]; + foreach($profile_fields as $field) { + if(!empty($a->profile[$field])) { + $json_info["$field"] = $a->profile[$field]; + } + } $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) + foreach($dfrn_pages as $dfrn) { $json_info["dfrn-{$dfrn}"] = App::get_baseurl()."/dfrn_{$dfrn}/{$which}"; + } //Output all the JSON! header('Content-type: application/json; charset=utf-8'); diff --git a/mod/profile.php b/mod/profile.php index a4b6183715..20206c7335 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -62,8 +62,9 @@ function profile_init(&$a) { header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) + foreach($dfrn_pages as $dfrn) { $a->page['htmlhead'] .= "\r\n"; + } $a->page['htmlhead'] .= "\r\n"; } From a9bed1422e0a476df17a9e6edefce1925404184d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 10:44:27 +0100 Subject: [PATCH 04/41] added more curyl braces + spaces between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/network.php | 3 ++- include/socgraph.php | 3 ++- mod/dfrn_request.php | 28 +++++++++++++++++----------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/network.php b/include/network.php index cac77fcdf0..7a662e4cbf 100644 --- a/include/network.php +++ b/include/network.php @@ -520,8 +520,9 @@ function avatar_img($email) { call_hooks('avatar_lookup', $avatar); - if(! $avatar['success']) + if (! $avatar['success']) { $avatar['url'] = App::get_baseurl() . '/images/person-175.jpg'; + } logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG); return $avatar['url']; diff --git a/include/socgraph.php b/include/socgraph.php index 6ad276cdda..11dcbf1e72 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -207,8 +207,9 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca $orig_updated = $updated; // The global contacts should contain the original picture, not the cached one - if (($generation != 1) AND stristr(normalise_link($profile_photo), normalise_link(App::get_baseurl()."/photo/"))) + if (($generation != 1) AND stristr(normalise_link($profile_photo), normalise_link(App::get_baseurl()."/photo/"))) { $profile_photo = ""; + } $r = q("SELECT `network` FROM `contact` WHERE `nurl` = '%s' AND `network` != '' AND `network` != '%s' LIMIT 1", dbesc(normalise_link($profile_url)), dbesc(NETWORK_STATUSNET) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 7a8021784d..14ea0fdd4a 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -194,18 +194,21 @@ function dfrn_request_post(&$a) { update_contact_avatar($photo, local_user(), $r[0]["id"], true); $forwardurl = App::get_baseurl()."/contacts/".$r[0]['id']; - } else + } else { $forwardurl = App::get_baseurl()."/contacts"; + } /* * Allow the blocked remote notification to complete */ - if(is_array($contact_record)) + if (is_array($contact_record)) { $dfrn_request = $contact_record['request']; + } - if(strlen($dfrn_request) && strlen($confirm_key)) + if (strlen($dfrn_request) && strlen($confirm_key)) { $s = fetch_url($dfrn_request . '?confirm_key=' . $confirm_key); + } // (ignore reply, nothing we can do it failed) @@ -565,7 +568,7 @@ function dfrn_request_post(&$a) { ); // find the contact record we just created - if($r) { + if ($r) { $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `issued-id` = '%s' LIMIT 1", intval($uid), @@ -579,14 +582,14 @@ function dfrn_request_post(&$a) { } } - if($r === false) { + if ($r === false) { notice( t('Failed to update contact record.') . EOL ); return; } $hash = random_string() . (string) time(); // Generate a confirm_key - if(is_array($contact_record)) { + if (is_array($contact_record)) { $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`) VALUES ( %d, %d, 1, %d, '%s', '%s', '%s' )", intval($uid), @@ -600,8 +603,9 @@ function dfrn_request_post(&$a) { // This notice will only be seen by the requestor if the requestor and requestee are on the same server. - if(! $failed) + if (! $failed) { info( t('Your introduction has been sent.') . EOL ); + } // "Homecoming" - send the requestor back to their site to record the introduction. @@ -633,8 +637,9 @@ function dfrn_request_post(&$a) { $uri .= '/'.$a->get_path(); $uri = urlencode($uri); - } else + } else { $uri = App::get_baseurl().'/profile/'.$nickname; + } $url = str_replace('{uri}', $uri, $url); goaway($url); @@ -651,16 +656,17 @@ function dfrn_request_post(&$a) { function dfrn_request_content(&$a) { - if(($a->argc != 2) || (! count($a->profile))) + if (($a->argc != 2) || (! count($a->profile))) { return ""; + } // "Homecoming". Make sure we're logged in to this site as the correct user. Then offer a confirm button // to send us to the post section to record the introduction. - if(x($_GET,'dfrn_url')) { + if (x($_GET,'dfrn_url')) { - if(! local_user()) { + if (! local_user()) { info( t("Please login to confirm introduction.") . EOL ); /* setup the return URL to come back to this page if they use openid */ $_SESSION['return_url'] = $a->query_string; From 40dc3774e4fad80d8332fb535775dc0a8bfef305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:02:57 +0100 Subject: [PATCH 05/41] Also here (was committed in other branch, too. :-( ) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/events.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mod/events.php b/mod/events.php index bb9cc3c52e..44e6dd4cf0 100644 --- a/mod/events.php +++ b/mod/events.php @@ -191,31 +191,34 @@ function events_content(&$a) { return; } - if($a->argc == 1) + if ($a->argc == 1) { $_SESSION['return_url'] = App::get_baseurl() . '/' . $a->cmd; + } - if(($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) { + if (($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) { $r = q("update event set ignore = 1 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()) ); } - if(($a->argc > 2) && ($a->argv[1] === 'unignore') && intval($a->argv[2])) { + if (($a->argc > 2) && ($a->argv[1] === 'unignore') && intval($a->argv[2])) { $r = q("update event set ignore = 0 where id = %d and uid = %d", intval($a->argv[2]), intval(local_user()) ); } - if ($a->theme_events_in_profile) + if ($a->theme_events_in_profile) { nav_set_selected('home'); - else + } else { nav_set_selected('events'); + } $editselect = 'none'; - if( feature_enabled(local_user(), 'richtext') ) + if ( feature_enabled(local_user(), 'richtext') ) { $editselect = 'textareas'; + } // get the translation strings for the callendar $i18n = get_event_strings(); From 6ab84bf52070642c5f815e87a3794fe7f0522984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:04:29 +0100 Subject: [PATCH 06/41] added curly braces + space between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/group.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mod/group.php b/mod/group.php index c4854a602d..d50b39022a 100644 --- a/mod/group.php +++ b/mod/group.php @@ -28,15 +28,18 @@ function group_post(&$a) { if($r) { info( t('Group created.') . EOL ); $r = group_byname(local_user(),$name); - if($r) + if ($r) { goaway(App::get_baseurl() . '/group/' . $r); + } } - else + else { notice( t('Could not create group.') . EOL ); + } goaway(App::get_baseurl() . '/group'); return; // NOTREACHED } - if(($a->argc == 2) && (intval($a->argv[1]))) { + + if (($a->argc == 2) && (intval($a->argv[1]))) { check_form_security_token_redirectOnErr('/group', 'group_edit'); $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", @@ -50,14 +53,16 @@ function group_post(&$a) { } $group = $r[0]; $groupname = notags(trim($_POST['groupname'])); - if((strlen($groupname)) && ($groupname != $group['name'])) { + if ((strlen($groupname)) && ($groupname != $group['name'])) { $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc($groupname), intval(local_user()), intval($group['id']) ); - if($r) + + if ($r) { info( t('Group name changed.') . EOL ); + } } $a->page['aside'] = group_side(); From e05a8e99749d3518056c93ddcbfc0b2abac78de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:14:30 +0100 Subject: [PATCH 07/41] added curly braces + space between "if" and brace + added TODO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/home.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/mod/home.php b/mod/home.php index 62ee9868fb..0e83340cc3 100644 --- a/mod/home.php +++ b/mod/home.php @@ -6,12 +6,13 @@ function home_init(&$a) { $ret = array(); call_hooks('home_init',$ret); - if(local_user() && ($a->user['nickname'])) + if (local_user() && ($a->user['nickname'])) { goaway(App::get_baseurl()."/network"); - //goaway(App::get_baseurl()."/profile/".$a->user['nickname']); + } - if(strlen(get_config('system','singleuser'))) + if (strlen(get_config('system','singleuser'))) { goaway(App::get_baseurl()."/profile/" . get_config('system','singleuser')); + } }} @@ -21,18 +22,24 @@ function home_content(&$a) { $o = ''; - if(x($_SESSION,'theme')) + if (x($_SESSION,'theme')) { unset($_SESSION['theme']); - if(x($_SESSION,'mobile-theme')) + } + if (x($_SESSION,'mobile-theme')) { unset($_SESSION['mobile-theme']); + } - if(file_exists('home.html')){ - if(file_exists('home.css')){ - $a->page['htmlhead'] .= '';} + /// @TODO No absolute path used, maybe risky (security) + if (file_exists('home.html')) { + if (file_exists('home.css')) { + $a->page['htmlhead'] .= ''; + } - $o .= file_get_contents('home.html');} + $o .= file_get_contents('home.html');} - else $o .= '

'.((x($a->config,'sitename')) ? sprintf(t("Welcome to %s"), $a->config['sitename']) : "").'

'; + else { + $o .= '

'.((x($a->config,'sitename')) ? sprintf(t("Welcome to %s"), $a->config['sitename']) : "").'

'; + } $o .= login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1); From fa444f373c11d84f9c531931103eb61eb09bb106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:18:54 +0100 Subject: [PATCH 08/41] added curly braces + space between "if" and brace + added missing @param MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/item.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/mod/item.php b/mod/item.php index 7bee5f3eae..c22d4448ad 100644 --- a/mod/item.php +++ b/mod/item.php @@ -766,8 +766,9 @@ function item_post(&$a) { } $json = array('cancel' => 1); - if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload'])) + if (x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload'])) { $json['reload'] = App::get_baseurl() . '/' . $_REQUEST['jsreload']; + } echo json_encode($json); killme(); @@ -1049,13 +1050,14 @@ function item_post_return($baseurl, $api_source, $return_path) { if($api_source) return; - if($return_path) { + if ($return_path) { goaway($return_path); } $json = array('success' => 1); - if(x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload'])) + if (x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload'])) { $json['reload'] = $baseurl . '/' . $_REQUEST['jsreload']; + } logger('post_json: ' . print_r($json,true), LOGGER_DEBUG); @@ -1067,15 +1069,16 @@ function item_post_return($baseurl, $api_source, $return_path) { function item_content(&$a) { - if((! local_user()) && (! remote_user())) + if ((! local_user()) && (! remote_user())) { return; + } require_once('include/security.php'); $o = ''; - if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { + if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { $o = drop_item($a->argv[2], !is_ajax()); - if (is_ajax()){ + if (is_ajax()) { // ajax return: [, 0 (no perm) | ] echo json_encode(array(intval($a->argv[2]), intval($o))); killme(); @@ -1088,6 +1091,7 @@ function item_content(&$a) { * This function removes the tag $tag from the text $body and replaces it with * the appropiate link. * + * @param App $a Application instance @TODO is unused in this function's scope (excluding included files) * @param unknown_type $body the text to replace the tag in * @param string $inform a comma-seperated string containing everybody to inform * @param string $str_tags string to add the tag to @@ -1105,13 +1109,14 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $r = null; //is it a person tag? - if(strpos($tag,'@') === 0) { + if (strpos($tag,'@') === 0) { //is it already replaced? - if(strpos($tag,'[url=')) { + if (strpos($tag,'[url=')) { //append tag to str_tags - if(!stristr($str_tags,$tag)) { - if(strlen($str_tags)) + if (!stristr($str_tags,$tag)) { + if (strlen($str_tags)) { $str_tags .= ','; + } $str_tags .= $tag; } From fd0e2a9406fb343077c322ea3c47957a5dc68ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:21:32 +0100 Subject: [PATCH 09/41] added curly braces + space between "if" and brace + initialized $result (was only within if() block but not outside of it) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/group.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mod/group.php b/mod/group.php index d50b39022a..da5f4df521 100644 --- a/mod/group.php +++ b/mod/group.php @@ -104,26 +104,32 @@ function group_content(&$a) { } - if(($a->argc == 3) && ($a->argv[1] === 'drop')) { + if (($a->argc == 3) && ($a->argv[1] === 'drop')) { check_form_security_token_redirectOnErr('/group', 'group_drop', 't'); - if(intval($a->argv[2])) { + if (intval($a->argv[2])) { $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), intval(local_user()) ); - if (dbm::is_result($r)) + + $result = null; + + if (dbm::is_result($r)) { $result = group_rmv(local_user(),$r[0]['name']); - if($result) + } + + if ($result) { info( t('Group removed.') . EOL); - else + } else { notice( t('Unable to remove group.') . EOL); + } } goaway(App::get_baseurl() . '/group'); // NOTREACHED } - if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { + if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { check_form_security_token_ForbiddenOnErr('group_member_change', 't'); $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1", @@ -134,7 +140,7 @@ function group_content(&$a) { $change = intval($a->argv[2]); } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { require_once('include/acl_selectors.php'); $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", From 4780df394dbc3a85c6e12530d42f6599f4dc5c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:27:40 +0100 Subject: [PATCH 10/41] added curly braces + space between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder Conflicts: mod/notify.php --- mod/notify.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mod/notify.php b/mod/notify.php index 092639735d..88f5fa5429 100644 --- a/mod/notify.php +++ b/mod/notify.php @@ -3,10 +3,13 @@ require_once('include/NotificationsManager.php'); function notify_init(&$a) { - if(! local_user()) return; + if (! local_user()) { + return; + } + $nm = new NotificationsManager(); - - if($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) { + + if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) { $note = $nm->getByID($a->argv[2]); if ($note) { $nm->setSeen($note); @@ -17,8 +20,9 @@ function notify_init(&$a) { $urldata = parse_url($note['link']); $guid = basename($urldata["path"]); $itemdata = get_item_id($guid, local_user()); - if ($itemdata["id"] != 0) + if ($itemdata["id"] != 0) { $note['link'] = App::get_baseurl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"]; + } } goaway($note['link']); @@ -27,7 +31,7 @@ function notify_init(&$a) { goaway(App::get_baseurl(true)); } - if($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all' ) { + if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all' ) { $r = $nm->setAllSeen(); $j = json_encode(array('result' => ($r) ? 'success' : 'fail')); echo $j; @@ -37,7 +41,9 @@ function notify_init(&$a) { } function notify_content(&$a) { - if(! local_user()) return login(); + if (! local_user()) { + return login(); + } $nm = new NotificationsManager(); From 2e908ebbbf916fd838906bdc1398955605cb097a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:33:04 +0100 Subject: [PATCH 11/41] added more curly braces + fixed space->tab for code indentation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/videos.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mod/videos.php b/mod/videos.php index 92e5fe5548..d0c9c97ddf 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -106,13 +106,17 @@ function videos_post(&$a) { $owner_uid = $a->data['user']['uid']; - if (local_user() != $owner_uid) goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']); + if (local_user() != $owner_uid) { + goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']); + } - if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) { + if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) { // Check if we should do HTML-based delete confirmation if(!x($_REQUEST,'confirm')) { - if(x($_REQUEST,'canceled')) goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']); + if (x($_REQUEST,'canceled')) { + goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']); + } $drop_url = $a->query_string; $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array( @@ -149,7 +153,7 @@ function videos_post(&$a) { dbesc($video_id), intval(local_user()) ); - #echo "
"; var_dump($i); killme();
+			//echo "
"; var_dump($i); killme();
 			if(count($i)) {
 				q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
 					dbesc(datetime_convert()),
@@ -172,7 +176,7 @@ function videos_post(&$a) {
 		return; // NOTREACHED
 	}
 
-    goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
+	goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
 
 }
 

From f3529e7dbcad8af388764938230b1e864359fa83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 11:36:03 +0100
Subject: [PATCH 12/41] added spaces + curly braces
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 include/notifier.php  |  2 +-
 include/socgraph.php  | 14 +++++++-------
 mod/profile_photo.php |  6 ++++--
 mod/profiles.php      |  3 ++-
 mod/redir.php         |  8 +++++---
 mod/regmod.php        |  3 ++-
 mod/settings.php      |  3 ++-
 7 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/include/notifier.php b/include/notifier.php
index 8823834c1d..9e1450ba2b 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -558,7 +558,7 @@ function notifier_run(&$argv, &$argc){
 	if($slap && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) {
 		if(!get_config('system','dfrn_only')) {
 			foreach($url_recipients as $url) {
-				if($url) {
+				if ($url) {
 					logger('notifier: urldelivery: ' . $url);
 					$deliver_status = slapper($owner,$url,$slap);
 					/// @TODO Redeliver/queue these items on failure, though there is no contact record
diff --git a/include/socgraph.php b/include/socgraph.php
index 11dcbf1e72..6e53f2ae72 100644
--- a/include/socgraph.php
+++ b/include/socgraph.php
@@ -93,19 +93,19 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
 
 		if(isset($entry->urls)) {
 			foreach($entry->urls as $url) {
-				if($url->type == 'profile') {
+				if ($url->type == 'profile') {
 					$profile_url = $url->value;
 					continue;
 				}
-				if($url->type == 'webfinger') {
+				if ($url->type == 'webfinger') {
 					$connect_url = str_replace('acct:' , '', $url->value);
 					continue;
 				}
 			}
 		}
-		if(isset($entry->photos)) {
+		if (isset($entry->photos)) {
 			foreach($entry->photos as $photo) {
-				if($photo->type == 'profile') {
+				if ($photo->type == 'profile') {
 					$profile_photo = $photo->value;
 					continue;
 				}
@@ -1334,7 +1334,7 @@ function poco_discover_server_users($data, $server) {
 		$username = "";
 		if (isset($entry->urls)) {
 			foreach($entry->urls as $url)
-				if($url->type == 'profile') {
+				if ($url->type == 'profile') {
 					$profile_url = $url->value;
 					$urlparts = parse_url($profile_url);
 					$username = end(explode("/", $urlparts["path"]));
@@ -1378,11 +1378,11 @@ function poco_discover_server($data, $default_generation = 0) {
 
 		if(isset($entry->urls)) {
 			foreach($entry->urls as $url) {
-				if($url->type == 'profile') {
+				if ($url->type == 'profile') {
 					$profile_url = $url->value;
 					continue;
 				}
-				if($url->type == 'webfinger') {
+				if ($url->type == 'webfinger') {
 					$connect_url = str_replace('acct:' , '', $url->value);
 					continue;
 				}
diff --git a/mod/profile_photo.php b/mod/profile_photo.php
index 371effd0cb..70ea45afa4 100644
--- a/mod/profile_photo.php
+++ b/mod/profile_photo.php
@@ -124,8 +124,9 @@ function profile_photo_post(&$a) {
 				info( t('Shift-reload the page or clear browser cache if the new photo does not display immediately.') . EOL);
 				// Update global directory in background
 				$url = App::get_baseurl() . '/profile/' . $a->user['nickname'];
-				if($url && strlen(get_config('system','directory')))
+				if ($url && strlen(get_config('system','directory'))) {
 					proc_run(PRIORITY_LOW, "include/directory.php", $url);
+				}
 
 				require_once('include/profile_update.php');
 				profile_change();
@@ -223,8 +224,9 @@ function profile_photo_content(&$a) {
 
 			// Update global directory in background
 			$url = $_SESSION['my_url'];
-			if($url && strlen(get_config('system','directory')))
+			if ($url && strlen(get_config('system','directory'))) {
 				proc_run(PRIORITY_LOW, "include/directory.php", $url);
+			}
 
 			goaway(App::get_baseurl() . '/profiles');
 			return; // NOTREACHED
diff --git a/mod/profiles.php b/mod/profiles.php
index 53372f83d2..5aa41c90d8 100644
--- a/mod/profiles.php
+++ b/mod/profiles.php
@@ -502,8 +502,9 @@ function profiles_post(&$a) {
 
 			// Update global directory in background
 			$url = $_SESSION['my_url'];
-			if($url && strlen(get_config('system','directory')))
+			if ($url && strlen(get_config('system','directory'))) {
 				proc_run(PRIORITY_LOW, "include/directory.php", $url);
+			}
 
 			require_once('include/profile_update.php');
 			profile_change();
diff --git a/mod/redir.php b/mod/redir.php
index 5dc5ad3724..762d373d53 100644
--- a/mod/redir.php
+++ b/mod/redir.php
@@ -63,12 +63,14 @@ function redir_init(&$a) {
 			. '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet );
 	}
 
-	if(local_user())
+	if (local_user()) {
 		$handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3);
-	if(remote_user())
+	}
+	if (remote_user()) {
 		$handle = $_SESSION['handle'];
+	}
 
-	if($url) {
+	if ($url) {
 		$url = str_replace('{zid}','&zid=' . $handle,$url);
 		goaway($url);
 	}
diff --git a/mod/regmod.php b/mod/regmod.php
index 56d91364f5..92433b6d82 100644
--- a/mod/regmod.php
+++ b/mod/regmod.php
@@ -36,8 +36,9 @@ function user_allow($hash) {
 	);
 	if (dbm::is_result($r) && $r[0]['net-publish']) {
 		$url = App::get_baseurl() . '/profile/' . $user[0]['nickname'];
-		if($url && strlen(get_config('system','directory')))
+		if ($url && strlen(get_config('system','directory'))) {
 			proc_run(PRIORITY_LOW, "include/directory.php", $url);
+		}
 	}
 
 	push_lang($register[0]['language']);
diff --git a/mod/settings.php b/mod/settings.php
index 3ea4d7acf8..2998b5dfac 100644
--- a/mod/settings.php
+++ b/mod/settings.php
@@ -629,8 +629,9 @@ function settings_post(&$a) {
 	if(($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) {
 		// Update global directory in background
 		$url = $_SESSION['my_url'];
-		if($url && strlen(get_config('system','directory')))
+		if ($url && strlen(get_config('system','directory'))) {
 			proc_run(PRIORITY_LOW, "include/directory.php", $url);
+		}
 	}
 
 	require_once('include/profile_update.php');

From fc9dbc0899aed223378be677356cd74e722dfd14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Tue, 20 Dec 2016 11:38:16 +0100
Subject: [PATCH 13/41] added spaces + curly braces
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 include/conversation.php |  6 ++++--
 include/email.php        | 19 +++++++++++++------
 include/socgraph.php     |  7 ++++---
 include/text.php         |  2 +-
 mod/randprof.php         |  6 +++++-
 5 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/include/conversation.php b/include/conversation.php
index 916a9e229e..ccfc070d4e 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -324,11 +324,13 @@ function localize_item(&$item){
 	// add sparkle links to appropriate permalinks
 
 	$x = stristr($item['plink'],'/display/');
-	if($x) {
+	if ($x) {
 		$sparkle = false;
 		$y = best_link_url($item,$sparkle,true);
-		if(strstr($y,'/redir/'))
+
+		if (strstr($y,'/redir/')) {
 			$item['plink'] = $y . '?f=&url=' . $item['plink'];
+		}
 	}
 
 
diff --git a/include/email.php b/include/email.php
index 2c05d3233f..42f80c2427 100644
--- a/include/email.php
+++ b/include/email.php
@@ -96,15 +96,20 @@ function email_get_msg($mbox,$uid, $reply) {
 		$html = '';
 		foreach($struc->parts as $ptop => $p) {
 			$x = email_get_part($mbox,$uid,$p,$ptop + 1, 'plain');
-			if($x)	$text .= $x;
+			if ($x) {
+				$text .= $x;
+			}
 
 			$x = email_get_part($mbox,$uid,$p,$ptop + 1, 'html');
-			if($x)	$html .= $x;
+			if ($x) {
+				$html .= $x;
+			}
 		}
-		if (trim($html) != '')
+		if (trim($html) != '') {
 			$ret['body'] = html2bbcode($html);
-		else
+		} else {
 			$ret['body'] = $text;
+		}
 	}
 
 	$ret['body'] = removegpg($ret['body']);
@@ -112,8 +117,9 @@ function email_get_msg($mbox,$uid, $reply) {
 	$ret['body'] = $msg['body'];
 	$ret['body'] = convertquote($ret['body'], $reply);
 
-	if (trim($html) != '')
+	if (trim($html) != '') {
 		$ret['body'] = removelinebreak($ret['body']);
+	}
 
 	$ret['body'] = unifyattributionline($ret['body']);
 
@@ -189,8 +195,9 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) {
 		$x = "";
 		foreach ($p->parts as $partno0=>$p2) {
 			$x .=  email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1), $subtype);  // 1.2, 1.2.1, etc.
-			//if($x)
+			//if ($x) {
 			//	return $x;
+			//}
 		}
 		return $x;
 	}
diff --git a/include/socgraph.php b/include/socgraph.php
index 6e53f2ae72..5960764f9e 100644
--- a/include/socgraph.php
+++ b/include/socgraph.php
@@ -1188,16 +1188,17 @@ function update_suggestions() {
 
 	if(strlen(get_config('system','directory'))) {
 		$x = fetch_url(get_server()."/pubsites");
-		if($x) {
+		if ($x) {
 			$j = json_decode($x);
-			if($j->entries) {
+			if ($j->entries) {
 				foreach($j->entries as $entry) {
 
 					poco_check_server($entry->url);
 
 					$url = $entry->url . '/poco';
-					if(! in_array($url,$done))
+					if (! in_array($url,$done)) {
 						poco_load(0,0,0,$entry->url . '/poco');
+					}
 				}
 			}
 		}
diff --git a/include/text.php b/include/text.php
index 05801d024c..e174aa3753 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1367,7 +1367,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
 	// map
 	if(strpos($s,'
') !== false && $item['coord']) { $x = generate_map(trim($item['coord'])); - if($x) { + if ($x) { $s = preg_replace('/\
/','$0' . $x,$s); } } diff --git a/mod/randprof.php b/mod/randprof.php index 877bf818b9..b208eeef29 100644 --- a/mod/randprof.php +++ b/mod/randprof.php @@ -3,8 +3,12 @@ function randprof_init(&$a) { require_once('include/Contact.php'); + $x = random_profile(); - if($x) + + if ($x) { goaway(zrl($x)); + } + goaway(App::get_baseurl() . '/profile'); } From 5f41375ad35006e17ed60513b1581a593b59d233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:39:53 +0100 Subject: [PATCH 14/41] Continued: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - added curly braces + spaces - added todo about testing empty/non-empty strings Signed-off-by: Roland Häder --- mod/settings.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/settings.php b/mod/settings.php index 2998b5dfac..b4546d8bff 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -824,8 +824,10 @@ function settings_content(&$a) { $settings_connectors .= mini_group_select(local_user(), $default_group, t("Default group for OStatus contacts")); - if ($legacy_contact != "") + /// @TODO Found to much different usage to test empty/non-empty strings (e.g. empty(), trim() == '' ) which is wanted? + if ($legacy_contact != "") { $a->page['htmlhead'] = ''; + } $settings_connectors .= '
'; $settings_connectors .= ''; From ace8f753ac81caaf3385c4c37b58551a8b10fdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 11:56:34 +0100 Subject: [PATCH 15/41] added much more curly braces + space between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder Conflicts: mod/bookmarklet.php mod/community.php mod/contacts.php mod/crepair.php mod/events.php mod/network.php mod/suggest.php mod/uexport.php view/theme/duepuntozero/config.php view/theme/frio/config.php view/theme/quattro/config.php view/theme/vier/config.php --- doc/themes.md | 3 +- include/acl_selectors.php | 5 +- include/contact_widgets.php | 15 ++++-- include/group.php | 2 +- mod/allfriends.php | 11 ++-- mod/api.php | 4 +- mod/bookmarklet.php | 2 +- mod/community.php | 2 +- mod/contactgroup.php | 2 +- mod/contacts.php | 15 +++--- mod/content.php | 2 +- mod/crepair.php | 9 ++-- mod/delegate.php | 2 +- mod/dirfind.php | 2 +- mod/editpost.php | 6 +-- mod/events.php | 8 +-- mod/filer.php | 2 +- mod/filerm.php | 2 +- mod/follow.php | 4 +- mod/fsuggest.php | 7 +-- mod/group.php | 4 +- mod/ignored.php | 14 +++-- mod/invite.php | 4 +- mod/manage.php | 5 +- mod/match.php | 3 +- mod/message.php | 4 +- mod/mood.php | 5 +- mod/network.php | 4 +- mod/nogroup.php | 8 +-- mod/notes.php | 5 +- mod/notifications.php | 4 +- mod/oexchange.php | 4 +- mod/ostatus_subscribe.php | 2 +- mod/poke.php | 14 +++-- mod/profile_photo.php | 6 +-- mod/profiles.php | 9 ++-- mod/profperm.php | 5 +- mod/qsearch.php | 3 +- mod/regmod.php | 11 ++-- mod/repair_ostatus.php | 2 +- mod/settings.php | 7 +-- mod/starred.php | 9 ++-- mod/suggest.php | 11 ++-- mod/tagrm.php | 8 +-- mod/uexport.php | 5 +- mod/viewsrc.php | 2 +- view/theme/duepuntozero/config.php | 85 ++++++++++++++++-------------- view/theme/frio/config.php | 9 +++- view/theme/quattro/config.php | 18 ++++--- view/theme/vier/config.php | 15 ++++-- 50 files changed, 225 insertions(+), 165 deletions(-) diff --git a/doc/themes.md b/doc/themes.md index add44c776b..0d3c6eb3d6 100644 --- a/doc/themes.md +++ b/doc/themes.md @@ -124,8 +124,9 @@ The selected 1st part will be saved in the database by the theme_post function. function theme_post(&$a){ // non local users shall not pass - if(! local_user()) + if (! local_user()) { return; + } // if the one specific submit button was pressed then proceed if (isset($_POST['duepuntozero-settings-submit'])){ // and save the selection key into the personal config of the user diff --git a/include/acl_selectors.php b/include/acl_selectors.php index ed9c634c23..2be0303049 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -392,8 +392,9 @@ function construct_acl_data(&$a, $user) { function acl_lookup(&$a, $out_type = 'json') { - if(!local_user()) - return ""; + if (!local_user()) { + return ''; + } $start = (x($_REQUEST,'start') ? $_REQUEST['start'] : 0); $count = (x($_REQUEST,'count') ? $_REQUEST['count'] : 100); diff --git a/include/contact_widgets.php b/include/contact_widgets.php index a74080e75b..71a75d431e 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -80,11 +80,13 @@ function networks_widget($baseurl,$selected = '') { $a = get_app(); - if(!local_user()) + if (!local_user()) { return ''; + } - if(!feature_enabled(local_user(),'networks')) + if (!feature_enabled(local_user(),'networks')) { return ''; + } $extra_sql = unavailable_networks(); @@ -116,15 +118,18 @@ function networks_widget($baseurl,$selected = '') { } function fileas_widget($baseurl,$selected = '') { - if(! local_user()) + if (! local_user()) { return ''; + } - if(! feature_enabled(local_user(),'filing')) + if (! feature_enabled(local_user(),'filing')) { return ''; + } $saved = get_pconfig(local_user(),'system','filetags'); - if(! strlen($saved)) + if (! strlen($saved)) { return; + } $matches = false; $terms = array(); diff --git a/include/group.php b/include/group.php index 67712aae7c..a2a55c4440 100644 --- a/include/group.php +++ b/include/group.php @@ -234,7 +234,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro $o = ''; - if(! local_user()) + if (! local_user()) return ''; $groups = array(); diff --git a/mod/allfriends.php b/mod/allfriends.php index e4f067eaf7..420bd8690f 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -8,16 +8,18 @@ require_once('mod/contacts.php'); function allfriends_content(&$a) { $o = ''; - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } - if($a->argc > 1) + if ($a->argc > 1) { $cid = intval($a->argv[1]); + } - if(! $cid) + if (! $cid) { return; + } $uid = $a->user[uid]; @@ -26,7 +28,8 @@ function allfriends_content(&$a) { intval(local_user()) ); - if(! count($c)) + if (! count($c)) { + } return; $a->page['aside'] = ""; diff --git a/mod/api.php b/mod/api.php index 406ef26c1c..caa1cba2a6 100644 --- a/mod/api.php +++ b/mod/api.php @@ -22,7 +22,7 @@ function oauth_get_client($request){ function api_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } @@ -84,7 +84,7 @@ function api_content(&$a) { } - if(! local_user()) { + if (! local_user()) { /// @TODO We need login form to redirect to this page notice( t('Please login to continue.') . EOL ); return login(false,$request->get_parameters()); diff --git a/mod/bookmarklet.php b/mod/bookmarklet.php index cb8320013f..86a73a7884 100644 --- a/mod/bookmarklet.php +++ b/mod/bookmarklet.php @@ -8,7 +8,7 @@ function bookmarklet_init(&$a) { } function bookmarklet_content(&$a) { - if(!local_user()) { + if (!local_user()) { $o = '

'.t('Login').'

'; $o .= login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true); return $o; diff --git a/mod/community.php b/mod/community.php index c8f04d8bd6..d7fd2bb933 100644 --- a/mod/community.php +++ b/mod/community.php @@ -1,7 +1,7 @@ argv[1]==="batch") { contacts_batch_actions($a); @@ -147,15 +149,16 @@ function contacts_post(&$a) { } $contact_id = intval($a->argv[1]); - if(! $contact_id) + if (! $contact_id) { return; + } $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval(local_user()) ); - if(! count($orig_record)) { + if (! count($orig_record)) { notice( t('Could not access contact record.') . EOL); goaway('contacts'); return; // NOTREACHED @@ -164,7 +167,7 @@ function contacts_post(&$a) { call_hooks('contact_edit_post', $_POST); $profile_id = intval($_POST['profile-assign']); - if($profile_id) { + if ($profile_id) { $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($profile_id), intval(local_user()) @@ -346,7 +349,7 @@ function contacts_content(&$a) { nav_set_selected('contacts'); - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/content.php b/mod/content.php index 1a3fb10952..2377032a79 100644 --- a/mod/content.php +++ b/mod/content.php @@ -23,7 +23,7 @@ function content_content(&$a, $update = 0) { // Currently security is based on the logged in user - if(! local_user()) { + if (! local_user()) { return; } diff --git a/mod/crepair.php b/mod/crepair.php index 66faadb06a..59b92df0a7 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -3,8 +3,9 @@ require_once("include/contact_selectors.php"); require_once("mod/contacts.php"); function crepair_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $contact_id = 0; @@ -29,10 +30,10 @@ function crepair_init(&$a) { } } - function crepair_post(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); @@ -97,7 +98,7 @@ function crepair_post(&$a) { function crepair_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/delegate.php b/mod/delegate.php index 94e641068d..3bd1c85ed7 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -8,7 +8,7 @@ function delegate_init(&$a) { function delegate_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/dirfind.php b/mod/dirfind.php index 1e3f6f354a..8cb0e1a083 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -7,7 +7,7 @@ require_once('mod/contacts.php'); function dirfind_init(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL ); return; } diff --git a/mod/editpost.php b/mod/editpost.php index eccd498d15..54b50bc36d 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -6,14 +6,14 @@ function editpost_content(&$a) { $o = ''; - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if(! $post_id) { + if (! $post_id) { notice( t('Item not found') . EOL); return; } @@ -23,7 +23,7 @@ function editpost_content(&$a) { intval(local_user()) ); - if(! count($itm)) { + if (! count($itm)) { notice( t('Item not found') . EOL); return; } diff --git a/mod/events.php b/mod/events.php index 44e6dd4cf0..a20934222f 100644 --- a/mod/events.php +++ b/mod/events.php @@ -9,8 +9,9 @@ require_once('include/event.php'); require_once('include/items.php'); function events_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } if($a->argc == 1) { // if it's a json request abort here becaus we don't @@ -33,8 +34,9 @@ function events_post(&$a) { logger('post: ' . print_r($_REQUEST,true)); - if(! local_user()) + if (! local_user()) { return; + } $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0); $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0); @@ -186,7 +188,7 @@ function events_post(&$a) { function events_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/filer.php b/mod/filer.php index 4e79f337dc..eac3260591 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -7,7 +7,7 @@ require_once('include/items.php'); function filer_content(&$a) { - if(! local_user()) { + if (! local_user()) { killme(); } diff --git a/mod/filerm.php b/mod/filerm.php index c266082c8f..2f504b80fb 100644 --- a/mod/filerm.php +++ b/mod/filerm.php @@ -2,7 +2,7 @@ function filerm_content(&$a) { - if(! local_user()) { + if (! local_user()) { killme(); } diff --git a/mod/follow.php b/mod/follow.php index 1f56caea50..f805296790 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -7,7 +7,7 @@ require_once('include/contact_selectors.php'); function follow_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); goaway($_SESSION['return_url']); // NOTREACHED @@ -151,7 +151,7 @@ function follow_content(&$a) { function follow_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); goaway($_SESSION['return_url']); // NOTREACHED diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 4370952ca1..66871653dd 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -3,12 +3,13 @@ function fsuggest_post(&$a) { - if(! local_user()) { + if (! local_user()) { return; } - if($a->argc != 2) + if ($a->argc != 2) { return; + } $contact_id = intval($a->argv[1]); @@ -74,7 +75,7 @@ function fsuggest_content(&$a) { require_once('include/acl_selectors.php'); - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/group.php b/mod/group.php index da5f4df521..8a744d1e11 100644 --- a/mod/group.php +++ b/mod/group.php @@ -15,7 +15,7 @@ function group_init(&$a) { function group_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } @@ -73,7 +73,7 @@ function group_post(&$a) { function group_content(&$a) { $change = false; - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied') . EOL); return; } diff --git a/mod/ignored.php b/mod/ignored.php index 4aeeb21e6b..5e8411e376 100644 --- a/mod/ignored.php +++ b/mod/ignored.php @@ -5,12 +5,15 @@ function ignored_init(&$a) { $ignored = 0; - if(! local_user()) + if (! local_user()) { killme(); - if($a->argc > 1) + } + if ($a->argc > 1) { $message_id = intval($a->argv[1]); - if(! $message_id) + } + if (! $message_id) { killme(); + } $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", intval(local_user()), @@ -20,8 +23,9 @@ function ignored_init(&$a) { killme(); } - if(! intval($r[0]['ignored'])) + if (! intval($r[0]['ignored'])) { $ignored = 1; + } $r = q("UPDATE `thread` SET `ignored` = %d WHERE `uid` = %d and `iid` = %d", intval($ignored), @@ -31,7 +35,7 @@ function ignored_init(&$a) { // See if we've been passed a return path to redirect to $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); - if($return_path) { + if ($return_path) { $rand = '_=' . time(); if(strpos($return_path, '?')) $rand = "&$rand"; else $rand = "?$rand"; diff --git a/mod/invite.php b/mod/invite.php index 5964acac43..ae08c387eb 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -11,7 +11,7 @@ require_once('include/email.php'); function invite_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } @@ -97,7 +97,7 @@ function invite_post(&$a) { function invite_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/manage.php b/mod/manage.php index 2138595bee..bb9dfc313c 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -5,8 +5,9 @@ require_once("include/text.php"); function manage_post(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $uid = local_user(); $orig_record = $a->user; @@ -93,7 +94,7 @@ function manage_post(&$a) { function manage_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/match.php b/mod/match.php index 69bf3c1101..6eb24338c2 100644 --- a/mod/match.php +++ b/mod/match.php @@ -16,8 +16,9 @@ require_once('mod/proxy.php'); function match_content(&$a) { $o = ''; - if(! local_user()) + if (! local_user()) { return; + } $a->page['aside'] .= findpeople_widget(); $a->page['aside'] .= follow_widget(); diff --git a/mod/message.php b/mod/message.php index b0d0ba95ca..f926352590 100644 --- a/mod/message.php +++ b/mod/message.php @@ -42,7 +42,7 @@ function message_init(&$a) { function message_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } @@ -178,7 +178,7 @@ function message_content(&$a) { $o = ''; nav_set_selected('messages'); - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/mood.php b/mod/mood.php index e378b9d0a4..ec318f85fd 100644 --- a/mod/mood.php +++ b/mod/mood.php @@ -7,8 +7,9 @@ require_once('include/items.php'); function mood_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $uid = local_user(); $verb = notags(trim($_GET['verb'])); @@ -110,7 +111,7 @@ function mood_init(&$a) { function mood_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/network.php b/mod/network.php index c040a547a4..ba97148009 100644 --- a/mod/network.php +++ b/mod/network.php @@ -1,6 +1,6 @@ query_string; return login(false); } diff --git a/mod/nogroup.php b/mod/nogroup.php index 0a014c0676..f2a5a3b33b 100644 --- a/mod/nogroup.php +++ b/mod/nogroup.php @@ -6,14 +6,16 @@ require_once('include/contact_selectors.php'); function nogroup_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } require_once('include/group.php'); require_once('include/contact_widgets.php'); - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) { $a->page['aside'] = ''; + } $a->page['aside'] .= group_side('contacts','group','extended',0,$contact_id); } @@ -21,7 +23,7 @@ function nogroup_init(&$a) { function nogroup_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return ''; } diff --git a/mod/notes.php b/mod/notes.php index 74ab18a6f9..d9222dca51 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -2,8 +2,9 @@ function notes_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $profile = 0; @@ -18,7 +19,7 @@ function notes_init(&$a) { function notes_content(&$a,$update = false) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/notifications.php b/mod/notifications.php index 3e0bd9cc47..4c56453350 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -11,7 +11,7 @@ require_once("include/network.php"); function notifications_post(&$a) { - if(! local_user()) { + if (! local_user()) { goaway(z_root()); } @@ -67,7 +67,7 @@ function notifications_post(&$a) { function notifications_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/oexchange.php b/mod/oexchange.php index b25c418e4c..6eb380dff4 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -16,12 +16,12 @@ function oexchange_init(&$a) { function oexchange_content(&$a) { - if(! local_user()) { + if (! local_user()) { $o = login(false); return $o; } - if(($a->argc > 1) && $a->argv[1] === 'done') { + if (($a->argc > 1) && $a->argv[1] === 'done') { info( t('Post successful.') . EOL); return; } diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 2e09bfc0d6..963f436939 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -5,7 +5,7 @@ require_once('include/follow.php'); function ostatus_subscribe_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); goaway($_SESSION['return_url']); // NOTREACHED diff --git a/mod/poke.php b/mod/poke.php index fea5c0c0d8..af8eed35a0 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -21,25 +21,29 @@ require_once('include/items.php'); function poke_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $uid = local_user(); $verb = notags(trim($_GET['verb'])); - if(! $verb) + if (! $verb) { return; + } $verbs = get_poke_verbs(); - if(! array_key_exists($verb,$verbs)) + if (! array_key_exists($verb,$verbs)) { return; + } $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]); $contact_id = intval($_GET['cid']); - if(! $contact_id) + if (! $contact_id) { return; + } $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0); @@ -146,7 +150,7 @@ function poke_init(&$a) { function poke_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 70ea45afa4..2aca9801d2 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -4,7 +4,7 @@ require_once("include/Photo.php"); function profile_photo_init(&$a) { - if(! local_user()) { + if (! local_user()) { return; } @@ -15,7 +15,7 @@ function profile_photo_init(&$a) { function profile_photo_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice ( t('Permission denied.') . EOL ); return; } @@ -172,7 +172,7 @@ function profile_photo_post(&$a) { if(! function_exists('profile_photo_content')) { function profile_photo_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL ); return; } diff --git a/mod/profiles.php b/mod/profiles.php index 5aa41c90d8..4e29b93fd2 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -6,7 +6,7 @@ function profiles_init(&$a) { nav_set_selected('profiles'); - if(! local_user()) { + if (! local_user()) { return; } @@ -162,7 +162,7 @@ function profile_clean_keywords($keywords) { function profiles_post(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } @@ -595,14 +595,15 @@ function profile_activity($changed, $value) { $arr['deny_gid'] = $a->user['deny_gid']; $i = item_store($arr); - if($i) + if ($i) { proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i); + } } function profiles_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/profperm.php b/mod/profperm.php index aa610d3a93..0a4b3e9a47 100644 --- a/mod/profperm.php +++ b/mod/profperm.php @@ -2,8 +2,9 @@ function profperm_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } $which = $a->user['nickname']; $profile = $a->argv[1]; @@ -15,7 +16,7 @@ function profperm_init(&$a) { function profperm_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied') . EOL); return; } diff --git a/mod/qsearch.php b/mod/qsearch.php index a440ea708f..b976e1a585 100644 --- a/mod/qsearch.php +++ b/mod/qsearch.php @@ -2,8 +2,9 @@ function qsearch_init(&$a) { - if(! local_user()) + if (! local_user()) { killme(); + } $limit = (get_config('system','qsearch_limit') ? intval(get_config('system','qsearch_limit')) : 100); diff --git a/mod/regmod.php b/mod/regmod.php index 92433b6d82..34d29a77ce 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -101,32 +101,33 @@ function regmod_content(&$a) { $_SESSION['return_url'] = $a->cmd; - if(! local_user()) { + if (! local_user()) { info( t('Please login.') . EOL); $o .= '

' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1); return $o; } - if((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) { + if ((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) { notice( t('Permission denied.') . EOL); return ''; } - if($a->argc != 3) + if ($a->argc != 3) { killme(); + } $cmd = $a->argv[1]; $hash = $a->argv[2]; - if($cmd === 'deny') { + if ($cmd === 'deny') { user_deny($hash); goaway(App::get_baseurl()."/admin/users/"); killme(); } - if($cmd === 'allow') { + if ($cmd === 'allow') { user_allow($hash); goaway(App::get_baseurl()."/admin/users/"); killme(); diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php index 7a454a4ae0..ba8a071756 100755 --- a/mod/repair_ostatus.php +++ b/mod/repair_ostatus.php @@ -5,7 +5,7 @@ require_once('include/follow.php'); function repair_ostatus_content(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); goaway($_SESSION['return_url']); // NOTREACHED diff --git a/mod/settings.php b/mod/settings.php index b4546d8bff..e67ea9bc6a 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -18,7 +18,7 @@ function get_theme_config_file($theme){ function settings_init(&$a) { - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL ); return; } @@ -118,8 +118,9 @@ function settings_init(&$a) { function settings_post(&$a) { - if(! local_user()) + if (! local_user()) { return; + } if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { return; @@ -658,7 +659,7 @@ function settings_content(&$a) { $o = ''; nav_set_selected('settings'); - if(! local_user()) { + if (! local_user()) { #notice( t('Permission denied.') . EOL ); return; } diff --git a/mod/starred.php b/mod/starred.php index 0e5e75d167..7ee531e447 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -7,12 +7,15 @@ function starred_init(&$a) { $starred = 0; - if(! local_user()) + if (! local_user()) { killme(); - if($a->argc > 1) + } + if ($a->argc > 1) { $message_id = intval($a->argv[1]); - if(! $message_id) + } + if (! $message_id) { killme(); + } $r = q("SELECT starred FROM item WHERE uid = %d AND id = %d LIMIT 1", intval(local_user()), diff --git a/mod/suggest.php b/mod/suggest.php index 73f5ffe4b2..a328b9768b 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -5,12 +5,13 @@ require_once('include/contact_widgets.php'); function suggest_init(&$a) { - if(! local_user()) + if (! local_user()) { return; + } - if(x($_GET,'ignore') && intval($_GET['ignore'])) { + if (x($_GET,'ignore') && intval($_GET['ignore'])) { // 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); @@ -35,7 +36,7 @@ function suggest_init(&$a) { return; } // Now check how the user responded to the confirmation query - if(!$_REQUEST['canceled']) { + if (!$_REQUEST['canceled']) { q("INSERT INTO `gcign` ( `uid`, `gcid` ) VALUES ( %d, %d ) ", intval(local_user()), intval($_GET['ignore']) @@ -54,7 +55,7 @@ function suggest_content(&$a) { require_once("mod/proxy.php"); $o = ''; - if(! local_user()) { + if (! local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/tagrm.php b/mod/tagrm.php index d6e57d36a9..c39b4ba51e 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -4,7 +4,7 @@ require_once('include/bbcode.php'); function tagrm_post(&$a) { - if(! local_user()) + if (! local_user()) goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); @@ -52,7 +52,7 @@ function tagrm_content(&$a) { $o = ''; - if(! local_user()) { + if (! local_user()) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); // NOTREACHED } @@ -63,7 +63,6 @@ function tagrm_content(&$a) { // NOTREACHED } - $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval(local_user()) @@ -75,8 +74,9 @@ function tagrm_content(&$a) { $arr = explode(',', $r[0]['tag']); - if(! count($arr)) + if (! count($arr)) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); + } $o .= '

' . t('Remove Item Tag') . '

'; diff --git a/mod/uexport.php b/mod/uexport.php index d9bd5ae01e..140f19a59b 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -1,11 +1,12 @@ t('default'), - 'greenzero'=>t('greenzero'), - 'purplezero'=>t('purplezero'), - 'easterbunny'=>t('easterbunny'), - 'darkzero'=>t('darkzero'), - 'comix'=>t('comix'), - 'slackr'=>t('slackr'), - ); - if ($user) { - $color = get_pconfig(local_user(), 'duepuntozero', 'colorset'); - } else { - $color = get_config( 'duepuntozero', 'colorset'); - } - $t = get_markup_template("theme_settings.tpl" ); - $o .= replace_macros($t, array( - '$submit' => t('Submit'), - '$baseurl' => App::get_baseurl(), - '$title' => t("Theme settings"), - '$colorset' => array('duepuntozero_colorset', t('Variations'), $color, '', $colorset), - )); - return $o; + $colorset = array( + 'default'=>t('default'), + 'greenzero'=>t('greenzero'), + 'purplezero'=>t('purplezero'), + 'easterbunny'=>t('easterbunny'), + 'darkzero'=>t('darkzero'), + 'comix'=>t('comix'), + 'slackr'=>t('slackr'), + ); + + if ($user) { + $color = get_pconfig(local_user(), 'duepuntozero', 'colorset'); + } else { + $color = get_config( 'duepuntozero', 'colorset'); + } + + $t = get_markup_template("theme_settings.tpl" ); + /// @TODO No need for adding string here, $o is not defined + $o .= replace_macros($t, array( + '$submit' => t('Submit'), + '$baseurl' => App::get_baseurl(), + '$title'=> t("Theme settings"), + '$colorset' => array('duepuntozero_colorset', t('Variations'), $color, '', $colorset), + )); + + return $o; } diff --git a/view/theme/frio/config.php b/view/theme/frio/config.php index 589f1591a0..edd16bd71f 100644 --- a/view/theme/frio/config.php +++ b/view/theme/frio/config.php @@ -2,7 +2,9 @@ require_once('view/theme/frio/php/Image.php'); function theme_content(&$a) { - if(!local_user()) { return;} + if (!local_user()) { + return; + } $arr = array(); $arr["schema"] = get_pconfig(local_user(),'frio', 'schema'); @@ -18,7 +20,10 @@ function theme_content(&$a) { } function theme_post(&$a) { - if(!local_user()) { return;} + if (!local_user()) { + return; + } + if (isset($_POST['frio-settings-submit'])) { set_pconfig(local_user(), 'frio', 'schema', $_POST["frio_schema"]); set_pconfig(local_user(), 'frio', 'nav_bg', $_POST["frio_nav_bg"]); diff --git a/view/theme/quattro/config.php b/view/theme/quattro/config.php index 2a32b9f05a..9a08adbaf9 100644 --- a/view/theme/quattro/config.php +++ b/view/theme/quattro/config.php @@ -6,21 +6,23 @@ function theme_content(&$a){ - if(!local_user()) - return; - + if (!local_user()) { + return; + } + $align = get_pconfig(local_user(), 'quattro', 'align' ); $color = get_pconfig(local_user(), 'quattro', 'color' ); - $tfs = get_pconfig(local_user(),"quattro","tfs"); - $pfs = get_pconfig(local_user(),"quattro","pfs"); - + $tfs = get_pconfig(local_user(),"quattro","tfs"); + $pfs = get_pconfig(local_user(),"quattro","pfs"); + return quattro_form($a,$align, $color, $tfs, $pfs); } function theme_post(&$a){ - if(! local_user()) + if (! local_user()) { return; - + } + if (isset($_POST['quattro-settings-submit'])){ set_pconfig(local_user(), 'quattro', 'align', $_POST['quattro_align']); set_pconfig(local_user(), 'quattro', 'color', $_POST['quattro_color']); diff --git a/view/theme/vier/config.php b/view/theme/vier/config.php index 0f07ff9a1e..2989f6c5cf 100644 --- a/view/theme/vier/config.php +++ b/view/theme/vier/config.php @@ -6,19 +6,23 @@ function theme_content(&$a){ - if(!local_user()) + if (!local_user()) { return; + } - if (!function_exists('get_vier_config')) + if (!function_exists('get_vier_config')) { return; + } $style = get_pconfig(local_user(), 'vier', 'style'); - if ($style == "") + if ($style == "") { $style = get_config('vier', 'style'); + } - if ($style == "") + if ($style == "") { $style = "plus"; + } $show_pages = get_vier_config('show_pages', true); $show_profiles = get_vier_config('show_profiles', true); @@ -32,8 +36,9 @@ function theme_content(&$a){ } function theme_post(&$a){ - if(! local_user()) + if (! local_user()) { return; + } if (isset($_POST['vier-settings-submit'])){ set_pconfig(local_user(), 'vier', 'style', $_POST['vier_style']); From a25b628286e6e0c00facb99a44e9fc4efd377536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 12:35:18 +0100 Subject: [PATCH 16/41] added curly braces + space between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/tagrm.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mod/tagrm.php b/mod/tagrm.php index c39b4ba51e..acdbd6a9c2 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -4,12 +4,13 @@ require_once('include/bbcode.php'); function tagrm_post(&$a) { - if (! local_user()) + if (! local_user()) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); + } - - if((x($_POST,'submit')) && ($_POST['submit'] === t('Cancel'))) + if ((x($_POST,'submit')) && ($_POST['submit'] === t('Cancel'))) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); + } $tag = ((x($_POST,'tag')) ? hex2bin(notags(trim($_POST['tag']))) : ''); $item = ((x($_POST,'item')) ? intval($_POST['item']) : 0 ); @@ -24,8 +25,8 @@ function tagrm_post(&$a) { } $arr = explode(',', $r[0]['tag']); - for($x = 0; $x < count($arr); $x ++) { - if($arr[$x] === $tag) { + for ($x = 0; $x < count($arr); $x ++) { + if ($arr[$x] === $tag) { unset($arr[$x]); break; } From a883514604937d26a2c77b2763b496ced95b4403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 12:36:51 +0100 Subject: [PATCH 17/41] Opps, forgot this ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/toggle_mobile.php | 10 ++++++---- view/theme/frost-mobile/theme.php | 6 ++++-- view/theme/frost/theme.php | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mod/toggle_mobile.php b/mod/toggle_mobile.php index dbf0eb0f13..8ef2b9fc4d 100644 --- a/mod/toggle_mobile.php +++ b/mod/toggle_mobile.php @@ -2,15 +2,17 @@ function toggle_mobile_init(&$a) { - if(isset($_GET['off'])) + if (isset($_GET['off'])) { $_SESSION['show-mobile'] = false; - else + } else { $_SESSION['show-mobile'] = true; + } - if(isset($_GET['address'])) + if (isset($_GET['address'])) { $address = $_GET['address']; - else + } else { $address = App::get_baseurl(); + } goaway($address); } diff --git a/view/theme/frost-mobile/theme.php b/view/theme/frost-mobile/theme.php index 24d5e9e52e..ceb28c2d66 100644 --- a/view/theme/frost-mobile/theme.php +++ b/view/theme/frost-mobile/theme.php @@ -22,11 +22,13 @@ function frost_mobile_content_loaded(&$a) { // I could do this in style.php, but by having the CSS in a file the browser will cache it, // making pages load faster - if( $a->module === 'home' || $a->module === 'login' || $a->module === 'register' || $a->module === 'lostpass' ) { + if ( $a->module === 'home' || $a->module === 'login' || $a->module === 'register' || $a->module === 'lostpass' ) { // $a->page['htmlhead'] = str_replace('$stylesheet', App::get_baseurl() . '/view/theme/frost-mobile/login-style.css', $a->page['htmlhead']); $a->theme['stylesheet'] = App::get_baseurl() . '/view/theme/frost-mobile/login-style.css'; } - if( $a->module === 'login' ) + + if ( $a->module === 'login' ) { $a->page['end'] .= ''; + } } diff --git a/view/theme/frost/theme.php b/view/theme/frost/theme.php index 464c14d470..b93123b3dd 100644 --- a/view/theme/frost/theme.php +++ b/view/theme/frost/theme.php @@ -24,8 +24,10 @@ function frost_content_loaded(&$a) { //$a->page['htmlhead'] = str_replace('$stylesheet', App::get_baseurl() . '/view/theme/frost/login-style.css', $a->page['htmlhead']); $a->theme['stylesheet'] = App::get_baseurl() . '/view/theme/frost/login-style.css'; } - if( $a->module === 'login' ) + + if ( $a->module === 'login' ) { $a->page['end'] .= ''; + } } From b69d82e64c8a0622823b99d0b8754a213a989dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 12:36:51 +0100 Subject: [PATCH 18/41] Continued a bit: - added more curly braces around conditional blocks - added space between "if" and brace - aligned "=>" (will do with more if wanted) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/videos.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mod/videos.php b/mod/videos.php index d0c9c97ddf..53bba84c6e 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -380,12 +380,12 @@ function videos_content(&$a) { $videos[] = array( 'id' => $rr['id'], - 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'], - 'title' => t('View Video'), - 'src' => App::get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0', - 'alt' => $alt_e, - 'mime' => $rr['filetype'], - 'album' => array( + 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'], + 'title' => t('View Video'), + 'src' => App::get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0', + 'alt' => $alt_e, + 'mime' => $rr['filetype'], + 'album' => array( 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']), 'name' => $name_e, 'alt' => t('View Album'), @@ -397,11 +397,11 @@ function videos_content(&$a) { $tpl = get_markup_template('videos_recent.tpl'); $o .= replace_macros($tpl, array( - '$title' => t('Recent Videos'), - '$can_post' => $can_post, - '$upload' => array(t('Upload New Videos'), App::get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'), - '$videos' => $videos, - '$delete_url' => (($can_post)?App::get_baseurl().'/videos/'.$a->data['user']['nickname']:False) + '$title' => t('Recent Videos'), + '$can_post' => $can_post, + '$upload' => array(t('Upload New Videos'), App::get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'), + '$videos' => $videos, + '$delete_url' => (($can_post)?App::get_baseurl().'/videos/'.$a->data['user']['nickname']:False) )); From 4f26bee453fc252d8a0e20c5fab4522ae0e9d752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 12:45:16 +0100 Subject: [PATCH 19/41] Changed $a->get_baseurl() to App::get_baseurl() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- boot.php | 6 +++--- index.php | 10 +++++----- mod/filerm.php | 2 +- mod/follow.php | 6 +++--- mod/help.php | 2 +- mod/match.php | 6 +++--- mod/redir.php | 2 +- mod/removeme.php | 2 +- mod/subthread.php | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/boot.php b/boot.php index c500468e5f..dec4eca32b 100644 --- a/boot.php +++ b/boot.php @@ -1548,9 +1548,9 @@ function check_url(&$a) { // We will only change the url to an ip address if there is no existing setting if(! x($url)) - $url = set_config('system','url',$a->get_baseurl()); - if((! link_compare($url,$a->get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) - $url = set_config('system','url',$a->get_baseurl()); + $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))) + $url = set_config('system','url',App::get_baseurl()); return; } diff --git a/index.php b/index.php index 08f24af60f..39e8c583a0 100644 --- a/index.php +++ b/index.php @@ -60,15 +60,15 @@ if(!$install) { if ($a->max_processes_reached() OR $a->maxload_reached()) { header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable'); header('Retry-After: 120'); - header('Refresh: 120; url='.$a->get_baseurl()."/".$a->query_string); + header('Refresh: 120; url='.App::get_baseurl()."/".$a->query_string); die("System is currently unavailable. Please try again later"); } if (get_config('system','force_ssl') AND ($a->get_scheme() == "http") AND (intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND - (substr($a->get_baseurl(), 0, 8) == "https://")) { + (substr(App::get_baseurl(), 0, 8) == "https://")) { header("HTTP/1.1 302 Moved Temporarily"); - header("Location: ".$a->get_baseurl()."/".$a->query_string); + header("Location: ".App::get_baseurl()."/".$a->query_string); exit(); } @@ -150,7 +150,7 @@ if((x($_GET,'zrl')) && (!$install && !$maintenance)) { * */ -// header('Link: <' . $a->get_baseurl() . '/amcd>; rel="acct-mgmt";'); +// header('Link: <' . App::get_baseurl() . '/amcd>; rel="acct-mgmt";'); if(x($_COOKIE["Friendica"]) || (x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login')) require("include/auth.php"); @@ -281,7 +281,7 @@ if(strlen($a->module)) { if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']); - goaway($a->get_baseurl() . $_SERVER['REQUEST_URI']); + goaway(App::get_baseurl() . $_SERVER['REQUEST_URI']); } logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] . ' ADDRESS: ' . $_SERVER['REMOTE_ADDR'] . ' QUERY: ' . $_SERVER['QUERY_STRING'], LOGGER_DEBUG); diff --git a/mod/filerm.php b/mod/filerm.php index 2f504b80fb..c8bf8658be 100644 --- a/mod/filerm.php +++ b/mod/filerm.php @@ -21,7 +21,7 @@ function filerm_content(&$a) { file_tag_unsave_file(local_user(),$item_id,$term, $category); if(x($_SESSION,'return_url')) - goaway($a->get_baseurl() . '/' . $_SESSION['return_url']); + goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); killme(); } diff --git a/mod/follow.php b/mod/follow.php index f805296790..8f8c73c90c 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -63,7 +63,7 @@ function follow_content(&$a) { $request = $ret["request"]; $tpl = get_markup_template('dfrn_request.tpl'); } else { - $request = $a->get_baseurl()."/follow"; + $request = App::get_baseurl()."/follow"; $tpl = get_markup_template('auto_request.tpl'); } @@ -175,12 +175,12 @@ function follow_post(&$a) { notice($result['message']); goaway($return_url); } elseif ($result['cid']) - goaway($a->get_baseurl().'/contacts/'.$result['cid']); + goaway(App::get_baseurl().'/contacts/'.$result['cid']); info( t('Contact added').EOL); if(strstr($return_url,'contacts')) - goaway($a->get_baseurl().'/contacts/'.$contact_id); + goaway(App::get_baseurl().'/contacts/'.$contact_id); goaway($return_url); // NOTREACHED diff --git a/mod/help.php b/mod/help.php index 7222569279..0512e0f2e0 100644 --- a/mod/help.php +++ b/mod/help.php @@ -77,7 +77,7 @@ function help_content(&$a) { if ($level>$lastlevel) $toc.="
    "; $idnum[$level]++; $id = implode("_", array_slice($idnum,1,$level)); - $href = $a->get_baseurl()."/help/{$filename}#{$id}"; + $href = App::get_baseurl()."/help/{$filename}#{$id}"; $toc .= "
  • ".strip_tags($line)."
  • "; $line = "".$line; $lastlevel = $level; diff --git a/mod/match.php b/mod/match.php index 6eb24338c2..a9535d2d66 100644 --- a/mod/match.php +++ b/mod/match.php @@ -23,7 +23,7 @@ function match_content(&$a) { $a->page['aside'] .= findpeople_widget(); $a->page['aside'] .= follow_widget(); - $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd; + $_SESSION['return_url'] = App::get_baseurl() . '/' . $a->cmd; $r = q("SELECT `pub_keywords`, `prv_keywords` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval(local_user()) @@ -47,7 +47,7 @@ function match_content(&$a) { if(strlen(get_config('system','directory'))) $x = post_url(get_server().'/msearch', $params); else - $x = post_url($a->get_baseurl() . '/msearch', $params); + $x = post_url(App::get_baseurl() . '/msearch', $params); $j = json_decode($x); @@ -68,7 +68,7 @@ function match_content(&$a) { if (!count($match)) { $jj->photo = str_replace("http:///photo/", get_server()."/photo/", $jj->photo); - $connlnk = $a->get_baseurl() . '/follow/?url=' . $jj->url; + $connlnk = App::get_baseurl() . '/follow/?url=' . $jj->url; $photo_menu = array( 'profile' => array(t("View Profile"), zrl($jj->url)), 'follow' => array(t("Connect/Follow"), $connlnk) diff --git a/mod/redir.php b/mod/redir.php index 762d373d53..be5e0c5933 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -64,7 +64,7 @@ function redir_init(&$a) { } if (local_user()) { - $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3); + $handle = $a->user['nickname'] . '@' . substr(App::get_baseurl(),strpos(App::get_baseurl(),'://')+3); } if (remote_user()) { $handle = $_SESSION['handle']; diff --git a/mod/removeme.php b/mod/removeme.php index b7043f37bb..6920cbc187 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -47,7 +47,7 @@ function removeme_content(&$a) { $tpl = get_markup_template('removeme.tpl'); $o .= replace_macros($tpl, array( - '$basedir' => $a->get_baseurl(), + '$basedir' => App::get_baseurl(), '$hash' => $hash, '$title' => t('Remove My Account'), '$desc' => t('This will completely remove your account. Once this has been done it is not recoverable.'), diff --git a/mod/subthread.php b/mod/subthread.php index 66072bcc88..7e2632c687 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -87,7 +87,7 @@ function subthread_content(&$a) { $post_type = (($item['resource-id']) ? t('photo') : t('status')); $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); - $link = xmlify('' . "\n") ; + $link = xmlify('' . "\n") ; $body = $item['body']; $obj = <<< EOT @@ -128,7 +128,7 @@ EOT; $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; - $plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; + $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink ); $arr['verb'] = $activity; From 1f93024ed63492497c74d287007f1faa5a13084e Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 20 Dec 2016 07:08:03 +0000 Subject: [PATCH 20/41] Workaround for vanished database connections while authentication --- include/auth_ejabberd.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/include/auth_ejabberd.php b/include/auth_ejabberd.php index e12da35ef1..8ee3af8e2b 100755 --- a/include/auth_ejabberd.php +++ b/include/auth_ejabberd.php @@ -159,14 +159,19 @@ class exAuth { $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]); $this->writeDebugLog("[debug] checking isuser for ". $sUser."@".$aCommand[2]); - // If the hostnames doesn't match, we try to check remotely - if ($a->get_hostname() != $aCommand[2]) - $found = $this->check_user($aCommand[2], $aCommand[1], true); - else { + // Does the hostname match? So we try directly + if ($a->get_hostname() == $aCommand[2]) { $sQuery = "SELECT `uid` FROM `user` WHERE `nickname`='".dbesc($sUser)."'"; $this->writeDebugLog("[debug] using query ". $sQuery); $r = q($sQuery); $found = dbm::is_result($r); + } else { + $found = false; + } + + // If the hostnames doesn't match or there is some failure, we try to check remotely + if (!$found) { + $found = $this->check_user($aCommand[2], $aCommand[1], true); } if ($found) { @@ -227,10 +232,8 @@ class exAuth { $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]); $this->writeDebugLog("[debug] doing auth for ".$sUser."@".$aCommand[2]); - // If the hostnames doesn't match, we try to authenticate remotely - if ($a->get_hostname() != $aCommand[2]) - $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true); - else { + // Does the hostname match? So we try directly + if ($a->get_hostname() == $aCommand[2]) { $sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='".dbesc($sUser)."'"; $this->writeDebugLog("[debug] using query ". $sQuery); if ($oResult = q($sQuery)) { @@ -246,6 +249,13 @@ class exAuth { $this->writeLog("[exAuth] got password ".$oConfig[0]["v"]); $Error = ($aCommand[3] != $oConfig[0]["v"]); } + } else { + $Error = true; + } + + // If the hostnames doesn't match or there is some failure, we try to check remotely + if ($Error) { + $Error = !$this->check_credentials($aCommand[2], $aCommand[1], $aCommand[3], true); } if ($Error) { From 4aafbb09a539069b6e07673208d107c83ff0e1ab Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 20 Dec 2016 07:10:47 +0000 Subject: [PATCH 21/41] The object type "photo" is deprecated and was replaced by "image" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder Conflicts: include/like.php mod/photos.php mod/subthread.php --- include/diaspora.php | 2 +- include/like.php | 2 +- mod/photos.php | 4 ++-- mod/subthread.php | 2 +- mod/tagger.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 94c6ccfb8d..3b4832e74f 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2290,7 +2290,7 @@ class diaspora { $body = "[img]".unxmlify($photo->remote_photo_path). unxmlify($photo->remote_photo_name)."[/img]\n".$body; - $datarray["object-type"] = ACTIVITY_OBJ_PHOTO; + $datarray["object-type"] = ACTIVITY_OBJ_IMAGE; } else { $datarray["object-type"] = ACTIVITY_OBJ_NOTE; diff --git a/include/like.php b/include/like.php index 8223cf3626..b04b9b4e09 100644 --- a/include/like.php +++ b/include/like.php @@ -164,7 +164,7 @@ function do_like($item_id, $verb) { $post_type = (($item['resource-id']) ? t('photo') : t('status')); if($item['object-type'] === ACTIVITY_OBJ_EVENT) $post_type = t('event'); - $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; diff --git a/mod/photos.php b/mod/photos.php index 5b402746a9..c60f8dd496 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -681,7 +681,7 @@ function photos_post(&$a) { $arr['visible'] = 1; $arr['verb'] = ACTIVITY_TAG; $arr['object-type'] = ACTIVITY_OBJ_PERSON; - $arr['target-type'] = ACTIVITY_OBJ_PHOTO; + $arr['target-type'] = ACTIVITY_OBJ_IMAGE; $arr['tag'] = $tagged[4]; $arr['inform'] = $tagged[2]; $arr['origin'] = 1; @@ -694,7 +694,7 @@ function photos_post(&$a) { $arr['object'] .= xmlify('' . "\n"); $arr['object'] .= '' . "\n"; - $arr['target'] = '' . ACTIVITY_OBJ_PHOTO . '' . $p[0]['desc'] . '' + $arr['target'] = '' . ACTIVITY_OBJ_IMAGE . '' . $p[0]['desc'] . '' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ''; $arr['target'] .= '' . xmlify('' . "\n" . '') . ''; diff --git a/mod/subthread.php b/mod/subthread.php index 7e2632c687..81cb1fcc11 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -86,7 +86,7 @@ function subthread_content(&$a) { $uri = item_new_uri($a->get_hostname(),$owner_uid); $post_type = (($item['resource-id']) ? t('photo') : t('status')); - $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; diff --git a/mod/tagger.php b/mod/tagger.php index d44288ef0a..4055edddbd 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -60,7 +60,7 @@ function tagger_content(&$a) { $uri = item_new_uri($a->get_hostname(),$owner_uid); $xterm = xmlify($term); $post_type = (($item['resource-id']) ? t('photo') : t('status')); - $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; From d72673b1624908279d0a79a20888577ddfb5d9d1 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 20 Dec 2016 07:13:22 +0000 Subject: [PATCH 22/41] Only distribute items to active contacts --- include/notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/notifier.php b/include/notifier.php index 9e1450ba2b..d78db4055d 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -576,7 +576,7 @@ function notifier_run(&$argv, &$argc){ $r0 = array(); $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s' - AND `uid` = %d AND `rel` != %d group by `batch` ORDER BY rand() ", + AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()", dbesc(NETWORK_DIASPORA), intval($owner['uid']), intval(CONTACT_IS_SHARING) From 361a55155c5b439c5a527647bd22356560c867a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 16:21:59 +0100 Subject: [PATCH 23/41] Don't cherry-pick: reverted unrelated changes (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/Core/Config.php | 2 +- include/Core/PConfig.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Core/Config.php b/include/Core/Config.php index 5235728864..7b7045a9ee 100644 --- a/include/Core/Config.php +++ b/include/Core/Config.php @@ -97,7 +97,7 @@ class Config { dbesc($family), dbesc($key) ); - if (dbm::is_result($ret)) { + if (count($ret)) { // manage array value $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); $a->config[$family][$key] = $val; diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 49b69a1f7a..43735018e4 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -92,7 +92,7 @@ class PConfig { dbesc($key) ); - if (dbm::is_result($ret)) { + if (count($ret)) { $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); $a->config[$uid][$family][$key] = $val; From 4805aa8fdb51bbfa58e8dafb5579846ded7bb1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 16:28:23 +0100 Subject: [PATCH 24/41] Don't cherry-pick: - reverted dbm::is_result() to count() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/dfrn_confirm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 6d97899aff..2eca28b95d 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -584,7 +584,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { dbesc($decrypted_source_url), intval($local_uid) ); - if(! dbm::is_result($ret)) { + if(! count($ret)) { if(strstr($decrypted_source_url,'http:')) $newurl = str_replace('http:','https:',$decrypted_source_url); else @@ -594,7 +594,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { dbesc($newurl), intval($local_uid) ); - if(! dbm::is_result($ret)) { + if(! count($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); From de689583e2741a2caee0e266a19a07d1ad4ed043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 17:43:46 +0100 Subject: [PATCH 25/41] added more curly braces + space between "if" and brace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder Conflicts: mod/admin.php --- boot.php | 15 +++++---- include/follow.php | 20 +++++++----- include/salmon.php | 21 ++++++------ include/security.php | 28 ++++++++-------- include/socgraph.php | 77 ++++++++++++++++++++++++++------------------ index.php | 39 ++++++++++++---------- mod/admin.php | 73 +++++++++++++++++++++-------------------- mod/allfriends.php | 2 +- mod/cal.php | 2 +- mod/delegate.php | 4 +-- mod/dfrn_confirm.php | 9 +++--- mod/dfrn_request.php | 39 +++++++++++++--------- mod/dirfind.php | 36 +++++++++++++-------- mod/events.php | 22 +++++++------ mod/settings.php | 5 +-- 15 files changed, 225 insertions(+), 167 deletions(-) diff --git a/boot.php b/boot.php index dec4eca32b..aab3498146 100644 --- a/boot.php +++ b/boot.php @@ -670,22 +670,23 @@ class App { #set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path()); - if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") { + if ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") { $this->query_string = substr($_SERVER['QUERY_STRING'],9); // removing trailing / - maybe a nginx problem if (substr($this->query_string, 0, 1) == "/") $this->query_string = substr($this->query_string, 1); - } elseif((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") { + } elseif ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") { $this->query_string = substr($_SERVER['QUERY_STRING'],2); // removing trailing / - maybe a nginx problem if (substr($this->query_string, 0, 1) == "/") $this->query_string = substr($this->query_string, 1); } - if (x($_GET,'pagename')) + if (x($_GET,'pagename')) { $this->cmd = trim($_GET['pagename'],'/\\'); - elseif (x($_GET,'q')) + } elseif (x($_GET,'q')) { $this->cmd = trim($_GET['q'],'/\\'); + } // fix query_string @@ -694,13 +695,15 @@ class App { // unix style "homedir" - if(substr($this->cmd,0,1) === '~') + if (substr($this->cmd,0,1) === '~') { $this->cmd = 'profile/' . substr($this->cmd,1); + } // Diaspora style profile url - if(substr($this->cmd,0,2) === 'u/') + if (substr($this->cmd,0,2) === 'u/') { $this->cmd = 'profile/' . substr($this->cmd,2); + } /* diff --git a/include/follow.php b/include/follow.php index e67beb84c2..15e8dd28d8 100644 --- a/include/follow.php +++ b/include/follow.php @@ -77,12 +77,12 @@ function new_contact($uid,$url,$interactive = false) { $url = str_replace('/#!/','/',$url); - if(! allowed_url($url)) { + if (! allowed_url($url)) { $result['message'] = t('Disallowed profile URL.'); return $result; } - if(! $url) { + if (! $url) { $result['message'] = t('Connect URL missing.'); return $result; } @@ -91,17 +91,21 @@ function new_contact($uid,$url,$interactive = false) { call_hooks('follow', $arr); - if(x($arr['contact'],'name')) + if (x($arr['contact'],'name')) { $ret = $arr['contact']; - else + } + else { $ret = probe_url($url); + } - if($ret['network'] === NETWORK_DFRN) { - if($interactive) { - if(strlen($a->path)) + if ($ret['network'] === NETWORK_DFRN) { + if ($interactive) { + if (strlen($a->path)) { $myaddr = bin2hex(App::get_baseurl() . '/profile/' . $a->user['nickname']); - else + } + else { $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); + } goaway($ret['request'] . "&addr=$myaddr"); diff --git a/include/salmon.php b/include/salmon.php index c5c3d72237..2b58334704 100644 --- a/include/salmon.php +++ b/include/salmon.php @@ -24,22 +24,24 @@ function get_salmon_key($uri,$keyhash) { // We have found at least one key URL // If it's inline, parse it - otherwise get the key - if(count($ret) > 0) { - for($x = 0; $x < count($ret); $x ++) { - if(substr($ret[$x],0,5) === 'data:') { - if(strstr($ret[$x],',')) + if (count($ret) > 0) { + for ($x = 0; $x < count($ret); $x ++) { + if (substr($ret[$x],0,5) === 'data:') { + if (strstr($ret[$x],',')) { $ret[$x] = substr($ret[$x],strpos($ret[$x],',')+1); - else + } else { $ret[$x] = substr($ret[$x],5); - } elseif (normalise_link($ret[$x]) == 'http://') + } + } elseif (normalise_link($ret[$x]) == 'http://') { $ret[$x] = fetch_url($ret[$x]); + } } } logger('Key located: ' . print_r($ret,true)); - if(count($ret) == 1) { + if (count($ret) == 1) { // We only found one one key so we don't care if the hash matches. // If it's the wrong key we'll find out soon enough because @@ -50,10 +52,11 @@ function get_salmon_key($uri,$keyhash) { return $ret[0]; } else { - foreach($ret as $a) { + foreach ($ret as $a) { $hash = base64url_encode(hash('sha256',$a)); - if($hash == $keyhash) + if ($hash == $keyhash) { return $a; + } } } diff --git a/include/security.php b/include/security.php index 7e14146d94..cd00b5f7b0 100644 --- a/include/security.php +++ b/include/security.php @@ -94,11 +94,12 @@ function authenticate_success($user_record, $login_initial = false, $interactive } - if($login_initial) { + if ($login_initial) { call_hooks('logged_in', $a->user); - if(($a->module !== 'home') && isset($_SESSION['return_url'])) + if (($a->module !== 'home') && isset($_SESSION['return_url'])) { goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); + } } } @@ -109,16 +110,17 @@ function can_write_wall(&$a,$owner) { static $verified = 0; - if((! (local_user())) && (! (remote_user()))) + if ((! (local_user())) && (! (remote_user()))) { return false; + } $uid = local_user(); - if(($uid) && ($uid == $owner)) { + if (($uid) && ($uid == $owner)) { return true; } - if(remote_user()) { + if (remote_user()) { // use remembered decision and avoid a DB lookup for each and every display item // DO NOT use this function if there are going to be multiple owners @@ -126,25 +128,25 @@ function can_write_wall(&$a,$owner) { // We have a contact-id for an authenticated remote user, this block determines if the contact // belongs to this page owner, and has the necessary permissions to post content - if($verified === 2) + if ($verified === 2) { return true; - elseif($verified === 1) + } elseif ($verified === 1) { return false; - else { + } else { $cid = 0; - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $visitor) { - if($visitor['uid'] == $owner) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $visitor) { + if ($visitor['uid'] == $owner) { $cid = $visitor['cid']; break; } } } - if(! $cid) + if (! $cid) { return false; - + } $r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `user`.`uid` = `contact`.`uid` WHERE `contact`.`uid` = %d AND `contact`.`id` = %d AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 diff --git a/include/socgraph.php b/include/socgraph.php index 5960764f9e..135d759bfd 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -91,8 +91,8 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { $name = $entry->displayName; - if(isset($entry->urls)) { - foreach($entry->urls as $url) { + if (isset($entry->urls)) { + foreach ($entry->urls as $url) { if ($url->type == 'profile') { $profile_url = $url->value; continue; @@ -104,7 +104,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { } } if (isset($entry->photos)) { - foreach($entry->photos as $photo) { + foreach ($entry->photos as $photo) { if ($photo->type == 'profile') { $profile_photo = $photo->value; continue; @@ -112,29 +112,37 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { } } - if(isset($entry->updated)) + if (isset($entry->updated)) { $updated = date("Y-m-d H:i:s", strtotime($entry->updated)); + } - if(isset($entry->network)) + if (isset($entry->network)) { $network = $entry->network; + } - if(isset($entry->currentLocation)) + if (isset($entry->currentLocation)) { $location = $entry->currentLocation; + } - if(isset($entry->aboutMe)) + if (isset($entry->aboutMe)) { $about = html2bbcode($entry->aboutMe); + } - if(isset($entry->gender)) + if (isset($entry->gender)) { $gender = $entry->gender; + } - if(isset($entry->generation) AND ($entry->generation > 0)) + if (isset($entry->generation) AND ($entry->generation > 0)) { $generation = ++$entry->generation; + } - if(isset($entry->tags)) - foreach($entry->tags as $tag) + if (isset($entry->tags)) { + foreach($entry->tags as $tag) { $keywords = implode(", ", $tag); + } + } - if(isset($entry->contactType) AND ($entry->contactType >= 0)) + if (isset($entry->contactType) AND ($entry->contactType >= 0)) $contact_type = $entry->contactType; // If you query a Friendica server for its profiles, the network has to be Friendica @@ -171,8 +179,6 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { function poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid = 0, $uid = 0, $zcid = 0) { - $a = get_app(); - // Generation: // 0: No definition // 1: Profiles on this server @@ -1186,12 +1192,12 @@ function update_suggestions() { $done[] = App::get_baseurl() . '/poco'; - if(strlen(get_config('system','directory'))) { + if (strlen(get_config('system','directory'))) { $x = fetch_url(get_server()."/pubsites"); if ($x) { $j = json_decode($x); if ($j->entries) { - foreach($j->entries as $entry) { + foreach ($j->entries as $entry) { poco_check_server($entry->url); @@ -1210,7 +1216,7 @@ function update_suggestions() { ); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $base = substr($rr['poco'],0,strrpos($rr['poco'],'/')); if(! in_array($base,$done)) poco_load(0,0,0,$base); @@ -1221,7 +1227,7 @@ function update_suggestions() { function poco_discover_federation() { $last = get_config('poco','last_federation_discovery'); - if($last) { + if ($last) { $next = $last + (24 * 60 * 60); if($next > time()) return; @@ -1377,7 +1383,7 @@ function poco_discover_server($data, $default_generation = 0) { $name = $entry->displayName; - if(isset($entry->urls)) { + if (isset($entry->urls)) { foreach($entry->urls as $url) { if ($url->type == 'profile') { $profile_url = $url->value; @@ -1390,39 +1396,48 @@ function poco_discover_server($data, $default_generation = 0) { } } - if(isset($entry->photos)) { - foreach($entry->photos as $photo) { - if($photo->type == 'profile') { + if (isset($entry->photos)) { + foreach ($entry->photos as $photo) { + if ($photo->type == 'profile') { $profile_photo = $photo->value; continue; } } } - if(isset($entry->updated)) + if (isset($entry->updated)) { $updated = date("Y-m-d H:i:s", strtotime($entry->updated)); + } - if(isset($entry->network)) + if(isset($entry->network)) { $network = $entry->network; + } - if(isset($entry->currentLocation)) + if(isset($entry->currentLocation)) { $location = $entry->currentLocation; + } - if(isset($entry->aboutMe)) + if(isset($entry->aboutMe)) { $about = html2bbcode($entry->aboutMe); + } - if(isset($entry->gender)) + if(isset($entry->gender)) { $gender = $entry->gender; + } - if(isset($entry->generation) AND ($entry->generation > 0)) + if(isset($entry->generation) AND ($entry->generation > 0)) { $generation = ++$entry->generation; + } - if(isset($entry->contactType) AND ($entry->contactType >= 0)) + if(isset($entry->contactType) AND ($entry->contactType >= 0)) { $contact_type = $entry->contactType; + } - if(isset($entry->tags)) - foreach($entry->tags as $tag) + if(isset($entry->tags)) { + foreach ($entry->tags as $tag) { $keywords = implode(", ", $tag); + } + } if ($generation > 0) { $success = true; diff --git a/index.php b/index.php index 39e8c583a0..f05151757b 100644 --- a/index.php +++ b/index.php @@ -152,22 +152,26 @@ if((x($_GET,'zrl')) && (!$install && !$maintenance)) { // header('Link: <' . App::get_baseurl() . '/amcd>; rel="acct-mgmt";'); -if(x($_COOKIE["Friendica"]) || (x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login')) +if (x($_COOKIE["Friendica"]) || (x($_SESSION,'authenticated')) || (x($_POST,'auth-params')) || ($a->module === 'login')) { require("include/auth.php"); +} -if(! x($_SESSION,'authenticated')) +if (! x($_SESSION,'authenticated')) { header('X-Account-Management-Status: none'); +} /* set up page['htmlhead'] and page['end'] for the modules to use */ $a->page['htmlhead'] = ''; $a->page['end'] = ''; -if(! x($_SESSION,'sysmsg')) +if (! x($_SESSION,'sysmsg')) { $_SESSION['sysmsg'] = array(); +} -if(! x($_SESSION,'sysmsg_info')) +if (! x($_SESSION,'sysmsg_info')) { $_SESSION['sysmsg_info'] = array(); +} /* * check_config() is responsible for running update scripts. These automatically @@ -177,11 +181,11 @@ if(! x($_SESSION,'sysmsg_info')) // in install mode, any url loads install module // but we need "view" module for stylesheet -if($install && $a->module!="view") +if ($install && $a->module!="view") { $a->module = 'install'; -elseif($maintenance && $a->module!="view") +} elseif ($maintenance && $a->module!="view") { $a->module = 'maintenance'; -else { +} else { check_url($a); check_db(); check_plugins($a); @@ -191,8 +195,7 @@ nav_set_selected('nothing'); //Don't populate apps_menu if apps are private $privateapps = get_config('config','private_addons'); -if((local_user()) || (! $privateapps === "1")) -{ +if ((local_user()) || (! $privateapps === "1")) { $arr = array('app_menu' => $a->apps); call_hooks('app_menu', $arr); @@ -238,9 +241,9 @@ if(strlen($a->module)) { $privateapps = get_config('config','private_addons'); - if(is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) { + if (is_array($a->plugins) && in_array($a->module,$a->plugins) && file_exists("addon/{$a->module}/{$a->module}.php")) { //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") { + if ((!local_user()) && plugin_is_app($a->module) && $privateapps === "1") { info( t("You must be logged in to use addons. ")); } else { @@ -254,7 +257,7 @@ if(strlen($a->module)) { * If not, next look for a 'standard' program module in the 'mod' directory */ - if((! $a->module_loaded) && (file_exists("mod/{$a->module}.php"))) { + if ((! $a->module_loaded) && (file_exists("mod/{$a->module}.php"))) { include_once("mod/{$a->module}.php"); $a->module_loaded = true; } @@ -272,14 +275,14 @@ if(strlen($a->module)) { * */ - if(! $a->module_loaded) { + if (! $a->module_loaded) { // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit. - if((x($_SERVER,'QUERY_STRING')) && preg_match('/{[0-9]}/',$_SERVER['QUERY_STRING']) !== 0) { + if ((x($_SERVER,'QUERY_STRING')) && preg_match('/{[0-9]}/',$_SERVER['QUERY_STRING']) !== 0) { killme(); } - if((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { + if ((x($_SERVER,'QUERY_STRING')) && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') && isset($dreamhost_error_hack)) { logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI']); goaway(App::get_baseurl() . $_SERVER['REQUEST_URI']); } @@ -304,11 +307,13 @@ if (file_exists($theme_info_file)){ /* initialise content region */ -if(! x($a->page,'content')) +if (! x($a->page,'content')) { $a->page['content'] = ''; +} -if(!$install && !$maintenance) +if (!$install && !$maintenance) { call_hooks('page_content_top',$a->page['content']); +} /** * Call module functions diff --git a/mod/admin.php b/mod/admin.php index b4495a1946..bfc8aef7b6 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1129,19 +1129,19 @@ function admin_page_dbsync(&$a) { $failed[] = $upd; } } - if(! count($failed)) { + if (! count($failed)) { $o = replace_macros(get_markup_template('structure_check.tpl'),array( - '$base' => App::get_baseurl(true), + '$base' => App::get_baseurl(true), '$banner' => t('No failed updates.'), - '$check' => t('Check database structure'), + '$check' => t('Check database structure'), )); } else { $o = replace_macros(get_markup_template('failed_updates.tpl'),array( - '$base' => App::get_baseurl(true), + '$base' => App::get_baseurl(true), '$banner' => t('Failed Updates'), - '$desc' => t('This does not include updates prior to 1139, which did not return a status.'), - '$mark' => t('Mark success (if update was manually applied)'), - '$apply' => t('Attempt to execute this update step automatically'), + '$desc' => t('This does not include updates prior to 1139, which did not return a status.'), + '$mark' => t('Mark success (if update was manually applied)'), + '$apply' => t('Attempt to execute this update step automatically'), '$failed' => $failed )); } @@ -1156,11 +1156,11 @@ function admin_page_dbsync(&$a) { * @param App $a */ function admin_page_users_post(&$a){ - $pending = (x($_POST, 'pending') ? $_POST['pending'] : array()); - $users = (x($_POST, 'user') ? $_POST['user'] : array()); - $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : ''); - $nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : ''); - $nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : ''); + $pending = (x($_POST, 'pending') ? $_POST['pending'] : array()); + $users = (x($_POST, 'user') ? $_POST['user'] : array()); + $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : ''); + $nu_nickname = (x($_POST, 'new_user_nickname') ? $_POST['new_user_nickname'] : ''); + $nu_email = (x($_POST, 'new_user_email') ? $_POST['new_user_email'] : ''); $nu_language = get_config('system', 'language'); check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); @@ -1546,7 +1546,7 @@ function admin_page_plugins(&$a){ * List plugins */ - if(x($_GET,"a") && $_GET['a']=="r") { + if (x($_GET,"a") && $_GET['a']=="r") { check_form_security_token_redirectOnErr(App::get_baseurl().'/admin/plugins', 'admin_themes', 't'); reload_plugins(); info("Plugins reloaded"); @@ -1555,23 +1555,26 @@ function admin_page_plugins(&$a){ $plugins = array(); $files = glob("addon/*/"); - if($files) { - foreach($files as $file) { - if(is_dir($file)) { + if ($files) { + foreach ($files as $file) { + if (is_dir($file)) { list($tmp, $id)=array_map("trim", explode("/",$file)); $info = get_plugin_info($id); $show_plugin = true; // If the addon is unsupported, then only show it, when it is enabled - if((strtolower($info["status"]) == "unsupported") AND !in_array($id, $a->plugins)) + if ((strtolower($info["status"]) == "unsupported") AND !in_array($id, $a->plugins)) { $show_plugin = false; + } // Override the above szenario, when the admin really wants to see outdated stuff - if(get_config("system", "show_unsupported_addons")) + if (get_config("system", "show_unsupported_addons")) { $show_plugin = true; + } - if($show_plugin) + if ($show_plugin) { $plugins[] = array($id, (in_array($id, $a->plugins)?"on":"off") , $info); + } } } } @@ -1798,11 +1801,11 @@ function admin_page_themes(&$a){ // reload active themes - if(x($_GET,"a") && $_GET['a']=="r") { + if (x($_GET,"a") && $_GET['a']=="r") { check_form_security_token_redirectOnErr(App::get_baseurl().'/admin/themes', 'admin_themes', 't'); - if($themes) { - foreach($themes as $th) { - if($th['allowed']) { + if ($themes) { + foreach ($themes as $th) { + if ($th['allowed']) { uninstall_theme($th['name']); install_theme($th['name']); } @@ -1817,7 +1820,7 @@ function admin_page_themes(&$a){ */ $xthemes = array(); - if($themes) { + if ($themes) { foreach($themes as $th) { $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name'])); } @@ -1826,17 +1829,17 @@ function admin_page_themes(&$a){ $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array( - '$title' => t('Administration'), - '$page' => t('Themes'), - '$submit' => t('Save Settings'), - '$reload' => t('Reload active themes'), - '$baseurl' => App::get_baseurl(true), - '$function' => 'themes', - '$plugins' => $xthemes, - '$pcount' => count($themes), - '$noplugshint' => sprintf(t('No themes found on the system. They should be paced in %1$s'),'/view/themes'), - '$experimental' => t('[Experimental]'), - '$unsupported' => t('[Unsupported]'), + '$title' => t('Administration'), + '$page' => t('Themes'), + '$submit' => t('Save Settings'), + '$reload' => t('Reload active themes'), + '$baseurl' => App::get_baseurl(true), + '$function' => 'themes', + '$plugins' => $xthemes, + '$pcount' => count($themes), + '$noplugshint' => sprintf(t('No themes found on the system. They should be paced in %1$s'),'/view/themes'), + '$experimental' => t('[Experimental]'), + '$unsupported' => t('[Unsupported]'), '$form_security_token' => get_form_security_token("admin_themes"), )); } diff --git a/mod/allfriends.php b/mod/allfriends.php index 420bd8690f..773b1ca802 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -29,8 +29,8 @@ function allfriends_content(&$a) { ); if (! count($c)) { - } return; + } $a->page['aside'] = ""; profile_load($a, "", 0, get_contact_details_by_url($c[0]["url"])); diff --git a/mod/cal.php b/mod/cal.php index 8b8dbed958..49706e3989 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -231,7 +231,7 @@ function cal_content(&$a) { $r = sort_by_date($r); foreach($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); - if(! x($links,$j)) { + if (! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; } } diff --git a/mod/delegate.php b/mod/delegate.php index 3bd1c85ed7..14e542fb49 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -13,7 +13,7 @@ function delegate_content(&$a) { return; } - if($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) { + if ($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) { // delegated admins can view but not change delegation permissions @@ -42,7 +42,7 @@ function delegate_content(&$a) { goaway(App::get_baseurl() . '/delegate'); } - if($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) { + if ($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) { // delegated admins can view but not change delegation permissions diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 2eca28b95d..65ec675869 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -503,10 +503,11 @@ function dfrn_confirm_post(&$a,$handsfree = null) { // Let's send our user to the contact editor in case they want to // do anything special with this new friend. - if($handsfree === null) + if ($handsfree === null) { goaway(App::get_baseurl() . '/contacts/' . intval($contact_id)); - else + } else { return; + } //NOTREACHED } @@ -522,7 +523,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { * */ - if(x($_POST,'source_url')) { + if (x($_POST,'source_url')) { // We are processing an external confirmation to an introduction created by our user. @@ -543,7 +544,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { // If $aes_key is set, both of these items require unpacking from the hex transport encoding. - if(x($aes_key)) { + if (x($aes_key)) { $aes_key = hex2bin($aes_key); $public_key = hex2bin($public_key); } diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 14ea0fdd4a..e892598b0e 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -120,17 +120,19 @@ function dfrn_request_post(&$a) { $parms = Probe::profile($dfrn_url); - if(! count($parms)) { + if (! count($parms)) { notice( t('Profile location is not valid or does not contain profile information.') . EOL ); return; } else { - if(! x($parms,'fn')) + if (! x($parms,'fn')) { notice( t('Warning: profile location has no identifiable owner name.') . EOL ); - if(! x($parms,'photo')) + } + if (! x($parms,'photo')) { notice( t('Warning: profile location has no profile photo.') . EOL ); + } $invalid = Probe::valid_dfrn($parms); - if($invalid) { + if ($invalid) { notice( sprintf( tt("%d required parameter was not found at the given location", "%d required parameters were not found at the given location", $invalid), $invalid) . EOL ); @@ -502,13 +504,13 @@ function dfrn_request_post(&$a) { ); } else { - if(! validate_url($url)) { + if (! validate_url($url)) { notice( t('Invalid profile URL.') . EOL); goaway(App::get_baseurl() . '/' . $a->cmd); return; // NOTREACHED } - if(! allowed_url($url)) { + if (! allowed_url($url)) { notice( t('Disallowed profile URL.') . EOL); goaway(App::get_baseurl() . '/' . $a->cmd); return; // NOTREACHED @@ -519,17 +521,19 @@ function dfrn_request_post(&$a) { $parms = Probe::profile(($hcard) ? $hcard : $url); - if(! count($parms)) { + if (! count($parms)) { notice( t('Profile location is not valid or does not contain profile information.') . EOL ); goaway(App::get_baseurl() . '/' . $a->cmd); } else { - if(! x($parms,'fn')) + if (! x($parms,'fn')) { notice( t('Warning: profile location has no identifiable owner name.') . EOL ); - if(! x($parms,'photo')) + } + if (! x($parms,'photo')) { notice( t('Warning: profile location has no profile photo.') . EOL ); + } $invalid = Probe::valid_dfrn($parms); - if($invalid) { + if ($invalid) { notice( sprintf( tt("%d required parameter was not found at the given location", "%d required parameters were not found at the given location", $invalid), $invalid) . EOL ); @@ -810,15 +814,18 @@ function dfrn_request_content(&$a) { $myaddr = hex2bin($_GET['addr']); elseif (x($_GET,'address') AND ($_GET['address'] != "")) $myaddr = $_GET['address']; - elseif(local_user()) { - if(strlen($a->path)) { + elseif (local_user()) { + if (strlen($a->path)) { $myaddr = App::get_baseurl() . '/profile/' . $a->user['nickname']; } else { $myaddr = $a->user['nickname'] . '@' . substr(z_root(), strpos(z_root(),'://') + 3 ); } - } else // last, try a zrl + } + else { + // last, try a zrl $myaddr = get_my_url(); + } $target_addr = $a->profile['nickname'] . '@' . substr(z_root(), strpos(z_root(),'://') + 3 ); @@ -831,10 +838,12 @@ function dfrn_request_content(&$a) { * */ - if($a->profile['page-flags'] == PAGE_NORMAL) + if ($a->profile['page-flags'] == PAGE_NORMAL) { $tpl = get_markup_template('dfrn_request.tpl'); - else + } + else { $tpl = get_markup_template('auto_request.tpl'); + } $page_desc = t("Please enter your 'Identity Address' from one of the following supported communications networks:"); diff --git a/mod/dirfind.php b/mod/dirfind.php index 8cb0e1a083..1a78421671 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -12,8 +12,9 @@ function dirfind_init(&$a) { return; } - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) { $a->page['aside'] = ''; + } $a->page['aside'] .= findpeople_widget(); @@ -31,7 +32,7 @@ function dirfind_content(&$a, $prefix = "") { $search = $prefix.notags(trim($_REQUEST['search'])); - if(strpos($search,'@') === 0) { + if (strpos($search,'@') === 0) { $search = substr($search,1); $header = sprintf( t('People Search - %s'), $search); if ((valid_email($search) AND validate_email($search)) OR @@ -41,7 +42,7 @@ function dirfind_content(&$a, $prefix = "") { } } - if(strpos($search,'!') === 0) { + if (strpos($search,'!') === 0) { $search = substr($search,1); $community = true; $header = sprintf( t('Forum Search - %s'), $search); @@ -49,7 +50,7 @@ function dirfind_content(&$a, $prefix = "") { $o = ''; - if($search) { + if ($search) { if ($discover_user) { $j = new stdClass(); @@ -85,15 +86,19 @@ function dirfind_content(&$a, $prefix = "") { $perpage = 80; $startrec = (($a->pager['page']) * $perpage) - $perpage; - if (get_config('system','diaspora_enabled')) + if (get_config('system','diaspora_enabled')) { $diaspora = NETWORK_DIASPORA; - else + } + else { $diaspora = NETWORK_DFRN; + } - if (!get_config('system','ostatus_disabled')) + if (!get_config('system','ostatus_disabled')) { $ostatus = NETWORK_OSTATUS; - else + } + else { $ostatus = NETWORK_DFRN; + } $search2 = "%".$search."%"; @@ -133,8 +138,9 @@ function dirfind_content(&$a, $prefix = "") { $j->items_page = $perpage; $j->page = $a->pager['page']; foreach ($results AS $result) { - if (poco_alternate_ostatus_url($result["url"])) - continue; + if (poco_alternate_ostatus_url($result["url"])) { + continue; + } $result = get_contact_details_by_url($result["url"], local_user(), $result); @@ -167,16 +173,16 @@ function dirfind_content(&$a, $prefix = "") { $j = json_decode($x); } - if($j->total) { + if ($j->total) { $a->set_pager_total($j->total); $a->set_pager_itemspage($j->items_page); } - if(count($j->results)) { + if (count($j->results)) { $id = 0; - foreach($j->results as $jj) { + foreach ($j->results as $jj) { $alt_text = ""; @@ -194,8 +200,10 @@ function dirfind_content(&$a, $prefix = "") { $photo_menu = contact_photo_menu($contact[0]); $details = _contact_detail_for_template($contact[0]); $alt_text = $details['alt_text']; - } else + } + else { $photo_menu = array(); + } } else { $connlnk = App::get_baseurl().'/follow/?url='.(($jj->connect) ? $jj->connect : $jj->url); $conntxt = t('Connect'); diff --git a/mod/events.php b/mod/events.php index a20934222f..6552117747 100644 --- a/mod/events.php +++ b/mod/events.php @@ -253,15 +253,15 @@ function events_content(&$a) { $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0); if($a->argc > 1) { - if($a->argc > 2 && $a->argv[1] == 'event') { + if ($a->argc > 2 && $a->argv[1] == 'event') { $mode = 'edit'; $event_id = intval($a->argv[2]); } - if($a->argv[1] === 'new') { + if ($a->argv[1] === 'new') { $mode = 'new'; $event_id = 0; } - if($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) { + if ($a->argc > 2 && intval($a->argv[1]) && intval($a->argv[2])) { $mode = 'view'; $y = intval($a->argv[1]); $m = intval($a->argv[2]); @@ -269,23 +269,27 @@ function events_content(&$a) { } // The view mode part is similiar to /mod/cal.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; @@ -341,7 +345,7 @@ function events_content(&$a) { $r = sort_by_date($r); foreach($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); - if(! x($links,$j)) { + if (! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; } } diff --git a/mod/settings.php b/mod/settings.php index e67ea9bc6a..cedee18473 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1170,13 +1170,14 @@ function settings_content(&$a) { )); } - if(strlen(get_config('system','directory'))) { + if (strlen(get_config('system','directory'))) { $profile_in_net_dir = replace_macros($opt_tpl,array( '$field' => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'),t('Yes'))), )); } - else + else { $profile_in_net_dir = ''; + } $hide_friends = replace_macros($opt_tpl,array( From 6c0c9d542abaabd8000a10eb47b0921426fcd25d Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 20 Dec 2016 21:13:50 +0100 Subject: [PATCH 26/41] Continued with coding convention: - added curly braces around conditional code blocks - added space between if/foreach/... and brace - rewrote a code block so if dbm::is_result() fails it will abort, else the id is fetched from INSERT statement - made some SQL keywords upper-cased and added back-ticks to columns/table names Signed-off-by: Roland Haeder --- include/acl_selectors.php | 22 ++++++++++++-------- include/api.php | 4 ++-- include/bbcode.php | 2 +- include/contact_selectors.php | 2 +- include/contact_widgets.php | 8 ++++--- include/conversation.php | 2 +- include/datetime.php | 2 +- include/diaspora.php | 14 ++++++------- include/expire.php | 2 +- include/group.php | 6 +++--- include/identity.php | 6 +++--- include/message.php | 39 +++++++++++++++++++---------------- include/notifier.php | 4 ++-- include/plugin.php | 3 ++- include/pubsubpublish.php | 14 ++++++++----- include/queue.php | 13 ++++++------ include/text.php | 4 ++-- include/user.php | 2 +- 18 files changed, 82 insertions(+), 67 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 2be0303049..dc86ba0345 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -34,7 +34,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) { call_hooks($a->module . '_pre_' . $selname, $arr); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if((is_array($preselected)) && in_array($rr['id'], $preselected)) $selected = " selected=\"selected\" "; else @@ -145,7 +145,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { call_hooks($a->module . '_pre_' . $selname, $arr); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if((is_array($preselected)) && in_array($rr['id'], $preselected)) $selected = " selected=\"selected\" "; else @@ -221,16 +221,20 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p $receiverlist = array(); if (dbm::is_result($r)) { - foreach($r as $rr) { - if((is_array($preselected)) && in_array($rr['id'], $preselected)) + foreach ($r as $rr) { + if ((is_array($preselected)) && in_array($rr['id'], $preselected)) { $selected = " selected=\"selected\" "; - else + } + else { $selected = ''; + } - if($privmail) + if ($privmail) { $trimmed = GetProfileUsername($rr['url'], $rr['name'], false); - else + } + else { $trimmed = mb_substr($rr['name'],0,20); + } $receiverlist[] = $trimmed; @@ -260,7 +264,7 @@ function prune_deadguys($arr) { return $arr; $str = dbesc(implode(',',$arr)); $r = q("SELECT `id` FROM `contact` WHERE `id` IN ( " . $str . ") AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 "); - if($r) { + if ($r) { $ret = array(); foreach($r as $rr) $ret[] = intval($rr['id']); @@ -554,7 +558,7 @@ function acl_lookup(&$a, $out_type = 'json') { // autocomplete for global contact search (e.g. navbar search) $r = navbar_complete($a); $contacts = array(); - if($r) { + if ($r) { foreach($r as $g) { $contacts[] = array( "photo" => proxy_url($g['photo'], false, PROXY_SIZE_MICRO), diff --git a/include/api.php b/include/api.php index 2ae1aeaa02..a352da9fac 100644 --- a/include/api.php +++ b/include/api.php @@ -3068,8 +3068,8 @@ 'image/gif' => 'gif' ); $data = array('photo'=>array()); - if($r) { - foreach($r as $rr) { + if ($r) { + foreach ($r as $rr) { $photo = array(); $photo['id'] = $rr['resource-id']; $photo['album'] = $rr['album']; diff --git a/include/bbcode.php b/include/bbcode.php index c05173f47c..74dde2fdf4 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -343,7 +343,7 @@ function bb_replace_images($body, $images) { $newbody = $body; $cnt = 0; - foreach($images as $image) { + foreach ($images as $image) { // We're depending on the property of 'foreach' (specified on the PHP website) that // it loops over the array starting from the first element and going sequentially // to the last element diff --git a/include/contact_selectors.php b/include/contact_selectors.php index 0790e503ea..ec9dff61d5 100644 --- a/include/contact_selectors.php +++ b/include/contact_selectors.php @@ -13,7 +13,7 @@ function contact_profile_assign($current,$foreign_net) { intval($_SESSION['uid'])); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $selected = (($rr['id'] == $current) ? " selected=\"selected\" " : ""); $o .= "\r\n"; } diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 71a75d431e..36675da873 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -97,9 +97,11 @@ function networks_widget($baseurl,$selected = '') { $nets = array(); if (dbm::is_result($r)) { require_once('include/contact_selectors.php'); - foreach($r as $rr) { - if($rr['network']) - $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); + foreach ($r as $rr) { + /// @TODO If 'network' is not there, this triggers an E_NOTICE + if ($rr['network']) { + $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' )); + } } } diff --git a/include/conversation.php b/include/conversation.php index ccfc070d4e..36eded8e8a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -78,7 +78,7 @@ function item_redir_and_replace_images($body, $images, $cid) { $newbody .= $origbody; $cnt = 0; - foreach($images as $image) { + foreach ($images as $image) { // We're depending on the property of 'foreach' (specified on the PHP website) that // it loops over the array starting from the first element and going sequentially // to the last element diff --git a/include/datetime.php b/include/datetime.php index e88c274ab9..a17c405dc3 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -553,7 +553,7 @@ function update_contact_birthdays() { $r = q("SELECT * FROM contact WHERE `bd` != '' AND `bd` != '0000-00-00' AND SUBSTRING(`bd`,1,4) != `bdyear` "); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { logger('update_contact_birthday: ' . $rr['bd']); diff --git a/include/diaspora.php b/include/diaspora.php index 3b4832e74f..cfb624fdf2 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -319,8 +319,8 @@ class diaspora { dbesc(NETWORK_DIASPORA), dbesc($msg["author"]) ); - if($r) { - foreach($r as $rr) { + if ($r) { + foreach ($r as $rr) { logger("delivering to: ".$rr["username"]); self::dispatch($rr,$msg); } @@ -806,7 +806,7 @@ class diaspora { dbesc($guid) ); - if($r) { + if ($r) { logger("message ".$guid." already exists for user ".$uid); return $r[0]["id"]; } @@ -1577,7 +1577,7 @@ class diaspora { dbesc($message_uri), intval($importer["uid"]) ); - if($r) { + if ($r) { logger("duplicate message already delivered.", LOGGER_DEBUG); return false; } @@ -2022,7 +2022,7 @@ class diaspora { FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", dbesc($guid)); - if($r) { + if ($r) { logger("reshared message ".$guid." already exists on system."); // Maybe it is already a reshared item? @@ -2623,7 +2623,7 @@ class diaspora { logger("transmit: ".$logid."-".$guid." returns: ".$return_code); - if(!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) { + if (!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) { logger("queue message"); $r = q("SELECT `id` FROM `queue` WHERE `cid` = %d AND `network` = '%s' AND `content` = '%s' AND `batch` = %d LIMIT 1", @@ -2632,7 +2632,7 @@ class diaspora { dbesc($slap), intval($public_batch) ); - if($r) { + if ($r) { logger("add_to_queue ignored - identical item already in queue"); } else { // queue message for redelivery diff --git a/include/expire.php b/include/expire.php index eca2b1c42a..e3313a78be 100644 --- a/include/expire.php +++ b/include/expire.php @@ -40,7 +40,7 @@ function expire_run(&$argv, &$argc){ $r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG); item_expire($rr['uid'],$rr['expire']); } diff --git a/include/group.php b/include/group.php index a2a55c4440..6332c45da2 100644 --- a/include/group.php +++ b/include/group.php @@ -53,7 +53,7 @@ function group_rmv($uid,$name) { $r = q("SELECT def_gid, allow_gid, deny_gid FROM user WHERE uid = %d LIMIT 1", intval($uid) ); - if($r) { + if ($r) { $user_info = $r[0]; $change = false; @@ -199,7 +199,7 @@ function mini_group_select($uid,$gid = 0, $label = "") { ); $grps[] = array('name' => '', 'id' => '0', 'selected' => ''); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $grps[] = array('name' => $rr['name'], 'id' => $rr['id'], 'selected' => (($gid == $rr['id']) ? 'true' : '')); } @@ -257,7 +257,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro } if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $selected = (($group_id == $rr['id']) ? ' group-selected' : ''); if ($editmode == "full") { diff --git a/include/identity.php b/include/identity.php index 5439b2cc10..70ff7f00ac 100644 --- a/include/identity.php +++ b/include/identity.php @@ -294,7 +294,7 @@ function profile_sidebar($profile, $block = 0) { if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $profile['menu']['entries'][] = array( 'photo' => $rr['thumb'], 'id' => $rr['id'], @@ -469,7 +469,7 @@ function get_birthdays() { $cids = array(); $istoday = false; - foreach($r as $rr) { + foreach ($r as $rr) { if(strlen($rr['name'])) $total ++; if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) @@ -549,7 +549,7 @@ function get_events() { if (dbm::is_result($r)) { $now = strtotime('now'); $istoday = false; - foreach($r as $rr) { + foreach ($r as $rr) { if(strlen($rr['name'])) $total ++; diff --git a/include/message.php b/include/message.php index e5ebe6f915..5bd611f220 100644 --- a/include/message.php +++ b/include/message.php @@ -130,12 +130,13 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $match = null; - if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) { + if (preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) { $images = $match[1]; - if(count($images)) { - foreach($images as $image) { - if(! stristr($image,App::get_baseurl() . '/photo/')) + if (count($images)) { + foreach ($images as $image) { + if (! stristr($image,App::get_baseurl() . '/photo/')) { continue; + } $image_uri = substr($image,strrpos($image,'/') + 1); $image_uri = substr($image_uri,0, strpos($image_uri,'-')); $r = q("UPDATE `photo` SET `allow_cid` = '%s' @@ -149,25 +150,25 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ } } - if($post_id) { + if ($post_id) { proc_run(PRIORITY_HIGH, "include/notifier.php", "mail", $post_id); return intval($post_id); - } else { + } + else { return -3; } } - - - - function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){ - if(! $recipient) return -1; + if (! $recipient) { + return -1; + } - if(! strlen($subject)) + if (! strlen($subject)) { $subject = t('[no subject]'); + } $guid = get_guid(32); $uri = 'urn:X-dfrn:' . App::get_baseurl() . ':' . local_user() . ':' . $guid; @@ -179,8 +180,9 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){ $me = probe_url($replyto); - if(! $me['name']) + if (! $me['name']) { return -2; + } $conv_guid = get_guid(32); @@ -193,7 +195,7 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){ $handles = $recip_handle . ';' . $sender_handle; - $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ", + $r = q("INSERT INTO `conv` (`uid`,`guid`,`creator`,`created`,`updated`,`subject`,`recips`) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ", intval($recipient['uid']), dbesc($conv_guid), dbesc($sender_handle), @@ -203,18 +205,19 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){ dbesc($handles) ); - $r = q("select * from conv where guid = '%s' and uid = %d limit 1", + $r = q("SELECT * FROM `conv` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1", dbesc($conv_guid), intval($recipient['uid']) ); - if (dbm::is_result($r)) - $convid = $r[0]['id']; - if(! $convid) { + + if (! dbm::is_result($r)) { logger('send message: conversation not found.'); return -4; } + $convid = $r[0]['id']; + $r = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`, `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`) VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )", diff --git a/include/notifier.php b/include/notifier.php index d78db4055d..72387c98db 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -598,7 +598,7 @@ function notifier_run(&$argv, &$argc){ // throw everything into the queue in case we get killed - foreach($r as $rr) { + foreach ($r as $rr) { if((! $mail) && (! $fsuggest) && (! $followup)) { q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d) ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d", @@ -608,7 +608,7 @@ function notifier_run(&$argv, &$argc){ } } - foreach($r as $rr) { + foreach ($r as $rr) { // except for Diaspora batch jobs // Don't deliver to folks who have already been delivered to diff --git a/include/plugin.php b/include/plugin.php index c7c44e433d..39cb5d5231 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -187,8 +187,9 @@ function load_hooks() { $a = get_app(); $a->hooks = array(); $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC, `file`"); + if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if(! array_key_exists($rr['hook'],$a->hooks)) $a->hooks[$rr['hook']] = array(); $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']); diff --git a/include/pubsubpublish.php b/include/pubsubpublish.php index abf973a284..6bd90bfc21 100644 --- a/include/pubsubpublish.php +++ b/include/pubsubpublish.php @@ -76,16 +76,19 @@ function pubsubpublish_run(&$argv, &$argc){ load_config('system'); // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") - if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540)) + if (App::callstack() != "poller_run") { + if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540)) { return; + } + } $a->set_baseurl(get_config('system','url')); load_hooks(); - if($argc > 1) + if ($argc > 1) { $pubsubpublish_id = intval($argv[1]); + } else { // We'll push to each subscriber that has push > 0, // i.e. there has been an update (set in notifier.php). @@ -95,10 +98,11 @@ function pubsubpublish_run(&$argv, &$argc){ $interval = Config::get("system", "delivery_interval", 2); // If we are using the worker we don't need a delivery interval - if (get_config("system", "worker")) + if (get_config("system", "worker")) { $interval = false; + } - foreach($r as $rr) { + foreach ($r as $rr) { logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG); proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]); diff --git a/include/queue.php b/include/queue.php index ad7079e959..8f57bf3d72 100644 --- a/include/queue.php +++ b/include/queue.php @@ -58,20 +58,21 @@ function queue_run(&$argv, &$argc){ $interval = false; $r = q("select * from deliverq where 1"); - if($r) { - foreach($r as $rr) { + if ($r) { + foreach ($r as $rr) { logger('queue: deliverq'); proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']); - if($interval) - @time_sleep_until(microtime(true) + (float) $interval); + if($interval) { + time_sleep_until(microtime(true) + (float) $interval); + } } } $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); - if($r) { - foreach($r as $rr) { + if ($r) { + foreach ($r as $rr) { logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']); logger('Expired queue data :' . $rr['content'], LOGGER_DATA); } diff --git a/include/text.php b/include/text.php index e174aa3753..4f71ab8e60 100644 --- a/include/text.php +++ b/include/text.php @@ -912,7 +912,7 @@ function contact_block() { if (dbm::is_result($r)) { $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total); $micropro = Array(); - foreach($r as $rr) { + foreach ($r as $rr) { $micropro[] = micropro($rr,true,'mpfriend'); } } @@ -1717,7 +1717,7 @@ function bb_translate_video($s) { $matches = null; $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER); - if($r) { + if ($r) { foreach($matches as $mtch) { if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be'))) $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s); diff --git a/include/user.php b/include/user.php index ec15d5b134..983c4a416b 100644 --- a/include/user.php +++ b/include/user.php @@ -216,7 +216,7 @@ function create_user($arr) { dbesc($default_service_class) ); - if($r) { + if ($r) { $r = q("SELECT * FROM `user` WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", dbesc($username), From 52f14ffa5f266e0e811b0e3e429734f0ec73a859 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 20 Dec 2016 21:15:53 +0100 Subject: [PATCH 27/41] Continued with coding convention: - added curly braces around conditional code blocks - added space between if/foreach/... and brace - rewrote a code block so if dbm::is_result() fails it will abort, else the id is fetched from INSERT statement - made some SQL keywords upper-cased and added back-ticks to columns/table names Signed-off-by: Roland Haeder --- mod/admin.php | 2 +- mod/allfriends.php | 2 +- mod/cal.php | 2 +- mod/common.php | 2 +- mod/contacts.php | 28 +++++++++++++++++----------- mod/delegate.php | 2 +- mod/dfrn_request.php | 6 +++--- mod/directory.php | 8 +++++--- mod/events.php | 2 +- mod/filerm.php | 9 ++++++--- mod/follow.php | 15 ++++++++++----- mod/group.php | 2 +- mod/hcard.php | 23 +++++++++++++---------- mod/install.php | 13 ++++++++----- mod/invite.php | 16 +++++++++------- mod/item.php | 32 +++++++++++++++++++------------- mod/lostpass.php | 2 +- mod/message.php | 4 ++-- mod/network.php | 20 ++++++++++---------- mod/nogroup.php | 2 +- mod/noscrape.php | 28 +++++++++++++++------------- mod/openid.php | 36 +++++++++++++++++++++++------------- mod/photos.php | 4 ++-- mod/poco.php | 2 +- mod/profile.php | 2 +- mod/profile_photo.php | 2 +- mod/profiles.php | 20 +++++++++++--------- mod/search.php | 2 +- mod/suggest.php | 2 +- mod/videos.php | 4 ++-- mod/viewcontacts.php | 6 ++++-- 31 files changed, 173 insertions(+), 127 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index bfc8aef7b6..72412f69b4 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1122,7 +1122,7 @@ function admin_page_dbsync(&$a) { $failed = array(); $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' "); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $upd = intval(substr($rr['k'],7)); if($upd < 1139 || $rr['v'] === 'success') continue; diff --git a/mod/allfriends.php b/mod/allfriends.php index 773b1ca802..d7f4073b7e 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -49,7 +49,7 @@ function allfriends_content(&$a) { $id = 0; - foreach($r as $rr) { + foreach ($r as $rr) { //get further details of the contact $contact_details = get_contact_details_by_url($rr['url'], $uid, $rr); diff --git a/mod/cal.php b/mod/cal.php index 49706e3989..d49e8f7649 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -229,7 +229,7 @@ function cal_content(&$a) { if (dbm::is_result($r)) { $r = sort_by_date($r); - foreach($r as $rr) { + foreach ($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); if (! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; diff --git a/mod/common.php b/mod/common.php index 9781d1607c..0be8f1d14a 100644 --- a/mod/common.php +++ b/mod/common.php @@ -100,7 +100,7 @@ function common_content(&$a) { $id = 0; - foreach($r as $rr) { + foreach ($r as $rr) { //get further details of the contact $contact_details = get_contact_details_by_url($rr['url'], $uid); diff --git a/mod/contacts.php b/mod/contacts.php index f9b6f64d86..b1553393e2 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -129,10 +129,12 @@ function contacts_batch_actions(&$a){ info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) ); } - if(x($_SESSION,'return_url')) + if (x($_SESSION,'return_url')) { goaway('' . $_SESSION['return_url']); - else + } + else { goaway('contacts'); + } } @@ -387,7 +389,7 @@ function contacts_content(&$a) { if($cmd === 'block') { $r = _contact_block($contact_id, $orig_record[0]); - if($r) { + if ($r) { $blocked = (($orig_record[0]['blocked']) ? 0 : 1); info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL); } @@ -398,7 +400,7 @@ function contacts_content(&$a) { if($cmd === 'ignore') { $r = _contact_ignore($contact_id, $orig_record[0]); - if($r) { + if ($r) { $readonly = (($orig_record[0]['readonly']) ? 0 : 1); info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL); } @@ -410,7 +412,7 @@ function contacts_content(&$a) { if($cmd === 'archive') { $r = _contact_archive($contact_id, $orig_record[0]); - if($r) { + if ($r) { $archived = (($orig_record[0]['archive']) ? 0 : 1); info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL); } @@ -449,22 +451,26 @@ function contacts_content(&$a) { )); } // Now check how the user responded to the confirmation query - if($_REQUEST['canceled']) { - if(x($_SESSION,'return_url')) + if ($_REQUEST['canceled']) { + if (x($_SESSION,'return_url')) { goaway('' . $_SESSION['return_url']); - else + } + else { goaway('contacts'); + } } _contact_drop($contact_id, $orig_record[0]); info( t('Contact has been removed.') . EOL ); - if(x($_SESSION,'return_url')) + if (x($_SESSION,'return_url')) { goaway('' . $_SESSION['return_url']); - else + } + else { goaway('contacts'); + } return; // NOTREACHED } - if($cmd === 'posts') { + if ($cmd === 'posts') { return contact_posts($a, $contact_id); } } diff --git a/mod/delegate.php b/mod/delegate.php index 14e542fb49..1a3f13c763 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -107,7 +107,7 @@ function delegate_content(&$a) { $nicknames = array(); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'"; } } diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index e892598b0e..68ef4971b4 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -178,7 +178,7 @@ function dfrn_request_post(&$a) { ); } - if($r) { + if ($r) { info( t("Introduction complete.") . EOL); } @@ -301,7 +301,7 @@ function dfrn_request_post(&$a) { dbesc(NETWORK_MAIL2) ); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if(! $rr['rel']) { q("DELETE FROM `contact` WHERE `id` = %d", intval($rr['cid']) @@ -326,7 +326,7 @@ function dfrn_request_post(&$a) { dbesc(NETWORK_MAIL2) ); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if(! $rr['rel']) { q("DELETE FROM `contact` WHERE `id` = %d", intval($rr['cid']) diff --git a/mod/directory.php b/mod/directory.php index ddea650de2..50a0a93b9c 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -92,12 +92,14 @@ function directory_content(&$a) { WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 AND `contact`.`self` $sql_extra $order LIMIT ".$limit); if (dbm::is_result($r)) { - if(in_array('small', $a->argv)) + if (in_array('small', $a->argv)) { $photo = 'thumb'; - else + } + else { $photo = 'photo'; + } - foreach($r as $rr) { + foreach ($r as $rr) { $itemurl= ''; diff --git a/mod/events.php b/mod/events.php index 6552117747..9b5f7cce89 100644 --- a/mod/events.php +++ b/mod/events.php @@ -343,7 +343,7 @@ function events_content(&$a) { if (dbm::is_result($r)) { $r = sort_by_date($r); - foreach($r as $rr) { + foreach ($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); if (! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; diff --git a/mod/filerm.php b/mod/filerm.php index c8bf8658be..d3d74a4c2f 100644 --- a/mod/filerm.php +++ b/mod/filerm.php @@ -10,18 +10,21 @@ function filerm_content(&$a) { $cat = unxmlify(trim($_GET['cat'])); $category = (($cat) ? true : false); - if($category) + if ($category) { $term = $cat; + } $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); logger('filerm: tag ' . $term . ' item ' . $item_id); - if($item_id && strlen($term)) + if ($item_id && strlen($term)) { file_tag_unsave_file(local_user(),$item_id,$term, $category); + } - if(x($_SESSION,'return_url')) + if (x($_SESSION,'return_url')) { goaway(App::get_baseurl() . '/' . $_SESSION['return_url']); + } killme(); } diff --git a/mod/follow.php b/mod/follow.php index 8f8c73c90c..eb5570e8ab 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -157,8 +157,9 @@ function follow_post(&$a) { // NOTREACHED } - if ($_REQUEST['cancel']) + if ($_REQUEST['cancel']) { goaway($_SESSION['return_url']); + } $uid = local_user(); $url = notags(trim($_REQUEST['url'])); @@ -170,17 +171,21 @@ function follow_post(&$a) { $result = new_contact($uid,$url,true); - if($result['success'] == false) { - if($result['message']) + if ($result['success'] == false) { + if ($result['message']) { notice($result['message']); + } goaway($return_url); - } elseif ($result['cid']) + } + elseif ($result['cid']) { goaway(App::get_baseurl().'/contacts/'.$result['cid']); + } info( t('Contact added').EOL); - if(strstr($return_url,'contacts')) + if (strstr($return_url,'contacts')) { goaway(App::get_baseurl().'/contacts/'.$contact_id); + } goaway($return_url); // NOTREACHED diff --git a/mod/group.php b/mod/group.php index 8a744d1e11..75ccc8f6d9 100644 --- a/mod/group.php +++ b/mod/group.php @@ -25,7 +25,7 @@ function group_post(&$a) { $name = notags(trim($_POST['groupname'])); $r = group_add(local_user(),$name); - if($r) { + if ($r) { info( t('Group created.') . EOL ); $r = group_byname(local_user(),$name); if ($r) { diff --git a/mod/hcard.php b/mod/hcard.php index 3669863447..512949f1a3 100644 --- a/mod/hcard.php +++ b/mod/hcard.php @@ -4,8 +4,9 @@ function hcard_init(&$a) { $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); - if($a->argc > 1) + if ($a->argc > 1) { $which = $a->argv[1]; + } else { notice( t('No profile') . EOL ); $a->error = 404; @@ -13,28 +14,30 @@ function hcard_init(&$a) { } $profile = 0; - if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { - $which = $a->user['nickname']; - $profile = $a->argv[1]; + if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { + $which = $a->user['nickname']; + $profile = $a->argv[1]; } profile_load($a,$which,$profile); - if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { + if ((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { $a->page['htmlhead'] .= ''; } - if(x($a->profile,'openidserver')) + if (x($a->profile,'openidserver')) { $a->page['htmlhead'] .= '' . "\r\n"; - if(x($a->profile,'openid')) { + } + if (x($a->profile,'openid')) { $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']); $a->page['htmlhead'] .= '' . "\r\n"; } - if(! $blocked) { + if (! $blocked) { $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords); - if(strlen($keywords)) + if (strlen($keywords)) { $a->page['htmlhead'] .= '' . "\r\n" ; + } } $a->page['htmlhead'] .= '' . "\r\n" ; @@ -44,7 +47,7 @@ function hcard_init(&$a) { header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) { + foreach ($dfrn_pages as $dfrn) { $a->page['htmlhead'] .= "\r\n"; } diff --git a/mod/install.php b/mod/install.php index c5baa17db2..73216e7f88 100755 --- a/mod/install.php +++ b/mod/install.php @@ -52,7 +52,7 @@ function install_post(&$a) { $r = q("CREATE DATABASE '%s'", dbesc($dbdata) ); - if($r) { + if ($r) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); } else { @@ -520,19 +520,22 @@ function check_smarty3(&$checks) { function check_htaccess(&$checks) { $status = true; $help = ""; - if (function_exists('curl_init')){ + if (function_exists('curl_init')) { $test = fetch_url(App::get_baseurl()."/install/testrewrite"); - if ($test!="ok") + if ($test!="ok") { $test = fetch_url(normalise_link(App::get_baseurl()."/install/testrewrite")); + } if ($test!="ok") { $status = false; $help = t('Url rewrite in .htaccess is not working. Check your server configuration.'); } check_add($checks, t('Url rewrite is working'), $status, true, $help); - } else { + } + else { // cannot check modrewrite if libcurl is not installed + /// @TODO Maybe issue warning here? } } @@ -549,7 +552,7 @@ function check_imagik(&$checks) { } if ($imagick == false) { check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, ""); - } + } else { check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, ""); if ($imagick) { diff --git a/mod/invite.php b/mod/invite.php index ae08c387eb..12f8306e8a 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -116,11 +116,13 @@ function invite_content(&$a) { $dirloc = get_config('system','directory'); if(strlen($dirloc)) { - if($a->config['register_policy'] == REGISTER_CLOSED) + if ($a->config['register_policy'] == REGISTER_CLOSED) { $linktxt = sprintf( t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.'), $dirloc . '/siteinfo'); - elseif($a->config['register_policy'] != REGISTER_CLOSED) + } + elseif($a->config['register_policy'] != REGISTER_CLOSED) { $linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), App::get_baseurl()) . "\r\n" . "\r\n" . sprintf( t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.'),$dirloc . '/siteinfo'); + } } else { $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); @@ -129,15 +131,15 @@ function invite_content(&$a) { $o = replace_macros($tpl, array( '$form_security_token' => get_form_security_token("send_invite"), - '$invite' => t('Send invitations'), - '$addr_text' => t('Enter email addresses, one per line:'), - '$msg_text' => t('Your message:'), - '$default_message' => t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n" + '$invite' => t('Send invitations'), + '$addr_text' => t('Enter email addresses, one per line:'), + '$msg_text' => t('Your message:'), + '$default_message' => t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n" . $linktxt . "\r\n" . "\r\n" . (($invonly) ? t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') .t('Once you have registered, please connect with me via my profile page at:') . "\r\n" . "\r\n" . App::get_baseurl() . '/profile/' . $a->user['nickname'] . "\r\n" . "\r\n" . t('For more information about the Friendica project and why we feel it is important, please visit http://friendica.com') . "\r\n" . "\r\n" , - '$submit' => t('Submit') + '$submit' => t('Submit') )); return $o; diff --git a/mod/item.php b/mod/item.php index c22d4448ad..17cf4c6487 100644 --- a/mod/item.php +++ b/mod/item.php @@ -59,13 +59,14 @@ function item_post(&$a) { // Check for doubly-submitted posts, and reject duplicates // Note that we have to ignore previews, otherwise nothing will post // after it's been previewed - if(!$preview && x($_REQUEST['post_id_random'])) { - if(x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { + if (!$preview && x($_REQUEST['post_id_random'])) { + if (x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { logger("item post: duplicate post", LOGGER_DEBUG); item_post_return(App::get_baseurl(), $api_source, $return_path); } - else + else { $_SESSION['post-random'] = $_REQUEST['post_id_random']; + } } /** @@ -82,18 +83,20 @@ function item_post(&$a) { $r = false; $objecttype = null; - if($parent || $parent_uri) { + if ($parent || $parent_uri) { $objecttype = ACTIVITY_OBJ_COMMENT; - if(! x($_REQUEST,'type')) + if (! x($_REQUEST,'type')) { $_REQUEST['type'] = 'net-comment'; + } - if($parent) { + if ($parent) { $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($parent) ); - } elseif($parent_uri && local_user()) { + } + elseif ($parent_uri && local_user()) { // This is coming from an API source, and we are logged in $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent_uri), @@ -105,7 +108,7 @@ function item_post(&$a) { if (dbm::is_result($r)) { $parid = $r[0]['parent']; $parent_uri = $r[0]['uri']; - if($r[0]['id'] != $r[0]['parent']) { + if ($r[0]['id'] != $r[0]['parent']) { $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1", intval($parid) ); @@ -114,8 +117,9 @@ function item_post(&$a) { if (! dbm::is_result($r)) { notice( t('Unable to locate original post.') . EOL); - if(x($_REQUEST,'return')) + if (x($_REQUEST,'return')) { goaway($return_path); + } killme(); } $parent_item = $r[0]; @@ -125,7 +129,7 @@ function item_post(&$a) { //if(($parid) && ($parid != $parent)) $thr_parent = $parent_uri; - if($parent_item['contact-id'] && $uid) { + if ($parent_item['contact-id'] && $uid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($parent_item['contact-id']), intval($uid) @@ -448,13 +452,15 @@ function item_post(&$a) { $objecttype = ACTIVITY_OBJ_IMAGE; - foreach($images as $image) { - if(! stristr($image,App::get_baseurl() . '/photo/')) + foreach ($images as $image) { + if (! stristr($image,App::get_baseurl() . '/photo/')) { continue; + } $image_uri = substr($image,strrpos($image,'/') + 1); $image_uri = substr($image_uri,0, strpos($image_uri,'-')); - if(! strlen($image_uri)) + if (! strlen($image_uri)) { continue; + } $srch = '<' . intval($contact_id) . '>'; $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' diff --git a/mod/lostpass.php b/mod/lostpass.php index 92e64f7e2e..a5ef739cd1 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -102,7 +102,7 @@ function lostpass_content(&$a) { dbesc($new_password_encoded), intval($uid) ); - if($r) { + if ($r) { $tpl = get_markup_template('pwdreset.tpl'); $o .= replace_macros($tpl,array( '$lbl1' => t('Password Reset'), diff --git a/mod/message.php b/mod/message.php index f926352590..fcf0989ae0 100644 --- a/mod/message.php +++ b/mod/message.php @@ -160,7 +160,7 @@ function item_redir_and_replace_images($body, $images, $cid) { $newbody = $newbody . $origbody; $cnt = 0; - foreach($images as $image) { + foreach ($images as $image) { // We're depending on the property of 'foreach' (specified on the PHP website) that // it loops over the array starting from the first element and going sequentially // to the last element @@ -231,7 +231,7 @@ function message_content(&$a) { intval($a->argv[2]), intval(local_user()) ); - if($r) { + if ($r) { info( t('Message deleted.') . EOL ); } //goaway(App::get_baseurl(true) . '/message' ); diff --git a/mod/network.php b/mod/network.php index ba97148009..cce511ae19 100644 --- a/mod/network.php +++ b/mod/network.php @@ -183,13 +183,13 @@ function saved_searches($search) { $saved = array(); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $saved[] = array( - 'id' => $rr['id'], - 'term' => $rr['term'], - 'encodedterm' => urlencode($rr['term']), - 'delete' => t('Remove term'), - 'selected' => ($search==$rr['term']), + 'id' => $rr['id'], + 'term' => $rr['term'], + 'encodedterm' => urlencode($rr['term']), + 'delete' => t('Remove term'), + 'selected' => ($search==$rr['term']), ); } } @@ -197,10 +197,10 @@ function saved_searches($search) { $tpl = get_markup_template("saved_searches_aside.tpl"); $o = replace_macros($tpl, array( - '$title' => t('Saved Searches'), - '$add' => t('add'), - '$searchbox' => search($search,'netsearch-box',$srchurl,true), - '$saved' => $saved, + '$title' => t('Saved Searches'), + '$add' => t('add'), + '$searchbox' => search($search,'netsearch-box',$srchurl,true), + '$saved' => $saved, )); return $o; diff --git a/mod/nogroup.php b/mod/nogroup.php index f2a5a3b33b..c75b595c36 100644 --- a/mod/nogroup.php +++ b/mod/nogroup.php @@ -35,7 +35,7 @@ function nogroup_content(&$a) { } $r = contacts_not_grouped(local_user(),$a->pager['start'],$a->pager['itemspage']); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $contact_details = get_contact_details_by_url($rr['url'], local_user(), $rr); diff --git a/mod/noscrape.php b/mod/noscrape.php index 98d491bca6..939ccbf79a 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -31,21 +31,22 @@ function noscrape_init(&$a) { intval($a->profile['uid'])); $json_info = array( - 'fn' => $a->profile['name'], - 'addr' => $a->profile['addr'], - 'nick' => $which, - 'key' => $a->profile['pubkey'], + 'fn' => $a->profile['name'], + 'addr' => $a->profile['addr'], + 'nick' => $which, + 'key' => $a->profile['pubkey'], 'homepage' => App::get_baseurl()."/profile/{$which}", - 'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY), - 'photo' => $r[0]["photo"], - 'tags' => $keywords + 'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY), + 'photo' => $r[0]["photo"], + 'tags' => $keywords ); - if(is_array($a->profile) AND !$a->profile['hide-friends']) { + if (is_array($a->profile) AND !$a->profile['hide-friends']) { $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1", intval($a->profile['uid'])); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $json_info["updated"] = date("c", strtotime($r[0]['updated'])); + } $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0 AND `network` IN ('%s', '%s', '%s', '')", @@ -54,20 +55,21 @@ function noscrape_init(&$a) { dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $json_info["contacts"] = intval($r[0]['total']); + } } //These are optional fields. $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'); - foreach($profile_fields as $field) { - if(!empty($a->profile[$field])) { + foreach ($profile_fields as $field) { + if (!empty($a->profile[$field])) { $json_info["$field"] = $a->profile[$field]; } } $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) { + foreach ($dfrn_pages as $dfrn) { $json_info["dfrn-{$dfrn}"] = App::get_baseurl()."/dfrn_{$dfrn}/{$which}"; } diff --git a/mod/openid.php b/mod/openid.php index 9ee1877674..09905198c9 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -56,7 +56,7 @@ function openid_content(&$a) { // Successful OpenID login - but we can't match it to an existing account. // New registration? - if($a->config['register_policy'] == REGISTER_CLOSED) { + if ($a->config['register_policy'] == REGISTER_CLOSED) { notice( t('Account not found and OpenID registration is not permitted on this site.') . EOL); goaway(z_root()); } @@ -64,31 +64,41 @@ function openid_content(&$a) { unset($_SESSION['register']); $args = ''; $attr = $openid->getAttributes(); - if(is_array($attr) && count($attr)) { - foreach($attr as $k => $v) { - if($k === 'namePerson/friendly') + if (is_array($attr) && count($attr)) { + foreach ($attr as $k => $v) { + if ($k === 'namePerson/friendly') { $nick = notags(trim($v)); - if($k === 'namePerson/first') + } + if($k === 'namePerson/first') { $first = notags(trim($v)); - if($k === 'namePerson') + } + if($k === 'namePerson') { $args .= '&username=' . notags(trim($v)); - if($k === 'contact/email') + } + if ($k === 'contact/email') { $args .= '&email=' . notags(trim($v)); - if($k === 'media/image/aspect11') + } + if ($k === 'media/image/aspect11') { $photosq = bin2hex(trim($v)); - if($k === 'media/image/default') + } + if ($k === 'media/image/default') { $photo = bin2hex(trim($v)); + } } } - if($nick) + if ($nick) { $args .= '&nickname=' . $nick; - elseif($first) + } + elseif ($first) { $args .= '&nickname=' . $first; + } - if($photosq) + if ($photosq) { $args .= '&photo=' . $photosq; - elseif($photo) + } + elseif ($photo) { $args .= '&photo=' . $photo; + } $args .= '&openid_url=' . notags(trim($authid)); diff --git a/mod/photos.php b/mod/photos.php index c60f8dd496..a4bf19e940 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -255,7 +255,7 @@ function photos_post(&$a) { ); } if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $res[] = "'" . dbesc($rr['rid']) . "'" ; } } else { @@ -277,7 +277,7 @@ function photos_post(&$a) { intval($page_owner_uid) ); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc(datetime_convert()), dbesc($rr['parent-uri']), diff --git a/mod/poco.php b/mod/poco.php index e454d1e668..a97ca64e33 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -174,7 +174,7 @@ function poco_init(&$a) { if(is_array($r)) { if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if (!isset($rr['generation'])) { if ($global) $rr['generation'] = 3; diff --git a/mod/profile.php b/mod/profile.php index 20206c7335..ae8f2fa720 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -62,7 +62,7 @@ function profile_init(&$a) { header('Link: <' . App::get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) { + foreach ($dfrn_pages as $dfrn) { $a->page['htmlhead'] .= "\r\n"; } $a->page['htmlhead'] .= "\r\n"; diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 2aca9801d2..eee15c2af2 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -201,7 +201,7 @@ function profile_photo_content(&$a) { return; } $havescale = false; - foreach($r as $rr) { + foreach ($r as $rr) { if($rr['scale'] == 5) $havescale = true; } diff --git a/mod/profiles.php b/mod/profiles.php index 4e29b93fd2..9321aacb59 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -780,24 +780,26 @@ function profiles_content(&$a) { if (dbm::is_result($r)) { $tpl = get_markup_template('profile_entry.tpl'); - foreach($r as $rr) { + + $profiles = ''; + foreach ($r as $rr) { $profiles .= replace_macros($tpl, array( - '$photo' => $a->remove_baseurl($rr['thumb']), - '$id' => $rr['id'], - '$alt' => t('Profile Image'), + '$photo' => $a->remove_baseurl($rr['thumb']), + '$id' => $rr['id'], + '$alt' => t('Profile Image'), '$profile_name' => $rr['profile-name'], - '$visible' => (($rr['is-default']) ? '' . t('visible to everybody') . '' + '$visible' => (($rr['is-default']) ? '' . t('visible to everybody') . '' : '' . t('Edit visibility') . '') )); } $tpl_header = get_markup_template('profile_listing_header.tpl'); $o .= replace_macros($tpl_header,array( - '$header' => t('Edit/Manage Profiles'), - '$chg_photo' => t('Change profile photo'), - '$cr_new' => t('Create New Profile'), + '$header' => t('Edit/Manage Profiles'), + '$chg_photo' => t('Change profile photo'), + '$cr_new' => t('Create New Profile'), '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new"), - '$profiles' => $profiles + '$profiles' => $profiles )); } return $o; diff --git a/mod/search.php b/mod/search.php index c19bb27673..3de77a85c4 100644 --- a/mod/search.php +++ b/mod/search.php @@ -17,7 +17,7 @@ function search_saved_searches() { if (dbm::is_result($r)) { $saved = array(); - foreach($r as $rr) { + foreach ($r as $rr) { $saved[] = array( 'id' => $rr['id'], 'term' => $rr['term'], diff --git a/mod/suggest.php b/mod/suggest.php index a328b9768b..0004128a1a 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -75,7 +75,7 @@ function suggest_content(&$a) { require_once 'include/contact_selectors.php'; - foreach($r as $rr) { + foreach ($r as $rr) { $connlnk = App::get_baseurl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']); $ignlnk = App::get_baseurl() . '/suggest?ignore=' . $rr['id']; diff --git a/mod/videos.php b/mod/videos.php index 53bba84c6e..dbfc044ea0 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -368,8 +368,8 @@ function videos_content(&$a) { $videos = array(); if (dbm::is_result($r)) { - foreach($r as $rr) { - if($a->theme['template_engine'] === 'internal') { + foreach ($r as $rr) { + if ($a->theme['template_engine'] === 'internal') { $alt_e = template_escape($rr['filename']); $name_e = template_escape($rr['album']); } diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php index 3fd5d79e1b..ffb7154423 100644 --- a/mod/viewcontacts.php +++ b/mod/viewcontacts.php @@ -76,9 +76,11 @@ function viewcontacts_content(&$a) { $contacts = array(); - foreach($r as $rr) { - if($rr['self']) + foreach ($r as $rr) { + /// @TODO This triggers an E_NOTICE if 'self' is not there + if ($rr['self']) { continue; + } $url = $rr['url']; From bb06d9ce32a49e83ecb709e19b70768bb6a1d37f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 20 Dec 2016 21:16:01 +0100 Subject: [PATCH 28/41] Continued with coding convention: - added curly braces around conditional code blocks - added space between if/foreach/... and brace - rewrote a code block so if dbm::is_result() fails it will abort, else the id is fetched from INSERT statement - made some SQL keywords upper-cased and added back-ticks to columns/table names Signed-off-by: Roland Haeder --- update.php | 24 ++++++++--------- view/theme/frio/theme.php | 11 ++++---- view/theme/vier/theme.php | 57 +++++++++++++++++++++++++-------------- 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/update.php b/update.php index 0679b5a1f8..7aec2ec2b8 100644 --- a/update.php +++ b/update.php @@ -86,7 +86,7 @@ function update_1006() { $r = q("SELECT * FROM `user` WHERE `spubkey` = '' "); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $sres=openssl_pkey_new(array('encrypt_key' => false )); $sprvkey = ''; openssl_pkey_export($sres, $sprvkey); @@ -123,7 +123,7 @@ function update_1011() { q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` "); $r = q("SELECT * FROM `contact` WHERE 1"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d", dbesc(basename($rr['url'])), intval($rr['id']) @@ -146,7 +146,7 @@ function update_1014() { q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` "); $r = q("SELECT * FROM `photo` WHERE `scale` = 4"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $ph = new Photo($rr['data']); if($ph->is_valid()) { $ph->scaleImage(48); @@ -156,7 +156,7 @@ function update_1014() { } $r = q("SELECT * FROM `contact` WHERE 1"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if(stristr($rr['thumb'],'avatar')) q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('avatar','micro',$rr['thumb'])), @@ -309,7 +309,7 @@ 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)) { - foreach($r as $rr) { + foreach ($r as $rr) { if(strstr($rr['object'],'type="http')) { q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", dbesc(str_replace('type="http','href="http',$rr['object'])), @@ -357,7 +357,7 @@ function update_1036() { $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' "); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('include/photo','photo',$rr['photo'])), dbesc(str_replace('include/photo','photo',$rr['thumb'])), @@ -607,7 +607,7 @@ function update_1075() { q("ALTER TABLE `user` ADD `guid` CHAR( 16 ) NOT NULL AFTER `uid` "); $r = q("SELECT `uid` FROM `user` WHERE 1"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $found = true; do { $guid = substr(random_string(),0,16); @@ -689,7 +689,7 @@ function update_1082() { return; $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $guid = get_guid(); q("update `photo` set `guid` = '%s' where `resource-id` = '%s'", dbesc($guid), @@ -732,7 +732,7 @@ function update_1087() { $r = q("SELECT `id` FROM `item` WHERE `parent` = `id` "); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1", intval($rr['id']) ); @@ -855,7 +855,7 @@ function update_1100() { $r = q("select id, url from contact where url != '' and nurl = '' "); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { q("update contact set nurl = '%s' where id = %d", dbesc(normalise_link($rr['url'])), intval($rr['id']) @@ -1169,7 +1169,7 @@ function update_1136() { $r = q("select * from config where 1 order by id desc"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $found = false; foreach($arr as $x) { if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { @@ -1188,7 +1188,7 @@ function update_1136() { $arr = array(); $r = q("select * from pconfig where 1 order by id desc"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $found = false; foreach($arr as $x) { if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 5bc5140bf1..4a320e1f87 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -271,7 +271,7 @@ function frio_remote_nav($a,&$nav) { * We use this to give the data to textcomplete and have a filter function at the * contact page. * - * @param App $a The app data + * @param App $a The app data @TODO Unused * @param array $results The array with the originals from acl_lookup() */ function frio_acl_lookup($a, &$results) { @@ -281,17 +281,18 @@ function frio_acl_lookup($a, &$results) { // we introduce a new search type, r should do the same query like it's // done in /mod/contacts for connections - if($results["type"] == "r") { + if ($results["type"] == "r") { $searching = false; - if($search) { + if ($search) { $search_hdr = $search; $search_txt = dbesc(protect_sprintf(preg_quote($search))); $searching = true; } $sql_extra .= (($searching) ? " AND (`attag` LIKE '%%".dbesc($search_txt)."%%' OR `name` LIKE '%%".dbesc($search_txt)."%%' OR `nick` LIKE '%%".dbesc($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)) : ''); @@ -312,7 +313,7 @@ function frio_acl_lookup($a, &$results) { $contacts = array(); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { $contacts[] = _contact_detail_for_template($rr); } } diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index 45dde5f449..b909a26025 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -152,7 +152,7 @@ function vier_community_info() { $aside['$comunity_profiles_title'] = t('Community Profiles'); $aside['$comunity_profiles_items'] = array(); - foreach($r as $rr) { + foreach ($r as $rr) { $entry = replace_macros($tpl,array( '$id' => $rr['id'], //'$profile_link' => zrl($rr['url']), @@ -182,7 +182,7 @@ function vier_community_info() { $aside['$lastusers_title'] = t('Last users'); $aside['$lastusers_items'] = array(); - foreach($r as $rr) { + foreach ($r as $rr) { $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']); $entry = replace_macros($tpl,array( '$id' => $rr['id'], @@ -300,7 +300,7 @@ function vier_community_info() { $aside['$helpers_items'] = array(); - foreach($r as $rr) { + foreach ($r as $rr) { $entry = replace_macros($tpl,array( '$url' => $rr['url'], '$title' => $rr['name'], @@ -316,55 +316,72 @@ function vier_community_info() { //connectable services if ($show_services) { + /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo) $r = array(); - if (plugin_enabled("appnet")) + if (plugin_enabled("appnet")) { $r[] = array("photo" => "images/appnet.png", "name" => "App.net"); + } - if (plugin_enabled("buffer")) + if (plugin_enabled("buffer")) { $r[] = array("photo" => "images/buffer.png", "name" => "Buffer"); + } - if (plugin_enabled("blogger")) + if (plugin_enabled("blogger")) { $r[] = array("photo" => "images/blogger.png", "name" => "Blogger"); + } - if (plugin_enabled("dwpost")) + if (plugin_enabled("dwpost")) { $r[] = array("photo" => "images/dreamwidth.png", "name" => "Dreamwidth"); + } - if (plugin_enabled("fbpost")) + if (plugin_enabled("fbpost")) { $r[] = array("photo" => "images/facebook.png", "name" => "Facebook"); + } - if (plugin_enabled("ifttt")) + if (plugin_enabled("ifttt")) { $r[] = array("photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"); + } - if (plugin_enabled("statusnet")) + if (plugin_enabled("statusnet")) { $r[] = array("photo" => "images/gnusocial.png", "name" => "GNU Social"); + } - if (plugin_enabled("gpluspost")) + if (plugin_enabled("gpluspost")) { $r[] = array("photo" => "images/googleplus.png", "name" => "Google+"); + } - //if (plugin_enabled("ijpost")) + //if (plugin_enabled("ijpost")) { // $r[] = array("photo" => "images/", "name" => ""); + //} - if (plugin_enabled("libertree")) + if (plugin_enabled("libertree")) { $r[] = array("photo" => "images/libertree.png", "name" => "Libertree"); + } - //if (plugin_enabled("ljpost")) + //if (plugin_enabled("ljpost")) { // $r[] = array("photo" => "images/", "name" => ""); + //} - if (plugin_enabled("pumpio")) + if (plugin_enabled("pumpio")) { $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io"); + } - if (plugin_enabled("tumblr")) + if (plugin_enabled("tumblr")) { $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr"); + } - if (plugin_enabled("twitter")) + if (plugin_enabled("twitter")) { $r[] = array("photo" => "images/twitter.png", "name" => "Twitter"); + } - if (plugin_enabled("wppost")) + if (plugin_enabled("wppost")) { $r[] = array("photo" => "images/wordpress.png", "name" => "Wordpress"); + } - if(function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only")) + if (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only")) { $r[] = array("photo" => "images/mail.png", "name" => "E-Mail"); + } $tpl = get_markup_template('ch_connectors.tpl'); @@ -374,7 +391,7 @@ function vier_community_info() { $con_services['title'] = Array("", t('Connect Services'), "", ""); $aside['$con_services'] = $con_services; - foreach($r as $rr) { + foreach ($r as $rr) { $entry = replace_macros($tpl,array( '$url' => $url, '$photo' => $rr['photo'], From b4bc07fdcce4e326d5ade05aab0f7305e874398e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 20 Dec 2016 21:31:05 +0100 Subject: [PATCH 29/41] Continued with coding convention: - added curly braces around conditional code blocks - added space between if/foreach/... and brace - made some SQL keywords upper-cased and added back-ticks to columns/table names Signed-off-by: Roland Haeder --- include/like.php | 55 +++++++++++++++++++++++++++-------------------- mod/item.php | 15 ++++++++----- mod/noscrape.php | 1 - mod/settings.php | 8 +++---- mod/starred.php | 17 +++++++++------ mod/subthread.php | 18 +++++++++------- mod/tagger.php | 5 +++-- mod/tagrm.php | 7 +++--- mod/xrd.php | 8 ++++--- 9 files changed, 78 insertions(+), 56 deletions(-) diff --git a/include/like.php b/include/like.php index b04b9b4e09..94ff33a699 100644 --- a/include/like.php +++ b/include/like.php @@ -66,7 +66,7 @@ function do_like($item_id, $verb) { $owner_uid = $item['uid']; - if(! can_write_wall($a,$owner_uid)) { + if (! can_write_wall($a,$owner_uid)) { return false; } @@ -81,8 +81,9 @@ function do_like($item_id, $verb) { if (! dbm::is_result($r)) { return false; } - if(! $r[0]['self']) + if (! $r[0]['self']) { $remote_owner = $r[0]; + } } // this represents the post owner on this system. @@ -91,21 +92,22 @@ function do_like($item_id, $verb) { WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1", intval($owner_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $owner = $r[0]; + } - if(! $owner) { + if (! $owner) { logger('like: no owner'); return false; } - if(! $remote_owner) + if (! $remote_owner) { $remote_owner = $owner; - + } // This represents the person posting - if((local_user()) && (local_user() == $owner_uid)) { + if ((local_user()) && (local_user() == $owner_uid)) { $contact = $owner; } else { @@ -116,7 +118,7 @@ function do_like($item_id, $verb) { if (dbm::is_result($r)) $contact = $r[0]; } - if(! $contact) { + if (! $contact) { return false; } @@ -125,7 +127,7 @@ function do_like($item_id, $verb) { // event participation are essentially radio toggles. If you make a subsequent choice, // we need to eradicate your first choice. - if($activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE) { + if ($activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE) { $verbs = " '" . dbesc(ACTIVITY_ATTEND) . "','" . dbesc(ACTIVITY_ATTENDNO) . "','" . dbesc(ACTIVITY_ATTENDMAYBE) . "' "; } @@ -162,8 +164,9 @@ function do_like($item_id, $verb) { $uri = item_new_uri($a->get_hostname(),$owner_uid); $post_type = (($item['resource-id']) ? t('photo') : t('status')); - if($item['object-type'] === ACTIVITY_OBJ_EVENT) + if ($item['object-type'] === ACTIVITY_OBJ_EVENT) { $post_type = t('event'); + } $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; @@ -179,20 +182,31 @@ function do_like($item_id, $verb) { $body EOT; - if($verb === 'like') + if ($verb === 'like') { $bodyverb = t('%1$s likes %2$s\'s %3$s'); - if($verb === 'dislike') + } + if ($verb === 'dislike') { $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); - if($verb === 'attendyes') + } + if ($verb === 'attendyes') { $bodyverb = t('%1$s is attending %2$s\'s %3$s'); - if($verb === 'attendno') + } + if ($verb === 'attendno') { $bodyverb = t('%1$s is not attending %2$s\'s %3$s'); - if($verb === 'attendmaybe') + } + if ($verb === 'attendmaybe') { $bodyverb = t('%1$s may attend %2$s\'s %3$s'); + } - if(! isset($bodyverb)) - return false; + if (! isset($bodyverb)) { + return false; + } + $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; + $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; + $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; + + /// @TODO Or rewrite this to multi-line initialization of the array? $arr = array(); $arr['guid'] = get_guid(32); @@ -212,12 +226,7 @@ EOT; $arr['author-name'] = $contact['name']; $arr['author-link'] = $contact['url']; $arr['author-avatar'] = $contact['thumb']; - - $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; - $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; - $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink ); - $arr['verb'] = $activity; $arr['object-type'] = $objtype; $arr['object'] = $obj; @@ -231,7 +240,7 @@ EOT; $post_id = item_store($arr); - if(! $item['visible']) { + if (! $item['visible']) { $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", intval($item['id']), intval($owner_uid) diff --git a/mod/item.php b/mod/item.php index 17cf4c6487..ca428e3d1a 100644 --- a/mod/item.php +++ b/mod/item.php @@ -645,8 +645,9 @@ function item_post(&$a) { intval($mtch) ); if (dbm::is_result($r)) { - if(strlen($attachments)) + if (strlen($attachments)) { $attachments .= ','; + } $attachments .= '[attach]href="' . App::get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]'; } $body = str_replace($match[1],'',$body); @@ -655,14 +656,17 @@ function item_post(&$a) { $wall = 0; - if($post_type === 'wall' || $post_type === 'wall-comment') + if ($post_type === 'wall' || $post_type === 'wall-comment') { $wall = 1; + } - if(! strlen($verb)) + if (! strlen($verb)) { $verb = ACTIVITY_POST ; + } - if ($network == "") + if ($network == "") { $network = NETWORK_DFRN; + } $gravity = (($parent) ? 6 : 0 ); @@ -676,8 +680,9 @@ function item_post(&$a) { $uri = (($message_id) ? $message_id : item_new_uri($a->get_hostname(),$profile_uid, $guid)); // Fallback so that we alway have a thr-parent - if(!$thr_parent) + if (!$thr_parent) { $thr_parent = $uri; + } $datarray = array(); $datarray['uid'] = $profile_uid; diff --git a/mod/noscrape.php b/mod/noscrape.php index 939ccbf79a..3d298cfe39 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -26,7 +26,6 @@ function noscrape_init(&$a) { $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); $keywords = explode(',', $keywords); - /// @TODO This query's result is not being used (see below), maybe old-lost code? $r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d", intval($a->profile['uid'])); diff --git a/mod/settings.php b/mod/settings.php index cedee18473..d9c28ac379 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -627,7 +627,7 @@ function settings_post(&$a) { ); } - if(($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) { + if (($old_visibility != $net_publish) || ($page_flags != $old_page_flags)) { // Update global directory in background $url = $_SESSION['my_url']; if ($url && strlen(get_config('system','directory'))) { @@ -642,10 +642,10 @@ function settings_post(&$a) { update_gcontact_for_user(local_user()); //$_SESSION['theme'] = $theme; - if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) { + if ($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) { - // FIXME - set to un-verified, blocked and redirect to logout - // Why? Are we verifying people or email addresses? + /// @TODO set to un-verified, blocked and redirect to logout + /// @TODO Why? Are we verifying people or email addresses? } diff --git a/mod/starred.php b/mod/starred.php index 7ee531e447..beaa3b87d5 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -17,7 +17,7 @@ function starred_init(&$a) { killme(); } - $r = q("SELECT starred FROM item WHERE uid = %d AND id = %d LIMIT 1", + $r = q("SELECT `starred` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval(local_user()), intval($message_id) ); @@ -25,10 +25,11 @@ function starred_init(&$a) { killme(); } - if(! intval($r[0]['starred'])) + if (! intval($r[0]['starred'])) { $starred = 1; + } - $r = q("UPDATE item SET starred = %d WHERE uid = %d and id = %d", + $r = q("UPDATE `item` SET `starred` = %d WHERE `uid` = %d AND `id` = %d", intval($starred), intval(local_user()), intval($message_id) @@ -38,10 +39,14 @@ function starred_init(&$a) { // See if we've been passed a return path to redirect to $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); - if($return_path) { + if ($return_path) { $rand = '_=' . time(); - if(strpos($return_path, '?')) $rand = "&$rand"; - else $rand = "?$rand"; + if (strpos($return_path, '?')) { + $rand = "&$rand"; + } + else { + $rand = "?$rand"; + } goaway(App::get_baseurl() . "/" . $return_path . $rand); } diff --git a/mod/subthread.php b/mod/subthread.php index 81cb1fcc11..c154187a69 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -44,8 +44,9 @@ function subthread_content(&$a) { if (! dbm::is_result($r)) { return; } - if(! $r[0]['self']) + if (! $r[0]['self']) { $remote_owner = $r[0]; + } } // this represents the post owner on this system. @@ -57,18 +58,18 @@ function subthread_content(&$a) { if (dbm::is_result($r)) $owner = $r[0]; - if(! $owner) { + if (! $owner) { logger('like: no owner'); return; } - if(! $remote_owner) + if (! $remote_owner) $remote_owner = $owner; // This represents the person posting - if((local_user()) && (local_user() == $owner_uid)) { + if ((local_user()) && (local_user() == $owner_uid)) { $contact = $owner; } else { @@ -79,7 +80,7 @@ function subthread_content(&$a) { if (dbm::is_result($r)) $contact = $r[0]; } - if(! $contact) { + if (! $contact) { return; } @@ -103,8 +104,9 @@ function subthread_content(&$a) { EOT; $bodyverb = t('%1$s is following %2$s\'s %3$s'); - if(! isset($bodyverb)) - return; + if (! isset($bodyverb)) { + return; + } $arr = array(); @@ -144,7 +146,7 @@ EOT; $post_id = item_store($arr); - if(! $item['visible']) { + if (! $item['visible']) { $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", intval($item['id']), intval($owner_uid) diff --git a/mod/tagger.php b/mod/tagger.php index 4055edddbd..e53bc5eaf1 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -94,8 +94,9 @@ EOT; $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s'); - if(! isset($bodyverb)) - return; + if (! isset($bodyverb)) { + return; + } $termlink = html_entity_decode('⌗') . '[url=' . App::get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]'; diff --git a/mod/tagrm.php b/mod/tagrm.php index acdbd6a9c2..7a18d65d06 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -59,7 +59,7 @@ function tagrm_content(&$a) { } $item = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if(! $item) { + if (! $item) { goaway(App::get_baseurl() . '/' . $_SESSION['photo_return']); // NOTREACHED } @@ -87,8 +87,7 @@ function tagrm_content(&$a) { $o .= ''; $o .= '
      '; - - foreach($arr as $x) { + foreach ($arr as $x) { $o .= '
    • ' . bbcode($x) . '
    • '; } @@ -98,5 +97,5 @@ function tagrm_content(&$a) { $o .= ''; return $o; - + } diff --git a/mod/xrd.php b/mod/xrd.php index 290c524a7d..e4641f5a35 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -41,13 +41,15 @@ function xrd_init(&$a) { $profile_url = App::get_baseurl().'/profile/'.$r[0]['nickname']; - if ($acct) + if ($acct) { $alias = $profile_url; + } else { $alias = 'acct:'.$r[0]['nickname'].'@'.$a->get_hostname(); - if ($a->get_path()) + if ($a->get_path()) { $alias .= '/'.$a->get_path(); + } } $o = replace_macros($tpl, array( @@ -65,7 +67,7 @@ function xrd_init(&$a) { '$salmen' => App::get_baseurl() . '/salmon/' . $r[0]['nickname'] . '/mention', '$subscribe' => App::get_baseurl() . '/follow?url={uri}', '$modexp' => 'data:application/magic-public-key,' . $salmon_key, - '$bigkey' => salmon_key($r[0]['pubkey']) + '$bigkey' => salmon_key($r[0]['pubkey']), )); From 3befdc6920727cf8cdca4044e2333819de81a549 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 20 Dec 2016 21:51:25 +0100 Subject: [PATCH 30/41] used more App::get_baseurl() instead of get_app()->get_baseurl(). Signed-off-by: Roland Haeder --- include/poller.php | 2 +- mod/proxy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/poller.php b/include/poller.php index 44f4895cdb..a6671f5ae3 100644 --- a/include/poller.php +++ b/include/poller.php @@ -484,7 +484,7 @@ function call_worker() { return; } - $url = get_app()->get_baseurl()."/worker"; + $url = App::get_baseurl()."/worker"; fetch_url($url, false, $redirects, 1); } diff --git a/mod/proxy.php b/mod/proxy.php index ff58bba7f1..45c9e94569 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -326,7 +326,7 @@ function proxy_is_local_image($url) { if (strtolower(substr($url, 0, 5)) == "data:") return true; // links normalised - bug #431 - $baseurl = normalise_link(get_app()->get_baseurl()); + $baseurl = normalise_link(App::get_baseurl()); $url = normalise_link($url); return (substr($url, 0, strlen($baseurl)) == $baseurl); } From c0ec9c59077cdc3c7c98a2882fe5007ecc04438f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 19 Dec 2016 20:19:26 -0500 Subject: [PATCH 31/41] proxy_url: Fix extension extraction for URLs containing a . after a ? --- mod/proxy.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mod/proxy.php b/mod/proxy.php index 45c9e94569..af0f912616 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -281,14 +281,14 @@ function proxy_url($url, $writemode = false, $size = '') { $longpath .= '/' . strtr(base64_encode($url), '+/', '-_'); - // Checking for valid extensions. Only add them if they are safe - $pos = strrpos($url, '.'); - if ($pos) { - $extension = strtolower(substr($url, $pos + 1)); - $pos = strpos($extension, '?'); - if ($pos) { - $extension = substr($extension, 0, $pos); - } + // Extract the URL extension, disregarding GET parameters starting with ? + $question_mark_pos = strpos($url, '?'); + if ($question_mark_pos === false) { + $question_mark_pos = strlen($url); + } + $dot_pos = strrpos($url, '.', $question_mark_pos - strlen($url)); + if ($dot_pos !== false) { + $extension = strtolower(substr($url, $dot_pos + 1, $question_mark_pos - ($dot_pos + 1))); } $extensions = array('jpg', 'jpeg', 'gif', 'png'); From 1f94cb9aac1d329dcb49245493ec42a197b8f17a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 15:14:43 -0500 Subject: [PATCH 32/41] proxy: Simplify url extension extraction --- mod/proxy.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mod/proxy.php b/mod/proxy.php index af0f912616..4f3c994d75 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -281,15 +281,8 @@ function proxy_url($url, $writemode = false, $size = '') { $longpath .= '/' . strtr(base64_encode($url), '+/', '-_'); - // Extract the URL extension, disregarding GET parameters starting with ? - $question_mark_pos = strpos($url, '?'); - if ($question_mark_pos === false) { - $question_mark_pos = strlen($url); - } - $dot_pos = strrpos($url, '.', $question_mark_pos - strlen($url)); - if ($dot_pos !== false) { - $extension = strtolower(substr($url, $dot_pos + 1, $question_mark_pos - ($dot_pos + 1))); - } + // Extract the URL extension + $extension = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION); $extensions = array('jpg', 'jpeg', 'gif', 'png'); if (in_array($extension, $extensions)) { From 47f88bd625b85690414f1465cf8082e1ec83ef31 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 15:23:08 -0500 Subject: [PATCH 33/41] proxy mod: Standards bearer - Enforced PSR-2 standards - Normalized concatenation formatting - Normalized string delimiters - Normalized condition operators - Collapsed directly nested conditions - Used dvm::is_result - Added comments --- mod/proxy.php | 289 +++++++++++++++++++++++++++----------------------- 1 file changed, 154 insertions(+), 135 deletions(-) diff --git a/mod/proxy.php b/mod/proxy.php index 4f3c994d75..3fdb250b5c 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -1,20 +1,18 @@ -define("PROXY_DEFAULT_TIME", 86400); // 1 Day +define('PROXY_DEFAULT_TIME', 86400); // 1 Day -define("PROXY_SIZE_MICRO", "micro"); -define("PROXY_SIZE_THUMB", "thumb"); -define("PROXY_SIZE_SMALL", "small"); -define("PROXY_SIZE_MEDIUM", "medium"); -define("PROXY_SIZE_LARGE", "large"); +define('PROXY_SIZE_MICRO', 'micro'); +define('PROXY_SIZE_THUMB', 'thumb'); +define('PROXY_SIZE_SMALL', 'small'); +define('PROXY_SIZE_MEDIUM', 'medium'); +define('PROXY_SIZE_LARGE', 'large'); -require_once('include/security.php'); -require_once("include/Photo.php"); - -function proxy_init() { - global $a, $_SERVER; +require_once 'include/security.php'; +require_once 'include/Photo.php'; +function proxy_init(App $a) { // Pictures are stored in one of the following ways: // 1. If a folder "proxy" exists and is writeable, then use this for caching // 2. If a cache path is defined, use this @@ -24,11 +22,12 @@ function proxy_init() { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header('HTTP/1.1 304 Not Modified'); - header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); - header('Etag: '.$_SERVER['HTTP_IF_NONE_MATCH']); - header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); - header("Cache-Control: max-age=31536000"); - if(function_exists('header_remove')) { + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); + header('Etag: ' . $_SERVER['HTTP_IF_NONE_MATCH']); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); + header('Cache-Control: max-age=31536000'); + + if (function_exists('header_remove')) { header_remove('Last-Modified'); header_remove('Expires'); header_remove('Cache-Control'); @@ -36,140 +35,155 @@ function proxy_init() { exit; } - if(function_exists('header_remove')) { + if (function_exists('header_remove')) { header_remove('Pragma'); header_remove('pragma'); } $thumb = false; $size = 1024; - $sizetype = ""; + $sizetype = ''; $basepath = $a->get_basepath(); // If the cache path isn't there, try to create it - if (!is_dir($basepath."/proxy")) - if (is_writable($basepath)) - mkdir($basepath."/proxy"); + if (!is_dir($basepath . '/proxy') AND is_writable($basepath)) { + mkdir($basepath . '/proxy'); + } // Checking if caching into a folder in the webroot is activated and working - $direct_cache = (is_dir($basepath."/proxy") AND is_writable($basepath."/proxy")); + $direct_cache = (is_dir($basepath . '/proxy') AND is_writable($basepath . '/proxy')); // Look for filename in the arguments - if ((isset($a->argv[1]) OR isset($a->argv[2]) OR isset($a->argv[3])) AND !isset($_REQUEST["url"])) { - if (isset($a->argv[3])) + if ((isset($a->argv[1]) OR isset($a->argv[2]) OR isset($a->argv[3])) AND !isset($_REQUEST['url'])) { + if (isset($a->argv[3])) { $url = $a->argv[3]; - elseif (isset($a->argv[2])) + } elseif (isset($a->argv[2])) { $url = $a->argv[2]; - else + } else { $url = $a->argv[1]; - - if (isset($a->argv[3]) and ($a->argv[3] == "thumb")) - $size = 200; - - // thumb, small, medium and large. - if (substr($url, -6) == ":micro") { - $size = 48; - $sizetype = ":micro"; - $url = substr($url, 0, -6); - } elseif (substr($url, -6) == ":thumb") { - $size = 80; - $sizetype = ":thumb"; - $url = substr($url, 0, -6); - } elseif (substr($url, -6) == ":small") { - $size = 175; - $url = substr($url, 0, -6); - $sizetype = ":small"; - } elseif (substr($url, -7) == ":medium") { - $size = 600; - $url = substr($url, 0, -7); - $sizetype = ":medium"; - } elseif (substr($url, -6) == ":large") { - $size = 1024; - $url = substr($url, 0, -6); - $sizetype = ":large"; } - $pos = strrpos($url, "=."); - if ($pos) - $url = substr($url, 0, $pos+1); + if (isset($a->argv[3]) AND ($a->argv[3] == 'thumb')) { + $size = 200; + } - $url = str_replace(array(".jpg", ".jpeg", ".gif", ".png"), array("","","",""), $url); + // thumb, small, medium and large. + if (substr($url, -6) == ':micro') { + $size = 48; + $sizetype = ':micro'; + $url = substr($url, 0, -6); + } elseif (substr($url, -6) == ':thumb') { + $size = 80; + $sizetype = ':thumb'; + $url = substr($url, 0, -6); + } elseif (substr($url, -6) == ':small') { + $size = 175; + $url = substr($url, 0, -6); + $sizetype = ':small'; + } elseif (substr($url, -7) == ':medium') { + $size = 600; + $url = substr($url, 0, -7); + $sizetype = ':medium'; + } elseif (substr($url, -6) == ':large') { + $size = 1024; + $url = substr($url, 0, -6); + $sizetype = ':large'; + } + + $pos = strrpos($url, '=.'); + if ($pos) { + $url = substr($url, 0, $pos + 1); + } + + $url = str_replace(array('.jpg', '.jpeg', '.gif', '.png'), array('','','',''), $url); $url = base64_decode(strtr($url, '-_', '+/'), true); - if ($url) + if ($url) { $_REQUEST['url'] = $url; - } else + } + } else { $direct_cache = false; + } if (!$direct_cache) { $urlhash = 'pic:' . sha1($_REQUEST['url']); - $cachefile = get_cachefile(hash("md5", $_REQUEST['url'])); - if ($cachefile != '') { - if (file_exists($cachefile)) { - $img_str = file_get_contents($cachefile); - $mime = image_type_to_mime_type(exif_imagetype($cachefile)); + $cachefile = get_cachefile(hash('md5', $_REQUEST['url'])); + if ($cachefile != '' AND file_exists($cachefile)) { + $img_str = file_get_contents($cachefile); + $mime = image_type_to_mime_type(exif_imagetype($cachefile)); - header("Content-type: $mime"); - header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); - header('Etag: "'.md5($img_str).'"'); - header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); - header("Cache-Control: max-age=31536000"); + header('Content-type: ' . $mime); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); + header('Etag: "' . md5($img_str) . '"'); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); + header('Cache-Control: max-age=31536000'); - // reduce quality - if it isn't a GIF - if ($mime != "image/gif") { - $img = new Photo($img_str, $mime); - if($img->is_valid()) { - $img_str = $img->imageString(); - } + // reduce quality - if it isn't a GIF + if ($mime != 'image/gif') { + $img = new Photo($img_str, $mime); + if ($img->is_valid()) { + $img_str = $img->imageString(); } - - echo $img_str; - killme(); } + + echo $img_str; + killme(); } - } else - $cachefile = ""; + } else { + $cachefile = ''; + } $valid = true; - if (!$direct_cache AND ($cachefile == "")) { + if (!$direct_cache AND ($cachefile == '')) { $r = qu("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash); if (dbm::is_result($r)) { +<<<<<<< origin/rewrites/app_get_baseurl_static $img_str = $r[0]['data']; $mime = $r[0]["desc"]; if ($mime == "") $mime = "image/jpeg"; +======= + $img_str = $r[0]['data']; + $mime = $r[0]['desc']; + if ($mime == '') { + $mime = 'image/jpeg'; + } +>>>>>>> HEAD~0 } - } else + } else { $r = array(); + } if (!dbm::is_result($r)) { // It shouldn't happen but it does - spaces in URL - $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']); + $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $redirects = 0; - $img_str = fetch_url($_REQUEST['url'],true, $redirects, 10); + $img_str = fetch_url($_REQUEST['url'], true, $redirects, 10); - $tempfile = tempnam(get_temppath(), "cache"); + $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); $mime = image_type_to_mime_type(exif_imagetype($tempfile)); unlink($tempfile); // If there is an error then return a blank image - if ((substr($a->get_curl_code(), 0, 1) == "4") or (!$img_str)) { - $img_str = file_get_contents("images/blank.png"); - $mime = "image/png"; - $cachefile = ""; // Clear the cachefile so that the dummy isn't stored + if ((substr($a->get_curl_code(), 0, 1) == '4') OR (!$img_str)) { + $img_str = file_get_contents('images/blank.png'); + $mime = 'image/png'; + $cachefile = ''; // Clear the cachefile so that the dummy isn't stored $valid = false; - $img = new Photo($img_str, "image/png"); - if($img->is_valid()) { + $img = new Photo($img_str, 'image/png'); + if ($img->is_valid()) { $img->scaleImage(10); $img_str = $img->imageString(); } - } else if (($mime != "image/jpeg") AND !$direct_cache AND ($cachefile == "")) { + } elseif ($mime != 'image/jpeg' AND !$direct_cache AND $cachefile == '') { $image = @imagecreatefromstring($img_str); - if($image === FALSE) die(); + if ($image === FALSE) { + die(); + } q("INSERT INTO `photo` ( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `desc`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) @@ -177,7 +191,7 @@ function proxy_init() { 0, 0, get_guid(), dbesc($urlhash), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc(basename(dbesc($_REQUEST["url"]))), + dbesc(basename(dbesc($_REQUEST['url']))), dbesc(''), intval(imagesy($image)), intval(imagesx($image)), @@ -190,9 +204,8 @@ function proxy_init() { } else { $img = new Photo($img_str, $mime); - if($img->is_valid()) { - if (!$direct_cache AND ($cachefile == "")) - $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); + if ($img->is_valid() AND !$direct_cache AND ($cachefile == '')) { + $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); } } } @@ -200,9 +213,9 @@ function proxy_init() { $img_str_orig = $img_str; // reduce quality - if it isn't a GIF - if ($mime != "image/gif") { + if ($mime != 'image/gif') { $img = new Photo($img_str, $mime); - if($img->is_valid()) { + if ($img->is_valid()) { $img->scaleImage($size); $img_str = $img->imageString(); } @@ -212,20 +225,22 @@ function proxy_init() { // advantage: real file access is really fast // Otherwise write in cachefile if ($valid AND $direct_cache) { - file_put_contents($basepath."/proxy/".proxy_url($_REQUEST['url'], true), $img_str_orig); - if ($sizetype <> '') - file_put_contents($basepath."/proxy/".proxy_url($_REQUEST['url'], true).$sizetype, $img_str); - } elseif ($cachefile != '') + file_put_contents($basepath . '/proxy/' . proxy_url($_REQUEST['url'], true), $img_str_orig); + if ($sizetype != '') { + file_put_contents($basepath . '/proxy/' . proxy_url($_REQUEST['url'], true) . $sizetype, $img_str); + } + } elseif ($cachefile != '') { file_put_contents($cachefile, $img_str_orig); + } - header("Content-type: $mime"); + header('Content-type: ' . $mime); // Only output the cache headers when the file is valid if ($valid) { - header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); - header('Etag: "'.md5($img_str).'"'); - header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); - header("Cache-Control: max-age=31536000"); + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); + header('Etag: "' . md5($img_str) . '"'); + header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); + header('Cache-Control: max-age=31536000'); } echo $img_str; @@ -272,11 +287,9 @@ function proxy_url($url, $writemode = false, $size = '') { $shortpath = hash('md5', $url); $longpath = substr($shortpath, 0, 2); - if (is_dir($basepath) and $writemode) { - if (!is_dir($basepath . '/' . $longpath)) { - mkdir($basepath . '/' . $longpath); - chmod($basepath . '/' . $longpath, 0777); - } + if (is_dir($basepath) AND $writemode AND !is_dir($basepath . '/' . $longpath)) { + mkdir($basepath . '/' . $longpath); + chmod($basepath . '/' . $longpath, 0777); } $longpath .= '/' . strtr(base64_encode($url), '+/', '-_'); @@ -314,9 +327,13 @@ function proxy_url($url, $writemode = false, $size = '') { * @return boolean */ function proxy_is_local_image($url) { - if ($url[0] == '/') return true; + if ($url[0] == '/') { + return true; + } - if (strtolower(substr($url, 0, 5)) == "data:") return true; + if (strtolower(substr($url, 0, 5)) == 'data:') { + return true; + } // links normalised - bug #431 $baseurl = normalise_link(App::get_baseurl()); @@ -324,42 +341,44 @@ function proxy_is_local_image($url) { return (substr($url, 0, strlen($baseurl)) == $baseurl); } -function proxy_parse_query($var) { - /** - * Use this function to parse out the query array element from - * the output of parse_url(). - */ - $var = parse_url($var, PHP_URL_QUERY); - $var = html_entity_decode($var); - $var = explode('&', $var); - $arr = array(); +/** + * @brief Return the array of query string parameters from a URL + * + * @param string $url + * @return array Associative array of query string parameters + */ +function proxy_parse_query($url) { + $query = parse_url($url, PHP_URL_QUERY); + $query = html_entity_decode($query); + $query_list = explode('&', $query); + $arr = array(); - foreach($var as $val) { - $x = explode('=', $val); - $arr[$x[0]] = $x[1]; - } + foreach ($query_list as $key_value) { + $key_value_list = explode('=', $key_value); + $arr[$key_value_list[0]] = $key_value_list[1]; + } - unset($val, $x, $var); - return $arr; + unset($url, $query_list, $url); + return $arr; } function proxy_img_cb($matches) { - // if the picture seems to be from another picture cache then take the original source $queryvar = proxy_parse_query($matches[2]); - if (($queryvar['url'] != "") AND (substr($queryvar['url'], 0, 4) == "http")) + if (($queryvar['url'] != '') AND (substr($queryvar['url'], 0, 4) == 'http')) { $matches[2] = urldecode($queryvar['url']); + } // following line changed per bug #431 - if (proxy_is_local_image($matches[2])) + if (proxy_is_local_image($matches[2])) { return $matches[1] . $matches[2] . $matches[3]; + } - return $matches[1].proxy_url(htmlspecialchars_decode($matches[2])).$matches[3]; + return $matches[1] . proxy_url(htmlspecialchars_decode($matches[2])) . $matches[3]; } function proxy_parse_html($html) { - $a = get_app(); - $html = str_replace(normalise_link(App::get_baseurl())."/", App::get_baseurl()."/", $html); + $html = str_replace(normalise_link(App::get_baseurl()) . '/', App::get_baseurl() . '/', $html); - return preg_replace_callback("/(]*src *= *[\"'])([^\"']+)([\"'][^>]*>)/siU", "proxy_img_cb", $html); + return preg_replace_callback('/(]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'proxy_img_cb', $html); } From bb37cac77281675251f5238e3a7a87a3faf4677c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 21 Dec 2016 09:30:49 +0100 Subject: [PATCH 34/41] added curly braces + space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/events.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mod/events.php b/mod/events.php index 9b5f7cce89..36d8f0cf71 100644 --- a/mod/events.php +++ b/mod/events.php @@ -13,15 +13,15 @@ function events_init(&$a) { return; } - if($a->argc == 1) { + if ($a->argc == 1) { // if it's a json request abort here becaus we don't // need the widget data - if($a->argv[1] === 'json') + if ($a->argv[1] === 'json') return; $cal_widget = widget_events(); - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) $a->page['aside'] = ''; $a->page['aside'] .= $cal_widget; @@ -51,33 +51,35 @@ function events_post(&$a) { // The default setting for the `private` field in event_store() is false, so mirror that $private_event = false; - if($start_text) { + if ($start_text) { $start = $start_text; } else { $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute); } - if($nofinish) { + if ($nofinish) { $finish = '0000-00-00 00:00:00'; } - if($finish_text) { + if ($finish_text) { $finish = $finish_text; } else { $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute); } - if($adjust) { + if ($adjust) { $start = datetime_convert(date_default_timezone_get(),'UTC',$start); - if(! $nofinish) + if (! $nofinish) { $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish); + } } else { $start = datetime_convert('UTC','UTC',$start); - if(! $nofinish) + if (! $nofinish) { $finish = datetime_convert('UTC','UTC',$finish); + } } // Don't allow the event to finish before it begins. @@ -93,9 +95,9 @@ function events_post(&$a) { $action = ($event_id == '') ? 'new' : "event/" . $event_id; $onerror_url = App::get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish"; - if(strcmp($finish,$start) < 0 && !$nofinish) { + if (strcmp($finish,$start) < 0 && !$nofinish) { notice( t('Event can not end before it has started.') . EOL); - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { echo( t('Event can not end before it has started.')); killme(); } From d80b82c55d912f4de356923d504fc7594c89918b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 21 Dec 2016 22:53:08 +0100 Subject: [PATCH 35/41] no need for this else block Signed-off-by: Roland Haeder --- mod/proxy.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mod/proxy.php b/mod/proxy.php index e14f08570c..a8c24cf088 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -136,6 +136,7 @@ function proxy_init(App $a) { } $valid = true; + $r = array(); if (!$direct_cache AND ($cachefile == '')) { $r = qu("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash); @@ -158,8 +159,6 @@ function proxy_init(App $a) { ======= >>>>>>> upstream/develop } - } else { - $r = array(); } if (!dbm::is_result($r)) { From d97b6a2eba8bfe3af636cb154246b7791d807337 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 21 Dec 2016 23:04:09 +0100 Subject: [PATCH 36/41] added curly braces/spaces + replace spaces with tabs to fix code indending (or so?) Signed-off-by: Roland Haeder --- include/message.php | 3 +- mod/dirfind.php | 13 +++---- mod/follow.php | 18 +++++----- mod/home.php | 7 ++-- mod/install.php | 88 +++++++++++++++++++++++---------------------- mod/invite.php | 48 ++++++++++++------------- mod/starred.php | 3 +- 7 files changed, 88 insertions(+), 92 deletions(-) diff --git a/include/message.php b/include/message.php index 5bd611f220..3d5d4d33ab 100644 --- a/include/message.php +++ b/include/message.php @@ -153,8 +153,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ if ($post_id) { proc_run(PRIORITY_HIGH, "include/notifier.php", "mail", $post_id); return intval($post_id); - } - else { + } else { return -3; } diff --git a/mod/dirfind.php b/mod/dirfind.php index 1a78421671..0ac82f2817 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -88,20 +88,19 @@ function dirfind_content(&$a, $prefix = "") { if (get_config('system','diaspora_enabled')) { $diaspora = NETWORK_DIASPORA; - } - else { + } else { $diaspora = NETWORK_DFRN; } if (!get_config('system','ostatus_disabled')) { $ostatus = NETWORK_OSTATUS; - } - else { + } else { $ostatus = NETWORK_DFRN; } $search2 = "%".$search."%"; + /// @TODO These 2 SELECTs are not checked on validity with dbm::is_result() $count = q("SELECT count(*) AS `total` FROM `gcontact` LEFT JOIN `contact` ON `contact`.`nurl` = `gcontact`.`nurl` AND `contact`.`network` = `gcontact`.`network` @@ -200,8 +199,7 @@ function dirfind_content(&$a, $prefix = "") { $photo_menu = contact_photo_menu($contact[0]); $details = _contact_detail_for_template($contact[0]); $alt_text = $details['alt_text']; - } - else { + } else { $photo_menu = array(); } } else { @@ -243,8 +241,7 @@ function dirfind_content(&$a, $prefix = "") { '$paginate' => paginate($a), )); - } - else { + } else { info( t('No matches') . EOL); } diff --git a/mod/follow.php b/mod/follow.php index eb5570e8ab..2e970ad0cb 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -56,10 +56,11 @@ function follow_content(&$a) { // NOTREACHED } - if ($ret["network"] == NETWORK_MAIL) + if ($ret["network"] == NETWORK_MAIL) { $ret["url"] = $ret["addr"]; + } - if($ret['network'] === NETWORK_DFRN) { + if ($ret['network'] === NETWORK_DFRN) { $request = $ret["request"]; $tpl = get_markup_template('dfrn_request.tpl'); } else { @@ -84,20 +85,22 @@ function follow_content(&$a) { $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($ret["url"])); - if (!$r) + if (!$r) { $r = array(array("location" => "", "about" => "", "keywords" => "")); - else + } else { $gcontact_id = $r[0]["id"]; + } - if($ret['network'] === NETWORK_DIASPORA) { + if ($ret['network'] === NETWORK_DIASPORA) { $r[0]["location"] = ""; $r[0]["about"] = ""; } $header = $ret["name"]; - if ($ret["addr"] != "") + if ($ret["addr"] != "") { $header .= " <".$ret["addr"].">"; + } //$header .= " (".network_to_name($ret['network'], $ret['url']).")"; $header = t("Connect/Follow"); @@ -176,8 +179,7 @@ function follow_post(&$a) { notice($result['message']); } goaway($return_url); - } - elseif ($result['cid']) { + } elseif ($result['cid']) { goaway(App::get_baseurl().'/contacts/'.$result['cid']); } diff --git a/mod/home.php b/mod/home.php index 0e83340cc3..eb5d1e90b0 100644 --- a/mod/home.php +++ b/mod/home.php @@ -16,7 +16,6 @@ function home_init(&$a) { }} - if(! function_exists('home_content')) { function home_content(&$a) { @@ -35,9 +34,8 @@ function home_content(&$a) { $a->page['htmlhead'] .= ''; } - $o .= file_get_contents('home.html');} - - else { + $o .= file_get_contents('home.html'); + } else { $o .= '

      '.((x($a->config,'sitename')) ? sprintf(t("Welcome to %s"), $a->config['sitename']) : "").'

      '; } @@ -48,5 +46,4 @@ function home_content(&$a) { return $o; - }} diff --git a/mod/install.php b/mod/install.php index 73216e7f88..b13da8c28f 100755 --- a/mod/install.php +++ b/mod/install.php @@ -11,17 +11,16 @@ function install_init(&$a){ echo "ok"; killme(); } - + // We overwrite current theme css, because during install we could not have a working mod_rewrite // so we could not have a css at all. Here we set a static css file for the install procedure pages $a->config['system']['theme'] = "../install"; $a->theme['stylesheet'] = App::get_baseurl()."/view/install/style.css"; - - - + global $install_wizard_pass; - if (x($_POST,'pass')) + if (x($_POST,'pass')) { $install_wizard_pass = intval($_POST['pass']); + } } @@ -63,7 +62,7 @@ function install_post(&$a) { return; } }*/ - if(get_db_errno()) { + if (get_db_errno()) { $a->data['db_conn_failed']=true; } @@ -107,17 +106,18 @@ function install_post(&$a) { $result = file_put_contents('.htconfig.php', $txt); - if(! $result) { + if (! $result) { $a->data['txt'] = $txt; } $errors = load_database($db); - if($errors) + if ($errors) { $a->data['db_failed'] = $errors; - else + } else { $a->data['db_installed'] = true; + } return; break; @@ -125,10 +125,11 @@ function install_post(&$a) { } function get_db_errno() { - if(class_exists('mysqli')) + if (class_exists('mysqli')) { return mysqli_connect_errno(); - else + } else { return mysql_errno(); + } } function install_content(&$a) { @@ -140,23 +141,23 @@ function install_content(&$a) { - if(x($a->data,'db_conn_failed')) { + if (x($a->data,'db_conn_failed')) { $install_wizard_pass = 2; $wizard_status = t('Could not connect to database.'); } - if(x($a->data,'db_create_failed')) { + if (x($a->data,'db_create_failed')) { $install_wizard_pass = 2; $wizard_status = t('Could not create table.'); } $db_return_text=""; - if(x($a->data,'db_installed')) { + if (x($a->data,'db_installed')) { $txt = '

      '; $txt .= t('Your Friendica site database has been installed.') . EOL; $db_return_text .= $txt; } - if(x($a->data,'db_failed')) { + if (x($a->data,'db_failed')) { $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL; $txt .= t('Please see the file "INSTALL.txt".') . EOL ."


      " ; $txt .= "
      ".$a->data['db_failed'] . "
      ". EOL ; @@ -176,7 +177,7 @@ function install_content(&$a) { } } - if(x($a->data,'txt') && strlen($a->data['txt'])) { + if (x($a->data,'txt') && strlen($a->data['txt'])) { $db_return_text .= manual_config($a); } @@ -205,16 +206,19 @@ function install_content(&$a) { check_keys($checks); - if(x($_POST,'phpath')) + if (x($_POST,'phpath')) { $phpath = notags(trim($_POST['phpath'])); + } check_php($phpath, $checks); - check_htaccess($checks); + check_htaccess($checks); + /// @TODO Maybe move this out? function check_passed($v, $c){ - if ($c['required']) + if ($c['required']) { $v = $v && $c['status']; + } return $v; } $checkspassed = array_reduce($checks, "check_passed", true); @@ -343,7 +347,7 @@ function check_php(&$phpath, &$checks) { $passed = strlen($phpath); } $help = ""; - if(!$passed) { + if (!$passed) { $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL; $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run background polling via cron. See 'Setup the poller'") . EOL ; $help .= EOL . EOL ; @@ -370,7 +374,7 @@ function check_php(&$phpath, &$checks) { } - if($passed2) { + if ($passed2) { $str = autoname(8); $cmd = "$phpath testargs.php $str"; $result = trim(shell_exec($cmd)); @@ -392,15 +396,17 @@ function check_keys(&$checks) { $res = false; - if(function_exists('openssl_pkey_new')) - $res=openssl_pkey_new(array( - 'digest_alg' => 'sha1', - 'private_key_bits' => 4096, - 'encrypt_key' => false )); + if (function_exists('openssl_pkey_new')) { + $res = openssl_pkey_new(array( + 'digest_alg' => 'sha1', + 'private_key_bits' => 4096, + 'encrypt_key' => false + )); + } // Get private key - if(! $res) { + if (! $res) { $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL; $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".'); } @@ -420,7 +426,7 @@ function check_funcs(&$checks) { check_add($ck_funcs, t('XML PHP module'), true, true, ""); check_add($ck_funcs, t('iconv module'), true, true, ""); - if(function_exists('apache_get_modules')){ + if (function_exists('apache_get_modules')){ if (! in_array('mod_rewrite',apache_get_modules())) { check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.')); } else { @@ -428,31 +434,31 @@ function check_funcs(&$checks) { } } - if(! function_exists('curl_init')){ + if (! function_exists('curl_init')){ $ck_funcs[0]['status']= false; $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.'); } - if(! function_exists('imagecreatefromjpeg')){ + if (! function_exists('imagecreatefromjpeg')){ $ck_funcs[1]['status']= false; $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.'); } - if(! function_exists('openssl_public_encrypt')) { + if (! function_exists('openssl_public_encrypt')) { $ck_funcs[2]['status']= false; $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.'); } - if(! function_exists('mysqli_connect')){ + if (! function_exists('mysqli_connect')){ $ck_funcs[3]['status']= false; $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.'); } - if(! function_exists('mb_strlen')){ + if (! function_exists('mb_strlen')){ $ck_funcs[4]['status']= false; $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.'); } - if(! function_exists('mcrypt_create_iv')){ + if (! function_exists('mcrypt_create_iv')){ $ck_funcs[5]['status']= false; $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.'); } - if(! function_exists('iconv_strlen')){ + if (! function_exists('iconv_strlen')){ $ck_funcs[7]['status']= false; $ck_funcs[7]['help']= t('Error: iconv PHP module required but not installed.'); } @@ -487,7 +493,7 @@ function check_funcs(&$checks) { function check_htconfig(&$checks) { $status = true; $help = ""; - if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) || + if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) || (!file_exists('.htconfig.php') && !is_writable('.')) ) { $status=false; @@ -504,7 +510,7 @@ function check_htconfig(&$checks) { function check_smarty3(&$checks) { $status = true; $help = ""; - if( !is_writable('view/smarty3') ) { + if (!is_writable('view/smarty3') ) { $status=false; $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; @@ -532,8 +538,7 @@ function check_htaccess(&$checks) { $help = t('Url rewrite in .htaccess is not working. Check your server configuration.'); } check_add($checks, t('Url rewrite is working'), $status, true, $help); - } - else { + } else { // cannot check modrewrite if libcurl is not installed /// @TODO Maybe issue warning here? } @@ -552,8 +557,7 @@ function check_imagik(&$checks) { } if ($imagick == false) { check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, ""); - } - else { + } else { check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, ""); if ($imagick) { check_add($checks, t('ImageMagick supports GIF'), $gif, false, ""); @@ -561,8 +565,6 @@ function check_imagik(&$checks) { } } - - function manual_config(&$a) { $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8'); $o = t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'); diff --git a/mod/invite.php b/mod/invite.php index 12f8306e8a..441d39e6e0 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -19,14 +19,15 @@ function invite_post(&$a) { check_form_security_token_redirectOnErr('/', 'send_invite'); $max_invites = intval(get_config('system','max_invites')); - if(! $max_invites) + if (! $max_invites) { $max_invites = 50; + } $current_invites = intval(get_pconfig(local_user(),'system','sent_invites')); - if($current_invites > $max_invites) { + if ($current_invites > $max_invites) { notice( t('Total invitation limit exceeded.') . EOL); return; - }; + } $recips = ((x($_POST,'recipients')) ? explode("\n",$_POST['recipients']) : array()); @@ -34,23 +35,24 @@ function invite_post(&$a) { $total = 0; - if(get_config('system','invitation_only')) { + if (get_config('system','invitation_only')) { $invonly = true; $x = get_pconfig(local_user(),'system','invites_remaining'); - if((! $x) && (! is_site_admin())) + if ((! $x) && (! is_site_admin())) { return; + } } - foreach($recips as $recip) { + foreach ($recips as $recip) { $recip = trim($recip); - if(! valid_email($recip)) { + if (! valid_email($recip)) { notice( sprintf( t('%s : Not a valid email address.'), $recip) . EOL); continue; } - - if($invonly && ($x || is_site_admin())) { + + if ($invonly && ($x || is_site_admin())) { $code = autoname(8) . srand(1000,9999); $nmessage = str_replace('$invite_code',$code,$message); @@ -59,16 +61,17 @@ function invite_post(&$a) { dbesc(datetime_convert()) ); - if(! is_site_admin()) { + if (! is_site_admin()) { $x --; - if($x >= 0) + if ($x >= 0) { set_pconfig(local_user(),'system','invites_remaining',$x); - else + } else { return; + } } - } - else + } else { $nmessage = $message; + } $res = mail($recip, email_header_encode( t('Please join us on Friendica'),'UTF-8'), $nmessage, @@ -76,7 +79,7 @@ function invite_post(&$a) { . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit' ); - if($res) { + if ($res) { $total ++; $current_invites ++; set_pconfig(local_user(),'system','sent_invites',$current_invites); @@ -84,8 +87,7 @@ function invite_post(&$a) { notice( t('Invitation limit exceeded. Please contact your site administrator.') . EOL); return; } - } - else { + } else { notice( sprintf( t('%s : Message delivery failed.'), $recip) . EOL); } @@ -105,26 +107,24 @@ function invite_content(&$a) { $tpl = get_markup_template('invite.tpl'); $invonly = false; - if(get_config('system','invitation_only')) { + if (get_config('system','invitation_only')) { $invonly = true; $x = get_pconfig(local_user(),'system','invites_remaining'); - if((! $x) && (! is_site_admin())) { + if ((! $x) && (! is_site_admin())) { notice( t('You have no more invitations available') . EOL); return ''; } } $dirloc = get_config('system','directory'); - if(strlen($dirloc)) { + if (strlen($dirloc)) { if ($a->config['register_policy'] == REGISTER_CLOSED) { $linktxt = sprintf( t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.'), $dirloc . '/siteinfo'); - } - elseif($a->config['register_policy'] != REGISTER_CLOSED) { + } elseif($a->config['register_policy'] != REGISTER_CLOSED) { $linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), App::get_baseurl()) . "\r\n" . "\r\n" . sprintf( t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.'),$dirloc . '/siteinfo'); } - } - else { + } else { $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); return $o; } diff --git a/mod/starred.php b/mod/starred.php index beaa3b87d5..84baa82cea 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -43,8 +43,7 @@ function starred_init(&$a) { $rand = '_=' . time(); if (strpos($return_path, '?')) { $rand = "&$rand"; - } - else { + } else { $rand = "?$rand"; } From b3d33ee1e61782ebc6c317ee93ae32f067888796 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 21 Dec 2016 23:17:22 +0100 Subject: [PATCH 37/41] More curly braces added, left some TODOs behind Signed-off-by: Roland Haeder --- mod/settings.php | 100 +++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index d9c28ac379..298b5025cd 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -671,9 +671,9 @@ function settings_content(&$a) { - if(($a->argc > 1) && ($a->argv[1] === 'oauth')) { + if (($a->argc > 1) && ($a->argv[1] === 'oauth')) { - if(($a->argc > 2) && ($a->argv[2] === 'add')) { + if (($a->argc > 2) && ($a->argv[2] === 'add')) { $tpl = get_markup_template("settings_oauth_edit.tpl"); $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("settings_oauth"), @@ -689,7 +689,7 @@ function settings_content(&$a) { return $o; } - if(($a->argc > 3) && ($a->argv[2] === 'edit')) { + if (($a->argc > 3) && ($a->argv[2] === 'edit')) { $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d", dbesc($a->argv[3]), local_user()); @@ -725,7 +725,7 @@ function settings_content(&$a) { return; } - + /// @TODO validate result with dbm::is_result() $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my FROM clients LEFT JOIN tokens ON clients.client_id=tokens.client_id @@ -751,7 +751,7 @@ function settings_content(&$a) { } - if(($a->argc > 1) && ($a->argv[1] === 'addon')) { + if (($a->argc > 1) && ($a->argv[1] === 'addon')) { $settings_addons = ""; $r = q("SELECT * FROM `hook` WHERE `hook` = 'plugin_settings' "); @@ -771,14 +771,14 @@ function settings_content(&$a) { return $o; } - if(($a->argc > 1) && ($a->argv[1] === 'features')) { + if (($a->argc > 1) && ($a->argv[1] === 'features')) { $arr = array(); $features = get_features(); - foreach($features as $fname => $fdata) { + foreach ($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; - foreach(array_slice($fdata,1) as $f) { + foreach (array_slice($fdata,1) as $f) { $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(feature_enabled(local_user(),$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On'))); } } @@ -787,14 +787,14 @@ function settings_content(&$a) { $tpl = get_markup_template("settings_features.tpl"); $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("settings_features"), - '$title' => t('Additional Features'), - '$features' => $arr, - '$submit' => t('Save Settings'), + '$title' => t('Additional Features'), + '$features' => $arr, + '$submit' => t('Save Settings'), )); return $o; } - if(($a->argc > 1) && ($a->argv[1] === 'connectors')) { + if (($a->argc > 1) && ($a->argv[1] === 'connectors')) { $settings_connectors = ''; $settings_connectors .= '

      '. t('General Social Media Settings').'

      '; @@ -860,8 +860,7 @@ function settings_content(&$a) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", local_user() ); - } - else { + } else { $r = null; } @@ -878,10 +877,9 @@ function settings_content(&$a) { $tpl = get_markup_template("settings_connectors.tpl"); - if(! service_class_allows(local_user(),'email_connect')) { + if (! service_class_allows(local_user(),'email_connect')) { $mail_disabled_message = upgrade_bool_message(); - } - else { + } else { $mail_disabled_message = (($mail_disabled) ? t('Email access is disabled on this site.') : ''); } @@ -919,38 +917,42 @@ function settings_content(&$a) { /* * DISPLAY SETTINGS */ - if(($a->argc > 1) && ($a->argv[1] === 'display')) { + if (($a->argc > 1) && ($a->argv[1] === 'display')) { $default_theme = get_config('system','theme'); - if(! $default_theme) + if (! $default_theme) { $default_theme = 'default'; + } $default_mobile_theme = get_config('system','mobile-theme'); - if(! $mobile_default_theme) + if (! $mobile_default_theme) { $mobile_default_theme = 'none'; + } $allowed_themes_str = get_config('system','allowed_themes'); $allowed_themes_raw = explode(',',$allowed_themes_str); $allowed_themes = array(); - if(count($allowed_themes_raw)) - foreach($allowed_themes_raw as $x) - if(strlen(trim($x)) && is_dir("view/theme/$x")) + if (count($allowed_themes_raw)) { + foreach ($allowed_themes_raw as $x) { + if (strlen(trim($x)) && is_dir("view/theme/$x")) { $allowed_themes[] = trim($x); + } + } + } $themes = array(); $mobile_themes = array("---" => t('No special theme for mobile devices')); $files = glob('view/theme/*'); /* */ - if($allowed_themes) { - foreach($allowed_themes as $th) { + if ($allowed_themes) { + foreach ($allowed_themes as $th) { $f = $th; $is_experimental = file_exists('view/theme/' . $th . '/experimental'); $unsupported = file_exists('view/theme/' . $th . '/unsupported'); $is_mobile = file_exists('view/theme/' . $th . '/mobile'); if (!$is_experimental or ($is_experimental && (get_config('experimentals','exp_themes')==1 or get_config('experimentals','exp_themes')===false))){ $theme_name = (($is_experimental) ? sprintf("%s - \x28Experimental\x29", $f) : $f); - if($is_mobile) { + if ($is_mobile) { $mobile_themes[$f]=$theme_name; - } - else { + } else { $themes[$f]=$theme_name; } } @@ -962,8 +964,9 @@ function settings_content(&$a) { $nowarn_insecure = intval(get_pconfig(local_user(), 'system', 'nowarn_insecure')); $browser_update = intval(get_pconfig(local_user(), 'system','update_interval')); - if (intval($browser_update) != -1) + if (intval($browser_update) != -1) { $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds + } $itemspage_network = intval(get_pconfig(local_user(), 'system','itemspage_network')); $itemspage_network = (($itemspage_network > 0 && $itemspage_network < 101) ? $itemspage_network : 40); // default if not set: 40 items @@ -1042,8 +1045,9 @@ function settings_content(&$a) { $p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval(local_user()) ); - if(count($p)) + if (count($p)) { $profile = $p[0]; + } $username = $a->user['username']; $email = $a->user['email']; @@ -1090,8 +1094,9 @@ function settings_content(&$a) { // nowarn_insecure - if(! strlen($a->user['timezone'])) + if (! strlen($a->user['timezone'])) { $timezone = date_default_timezone_get(); + } // Set the account type to "Community" when the page is a community page but the account type doesn't fit // This is only happening on the first visit after the update @@ -1152,19 +1157,16 @@ function settings_content(&$a) { $noid = get_config('system','no_openid'); - if($noid) { + if ($noid) { $openid_field = false; - } - else { + } else { $openid_field = array('openid_url', t('OpenID:'),$openid, t("\x28Optional\x29 Allow this OpenID to login to this account."), "", "", "url"); } - $opt_tpl = get_markup_template("field_yesno.tpl"); if(get_config('system','publish_all')) { $profile_in_dir = ''; - } - else { + } else { $profile_in_dir = replace_macros($opt_tpl,array( '$field' => array('profile_in_directory', t('Publish your default profile in your local site directory?'), $profile['publish'], '', array(t('No'),t('Yes'))), )); @@ -1174,12 +1176,10 @@ function settings_content(&$a) { $profile_in_net_dir = replace_macros($opt_tpl,array( '$field' => array('profile_in_netdirectory', t('Publish your default profile in the global social directory?'), $profile['net-publish'], '', array(t('No'),t('Yes'))), )); - } - else { + } else { $profile_in_net_dir = ''; } - $hide_friends = replace_macros($opt_tpl,array( '$field' => array('hide-friends', t('Hide your contact/friend list from viewers of your default profile?'), $profile['hide-friends'], '', array(t('No'),t('Yes'))), )); @@ -1194,19 +1194,16 @@ function settings_content(&$a) { )); - $blocktags = replace_macros($opt_tpl,array( '$field' => array('blocktags', t('Allow friends to tag your posts?'), (intval($a->user['blocktags']) ? '0' : '1'), '', array(t('No'),t('Yes'))), )); - $suggestme = replace_macros($opt_tpl,array( '$field' => array('suggestme', t('Allow us to suggest you as a potential friend to new members?'), $suggestme, '', array(t('No'),t('Yes'))), )); - $unkmail = replace_macros($opt_tpl,array( '$field' => array('unkmail', t('Permit unknown people to send you private mail?'), $unkmail, '', array(t('No'),t('Yes'))), @@ -1215,9 +1212,9 @@ function settings_content(&$a) { $invisible = (((! $profile['publish']) && (! $profile['net-publish'])) ? true : false); - if($invisible) + if ($invisible) { info( t('Profile is not published.') . EOL ); - + } //$subdir = ((strlen($a->get_path())) ? '
      ' . t('or') . ' ' . 'profile/' . $nickname : ''); @@ -1244,27 +1241,30 @@ function settings_content(&$a) { require_once('include/group.php'); $group_select = mini_group_select(local_user(),$a->user['def_gid']); - // Private/public post links for the non-JS ACL form $private_post = 1; - if($_REQUEST['public']) + if ($_REQUEST['public']) { $private_post = 0; + } $query_str = $a->query_string; - if(strpos($query_str, 'public=1') !== false) + if (strpos($query_str, 'public=1') !== false) { $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str); + } // I think $a->query_string may never have ? in it, but I could be wrong // It looks like it's from the index.php?q=[etc] rewrite that the web // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 - if(strpos($query_str, '?') === false) + if (strpos($query_str, '?') === false) { $public_post_link = '?public=1'; - else + } else { $public_post_link = '&public=1'; + } /* Installed langs */ $lang_choices = get_available_languages(); + /// @TODO Fix indending (or so) $o .= replace_macros($stpl, array( '$ptitle' => t('Account Settings'), From 99c8fd36c06f1fa315675b841d6be3e78d1b560b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 09:09:27 +0100 Subject: [PATCH 38/41] applied coding convention rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/like.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/like.php b/include/like.php index feaffe011b..b8909be320 100644 --- a/include/like.php +++ b/include/like.php @@ -48,10 +48,8 @@ function do_like($item_id, $verb) { break; } - logger('like: verb ' . $verb . ' item ' . $item_id); - $r = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1", dbesc($item_id), dbesc($item_id) @@ -109,8 +107,7 @@ function do_like($item_id, $verb) { if ((local_user()) && (local_user() == $owner_uid)) { $contact = $owner; - } - else { + } else { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($_SESSION['visitor_id']), intval($owner_uid) From ef5838bbd22134ee9ba2180e96b69e8efac2022b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 09:10:17 +0100 Subject: [PATCH 39/41] was not missing in develop branch, but here. :-( MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/like.php | 1 + 1 file changed, 1 insertion(+) diff --git a/include/like.php b/include/like.php index b8909be320..4df15b4b63 100644 --- a/include/like.php +++ b/include/like.php @@ -163,6 +163,7 @@ function do_like($item_id, $verb) { $post_type = (($item['resource-id']) ? t('photo') : t('status')); if ($item['object-type'] === ACTIVITY_OBJ_EVENT) { $post_type = t('event'); + } $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; From a314dbc56207eff751dbce5c88b055ae8e41ae30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 09:14:14 +0100 Subject: [PATCH 40/41] removed conflict solving remains, took from upstream/develop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/proxy.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/mod/proxy.php b/mod/proxy.php index a8c24cf088..8046e4e963 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -141,23 +141,11 @@ function proxy_init(App $a) { if (!$direct_cache AND ($cachefile == '')) { $r = qu("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash); if (dbm::is_result($r)) { -<<<<<<< HEAD -<<<<<<< origin/rewrites/app_get_baseurl_static - $img_str = $r[0]['data']; - $mime = $r[0]["desc"]; - if ($mime == "") $mime = "image/jpeg"; -======= -======= ->>>>>>> upstream/develop $img_str = $r[0]['data']; $mime = $r[0]['desc']; if ($mime == '') { $mime = 'image/jpeg'; } -<<<<<<< HEAD ->>>>>>> HEAD~0 -======= ->>>>>>> upstream/develop } } From 5d0db51fdf560d9599af461664188451941d5295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 11:21:50 +0100 Subject: [PATCH 41/41] Beatification/coding convention: - added a lot spaces to make it look nicer - added curly braces (coding convention) - added needed spaces (coding convention)get_id - removed obsolete $a = get_app() call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- object/Item.php | 383 ++++++++++++++++++++++++------------------------ 1 file changed, 193 insertions(+), 190 deletions(-) diff --git a/object/Item.php b/object/Item.php index d14b5418cc..e60344f7d3 100644 --- a/object/Item.php +++ b/object/Item.php @@ -52,21 +52,22 @@ class Item extends BaseObject { $ssl_state = ((local_user()) ? true : false); $this->redirect_url = 'redir/' . $this->get_data_value('cid') ; - if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) + if (get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) { $this->threaded = true; + } // Prepare the children - if(count($data['children'])) { - foreach($data['children'] as $item) { + if (count($data['children'])) { + foreach ($data['children'] as $item) { /* * Only add will be displayed */ - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { - continue; - } - if(! visible_activity($item)) { + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + continue; + } elseif (! visible_activity($item)) { continue; } + $item['pagedrop'] = $data['pagedrop']; $child = new Item($item); $this->add_child($child); @@ -91,11 +92,11 @@ class Item extends BaseObject { $item = $this->get_data(); $edited = false; if (strcmp($item['created'], $item['edited'])<>0) { - $edited = array( - 'label' => t('This entry was edited'), - 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), - 'relative' => relative_date($item['edited']) - ); + $edited = array( + 'label' => t('This entry was edited'), + 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), + 'relative' => relative_date($item['edited']) + ); } $commentww = ''; $sparkle = ''; @@ -111,7 +112,6 @@ class Item extends BaseObject { $conv = $this->get_conversation(); - $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) ? t('Private Message') @@ -134,22 +134,24 @@ class Item extends BaseObject { $drop = array( 'dropping' => $dropping, 'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''), - 'select' => t('Select'), - 'delete' => t('Delete'), + 'select' => t('Select'), + 'delete' => t('Delete'), ); $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false); $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); $profile_name = htmlentities(((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; $profile_link = best_link_url($item,$sp); if ($profile_link === 'mailbox') { $profile_link = ''; } + if ($sp) { $sparkle = ' sparkle'; } else { @@ -198,13 +200,14 @@ class Item extends BaseObject { // process action responses - e.g. like/dislike/attend/agree/whatever $response_verbs = array('like'); - if(feature_enabled($conv->get_profile_owner(),'dislike')) + if (feature_enabled($conv->get_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($conv->is_writable()) { + if ($conv->is_writable()) { $isevent = true; $attend = array( t('I will attend'), t('I will not attend'), t('I might attend')); } @@ -213,8 +216,7 @@ class Item extends BaseObject { $responses = get_responses($conv_responses,$response_verbs,$this,$item); foreach ($response_verbs as $value=>$verbs) { - $responses[$verbs][output] = ((x($conv_responses[$verbs],$item['uri'])) ? format_like($conv_responses[$verbs][$item['uri']],$conv_responses[$verbs][$item['uri'] . '-l'],$verbs,$item['uri']) : ''); - + $responses[$verbs]['output'] = ((x($conv_responses[$verbs],$item['uri'])) ? format_like($conv_responses[$verbs][$item['uri']],$conv_responses[$verbs][$item['uri'] . '-l'],$verbs,$item['uri']) : ''); } /* @@ -224,20 +226,21 @@ class Item extends BaseObject { */ $this->check_wall_to_wall(); - if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) + if ($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) { $osparkle = ' sparkle'; + } - if($this->is_toplevel()) { - if($conv->get_profile_owner() == local_user()) { + if ($this->is_toplevel()) { + if ($conv->get_profile_owner() == local_user()) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = array( - 'do' => t("add star"), - 'undo' => t("remove star"), - 'toggle' => t("toggle star status"), - 'classdo' => (($item['starred']) ? "hidden" : ""), + 'do' => t("add star"), + 'undo' => t("remove star"), + 'toggle' => t("toggle star status"), + 'classdo' => (($item['starred']) ? "hidden" : ""), 'classundo' => (($item['starred']) ? "" : "hidden"), - 'starred' => t('starred'), + 'starred' => t('starred'), ); $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", intval($item['uid']), @@ -245,19 +248,19 @@ class Item extends BaseObject { ); if (dbm::is_result($r)) { $ignore = array( - 'do' => t("ignore thread"), - 'undo' => t("unignore thread"), - 'toggle' => t("toggle ignore status"), - 'classdo' => (($r[0]['ignored']) ? "hidden" : ""), + 'do' => t("ignore thread"), + 'undo' => t("unignore thread"), + 'toggle' => t("toggle ignore status"), + 'classdo' => (($r[0]['ignored']) ? "hidden" : ""), 'classundo' => (($r[0]['ignored']) ? "" : "hidden"), - 'ignored' => t('ignored'), + 'ignored' => t('ignored'), ); } $tagger = ''; if(feature_enabled($conv->get_profile_owner(),'commtag')) { $tagger = array( - 'add' => t("add tag"), + 'add' => t("add tag"), 'class' => "", ); } @@ -266,17 +269,19 @@ class Item extends BaseObject { $indent = 'comment'; } - if($conv->is_writable()) { + if ($conv->is_writable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), ); - if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); + if ($shareable) { + $buttons['share'] = array( t('Share this'), t('share')); + } } $comment = $this->get_comment_box($indent); - 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'; } @@ -298,8 +303,9 @@ class Item extends BaseObject { foreach ($languages as $language) { $langdata = explode(";", $language); - if ($langstr != "") + if ($langstr != "") { $langstr .= ", "; + } //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)"; $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0]; @@ -311,20 +317,19 @@ class Item extends BaseObject { list($categories, $folders) = get_cats_and_terms($item); - 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); + 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($this->get_owner_name()); - } - else { - $body_e = $body; - $text_e = strip_tags($body); - $name_e = $profile_name; - $title_e = $item['title']; - $location_e = $location; + } else { + $body_e = $body; + $text_e = strip_tags($body); + $name_e = $profile_name; + $title_e = $item['title']; + $location_e = $location; $owner_name_e = $this->get_owner_name(); } @@ -334,89 +339,93 @@ class Item extends BaseObject { $tagger = ''; } - if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) + if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) { unset($buttons["like"]); + } - if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) + if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) { unset($buttons["like"]); + } // Diaspora isn't able to do likes on comments - but red does if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND - !diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) + !diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { unset($buttons["like"]); + } // Diaspora doesn't has multithreaded comments - if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) + if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) { unset($comment); + } // Facebook can like comments - but it isn't programmed in the connector yet. - if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) + if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) { unset($buttons["like"]); + } $tmp_item = array( - 'template' => $this->get_template(), - - 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), - 'tags' => $item['tags'], - 'hashtags' => $item['hashtags'], - 'mentions' => $item['mentions'], - 'txt_cats' => t('Categories:'), - 'txt_folders' => t('Filed under:'), - 'has_cats' => ((count($categories)) ? 'true' : ''), - 'has_folders' => ((count($folders)) ? 'true' : ''), - 'categories' => $categories, - 'folders' => $folders, - 'body' => $body_e, - 'text' => $text_e, - 'id' => $this->get_id(), - 'guid' => urlencode($item['guid']), - 'isevent' => $isevent, - 'attend' => $attend, - 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), - 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), - 'to' => t('to'), - 'via' => t('via'), - 'wall' => t('Wall-to-Wall'), - 'vwall' => t('via Wall-To-Wall:'), - 'profile_url' => $profile_link, + 'template' => $this->get_template(), + 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), + 'tags' => $item['tags'], + 'hashtags' => $item['hashtags'], + 'mentions' => $item['mentions'], + 'txt_cats' => t('Categories:'), + 'txt_folders' => t('Filed under:'), + 'has_cats' => ((count($categories)) ? 'true' : ''), + 'has_folders' => ((count($folders)) ? 'true' : ''), + 'categories' => $categories, + 'folders' => $folders, + 'body' => $body_e, + 'text' => $text_e, + 'id' => $this->get_id(), + 'guid' => urlencode($item['guid']), + 'isevent' => $isevent, + 'attend' => $attend, + 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), + 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), + 'to' => t('to'), + 'via' => t('via'), + 'wall' => t('Wall-to-Wall'), + 'vwall' => t('via Wall-To-Wall:'), + 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), - 'name' => $name_e, - 'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), - 'osparkle' => $osparkle, - 'sparkle' => $sparkle, - 'title' => $title_e, - 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), - 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), - 'app' => $item['app'], - 'created' => relative_date($item['created']), - 'lock' => $lock, - 'location' => $location_e, - 'indent' => $indent, - 'shiny' => $shiny, - 'owner_url' => $this->get_owner_url(), - 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), - 'owner_name' => htmlentities($owner_name_e), - 'plink' => get_plink($item), - 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), - 'isstarred' => $isstarred, - 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''), - 'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''), - 'tagger' => $tagger, - 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''), - 'drop' => $drop, - 'vote' => $buttons, - 'like' => $responses['like']['output'], - 'dislike' => $responses['dislike']['output'], - 'responses' => $responses, - 'switchcomment' => t('Comment'), - 'comment' => $comment, - 'previewing' => ($conv->is_preview() ? ' preview ' : ''), - 'wait' => t('Please wait'), - 'thread_level' => $thread_level, - 'postopts' => $langstr, - 'edited' => $edited, - 'network' => $item["item_network"], - 'network_name' => network_to_name($item['item_network'], $profile_link), + 'name' => $name_e, + 'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), + 'osparkle' => $osparkle, + 'sparkle' => $sparkle, + 'title' => $title_e, + 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), + 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'app' => $item['app'], + 'created' => relative_date($item['created']), + 'lock' => $lock, + 'location' => $location_e, + 'indent' => $indent, + 'shiny' => $shiny, + 'owner_url' => $this->get_owner_url(), + 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), + 'owner_name' => htmlentities($owner_name_e), + 'plink' => get_plink($item), + 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), + 'isstarred' => $isstarred, + 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''), + 'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''), + 'tagger' => $tagger, + 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''), + 'drop' => $drop, + 'vote' => $buttons, + 'like' => $responses['like']['output'], + 'dislike' => $responses['dislike']['output'], + 'responses' => $responses, + 'switchcomment' => t('Comment'), + 'comment' => $comment, + 'previewing' => ($conv->is_preview() ? ' preview ' : ''), + 'wait' => t('Please wait'), + 'thread_level' => $thread_level, + 'postopts' => $langstr, + 'edited' => $edited, + 'network' => $item["item_network"], + 'network_name' => network_to_name($item['item_network'], $profile_link), ); $arr = array('item' => $item, 'output' => $tmp_item); @@ -427,39 +436,37 @@ class Item extends BaseObject { $result['children'] = array(); $children = $this->get_children(); $nb_children = count($children); - if($nb_children > 0) { - foreach($children as $child) { + if ($nb_children > 0) { + foreach ($children as $child) { $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1); } // Collapse - if(($nb_children > 2) || ($thread_level > 1)) { + if (($nb_children > 2) || ($thread_level > 1)) { $result['children'][0]['comment_firstcollapsed'] = true; $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); $result['children'][0]['hidden_comments_num'] = $total_children; $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children); $result['children'][0]['hide_text'] = t('show more'); - if($thread_level > 1) { + if ($thread_level > 1) { $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; - } - else { + } else { $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; } } } if ($this->is_toplevel()) { - $result['total_comments_num'] = "$total_children"; - $result['total_comments_text'] = tt('comment', 'comments', $total_children); + $result['total_comments_num'] = "$total_children"; + $result['total_comments_text'] = tt('comment', 'comments', $total_children); } $result['private'] = $item['private']; $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); - if($this->is_threaded()) { + if ($this->is_threaded()) { $result['flatten'] = false; $result['threaded'] = true; - } - else { + } else { $result['flatten'] = true; $result['threaded'] = false; } @@ -478,23 +485,21 @@ class Item extends BaseObject { /** * Add a child item */ - public function add_child($item) { + public function add_child(Item $item) { $item_id = $item->get_id(); - if(!$item_id) { + if (!$item_id) { logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG); return false; - } - if($this->get_child($item->get_id())) { + } elseif ($this->get_child($item->get_id())) { logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG); return false; } /* * Only add what will be displayed */ - if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { + if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { return false; - } - if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) { + } elseif (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) { return false; } @@ -507,9 +512,10 @@ class Item extends BaseObject { * Get a child by its ID */ public function get_child($id) { - foreach($this->get_children() as $child) { - if($child->get_id() == $id) + foreach ($this->get_children() as $child) { + if ($child->get_id() == $id) { return $child; + } } return null; } @@ -546,8 +552,8 @@ class Item extends BaseObject { */ public function remove_child($item) { $id = $item->get_id(); - foreach($this->get_children() as $key => $child) { - if($child->get_id() == $id) { + foreach ($this->get_children() as $key => $child) { + if ($child->get_id() == $id) { $child->remove_parent(); unset($this->children[$key]); // Reindex the array, in order to make sure there won't be any trouble on loops using count() @@ -575,8 +581,9 @@ class Item extends BaseObject { $this->conversation = $conv; // Set it on our children too - foreach($this->get_children() as $child) + foreach ($this->get_children() as $child) { $child->set_conversation($conv); + } } /** @@ -603,7 +610,7 @@ class Item extends BaseObject { * _ false on failure */ public function get_data_value($name) { - if(!isset($this->data[$name])) { + if (!isset($this->data[$name])) { // logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); return false; } @@ -615,9 +622,7 @@ class Item extends BaseObject { * Set template */ private function set_template($name) { - $a = get_app(); - - if(!x($this->available_templates, $name)) { + if (!x($this->available_templates, $name)) { logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG); return false; } @@ -645,13 +650,14 @@ class Item extends BaseObject { private function is_writable() { $conv = $this->get_conversation(); - if($conv) { + if ($conv) { // This will allow us to comment on wall-to-wall items owned by our friends // and community forums even if somebody else wrote the post. // bug #517 - this fixes for conversation owner - if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) - return true; + if ($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) { + return true; + } // this fixes for visitors return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile')); @@ -665,8 +671,8 @@ class Item extends BaseObject { private function count_descendants() { $children = $this->get_children(); $total = count($children); - if($total > 0) { - foreach($children as $child) { + if ($total > 0) { + foreach ($children as $child) { $total += $child->count_descendants(); } } @@ -689,7 +695,7 @@ class Item extends BaseObject { */ private function get_comment_box($indent) { $a = $this->get_app(); - if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) { + if (!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) { return ''; } @@ -697,48 +703,48 @@ class Item extends BaseObject { $conv = $this->get_conversation(); $template = get_markup_template($this->get_comment_box_template()); $ww = ''; - if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) + if ( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) $ww = 'ww'; - if($conv->is_writable() && $this->is_writable()) { + if ($conv->is_writable() && $this->is_writable()) { $qc = $qcomment = null; /* * Hmmm, code depending on the presence of a particular plugin? * This should be better if done by a hook */ - 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); } $comment_box = replace_macros($template,array( '$return_path' => $a->query_string, - '$threaded' => $this->is_threaded(), -// '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), - '$jsreload' => '', - '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), - '$id' => $this->get_id(), - '$parent' => $this->get_id(), - '$qcomment' => $qcomment, + '$threaded' => $this->is_threaded(), +// '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), + '$jsreload' => '', + '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), + '$id' => $this->get_id(), + '$parent' => $this->get_id(), + '$qcomment' => $qcomment, '$profile_uid' => $conv->get_profile_owner(), - '$mylink' => $a->remove_baseurl($a->contact['url']), - '$mytitle' => t('This is you'), - '$myphoto' => $a->remove_baseurl($a->contact['thumb']), - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$edbold' => t('Bold'), - '$editalic' => t('Italic'), - '$eduline' => t('Underline'), - '$edquote' => t('Quote'), - '$edcode' => t('Code'), - '$edimg' => t('Image'), - '$edurl' => t('Link'), - '$edvideo' => t('Video'), - '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''), - '$indent' => $indent, - '$sourceapp' => t($a->sourcename), - '$ww' => (($conv->get_mode() === 'network') ? $ww : ''), - '$rand_num' => random_digits(12) + '$mylink' => $a->remove_baseurl($a->contact['url']), + '$mytitle' => t('This is you'), + '$myphoto' => $a->remove_baseurl($a->contact['thumb']), + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$edbold' => t('Bold'), + '$editalic' => t('Italic'), + '$eduline' => t('Underline'), + '$edquote' => t('Quote'), + '$edcode' => t('Code'), + '$edimg' => t('Image'), + '$edurl' => t('Link'), + '$edvideo' => t('Video'), + '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''), + '$indent' => $indent, + '$sourceapp' => t($a->sourcename), + '$ww' => (($conv->get_mode() === 'network') ? $ww : ''), + '$rand_num' => random_digits(12) )); } @@ -768,14 +774,13 @@ class Item extends BaseObject { $this->owner_photo = $a->page_contact['thumb']; $this->owner_name = $a->page_contact['name']; $this->wall_to_wall = true; - } - else if($this->get_data_value('owner-link')) { + } elseif($this->get_data_value('owner-link')) { $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('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. @@ -791,18 +796,18 @@ class Item extends BaseObject { $this->owner_name = $this->get_data_value('owner-name'); $this->wall_to_wall = true; // If it is our contact, use a friendly redirect link - if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) + if ((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) && ($this->get_data_value('network') === NETWORK_DFRN)) { $this->owner_url = $this->get_redirect_url(); - } - else + } else { $this->owner_url = zrl($this->get_data_value('owner-link')); + } } } } } - if(!$this->wall_to_wall) { + if (!$this->wall_to_wall) { $this->set_template('wall'); $this->owner_url = ''; $this->owner_photo = ''; @@ -830,8 +835,6 @@ class Item extends BaseObject { return $this->visiting; } - - - } +/// @TODO These are discouraged and should be removed: ?>