/** * prints the field element * */ public function print_element() { $this->field_class = ($this->validation != 'no' ? "required-field" : '') . (in_array($this->form_element, array('text-line', 'date', 'timestamp')) ? ' regular-text' : ''); if ($this->readonly && !in_array($this->form_element, array('captcha'))) { if (!in_array($this->form_element, array('rich-text'))) { $this->attributes['readonly'] = 'readonly'; $this->_print(); } else { $this->value = PDb_FormElement::get_field_value_display($this); echo '<span class="pdb-readonly ' . $this->field_class . '" >' . $this->value . '</span>'; } } else { $this->_print(); } }
$this->the_record(); // each record is one row ?> <tr> <?php while ($this->have_fields()) { $this->the_field(); // each field is one cell ?> <?php if ($this->field->has_content()) { ?> <td> <?php echo PDb_FormElement::get_field_value_display($this->field); ?> </td> <?php } else { // if the field is empty ?> <td></td> <?php } ?> <?php } // each field
/** * supplied for backwards compatibility * * the original func has been superceded, but this will allow the old func to be used * * @var string $value * @var string $form_element * @return string */ public static function prep_field_for_display($value, $form_element) { $field = (object) array('value' => $value, 'form_element' => $form_element, 'module' => 'single'); return PDb_FormElement::get_field_value_display($field); }
/** * * prints a formatted field value * * @param string $name name of the field to print */ protected function _print($name) { if (isset($this->fields->{$name})) { echo PDb_FormElement::get_field_value_display($this->fields->{$name}); } }
/** * replace the tags in text messages * * a tag contains the column name for the value to use: [column_name] * * also processes the [record_link] tag * * @param string $text the unporcessed text with tags * @param array $values the values to replace the tags with * @param array $tags the tags to look for in the text * * @return string the text with the replacements made * */ protected function _proc_tags($text, $values = array(), $tags = array()) { if (empty($values)) { foreach ($this->columns as $column) { $tags[] = '[' . $column->name . ']'; $column->value = $this->participant_values[$column->name]; $values[] = PDb_FormElement::get_field_value_display($column, false); } } // add some extra tags foreach (array('id', 'private_id') as $v) { $tags[] = '[' . $v . ']'; $values[] = $this->participant_values[$v]; } $tags[] = '[record_link]'; $values[] = $this->registration_page; $tags[] = '[admin_record_link]'; $values[] = Participants_Db::get_admin_record_link($this->participant_values['id']); $placeholders = array(); for ($i = 1; $i <= count($tags); $i++) { $placeholders[] = '%' . $i . '$s'; } // replace the tags with variables $pattern = str_replace($tags, $placeholders, $text); // replace the variables with strings return vsprintf($pattern, $values); }
/** * prints the main body of the list, including headers * * @param string $mode dtermines the print mode: 'noheader' skips headers, (other choices to be determined) */ private static function _main_table($mode = '') { $hscroll = Participants_Db::plugin_setting_is_true('admin_horiz_scroll'); ?> <?php if ($hscroll) { ?> <div class="pdb-horiz-scroll-scroller"> <div class="pdb-horiz-scroll-width" style="width: <?php echo count(self::$display_columns) * 10; ?> em"> <?php } ?> <table class="wp-list-table widefat fixed pages pdb-list stuffbox" cellspacing="0" > <?php $PID_pattern = '<td><a href="%2$s">%1$s</a></td>'; //template for outputting a column $col_pattern = '<td>%s</td>'; if (count(self::$participants) > 0) { if ($mode != 'noheader') { ?> <thead> <tr> <?php self::_print_header_row(); ?> </tr> </thead> <?php } // table header row // print the table footer row if there is a long list if ($mode != 'noheader' && count(self::$participants) > 10) { ?> <tfoot> <tr> <?php self::_print_header_row(); ?> </tr> </tfoot> <?php } // table footer row ?> <tbody> <?php // output the main list foreach (self::$participants as $value) { ?> <tr> <?php // print delete check ?> <td> <?php if (current_user_can(Participants_Db::plugin_capability('plugin_admin_capability', 'delete participants'))) { ?> <input type="checkbox" class="delete-check" name="pid[]" value="<?php echo $value['id']; ?> " /> <?php } ?> <a href="admin.php?page=<?php echo 'participants-database'; ?> -edit_participant&action=edit&id=<?php echo $value['id']; ?> " title="<?php _e('Edit', 'participants-database'); ?> "><span class="glyphicon glyphicon-edit"></span></a> </td> <?php foreach (self::$display_columns as $column) { // this is where we place form-element-specific text transformations for display switch ($column->form_element) { case 'image-upload': $image_params = array('filename' => basename($value[$column->name]), 'link' => '', 'mode' => Participants_Db::plugin_setting_is_true('admin_thumbnails') ? 'image' : 'filename'); if (Participants_Db::is_single_record_link($column)) { $page_link = get_permalink(Participants_Db::plugin_setting('single_record_page')); $image_params['link'] = Participants_Db::add_uri_conjunction($page_link) . 'pdb=' . $value['id']; } // this is to display the image as a linked thumbnail $image = new PDb_Image($image_params); $display_value = $image->get_image_html(); break; case 'date': case 'timestamp': if (!empty($value[$column->name])) { $format = Participants_Db::$date_format; if (Participants_Db::plugin_setting_is_true('show_time') and $column->form_element == 'timestamp') { // replace spaces with so the time value stays together on a broken line $format .= ' ' . str_replace(' ', '&\\nb\\sp;', get_option('time_format')); } $time = Participants_Db::is_valid_timestamp($value[$column->name]) ? (int) $value[$column->name] : Participants_Db::parse_date($value[$column->name], $column->name, $column->form_element == 'date'); $display_value = $value[$column->name] == '0000-00-00 00:00:00' ? '' : date_i18n($format, $time); //$display_value = date_i18n($format, $time); } else { $display_value = ''; } break; case 'multi-select-other': case 'multi-checkbox': // multi selects are displayed as comma separated lists $column->value = $value[$column->name]; $display_value = PDb_FormElement::get_field_value_display($column, false); //$display_value = is_serialized($value[$column->name]) ? implode(', ', unserialize($value[$column->name])) : $value[$column->name]; break; case 'link': $link_value = maybe_unserialize($value[$column->name]); if (count($link_value) === 1) { $link_value = array_fill(0, 2, current((array) $link_value)); } $display_value = Participants_Db::make_link($link_value[0], $link_value[1]); break; case 'rich-text': if (!empty($value[$column->name])) { $display_value = '<span class="textarea">' . $value[$column->name] . '</span>'; } else { $display_value = ''; } break; case 'text-line': if (Participants_Db::is_single_record_link($column)) { $url = get_permalink(Participants_Db::plugin_setting('single_record_page')); $template = '<a href="%1$s" >%2$s</a>'; $delimiter = false !== strpos($url, '?') ? '&' : '?'; $url = $url . $delimiter . 'pdb=' . $value['id']; $display_value = sprintf($template, $url, $value[$column->name]); } elseif (Participants_Db::plugin_setting_is_true('make_links')) { $field = new stdClass(); $field->value = $value[$column->name]; $display_value = PDb_FormElement::make_link($field); } else { $display_value = $value[$column->name] === '' ? $column->default : esc_html($value[$column->name]); } break; case 'hidden': $display_value = $value[$column->name] === '' ? '' : esc_html($value[$column->name]); break; default: $column->value = $value[$column->name]; $display_value = PDb_FormElement::get_field_value_display($column, false); } if ($column->name === 'private_id' && Participants_Db::plugin_setting_is_set('registration_page')) { printf($PID_pattern, $display_value, Participants_Db::get_record_link($display_value)); } else { printf($col_pattern, $display_value); } } ?> </tr> <?php } ?> </tbody> <?php } else { // if there are no records to show; do this ?> <tbody> <tr> <td><?php _e('No records found', 'participants-database'); ?> </td> </tr> </tbody> <?php } // participants array ?> </table> <?php if ($hscroll) { ?> </div> </div> <?php } ?> </form> <?php }