aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-06-02 17:49:19 -0700
committerfriendica <info@friendica.com>2014-06-02 17:49:19 -0700
commit2386bc4d00bac9a1ad1ae50380c351f46e4ca5c2 (patch)
tree5edc87644a619013e46a0b055f630e1eef82bb33 /include
parent576c36c56fd1e14deb2f1c9072988a45bab355cc (diff)
downloadvolse-hubzilla-2386bc4d00bac9a1ad1ae50380c351f46e4ca5c2.tar.gz
volse-hubzilla-2386bc4d00bac9a1ad1ae50380c351f46e4ca5c2.tar.bz2
volse-hubzilla-2386bc4d00bac9a1ad1ae50380c351f46e4ca5c2.zip
bring back birthdays
Diffstat (limited to 'include')
-rw-r--r--include/datetime.php50
-rw-r--r--include/event.php8
-rw-r--r--include/poller.php2
-rw-r--r--include/zot.php13
4 files changed, 67 insertions, 6 deletions
diff --git a/include/datetime.php b/include/datetime.php
index c0503fc7d..4884cda11 100644
--- a/include/datetime.php
+++ b/include/datetime.php
@@ -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") {
@@ -450,8 +456,10 @@ function z_birthday($dob,$tz,$format="Y-m-d H:i:s") {
if(! strlen($tz))
$tz = 'UTC';
+ $birthday = '';
$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');
$bd = $y . '-' . $tmp_dob . ' 00:00';
$t_dob = strtotime($bd);
@@ -464,3 +472,43 @@ function z_birthday($dob,$tz,$format="Y-m-d H:i:s") {
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'])
+ );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/include/event.php b/include/event.php
index 107b15427..861d74f00 100644
--- a/include/event.php
+++ b/include/event.php
@@ -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",
dbesc($event['event_hash']),
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);
-
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(format_event_bbcode($arr)),
+ dbesc($prefix . format_event_bbcode($arr)),
dbesc($object),
dbesc($arr['allow_cid']),
dbesc($arr['allow_gid']),
@@ -412,7 +413,8 @@ function event_store_item($arr,$event) {
$item_arr['resource_id'] = $event['event_hash'];
$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'];
diff --git a/include/poller.php b/include/poller.php
index 35844e666..926deeb47 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -123,6 +123,8 @@ function poller_run($argv, $argc){
}
+ update_birthdays();
+
// expire any read notifications over a month old
q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY");
diff --git a/include/zot.php b/include/zot.php
index 8c50d723d..578bdde49 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -355,14 +355,22 @@ function zot_refresh($them,$channel = null, $force = false) {
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) {
$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
and not (abook_flags & %d) limit 1",
intval($their_perms),
+ dbesc($next_birthday),
dbesc($x['hash']),
intval($channel['channel_id']),
intval(ABOOK_FLAG_SELF)
@@ -402,7 +410,7 @@ function zot_refresh($them,$channel = null, $force = false) {
if($z)
$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_id']),
dbesc($x['hash']),
@@ -410,6 +418,7 @@ function zot_refresh($them,$channel = null, $force = false) {
intval($default_perms),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
+ dbesc($next_birthday),
intval(($default_perms) ? 0 : ABOOK_FLAG_PENDING)
);