### Eclipse Workspace Patch 1.0 #P birthdays-contrib Index: birthdays.page.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/birthdays/birthdays.page.inc,v retrieving revision 1.10 diff -u -r1.10 birthdays.page.inc --- birthdays.page.inc 8 Oct 2008 15:59:24 -0000 1.10 +++ birthdays.page.inc 18 May 2009 20:32:10 -0000 @@ -12,55 +12,55 @@ * Themed birthday listing of all users */ function birthdays_view_page() { - global $_birthdays_field; - // Nothing to see when the birthdays profile field hasn't been set yet. - if (!isset($_birthdays_field)) { - return NULL; - } - drupal_add_css(drupal_get_path('module', 'birthdays') .'/birthdays.css'); - if (isset($_REQUEST['birthdays_filter_month'])) { - $filter_month = (int) $_REQUEST['birthdays_filter_month']; - } - if (isset($_REQUEST['birthdays_filter_year'])) { - $filter_year = (int) $_REQUEST['birthdays_filter_year']; - } - $output = ''; - $filter = ''; - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - // Right join = filtering out - $join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN'; - $sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? 'MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), ' : ''; - $filter .= !empty($filter_month) ? " AND MONTH({dob}.birthday) = ". $filter_month : ''; - $filter .= !empty($filter_year) ? " AND YEAR({dob}.birthday) = ". $filter_year : ''; - break; - case 'pgsql': - // Right join = filtering out - $join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN'; - $sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? "date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), " : ''; - $filter .= !empty($filter_month) ? " AND date_part('month', {dob}.birthday) = ". $filter_month : ''; - $filter .= !empty($filter_year) ? " AND date_part('year', {dob}.birthday) = ". $filter_year : ''; - break; - } - - // Select all users (but ignore blocked and never logged in ones) - $result = pager_query("SELECT {users}.uid FROM {users} ". $join ." {dob} ON {users}.uid = {dob}.uid WHERE {users}.status <> 0 AND {users}.access <> 0". $filter ." ORDER BY ". $sort ."{users}.name", variable_get('birthdays_page_list_number', 25)); - - while ($uid = db_fetch_object($result)) { - // load the user objects - $account = user_load(array('uid' => $uid->uid)); - if (empty($filter_year) || !$account->birthdays_user_hide_year) { - $accounts[] = $account; - } - } - - // Call theme_birthdays_page - $output .= theme('birthdays_page', $accounts, $filter_month, $filter_year); - // Get the filter form + global $_birthdays_field; + // Nothing to see when the birthdays profile field hasn't been set yet. + if (!isset($_birthdays_field)) { + return NULL; + } + drupal_add_css(drupal_get_path('module', 'birthdays') .'/birthdays.css'); + if (isset($_REQUEST['birthdays_filter_month'])) { + $filter_month = (int) $_REQUEST['birthdays_filter_month']; + } + if (isset($_REQUEST['birthdays_filter_year'])) { + $filter_year = (int) $_REQUEST['birthdays_filter_year']; + } + $output = ''; + $filter = ''; + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + // Right join = filtering out + $join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN'; + $sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? 'MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), ' : ''; + $filter .= !empty($filter_month) ? " AND MONTH({dob}.birthday) = ". $filter_month : ''; + $filter .= !empty($filter_year) ? " AND YEAR({dob}.birthday) = ". $filter_year : ''; + break; + case 'pgsql': + // Right join = filtering out + $join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN'; + $sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? "date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), " : ''; + $filter .= !empty($filter_month) ? " AND date_part('month', {dob}.birthday) = ". $filter_month : ''; + $filter .= !empty($filter_year) ? " AND date_part('year', {dob}.birthday) = ". $filter_year : ''; + break; + } + + // Select all users (but ignore blocked and never logged in ones) + $result = pager_query("SELECT {users}.uid FROM {users} ". $join ." {dob} ON {users}.uid = {dob}.uid WHERE {users}.status <> 0 AND {users}.access <> 0". $filter ." ORDER BY ". $sort ."{users}.name", variable_get('birthdays_page_list_number', 25)); + + while ($uid = db_fetch_object($result)) { + // load the user objects + $account = user_load(array('uid' => $uid->uid)); + if (empty($filter_year) || !$account->{$_birthdays_field->name}['birthdays_user_hide_year']) { + $accounts[] = $account; + } + } + + // Call theme_birthdays_page + $output .= theme('birthdays_page', $accounts, $filter_month, $filter_year); + // Get the filter form - return $output; + return $output; } @@ -72,40 +72,40 @@ * @return array of the form */ function birthdays_page_filter($filter_month = NULL, $filter_year = NULL) { - $options_months[0] = ''; - for ($i = 1; $i <= 12; $i++) { - $options_months[$i] = format_date(gmmktime(0, 0, 0, $i, 2, 1970), 'custom', 'F', 0); - } + $options_months[0] = ''; + for ($i = 1; $i <= 12; $i++) { + $options_months[$i] = format_date(gmmktime(0, 0, 0, $i, 2, 1970), 'custom', 'F', 0); + } - $options_years[0] = ''; - $options_years = $options_years + drupal_map_assoc(range(date('Y'), 1900)); + $options_years[0] = ''; + $options_years = $options_years + drupal_map_assoc(range(date('Y'), 1900)); - $form['birthdays_filter_month'] = array( + $form['birthdays_filter_month'] = array( '#type' => 'select', '#options' => $options_months, '#default_value' => $filter_month, '#title' => t('Filter by month'), '#attributes' => array('onchange' => 'submit()'), - ); + ); - if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) != BIRTHDAYS_HIDE_YEAR_YES) { - $form['birthdays_filter_year'] = array( + if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) != BIRTHDAYS_HIDE_YEAR_YES) { + $form['birthdays_filter_year'] = array( '#type' => 'select', '#options' => $options_years, '#default_value' => $filter_year, '#title' => t('Year'), '#attributes' => array('onchange' => 'submit()'), - ); - } + ); + } - $form['button'] = array( + $form['button'] = array( '#type' => 'button', '#prefix' => '', - ); + ); - return $form; + return $form; } /** @@ -117,18 +117,18 @@ * - $filter_year */ function template_preprocess_birthdays_page(&$variables) { - global $_birthdays_field; + global $_birthdays_field; - $row = 0; - $birthdays = array(); + $row = 0; + $birthdays = array(); - $variables['show_year'] = variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) != BIRTHDAYS_HIDE_YEAR_YES; - $variables['show_starsign'] = (bool) variable_get('birthdays_show_starsign', BIRTHDAYS_STARSIGN_OFF); - $variables['show_user_picture'] = variable_get('user_pictures', FALSE); - $variables['show_filter'] = variable_get('birthdays_page_show_filters', 1); + $variables['show_year'] = variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) != BIRTHDAYS_HIDE_YEAR_YES; + $variables['show_starsign'] = (bool) variable_get('birthdays_show_starsign', BIRTHDAYS_STARSIGN_OFF); + $variables['show_user_picture'] = variable_get('user_pictures', FALSE); + $variables['show_filter'] = variable_get('birthdays_page_show_filters', 1); - foreach ($variables['accounts'] as $account) { - $birthdays[$row] = array( + foreach ($variables['accounts'] as $account) { + $birthdays[$row] = array( 'account' => $account, 'age' => _birthdays_show_age($account), 'username' => theme('username', $account), @@ -136,15 +136,15 @@ 'picture' => theme('user_picture', $account), 'date' => _birthdays_show_date($account->{$_birthdays_field->name}, $account), 'zebra' => $row % 2 == 0 ? 'odd' : 'even', - ); + ); - $birthdays[$row]['show_age'] = isset($birthdays[$row]['age']); + $birthdays[$row]['show_age'] = isset($birthdays[$row]['age']); - $row++; - } + $row++; + } - $variables['birthdays'] = $birthdays; + $variables['birthdays'] = $birthdays; - $variables['filter_form'] = drupal_get_form('birthdays_page_filter', $variables['filter_month'], $variables['filter_year']); - $variables['pager'] = theme('pager', NULL, variable_get('birthdays_page_list_number', 25), 0); + $variables['filter_form'] = drupal_get_form('birthdays_page_filter', $variables['filter_month'], $variables['filter_year']); + $variables['pager'] = theme('pager', NULL, variable_get('birthdays_page_list_number', 25), 0); } Index: birthdays.module =================================================================== RCS file: /cvs/drupal/contributions/modules/birthdays/birthdays.module,v retrieving revision 1.33 diff -u -r1.33 birthdays.module --- birthdays.module 14 Oct 2008 07:16:03 -0000 1.33 +++ birthdays.module 18 May 2009 20:32:10 -0000 @@ -127,57 +127,57 @@ * Implementation of hook_init(). */ function birthdays_init() { - global $_birthdays_field; - $_birthdays_field = _birthdays_get_field(variable_get('birthdays_field_id', NULL)); + global $_birthdays_field; + $_birthdays_field = _birthdays_get_field(variable_get('birthdays_field_id', NULL)); } /** * Implementation of hook_help(). */ function birthdays_help($path, $arg) { - global $_birthdays_field; - switch ($path) { - case 'admin/help#birthdays': - $output = '

