diff --git a/boot.php b/boot.php index 46c5144815..7e71a38d9e 100644 --- a/boot.php +++ b/boot.php @@ -182,6 +182,7 @@ class App { public $strings; public $path; public $hooks; + public $timezone; public $interactive = true; @@ -2118,3 +2119,60 @@ function call_hooks($name, &$data = null) { } }} + +if(! function_exists('day_translate')) { +function day_translate($s) { + $ret = str_replace(array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'), + array( t('Monday'), t('Tuesday'), t('Wednesday'), t('Thursday'), t('Friday'), t('Saturday'), t('Sunday')), + $s); + + $ret = str_replace(array('January','February','March','April','May','June','July','August','September','October','November','December'), + array( t('January'), t('February'), t('March'), t('April'), t('May'), t('June'), t('July'), t('August'), t('September'), t('October'), t('November'), t('December')), + $ret); + + return $ret; +}} + +if(! function_exists('get_birthdays')) { +function get_birthdays() { + + $a = get_app(); + $o = ''; + + if(! local_user()) + return $o; + + $bd_format = get_config('system','birthday_format'); + if(! $bd_format) + $bd_format = 'g A l F d' ; // 8 AM Friday January 18 + + $r = q("SELECT `event`.*, `event`.`id` AS `eid`, `contact`.* FROM `event` + LEFT JOIN `contact` ON `contact`.`id` = `event`.`cid` + WHERE `event`.`uid` = %d AND `type` = 'birthday' AND `start` < '%s' AND `finish` > '%s' + ORDER BY `start` DESC ", + intval(local_user()), + dbesc(datetime_convert('UTC','UTC','now + 6 days')), + dbesc(datetime_convert('UTC','UTC','now')) + ); + + if($r && count($r)) { + $o .= '
' . t('Birthdays this week:') . '
'; + $o .= '
' . t("\x28Adjusted for local time\x29") . '
'; + $o .= '
'; + + foreach($r as $rr) { + $now = strtotime('now'); + $today = (((strtotime($rr['start']) < $now) && (strtotime($rr['finish']) > $now)) ? true : false); + + $o .= '
' . $rr['name'] . ' ' + . day_translate(datetime_convert('UTC', $a->timezone, $rr['start'], $bd_format)) . (($today) ? ' ' . t('[today]') : '') ; + } + + $o .= '
'; + } + + return $o; + +}} + diff --git a/include/auth.php b/include/auth.php index d2bcb68dc8..a0244571b3 100644 --- a/include/auth.php +++ b/include/auth.php @@ -53,8 +53,11 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p $a->user = $r[0]; $_SESSION['theme'] = $a->user['theme']; $_SESSION['page_flags'] = $a->user['page-flags']; - if(strlen($a->user['timezone'])) + + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); + $a->timezone = $a->user['timezone']; + } $_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $a->user['nickname']; @@ -183,8 +186,11 @@ else { notice( t("Welcome back ") . $record['username'] . EOL); $a->user = $record; - if(strlen($a->user['timezone'])) + + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); + $a->timezone = $a->user['timezone']; + } $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); diff --git a/include/items.php b/include/items.php index c63e5c208d..47bc9f15a9 100644 --- a/include/items.php +++ b/include/items.php @@ -872,7 +872,7 @@ function dfrn_deliver($owner,$contact,$atom) { * */ -function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) { +function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) { require_once('simplepie/simplepie.inc'); @@ -890,7 +890,7 @@ function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) { $new_name = ''; $photo_timestamp = ''; $photo_url = ''; - + $birthday = ''; $hubs = $feed->get_links('hub'); @@ -908,10 +908,14 @@ function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) { $photo_timestamp = datetime_convert('UTC','UTC',$elems['link'][0]['attribs'][NAMESPACE_DFRN]['updated']); $photo_url = $elems['link'][0]['attribs']['']['href']; } + + if((x($rawtags[0]['child'], NAMESPACE_DFRN)) && (x($rawtags[0]['child'][NAMESPACE_DFRN],'birthday'))) { + $birthday = datetime_convert('UTC','UTC', $rawtags[0]['child'][NAMESPACE_DFRN]['birthday'][0]['data']); + } } if((is_array($contact)) && ($photo_timestamp) && (strlen($photo_url)) && ($photo_timestamp > $contact['avatar-date'])) { - logger('Consume feed: Updating photo for ' . $contact['name']); + logger('consume_feed: Updating photo for ' . $contact['name']); require_once("Photo.php"); $photo_failure = false; $have_photo = false; @@ -973,6 +977,53 @@ function consume_feed($xml,$importer,$contact, &$hub, $datedir = 0) { ); } + if(strlen($birthday)) { + if(substr($birthday,0,4) != $contact['bdyear']) { + logger('consume_feed: updating birthday: ' . $birthday); + + /** + * + * 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. + * + */ + + $bdtext = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . t('\'s birthday'); + + + $r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`desc`,`type`) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' ) ", + intval($contact['uid']), + intval($contact['id']), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert('UTC','UTC', $birthday)), + dbesc(datetime_convert('UTC','UTC', $birthday . ' + 1 day ')), + dbesc($bdtext), + dbesc('birthday') + ); + + + // update bdyear + + q("UPDATE `contact` SET `bdyear` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", + dbesc(substr($birthday,0,4)), + intval($contact['uid']), + intval($contact['id']) + ); + + // This function is called twice without reloading the contact + // Make sure we only create one event. This is why &$contact + // is a reference var in this function + + $contact['bdyear'] = substr($birthday,0,4); + } + + } + // Now process the feed if($feed->get_item_quantity()) { diff --git a/index.php b/index.php index 1c06967813..ae6a578cb4 100644 --- a/index.php +++ b/index.php @@ -71,7 +71,9 @@ if(! $install) { require_once("datetime.php"); -date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC'); +$a->timezone = (($default_timezone) ? $default_timezone : 'UTC'); + +date_default_timezone_set($a->timezone); $a->init_pagehead(); diff --git a/mod/openid.php b/mod/openid.php index 91efbbbc42..2e1025692d 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -72,8 +72,11 @@ function openid_content(&$a) { notice( t("Welcome back ") . $r[0]['username'] . EOL); $a->user = $r[0]; - if(strlen($a->user['timezone'])) + + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); + $a->timezone = $a->user['timezone']; + } $r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); diff --git a/mod/profile.php b/mod/profile.php index e8eee810bf..9b8388177d 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -228,6 +228,10 @@ function profile_content(&$a, $update = 0) { ); + + if($is_owner && ! $update) + $o .= get_birthdays(); + $cmnt_tpl = load_view_file('view/comment_item.tpl'); $like_tpl = load_view_file('view/like.tpl'); diff --git a/view/theme/default/style.css b/view/theme/default/style.css index 240ace8960..fd14c6bddd 100644 --- a/view/theme/default/style.css +++ b/view/theme/default/style.css @@ -1957,3 +1957,27 @@ a.mail-list-link { #plugin-settings-link, #account-settings-link { margin-bottom: 25px; } + + +#birthday-title { + float: left; + font-weight: bold; +} + +#birthday-adjust { + float: left; + font-size: 75%; + margin-left: 10px; +} + +#birthday-title-end { + clear: both; +} + +.birthday-list { + margin-left: 15px; +} + +#birthday-wrapper { + margin-bottom: 15px; +} diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index f64ad3fb89..37670df01e 100644 --- a/view/theme/duepuntozero/style.css +++ b/view/theme/duepuntozero/style.css @@ -1854,3 +1854,27 @@ a.mail-list-link { font-size: 120%; font-weight: bold; } + + +#birthday-title { + float: left; + font-weight: bold; +} + +#birthday-adjust { + float: left; + font-size: 75%; + margin-left: 10px; +} + +#birthday-title-end { + clear: both; +} + +.birthday-list { + margin-left: 15px; +} + +#birthday-wrapper { + margin-bottom: 15px; +}