Example #1
0
 /**
  * Returns a value for output of this field
  *
  * @param XoopsUser $user {@link XoopsUser} object to get the value of
  * @param profileProfile $profile object to get the value of
  *
  * @return string
  **/
 public function getOutputValue(XoopsUser $user, ProfileProfile $profile)
 {
     $xoops = Xoops::getInstance();
     $xoops->loadLanguage('modinfo', 'profile');
     $value = in_array($this->getVar('field_name'), $this->getUserVars()) ? $user->getVar($this->getVar('field_name')) : $profile->getVar($this->getVar('field_name'));
     switch ($this->getVar('field_type')) {
         default:
         case "textbox":
             if ($this->getVar('field_name') == 'url' && $value != '') {
                 return '<a href="' . $xoops->formatURL($value) . '" rel="external">' . $value . '</a>';
             } else {
                 return $value;
             }
             break;
         case "textarea":
         case "dhtml":
         case 'theme':
         case "language":
         case "list":
             return $value;
             break;
         case "select":
         case "radio":
             $options = $this->getVar('field_options');
             if (isset($options[$value])) {
                 $value = htmlspecialchars(defined($options[$value]) ? constant($options[$value]) : $options[$value]);
             } else {
                 $value = "";
             }
             return $value;
             break;
         case "select_multi":
         case "checkbox":
             $options = $this->getVar('field_options');
             $ret = array();
             if (count($options) > 0) {
                 foreach (array_keys($options) as $key) {
                     if (in_array($key, $value)) {
                         $ret[$key] = htmlspecialchars(defined($options[$key]) ? constant($options[$key]) : $options[$key]);
                     }
                 }
             }
             return $ret;
             break;
         case "group":
             $member_handler = $xoops->getHandlerMember();
             $options = $member_handler->getGroupList();
             $ret = isset($options[$value]) ? $options[$value] : '';
             return $ret;
             break;
         case "group_multi":
             $member_handler = $xoops->getHandlerMember();
             $options = $member_handler->getGroupList();
             $ret = array();
             foreach (array_keys($options) as $key) {
                 if (in_array($key, $value)) {
                     $ret[$key] = htmlspecialchars($options[$key]);
                 }
             }
             return $ret;
             break;
         case "longdate":
             //return YYYY/MM/DD format - not optimal as it is not using local date format, but how do we do that
             //when we cannot convert it to a UNIX timestamp?
             return str_replace("-", "/", $value);
         case "date":
             return XoopsLocale::formatTimestamp($value, 's');
             break;
         case "datetime":
             if (!empty($value)) {
                 return XoopsLocale::formatTimestamp($value, 'm');
             } else {
                 return _PROFILE_MI_NEVER_LOGGED_IN;
             }
             break;
         case "autotext":
             $value = $user->getVar($this->getVar('field_name'), 'n');
             //autotext can have HTML in it
             $value = str_replace("{X_UID}", $user->getVar("uid"), $value);
             $value = str_replace("{X_URL}", \XoopsBaseConfig::get('url'), $value);
             $value = str_replace("{X_UNAME}", $user->getVar("uname"), $value);
             return $value;
             break;
         case "rank":
             $userrank = $user->rank();
             $user_rankimage = "";
             if (isset($userrank['image']) && $userrank['image'] != "") {
                 $user_rankimage = '<img src="' . $userrank['image'] . '" alt="' . $userrank['title'] . '" /><br />';
             }
             return $user_rankimage . $userrank['title'];
             break;
         case "yesno":
             return $value ? XoopsLocale::YES : XoopsLocale::NO;
             break;
         case "timezone":
             $timezones = XoopsLists::getTimeZoneList();
             $value = empty($value) ? "0" : (string) $value;
             return $timezones[str_replace('.0', '', $value)];
             break;
     }
 }