/** * sets the field value; uses the default value if no stored value is present * * as of version 1.5.5 we slightly changed how this works: formerly, the default * value was only used in the record module if the "persistent" flag was set, now * the default value is used anyway. Seems more intuitive to let the default value * be used if it's set, and not require the persistent flag. The default value is * always used in the signup module. * * * @param object $field the current field object * @return string the value of the field */ protected function _set_field_value($field) { /* * get the value from the record; if it is empty, use the default value if the * "persistent" flag is set. */ $record_value = isset($this->participant_values[$field->name]) ? $this->participant_values[$field->name] : ''; $value = $this->_empty($record_value) ? $this->_empty($field->default) ? '' : $field->default : $record_value; // replace it with the new value if provided, escaping the input if (in_array($this->module, array('record', 'signup', 'retrieve')) && isset($_POST[$field->name])) { $value = $this->_esc_submitted_value($_POST[$field->name]); } /* * make sure id and private_id fields are read only */ if (in_array($field->name, array('id', 'private_id'))) { $this->display_as_readonly($field); } if ($field->form_element === 'hidden') { /* * use the dynamic value if no value has been set */ if (in_array($this->module, array('signup', 'record', 'retrieve'))) { if (Participants_Db::is_dynamic_value($field->default)) { $value = $this->get_dynamic_value($field->default); } /* * add to the display columns if not already present so it will be processed * in the form submission */ $this->display_columns += array($field->name); } else { // show this one as a readonly field $this->display_as_readonly($field); } } $field->value = $value; }
/** * returns an element value formatted for display or storage * * this supplants the function Participants_Db::prep_field_for_display * * @param object $field a Field_Item object * @param bool $html if true, retuns the value wrapped in HTML, false returns * the formatted value alone * @return string the object's current value, formatted */ public static function get_field_value_display($field, $html = true) { $return = ''; /** * filter: pdb-before_display_form_element * * @since 1.6 * * @param string $return the value display * @param object $field the field object * * formerly, this was set as "pdb-before_display_field" and included a more limited set of arguments */ if (has_filter(Participants_Db::$prefix . 'before_display_form_element')) { $return = Participants_Db::set_filter('before_display_form_element', $return, $field); } elseif (has_filter(Participants_Db::$prefix . 'before_display_field')) { // provided for backward-compatibility $return = Participants_Db::set_filter('before_display_field', $return, $field->value, $field->form_element); } if (empty($return)) { switch ($field->form_element) { case 'image-upload': $image = new PDb_Image(array('filename' => $field->value, 'link' => isset($field->link) ? $field->link : false, 'mode' => 'both', 'module' => $field->module)); if ($html) { if (isset($field->module) and in_array($field->module, array('single', 'list'))) { $image->display_mode = 'image'; } elseif (isset($field->module) and in_array($field->module, array('signup'))) { $image->display_mode = $image->image_defined ? 'both' : 'none'; $image->link = false; } $image->set_image_wrap(); $return = $image->get_image_html(); } elseif ($image->file_exists) { $return = $image->get_image_file(); } else { $return = $field->value; } break; case 'file-upload': if ($html and !empty($field->value)) { if ($field->module == 'signup') { $field->link = false; $return = $field->value; } else { $field->link = PDb_Path::files_uri() . $field->value; $return = self::make_link($field); } break; } else { $return = $field->value; break; } case 'date': case 'timestamp': $return = ''; if (self::is_empty($field->value) === false) { $date = Participants_Db::parse_date($field->value, $field); $format = Participants_Db::$date_format; if (Participants_Db::plugin_setting_is_true('show_time') and $field->form_element === 'timestamp') { $format .= ' ' . get_option('time_format'); } $return = date_i18n($format, $date); } else { $return = ''; } break; case 'multi-checkbox': case 'multi-select-other': /* * these elements are stored as serialized arrays of values, the data is displayed * a comma-separated string of the values, using the value titles if defined */ $return = self::array_display($field); break; case 'link': $linkdata = maybe_unserialize($field->value); if (!is_array($linkdata)) { $return = ''; break; } if (empty($linkdata[1])) { $linkdata[1] = str_replace('http://', '', $linkdata[0]); } if ($html) { $return = vsprintf(empty($linkdata[0]) ? '%1$s%2$s' : '<a href="%1$s">%2$s</a>', $linkdata); } else { $return = $linkdata[0]; } break; case 'text-line': if ($html) { $field->value = self::get_value_title($field->value, $field->name); $return = self::make_link($field); break; } else { $return = $field->value; break; } case 'text-area': case 'textarea': $pattern = $html ? '<span ' . self::class_attribute('textarea') . '>%s</span>' : '%s'; $return = sprintf($pattern, $field->value); break; case 'rich-text': if ($html) { $return = sprintf('<span ' . self::class_attribute('textarea richtext') . '>%s</span>', Participants_Db::process_rich_text($field->value)); } else { $return = strip_tags($field->value); } break; case 'dropdown': case 'radio': case 'checkbox': case 'dropdown-other': case 'select-other': $field->value = self::array_display($field); if ($html) { $return = sprintf('<span %s>%s</span>', self::class_attribute($field->form_element), self::make_link($field)); } else { $return = $field->value; } break; case 'placeholder': $field->value = $field->default; $return = $html ? self::make_link($field) : $field->value; break; case 'hidden': if ($field->value === $field->default) { $field->value = ''; } elseif (!Participants_Db::is_dynamic_value($field->default)) { $field->value = $field->default; } default: $return = $html ? self::make_link($field) : $field->value; } } return $return; }