bring back birthdays
This commit is contained in:
parent
576c36c56f
commit
2386bc4d00
@ -443,6 +443,12 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the next birthday, converted from the owner's timezone to UTC.
|
||||||
|
* This makes it globally portable.
|
||||||
|
* If the provided birthday lacks a month and or day, return an empty string.
|
||||||
|
* A missing year is acceptable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
function z_birthday($dob,$tz,$format="Y-m-d H:i:s") {
|
function z_birthday($dob,$tz,$format="Y-m-d H:i:s") {
|
||||||
@ -450,8 +456,10 @@ function z_birthday($dob,$tz,$format="Y-m-d H:i:s") {
|
|||||||
if(! strlen($tz))
|
if(! strlen($tz))
|
||||||
$tz = 'UTC';
|
$tz = 'UTC';
|
||||||
|
|
||||||
|
$birthday = '';
|
||||||
$tmp_dob = substr($dob,5);
|
$tmp_dob = substr($dob,5);
|
||||||
if(intval($tmp_dob)) {
|
$tmp_d = substr($dob,8);
|
||||||
|
if(intval($tmp_dob) && intval($tmp_d)) {
|
||||||
$y = datetime_convert($tz,$tz,'now','Y');
|
$y = datetime_convert($tz,$tz,'now','Y');
|
||||||
$bd = $y . '-' . $tmp_dob . ' 00:00';
|
$bd = $y . '-' . $tmp_dob . ' 00:00';
|
||||||
$t_dob = strtotime($bd);
|
$t_dob = strtotime($bd);
|
||||||
@ -464,3 +472,43 @@ function z_birthday($dob,$tz,$format="Y-m-d H:i:s") {
|
|||||||
return $birthday;
|
return $birthday;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Create a birthday event for any connections with a birthday in the next 1-2 weeks.
|
||||||
|
* Update the year so that we don't create another event until next year.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
function update_birthdays() {
|
||||||
|
|
||||||
|
require_once('include/event.php');
|
||||||
|
|
||||||
|
$r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash
|
||||||
|
WHERE abook_dob > utc_timestamp() + interval 7 day and abook_dob < utc_timestamp() + interval 14 day");
|
||||||
|
if($r) {
|
||||||
|
foreach($r as $rr) {
|
||||||
|
$ev = array();
|
||||||
|
$ev['uid'] = $rr['abook_channel'];
|
||||||
|
$ev['account'] = $rr['abook_account'];
|
||||||
|
$ev['event_xchan'] = $rr['xchan_hash'];
|
||||||
|
$ev['start'] = datetime_convert('UTC','UTC', $rr['abook_dob']);
|
||||||
|
$ev['finish'] = datetime_convert('UTC','UTC', $rr['abook_dob'] . ' + 1 day ');
|
||||||
|
$ev['adjust'] = 1;
|
||||||
|
$ev['summary'] = sprintf( t('%1$s\'s birthday'), $rr['xchan_name']);
|
||||||
|
$ev['description'] = sprintf( t('Happy Birthday %1$s'),
|
||||||
|
'[zrl=' . $rr['xchan_url'] . ']' . $rr['xchan_name'] . '[/zrl]') ;
|
||||||
|
$ev['type'] = 'birthday';
|
||||||
|
|
||||||
|
$z = event_store_event($ev);
|
||||||
|
if($z) {
|
||||||
|
$item_id = event_store_item($ev,$z);
|
||||||
|
q("update abook set abook_dob = '%s' where abook_id = %d limit 1",
|
||||||
|
dbesc(intval($rr['abook_dob']) + 1 . substr($rr['abook_dob'],4)),
|
||||||
|
intval($rr['abook_id'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -318,6 +318,8 @@ function event_store_item($arr,$event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prefix = (($event['type'] === 'birthday') ? t('This event has been added to your calendar.') . "\n\n" : '');
|
||||||
|
|
||||||
$r = q("SELECT * FROM item left join xchan on author_xchan = xchan_hash WHERE resource_id = '%s' AND resource_type = 'event' and uid = %d LIMIT 1",
|
$r = q("SELECT * FROM item left join xchan on author_xchan = xchan_hash WHERE resource_id = '%s' AND resource_type = 'event' and uid = %d LIMIT 1",
|
||||||
dbesc($event['event_hash']),
|
dbesc($event['event_hash']),
|
||||||
intval($arr['uid'])
|
intval($arr['uid'])
|
||||||
@ -342,10 +344,9 @@ function event_store_item($arr,$event) {
|
|||||||
|
|
||||||
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
|
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
|
||||||
|
|
||||||
|
|
||||||
q("UPDATE item SET title = '%s', body = '%s', object = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', edited = '%s', item_flags = %d, item_private = %d WHERE id = %d AND uid = %d LIMIT 1",
|
q("UPDATE item SET title = '%s', body = '%s', object = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', edited = '%s', item_flags = %d, item_private = %d WHERE id = %d AND uid = %d LIMIT 1",
|
||||||
dbesc($arr['summary']),
|
dbesc($arr['summary']),
|
||||||
dbesc(format_event_bbcode($arr)),
|
dbesc($prefix . format_event_bbcode($arr)),
|
||||||
dbesc($object),
|
dbesc($object),
|
||||||
dbesc($arr['allow_cid']),
|
dbesc($arr['allow_cid']),
|
||||||
dbesc($arr['allow_gid']),
|
dbesc($arr['allow_gid']),
|
||||||
@ -412,7 +413,8 @@ function event_store_item($arr,$event) {
|
|||||||
$item_arr['resource_id'] = $event['event_hash'];
|
$item_arr['resource_id'] = $event['event_hash'];
|
||||||
|
|
||||||
$item_arr['obj_type'] = ACTIVITY_OBJ_EVENT;
|
$item_arr['obj_type'] = ACTIVITY_OBJ_EVENT;
|
||||||
$item_arr['body'] = format_event_bbcode($arr);
|
|
||||||
|
$item_arr['body'] = $prefix . format_event_bbcode($arr);
|
||||||
|
|
||||||
$item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . $item_arr['mid'];
|
$item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . $item_arr['mid'];
|
||||||
|
|
||||||
|
@ -123,6 +123,8 @@ function poller_run($argv, $argc){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_birthdays();
|
||||||
|
|
||||||
// expire any read notifications over a month old
|
// expire any read notifications over a month old
|
||||||
|
|
||||||
q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY");
|
q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY");
|
||||||
|
@ -355,14 +355,22 @@ function zot_refresh($them,$channel = null, $force = false) {
|
|||||||
intval(ABOOK_FLAG_SELF)
|
intval(ABOOK_FLAG_SELF)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(array_key_exists('profile',$j) && array_key_exists('next_birthday',$j['profile'])) {
|
||||||
|
$next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$next_birthday = '0000-00-00 00:00:00';
|
||||||
|
}
|
||||||
|
|
||||||
if($r) {
|
if($r) {
|
||||||
|
|
||||||
$current_abook_connected = (($r[0]['abook_flags'] & ABOOK_FLAG_UNCONNECTED) ? 0 : 1);
|
$current_abook_connected = (($r[0]['abook_flags'] & ABOOK_FLAG_UNCONNECTED) ? 0 : 1);
|
||||||
|
|
||||||
$y = q("update abook set abook_their_perms = %d
|
$y = q("update abook set abook_their_perms = %d, abook_dob = '%s'
|
||||||
where abook_xchan = '%s' and abook_channel = %d
|
where abook_xchan = '%s' and abook_channel = %d
|
||||||
and not (abook_flags & %d) limit 1",
|
and not (abook_flags & %d) limit 1",
|
||||||
intval($their_perms),
|
intval($their_perms),
|
||||||
|
dbesc($next_birthday),
|
||||||
dbesc($x['hash']),
|
dbesc($x['hash']),
|
||||||
intval($channel['channel_id']),
|
intval($channel['channel_id']),
|
||||||
intval(ABOOK_FLAG_SELF)
|
intval(ABOOK_FLAG_SELF)
|
||||||
@ -402,7 +410,7 @@ function zot_refresh($them,$channel = null, $force = false) {
|
|||||||
if($z)
|
if($z)
|
||||||
$default_perms = intval($z[0]['abook_my_perms']);
|
$default_perms = intval($z[0]['abook_my_perms']);
|
||||||
|
|
||||||
$y = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated, abook_flags ) values ( %d, %d, '%s', %d, %d, '%s', '%s', %d )",
|
$y = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated, abook_dob, abook_flags ) values ( %d, %d, '%s', %d, %d, '%s', '%s', '%s', %d )",
|
||||||
intval($channel['channel_account_id']),
|
intval($channel['channel_account_id']),
|
||||||
intval($channel['channel_id']),
|
intval($channel['channel_id']),
|
||||||
dbesc($x['hash']),
|
dbesc($x['hash']),
|
||||||
@ -410,6 +418,7 @@ function zot_refresh($them,$channel = null, $force = false) {
|
|||||||
intval($default_perms),
|
intval($default_perms),
|
||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
|
dbesc($next_birthday),
|
||||||
intval(($default_perms) ? 0 : ABOOK_FLAG_PENDING)
|
intval(($default_perms) ? 0 : ABOOK_FLAG_PENDING)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -74,10 +74,15 @@ function zfinger_init(&$a) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
||||||
where (( channel_pageflags & %d ) or not ( channel_pageflags & %d )) order by channel_id limit 1",
|
where ( channel_pageflags & %d ) order by channel_id limit 1",
|
||||||
intval(PAGE_SYSTEM),
|
intval(PAGE_SYSTEM)
|
||||||
intval(PAGE_REMOVED)
|
|
||||||
);
|
);
|
||||||
|
if(! $r) {
|
||||||
|
$r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash
|
||||||
|
where not ( channel_pageflags & %d ) order by channel_id limit 1",
|
||||||
|
intval(PAGE_REMOVED)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -116,8 +121,8 @@ function zfinger_init(&$a) {
|
|||||||
|
|
||||||
$profile['description'] = $p[0]['pdesc'];
|
$profile['description'] = $p[0]['pdesc'];
|
||||||
$profile['birthday'] = $p[0]['dob'];
|
$profile['birthday'] = $p[0]['dob'];
|
||||||
if($profile['birthday'] != '0000-00-00')
|
if(($profile['birthday'] != '0000-00-00') && (($bd = z_birthday($p[0]['dob'],$e['channel_timezone'])) !== ''))
|
||||||
$profile['next_birthday'] = z_birthday($p[0]['dob'],$e['channel_timezone']);
|
$profile['next_birthday'] = $bd;
|
||||||
|
|
||||||
if($age = age($p[0]['dob'],$e['channel_timezone'],''))
|
if($age = age($p[0]['dob'],$e['channel_timezone'],''))
|
||||||
$profile['age'] = $age;
|
$profile['age'] = $age;
|
||||||
|
Reference in New Issue
Block a user