' . t("The Birthdays module allows a user to put in their birthday and display it in their profile, on a separate Birthdays page and in a block. It also has the option to send out e-mails on users's birthdays, and to notify the administrator periodically about upcoming birthdays via e-mail.") . '

'; - $output .= '

' . t('Some basic information about this module can be found below. For more information, support questions, feature requests and bug reports please visit the Birthdays project page and the online documentation.', array('@project_url' => 'http://drupal.org/project/birthdays', '@documentation_url' => 'http://drupal.org/node/315658')) . '

'; - $output .= '

' . t('Configuring the module') . '

'; - $output .= '

' . t('Configuring the module is done on a number of pages.') . '

'; - $output .= '

' . t('Birthdays administration pages') . '

'; - $output .= '

' . t('The Birthdays administration pages are where the actual features of the birthdays module are set. Some of the options are described below.', array('@birthdays_admin' => url('admin/settings/birthdays'))) . '

'; - $output .= ''; - - $output .= '

' . t('Permissions') . '

'; - $output .= '

' . t('To allow users to view birthdays of other people, the "access birthdays" permissions needs to be set for the appropriate role. This allows them to access the Birthdays page, see activated blocks with birthdays and view the birthdays of users in the profiles.', array('@birthdays_page' => url('birthdays'), '@permissions_page' => url('admin/user/permissions', array('fragment' => 'module-birthdays')))) . '

'; - - $output .= '

' . t('Profile field settings') . '

'; - - $output .= '

' . t("Several things can be adjusted to the assigned profile field. To do so please visit the !profile_admin, and edit the field in question or add one if you haven't done so already. The following settings require extra attention.", array('!profile_admin' => l('Profile settings', 'admin/user/profile'))) . '

'; - - $output .= ''; - $output .= '

' . t('The other options on this page behave as described on the settings page.') . '

'; - - $output .= '

' . t('Date format') . '

'; - $output .= '

' . t('The way the birthdays are formatted (e.g. 11 may 1934 or 5/11/1934) is controlled by the date and time settings. The Birthdays module uses the short date format as basis for displaying days and months in the blocks and the medium date format is used in the profile and on the Birthdays page.', array('!date_settings_page' => url('admin/settings/date-time'))) . '

'; - - $output .= '

' . t('Synchronizing') . '

'; - - $output .= '

' . t('The birthdays are saved to two different database tables. This is because the profile module saves the dates in a format which limits the ability to perform calculations on the dates. These two tables need to be in sync with each other.') . '

'; - $output .= '

' . t('Normally this is the case, but sometimes not. For example when you already collected birthdays with the Profile module, but later decided to switch to the birthdays module. Or when you accidentally (on intentionally) completely uninstalled the profile module, but left birthdays module merely disabled. To perform the synchronization you can use the synchronization form.', array('@sync_page' => url('admin/settings/birthdays/sync'))) . '

'; - $output .= '

' . t('In the first case you need to copy the Profile data to the (most likely empty) Birthdays table, which is done with the top button. In the latter you need the copy the birthdays in the Birthdays table back to the Profile module with the bottom button.') . '

'; - $output .= '

' . t('Please note that with a large amount of users this might take some time.') . '

'; - - return $output; - case 'admin/settings/birthdays': - return t('Use this page to alter the settings of the Birthdays module.'); - } + global $_birthdays_field; + switch ($path) { + case 'admin/help#birthdays': + $output = '

' . t("The Birthdays module allows a user to put in their birthday and display it in their profile, on a separate Birthdays page and in a block. It also has the option to send out e-mails on users's birthdays, and to notify the administrator periodically about upcoming birthdays via e-mail.") . '

'; + $output .= '

' . t('Some basic information about this module can be found below. For more information, support questions, feature requests and bug reports please visit the Birthdays project page and the online documentation.', array('@project_url' => 'http://drupal.org/project/birthdays', '@documentation_url' => 'http://drupal.org/node/315658')) . '

'; + $output .= '

' . t('Configuring the module') . '

'; + $output .= '

' . t('Configuring the module is done on a number of pages.') . '

'; + $output .= '

' . t('Birthdays administration pages') . '

'; + $output .= '

' . t('The Birthdays administration pages are where the actual features of the birthdays module are set. Some of the options are described below.', array('@birthdays_admin' => url('admin/settings/birthdays'))) . '

'; + $output .= ''; + + $output .= '

' . t('Permissions') . '

'; + $output .= '

' . t('To allow users to view birthdays of other people, the "access birthdays" permissions needs to be set for the appropriate role. This allows them to access the Birthdays page, see activated blocks with birthdays and view the birthdays of users in the profiles.', array('@birthdays_page' => url('birthdays'), '@permissions_page' => url('admin/user/permissions', array('fragment' => 'module-birthdays')))) . '

'; + + $output .= '

' . t('Profile field settings') . '

'; + + $output .= '

' . t("Several things can be adjusted to the assigned profile field. To do so please visit the !profile_admin, and edit the field in question or add one if you haven't done so already. The following settings require extra attention.", array('!profile_admin' => l('Profile settings', 'admin/user/profile'))) . '

'; + + $output .= ''; + $output .= '

' . t('The other options on this page behave as described on the settings page.') . '

'; + + $output .= '

' . t('Date format') . '

'; + $output .= '

' . t('The way the birthdays are formatted (e.g. 11 may 1934 or 5/11/1934) is controlled by the date and time settings. The Birthdays module uses the short date format as basis for displaying days and months in the blocks and the medium date format is used in the profile and on the Birthdays page.', array('!date_settings_page' => url('admin/settings/date-time'))) . '

'; + + $output .= '

' . t('Synchronizing') . '

'; + + $output .= '

' . t('The birthdays are saved to two different database tables. This is because the profile module saves the dates in a format which limits the ability to perform calculations on the dates. These two tables need to be in sync with each other.') . '

