From c72c64a6d82063877e7f3013428ddef0dd44fd1b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 2 Aug 2018 07:21:01 +0200 Subject: [PATCH] Notices again (#5543) * And again notices * Notices in the directory * Much more places * Fix some double $ * Notice in ping * Missing field * Fix: We now remove deleted users from the directory * Some more stuff * Notices when removing users * Added logging * More logging * Two more --- include/enotify.php | 21 ++++++++++++++------ index.php | 10 ++++++---- mod/dfrn_poll.php | 3 ++- mod/dfrn_request.php | 2 +- mod/directory.php | 4 ++++ mod/group.php | 24 ++++++++++++----------- mod/ping.php | 4 ++-- mod/probe.php | 2 +- src/Content/Text/BBCode.php | 6 +++--- src/Model/Contact.php | 32 +++++++++++++++++-------------- src/Model/Event.php | 2 +- src/Model/User.php | 3 ++- src/Module/Proxy.php | 4 ++-- src/Network/Probe.php | 20 ++++++++++--------- src/Protocol/Email.php | 10 ++++++++++ view/theme/duepuntozero/style.php | 4 +++- view/theme/frio/style.php | 1 + 17 files changed, 95 insertions(+), 57 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index 35f984b0ec..6d27aa8897 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -27,6 +27,11 @@ function notification($params) { $a = get_app(); + // Temporary logging for finding the origin + if (!isset($params['language']) || !isset($params['uid'])) { + logger('Missing parameters.' . System::callstack()); + } + // from here on everything is in the recipients language L10n::pushLang($params['language']); @@ -57,8 +62,10 @@ function notification($params) if (!DBA::isResult($user) || in_array($user["page-flags"], [Contact::PAGE_COMMUNITY, Contact::PAGE_PRVGROUP])) { return; } + $nickname = $user["nickname"]; + } else { + $nickname = ''; } - $nickname = $user["nickname"]; // with $params['show_in_notification_page'] == false, the notification isn't inserted into // the database, and an email is sent if applicable. @@ -93,6 +100,8 @@ function notification($params) $parent_id = 0; } + $epreamble = ''; + if ($params['type'] == NOTIFY_MAIL) { $itemlink = $siteurl.'/message/'.$params['item']['id']; $params["link"] = $itemlink; @@ -529,7 +538,7 @@ function notification($params) } // send email notification if notification preferences permit - if ((intval($params['notify_flags']) & intval($params['type'])) + if ((!empty($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM || $params['type'] == SYSTEM_EMAIL) { @@ -577,11 +586,11 @@ function notification($params) $datarray['siteurl'] = $siteurl; $datarray['type'] = $params['type']; $datarray['parent'] = $parent_id; - $datarray['source_name'] = $params['source_name']; - $datarray['source_link'] = $params['source_link']; - $datarray['source_photo'] = $params['source_photo']; + $datarray['source_name'] = defaults($params, 'source_name', ''); + $datarray['source_link'] = defaults($params, 'source_link', ''); + $datarray['source_photo'] = defaults($params, 'source_photo', ''); $datarray['uid'] = $params['uid']; - $datarray['username'] = $params['to_name']; + $datarray['username'] = defaults($params, 'to_name', ''); $datarray['hsitelink'] = $hsitelink; $datarray['tsitelink'] = $tsitelink; $datarray['hitemlink'] = ''.$itemlink.''; diff --git a/index.php b/index.php index 8d40dbf85f..41e177ce3b 100644 --- a/index.php +++ b/index.php @@ -92,11 +92,13 @@ if (!$a->is_backend()) { * We have to do it here because the session was just now opened. */ if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) { - // we haven't loaded user data yet, but we need user language - $user = DBA::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]); $_SESSION['language'] = $lang; - if (DBA::isResult($user)) { - $_SESSION['language'] = $user['language']; + // we haven't loaded user data yet, but we need user language + if (!empty($_SESSION['uid'])) { + $user = DBA::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]); + if (DBA::isResult($user)) { + $_SESSION['language'] = $user['language']; + } } } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 943ddddecc..5e5540be14 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -32,7 +32,8 @@ function dfrn_poll_init(App $a) $quiet = x($_GET, 'quiet'); // Possibly it is an OStatus compatible server that requests a user feed - if (($a->argc > 1) && ($dfrn_id == '') && !strstr($_SERVER["HTTP_USER_AGENT"], 'Friendica')) { + $user_agent = defaults($_SERVER, 'HTTP_USER_AGENT', ''); + if (($a->argc > 1) && ($dfrn_id == '') && !strstr($user_agent, 'Friendica')) { $nickname = $a->argv[1]; header("Content-type: application/atom+xml"); echo OStatus::feed($nickname, $last_update, 10); diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 9696e059a9..21c5d2c0fc 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -422,7 +422,7 @@ function dfrn_request_post(App $a) intval($uid), intval($contact_record['id']), ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0), - DBA::escape(notags(trim($_POST['dfrn-request-message']))), + DBA::escape(notags(trim(defaults($_POST, 'dfrn-request-message', '')))), DBA::escape($hash), DBA::escape(DateTimeFormat::utcNow()) ); diff --git a/mod/directory.php b/mod/directory.php index 9cddf3b4b5..411024dc1a 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -76,6 +76,8 @@ function directory_content(App $a) (`profile`.`education` LIKE '%$search%') OR (`profile`.`pub_keywords` LIKE '%$search%') OR (`profile`.`prv_keywords` LIKE '%$search%'))"; + } else { + $sql_extra = ''; } $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 " ); @@ -147,6 +149,8 @@ function directory_content(App $a) || (x($profile, 'country-name') == 1) ) { $location = L10n::t('Location:'); + } else { + $location = ''; } $gender = ((x($profile, 'gender') == 1) ? L10n::t('Gender:') : false); diff --git a/mod/group.php b/mod/group.php index 71a84a80ca..88b9830626 100644 --- a/mod/group.php +++ b/mod/group.php @@ -22,7 +22,7 @@ function group_init(App $a) { function group_post(App $a) { - if (! local_user()) { + if (!local_user()) { notice(L10n::t('Permission denied.') . EOL); return; } @@ -45,21 +45,21 @@ function group_post(App $a) { 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", intval($a->argv[1]), intval(local_user()) ); - if (! DBA::isResult($r)) { + if (!DBA::isResult($r)) { notice(L10n::t('Group not found.') . EOL); goaway(System::baseUrl() . '/contacts'); return; // NOTREACHED } $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", DBA::escape($groupname), intval(local_user()), @@ -79,13 +79,13 @@ function group_post(App $a) { function group_content(App $a) { $change = false; - if (! local_user()) { + if (!local_user()) { notice(L10n::t('Permission denied') . EOL); return; } // Switch to text mode interface if we have more than 'n' contacts or group members - + if ($a->argc == 1) { goaway(System::baseUrl() . '/contacts'); } @@ -113,11 +113,13 @@ function group_content(App $a) { } + $nogroup = false; + if (($a->argc == 2) && ($a->argv[1] === 'none')) { require_once 'mod/contacts.php'; $id = -1; - $nogroup = True; + $nogroup = true; $group = [ 'id' => $id, 'name' => L10n::t('Contacts not in any group'), @@ -173,7 +175,7 @@ function group_content(App $a) { } } - if (($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && intval($a->argv[1])) { require_once 'mod/contacts.php'; $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", @@ -181,7 +183,7 @@ function group_content(App $a) { intval(local_user()) ); - if (! DBA::isResult($r)) { + if (!DBA::isResult($r)) { notice(L10n::t('Group not found.') . EOL); goaway(System::baseUrl() . '/contacts'); } @@ -234,7 +236,7 @@ function group_content(App $a) { } - if (! isset($group)) { + if (!isset($group)) { return; } @@ -279,7 +281,7 @@ function group_content(App $a) { if (DBA::isResult($r)) { // Format the data of the contacts who aren't in the contact group foreach ($r as $member) { - if (! in_array($member['id'], $preselected)) { + if (!in_array($member['id'], $preselected)) { $entry = _contact_detail_for_template($member); $entry['label'] = 'contacts'; if (!$nogroup) diff --git a/mod/ping.php b/mod/ping.php index 2ac4924a96..99ebde70c1 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -108,7 +108,7 @@ function ping_init(App $a) if (local_user()) { // Different login session than the page that is calling us. - if (intval($_GET['uid']) && intval($_GET['uid']) != local_user()) { + if (!empty($_GET['uid']) && intval($_GET['uid']) != local_user()) { $data = ['result' => ['invalid' => 1]]; if ($format == 'json') { @@ -347,7 +347,7 @@ function ping_init(App $a) if (DBA::isResult($notifs)) { // Are the nofications called from the regular process or via the friendica app? - $regularnotifications = (intval($_GET['uid']) && intval($_GET['_'])); + $regularnotifications = (!empty($_GET['uid']) && !empty($_GET['_'])); foreach ($notifs as $notif) { if ($a->is_friendica_app() || !$regularnotifications) { diff --git a/mod/probe.php b/mod/probe.php index 5e7a5253fd..fb85de91bd 100644 --- a/mod/probe.php +++ b/mod/probe.php @@ -23,7 +23,7 @@ function probe_content(App $a) $o .= '

'; - if (x($_GET, 'addr')) { + if (!empty($_GET['addr'])) { $addr = trim($_GET['addr']); $res = Probe::uri($addr, "", 0, false); $o .= '
';
diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php
index 801e7054b2..76f8a8c2d8 100644
--- a/src/Content/Text/BBCode.php
+++ b/src/Content/Text/BBCode.php
@@ -86,7 +86,7 @@ class BBCode extends BaseObject
 					$post["url"] = $matches[1];
 					$post["title"] = $matches[2];
 				}
