Fix Scrutinizer issues in contacts/credits/crepair

- Add back uninitialized variables
- Fix formatting
- Use dba::selectFirst whenever possible
This commit is contained in:
Hypolite Petovan 2018-01-12 23:41:18 -05:00
parent adfabeadb1
commit c66af117b3
3 changed files with 23 additions and 47 deletions

View File

@ -1,7 +1,9 @@
<?php <?php
/** /**
* @file mod/contacts.php * @file mod/contacts.php
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Content\ContactSelector; use Friendica\Content\ContactSelector;
use Friendica\Core\System; use Friendica\Core\System;
@ -30,6 +32,7 @@ function contacts_init(App $a)
$a->page['aside'] = ''; $a->page['aside'] = '';
} }
$contact_id = null;
$contact = null; $contact = null;
if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) { if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
$contact_id = intval($a->argv[1]); $contact_id = intval($a->argv[1]);
@ -164,11 +167,7 @@ function contacts_post(App $a)
return; return;
} }
$orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", if (!DBM::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
intval($contact_id),
intval(local_user())
);
if (!DBM::is_result($orig_record)) {
notice(t('Could not access contact record.') . EOL); notice(t('Could not access contact record.') . EOL);
goaway('contacts'); goaway('contacts');
return; // NOTREACHED return; // NOTREACHED
@ -178,11 +177,7 @@ function contacts_post(App $a)
$profile_id = intval($_POST['profile-assign']); $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", if (!DBM::exists('profile', ['id' => $profile_id, 'uid' => local_user()])) {
intval($profile_id),
intval(local_user())
);
if (!DBM::is_result($r)) {
notice(t('Could not locate selected profile.') . EOL); notice(t('Could not locate selected profile.') . EOL);
return; return;
} }
@ -229,6 +224,7 @@ function contacts_post(App $a)
return; return;
} }
/* contact actions */ /* contact actions */
function _contact_update($contact_id) function _contact_update($contact_id)
@ -764,7 +760,6 @@ function contacts_content(App $a)
$total = 0; $total = 0;
$searching = false; $searching = false;
$search_hdr = null; $search_hdr = null;
$search_txt = '';
if ($search) { if ($search) {
$searching = true; $searching = true;
$search_hdr = $search; $search_hdr = $search;

View File

@ -5,19 +5,17 @@
* (only contributors to the git repositories for friendica core and the * (only contributors to the git repositories for friendica core and the
* addons repository will be listed though ATM) * addons repository will be listed though ATM)
*/ */
use Friendica\App; use Friendica\App;
function credits_content(App $a) { function credits_content()
{
/* fill the page with credits */ /* fill the page with credits */
$f = fopen('util/credits.txt', 'r'); $credits_string = file_get_contents('util/credits.txt');
$names = fread($f, filesize('util/credits.txt')); $names = explode("\n", htmlspecialchars($credits_string));
$arr = explode("\n", htmlspecialchars($names));
fclose($f);
$tpl = get_markup_template('credits.tpl'); $tpl = get_markup_template('credits.tpl');
return replace_macros($tpl, array( return replace_macros($tpl, [
'$title' => t('Credits'), '$title' => t('Credits'),
'$thanks' => t('Friendica is a community project, that would not be possible without the help of many people. Here is a list of those who have contributed to the code or the translation of Friendica. Thank you all!'), '$thanks' => t('Friendica is a community project, that would not be possible without the help of many people. Here is a list of those who have contributed to the code or the translation of Friendica. Thank you all!'),
'$names' => $arr, '$names' => $names,
)); ]);
} }

View File

@ -16,26 +16,17 @@ function crepair_init(App $a)
return; return;
} }
$contact_id = 0; $contact = null;
if (($a->argc == 2) && intval($a->argv[1])) { if (($a->argc == 2) && intval($a->argv[1])) {
$contact_id = intval($a->argv[1]); $contact = dba::selectFirst('contact', [], ['uid' => local_user(), 'id' => $a->argv[1]]);
$r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
intval(local_user()),
intval($contact_id)
);
if (!DBM::is_result($r)) {
$contact_id = 0;
}
} }
if (!x($a->page, 'aside')) { if (!x($a->page, 'aside')) {
$a->page['aside'] = ''; $a->page['aside'] = '';
} }
if ($contact_id) { if (DBM::is_result($contact)) {
$a->data['contact'] = $r[0]; $a->data['contact'] = $contact;
$contact = $r[0];
profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"])); profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
} }
} }
@ -48,19 +39,15 @@ function crepair_post(App $a)
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
$contact = null;
if ($cid) { if ($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $contact = dba::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
intval($cid),
intval(local_user())
);
} }
if (!DBM::is_result($r)) { if (!DBM::is_result($contact)) {
return; return;
} }
$contact = $r[0];
$name = defaults($_POST, 'name' , $contact['name']); $name = defaults($_POST, 'name' , $contact['name']);
$nick = defaults($_POST, 'nick' , ''); $nick = defaults($_POST, 'nick' , '');
$url = defaults($_POST, 'url' , ''); $url = defaults($_POST, 'url' , '');
@ -113,20 +100,16 @@ function crepair_content(App $a)
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
$contact = null;
if ($cid) { if ($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $contact = dba::selectFirst('contact', [], ['id' => $cid, 'uid' => local_user()]);
intval($cid),
intval(local_user())
);
} }
if (!DBM::is_result($r)) { if (!DBM::is_result($contact)) {
notice(t('Contact not found.') . EOL); notice(t('Contact not found.') . EOL);
return; return;
} }
$contact = $r[0];
$warning = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.'); $warning = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
$info = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.'); $info = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');