/** * gets a form element html * * @param array $params * @return string */ public static function get_element($params) { return PDb_FormElement::get_element($params); }
/** * provides the field's form element * * @var string $name the field name * @return string HTML */ public function get_form_element($name) { if (property_exists($this->fields, $name)) { $field = $this->fields->{$name}; if (!property_exists($this->fields, 'attributes')) { $field->attributes = array(); } $element = array('type' => $field->form_element, 'name' => $field->name, 'value' => $field->value, 'options' => $field->values, 'class' => Participants_Db::$prefix . $field->form_element, 'attributes' => $field->attributes); return PDb_FormElement::get_element($element); } }
/** * creates the math captcha * * @return null */ protected function math_capcha() { if (is_array($this->value)) { $this->value = $this->value[1]; } $this->size = 3; $operators = array('×' => 'bcmul', '+' => 'bcadd', '−' => 'bcsub'); /* * if the last CAPTCHA submission was correct, we display it again */ if ($this->last_challenge_met() && !empty($this->value)) { extract(Participants_Db::$session->getArray('captcha_vars')); } else { /* generate the math question. We try to make it a simple arithmetic problem */ Participants_Db::$session->clear('captcha_result'); $o = array_rand($operators); switch ($o) { case '×': $a = rand(1, 10); $b = rand(1, 5); break; case '−': $a = rand(2, 10); do { $b = rand(1, 9); } while ($b >= $a); break; default: $a = rand(1, 10); $b = rand(1, 10); } Participants_Db::$session->set('captcha_vars', compact('a', 'o', 'b')); } $prompt_string = $a . ' <span class="' . Participants_Db::$prefix . 'operator">' . $o . '</span> ' . $b . ' <span class="' . Participants_Db::$prefix . 'operator">=</span> ?'; $this->HTML = '<span class="math-captcha">' . $prompt_string . '</span>'; $this->HTML .= PDb_FormElement::get_element(array('type' => 'text', 'name' => $this->name, 'value' => $this->value, 'group' => true)); try { $regex_value = call_user_func($operators[$o], $a, $b); } catch (Exception $e) { error_log(Participants_Db::$plugin_title . ' bcmath function could not be called: using alternative method. '); $regex_value = $this->compute($o, $a, $b); } $this->validation = '#^' . $regex_value . '$#'; $this->captcha_params = array('a' => $a, 'o' => $o, 'b' => $b); }
/** * * @param bool $print * @return null|string */ public function sort_form($print = true) { $value = $this->list_query->current_filter('sort_field'); $options = array(); if (!in_array($value, $this->sortables)) { $options = array('null_select' => ''); } $element = array('type' => 'dropdown', 'name' => 'sortBy', 'value' => $value, 'options' => $options + $this->sortables, 'class' => 'search-item'); $output[] = PDb_FormElement::get_element($element); $element = array('type' => 'radio', 'name' => 'ascdesc', 'value' => $this->list_query->current_filter('sort_order'), 'class' => 'checkbox inline search-item', 'options' => array(__('Ascending', 'participants-database') => 'ASC', __('Descending', 'participants-database') => 'DESC')); $output[] = PDb_FormElement::get_element($element); $output[] = '<input name="submit_button" data-submit="sort" type="submit" value="' . esc_attr($this->i18n['sort']) . '" />'; if ($print) { echo $this->output_HTML($output); } else { return $this->output_HTML($output); } }
/** * displays a settings page form using the WP Settings API * * this function is called by the plugin on it's settings page * * @return null */ public function show_settings_form() { ?> <div class="wrap participants_db settings-class"> <?php Participants_Db::admin_page_heading(Participants_Db::$plugin_title . ' ' . __('Settings', 'participants-database')); ?> <?php settings_errors(); ?> <form action="options.php" method="post" > <div class="ui-tabs"> <?php /* ?> <h2 class="nav-tab-wrapper"> <?php foreach ($this->sections as $id => $title) printf('<a class="nav-tab" href="#%s">%s</a>', Participants_Db::make_anchor($id), $title); ?> </h2> <?php */ ?> <ul class="ui-tabs-nav"> <?php foreach ($this->sections as $id => $title) { printf('<li><a href="#%s">%s</a></li>', Participants_Db::make_anchor($id), $title); } ?> </ul> <?php settings_fields($this->WP_setting); do_settings_sections($this->settings_page); ?> </div> <?php $args = array('type' => 'submit', 'class' => $this->submit_class, 'value' => $this->submit_button, 'name' => 'submit'); printf($this->submit_wrap, PDb_FormElement::get_element($args)); ?> </form> </div> <?php }
/** * prints the general list form controls for the admin lising: deleting and items-per-page selector */ private static function _general_list_form_top() { ?> <form id="list_form" method="post"> <?php PDb_FormElement::print_hidden_fields(array('action' => 'list_action')); ?> <input type="hidden" id="select_count" value="0" /> <table class="form-table"><tbody><tr><td> <fieldset class="widefat inline-controls"> <?php if (current_user_can(Participants_Db::$plugin_options['plugin_admin_capability'])) { ?> <span style="padding-right:20px" ><input type="submit" name="submit-button" class="button button-default" value="<?php echo self::$i18n['delete_checked']; ?> " onClick="return delete_confirm();" id="delete_button" ></span> <?php } ?> <?php $list_limit = PDb_FormElement::get_element(array('type' => 'text-line', 'name' => 'list_limit', 'value' => self::$page_list_limit, 'attributes' => array('style' => 'width:2.8em', 'maxLength' => '3'))); ?> <?php printf(__('Show %s items per page.', 'participants-database'), $list_limit); ?> <?php PDb_FormElement::print_element(array('type' => 'submit', 'name' => 'submit-button', 'class' => 'button button-default', 'value' => self::$i18n['change'])); ?> </fieldset> </td></tr></tbody> <?php }
/** * prints the general list form controls for the admin lising: deleting and items-per-page selector */ private static function _general_list_form_top() { ?> <form id="list_form" method="post"> <?php PDb_FormElement::print_hidden_fields(array('action' => 'list_action')); ?> <input type="hidden" id="select_count" value="0" /> <?php /** * action pdb-admin_list_form_top * @version 1.6 * * todo: add relevent data to action * * good for adding functionality to the admin list */ // do_action(Participants_Db::$prefix . 'admin_list_form_top', $this); do_action(Participants_Db::$prefix . 'admin_list_form_top'); ?> <table class="form-table"><tbody><tr><td> <fieldset class="widefat inline-controls"> <?php if (current_user_can(Participants_Db::plugin_capability('plugin_admin_capability', 'delete participants'))) { ?> <span style="padding-right:20px" ><input type="submit" name="submit-button" class="button button-default" value="<?php echo self::$i18n['delete_checked']; ?> " id="delete_button" ></span> <?php } ?> <?php $list_limit = PDb_FormElement::get_element(array('type' => 'text-line', 'name' => 'list_limit', 'value' => self::$page_list_limit, 'attributes' => array('style' => 'width:2.8em', 'maxLength' => '3'))); ?> <?php printf(__('Show %s items per page.', 'participants-database'), $list_limit); ?> <?php PDb_FormElement::print_element(array('type' => 'submit', 'name' => 'submit-button', 'class' => 'button button-default', 'value' => self::$i18n['change'])); ?> </fieldset> </td></tr></tbody></table> <?php }
public function sort_form($print = true) { $element = array('type' => 'dropdown', 'name' => 'sortBy', 'value' => $this->get_first_in_list($this->filter['sortBy']), 'options' => array('null_select' => true) + $this->sortables, 'class' => 'search-item'); $output[] = PDb_FormElement::get_element($element); $element = array('type' => 'radio', 'name' => 'ascdesc', 'value' => strtoupper($this->get_first_in_list($this->filter['ascdesc'])), 'class' => 'checkbox inline search-item', 'options' => array(__('Ascending', 'participants-database') => 'ASC', __('Descending', 'participants-database') => 'DESC')); $output[] = PDb_FormElement::get_element($element); $output[] = '<input name="submit_button" type="submit" value="' . $this->i18n['sort'] . '" />'; if ($print) { echo $this->output_HTML($output); } else { return $this->output_HTML($output); } }
/** * returns a form element * * @param array $parameters (same as __construct() ) * @static */ public static function get_element($parameters) { PDb_FormElement::get_element($parameters); }
/** * displays a settings page form using the WP Settings API * * this just displays the core (form element) of the page; the complete * page display should be defined by the plugin subclass. * * @return null */ protected function show_settings_form() { settings_errors(); ?> <form action="options.php" method="post"> <?php settings_fields($this->WP_setting); do_settings_sections($this->settings_page); $args = array('type' => 'submit', 'class' => $this->submit_class, 'value' => $this->submit_button, 'name' => 'submit_button'); printf($this->submit_wrap, PDb_FormElement::get_element($args)); ?> </form> <?php }