/** * offsets date-time if time is present and $serverTimeOffset 1, then formats to CB's configured date-time format. * * @param mixed string $date in "Y-m-d H:i:s" format, or int : unix timestamp * @param int $serverTimeOffset : 0: don't offset, 1: offset if time also in $date * @param boolean $showtime : false don't show time even if time is present in string * @return string date formatted */ function cbFormatDate($date, $serverTimeOffset = 1, $showtime = true) { global $ueConfig; if (is_int($date)) { $date = date($showtime ? "Y-m-d H:i:s" : "Y-m-d", $date); } if ($date != '' && $date != null && $date != '0000-00-00 00:00:00' && $date != '0000-00-00') { if (strlen($date) > 10) { if ($serverTimeOffset == 1) { $date = _old_cbFormatDate($date, $showtime ? "%Y-%m-%d %H:%M:%S" : "%Y-%m-%d"); // offsets datetime with server offset setting } else { $date = substr($date, 0, 10); } } $ret = dateConverter($date, 'Y-m-d', $ueConfig['date_format']); } else { $ret = ""; } return $ret; }
/** * Returns a field in specified format * * @param moscomprofilerFields $field * @param moscomprofilerUser $user * @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit' * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'list' for user-lists * @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search * @return mixed */ function getField(&$field, &$user, $output, $reason, $list_compare_types) { $value = $user->get($field->name); switch ($output) { case 'html': case 'rss': if ($value != '' && $value != '0000-00-00 00:00:00' && $value != '0000-00-00') { $display_by = $field->params->get('field_display_by', 0); if ($display_by == 1) { // display by years: list($yb, $cb, $db) = sscanf($value, '%d-%d-%d'); list($yn, $cn, $dn) = sscanf(date('Y-m-d'), '%d-%d-%d'); $age = (int) ($yn - $yb); if ($cb > $cn || $cb == $cn && $db > $dn) { $age -= 1; } if ($age < 0) { $age = null; } return $field->params->get('field_display_years_text', 1) ? sprintf(_UE_AGE_YEARS, $age) : $age; } elseif ($display_by == 2) { // display by ago: return $this->_ago($value, $field->params->get('field_display_ago_text', 1), true); } elseif ($display_by == 3) { // display birthday without the year: global $ueConfig; if ($value != '' && $value != null && $value != '0000-00-00 00:00:00' && $value != '0000-00-00') { if (strlen($value) > 10) { $value = _old_cbFormatDate($value, "%m-%d"); // offsets datetime with server offset setting } $value = substr($value, 5, 5); $month = substr($value, 0, 2); if (defined('_UE_MONTHS_' . (int) $month)) { $value = 'MM' . substr($value, 2); } $convert = array('Y/m/d' => 'm/d', 'd/m/y' => 'd/m', 'y/m/d' => 'm/d', 'd/m/Y' => 'd/m', 'm/d/y' => 'm/d', 'm/d/Y' => 'm/d', 'Y-m-d' => 'm/d', 'd-m-y' => 'd/m', 'y-m-d' => 'm/d', 'd-m-Y' => 'd/m', 'm-d-y' => 'm/d', 'm-d-Y' => 'm/d', 'Y.m.d' => 'm/d', 'd.m.y' => 'd/m', 'y.m.d' => 'm/d', 'd.m.Y' => 'd/m', 'm.d.y' => 'm/d', 'm.d.Y' => 'm/d'); if (isset($convert[$ueConfig['date_format']])) { $format = $convert[$ueConfig['date_format']]; } else { $format = 'm/d'; } $value = dateConverter($value, 'm-d', $format); if (defined('_UE_MONTHS_' . (int) $month)) { $value = str_replace(array('MM', '/'), array(constant('_UE_MONTHS_' . (int) $month), ' '), $value); } return $value; } else { return ''; } } else { $date_time = $field->params->get('show_date_time', 0); return htmlspecialchars(cbFormatDate($value, 1, $date_time == 1 ? false : true)); } } else { return ''; } break; case 'htmledit': global $_CB_framework; $calendars = new cbCalendars($_CB_framework->getUi()); if ($reason == 'search') { $minNam = $field->name . '__minval'; $maxNam = $field->name . '__maxval'; $minVal = $user->get($minNam); $maxVal = $user->get($maxNam); $search_by = $field->params->get('field_search_by', 0); list($yMin, $yMax) = $this->_yearsRange($field, $search_by); if ($search_by == 1) { // Search by age range: $choices = array(); $choices = array(); for ($i = $yMin; $i <= $yMax; $i++) { $choices[] = moscomprofilerHTML::makeOption($i, $i); } if ($minVal === null) { $minVal = $yMin; } if ($maxVal === null) { $maxVal = $yMax; } $additional = ' class="inputbox"'; $minHtml = moscomprofilerHTML::selectList($choices, $minNam, $additional, 'text', 'value', $minVal, 2); $maxHtml = moscomprofilerHTML::selectList($choices, $maxNam, $additional, 'text', 'value', $maxVal, 2); } else { if ($minVal !== null) { $minVal = date('Y-m-d', strtotime($minVal)); } if ($maxVal !== null) { $maxVal = date('Y-m-d', strtotime($maxVal)); } // Search by date range: $minHtml = $calendars->cbAddCalendar($minNam, _UE_SEARCH_FROM . ' ' . $this->getFieldTitle($field, $user, 'text', $reason), false, $minVal, false, false, $yMin, $yMax); $maxHtml = $calendars->cbAddCalendar($maxNam, _UE_SEARCH_TO . ' ' . $this->getFieldTitle($field, $user, 'text', $reason), false, $maxVal, false, false, $yMin, $yMax); } $html = $this->_fieldSearchRangeModeHtml($field, $user, $output, $reason, $value, $minHtml, $maxHtml, $list_compare_types); return $html; } elseif (!in_array($field->name, array('registerDate', 'lastvisitDate', 'lastupdatedate'))) { list($yMin, $yMax) = $this->_yearsRange($field, 0); $html = $calendars->cbAddCalendar($field->name, $this->getFieldTitle($field, $user, 'text', $reason), $this->_isRequired($field, $user, $reason), $value, $this->_isReadOnly($field, $user, $reason), false, $yMin, $yMax) . $this->_fieldIconsHtml($field, $user, $output, $reason, null, $field->type, $value, 'input', null, true, $this->_isRequired($field, $user, $reason) && !$this->_isReadOnly($field, $user, $reason)); } else { $html = null; } return $html; break; case 'json': case 'php': case 'xml': case 'csvheader': case 'fieldslist': case 'csv': default: return parent::getField($field, $user, $output, $reason, $list_compare_types); break; } return '*' . CBTxt::T('Unknown Output Format') . '*'; }