/** * 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; }
$single_record_uri = Participants_Db::add_uri_conjunction($single_record_link) . 'pdb=' . $this->record->record_id; /* * print the opening tag of the single record link */ echo '<a class="single-record-link" href="' . $single_record_uri . '" >'; } ?> <?php /* * here is where we determine how each field value is presented, * depending on what kind of field it is */ switch ($this->field->form_element) { case 'image-upload': $image = new PDb_Image(array('filename' => $value, 'mode' => 'image', 'module' => 'list')); $image->print_image(); break; case 'date': /* * if you want to specify a format, include it as the second * argument in this function; otherwise, it will default to * the site setting. See PHP date() for formatting codes */ $this->show_date($value, false); break; case 'multi-select-other': case 'multi-checkbox': /* * this function shows the values as a comma separated list * you can customize the glue string that joins the array elements
/** * supplies the absolute path to the files location * * @return string */ public static function files_path() { return trailingslashit(PDb_Image::concatenate_directory_path(self::app_base_path(), Participants_Db::files_location())); }
/** * 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 = ''; if (has_filter(Participants_Db::$prefix . 'before_display_field')) { $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 : '', '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', 'admin-edit'))) { $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 = xnau_Image_Handler::concatenate_directory_path(get_bloginfo('url'), Participants_Db::$plugin_options['image_upload_location']) . $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_options['show_time'] == '1' 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 */ $multivalues = Participants_Db::unserialize_array($field->value); // remove empty elements and convert to string for display $multivalues = array_filter((array) $multivalues, array(__CLASS__, 'is_displayable')); $titles = array(); foreach ($multivalues as $value) { $titles[] = self::get_value_title($value, $field->name); } $return = implode(', ', $titles); break; case 'link': $linkdata = Participants_Db::unserialize_array($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': $return = sprintf('<span class="textarea">%s</span>', $field->value); break; case 'rich-text': $return = sprintf('<span class="textarea richtext">%s</span>', Participants_Db::process_rich_text($field->value)); break; default: $field->value = self::get_value_title($field->value, $field->name); $return = self::make_link($field); } } return $return; }
/** * 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 = '') { ?> <table class="wp-list-table widefat fixed pages pdb-list stuffbox" cellspacing="0" > <?php // template for printing the registration page link in the admin $PID_pattern = '<td><a href="%2$s">%1$s</a></td>'; $head_pattern = ' <th class="%2$s" scope="col"> <span>%1$s</span> </th> '; //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($head_pattern); ?> </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($head_pattern); ?> </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_options['plugin_admin_capability'])) { ?> <input type="checkbox" name="pid[]" value="<?php echo $value['id']; ?> " onClick="addSelects(this.checked)"> <?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' => self::$options['admin_thumbnails'] ? 'image' : 'filename'); if (isset(self::$options['single_record_link_field']) && $column->name == self::$options['single_record_link_field'] && !empty(self::$options['single_record_page'])) { $page_link = get_permalink(self::$options['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_options['show_time'] == 1 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 $display_value = is_serialized($value[$column->name]) ? implode(', ', unserialize($value[$column->name])) : $value[$column->name]; break; case 'link': if (is_serialized($value[$column->name])) { $params = unserialize($value[$column->name]); if (empty($params)) { $page_link = array('', ''); } if (count($params) == 1) { $params[1] = $params[0]; } } else { // in case we got old unserialized data in there $params = array_fill(0, 2, $value[$column->name]); } $display_value = Participants_Db::make_link($params[0], $params[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 (isset(self::$options['single_record_link_field']) && $column->name == self::$options['single_record_link_field'] && !empty(self::$options['single_record_page'])) { $url = get_permalink(self::$options['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 (self::$options['make_links']) { $display_value = Participants_Db::make_link($value[$column->name]); } else { $display_value = NULL === $value[$column->name] ? $column->default : esc_html($value[$column->name]); } break; case 'hidden': $display_value = NULL === $value[$column->name] ? '' : esc_html($value[$column->name]); break; default: $display_value = NULL === $value[$column->name] ? $column->default : esc_html($value[$column->name]); } if ($column->name == 'private_id') { 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> </form> <?php }
/** * 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 }
/** * returns an element value formatted for display or storage * * @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) { //error_log(__METHOD__.' field:'.print_r($field,1)); switch ($field->form_element) { case 'image-upload': $image = new PDb_Image(array('filename' => $field->value, 'link' => isset($field->link) ? $field->link : '', 'mode' => 'both', 'module' => $field->module)); if ($html and (!is_admin() or defined('DOING_AJAX') and DOING_AJAX)) { if (isset($field->module) and in_array($field->module, array('single', 'list'))) { $image->display_mode = 'image'; } elseif (isset($field->module) and $field->module == '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 { $upload_dir = wp_upload_dir(); $field->link = get_bloginfo('url') . '/' . Participants_Db::$plugin_options['image_upload_location'] . $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 = strtotime($field->value); $format = get_option('date_format', 'r'); $return = date_i18n($format, $date); } break; case 'multi-checkbox': case 'multi-select-other': $multivalues = maybe_unserialize($field->value); if (is_array($multivalues) and empty($multivalues['other'])) { unset($multivalues['other']); } $return = implode(', ', (array) $multivalues); break; case 'link': /* * value is indexed array: array( $url, $linktext ) */ if (!($linkdata = unserialize_array($field->value))) { $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) { $return = self::make_link($field); break; } else { $return = $field->value; break; } case 'text-area': case 'textarea': $return = sprintf('<span class="textarea">%s</span>', $field->value); break; case 'rich-text': $return = '<span class="textarea richtext">' . $field->value . '</span>'; break; default: $return = $field->value; } return $return; }