Exemplo n.º 1
0
?>
</h3>

<?php 
foreach ($debug_info as $section_id => &$section) {
    ?>
<table class="wpbdp-debug-section" data-id="<?php 
    echo $section_id;
    ?>
" style="display: none;">
	<tbody>
		<?php 
    foreach ($section as $k => $v) {
        ?>
		<?php 
        if (wpbdp_starts_with($k, '_')) {
            continue;
        }
        ?>
		<tr>
			<th scope="row"><?php 
        echo esc_attr($k);
        ?>
</th>
			<td><?php 
        echo esc_attr($v);
        ?>
</td>
		</tr>
		<?php 
    }
 protected function step_listing_fields()
 {
     $fields = wpbdp_get_form_fields(array('association' => '-category'));
     $fields = apply_filters_ref_array('wpbdp_listing_submit_fields', array(&$fields, &$this->state));
     $validation_errors = array();
     if (isset($_POST['listingfields']) && isset($_POST['step']) && 'listing_fields' == $_POST['step']) {
         $_POST['listingfields'] = stripslashes_deep($_POST['listingfields']);
         foreach ($fields as &$f) {
             $value = $f->convert_input(wpbdp_getv($_POST['listingfields'], $f->get_id(), null));
             $this->state->fields[$f->get_id()] = $value;
             $field_errors = null;
             $validate_res = apply_filters_ref_array('wpbdp_listing_submit_validate_field', array($f->validate($value, $field_errors), &$field_errors, &$f, $value, &$this->state));
             if (!$validate_res) {
                 $validation_errors = array_merge($validation_errors, $field_errors);
             }
         }
         if (!$this->state->editing && !current_user_can('administrator') && wpbdp_get_option('display-terms-and-conditions')) {
             $tos = trim(wpbdp_get_option('terms-and-conditions'));
             if ($tos && (!isset($_POST['terms-and-conditions-agreement']) || $_POST['terms-and-conditions-agreement'] != 1)) {
                 $validation_errors[] = _x('Please agree to the Terms and Conditions.', 'templates', 'WPBDM');
             }
         }
         if (wpbdp_get_option('recaptcha-for-submits')) {
             if (!wpbdp_recaptcha_check_answer()) {
                 $validation_errors[] = _x("The reCAPTCHA wasn't entered correctly.", 'templates', 'WPBDM');
             }
         }
         if (!$validation_errors) {
             $this->state->advance();
             return $this->dispatch();
         }
     }
     $terms_field = '';
     if (!$this->state->editing && wpbdp_get_option('display-terms-and-conditions')) {
         $tos = trim(wpbdp_get_option('terms-and-conditions'));
         if ($tos) {
             if (wpbdp_starts_with($tos, 'http://', false) || wpbdp_starts_with($tos, 'https://', false)) {
                 $terms_field .= sprintf('<a href="%s" target="_blank">%s</a>', esc_url($tos), _x('Read our Terms and Conditions', 'templates', 'WPBDM'));
             } else {
                 $terms_field .= '<div class="wpbdp-form-field-label">';
                 $terms_field .= '<label>';
                 $terms_field .= _x('Terms and Conditions:', 'templates', 'WPBDM');
                 $terms_field .= '</label>';
                 $terms_field .= '</div>';
                 $terms_field .= '<div class="wpbdp-form-field-html wpbdp-form-field-inner">';
                 $terms_field .= sprintf('<textarea readonly="readonly" rows="5" cols="50">%s</textarea>', esc_textarea($tos));
                 $terms_field .= '</div>';
             }
             $terms_field .= '<label>';
             $terms_field .= '<input type="checkbox" name="terms-and-conditions-agreement" value="1" />';
             $terms_field .= _x('I agree to the Terms and Conditions', 'templates', 'WPBDM');
             $terms_field .= '</label>';
         }
     }
     $recaptcha = '';
     if (wpbdp_get_option('recaptcha-for-submits')) {
         $recaptcha = wpbdp_recaptcha();
     }
     return $this->render('listing-fields', array('fields' => $fields, 'validation_errors' => $validation_errors, 'recaptcha' => $recaptcha, 'terms_and_conditions' => $terms_field));
 }
Exemplo n.º 3
0
 private static function add_debug_msg($msg, $type = 'debug', $context = null)
 {
     self::$messages[] = array('timestamp' => microtime(), 'message' => $msg, 'type' => $type, 'context' => wpbdp_starts_with($type, 'php', false) ? $context : self::_extract_context($context));
 }
Exemplo n.º 4
0
 public function &find_fields($args = array(), $one = false)
 {
     global $wpdb;
     $res = array();
     $args = wp_parse_args($args, array('association' => null, 'field_type' => null, 'validators' => null, 'display_flags' => null, 'unique' => false));
     if ($one == true) {
         $args['unique'] = true;
     }
     extract($args);
     $validators = $validators ? !is_array($validators) ? array($validators) : $validators : array();
     $display_flags = $display_flags ? !is_array($display_flags) ? array($display_flags) : $display_flags : array();
     $where = '';
     if ($args['association']) {
         $associations_in = array();
         $associations_not_in = array();
         $association = !is_array($association) ? array($association) : $association;
         foreach ($association as &$assoc) {
             if (wpbdp_starts_with($assoc, '-')) {
                 $associations_not_in[] = substr($assoc, 1);
             } else {
                 $associations_in[] = $assoc;
             }
         }
         if ($associations_in) {
             $where .= ' AND ( association IN ( \'' . implode('\',\'', $associations_in) . '\' ) ) ';
         }
         if ($associations_not_in) {
             $where .= ' AND ( association NOT IN ( \'' . implode('\',\'', $associations_not_in) . '\' ) ) ';
         }
         // $where .= $wpdb->prepare( " AND ( association = %s ) ", $args['association'] );
     }
     if ($args['field_type']) {
         $field_types_in = array();
         $field_types_not_in = array();
         $field_type = !is_array($field_type) ? array($field_type) : $field_type;
         foreach ($field_type as $f) {
             if (wpbdp_starts_with($f, '-')) {
                 $field_types_not_in[] = substr($f, 1);
             } else {
                 $field_types_in[] = $f;
             }
         }
         if ($field_types_in) {
             $where .= ' AND ( field_type IN ( \'' . implode('\',\'', $field_types_in) . '\' ) ) ';
         }
         if ($field_types_not_in) {
             $where .= ' AND ( field_type NOT IN ( \'' . implode('\',\'', $field_types_not_in) . '\' ) ) ';
         }
     }
     foreach ($display_flags as $f) {
         if (substr($f, 0, 1) == '-') {
             $where .= $wpdb->prepare(" AND ( display_flags IS NULL OR display_flags NOT LIKE '%%%s%%' )", substr($f, 1));
         } else {
             $where .= $wpdb->prepare(" AND ( display_flags LIKE '%%%s%%' )", $f);
         }
     }
     foreach ($validators as $v) {
         if (substr($v, 0, 1) == '-') {
             $where .= $wpdb->prepare(" AND ( validators IS NULL OR validators NOT LIKE '%%%s%%' )", substr($v, 1));
         } else {
             $where .= $wpdb->prepare(" AND ( validators LIKE '%%%s%%' )", $v);
         }
     }
     if ($where) {
         $sql = "SELECT id FROM {$wpdb->prefix}wpbdp_form_fields WHERE 1=1 {$where} ORDER BY weight DESC";
     } else {
         $sql = "SELECT id FROM {$wpdb->prefix}wpbdp_form_fields ORDER BY weight DESC";
     }
     $ids = $wpdb->get_col($sql);
     foreach ($ids as $id) {
         if ($field = WPBDP_FormField::get($id)) {
             $res[] = $field;
         }
     }
     $res = $unique ? $res ? $res[0] : null : $res;
     return $res;
 }
Exemplo n.º 5
0
 protected static function _find($id, $args = array(), $table = '', $classname = '')
 {
     if (!$table || !$classname || !class_exists($classname)) {
         throw new Exception('Please provide a table and class name.');
     }
     global $wpdb;
     $single = false;
     switch ($id) {
         case 'first':
             $args['_limit'] = 1;
             $args['_order'] = 'id';
             $single = true;
             break;
         case 'last':
             $args['_limit'] = 1;
             $args['_order'] = '-id';
             $single = true;
             break;
         case 'all':
             break;
         default:
             $args['id'] = intval($id);
             $args['_limit'] = 1;
             $single = true;
             break;
     }
     $single = !$single && isset($args['_single']) && true == $args['_single'] ? true : $single;
     $order = isset($args['_order']) ? $args['_order'] : '';
     $limit = isset($args['_limit']) ? $args['_limit'] : '';
     $extra = isset($args['_query_extra']) ? $args['_query_extra'] : array();
     $query = "SELECT t.*";
     if (isset($extra['fields'])) {
         $query .= ', ' . $extra['fields'];
     }
     $query .= " FROM {$table} t";
     if (isset($extra['table'])) {
         $query .= ', ' . $extra['table'] . ' ';
     }
     $query .= " WHERE 1=1";
     if (isset($extra['where'])) {
         $query .= ' ' . $extra['where'] . ' ';
     }
     foreach ($args as $arg => $value) {
         if (is_null($value) || in_array($arg, array('_single', '_order', '_limit', '_query_extra'), true)) {
             continue;
         }
         if (is_array($value)) {
             $value_str = implode(',', $value);
             $query .= " AND t.{$arg} IN ({$value_str})";
         } elseif ($value[0] == '>') {
             $query .= " AND t.{$arg} {$value}";
         } else {
             $query .= $wpdb->prepare(" AND t.{$arg}=" . (is_int($value) ? '%d' : '%s'), $value);
         }
     }
     if (isset($extra['groupby'])) {
         $query .= ' GROUP BY ' . $extra['groupby'];
     }
     if ($order) {
         $order_field = wpbdp_starts_with($order, '-') ? substr($order, 1) : $order;
         $order_dir = wpbdp_starts_with($order, '-') ? 'DESC' : 'ASC';
         if (isset($extra['orderby'])) {
             $query .= ' ORDER BY ' . $extra['orderby'];
         } else {
             $query .= " ORDER BY t.{$order_field} {$order_dir}";
         }
     }
     if ($limit > 0) {
         $query .= " LIMIT {$limit}";
     }
     if ($single) {
         if ($row = $wpdb->get_row($query, ARRAY_A)) {
             return new $classname($row);
         } else {
             return null;
         }
     }
     return array_map(create_function('$x', 'return new ' . $classname . '( $x );'), $wpdb->get_results($query, ARRAY_A));
 }