Merge pull request #6183 from MrPetovan/bug/6135-hide-follower-only-birthdays

Hide follower-only birthday reminders
This commit is contained in:
Michael Vogel 2018-11-24 15:55:43 +01:00 committed by GitHub
commit 3f4636d490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 142 additions and 174 deletions

View file

@ -740,7 +740,7 @@ class Contact extends BaseObject
// "bd" always contains the upcoming birthday of a contact.
// "birthday" might contain the birthday including the year of birth.
if ($profile["birthday"] > '0001-01-01') {
if ($profile["birthday"] > DBA::NULL_DATE) {
$bd_timestamp = strtotime($profile["birthday"]);
$month = date("m", $bd_timestamp);
$day = date("d", $bd_timestamp);
@ -757,7 +757,7 @@ class Contact extends BaseObject
$profile["bd"] = ( ++$current_year) . "-" . $month . "-" . $day;
}
} else {
$profile["bd"] = '0001-01-01';
$profile["bd"] = DBA::NULL_DATE;
}
} else {
$profile = $default;
@ -794,7 +794,7 @@ class Contact extends BaseObject
$profile["location"] = "";
$profile["about"] = "";
$profile["gender"] = "";
$profile["birthday"] = '0001-01-01';
$profile["birthday"] = DBA::NULL_DATE;
}
$cache[$url][$uid] = $profile;
@ -1962,44 +1962,33 @@ class Contact extends BaseObject
*/
public static function updateBirthdays()
{
// This only handles foreign or alien networks where a birthday has been provided.
// In-network birthdays are handled within local_delivery
$condition = [
'`bd` != ""
AND `bd` > "0001-01-01"
AND SUBSTRING(`bd`, 1, 4) != `bdyear`
AND (`contact`.`rel` = ? OR `contact`.`rel` = ?)
AND NOT `contact`.`pending`
AND NOT `contact`.`hidden`
AND NOT `contact`.`blocked`
AND NOT `contact`.`archive`
AND NOT `contact`.`deleted`',
Contact::SHARING,
Contact::FRIEND
];
$r = q("SELECT * FROM `contact` WHERE `bd` != '' AND `bd` > '0001-01-01' AND SUBSTRING(`bd`, 1, 4) != `bdyear` ");
if (DBA::isResult($r)) {
foreach ($r as $rr) {
Logger::log('update_contact_birthday: ' . $rr['bd']);
$contacts = DBA::select('contact', ['id', 'uid', 'name', 'url', 'bd'], $condition);
$nextbd = DateTimeFormat::utcNow('Y') . substr($rr['bd'], 4);
while ($contact = DBA::fetch($contacts)) {
Logger::log('update_contact_birthday: ' . $contact['bd']);
/*
* Add new birthday event for this person
*
* $bdtext is just a readable placeholder in case the event is shared
* with others. We will replace it during presentation to our $importer
* to contain a sparkle link and perhaps a photo.
*/
// Check for duplicates
$condition = ['uid' => $rr['uid'], 'cid' => $rr['id'],
'start' => DateTimeFormat::utc($nextbd), 'type' => 'birthday'];
if (DBA::exists('event', $condition)) {
continue;
}
$bdtext = L10n::t('%s\'s birthday', $rr['name']);
$bdtext2 = L10n::t('Happy Birthday %s', ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]');
q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ", intval($rr['uid']), intval($rr['id']),
DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utc($nextbd)),
DBA::escape(DateTimeFormat::utc($nextbd . ' + 1 day ')), DBA::escape($bdtext), DBA::escape($bdtext2), DBA::escape('birthday'),
intval(0)
);
$nextbd = DateTimeFormat::utcNow('Y') . substr($contact['bd'], 4);
if (Event::createBirthday($contact, $nextbd)) {
// update bdyear
q("UPDATE `contact` SET `bdyear` = '%s', `bd` = '%s' WHERE `uid` = %d AND `id` = %d", DBA::escape(substr($nextbd, 0, 4)),
DBA::escape($nextbd), intval($rr['uid']), intval($rr['id'])
DBA::update(
'contact',
['bdyear' => substr($nextbd, 0, 4), 'bd' => $nextbd],
['id' => $contact['id']]
);
}
}

View file

@ -322,43 +322,48 @@ class Event extends BaseObject
// New event. Store it.
DBA::insert('event', $event);
$event['id'] = DBA::lastInsertId();
$item_id = 0;
$item_arr = [];
// Don't create an item for birthday events
if ($event['type'] == 'event') {
$event['id'] = DBA::lastInsertId();
$item_arr['uid'] = $event['uid'];
$item_arr['contact-id'] = $event['cid'];
$item_arr['uri'] = $event['uri'];
$item_arr['parent-uri'] = $event['uri'];
$item_arr['guid'] = $event['guid'];
$item_arr['plink'] = defaults($arr, 'plink', '');
$item_arr['post-type'] = Item::PT_EVENT;
$item_arr['wall'] = $event['cid'] ? 0 : 1;
$item_arr['contact-id'] = $contact['id'];
$item_arr['owner-name'] = $contact['name'];
$item_arr['owner-link'] = $contact['url'];
$item_arr['owner-avatar'] = $contact['thumb'];
$item_arr['author-name'] = $contact['name'];
$item_arr['author-link'] = $contact['url'];
$item_arr['author-avatar'] = $contact['thumb'];
$item_arr['title'] = '';
$item_arr['allow_cid'] = $event['allow_cid'];
$item_arr['allow_gid'] = $event['allow_gid'];
$item_arr['deny_cid'] = $event['deny_cid'];
$item_arr['deny_gid'] = $event['deny_gid'];
$item_arr['private'] = $private;
$item_arr['visible'] = 1;
$item_arr['verb'] = ACTIVITY_POST;
$item_arr['object-type'] = ACTIVITY_OBJ_EVENT;
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
$item_arr['body'] = self::getBBCode($event);
$item_arr['event-id'] = $event['id'];
$item_arr = [];
$item_arr['object'] = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
$item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
$item_arr['object'] .= '</object>' . "\n";
$item_arr['uid'] = $event['uid'];
$item_arr['contact-id'] = $event['cid'];
$item_arr['uri'] = $event['uri'];
$item_arr['parent-uri'] = $event['uri'];
$item_arr['guid'] = $event['guid'];
$item_arr['plink'] = defaults($arr, 'plink', '');
$item_arr['post-type'] = Item::PT_EVENT;
$item_arr['wall'] = $event['cid'] ? 0 : 1;
$item_arr['contact-id'] = $contact['id'];
$item_arr['owner-name'] = $contact['name'];
$item_arr['owner-link'] = $contact['url'];
$item_arr['owner-avatar'] = $contact['thumb'];
$item_arr['author-name'] = $contact['name'];
$item_arr['author-link'] = $contact['url'];
$item_arr['author-avatar'] = $contact['thumb'];
$item_arr['title'] = '';
$item_arr['allow_cid'] = $event['allow_cid'];
$item_arr['allow_gid'] = $event['allow_gid'];
$item_arr['deny_cid'] = $event['deny_cid'];
$item_arr['deny_gid'] = $event['deny_gid'];
$item_arr['private'] = $private;
$item_arr['visible'] = 1;
$item_arr['verb'] = ACTIVITY_POST;
$item_arr['object-type'] = ACTIVITY_OBJ_EVENT;
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
$item_arr['body'] = self::getBBCode($event);
$item_arr['event-id'] = $event['id'];
$item_id = Item::insert($item_arr);
$item_arr['object'] = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
$item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
$item_arr['object'] .= '</object>' . "\n";
$item_id = Item::insert($item_arr);
}
Addon::callHooks("event_created", $event['id']);
}
@ -981,4 +986,47 @@ class Event extends BaseObject
return $location;
}
/**
* @brief Add new birthday event for this person
*
* @param array $contact Contact array, expects: id, uid, url, name
* @param string $birthday Birthday of the contact
* @return bool
*/
public static function createBirthday($contact, $birthday)
{
// Check for duplicates
$condition = [
'uid' => $contact['uid'],
'cid' => $contact['id'],
'start' => DateTimeFormat::utc($birthday),
'type' => 'birthday'
];
if (DBA::exists('event', $condition)) {
return false;
}
/*
* Add new birthday event for this person
*
* summary is just a readable placeholder in case the event is shared
* with others. We will replace it during presentation to our $importer
* to contain a sparkle link and perhaps a photo.
*/
$values = [
'uid' => $contact['uid'],
'cid' => $contact['id'],
'start' => DateTimeFormat::utc($birthday),
'finish' => DateTimeFormat::utc($birthday . ' + 1 day '),
'summary' => L10n::t('%s\'s birthday', $contact['name']),
'desc' => L10n::t('Happy Birthday %s', ' [url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'),
'type' => 'birthday',
'adjust' => 0
];
self::store($values);
return true;
}
}

