/** * instantiates the signup form object * * this class is called by a WP shortcode * * @param array $shortcode_atts this array supplies the display parameters for the instance * 'title' string displays a title for the form (default none) * */ public function __construct($shortcode_atts) { // define shortcode-specific attributes to use $shortcode_defaults = array('module' => 'signup'); $sent = true; // start by assuming the notification email has been sent /* * this is set true if the form is a multi-page form. This is so a multi-page form * can't be completed by skipping back to the signup form, they must go to a page * with a thanks shortcode */ $redirected = false; if ($shortcode_atts['module'] != 'thanks' && (isset($shortcode_atts['action']) && $shortcode_atts['action'] !== '')) { // this is set true if the signup form is supposed to be redirected after the submission $redirected = true; } if (isset($_GET['m']) && $_GET['m'] == 'r' || $shortcode_atts['module'] == 'retrieve') { /* * we're proceesing a link retrieve request */ $shortcode_atts['module'] = 'retrieve'; } elseif ($this->participant_id = Participants_Db::$session->get('pdbid')) { /* * the submission is successful, clear the session */ Participants_Db::$session->clear('pdbid'); Participants_Db::$session->clear('captcha_vars'); Participants_Db::$session->clear('captcha_result'); $this->participant_values = Participants_Db::get_participant($this->participant_id); if ($this->participant_values && !$redirected) { // check the notification sent status of the record $sent = $this->check_sent_status($this->participant_id); $this->submitted = true; $shortcode_atts['module'] = 'thanks'; } $shortcode_atts['id'] = $this->participant_id; } elseif ($shortcode_atts['module'] == 'signup') { /* * we're showing the signup form */ $this->participant_values = Participants_Db::get_default_record(); } else { /* * there was no type set */ return; } // run the parent class initialization to set up the $shortcode_atts property parent::__construct($shortcode_atts, $shortcode_defaults); $this->registration_page = Participants_Db::get_record_link($this->participant_values['private_id']); // set up the signup form email preferences $this->_set_email_prefs(); // set the action URI for the form $this->_set_submission_page(); // set up the template iteration object $this->_setup_iteration(); if ($this->submitted) { /* * filter provides access to the freshly-stored record and the email and thanks message properties so user feedback can be altered. */ if (has_filter(Participants_Db::$prefix . 'before_signup_thanks')) { $signup_feedback_props = array('recipient', 'receipt_subject', 'receipt_body', 'notify_recipients', 'notify_subject', 'notify_body', 'thanks_message', 'participant_values'); $signup_feedback = new stdClass(); foreach ($signup_feedback_props as $prop) { $signup_feedback->{$prop} =& $this->{$prop}; } apply_filters(Participants_Db::$prefix . 'before_signup_thanks', $signup_feedback); } /* * check to see if the thanks email has been sent and send it if it has not */ if ($sent === false) { $this->_send_email(); // mark the record as sent $this->update_sent_status($this->participant_id, true); } else { return false; } // the thanks message and email have already been sent for this ID } // print the shortcode output $this->_print_from_template(); }
/** * maps a sets of values to "tags"in a template, replacing the tags with the values * * @param string $text the tag-containing template string * @param array $data array of record values: $name => $value * @param array $columns array of field objects * * @return string template with all matching tags replaced with values */ public static function replace_tags($text, array $data, array $columns) { $values = $tags = array(); foreach ($columns as $column) { $column->value = isset($data[$column->name]) ? $data[$column->name] : ''; $tags[] = '[' . $column->name . ']'; $values[] = PDb_FormElement::get_field_value_display($column, false); } // add the "record_link" tag if (isset($data['private_id'])) { $tags[] = '[record_link]'; $values[] = Participants_Db::get_record_link($data['private_id']); } // add the date tag $tags[] = '[date]'; $values[] = date_i18n(self::$date_format, self::parse_date()); // add the time tag $tags[] = '[time]'; $values[] = date_i18n(get_option('time_format'), self::parse_date()); if (isset($data['id']) && is_numeric($data['id'])) { // add the admin record link tag $tags[] = '[admin_record_link]'; $values[] = self::get_admin_record_link($data['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 = '') { ?> <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 }
/** * maps a sets of values to "tags"in a template, replacing the tags with the values * * @param string $text the tag-containing template string * @param array $data array of record values: $name => $value * * @return string template with all matching tags replaced with values */ private function replace_tags($text, array $data) { $values = $tags = array(); foreach ($data as $name => $value) { $tags[] = '[' . $name . ']'; $values[] = $value; } // add the "record_link" tag if (isset($data['private_id'])) { $tags[] = '[record_link]'; $values[] = Participants_Db::get_record_link($data['private_id']); } // add the date tag $tags[] = '[date]'; $values[] = date_i18n(Participants_Db::$date_format, Participants_Db::parse_date()); // add the time tag $tags[] = '[time]'; $values[] = date_i18n(get_option('time_format'), Participants_Db::parse_date()); $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 }
/** * replace the tags in text messages * * returns the text with the values replacing the tags * all tags use the column name as the key string * also includes and processes the [record_link] and [date] tags * * @param string $text the text containing tags to be replaced with * values from the db * @param int $participant_id the record id to use * @param string $mode the column subset to use * @return string text with the tags replaced by the data */ public static function proc_tags($text, $participant_id, $mode = 'frontend') { $participant = self::get_participant($participant_id); $tags = array(); $values = array(); foreach (self::get_column_atts($mode) as $column) { $column->module = 'main'; $column->value = $participant[$column->name]; $tags[] = '[' . $column->name . ']'; $values[] = PDb_FormElement::get_field_value_display($column, false); } // add the "record_link" tag $tags[] = '[record_link]'; $values[] = Participants_Db::get_record_link($participant['private_id']); // add the date tag $tags[] = '[date]'; $values[] = date_i18n(self::$date_format, self::parse_date()); // add the admin record link tag $tags[] = '[admin_record_link]'; $values[] = self::get_admin_record_link($participant_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); }