-				if (($post["url"] == "") && (in_array($post["type"], ["link", "video"]))
+				if (!empty($post["url"] == "") && (in_array($post["type"], ["link", "video"]))
 					&& preg_match("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $attacheddata, $matches)) {
 					$post["url"] = $matches[1];
 				}
@@ -609,7 +609,7 @@ class BBCode extends BaseObject
 		if (!$data) {
 			return $Text;
 		} elseif ($nolink) {
-			return $data["text"] . $data["after"];
+			return $data["text"] . defaults($data, 'after', '');
 		}
 
 		$title = htmlentities(defaults($data, 'title', ''), ENT_QUOTES, 'UTF-8', false);
@@ -632,7 +632,7 @@ class BBCode extends BaseObject
 
 		$text = $data["text"];
 
-		if (!empty($data["url"]) && ($data["title"] != "")) {
+		if (!empty($data["url"]) && !empty($data["title"])) {
 			$text .= "\n[url=" . $data["url"] . "]" . $data["title"] . "[/url]";
 		} elseif (!empty($data["url"])) {
 			$text .= "\n[url]" . $data["url"] . "[/url]";
diff --git a/src/Model/Contact.php b/src/Model/Contact.php
index 52eaa437f1..6f83dba019 100644
--- a/src/Model/Contact.php
+++ b/src/Model/Contact.php
@@ -1563,20 +1563,24 @@ class Contact extends BaseObject
 	}
 
 	public static function addRelationship($importer, $contact, $datarray, $item, $sharing = false) {
-		$url = notags(trim($datarray['author-link']));
-		$name = notags(trim($datarray['author-name']));
-		$photo = notags(trim($datarray['author-avatar']));
-		$nick = '';
-
-		if (is_object($item)) {
-			$rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
-			if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) {
-				$nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
-			}
-		} else {
-			$nick = $item;
+		// Should always be set
+		if (empty($datarray['author-id'])) {
+			return;
 		}
 
+		$fields = ['url', 'name', 'nick', 'photo', 'network'];
+		$pub_contact = DBA::selectFirst('contact', $fields, ['id' => $datarray['author-id']]);
+		if (!DBA::isResult($pub_contact)) {
+			// Should never happen
+			return;
+		}
+
+		$url = $pub_contact['url'];
+		$name = $pub_contact['name'];
+		$photo = $pub_contact['photo'];
+		$nick = $pub_contact['nick'];
+		$network = $pub_contact['network'];
+
 		if (is_array($contact)) {
 			if (($contact['rel'] == self::SHARING)
 				|| ($sharing && $contact['rel'] == self::FOLLOWER)) {
@@ -1601,13 +1605,13 @@ class Contact extends BaseObject
 				DBA::escape($name),
 				DBA::escape($nick),
 				DBA::escape($photo),
-				DBA::escape(NETWORK_OSTATUS),
+				DBA::escape($network),
 				intval(self::FOLLOWER)
 			);
 
 			$contact_record = [
 				'id' => DBA::lastInsertId(),
-				'network' => NETWORK_OSTATUS,
+				'network' => $network,
 				'name' => $name,
 				'url' => $url,
 				'photo' => $photo
diff --git a/src/Model/Event.php b/src/Model/Event.php
index c705a6ca7d..1bc922b465 100644
--- a/src/Model/Event.php
+++ b/src/Model/Event.php
@@ -89,7 +89,7 @@ class Event extends BaseObject
 			$o .= '
' . BBCode::convert($event['desc'], false, $simple) . '
' . "\r\n"; } - if (strlen($event['location'])) { + if (!empty($event['location'])) { $o .= '
' . L10n::t('Location:') . ' ' . BBCode::convert($event['location'], false, $simple) . '
' . "\r\n"; diff --git a/src/Model/User.php b/src/Model/User.php index c272d4c6ce..3fbbc6e86b 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -729,7 +729,8 @@ class User Worker::add(PRIORITY_HIGH, "Notifier", "removeme", $uid); // Send an update to the directory - Worker::add(PRIORITY_LOW, "Directory", $user['url']); + $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]); + Worker::add(PRIORITY_LOW, "Directory", $self['url']); if ($uid == local_user()) { unset($_SESSION['authenticated']); diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 6287727dce..bf6d6b6d03 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -139,7 +139,7 @@ class Proxy extends BaseModule $cachefile = get_cachefile(hash('md5', $_REQUEST['url'])); if ($cachefile != '' && file_exists($cachefile)) { $img_str = file_get_contents($cachefile); - $mime = image_type_to_mime_type(exif_imagetype($cachefile)); + $mime = mime_content_type($cachefile); header('Content-type: ' . $mime); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); @@ -187,7 +187,7 @@ class Proxy extends BaseModule $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); - $mime = image_type_to_mime_type(exif_imagetype($tempfile)); + $mime = mime_content_type($tempfile); unlink($tempfile); // If there is an error then return a blank image diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 8f236796a9..c515e066a2 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -946,7 +946,7 @@ class Probe // This logging is for temporarily debugging reasons if (!isset($data["poco"])) { - logger('POCO not defined for ' . profile_link, LOGGER_DEBUG); + logger('POCO not defined for ' . $profile_link . ' - ' . System::callstack(), LOGGER_DEBUG); } logger("Result for profile ".$profile_link.": ".print_r($prof_data, true), LOGGER_DEBUG); @@ -1603,14 +1603,16 @@ class Probe $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid)); - if (DBA::isResult($x) && DBA::isResult($r)) { - $mailbox = Email::constructMailboxName($r[0]); - $password = ''; - openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); - $mbox = Email::connect($mailbox, $r[0]['user'], $password); - if (!$mbox) { - return false; - } + if (!DBA::isResult($x) || !DBA::isResult($r)) { + return false; + } + + $mailbox = Email::constructMailboxName($r[0]); + $password = ''; + openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); + $mbox = Email::connect($mailbox, $r[0]['user'], $password); + if (!$mbox) { + return false; } $msgs = Email::poll($mbox, $uri); diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index c3825a16bd..0963feb0d2 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -25,6 +25,16 @@ class Email $mbox = @imap_open($mailbox, $username, $password); + $errors = imap_errors(); + if (!empty($errors)) { + logger('IMAP Errors occured: ' . json_encode($errors)); + } + + $alerts = imap_alerts(); + if (!empty($alerts)) { + logger('IMAP Alerts occured: ' . json_encode($alerts)); + } + return $mbox; } diff --git a/view/theme/duepuntozero/style.php b/view/theme/duepuntozero/style.php index 5d841f1084..ff55f462f1 100644 --- a/view/theme/duepuntozero/style.php +++ b/view/theme/duepuntozero/style.php @@ -19,6 +19,8 @@ if (!x($colorset)) { $colorset = $s_colorset; } +$setcss = ''; + if ($colorset) { if ($colorset == 'greenzero') { $setcss = file_get_contents('view/theme/duepuntozero/deriv/greenzero.css'); @@ -27,7 +29,7 @@ if ($colorset) { if ($colorset == 'purplezero') { $setcss = file_get_contents('view/theme/duepuntozero/deriv/purplezero.css'); } - + if ($colorset == 'easterbunny') { $setcss = file_get_contents('view/theme/duepuntozero/deriv/easterbunny.css'); } diff --git a/view/theme/frio/style.php b/view/theme/frio/style.php index 621f5d0cce..30f8a0d771 100644 --- a/view/theme/frio/style.php +++ b/view/theme/frio/style.php @@ -110,6 +110,7 @@ if (empty($login_bg_image) && empty($login_bg_color)) { $login_bg_image = 'img/login_bg.jpg'; } $login_bg_color = (empty($login_bg_color) ? '#ededed' : $login_bg_color); +$login_bg_image = (empty($login_bg_image) ? '' : $login_bg_image); $contentbg_transp = ((isset($contentbg_transp) && $contentbg_transp != '') ? $contentbg_transp : 100); -- 2.39.5