View file

@ -864,7 +864,7 @@ class GContact
'location' => $contact['location'], 'about' => $contact['about']];
// Don't update the birthday field if not set or invalid
if (empty($contact['birthday']) || ($contact['birthday'] < '0001-01-01')) {
if (empty($contact['birthday']) || ($contact['birthday'] <= DBA::NULL_DATE)) {
unset($fields['bd']);
}

View file

@ -572,9 +572,18 @@ class Profile
if (is_null($r)) {
$s = DBA::p(
"SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event`
INNER JOIN `contact` ON `contact`.`id` = `event`.`cid`
INNER JOIN `contact`
ON `contact`.`id` = `event`.`cid`
AND (`contact`.`rel` = ? OR `contact`.`rel` = ?)
AND NOT `contact`.`pending`
AND NOT `contact`.`hidden`
AND NOT `contact`.`blocked`
AND NOT `contact`.`archive`
AND NOT `contact`.`deleted`
WHERE `event`.`uid` = ? AND `type` = 'birthday' AND `start` < ? AND `finish` > ?
ORDER BY `start` ASC ",
Contact::SHARING,
Contact::FRIEND,
local_user(),
DateTimeFormat::utc('now + 6 days'),
DateTimeFormat::utcNow()
@ -749,7 +758,7 @@ class Profile
$profile['gender'] = [L10n::t('Gender:'), $a->profile['gender']];
}
if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
if (!empty($a->profile['dob']) && $a->profile['dob'] > DBA::NULL_DATE) {
$year_bd_format = L10n::t('j F, Y');
$short_bd_format = L10n::t('j F');
@ -763,7 +772,7 @@ class Profile
}
if (!empty($a->profile['dob'])
&& $a->profile['dob'] > '0001-01-01'
&& $a->profile['dob'] > DBA::NULL_DATE
&& $age = Temporal::getAgeByTimezone($a->profile['dob'], $a->profile['timezone'], '')
) {
$profile['age'] = [L10n::t('Age:'), $age];