'; + $output .= '

' . t('Normally this is the case, but sometimes not. For example when you already collected birthdays with the Profile module, but later decided to switch to the birthdays module. Or when you accidentally (on intentionally) completely uninstalled the profile module, but left birthdays module merely disabled. To perform the synchronization you can use the synchronization form.', array('@sync_page' => url('admin/settings/birthdays/sync'))) . '

'; + $output .= '

' . t('In the first case you need to copy the Profile data to the (most likely empty) Birthdays table, which is done with the top button. In the latter you need the copy the birthdays in the Birthdays table back to the Profile module with the bottom button.') . '

'; + $output .= '

' . t('Please note that with a large amount of users this might take some time.') . '

'; + + return $output; + case 'admin/settings/birthdays': + return t('Use this page to alter the settings of the Birthdays module.'); + } } @@ -185,21 +185,21 @@ * Implementation of hook_menu(). */ function birthdays_menu() { - $items['admin/settings/birthdays'] = array( + $items['admin/settings/birthdays'] = array( 'title' => 'Birthdays', 'description' => 'Set user birthday mail and toggle user mail, upcoming birthdays mail and more.', 'page callback' => 'drupal_get_form', 'page arguments' => array('birthdays_admin_settings'), 'access arguments' => array('administer site configuration'), 'file' => 'birthdays.admin.inc', - ); + ); - $items['admin/settings/birthdays/settings'] = array( + $items['admin/settings/birthdays/settings'] = array( 'title' => 'Settings', 'type' => MENU_DEFAULT_LOCAL_TASK, - ); + ); - $items['admin/settings/birthdays/sync'] = array( + $items['admin/settings/birthdays/sync'] = array( 'title' => 'Synchronize', 'description' => 'Synchronize birthdays information of Profile module and Birthdays module. Used either when updating to a newer version of Birthdays or when integrating with an existing Profile Field.', 'page callback' => 'drupal_get_form', @@ -207,42 +207,42 @@ 'access arguments' => array('administer site configuration'), 'type' => MENU_LOCAL_TASK, 'file' => 'birthdays.sync.inc', - ); + ); - $items['birthdays'] = array( + $items['birthdays'] = array( 'title' => 'Birthdays', 'description' => 'List the birthdays of all users.', 'page callback' => 'birthdays_view_page', 'access arguments' => array('access birthdays'), 'type' => MENU_SUGGESTED_ITEM, 'file' => 'birthdays.page.inc', - ); + ); - return $items; + return $items; } /** * Implementation of hook_theme(). */ function birthdays_theme() { - return array( + return array( 'birthdays_block' => array( 'arguments' => array('uids' => array(), 'amount' => 0, 'block_type' => NULL), 'template' => 'birthdays-block', - ), + ), 'birthdays_page' => array( 'arguments' => array('accounts' => array(), 'filter_month' => NULL, 'filter_year' => NULL), 'file' => 'birthdays.page.inc', 'template' => 'birthdays-page', - ), - ); + ), + ); } /** * Implementation of hook_perm(). */ function birthdays_perm() { - return array('access birthdays'); + return array('access birthdays'); } @@ -250,35 +250,35 @@ * Implementation of hook_cron(). */ function birthdays_cron() { - global $_birthdays_field; + global $_birthdays_field; - // Either user mail or admin mail is activated, and the birthdays profile field has been set. - if (isset($_birthdays_field) && (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) != BIRTHDAYS_USER_MAIL_NO || variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED) != BIRTHDAYS_ADMIN_MAIL_DISABLED)) { - // Perform the check just once a day - $time = time(); - if (variable_get('birthdays_last_cron', 0) <= ($time - 24*3600)) { - // The message functions are now necessary, lets include them. - module_load_include('inc', 'birthdays', 'birthdays.mail'); - // Reset time limit, round to nearest 100 seconds. - variable_set('birthdays_last_cron', floor($time/100)*100); - - $remind_frequency = variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED); - - // Send user e-mails. - _birthdays_send_user_message(); - - // Send admin message if frequency is daily. - if ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_DAILY) { - _birthdays_send_admin_message(1); - }// Send admin message if frequency is weekly and today is the first day of the week. - elseif ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_WEEKLY && date('w', $time) == variable_get('date_first_day', 0)) { - _birthdays_send_admin_message(7); - }// Send admin message if frequency is monthly and today is the first day of the month. - elseif ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_MONTHLY && date('j', $time) == 1) { - _birthdays_send_admin_message(date('t', $time)); - } - } - } + // Either user mail or admin mail is activated, and the birthdays profile field has been set. + if (isset($_birthdays_field) && (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) != BIRTHDAYS_USER_MAIL_NO || variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED) != BIRTHDAYS_ADMIN_MAIL_DISABLED)) { + // Perform the check just once a day + $time = time(); + if (variable_get('birthdays_last_cron', 0) <= ($time - 24*3600)) { + // The message functions are now necessary, lets include them. + module_load_include('inc', 'birthdays', 'birthdays.mail'); + // Reset time limit, round to nearest 100 seconds. + variable_set('birthdays_last_cron', floor($time/100)*100); + + $remind_frequency = variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED); + + // Send user e-mails. + _birthdays_send_user_message(); + + // Send admin message if frequency is daily. + if ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_DAILY) { + _birthdays_send_admin_message(1); + }// Send admin message if frequency is weekly and today is the first day of the week. + elseif ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_WEEKLY && date('w', $time) == variable_get('date_first_day', 0)) { + _birthdays_send_admin_message(7); + }// Send admin message if frequency is monthly and today is the first day of the month. + elseif ($remind_frequency == BIRTHDAYS_ADMIN_MAIL_MONTHLY && date('j', $time) == 1) { + _birthdays_send_admin_message(date('t', $time)); + } + } + } } @@ -286,21 +286,21 @@ * Implementation of hook_block(). */ function birthdays_block($op = 'list', $delta = 'by_days', $edit = array()) { - global $_birthdays_field; - if (isset($_birthdays_field)) { - switch ($op) { - // List the blocks on the blocks settings page - case 'list': - $blocks['by_days']['info'] = t('Birthdays Block: Next N days'); - $blocks['by_birthdays']['info'] = t('Birthdays Block: N upcoming birthdays'); - return $blocks; - - // Configure the blocks - case 'configure': - $form = array(); - switch ($delta) { - case 'by_days': - $form["birthdays_block_settings"] = array( + global $_birthdays_field; + if (isset($_birthdays_field)) { + switch ($op) { + // List the blocks on the blocks settings page + case 'list': + $blocks['by_days']['info'] = t('Birthdays Block: Next N days'); + $blocks['by_birthdays']['info'] = t('Birthdays Block: N upcoming birthdays'); + return $blocks; + + // Configure the blocks + case 'configure': + $form = array(); + switch ($delta) { + case 'by_days': + $form["birthdays_block_settings"] = array( '#type' => 'textfield', '#title' => t("Number of days to show"), '#default_value' => variable_get("birthdays_block_number_by_days", 7), @@ -308,11 +308,11 @@ '#maxlength' => 2, '#description' => t("Number of days looking forward for upcoming birthdays. Use 1 for today's birthdays only. Note: it might show more or less birthday items than the specified number of days, because not all days have birthdays, and some days have multiple birthdays."), '#required' => TRUE, - ); - break; + ); + break; - case 'by_birthdays': - $form["birthdays_block_settings"] = array( + case 'by_birthdays': + $form["birthdays_block_settings"] = array( '#type' => 'textfield', '#title' => t("Number of birthdays to show"), '#default_value' => variable_get("birthdays_block_number_by_birthdays", 6), @@ -320,61 +320,61 @@ '#maxlength' => 2, '#description' => t("Number of upcoming birthdays to list in the block. It will show exactly the specified number of birthdays, even if more people have their birthday on the same day. In that case, there will be people who will never be shown."), '#required' => TRUE, - ); - break; + ); + break; - } - $form['birthdays_block_hide'] = array( + } + $form['birthdays_block_hide'] = array( '#type' => 'radios', '#title' => t('Hide block when no birthdays'), '#default_value' => variable_get("birthdays_block_hide_empty", 0), '#options' => array(t('No'), t('Yes')), '#description' => t("Should the block be hidden when there are no upcoming birthdays, or should it show a message."), - ); + ); - return $form; + return $form; - // Save the block's configuration - case 'save': - variable_set('birthdays_block_number_'. $delta, $edit['birthdays_block_settings']); - variable_set('birthdays_block_hide_empty', $edit['birthdays_block_hide']); - return; - - // View a block - case 'view': - $block = array(); - // Nothing to show when birthday_field_name is still empty - // Don't show anything when the current user doesn't have the rights. - if (user_access('access birthdays')) { - switch ($delta) { - case 'by_days': - // Get desired amount of birthdays - $amount = variable_get("birthdays_block_number_by_days", 7); - $uids = birthdays_get_birthdays_by_days($amount); - - if (count($uids) > 0 || variable_get('birthdays_block_hide_empty', 0) == 0) { - // Prepare block - $block['subject'] = t('Upcoming Birthdays'); - $block['content'] = theme('birthdays_block', $uids, $amount, $delta); - } - break; - case 'by_birthdays': - // Get desired amount of birthdays - $amount = variable_get("birthdays_block_number_by_birthdays", 6); - $uids = birthdays_get_birthdays($amount); - - if (count($uids) > 0 || variable_get('birthdays_block_hide_empty', 0) == 0) { - // Prepare block - $block['subject'] = t('Upcoming Birthdays'); - $block['content'] = theme('birthdays_block', $uids, $amount, $delta); - } - break; - } - - return $block; - } - } - } + // Save the block's configuration + case 'save': + variable_set('birthdays_block_number_'. $delta, $edit['birthdays_block_settings']); + variable_set('birthdays_block_hide_empty', $edit['birthdays_block_hide']); + return; + + // View a block + case 'view': + $block = array(); + // Nothing to show when birthday_field_name is still empty + // Don't show anything when the current user doesn't have the rights. + if (user_access('access birthdays')) { + switch ($delta) { + case 'by_days': + // Get desired amount of birthdays + $amount = variable_get("birthdays_block_number_by_days", 7); + $uids = birthdays_get_birthdays_by_days($amount); + + if (count($uids) > 0 || variable_get('birthdays_block_hide_empty', 0) == 0) { + // Prepare block + $block['subject'] = t('Upcoming Birthdays'); + $block['content'] = theme('birthdays_block', $uids, $amount, $delta); + } + break; + case 'by_birthdays': + // Get desired amount of birthdays + $amount = variable_get("birthdays_block_number_by_birthdays", 6); + $uids = birthdays_get_birthdays($amount); + + if (count($uids) > 0 || variable_get('birthdays_block_hide_empty', 0) == 0) { + // Prepare block + $block['subject'] = t('Upcoming Birthdays'); + $block['content'] = theme('birthdays_block', $uids, $amount, $delta); + } + break; + } + + return $block; + } + } + } } @@ -387,38 +387,38 @@ * - $block_type */ function template_preprocess_birthdays_block(&$variables) { - global $_birthdays_field; - //dsm($variables); - $variables['no_birthdays'] = TRUE; - $variables['show_starsigns'] = (bool) variable_get('birthdays_show_starsign',BIRTHDAYS_STARSIGN_OFF); + global $_birthdays_field; + //dsm($variables); + $variables['no_birthdays'] = TRUE; + $variables['show_starsigns'] = (bool) variable_get('birthdays_show_starsign',BIRTHDAYS_STARSIGN_OFF); - if (!empty($variables['uids'])) { - $row = 0; - $variables['no_birthdays'] = FALSE; + if (!empty($variables['uids'])) { + $row = 0; + $variables['no_birthdays'] = FALSE; - foreach ($variables['uids'] as $uid) { - $account = user_load(array('uid' => $uid)); - $birthdays[$row]['account'] = $account; - $birthdays[$row]['username'] = theme('username', $account); + foreach ($variables['uids'] as $uid) { + $account = user_load(array('uid' => $uid)); + $birthdays[$row]['account'] = $account; + $birthdays[$row]['username'] = theme('username', $account); - // +1 when the birthday isn't today, because it shows the age the person will be on his/her birthday - $account->age = ($account->age + !($account->{$_birthdays_field->name}['day'] == format_date(time(), 'custom', 'j') && $account->{$_birthdays_field->name}['month'] == format_date(time(), 'custom', 'n'))); + // +1 when the birthday isn't today, because it shows the age the person will be on his/her birthday + $account->age = ($account->age + !($account->{$_birthdays_field->name}['day'] == format_date(time(), 'custom', 'j') && $account->{$_birthdays_field->name}['month'] == format_date(time(), 'custom', 'n'))); - $birthdays[$row]['age'] = _birthdays_show_age($account); - $birthdays[$row]['show_age'] = isset($birthdays[$row]['age']); + $birthdays[$row]['age'] = _birthdays_show_age($account); + $birthdays[$row]['show_age'] = isset($birthdays[$row]['age']); - $birthdays[$row]['starsign'] = birthdays_get_starsign_image($account->birthdays_starsign, variable_get('birthdays_show_starsign',BIRTHDAYS_STARSIGN_OFF)); + $birthdays[$row]['starsign'] = birthdays_get_starsign_image($account->birthdays_starsign, variable_get('birthdays_show_starsign',BIRTHDAYS_STARSIGN_OFF)); - $account->{$_birthdays_field->name}['year'] = NULL; // Don't show the year in blocks - $birthdays[$row]['date'] = _birthdays_show_date($account->{$_birthdays_field->name}, $account); + $account->{$_birthdays_field->name}['year'] = NULL; // Don't show the year in blocks + $birthdays[$row]['date'] = _birthdays_show_date($account->{$_birthdays_field->name}, $account); - $row++; - } - $variables['birthdays'] = $birthdays; - } + $row++; + } + $variables['birthdays'] = $birthdays; + } - $variables['more'] = ''; + $variables['more'] = ''; } @@ -427,7 +427,7 @@ * @return An array containing all user objects that have their birthday today */ function birthdays_get_todays_birthdays() { - return birthdays_get_birthdays_by_days(1); + return birthdays_get_birthdays_by_days(1); } @@ -440,47 +440,47 @@ * An array containing user objects meeting the criteria */ function birthdays_get_birthdays_by_days($amount) { - $birthdays = array(); - // Current user, needed for timezone information - global $user; - - // $amount should be larger or equal to 1 - if ($amount < 1) { - $amount = 1; - } - - // Get user time zone - // needed to determine what day 'today' is in the timezone of the user/website. - if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) { - $timezone = $user->timezone; - } - else { // else use timezone of Drupal installation - $timezone = variable_get('date_default_timezone', 0); - } - - // MySQL prior to 4.1.1 has no option to use UTC, while drupal uses UTC. - // This is compensated by subtracting the machines timezone from the Drupal timezone. - // I believe the assumption is that the HTTP-server has the same timezone as the MySQL server. - $timezone -= date('Z'); - - // Hack to look further than the end of the year, if needed. - $current_year = date('Y'); - $next_year = $current_year + 1; - - /* Query: - - All dates are compensated for the timezone. This makes sure that someone in Asia will see the birthdays - of day 2 while someone in America still sees day 1. - - Blocked users are not shown - - Users that haven't logged in yet are also not shown (Drupal prohibits accessing their profile, thus showing - a link to the profile is unwanted). This is a anti spammers method. - - First part selects all birthdays that are in the next year when the interval exceeds the end of this year. - - Second part selects all birthdays that are between the begin and end date and are in the current year - */ - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $result = db_query( + $birthdays = array(); + // Current user, needed for timezone information + global $user; + + // $amount should be larger or equal to 1 + if ($amount < 1) { + $amount = 1; + } + + // Get user time zone + // needed to determine what day 'today' is in the timezone of the user/website. + if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) { + $timezone = $user->timezone; + } + else { // else use timezone of Drupal installation + $timezone = variable_get('date_default_timezone', 0); + } + + // MySQL prior to 4.1.1 has no option to use UTC, while drupal uses UTC. + // This is compensated by subtracting the machines timezone from the Drupal timezone. + // I believe the assumption is that the HTTP-server has the same timezone as the MySQL server. + $timezone -= date('Z'); + + // Hack to look further than the end of the year, if needed. + $current_year = date('Y'); + $next_year = $current_year + 1; + + /* Query: + - All dates are compensated for the timezone. This makes sure that someone in Asia will see the birthdays + of day 2 while someone in America still sees day 1. + - Blocked users are not shown + - Users that haven't logged in yet are also not shown (Drupal prohibits accessing their profile, thus showing + a link to the profile is unwanted). This is a anti spammers method. + - First part selects all birthdays that are in the next year when the interval exceeds the end of this year. + - Second part selects all birthdays that are between the begin and end date and are in the current year + */ + + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $result = db_query( "SELECT {dob}.uid FROM {dob}, {users} WHERE {users}.uid = {dob}.uid AND {users}.status <> 0 AND {users}.access <> 0 AND ( ( @@ -493,10 +493,10 @@ DATE_FORMAT({dob}.birthday,'$current_year%%m%%d') - DATE_FORMAT(ADDDATE(ADDDATE(NOW(),INTERVAL %d SECOND),INTERVAL %d DAY),'%%Y%%m%%d') < 0 ) ) ORDER BY MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), {users}.name", $timezone, $amount, $timezone, $timezone, $amount - ); - break; - case 'pgsql': - $result = db_query( + ); + break; + case 'pgsql': + $result = db_query( "SELECT {dob}.uid FROM {dob}, {users} WHERE {users}.uid = {dob}.uid AND {users}.status <> 0 AND {users}.access <> 0 AND ( ( @@ -509,16 +509,16 @@ cast(to_char({dob}.birthday,'{$current_year}MMDD') as integer) - cast(to_char(current_timestamp + INTERVAL '%d seconds' + INTERVAL '%d days','YYYYMMDD') as integer) < 0 ) ) ORDER BY date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), {users}.name", $timezone, $amount, $timezone, $timezone, $amount - ); - break; - } - - while ($account = db_fetch_object($result)) { - $birthdays[] = $account->uid; - } + ); + break; + } + + while ($account = db_fetch_object($result)) { + $birthdays[] = $account->uid; + } - // Return array of uids that have their birthday - return $birthdays; + // Return array of uids that have their birthday + return $birthdays; } @@ -531,88 +531,88 @@ * An array containing user objects meeting the criteria */ function birthdays_get_birthdays($amount) { - $birthdays = array(); + $birthdays = array(); - // Current logged in user - global $user; + // Current logged in user + global $user; - // Get user time zone - // Needed to determine what day 'today' is in the timezone of the user/website. - if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) { - $timezone = $user->timezone; - } - else { - $timezone = variable_get('date_default_timezone', 0); - } - - // $amount should be larger or equal to 1 - if ($amount < 1) { - $amount = 1; - } - - // MySQL prior to 4.1.1 has no option to use UTC, while drupal uses UTC. - // This is compensated by subtracting the machines timezone from the Drupal timezone. - // I believe the assumption is that the HTTP-server has the same timezone as the MySQL server. - $timezone -= date('Z'); - - /* Query: - - Select all active users that have their birthday today or in the future (stops at 31-12) - - return at most $amount users - - Don't show blocked users - - Users that haven't logged in yet are also not shown (Drupal prohibits accessing their profile, thus showing - a link to the profile is unwanted). This is a anti spammers method. - */ - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $result = db_query_range( + // Get user time zone + // Needed to determine what day 'today' is in the timezone of the user/website. + if (variable_get('configurable_timezones', 1) && $user->uid && drupal_strlen($user->timezone)) { + $timezone = $user->timezone; + } + else { + $timezone = variable_get('date_default_timezone', 0); + } + + // $amount should be larger or equal to 1 + if ($amount < 1) { + $amount = 1; + } + + // MySQL prior to 4.1.1 has no option to use UTC, while drupal uses UTC. + // This is compensated by subtracting the machines timezone from the Drupal timezone. + // I believe the assumption is that the HTTP-server has the same timezone as the MySQL server. + $timezone -= date('Z'); + + /* Query: + - Select all active users that have their birthday today or in the future (stops at 31-12) + - return at most $amount users + - Don't show blocked users + - Users that haven't logged in yet are also not shown (Drupal prohibits accessing their profile, thus showing + a link to the profile is unwanted). This is a anti spammers method. + */ + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $result = db_query_range( "SELECT {dob}.uid FROM {dob}, {users} WHERE {users}.uid = {dob}.uid AND {users}.status <> 0 AND {users}.access <> 0 AND DATE_FORMAT({dob}.birthday,'%%c%%d') - DATE_FORMAT(ADDDATE(NOW(),INTERVAL %d SECOND),'%%c%%d') >= 0 ORDER BY MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), {users}.name", $timezone, 0, $amount - ); - break; - case 'pgsql': - $result = db_query_range( + ); + break; + case 'pgsql': + $result = db_query_range( "SELECT {dob}.uid FROM {dob}, {users} WHERE {users}.uid = {dob}.uid AND {users}.status <> 0 AND {users}.access <> 0 AND cast(to_char({dob}.birthday,'FMMMDD') as integer) - cast(to_char(current_timestamp + INTERVAL '%d seconds','FMMMDD') as integer) >= 0 ORDER BY date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), {users}.name", $timezone, 0, $amount - ); - break; - } - $count_rows = 0; - while ($account = db_fetch_object($result)) { - $birthdays[] = $account->uid; - $count_rows++; - } - - // If less than $amount results returned, look for more after 31-12 - // return at most the difference between the number already found and - if ($count_rows < $amount) { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $result = db_query_range( + ); + break; + } + $count_rows = 0; + while ($account = db_fetch_object($result)) { + $birthdays[] = $account->uid; + $count_rows++; + } + + // If less than $amount results returned, look for more after 31-12 + // return at most the difference between the number already found and + if ($count_rows < $amount) { + switch ($GLOBALS['db_type']) { + case 'mysql': + case 'mysqli': + $result = db_query_range( "SELECT {dob}.uid FROM {dob}, {users} WHERE {users}.uid = {dob}.uid AND {users}.status <> 0 AND {users}.access <> 0 AND DATE_FORMAT({dob}.birthday,'%%c%%d') - DATE_FORMAT(ADDDATE(NOW(),INTERVAL %d SECOND),'%%c%%d') < 0 ORDER BY MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), {users}.name", $timezone, 0, $amount - $count_rows - ); - break; - case 'pgsql': - $result = db_query_range( + ); + break; + case 'pgsql': + $result = db_query_range( "SELECT {dob}.uid FROM {dob}, {users} WHERE {users}.uid = {dob}.uid AND {users}.status <> 0 AND {users}.access <> 0 AND cast(to_char({dob}.birthday,'FMMMDD') as integer) - cast(to_char(current_timestamp + INTERVAL '%d seconds','FMMMDD') as integer) < 0 ORDER BY date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), {users}.name", $timezone, 0, $amount - $count_rows - ); - break; - } - - while ($account = db_fetch_object($result)) { - $birthdays[] = $account->uid; - } - } + ); + break; + } + + while ($account = db_fetch_object($result)) { + $birthdays[] = $account->uid; + } + } - // Return array of uids that have their birthday - return $birthdays; + // Return array of uids that have their birthday + return $birthdays; } @@ -620,26 +620,26 @@ * Implementation of hook_user(). */ function birthdays_user($op, &$edit, &$account, $category = NULL) { - global $_birthdays_field; - // Do nothing with user when _birthdays_field is not yet set - if (!isset($_birthdays_field)) { - return; - } - switch ($op) { - case 'load': - return birthdays_load_user($account); - case 'update': - case 'insert': - return birthdays_save_user($edit, $account, $category); - case 'form': - return birthdays_form_user($edit, $account, $category); - case 'register': - return birthdays_form_user($edit, $account, $category, TRUE); - case 'delete': - // Delete from {dob} table, other information is handled by profile.module and user.module - db_query('DELETE FROM {dob} WHERE uid = %d', $account->uid); - break; - } + global $_birthdays_field; + // Do nothing with user when _birthdays_field is not yet set + if (!isset($_birthdays_field)) { + return; + } + switch ($op) { + case 'load': + return birthdays_load_user($account); + case 'update': + case 'insert': + return birthdays_save_user($edit, $account, $category); + case 'form': + return birthdays_form_user($edit, $account, $category); + case 'register': + return birthdays_form_user($edit, $account, $category, TRUE); + case 'delete': + // Delete from {dob} table, other information is handled by profile.module and user.module + db_query('DELETE FROM {dob} WHERE uid = %d', $account->uid); + break; + } } @@ -650,15 +650,15 @@ * User object passed by reference. */ function birthdays_load_user(&$account) { - global $_birthdays_field; - // Pre-load birthday-information into $account - profile_load_profile($account); - - // If it was set by the user - if ($account->{$_birthdays_field->name}) { - // Set the user's age - $account->age = _birthdays_get_age($account->{$_birthdays_field->name}); - } + global $_birthdays_field; + // Pre-load birthday-information into $account + profile_load_profile($account); + + // If it was set by the user + if ($account->{$_birthdays_field->name}) { + // Set the user's age + $account->age = _birthdays_get_age($account->{$_birthdays_field->name}); + } } @@ -666,65 +666,65 @@ * Inject information and save birthday when editing or adding a user. */ function birthdays_save_user(&$edit, &$account, $category) { - global $_birthdays_field; + global $_birthdays_field; - // Only continue when the field is present in the form results - if (!empty($_birthdays_field->name) && array_key_exists($_birthdays_field->name, $edit)) { - // Extract the date information - if (is_array($edit[$_birthdays_field->name])) { - extract($edit[$_birthdays_field->name]); - } - - // Delete the old - db_query("DELETE FROM {dob} where uid = %d", $account->uid); - - if ($day && $year && $month) { - // Set the starsign for the user.module to save in the {users}.data field - $edit['birthdays_starsign'] = _birthdays_get_starsign($day, $month); - // Insert the new - db_query("INSERT INTO {dob} (uid, birthday) VALUES (%d, '%d-%d-%d');", $account->uid, $year, $month, $day); - } - else { - $edit['birthdays_starsign'] = ''; - unset($edit[$_birthdays_field->name]); - } - } + // Only continue when the field is present in the form results + if (!empty($_birthdays_field->name) && array_key_exists($_birthdays_field->name, $edit)) { + // Extract the date information + if (is_array($edit[$_birthdays_field->name])) { + extract($edit[$_birthdays_field->name]); + } + + // Delete the old + db_query("DELETE FROM {dob} where uid = %d", $account->uid); + + if ($day && $year && $month) { + // Set the starsign for the user.module to save in the {users}.data field + $edit['birthdays_starsign'] = _birthdays_get_starsign($day, $month); + // Insert the new + db_query("INSERT INTO {dob} (uid, birthday) VALUES (%d, '%d-%d-%d');", $account->uid, $year, $month, $day); + } + else { + $edit['birthdays_starsign'] = ''; + unset($edit[$_birthdays_field->name]); + } + } } /** * Alter the way the birthday is shown. This is fired after every module has filled the profile. */ function birthdays_profile_alter(&$account) { - global $_birthdays_field; - // If the _birthdays_field hasn't been set yet, do not continue - if (!isset($_birthdays_field)) { - return; - } - - // If the field existed, and is amongst the profile fields to be shown, it is save to continue - if (isset( $_birthdays_field ) && array_key_exists($_birthdays_field->category, $account->content) && array_key_exists($_birthdays_field->name, $account->content[$_birthdays_field->category])) { - - // Do you have access to see birthdays? - if (user_access('access birthdays')) { - // Show starsign (will be hidden when needed) - $starsign = ''. - birthdays_get_starsign_image($account->birthdays_starsign, variable_get('birthdays_show_starsign', BIRTHDAYS_STARSIGN_OFF)) . + global $_birthdays_field; + // If the _birthdays_field hasn't been set yet, do not continue + if (!isset($_birthdays_field)) { + return; + } + + // If the field existed, and is amongst the profile fields to be shown, it is save to continue + if (isset( $_birthdays_field ) && array_key_exists($_birthdays_field->category, $account->content) && array_key_exists($_birthdays_field->name, $account->content[$_birthdays_field->category])) { + + // Do you have access to see birthdays? + if (user_access('access birthdays')) { + // Show starsign (will be hidden when needed) + $starsign = ''. + birthdays_get_starsign_image($account->birthdays_starsign, variable_get('birthdays_show_starsign', BIRTHDAYS_STARSIGN_OFF)) . '   '; - // Show age (when allowed by user and administrator) - if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_NO || (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER && $account->birthdays_user_hide_year != BIRTHDAYS_HIDE_YEAR_USER_YES)) { - $age = '   ('. $account->age .')'; - } - - // Alter the profile field setup by profile.module. Show medium format in stead of short format - $account->content[$_birthdays_field->category][$_birthdays_field->name]['#value'] = $starsign . _birthdays_show_date($account->{$_birthdays_field->name}, $account, 'medium') . $age ; - - } - else { - // No access? Remove from profile to show - unset($account->content[$_birthdays_field->category][$_birthdays_field->name]); - } - } + // Show age (when allowed by user and administrator) + if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_NO || (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER && $account->{$_birthdays_field->name}['birthdays_user_hide_year'] != BIRTHDAYS_HIDE_YEAR_USER_YES)) { + $age = '   ('. $account->age .')'; + } + + // Alter the profile field setup by profile.module. Show medium format in stead of short format + $account->content[$_birthdays_field->category][$_birthdays_field->name]['#value'] = $starsign . _birthdays_show_date($account->{$_birthdays_field->name}, $account, 'medium') . $age ; + + } + else { + // No access? Remove from profile to show + unset($account->content[$_birthdays_field->category][$_birthdays_field->name]); + } + } } @@ -734,48 +734,48 @@ * @return fields for the form */ function birthdays_form_user($edit, $account, $category, $register = FALSE) { - global $_birthdays_field; + global $_birthdays_field; - // If the called category is the category of the form field - if ($category == $_birthdays_field->category || ($_birthdays_field->register && $register)) { - // If the hiding of the year is a user option: show the option - if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER) { - $form[$_birthdays_field->category]['birthdays_user_hide_year'] = array( + // If the called category is the category of the form field + if ($category == $_birthdays_field->category || ($_birthdays_field->register && $register)) { + // If the hiding of the year is a user option: show the option + if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER) { + $form[$_birthdays_field->category]['birthdays_user_hide_year'] = array( '#type' => 'checkbox', '#title' => t("Hide age and birth year"), - '#default_value' => (int) $account->birthdays_user_hide_year, + '#default_value' => (int) $account->{$_birthdays_field->name}['birthdays_user_hide_year'], '#description' => t("Do not show your age and your year of birth."), '#return_value' => BIRTHDAYS_HIDE_YEAR_USER_YES, '#weight' => $_birthdays_field->weight + 1 - ); - } + ); + } - // If the birthday user mail is optionally, show the option - if (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) == BIRTHDAYS_USER_MAIL_USER) { - $form[$_birthdays_field->category]['birthdays_user_send_mail'] = array( + // If the birthday user mail is optionally, show the option + if (variable_get('birthdays_send_user', BIRTHDAYS_USER_MAIL_NO) == BIRTHDAYS_USER_MAIL_USER) { + $form[$_birthdays_field->category]['birthdays_user_send_mail'] = array( '#type' => 'checkbox', '#title' => t("Do not send birthday mail"), '#default_value' => (int) $account->birthdays_user_send_mail, '#description' => t("Do not send me an e-mail or e-card when it's my birthday."), '#return_value' => BIRTHDAYS_USER_MAIL_USER_NO, '#weight' => $_birthdays_field->weight + 1 - ); - } - } + ); + } + } - return $form; + return $form; } /** * Implementation of hook_form_alter(). */ function birthdays_form_alter(&$form, &$form_state, $form_id) { - global $_birthdays_field; + global $_birthdays_field; - if (($form_id == 'user_profile_form' && isset($form[$_birthdays_field->category])) || ($form_id == 'user_register' && $_birthdays_field->register)) { - $form[$_birthdays_field->category][$_birthdays_field->name]['#process'] = array('expand_birthdays_date'); - $form[$_birthdays_field->category][$_birthdays_field->name]['#element_validate'] = array('birthdays_date_validate'); - } + if (($form_id == 'user_profile_form' && isset($form[$_birthdays_field->category])) || ($form_id == 'user_register' && $_birthdays_field->register)) { + $form[$_birthdays_field->category][$_birthdays_field->name]['#process'] = array('expand_birthdays_date'); + $form[$_birthdays_field->category][$_birthdays_field->name]['#element_validate'] = array('birthdays_date_validate'); + } } /** @@ -784,34 +784,34 @@ * by adding empty options for days, months and years. */ function expand_birthdays_date($element) { - if (empty($element['#value'])) { - $element['#value'] = array('day' => '', 'month' => '', 'year' => ''); - } - - $element = expand_date($element); - $element['month']['#options'] = array('' => '--') + $element['month']['#options']; - $element['day']['#options'] = array('' => '--') + $element['day']['#options']; - $element['year']['#options'] = array('' => '--') + drupal_map_assoc(range(date('Y'), 1900)); + if (empty($element['#value'])) { + $element['#value'] = array('day' => '', 'month' => '', 'year' => ''); + } + + $element = expand_date($element); + $element['month']['#options'] = array('' => '--') + $element['month']['#options']; + $element['day']['#options'] = array('' => '--') + $element['day']['#options']; + $element['year']['#options'] = array('' => '--') + drupal_map_assoc(range(date('Y'), 1900)); - return $element; + return $element; } /** * Validate the birthday field. */ function birthdays_date_validate($element) { - extract($element['#value']); - if (empty($month) || empty($year) || empty($day)) { - if ($element['#required']) { - form_error($element, t('!name field is required.', array('!name' => $element['#title']))); - } - elseif (!(empty($month) && empty($year) && empty($day))) { - form_error($element, t('The specified date is invalid.')); - } - } - elseif (!checkdate($month, $day, $year)) { - form_error($element, t('The specified date is invalid.')); - } + extract($element['#value']); + if (empty($month) || empty($year) || empty($day)) { + if ($element['#required']) { + form_error($element, t('!name field is required.', array('!name' => $element['#title']))); + } + elseif (!(empty($month) && empty($year) && empty($day))) { + form_error($element, t('The specified date is invalid.')); + } + } + elseif (!checkdate($month, $day, $year)) { + form_error($element, t('The specified date is invalid.')); + } } /** @@ -822,46 +822,46 @@ */ function _birthdays_get_starsign($day, $month) { - switch ($month) { - case 1: - $starsign = $day < 20 ? 'capricorn' : 'aquarius'; - break; - case 2: - $starsign = $day < 19 ? 'aquarius' : 'pisces'; - break; - case 3: - $starsign = $day < 21 ? 'pisces' : 'aries'; - break; - case 4: - $starsign = $day < 20 ? 'aries' : 'taurus'; - break; - case 5: - $starsign = $day < 21 ? 'taurus' : 'gemini'; - break; - case 6: - $starsign = $day < 22 ? 'gemini' : 'cancer'; - break; - case 7: - $starsign = $day < 23 ? 'cancer' : 'leo'; - break; - case 8: - $starsign = $day < 23 ? 'leo' : 'virgo'; - break; - case 9: - $starsign = $day < 23 ? 'virgo' : 'libra'; - break; - case 10: - $starsign = $day < 23 ? 'libra' : 'scorpio'; - break; - case 11: - $starsign = $day < 23 ? 'scorpio' : 'sagittarius'; - break; - case 12: - $starsign = $day < 22 ? 'sagittarius' : 'capricorn'; - break; - } + switch ($month) { + case 1: + $starsign = $day < 20 ? 'capricorn' : 'aquarius'; + break; + case 2: + $starsign = $day < 19 ? 'aquarius' : 'pisces'; + break; + case 3: + $starsign = $day < 21 ? 'pisces' : 'aries'; + break; + case 4: + $starsign = $day < 20 ? 'aries' : 'taurus'; + break; + case 5: + $starsign = $day < 21 ? 'taurus' : 'gemini'; + break; + case 6: + $starsign = $day < 22 ? 'gemini' : 'cancer'; + break; + case 7: + $starsign = $day < 23 ? 'cancer' : 'leo'; + break; + case 8: + $starsign = $day < 23 ? 'leo' : 'virgo'; + break; + case 9: + $starsign = $day < 23 ? 'virgo' : 'libra'; + break; + case 10: + $starsign = $day < 23 ? 'libra' : 'scorpio'; + break; + case 11: + $starsign = $day < 23 ? 'scorpio' : 'sagittarius'; + break; + case 12: + $starsign = $day < 22 ? 'sagittarius' : 'capricorn'; + break; + } - return $starsign; + return $starsign; } @@ -870,14 +870,14 @@ * @return array with fieldnames */ function _birthdays_get_date_fields() { - $options = array(); - $result = db_query("SELECT fid, name FROM {profile_fields} WHERE type = 'date'"); + $options = array(); + $result = db_query("SELECT fid, name FROM {profile_fields} WHERE type = 'date'"); - while ($field = db_fetch_object($result)) { - $options[$field->fid] = $field->name; - } + while ($field = db_fetch_object($result)) { + $options[$field->fid] = $field->name; + } - return $options; + return $options; } @@ -890,13 +890,13 @@ * profile field object */ function _birthdays_get_field($fid) { - if (isset($fid)) { - $field = db_fetch_object(db_query("SELECT * FROM {profile_fields} WHERE fid = %d", $fid)); - return empty($field) ? NULL : $field; - } - else { - return NULL; - } + if (isset($fid)) { + $field = db_fetch_object(db_query("SELECT * FROM {profile_fields} WHERE fid = %d", $fid)); + return empty($field) ? NULL : $field; + } + else { + return NULL; + } } @@ -911,21 +911,21 @@ * HTML of a picture link to Yahoo horoscopes */ function birthdays_get_starsign_image($starsign, $show = BIRTHDAYS_STARSIGN_OFF) { - $output = ''; + $output = ''; - // Only show starsign when enabled - if ($show > BIRTHDAYS_STARSIGN_OFF && !empty($starsign)) { - // Image based on thme path. - $output = ''. t($starsign) .''; - - // If link should be shown: update $output - if ($show == BIRTHDAYS_STARSIGN_LINK) { - $output = ''. $output .''; - } - } + // Only show starsign when enabled + if ($show > BIRTHDAYS_STARSIGN_OFF && !empty($starsign)) { + // Image based on thme path. + $output = ''. t($starsign) .''; + + // If link should be shown: update $output + if ($show == BIRTHDAYS_STARSIGN_LINK) { + $output = ''. $output .''; + } + } - // Return HTML - return $output; + // Return HTML + return $output; } /** @@ -937,17 +937,17 @@ * age */ function _birthdays_get_age($date) { - // If date is not empty - if (is_array($date)) { - // extract date - extract($date); - - // call main age function (no overloading in PHP) - return _birthdays_calculate_age($day, $month, $year); - } - else { - return NULL; - } + // If date is not empty + if (is_array($date)) { + // extract date + extract($date); + + // call main age function (no overloading in PHP) + return _birthdays_calculate_age($day, $month, $year); + } + else { + return NULL; + } } @@ -959,13 +959,13 @@ * age */ function _birthdays_calculate_age($day, $month, $year) { - if ($year && $month && $day) { - // age = (current year - birthyear) - 1 (when the birthday hasn't arrived yet). - return format_date(time(), 'custom', 'Y') - $year - (format_date(time(), 'custom', 'nd') < $month . str_pad($day, 2, 0, STR_PAD_LEFT)); - } - else { - return NULL; - } + if ($year && $month && $day) { + // age = (current year - birthyear) - 1 (when the birthday hasn't arrived yet). + return format_date(time(), 'custom', 'Y') - $year - (format_date(time(), 'custom', 'nd') < $month . str_pad($day, 2, 0, STR_PAD_LEFT)); + } + else { + return NULL; + } } @@ -977,11 +977,12 @@ * @return int */ function _birthdays_show_age($account) { - $age = NULL; - if (isset($account->age) && (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_NO || (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER && $account->birthdays_user_hide_year != BIRTHDAYS_HIDE_YEAR_USER_YES))) { - $age = $account->age; - } - return $age; + global $_birthdays_field; + $age = NULL; + if (isset($account->age) && (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_NO || (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER && $account->{$_birthdays_field->name}['birthdays_user_hide_year'] != BIRTHDAYS_HIDE_YEAR_USER_YES))) { + $age = $account->age; + } + return $age; } @@ -989,43 +990,44 @@ * Format date array */ function _birthdays_show_date($date, $account, $format = 'small') { - if (is_array($date)) { - // Extract date - extract($date); - - // Call main format function - return _birthdays_show_date_2($day, $month, $year, $account, $format); - } - else { - return NULL; - } + if (is_array($date)) { + // Extract date + extract($date); + + // Call main format function + return _birthdays_show_date_2($day, $month, $year, $account, $format); + } + else { + return NULL; + } } /** * Format date, optionally hide year */ function _birthdays_show_date_2($day, $month, $year, $account, $type = 'small') { - $output = ''; - // Determine format type - switch ($type) { - case 'medium': - $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); - break; - case 'small': - default: - $format = variable_get('date_format_short', 'm/d/Y - H:i'); - } - - // remove time from (- H:i) - //$format = substr($format, 0, -6); - - // If admin or user decide to hide the age&year: hide year - if ($year && ( variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_YES || (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER && $account->birthdays_user_hide_year == BIRTHDAYS_HIDE_YEAR_YES))) { - $year = NULL; - } + global $_birthdays_field; + $output = ''; + // Determine format type + switch ($type) { + case 'medium': + $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); + break; + case 'small': + default: + $format = variable_get('date_format_short', 'm/d/Y - H:i'); + } + + // remove time from (- H:i) + //$format = substr($format, 0, -6); + + // If admin or user decide to hide the age&year: hide year + if ($year && ( variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_YES || (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) == BIRTHDAYS_HIDE_YEAR_USER && $account->{$_birthdays_field->name}['birthdays_user_hide_year'] == BIRTHDAYS_HIDE_YEAR_YES))) { + $year = NULL; + } - // Replacement array (can't use date() because of 1970 limitations in e.g. Windows PHP4) - $replace = array( + // Replacement array (can't use date() because of 1970 limitations in e.g. Windows PHP4) + $replace = array( 'd' => sprintf('%02d', $day), 'D' => NULL, 'j' => $day, @@ -1036,13 +1038,13 @@ 'G:i' => NULL, 'g:ia' => NULL, 'F' => t(gmdate('F', mktime(0, 0, 0, $month, 15, 2000))), - ); + ); - // Translate string to correct format - $output .= strtr($format, $replace); - $output = trim($output, '/ ,.:-'); + // Translate string to correct format + $output .= strtr($format, $replace); + $output = trim($output, '/ ,.:-'); - return $output; + return $output; } /** @@ -1050,20 +1052,20 @@ * placeholders. Uses the same method as _user_mail_text(). */ function _birthdays_mail_text($key, $language = NULL, $variables = array()) { - $langcode = isset($language) ? $language->language : NULL; + $langcode = isset($language) ? $language->language : NULL; - // If the text is not the default, run it through strtr() to fill in the - // placeholders. - if ($text = variable_get('birthdays_send_user_' . $key, FALSE)) { - return strtr($text, $variables); - } - else { - // Which text do we want to retreive? - switch ($key) { - case 'subject': - return t('Happy Birthday, !username!', $variables, $langcode); - case 'message': - return t("Hey !username,\n\nHappy birthday!\nWe hope you have a great day\n\nThe !site-team\n!uri_brief", $variables, $langcode); - } - } + // If the text is not the default, run it through strtr() to fill in the + // placeholders. + if ($text = variable_get('birthdays_send_user_' . $key, FALSE)) { + return strtr($text, $variables); + } + else { + // Which text do we want to retreive? + switch ($key) { + case 'subject': + return t('Happy Birthday, !username!', $variables, $langcode); + case 'message': + return t("Hey !username,\n\nHappy birthday!\nWe hope you have a great day\n\nThe !site-team\n!uri_brief", $variables, $langcode); + } + } }