/** * Calculates the age of the person with the specified birth date. * * @param integer $year * @param integer $month * @param integer $day * * @return integer */ public function calculateAge($year, $month, $day) { list($cYear, $cMonth, $cDay) = explode('-', XenForo_Locale::getFormattedDate(XenForo_Application::$time, 'Y-m-d')); $age = $cYear - $year; if ($cMonth < $month || $cMonth == $month && $cDay < $day) { $age--; } return max(0, $age); }
protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $renderTemplateObject) { $core = WidgetFramework_Core::getInstance(); /** @var XenForo_Model_User $userModel */ $userModel = $core->getModelFromCache('XenForo_Model_User'); /** @var XenForo_Model_UserProfile $userProfileModel */ $userProfileModel = $core->getModelFromCache('XenForo_Model_UserProfile'); $todayStart = XenForo_Locale::getDayStartTimestamps(); $todayStart = $todayStart['today']; $day = XenForo_Locale::getFormattedDate($todayStart, 'd'); $month = XenForo_Locale::getFormattedDate($todayStart, 'm'); $conditions = array(WidgetFramework_XenForo_Model_User::CONDITIONS_DOB => array('d' => $day, 'm' => $month), 'user_state' => 'valid', 'is_banned' => false); $fetchOptions = array('order' => 'username', 'join' => XenForo_Model_User::FETCH_USER_PROFILE + XenForo_Model_User::FETCH_USER_OPTION); if (!empty($widget['options']['limit'])) { $fetchOptions['limit'] = $widget['options']['limit']; } if (!empty($widget['options']['avatar_only'])) { $conditions[WidgetFramework_XenForo_Model_User::CONDITIONS_HAS_AVATAR] = true; } $users = $userModel->getUsers($conditions, $fetchOptions); foreach (array_keys($users) as $userId) { $user =& $users[$userId]; if (!empty($widget['options']['whitelist_user_groups'])) { // check for whitelist user groups if (!$userModel->isMemberOfUserGroup($user, $widget['options']['whitelist_user_groups'])) { unset($users[$userId]); continue; } } if (!empty($widget['options']['blacklist_user_groups'])) { // check for blacklist user groups if ($userModel->isMemberOfUserGroup($user, $widget['options']['blacklist_user_groups'])) { unset($users[$userId]); continue; } } // we can call XenForo_Model_User::prepareUserCard instead $user['age'] = $userProfileModel->getUserAge($user); } $renderTemplateObject->setParam('users', array_values($users)); return $renderTemplateObject->render(); }
/** * Generates the date and time format examples based on the * current time. * * @return array [0] => date formats, [1] => time formats; keyed by format string */ public function getLanguageFormatExamples() { $dateFormatsRaw = array('M j, Y', 'F j, Y', 'j M Y', 'j F Y', 'j/n/y', 'n/j/y'); $dateFormats = array(); foreach ($dateFormatsRaw as $dateFormat) { $dateFormats[$dateFormat] = XenForo_Locale::getFormattedDate(XenForo_Application::$time, $dateFormat); } $timeFormatsRaw = array('g:i A', 'H:i'); $timeFormats = array(); foreach ($timeFormatsRaw as $timeFormat) { $timeFormats[$timeFormat] = XenForo_Locale::getFormattedDate(XenForo_Application::$time, $timeFormat); } return array($dateFormats, $timeFormats); }