Browse Source

Fix formatting and PHP notices in contacts

- Use x() and defaults() to fix undefined indexes
- Fix variable and constant name typos
- Remove unused variables and commented out code
- Add back undefined variables
pull/4157/head
Hypolite Petovan 4 years ago
parent
commit
f7165156f1
  1. 81
      mod/contacts.php
  2. 112
      mod/crepair.php
  3. 89
      mod/hovercard.php

81
mod/contacts.php

@ -35,8 +35,9 @@ function contacts_init(App $a) {
require_once 'include/contact_widgets.php';
if ($_GET['nets'] == "all") {
$_GET['nets'] = "";
$nets = defaults($_GET, 'nets', '');
if ($nets == "all") {
$nets = "";
}
if (! x($a->page,'aside')) {
@ -63,22 +64,22 @@ function contacts_init(App $a) {
'$account_type' => Contact::getAccountType($a->data['contact'])
));
$finpeople_widget = '';
$findpeople_widget = '';
$follow_widget = '';
$networks_widget = '';
} else {
$vcard_widget = '';
$networks_widget .= networks_widget('contacts',$_GET['nets']);
$networks_widget = networks_widget('contacts', $nets);
if (isset($_GET['add'])) {
$follow_widget = follow_widget($_GET['add']);
} else {
$follow_widget = follow_widget();
}
$findpeople_widget .= findpeople_widget();
$findpeople_widget = findpeople_widget();
}
$groups_widget .= Group::sidebarWidget('contacts','group','full',0,$contact_id);
$groups_widget = Group::sidebarWidget('contacts','group','full',0,$contact_id);
$a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
'$vcard_widget' => $vcard_widget,
@ -515,8 +516,6 @@ function contacts_content(App $a) {
require_once 'include/contact_selectors.php';
$tpl = get_markup_template("contact_edit.tpl");
switch($contact['rel']) {
case CONTACT_IS_FRIEND:
$dir_icon = 'images/lrarrow.gif';
@ -577,6 +576,7 @@ function contacts_content(App $a) {
$lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
$fetch_further_information = null;
if ($contact['network'] == NETWORK_FEED) {
$fetch_further_information = array('fetch_further_information',
t('Fetch further information for feeds'),
@ -587,12 +587,19 @@ function contacts_content(App $a) {
'3' => t('Fetch keywords'),
'2' => t('Fetch information and keywords')));
}
if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL)))
$poll_interval = null;
if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL))) {
$poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
}
if ($contact['network'] == NETWORK_DFRN)
$profile_select = null;
if ($contact['network'] == NETWORK_DFRN) {
$profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
}
$follow = '';
$follow_text = '';
if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
$follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
@ -606,7 +613,7 @@ function contacts_content(App $a) {
// Load contactact related actions like hide, suggest, delete and others
$contact_actions = contact_actions($contact);
$tpl = get_markup_template("contact_edit.tpl");
$o .= replace_macros($tpl, array(
//'$header' => t('Contact Editor'),
'$header' => t("Contact"),
@ -618,9 +625,7 @@ function contacts_content(App $a) {
'$lbl_info2' => t('Their personal note'),
'$reason' => trim(notags($contact['reason'])),
'$infedit' => t('Edit contact notes'),
'$common_text' => $common_text,
'$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
'$all_friends' => $all_friends,
'$relation_text' => $relation_text,
'$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
'$blockunblock' => t('Block/Unblock contact'),
@ -658,7 +663,6 @@ function contacts_content(App $a) {
'$photo' => $contact['photo'],
'$name' => htmlentities($contact['name']),
'$dir_icon' => $dir_icon,
'$alt_text' => $alt_text,
'$sparkle' => $sparkle,
'$url' => $url,
'$profileurllabel' => t('Profile URL'),
@ -688,36 +692,33 @@ function contacts_content(App $a) {
}
$blocked = false;
$hidden = false;
$ignored = false;
$all = false;
$blocked = false;
$hidden = false;
$ignored = false;
$archived = false;
$all = false;
if(($a->argc == 2) && ($a->argv[1] === 'all')) {
$sql_extra = '';
$all = true;
}
elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
} elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
$sql_extra = " AND `blocked` = 1 ";
$blocked = true;
}
elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
} elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
$sql_extra = " AND `hidden` = 1 ";
$hidden = true;
}
elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
} elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
$sql_extra = " AND `readonly` = 1 ";
$ignored = true;
}
elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
} elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
$sql_extra = " AND `archive` = 1 ";
$archived = true;
}
else
} else {
$sql_extra = " AND `blocked` = 0 ";
}
$search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
$nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
$search = x($_GET, 'search') ? notags(trim($_GET['search'])) : '';
$nets = x($_GET, 'nets') ? notags(trim($_GET['nets'])) : '';
$tabs = array(
array(
@ -786,25 +787,25 @@ function contacts_content(App $a) {
$tab_tpl = get_markup_template('common_tabs.tpl');
$t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
$searching = false;
if($search) {
$search_hdr = null;
if ($search) {
$search_hdr = $search;
$search_txt = dbesc(protect_sprintf(preg_quote($search)));
$searching = true;
}
$sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
if($nets)
if ($nets) {
$sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
}
$sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
$r = q("SELECT COUNT(*) AS `total` FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
intval($_SESSION['uid']));
intval($_SESSION['uid'])
);
if (DBM::is_result($r)) {
$a->set_pager_total($r[0]['total']);
$total = $r[0]['total'];
@ -834,7 +835,7 @@ function contacts_content(App $a) {
'$total' => $total,
'$search' => $search_hdr,
'$desc' => t('Search your contacts'),
'$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
'$finding' => $searching ? t('Results for: %s', $search) : "",
'$submit' => t('Find'),
'$cmd' => $a->cmd,
'$contacts' => $contacts,
@ -849,7 +850,6 @@ function contacts_content(App $a) {
),
'$h_batch_actions' => t('Batch Actions'),
'$paginate' => paginate($a),
));
return $o;
@ -927,12 +927,11 @@ function contact_posts($a, $contact_id) {
$contact = $r[0];
$a->page['aside'] = "";
profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
} else
$profile = "";
}
$tab_str = contacts_tab($a, $contact_id, 1);
$o .= $tab_str;
$o = $tab_str;
$o .= Contact::getPostsFromUrl($contact["url"]);

112
mod/crepair.php

@ -1,4 +1,5 @@
<?php
/**
* @file mod/crepair.php
*/
@ -10,65 +11,68 @@ use Friendica\Model\Contact;
require_once 'include/contact_selectors.php';
require_once 'mod/contacts.php';
function crepair_init(App $a) {
if (! local_user()) {
function crepair_init(App $a)
{
if (!local_user()) {
return;
}
$contact_id = 0;
if(($a->argc == 2) && intval($a->argv[1])) {
if (($a->argc == 2) && intval($a->argv[1])) {
$contact_id = intval($a->argv[1]);
$r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
intval(local_user()),
intval($contact_id)
);
if (! DBM::is_result($r)) {
if (!DBM::is_result($r)) {
$contact_id = 0;
}
}
if(! x($a->page,'aside'))
if (!x($a->page, 'aside')) {
$a->page['aside'] = '';
}
if($contact_id) {
if ($contact_id) {
$a->data['contact'] = $r[0];
$contact = $r[0];
profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
}
}
function crepair_post(App $a) {
if (! local_user()) {
function crepair_post(App $a)
{
if (!local_user()) {
return;
}
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if($cid) {
if ($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval(local_user())
);
}
if (! DBM::is_result($r)) {
if (!DBM::is_result($r)) {
return;
}
$contact = $r[0];
$name = ((x($_POST,'name')) ? $_POST['name'] : $contact['name']);
$nick = ((x($_POST,'nick')) ? $_POST['nick'] : '');
$url = ((x($_POST,'url')) ? $_POST['url'] : '');
$request = ((x($_POST,'request')) ? $_POST['request'] : '');
$confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : '');
$notify = ((x($_POST,'notify')) ? $_POST['notify'] : '');
$poll = ((x($_POST,'poll')) ? $_POST['poll'] : '');
$attag = ((x($_POST,'attag')) ? $_POST['attag'] : '');
$photo = ((x($_POST,'photo')) ? $_POST['photo'] : '');
$remote_self = ((x($_POST,'remote_self')) ? $_POST['remote_self'] : false);
$nurl = normalise_link($url);
$name = defaults($_POST, 'name' , $contact['name']);
$nick = defaults($_POST, 'nick' , '');
$url = defaults($_POST, 'url' , '');
$request = defaults($_POST, 'request' , '');
$confirm = defaults($_POST, 'confirm' , '');
$notify = defaults($_POST, 'notify' , '');
$poll = defaults($_POST, 'poll' , '');
$attag = defaults($_POST, 'attag' , '');
$photo = defaults($_POST, 'photo' , '');
$remote_self = defaults($_POST, 'remote_self', false);
$nurl = normalise_link($url);
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `nurl` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' , `remote_self` = %d
WHERE `id` = %d AND `uid` = %d",
@ -101,26 +105,24 @@ function crepair_post(App $a) {
return;
}
function crepair_content(App $a) {
if (! local_user()) {
notice( t('Permission denied.') . EOL);
function crepair_content(App $a)
{
if (!local_user()) {
notice(t('Permission denied.') . EOL);
return;
}
$cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if($cid) {
if ($cid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($cid),
intval(local_user())
);
}
if (! DBM::is_result($r)) {
notice( t('Contact not found.') . EOL);
if (!DBM::is_result($r)) {
notice(t('Contact not found.') . EOL);
return;
}
@ -131,45 +133,44 @@ function crepair_content(App $a) {
$returnaddr = "contacts/$cid";
$allow_remote_self = Config::get('system','allow_users_remote_self');
$allow_remote_self = Config::get('system', 'allow_users_remote_self');
// Disable remote self for everything except feeds.
// There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
// Problem is, you couldn't reply to both networks.
if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA)))
if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA))) {
$allow_remote_self = false;
}
if ($contact['network'] == NETWORK_FEED)
$remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting'), '2'=>t('Mirror as my own posting'));
else
$remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
if ($contact['network'] == NETWORK_FEED) {
$remote_self_options = array('0' => t('No mirroring'), '1' => t('Mirror as forwarded posting'), '2' => t('Mirror as my own posting'));
} else {
$remote_self_options = array('0' => t('No mirroring'), '2' => t('Mirror as my own posting'));
}
$update_profile = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DSPR, NETWORK_OSTATUS));
$update_profile = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS));
$tab_str = contacts_tab($a, $contact['id'], 5);
$tpl = get_markup_template('crepair.tpl');
$o .= replace_macros($tpl, array(
//'$title' => t('Repair Contact Settings'),
'$tab_str' => $tab_str,
'$warning' => $warning,
'$info' => $info,
'$returnaddr' => $returnaddr,
'$return' => t('Return to contact editor'),
'$update_profile' => update_profile,
'$udprofilenow' => t('Refetch contact data'),
'$contact_id' => $contact['id'],
'$lbl_submit' => t('Submit'),
$o = replace_macros($tpl, array(
'$tab_str' => $tab_str,
'$warning' => $warning,
'$info' => $info,
'$returnaddr' => $returnaddr,
'$return' => t('Return to contact editor'),
'$update_profile' => $update_profile,
'$udprofilenow' => t('Refetch contact data'),
'$contact_id' => $contact['id'],
'$lbl_submit' => t('Submit'),
'$label_remote_self' => t('Remote Self'),
'$allow_remote_self' => $allow_remote_self,
'$remote_self' => array('remote_self',
t('Mirror postings from this contact'),
$contact['remote_self'],
t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
$remote_self_options
),
t('Mirror postings from this contact'),
$contact['remote_self'],
t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
$remote_self_options
),
'$name' => array('name', t('Name') , htmlentities($contact['name'])),
'$nick' => array('nick', t('Account Nickname'), htmlentities($contact['nick'])),
@ -183,5 +184,4 @@ function crepair_content(App $a) {
));
return $o;
}

89
mod/hovercard.php

@ -7,90 +7,87 @@
* Author: Rabuzarus <https://github.com/rabuzarus>
* License: GNU AFFERO GENERAL PUBLIC LICENSE (Version 3)
*/
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
function hovercard_init(App $a) {
function hovercard_init(App $a)
{
// Just for testing purposes
$_GET["mode"] = "minimal";
$_GET['mode'] = 'minimal';
}
function hovercard_content() {
$profileurl = (x($_REQUEST,'profileurl') ? $_REQUEST['profileurl'] : "");
$datatype = (x($_REQUEST,'datatype') ?$_REQUEST['datatype'] : "json");
function hovercard_content()
{
$profileurl = defaults($_REQUEST, 'profileurl', '');
$datatype = defaults($_REQUEST, 'datatype' , 'json');
// Get out if the system doesn't have public access allowed
if(intval(Config::get('system','block_public')))
if (intval(Config::get('system', 'block_public'))) {
http_status_exit(401);
}
// Return the raw content of the template. We use this to make templates usable for js functions.
// Look at hovercard.js (function getHoverCardTemplate()).
// This part should be moved in it's own module. Maybe we could make more templates accessabel.
// (We need to discuss possible security lacks before doing this)
if ($datatype == "tpl") {
$templatecontent = get_template_content("hovercard.tpl");
// This part should be moved in its own module. Maybe we could make more templates accessible.
// (We need to discuss possible security leaks before doing this)
if ($datatype == 'tpl') {
$templatecontent = get_template_content('hovercard.tpl');
echo $templatecontent;
killme();
}
// If a contact is connected the url is internally changed to "redir/CID". We need the pure url to search for
// If a contact is connected the url is internally changed to 'redir/CID'. We need the pure url to search for
// the contact. So we strip out the contact id from the internal url and look in the contact table for
// the real url (nurl)
if (local_user() && strpos($profileurl, "redir/") === 0) {
$cid = 0;
if (local_user() && strpos($profileurl, 'redir/') === 0) {
$cid = intval(substr($profileurl, 6));
$r = dba::select('contact', array('nurl', 'self'), array('id' => $cid), array('limit' => 1));
$profileurl = ($r["nurl"] ? $r["nurl"] : "");
$self = ($r["self"] ? $r["self"] : "");
$r = dba::select('contact', array('nurl'), array('id' => $cid), array('limit' => 1));
$profileurl = defaults($r, 'nurl', '');
}
$contact = [];
// if it's the url containing https it should be converted to http
$nurl = normalise_link(GContact::cleanContactUrl($profileurl));
if($nurl) {
if ($nurl) {
// Search for contact data
$contact = Contact::getDetailsByURL($nurl);
}
if(!is_array($contact))
if (!count($contact)) {
return;
}
// Get the photo_menu - the menu if possible contact actions
if(local_user())
if (local_user()) {
$actions = Contact::photoMenu($contact);
}
// Move the contact data to the profile array so we can deliver it to
//
$profile = array(
'name' => $contact["name"],
'nick' => $contact["nick"],
'addr' => (($contact["addr"] != "") ? $contact["addr"] : $contact["url"]),
'thumb' => proxy_url($contact["thumb"], false, PROXY_SIZE_THUMB),
'url' => ($cid ? ("redir/".$cid) : zrl($contact["url"])),
'nurl' => $contact["nurl"], // We additionally store the nurl as identifier
// 'alias' => $contact["alias"],
'location' => $contact["location"],
'gender' => $contact["gender"],
'about' => $contact["about"],
'network' => format_network_name($contact["network"], $contact["url"]),
'tags' => $contact["keywords"],
// 'nsfw' => intval($contact["nsfw"]),
// 'server_url' => $contact["server_url"],
'bd' => (($contact["birthday"] <= '0001-01-01') ? "" : $contact["birthday"]),
// 'generation' => $contact["generation"],
'name' => $contact['name'],
'nick' => $contact['nick'],
'addr' => defaults($contact, 'addr', $contact['url']),
'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
'url' => $cid ? ('redir/' . $cid) : zrl($contact['url']),
'nurl' => $contact['nurl'], // We additionally store the nurl as identifier
'location' => $contact['location'],
'gender' => $contact['gender'],
'about' => $contact['about'],
'network' => format_network_name($contact['network'], $contact['url']),
'tags' => $contact['keywords'],
'bd' => $contact['birthday'] <= '0001-01-01' ? '' : $contact['birthday'],
'account_type' => Contact::getAccountType($contact),
'actions' => $actions,
'actions' => $actions,
);
if($datatype == "html") {
$t = get_markup_template("hovercard.tpl");
$o = replace_macros($t, array(
if ($datatype == 'html') {
$tpl = get_markup_template('hovercard.tpl');
$o = replace_macros($tpl, array(
'$profile' => $profile,
));
return $o;
} else {
json_return_and_die($profile);
}
@ -104,15 +101,15 @@ function hovercard_content() {
*
* @return string|bool Output the raw content if existent, otherwise false
*/
function get_template_content($template, $root = "") {
function get_template_content($template, $root = '')
{
// We load the whole template system to get the filename.
// Maybe we can do it a little bit smarter if I get time.
$t = get_markup_template($template, $root);
$filename = $t->filename;
// Get the content of the template file
if(file_exists($filename)) {
if (file_exists($filename)) {
$content = file_get_contents($filename);
return $content;

Loading…
Cancel
Save