Exemplo n.º 1
0
function bbconnect_update_v_0_9_2()
{
    $um = array('1', '2', '3', '4');
    foreach ($um as $m) {
        $meta = bbconnect_get_option('address_' . $m);
        if (false != $meta) {
            $address_keys = array();
            foreach ($meta['options']['choices'] as $k => $v) {
                if (false !== strpos($v, 'address_type')) {
                    $address_keys[] = $v;
                    $loc = '_' . $m;
                    $loc_tag = strtoupper(substr($m, 0, 1));
                    $address = array();
                    // ADDRESS RECIPIENT
                    $address[] = array('source' => 'bbconnect', 'meta_key' => 'address_recipient' . $loc, 'tag' => 'ADREP' . $loc_tag, 'name' => __('Address Recipient', 'bbconnect'), 'options' => array('admin' => true, 'user' => true, 'signup' => false, 'reports' => true, 'public' => false, 'req' => false, 'field_type' => 'text', 'choices' => array()), 'group' => 'address' . $loc, 'help' => __('The person receiving deliveries at this address.', 'bbconnect'));
                    // ADDRESS ORGANIZATION
                    $address[] = array('source' => 'bbconnect', 'meta_key' => 'address_organization' . $loc, 'tag' => 'ADORG' . $loc_tag, 'name' => __('Address Organization', 'bbconnect'), 'options' => array('admin' => true, 'user' => true, 'signup' => false, 'reports' => true, 'public' => false, 'req' => false, 'field_type' => 'text', 'choices' => array()), 'group' => 'address' . $loc, 'help' => __('The company or organization at this address.', 'bbconnect'));
                    foreach ($address as $key => $value) {
                        if (false != get_option('bbconnect_' . $value['meta_key'])) {
                            continue;
                        }
                        // SET A NAMED VALUE FOR THE BBCONNECT_USER_META ARRAY AND
                        $address_keys[] = 'bbconnect_' . $value['meta_key'];
                        // ADD THE OPTION
                        add_option('bbconnect_' . $value['meta_key'], $value);
                    }
                } else {
                    $address_keys[] = $v;
                }
            }
            $meta['options']['choices'] = $address_keys;
            update_option(bbconnect_get_option('address_' . $m, true), $meta);
        }
    }
    return 'success!';
}
function bbconnect_element_choices($args = '')
{
    $defaults = array('nonce' => false, 'meta_key' => false, 'field_type' => false);
    // PARSE THE INCOMING ARGS
    $args = wp_parse_args($args, $defaults);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    // GET THE OPTION
    $user_meta = bbconnect_get_option($meta_key);
    if (!isset($user_meta['meta_key'])) {
        if (strlen($meta_key) <= 2) {
            _e('Please choose a key for this field first!', 'bbconnect');
            die;
        } else {
            $user_meta['meta_key'] = $meta_key;
        }
    }
    // MODIFY THE ARRAY FOR A NEW TYPE
    $user_meta['options']['field_type'] = $field_type;
    // RETURN THE RESULTS
    bbconnect_meta_choices($user_meta);
    //die();
}
/**
 * Display the search attributes for filtering.
 *
 * @since 3.0.0 ibid.
 *
 * @param mix $args Can be an array or URL query-style to override the following defaults...
 *
 * @return html The query for display.
 */
function bbconnect_search_form($args = '')
{
    // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED
    if (isset($_POST['fid'])) {
        $defaults = array('nonce' => $_POST['bbconnect_search_nonce'], 'fid' => $_POST['fid'], 'key' => $_POST['key'], 'query' => array(), 'ajax' => true);
    } else {
        $defaults = array('nonce' => false, 'fid' => false, 'key' => false, 'query' => array(), 'order_by' => '');
    }
    // PARSE THE INCOMING ARGS
    $args = wp_parse_args($args, $defaults);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    global $querystr;
    if (!empty($query)) {
        $querystr = $query;
    }
    // MINI CONSTANTS FOR TRANSLATION
    $_is = __('is', 'bbconnect');
    $_not = __('not', 'bbconnect');
    $_like = __('like', 'bbconnect');
    $_unlike = __('not like', 'bbconnect');
    $_null = __('empty', 'bbconnect');
    $_notnull = __('not empty', 'bbconnect');
    $_any = __('any', 'bbconnect');
    $_all = __('all', 'bbconnect');
    $_show = __('show', 'bbconnect');
    $_lt = __('is less than', 'bbconnect');
    $_gt = __('is greater than', 'bbconnect');
    // DIFFERENTIATE BETWEEN META AND ACTION
    $user_meta = bbconnect_get_option($fid);
    $user_actions = bbconnect_get_user_actions();
    foreach ($user_actions as $arr) {
        if ($fid == $arr['type']) {
            $user_action = $fid;
            break;
        }
    }
    // ACTION
    if (isset($user_action)) {
        ?>
		<input class="i-type" type="hidden" name="search[<?php 
        echo $key;
        ?>
][type]" value="action" />
		<input class="i-field" type="hidden" name="search[<?php 
        echo $key;
        ?>
][field]" value="<?php 
        echo $fid;
        ?>
" />
		<span class="panel">
			<span class="op">
				<select name="search[<?php 
        echo $key;
        ?>
][operator]">
					<option value="min"<?php 
        if (isset($query['operator']) && in_array($query['operator'], array('is', 'min'))) {
            echo ' selected="selected"';
        }
        ?>
><?php 
        _e('>=', 'bbconnect');
        ?>
</option>
					<option value="max"<?php 
        if (isset($query['operator']) && in_array($query['operator'], array('not', 'max'))) {
            echo ' selected="selected"';
        }
        ?>
><?php 
        _e('<=', 'bbconnect');
        ?>
</option>
				</select>
				<input type="text" name="search[<?php 
        echo $key;
        ?>
][limit]" value="<?php 
        if (isset($query['limit'])) {
            echo $query['limit'];
        } else {
            echo '1';
        }
        ?>
" style="width: 25px;" />
			</span>
			<span class="op">
				<select name="search[<?php 
        echo $key;
        ?>
][coperator]" style="width: 55px;">
					<option value="like"<?php 
        if (isset($query['coperator'])) {
            selected($query['coperator'], 'like');
        }
        ?>
><?php 
        echo $_is;
        ?>
</option>
					<option value="notlike"<?php 
        if (isset($query['coperator'])) {
            selected($query['coperator'], 'notlike');
        }
        ?>
><?php 
        echo $_not;
        ?>
</option>
				</select>
				<input type="text" placeholder="<?php 
        _e('Title or Body', 'bbconnect');
        ?>
" name="search[<?php 
        echo $key;
        ?>
][title]" value="<?php 
        if (isset($query['title'])) {
            echo $query['title'];
        }
        ?>
" style="width: 200px;" />
			</span>

			<select class="date-toggle" id="<?php 
        echo $key;
        ?>
_dtoggle" name="search[<?php 
        echo $key;
        ?>
][date][toggle]">
				<option value=""><?php 
        _e('Date Options', 'bbconnect');
        ?>
</option>
				<option value="<?php 
        echo $key;
        ?>
_ran"<?php 
        if (isset($query['date']['toggle'])) {
            selected($query['date']['toggle'], $key . '_ran');
        }
        ?>
><?php 
        _e('Date Range', 'bbconnect');
        ?>
</option>
				<option value="<?php 
        echo $key;
        ?>
_rel"<?php 
        if (isset($query['date']['toggle'])) {
            selected($query['date']['toggle'], $key . '_rel');
        }
        ?>
><?php 
        _e('Relative Date', 'bbconnect');
        ?>
</option>
			</select>
			<span id="<?php 
        echo $key;
        ?>
_ran" class="date_field"<?php 
        if (isset($query['date']['toggle']) && $key . '_ran' == $query['date']['toggle']) {
            echo ' style="display: inline-block"';
        }
        ?>
>
				<input id="<?php 
        echo $key;
        ?>
_start" class="bbconnect-date" type="text" placeholder="Start" name="search[<?php 
        echo $key;
        ?>
][date][range][start]" value="<?php 
        if (isset($query['date']['range']['start'])) {
            echo $query['date']['range']['start'];
        }
        ?>
" style="width: 80px;" /> <input id="<?php 
        echo $key;
        ?>
_end" class="bbconnect-date" type="text"  placeholder="End" name="search[<?php 
        echo $key;
        ?>
][date][range][end]" value="<?php 
        if (isset($query['date']['range']['end'])) {
            echo $query['date']['range']['end'];
        }
        ?>
" style="width: 80px;" />
			</span>
			<span id="<?php 
        echo $key;
        ?>
_rel" class="date_field"<?php 
        if (isset($query['date']['toggle']) && $key . '_rel' == $query['date']['toggle']) {
            echo ' style="display: inline-block"';
        }
        ?>
>
				<select name="search[<?php 
        echo $key;
        ?>
][date][rel][operator]">
					<option value="min"<?php 
        if (isset($query['date']['rel']['operator']) && in_array($query['date']['rel']['operator'], array('min'))) {
            echo ' selected="selected"';
        } else {
            if (!isset($query['date']['rel']['operator']) || empty($query['date']['rel']['operator'])) {
                echo ' selected="selected"';
            }
        }
        ?>
><?php 
        _e('<=', 'bbconnect');
        ?>
</option>
					<option value="is"<?php 
        if (isset($query['date']['rel']['operator']) && in_array($query['date']['rel']['operator'], array('is'))) {
            echo ' selected="selected"';
        }
        ?>
><?php 
        _e('=', 'bbconnect');
        ?>
</option>
					<option value="max"<?php 
        if (isset($query['date']['rel']['operator']) && in_array($query['date']['rel']['operator'], array('max'))) {
            echo ' selected="selected"';
        }
        ?>
><?php 
        _e('>=', 'bbconnect');
        ?>
</option>
				</select>
				<input class="input-micro" type="text" placeholder="units" name="search[<?php 
        echo $key;
        ?>
][date][rel][units]" value="<?php 
        if (isset($query['date']['rel']['units'])) {
            echo $query['date']['rel']['units'];
        }
        ?>
" style="width: 37px;" />
				<select name="search[<?php 
        echo $key;
        ?>
][date][rel][context]">
					<option value=""><?php 
        _e('Time', 'bbconnect');
        ?>
</option>
					<option value="days"<?php 
        if (isset($query['date']['rel']['context'])) {
            selected('days', $query['date']['rel']['context']);
        }
        ?>
><?php 
        _e('days', 'bbconnect');
        ?>
</option>
					<option value="weeks"<?php 
        if (isset($query['date']['rel']['context'])) {
            selected('weeks', $query['date']['rel']['context']);
        }
        ?>
><?php 
        _e('weeks', 'bbconnect');
        ?>
</option>
					<option value="months"<?php 
        if (isset($query['date']['rel']['context'])) {
            selected('months', $query['date']['rel']['context']);
        }
        ?>
><?php 
        _e('months', 'bbconnect');
        ?>
</option>
					<option value="years"<?php 
        if (isset($query['date']['rel']['context'])) {
            selected('years', $query['date']['rel']['context']);
        }
        ?>
><?php 
        _e('years', 'bbconnect');
        ?>
</option>
				</select>
				<select name="search[<?php 
        echo $key;
        ?>
][date][rel][frame]">
					<option value=""><?php 
        _e('Frame', 'bbconnect');
        ?>
</option>
					<option value="before"<?php 
        if (isset($query['date']['rel']['frame'])) {
            selected('before', $query['date']['rel']['frame']);
        }
        ?>
><?php 
        _e('before', 'bbconnect');
        ?>
</option>
					<option value="after"<?php 
        if (isset($query['date']['rel']['frame'])) {
            selected('after', $query['date']['rel']['frame']);
        }
        ?>
><?php 
        _e('after', 'bbconnect');
        ?>
</option>
				</select>
				<select class="timeframe-select" title="<?php 
        echo $key;
        ?>
_timeframe-rel-abs" name="search[<?php 
        echo $key;
        ?>
][date][rel][pin]">
					<option value=""><?php 
        _e('When', 'bbconnect');
        ?>
</option>
					<option value="now"<?php 
        if (isset($query['date']['rel']['pin'])) {
            selected('now', $query['date']['rel']['pin']);
        }
        ?>
><?php 
        _e('now', 'bbconnect');
        ?>
</option>
					<option value="date"<?php 
        if (isset($query['date']['rel']['pin'])) {
            selected('date', $query['date']['rel']['pin']);
        }
        ?>
><?php 
        _e('date', 'bbconnect');
        ?>
</option>
				</select>
				<input id="<?php 
        echo $key;
        ?>
_timeframe-rel-abs" class="bbconnect-date s_date_field" type="text" name="search[<?php 
        echo $key;
        ?>
][date][rel][pindate]" value="<?php 
        if (isset($query['date']['rel']['pindate'])) {
            echo $query['date']['rel']['pindate'];
        }
        ?>
" style="width: 70px;" />
			</span>
		</span>
		<span class="sub-panel"><?php 
        do_action('bbconnect_action_search_meta', $fid, $key, $query);
        ?>
</span>
<?php 
        // META
    } else {
        if (!empty($user_meta)) {
            ?>
		<input class="i-type"  type="hidden" name="search[<?php 
            echo $key;
            ?>
][type]" value="user" />
<?php 
            // SPECIAL EXCEPTION FOR ADDRESSES
            if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) {
                $ext = count(strrchr($fid, '_'));
                $add_app = substr($fid, 0, -$ext);
                $fid = $add_app . '1';
                //$fid = $add_app;
            }
            ?>
		<input class="i-field"  type="hidden" name="search[<?php 
            echo $key;
            ?>
][field]" value="<?php 
            echo $fid;
            ?>
" />
		<span class="multi-op">
			<select name="search[<?php 
            echo $key;
            ?>
][operator]" class="chzn-select" style="width: 100px;">
<?php 
            // SHOW THE MODIFIER
            if ('multitext' == $user_meta['options']['field_type']) {
            } else {
                ?>
				<option value="is"<?php 
                if (isset($query['operator'])) {
                    selected($query['operator'], 'is');
                }
                ?>
><?php 
                echo $_is;
                ?>
</option>
				<option value="not"<?php 
                if (isset($query['operator'])) {
                    selected($query['operator'], 'not');
                }
                ?>
><?php 
                echo $_not;
                ?>
</option>

<?php 
            }
            if ('taxonomy' == $user_meta['options']['field_type'] || 'select' == $user_meta['options']['field_type'] || 'radio' == $user_meta['options']['field_type'] || 'checkbox' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key']) {
            } elseif ('number' == $user_meta['options']['field_type'] || 'date' == $user_meta['options']['field_type']) {
                ?>
				<option value="lt"<?php 
                if (isset($query['operator'])) {
                    selected($query['operator'], 'lt');
                }
                ?>
><?php 
                echo $_lt;
                ?>
</option>
				<option value="gt"<?php 
                if (isset($query['operator'])) {
                    selected($query['operator'], 'gt');
                }
                ?>
><?php 
                echo $_gt;
                ?>
</option>
<?php 
            } else {
                ?>
				<option value="like"<?php 
                if (isset($query['operator'])) {
                    selected($query['operator'], 'like');
                }
                ?>
><?php 
                echo $_like;
                ?>
</option>
				<option value="notlike"<?php 
                if (isset($query['operator'])) {
                    selected($query['operator'], 'notlike');
                }
                ?>
><?php 
                echo $_unlike;
                ?>
</option>
<?php 
            }
            ?>
				<option value=""<?php 
            if (isset($query['operator'])) {
                selected($query['operator'], '');
            }
            ?>
><?php 
            echo $_show;
            ?>
</option>
			</select>
		</span>

<?php 
            if ('taxonomy' == $user_meta['options']['field_type'] || 'bb_work_queue' == $user_meta['meta_key']) {
                //  || isset( $user_meta['group'] ) && false !== strpos( $user_meta['group'], 'address' )
                ?>
			<span class="multi-op">
				<select name="search[<?php 
                echo $key;
                ?>
][sub_operator]">
					<option value="any"<?php 
                if (isset($query['sub_operator'])) {
                    selected($query['sub_operator'], 'any');
                }
                ?>
><?php 
                echo $_any;
                ?>
</option>
					<option value="all"<?php 
                if (isset($query['sub_operator'])) {
                    selected($query['sub_operator'], 'all');
                }
                ?>
><?php 
                echo $_all;
                ?>
</option>
				</select>
			</span>
<?php 
            }
            // IF THIS IS AN ADDRESS, LET'S PRESET SOME OPTIONS
            if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) {
                ?>
			<span class="multi-op">
				<select data-placeholder="All" name="search[<?php 
                echo $key;
                ?>
][post_ops][]" multiple="multiple" class="chzn-select" style="width: 100px;">
		<?php 
                $post_ops_arr = apply_filters('bbconnect_post_ops_arr', array('bbc_primary' => __('Primary', 'bbconnect')));
                foreach ($post_ops_arr as $pops => $pop) {
                    echo '<option value="' . $pops . '"';
                    if (isset($query['post_ops']) && is_array($query['post_ops']) && in_array($pops, $query['post_ops'])) {
                        echo ' selected';
                    }
                    echo '>' . $pop . '</option>';
                }
                ?>
				</select>
			</span>
		<?php 
            }
            ?>

		<span class="panel">
			<?php 
            $args = array();
            $args['meta'] = $user_meta;
            $args['swap_name'] = array($key);
            if (isset($query['query'])) {
                $args['query'] = $query['query'];
            }
            bbconnect_search_field_manipulation($args);
            ?>
		</span>
	<?php 
        }
    }
    if (isset($ajax)) {
        die;
    } else {
    }
}
Exemplo n.º 4
0
/**
 * Displays the profile fields for both the public and private views.
 *
 * @since 1.0.0
 *
 * @param arr $user_id optional. User id integer -- if not present, the function won't
 * attempt to fill in the data.
 *
 * @return html formatted profile fields.
 */
function bbconnect_profile_user_meta($args = '')
{
    // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED
    $defaults = array('user_id' => '', 'bbconnect_cap' => '', 'group_override' => false, 'action' => false, 'bbconnect_user_meta' => get_option('_bbconnect_user_meta'), 'post_arr' => false);
    // PARSE THE INCOMING ARGS
    $args = wp_parse_args($args, $defaults);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    // EXAMINE THE DISPLAY GRID
    if (isset($bbconnect_user_meta['column_2']) && !empty($bbconnect_user_meta['column_2'])) {
        $column_two = true;
        $column_one = '';
    } else {
        $column_one = ' style="width: 99%;"';
    }
    // IF WE HAVE POST VARS, FLATTEN THE ARRAY FOR PROCESSING
    if (false != $post_arr) {
        foreach ($post_arr as $key => $val) {
            if ('bbconnect_user_meta' == $key) {
                foreach ($val as $pkey => $pval) {
                    $post_vars[$pkey] = $pval;
                }
            } else {
                $post_vars[$key] = $val;
            }
        }
    }
    ?>
    <div class="bbconnect-fields">
        <div id="column_1_holder"<?php 
    echo $column_one;
    ?>
>
            <ul id="column_1">
            <?php 
    foreach ($bbconnect_user_meta['column_1'] as $key => $value) {
        // GET THE OPTION
        $user_meta = bbconnect_get_option($value);
        $args = array('meta' => $user_meta, 'bbconnect_cap' => $bbconnect_cap, 'group_override' => $group_override, 'action' => $action);
        $hide_meta = bbconnect_hide_meta($args);
        if ($hide_meta) {
            continue;
        }
        $post_val = false;
        if (isset($post_vars)) {
            // FOR SECTIONS & GROUPS
            if (in_array($user_meta['options']['field_type'], array('group', 'section'))) {
                $post_val = $post_vars;
            } else {
                if (isset($post_vars[$user_meta['meta_key']])) {
                    $post_val = $post_vars[$user_meta['meta_key']];
                }
            }
        }
        bbconnect_get_field(array('meta' => $user_meta, 'id' => $user_id, 'bbconnect_cap' => $bbconnect_cap, 'action' => $action, 'type' => 'user', 'post_val' => $post_val));
    }
    ?>
            </ul>
        </div>

        <?php 
    if (isset($column_two)) {
        ?>

        <div id="column_2_holder">
            <ul id="column_2">
            <?php 
        foreach ($bbconnect_user_meta['column_2'] as $key => $value) {
            // GET THE OPTION
            $user_meta = bbconnect_get_option($value);
            $args = array('meta' => $user_meta, 'bbconnect_cap' => $bbconnect_cap, 'group_override' => $group_override, 'action' => $action);
            $hide_meta = bbconnect_hide_meta($args);
            if ($hide_meta) {
                continue;
            }
            $post_val = false;
            if (isset($post_vars)) {
                // FOR SECTIONS & GROUPS
                if (in_array($user_meta['options']['field_type'], array('group', 'section'))) {
                    $post_val = $post_vars;
                } else {
                    if (isset($post_vars[$user_meta['meta_key']])) {
                        $post_val = $post_vars[$user_meta['meta_key']];
                    }
                }
            }
            bbconnect_get_field(array('meta' => $user_meta, 'id' => $user_id, 'bbconnect_cap' => $bbconnect_cap, 'action' => $action, 'type' => 'user', 'post_val' => $post_val));
        }
        ?>
            </ul>
        </div>

        <?php 
    }
    ?>

    </div>
        <?php 
}
Exemplo n.º 5
0
function bbconnect_get_user_metadata_val($bbconnect_user_meta_arr, $val, $args)
{
    // GRAB THE META DATA
    $user_meta = bbconnect_get_option($val);
    // IF IT'S A SECTION
    if ('section' == $user_meta['options']['field_type']) {
        // RETURN ITS DETAILS
        if (false != $args['section_break']) {
            $bbconnect_user_meta_arr[] = bbconnect_val($user_meta, $args['return_val']);
        } else {
            // LOOP THROUGH ITS CHILDREN
            if (isset($user_meta['options']['choices']) && !empty($user_meta['options']['choices'])) {
                foreach ($user_meta['options']['choices'] as $section_key => $section_val) {
                    // GRAB THE META DATA
                    $section_meta = bbconnect_get_option($section_val);
                    // IF IT'S A GROUP
                    if ('group' == $section_meta['options']['field_type']) {
                        // RETURN ITS DETAILS
                        if (false != $args['group_break']) {
                            $bbconnect_user_meta_arr[] = bbconnect_val($section_meta, $args['return_val']);
                        } else {
                            // LOOP THROUGH ITS CHILDREN
                            foreach ($section_meta['options']['choices'] as $group_key => $group_val) {
                                $bbconnect_user_meta_arr[] = bbconnect_val(bbconnect_get_option($group_val), $args['return_val']);
                            }
                        }
                    } else {
                        $bbconnect_user_meta_arr[] = bbconnect_val($section_meta, $args['return_val']);
                    }
                }
            }
        }
        // IF IT'S A GROUP
    } elseif ('group' == $user_meta['options']['field_type']) {
        // RETURN ITS DETAILS
        if (false != $args['group_break']) {
            $bbconnect_user_meta_arr[] = bbconnect_val($user_meta, $args['return_val']);
        } else {
            // LOOP THROUGH ITS CHILDREN
            foreach ($user_meta['options']['choices'] as $group_key => $group_val) {
                $bbconnect_user_meta_arr[] = bbconnect_val(bbconnect_get_option($group_val), $args['return_val']);
            }
        }
    } else {
        $bbconnect_user_meta_arr[] = bbconnect_val($user_meta, $args['return_val']);
    }
    return $bbconnect_user_meta_arr;
}
Exemplo n.º 6
0
/**
 * Process the submissions return the results
 *
 * @since 0.1.0
 */
function bbconnectpanels_submission($embed = false)
{
    // RUN A SECURITY CHECK
    if (is_user_logged_in()) {
        if (!check_ajax_referer('bbconnectpanels-ajax-nonce', 'bbconnectpanels_nonce', false)) {
            wp_clear_auth_cookie();
            die(__('very sorry. there seems to be an error. please refresh the page and try again.', 'bbconnect'));
        }
    }
    // UNWRAP THE VALUES
    if (isset($_POST['data'])) {
        parse_str($_POST['data'], $_POST);
    }
    // SANITIZE ALL INPUT DATA
    $_POST = bbconnect_scrub('bbconnect_sanitize', $_POST);
    // DO A SERIALIZED VALUE CHECK
    $rel = maybe_unserialize(urldecode($_POST['rel']));
    if (is_array($rel)) {
        $rel_array = $rel;
        $rel = $rel_array['rel'];
        $_POST = array_merge($_POST, $rel_array);
    } else {
        if (false !== strpos($rel, '&')) {
            $rel_pre = explode('&', $rel);
        } else {
            $rel_pre = array($rel);
        }
        // REL CAN BE DECLARED BY THE FORMS
        if (1 == count($rel_pre) && false === strpos($rel, '=')) {
            $rel_array = array('rel' => $rel);
        } else {
            $rel_array = array();
            foreach ($rel_pre as $key => $pair) {
                $pair = explode('=', $pair);
                $rel_array[$pair[0]] = $pair[1];
            }
        }
        // ALLOWED $_GETs
        $okget = bbconnectpanels_get_query_vars();
        foreach ($rel_array as $key => $val) {
            if (in_array($key, $okget)) {
                $_POST[$key] = $val;
            }
        }
    }
    // SANITIZE ALL INPUT DATA
    $_POST = bbconnect_scrub('bbconnect_sanitize', $_POST);
    // IF WE'VE SET A TEMPORARY RE-DIRECT, UNSET IT HERE
    bbconnectpanels_done_whereto();
    // RUN THE SWITCH
    switch ($_POST['rel']) {
        // SENDING A CONTACT REQUEST
        case 'contact':
            if (!empty($_POST['email'])) {
                // CONDITIONS FOR NAME
                $fname = '';
                $lname = '';
                if (isset($_POST['bbconnect_user_meta']['first_name'])) {
                    $fname = $_POST['bbconnect_user_meta']['first_name'];
                }
                if (isset($_POST['bbconnect_user_meta']['last_name'])) {
                    $lname = $_POST['bbconnect_user_meta']['last_name'];
                }
                $name = $fname . ' ' . $lname;
                // EMAIL
                $email = $_POST['email'];
                // USER TARGET
                if (isset($_POST['uid'])) {
                    $uid = $_POST['uid'];
                    unset($_POST['uid']);
                }
                // CODE
                $log_code = false;
                $contact_title = '';
                $form = false;
                if (isset($_POST['bbc_form'])) {
                    $log_code = $_POST['bbc_form'];
                    $bbc_titles = get_option('_bbconnect_user_forms');
                    $contact_title = $bbc_titles[$_POST['bbc_form']] . ': ';
                    $form = get_option('_bbconnect_form_' . $_POST['bbc_form']);
                    $form_notifications = true;
                    if (!empty($form['notify_enable']) && 'false' == $form['notify_enable']) {
                        $form_notifications = false;
                    }
                }
                // SUBJECT
                $subject = $contact_title . __('Submission', 'bbconnect');
                if (false != $form && isset($form['subject'])) {
                    $subject = $form['subject'];
                }
                if (isset($_POST['_bbc_post']['_bbc_form_subject'])) {
                    $subject = $_POST['_bbc_post']['_bbc_form_subject'];
                    unset($_POST['_bbc_post']['_bbc_form_subject']);
                }
                // MESSAGE
                $message = '';
                if (isset($_POST['_bbc_post']['_bbc_form_message'])) {
                    $message = $_POST['_bbc_post']['_bbc_form_message'];
                    unset($_POST['_bbc_post']['_bbc_form_message']);
                }
                // APPEND ADDITIONAL FIELDS TO THE MESSAGE
                if (isset($_POST['bbconnect_user_meta'])) {
                    foreach ($_POST['bbconnect_user_meta'] as $k => $v) {
                        $option = bbconnect_get_option($k);
                        $message .= "\r\n";
                        $message .= $option['name'] . ": " . stripslashes(maybe_serialize($v)) . "\r\n";
                    }
                }
                // CC
                $cc_me = 'false';
                if (isset($_POST['_bbc_post']['_bbc_form_cc'])) {
                    $cc_me = $_POST['_bbc_post']['_bbc_form_cc'];
                    unset($_POST['_bbc_post']['_bbc_form_cc']);
                }
                $sender = get_user_by('email', $email);
                // IF THEY DON'T EXIST, ADD THEM!
                // FIRST TIME COMMUNICATIONS ARE GOING TO BE LOGGED NO MATTER WHAT
                if (!$sender) {
                    // NEED TO DO A SECONDARY CHECK FOR ALTERNATE EMAILS
                    $user_id = bbconnect_insert_user(array('ivals' => $_POST, 'log_type' => 'contact_form', 'log_code' => $log_code, 'title' => $contact_title . $subject, 'content' => $message));
                    $sender = get_user_by('id', $user_id);
                    // IF THEY DO EXIST, AND ARE CONTACTING AN ADMIN, LOG IT!
                } else {
                    if (!isset($uid)) {
                        $postdata['post_title'] = $contact_title . $subject;
                        $postdata['post_content'] = $message;
                        $postdata['post_status'] = 'private';
                        $postdata['post_author'] = $sender->ID;
                        $postdata['post_type'] = 'bbc_log';
                        $post_id = wp_insert_post($postdata, true);
                        // UPDATE THE META
                        if (intval($post_id)) {
                            update_post_meta($post_id, '_bbc_log_type', 'contact_form');
                            update_post_meta($post_id, '_bbc_log_code', $log_code);
                        }
                    }
                }
                // PREP THE FORM FOR MAIL NOTIFICATIONS
                // SENDER INFORMATION
                // EMAIL COMES FROM $_POST['email']
                $_POST['name'] = $name;
                if (false != $form) {
                    if (!empty($form['notify_from'])) {
                        $_POST['email'] = $form['notify_from'];
                    }
                    if (!empty($form['notify_from_name'])) {
                        $_POST['name'] = $form['notify_from_name'];
                    }
                }
                // NEED AN OPTION FOR MAIL NOTIFICATIONS
                // IF THIS IS GOING TO ANOTHER SITE USER...
                $to_email = array();
                if (isset($uid)) {
                    $recipient = get_user_by('id', $uid);
                    $to_email[] = $recipient->user_email;
                    $form_notifications = true;
                } else {
                    if (false != $form) {
                        $to_email = explode(',', $form['notify']);
                        foreach ($to_email as $tek => $tev) {
                            $to_email[$tek] = trim($tev);
                        }
                    }
                }
                $to_email = apply_filters('bbconnectpanels_contact_form_recipients', $to_email, $sender, $log_code);
                // IF WE'RE EMAILING, DO IT NOW
                if (!empty($to_email)) {
                    $admin_msg = '';
                    $admin_msg .= sprintf(__('Origin: %1$s', 'bbconnect'), get_option('blogname')) . "\r\n";
                    if (!empty($contact_title)) {
                        $admin_msg .= sprintf(__('Form: %1$s', 'bbconnect'), $contact_title) . "\r\n";
                    }
                    $admin_msg .= sprintf(__('Sender: %1$s <%2$s>', 'bbconnect'), $name, $email) . "\r\n";
                    $admin_msg .= "\r\n";
                    $admin_msg .= $message;
                    // IF WE'RE MAILING, ADD THE FILTERS
                    add_filter('wp_mail_from', 'bbconnectpanels_get_from_email', 20);
                    add_filter('wp_mail_from_name', 'bbconnectpanels_get_from_name', 20);
                    // SEND THE MAIL
                    if (false != $form_notifications) {
                        wp_mail($to_email, $subject, $admin_msg);
                    }
                    // COPY THEM BUT NOT ON THE SAME EMAIL
                    if ('true' == $cc_me) {
                        $_POST['email'] = get_option('admin_email');
                        $_POST['name'] = get_option('blogname');
                        $user_msg = sprintf(__('You asked to be copied on the message below that you sent via the website: %1$s', 'bbconnect'), get_option('blogname')) . "\r\n";
                        $user_msg .= "\r\n";
                        $user_msg .= $message;
                        wp_mail($email, 'Re: ' . $subject, $user_msg);
                    }
                    remove_filter('wp_mail_from', 'bbconnectpanels_get_from_email', 20);
                    remove_filter('wp_mail_from_name', 'bbconnectpanels_get_from_name', 20);
                }
                // THANK YOU
                $thankyou = __('Thank you.', 'bbconnect');
                if (isset($_POST['bbc_form'])) {
                    $bbc_form = get_option('_bbconnect_form_' . $_POST['bbc_form']);
                    $thankyou = bbconnect_scrub('bbconnect_esc_html', $bbc_form['confirm']);
                }
                $signcount = 2 + round(str_word_count(strip_tags($thankyou)) / 4);
                // GIVE PREFERENCE TO THE USER'S PRIOR ACTION
                // LET PLUGINS MODIFY THE SUCCESS ACTION
                do_action('bbconnect_after_contact', $sender, $log_code);
                // SET A FILTER FOR REDIRECTION
                $wloc = apply_filters('bbconnect_contact_redirect', '', $sender, $log_code);
                // REFRESH THE BROWSER
                ?>
				<p id="tschuss"><?php 
                echo wpautop($thankyou);
                ?>
</p>
				<script type="text/javascript">
					setTimeout(function() {
						jQuery('#tschuss').fadeOut('slow');
						jQuery('#bbconnectpanel').removeClass();
						<?php 
                if ('true' != get_option('bbconnectpanels_embed')) {
                    ?>
								jQuery('#bbconnectpanel').slideToggle('fast');
						<?php 
                    if (!empty($wloc)) {
                        echo "window.location = '" . $wloc . "';";
                    }
                } else {
                    if (!empty($wloc)) {
                        echo "window.location.href = '" . $wloc . "';";
                    }
                }
                ?>
					},  <?php 
                echo $signcount * 1000;
                ?>
);
				</script>
				<?php 
                die;
            } else {
                // THE DEFAULT FIELDS
                $form_fields = bbconnect_form_api_fields();
                // USER-DEFINED REPLACEMENT
                if (isset($_POST['bbc_form'])) {
                    $contact_arr = get_option('_bbconnect_form_' . $_POST['bbc_form']);
                }
                // THE DEFAULT CONTACT FORM
                if (!isset($contact_arr) || empty($contact_arr)) {
                    $contact_arr = get_option('_bbconnect_form_contact_form');
                }
                // THE SAFETY CONTACT FORM
                if (!isset($contact_arr) || empty($contact_arr)) {
                    $contact_arr = array('column_1' => array('first_name', 'last_name', 'email'), 'column_2' => array('_bbc_form_subject', '_bbc_form_message', '_bbc_form_cc'));
                }
                // DOUBLE-CHECK THAT WE HAVE AN EMAIL AND A MESSAGE
                $c_email = false;
                $c_msg = false;
                foreach ($contact_arr as $ckey => $cval) {
                    if (is_array($cval)) {
                        if (in_array('email', $cval)) {
                            $c_email = true;
                        }
                        if (in_array('_bbc_form_message', $cval)) {
                            $c_msg = true;
                        }
                    }
                }
                // ALWAYS ENSURE EMAIL IS SET
                if (false == $c_email) {
                    array_push($contact_arr['column_1'], 'email');
                }
                //if ( false == $c_msg )
                //array_push( $contact_arr['column_2'], '_bbc_form_message' );
                if (isset($contact_arr['msg']) && !empty($contact_arr['msg'])) {
                    echo '<div id="form-msg">';
                    echo wpautop(stripslashes($contact_arr['msg']));
                    echo '</div>';
                }
                // LET'S SEE IF THEY WANT ONE OR TWO COLUMNS
                if (empty($contact_arr['column_2'])) {
                    $colone = ' class="column-holder full"';
                    $coltwo = false;
                } else {
                    $colone = ' id="column_1_holder"';
                    $coltwo = ' id="column_2_holder"';
                }
                ?>
				<form class="bbconnectpanels-form" enctype="multipart/form-data" action="" method="POST">
					<div<?php 
                echo $colone;
                ?>
>
						<ul>
						<?php 
                if (isset($contact_arr['column_1'])) {
                    foreach ($contact_arr['column_1'] as $key => $val) {
                        if (isset($form_fields[$val])) {
                            $meta = $form_fields[$val];
                            $args['type'] = 'post';
                        } else {
                            $meta = bbconnect_get_option($val);
                        }
                        $args['meta'] = $meta;
                        $args['action'] = 'register';
                        if (is_user_logged_in()) {
                            global $current_user;
                            $args['id'] = $current_user->ID;
                        }
                        bbconnect_get_field($args);
                    }
                }
                ?>
						</ul>
					</div>
					
					<?php 
                if (false != $coltwo) {
                    ?>
					<div<?php 
                    echo $coltwo;
                    ?>
>
						<ul>
						<?php 
                    if (isset($contact_arr['column_2'])) {
                        foreach ($contact_arr['column_2'] as $key => $val) {
                            if (isset($form_fields[$val])) {
                                $meta = $form_fields[$val];
                                $args['type'] = 'post';
                            } else {
                                $meta = bbconnect_get_option($val);
                            }
                            $args['meta'] = $meta;
                            $args['action'] = 'register';
                            if (is_user_logged_in()) {
                                global $current_user;
                                $args['id'] = $current_user->ID;
                            }
                            bbconnect_get_field($args);
                        }
                    }
                    ?>
						</ul>
					</div>
					<?php 
                }
                ?>
					<div class="continue">
						<input type="hidden" name="rel" value="contact" />
						<?php 
                if (isset($_POST['uid'])) {
                    echo '<input type="hidden" name="uid" value="' . $_POST['uid'] . '" />';
                }
                if (isset($_POST['bbc_form'])) {
                    echo '<input type="hidden" name="bbc_form" value="' . $_POST['bbc_form'] . '" />';
                }
                ?>
						<input type="submit" name="_bbconnect[submission]" value="<?php 
                _e('Submit', 'bbconnect');
                ?>
" class="button" />
						<?php 
                echo bbconnectpanels_build_panel_link(array('links' => apply_filters('bbconnect_contact_links', array())));
                ?>
					</div>
				</form>
				<?php 
            }
            break;
            // EXTEND THE PANEL SYSTEM
        // EXTEND THE PANEL SYSTEM
        default:
            do_action('bbconnectpanels_switch', $rel);
            break;
    }
    if ('true' == get_option('bbconnectpanels_embed')) {
        echo '<div id="close-bot"></div>';
    } else {
        ?>
	<div id="close-top"><?php 
        bbconnectpanels_panel_link('action=close');
        ?>
</div>
	<div id="close-bot"><?php 
        bbconnectpanels_panel_link('action=close');
        ?>
</div>
	<script type="text/javascript">
	</script>
	<?php 
    }
    if ('true' == get_option('bbconnectpanels_google_analytics')) {
        ?>
	<script type="text/javascript">
		// "_trackEvent" is the pageview event,
		_gaq.push(['_trackPageview', '/<?php 
        echo $rel;
        ?>
']);
	</script>
	<?php 
    }
    // ALL DONE!
    die;
}
Exemplo n.º 7
0
function bbconnect_filter_process($post_data)
{
    // LOCAL VARIABLES
    global $wpdb, $memberquery, $membervalue, $users_per_page, $max_num_pages, $table_head, $table_body, $blog_prefix, $bid, $page_num, $query_diff, $action_search, $all_search;
    $bid = get_current_blog_id();
    $blog_prefix = $wpdb->get_blog_prefix($bid);
    $mtc = 0;
    $page_num = 1;
    $mtjoin = array();
    $mtquery = array();
    $mtselect = array("DISTINCT {$wpdb->users}.ID");
    // as id
    $skip_arr = array();
    // IF THERE'S A SORT BY REQUEST, PROCESS THAT
    if (!empty($post_data['order_by'])) {
        $order_by = apply_filters('bbcpres_filter_order_by', $post_data['order_by']);
        // STANDARDIZE WORDPRESS INCONSISTENCIES FOR RESERVED FIELDS
        // EMAIL
        switch ($order_by) {
            case 'ID':
                $order_by = 'ID';
                break;
            case 'email':
                $order_by = 'user_email';
                break;
            case 'url':
                $order_by = 'user_url';
                break;
            case 'user_login':
                $order_by = 'user_login';
                break;
            case 'display_name':
                $order_by = 'display_name';
                break;
            case 'user_registered':
                $order_by = 'user_registered';
                break;
            case 'role':
                $order_by = $blog_prefix . 'capabilities';
                $ometa = true;
                break;
            case 'first_name':
                $order_by = $order_by;
                $ometa = true;
                break;
            case 'last_name':
                $order_by = $order_by;
                $ometa = true;
                break;
            default:
                $order_by = $order_by;
                $ometa = true;
                break;
        }
    } else {
        $order_by = 'ID';
    }
    // SET THE SORT DIRECTION, IF IT HASN'T BEEN SET ALREADY
    if (!isset($post_data['order'])) {
        $post_data['order'] = 'DESC';
    }
    if ('DESC' === $post_data['order']) {
        //uksort( $all_sort, 'insensitive_uksort_rev' );
        $order = 'DESC';
    } else {
        //uksort( $all_sort, 'insensitive_uksort' );
        $order = 'ASC';
    }
    /*
    // SET UP THE SORTING ARRAY
    $all_sort = array();
    foreach ( $all_search as $user ) {
    
        // IF THERE'S A SORT BY REQUEST, PROCESS THAT
        if ( isset( $order_by ) ) {
    
            // GET THE VALUE TO ORDER BY
            $current_user = get_userdata( $user );
    
            // INCLUDE IT IF IT EXISTS AND APPEND THE USER ID TO ENSURE THE KEYS ARE UNIQUE
            if ( isset( $current_user->$order_by ) ) {
                $all_key = str_replace( '-', '_', $current_user->$order_by ) . '_' . $user;
            } else {
                $all_key = $user;
            }
    
        } else {
    
            $all_key = $user;
    
        }
    
        $all_val = $user;
        $all_sort[$all_key] = $all_val;
    }
    */
    // WE CAN TRY BYPASSING THIS FOR IMPORTS BY SETTING IT THROUGH POSTDATA
    if (!isset($post_data['all_search'])) {
        // RETURN VALUES
        $table_head = array();
        $table_body = array();
        $all_search = array();
        $member_search = array();
        $users_count = '';
        // THE POST-OPERATOR
        $post_operator = array();
        // THE COUNTER TO KEEP TRACK OF HOW MANY QUERIES WE'VE MADE
        global $u_count;
        $u_count = '0';
        // THE QUERY ARRAY CONTAINING THE RESULTING ARRAY OF USER IDS
        if (isset($post_data['search'])) {
            $q_array = array();
        }
        // LET'S GET STARTED!
        // MERGE TAGS: LOOP THROUGH THE POST VALUES AND BUILD THE QUERY
        if (isset($post_data['search'])) {
            foreach ($post_data['search'] as $key => $value) {
                if ('user' != $value['type']) {
                    continue;
                }
                // GO AHEAD AND TALLY
                $u_count++;
                // SET THE FIELD KEY
                $fkey = $value['field'];
                // DETERMINE THE OPERATOR
                switch ($value['operator']) {
                    case '':
                        $op = 'skip';
                        $sop = '||';
                        break;
                    case 'is':
                        $op = '=';
                        $sop = '||';
                        break;
                    case 'not':
                        $op = '!=';
                        $sop = '&&';
                        break;
                    case 'like':
                        $op = 'LIKE';
                        $sop = '||';
                        break;
                    case 'notlike':
                        $op = 'NOT LIKE';
                        $sop = '&&';
                        break;
                    case 'null':
                        $op = 'IS NULL';
                        $sop = '||';
                        break;
                    case 'notnull':
                        $op = 'IS NOT NULL';
                        $sop = '||';
                        break;
                    case 'lt':
                        $op = '<';
                        $sop = '||';
                        break;
                    case 'gt':
                        $op = '>';
                        $sop = '||';
                        break;
                }
                // DETERMINE THE SUB OPERATOR
                if (isset($value['sub_operator'])) {
                    switch ($value['sub_operator']) {
                        case 'all':
                            $sop = '&&';
                            break;
                        case 'any':
                            $sop = '||';
                            break;
                    }
                }
                // PREP THE RESULTS TABLE && DISTINGUISH BETWEEN TAXONOMIES & META
                if ('bbconnect' != substr($fkey, 0, 9)) {
                    $option_key = 'bbconnect_' . $fkey;
                } else {
                    $option_key = $fkey;
                }
                // EVALUATE THE FIELD
                $user_meta = get_option($option_key);
                // STANDARDIZE WORDPRESS INCONSISTENCIES FOR RESERVED FIELDS
                if (isset($user_meta['source']) && 'wpr' == $user_meta['source']) {
                    // EMAIL
                    if ('email' == $user_meta['meta_key']) {
                        $wp_col = 'user_email';
                    }
                    // USER ID
                    if ('ID' == $user_meta['meta_key']) {
                        $wp_col = 'ID';
                    }
                    // USER CREATED DATE
                    if ('user_registered' == $user_meta['meta_key']) {
                        $wp_col = 'user_registered';
                    }
                    // URL
                    if ('url' == $user_meta['meta_key']) {
                        $wp_col = 'user_url';
                    }
                    // LOGIN
                    if ('user_login' == $user_meta['meta_key']) {
                        $wp_col = 'user_login';
                    }
                    // DISPLAY NAME
                    if ('display_name' == $user_meta['meta_key']) {
                        $wp_col = 'display_name';
                    }
                    // ROLE
                    if ('role' == $user_meta['meta_key']) {
                        $wp_meta_col = $blog_prefix . 'capabilities';
                        //if ( 'skip' != $op )
                        //$op = 'LIKE';
                    }
                }
                // SPECIAL CASE FOR SERIALIZED DATA
                if ('taxonomy' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key']) {
                    if ('=' == $op && isset($value['query'])) {
                        $op = 'LIKE';
                    } else {
                        if ('!=' == $op && isset($value['query'])) {
                            $op = 'NOT LIKE';
                        }
                    }
                }
                // Even special-er case for Work Queues etc
                if ('bb_work_queue' == $user_meta['meta_key']) {
                    $wp_col = 'ID';
                    if ('=' == $op && isset($value['query'])) {
                        $op = 'IN';
                    } else {
                        if ('!=' == $op && isset($value['query'])) {
                            $op = 'NOT IN';
                        }
                    }
                }
                // STANDARDIZE WORDPRESS META FIELDS
                if (isset($user_meta['source'])) {
                    if ('wp' == $user_meta['source'] && 'taxonomy' != $user_meta['options']['field_type']) {
                        $wp_meta_col = $fkey;
                    } else {
                        if ('wp' == $user_meta['source'] && 'taxonomy' == $user_meta['options']['field_type']) {
                            $user_meta_col = '';
                        } else {
                            if ('user' == $user_meta['source']) {
                                $user_meta_col = '';
                            } else {
                                $user_meta_col = 'bbconnect_';
                            }
                        }
                    }
                }
                // IF WE'RE JUST DISPLAYING RESULTS, SIT THIS PART OUT
                if ('skip' != $op) {
                    // SET THE QUERY PREFIX
                    if (0 === $mtc) {
                        $mtc_as = '';
                        $mtc_dot = "{$wpdb->usermeta}.";
                    } else {
                        $mtc_as = 'AS mt' . $mtc . ' ';
                        $mtc_dot = 'mt' . $mtc . '.';
                        // FUTURE $mtselect[] = 'mt' . $mtc.'.meta_value';
                    }
                    // THIS IS A SUBQUERY
                    if (isset($value['query'])) {
                        $value_query = $value['query'];
                    } else {
                        $value_query = '';
                    }
                    if (is_array($value_query)) {
                        // SETUP A TEMP ARRAY TO JOIN
                        $temp_arr = array();
                        foreach ($value_query as $subkey => $subvalue) {
                            // MIMIC THE SERIALIZED STRUCTURE FOR ROLES AND TAXONOMIES
                            if ('taxonomy' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key']) {
                                $subvalue = substr($wpdb->prepare("%s", $subvalue), 1, -1);
                                $q_val = '\'%s:' . strlen($subvalue) . ':"' . $subvalue . '"%\'';
                                // Work Queues are rather special...
                            } else {
                                if ('bb_work_queue' == $user_meta['meta_key'] && function_exists('bbconnect_workqueues_get_action_items')) {
                                    $args = array('tax_query' => array(array('taxonomy' => 'bb_note_type', 'field' => 'term_id', 'terms' => array($subvalue))));
                                    $notes = bbconnect_workqueues_get_action_items($args);
                                    $note_users = array();
                                    foreach ($notes as $note) {
                                        $note_users[$note->post_author] = $note->post_author;
                                    }
                                    $q_val = '(' . implode(',', $note_users) . ')';
                                    //                             } elseif ($key == 'category_id' || $key == 'segment_id') {
                                    // CONDITIONS FOR THE VALUE
                                } else {
                                    if ('LIKE' === $op || 'NOT LIKE' === $op) {
                                        $q_val = $wpdb->prepare("%s", '%' . $subvalue . '%');
                                    } else {
                                        if ('IS NULL' === $op || 'IS NOT NULL' === $op) {
                                            $q_val = "";
                                        } else {
                                            if ('<' === $op || '>' === $op) {
                                                if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $value_query)) {
                                                    $is_date = true;
                                                } else {
                                                    $is_date = false;
                                                }
                                                if ($is_date) {
                                                    $q_val = "DATE('" . $value_query . "')";
                                                } else {
                                                    $q_val = strpos($subvalue, '.') !== false ? floatval($subvalue) : intval($subvalue);
                                                }
                                            } else {
                                                if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $subvalue) && $wp_col != 'user_registered') {
                                                    if (date('Y-m-d', strtotime($subvalue)) == $subvalue) {
                                                        $temp_date_arr[] = "DATE('" . $subvalue . "')";
                                                    }
                                                } else {
                                                    $q_val = $wpdb->prepare("%s", $subvalue);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // THIS IS A WORDPRESS USER FIELD
                            if (isset($wp_col)) {
                                if ($wp_col == 'user_registered') {
                                    if (date('Y-m-d', strtotime($subvalue)) == $subvalue) {
                                        $temp_arr[] = "DATE('" . $subvalue . "')";
                                    }
                                } else {
                                    $temp_arr[] = "(" . $wp_col . " " . $op . " " . $q_val . ")";
                                }
                            } else {
                                if (isset($wp_meta_col)) {
                                    $temp_arr[] = $mtc_dot . "meta_value " . $op . " " . $q_val;
                                } else {
                                    $temp_arr[] = $mtc_dot . "meta_value " . $op . " " . $q_val;
                                }
                            }
                        }
                        // JOIN THE JOIN
                        if (isset($wp_col)) {
                            if ($wp_col == 'user_registered') {
                                if ('!=' == $op || 'NOT LIKE' == $op) {
                                    $reg_op = " NOT BETWEEN ";
                                } else {
                                    $reg_op = " BETWEEN ";
                                }
                                $mtquery[$mtc] = "(" . $wp_col . $reg_op . implode(' AND ', $temp_arr) . ")";
                            } else {
                                $mtquery[$mtc] = "(" . implode(' ' . $sop . ' ', $temp_arr) . ")";
                            }
                        } else {
                            //if ( !isset( $wp_col ) )
                            $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)";
                            // JOIN THE QUERY TEMP ARRAY
                            if (isset($wp_meta_col)) {
                                $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = '" . $wp_meta_col . "' AND " . implode(' ' . $sop . ' ', $temp_arr) . ")";
                            } else {
                                if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) {
                                    $mod_key = substr($fkey, 0, -1);
                                    // PREPARE $mod_comp = "meta_key LIKE '%".$user_meta_col. $mod_key . "%'";
                                    $mod_comp = $wpdb->prepare("meta_key LIKE %s", "%" . $user_meta_col . $mod_key . "%");
                                } else {
                                    $mod_key = $fkey;
                                    // PREPARE $mod_comp = "meta_key = '".$user_meta_col. $mod_key . "'";
                                    $mod_comp = $wpdb->prepare("meta_key = %s", $user_meta_col . $mod_key);
                                }
                                if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $subvalue)) {
                                    if ('!=' == $op || 'NOT LIKE' == $op) {
                                        $reg_op = " NOT BETWEEN ";
                                    } else {
                                        $reg_op = " BETWEEN ";
                                    }
                                    $mtquery[$mtc] = "(" . $mtc_dot . $mod_comp . " AND " . $mtc_dot . "meta_value " . $reg_op . implode(' AND ', $temp_date_arr) . ")";
                                } else {
                                    $mtquery[$mtc] = "(" . $mtc_dot . $mod_comp . " AND " . implode(' ' . $sop . ' ', $temp_arr) . ")";
                                }
                            }
                        }
                    } else {
                        /* MIMIC THE SERIALIZED STRUCTURE FOR ROLES AND TAXONOMIES
                           if ( 'taxonomy' == $user_meta['options']['field_type'] || 'role' == $user_meta['meta_key'] ) {
                               if ( '' != $value_query )
                                   $value_query = 's:'.strlen($value_query).':"'.$value_query.'"';
                           }
                           */
                        // CONDITIONS FOR THE VALUE
                        // AND THE OPERATOR IF APPLICABLE
                        if ('LIKE' === $op || 'NOT LIKE' === $op) {
                            // PREPARE $q_val = "'%" . $value_query . "%'";
                            $q_val = $wpdb->prepare("%s", '%' . $value_query . '%');
                        } else {
                            if ('IS NULL' === $op || 'IS NOT NULL' === $op || '' == $value_query || empty($value_query) || !isset($value_query)) {
                                if (isset($wp_col)) {
                                    if ('IS NULL' === $op || '=' === $op) {
                                        $op = "=";
                                    } else {
                                        $op = "!=";
                                    }
                                    $q_val = "''";
                                } else {
                                    if ('' == $value_query || empty($value_query) || !isset($value_query)) {
                                        if ('=' === $op && !isset($wp_meta_col)) {
                                            $op = "IS NULL";
                                            $q_val = "";
                                        } else {
                                            if ('!=' == $op && !isset($wp_meta_col)) {
                                                $op = "IS NOT NULL";
                                                $q_val = "";
                                            } else {
                                                // PREPARE $q_val = "'" . $value_query . "'";
                                                $q_val = $wpdb->prepare("'%s'", $value_query);
                                            }
                                        }
                                    }
                                }
                            } else {
                                if ('<' === $op || '>' === $op) {
                                    if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\$/", $value_query)) {
                                        $is_date = true;
                                    } else {
                                        $is_date = false;
                                    }
                                    if ($is_date) {
                                        $q_val = "DATE('" . $value_query . "')";
                                    } else {
                                        $q_val = strpos($value_query, '.') !== false ? floatval($value_query) : intval($value_query);
                                    }
                                } else {
                                    // PREPARE $q_val = "'" . $value_query . "'";
                                    $q_val = $wpdb->prepare("'%s'", $value_query);
                                }
                            }
                        }
                        // THIS IS A WORDPRESS USER FIELD
                        if (isset($wp_col)) {
                            $mtquery[$mtc] = "(" . $wp_col . " " . $op . " " . $q_val . ")";
                        } else {
                            $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)";
                            // TEST FOR NULL COMPARISONS
                            if ('IS NULL' === $op) {
                                if (isset($wp_meta_col)) {
                                    $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = '" . $wp_meta_col . "' AND " . $mtc_dot . "meta_value = '')";
                                } else {
                                    if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) {
                                        $mod_key = substr($fkey, 0, -1);
                                        // PREPARE $mod_comp = "meta_key = '%".$user_meta_col. $mod_key . "%'";
                                        $mod_comp = $wpdb->prepare("meta_key LIKE %s", "%" . $user_meta_col . $mod_key . "%");
                                    } else {
                                        $mod_key = $fkey;
                                        // PREPARE $mod_comp = "meta_key = '".$user_meta_col. $mod_key . "'";
                                        $mod_comp = $wpdb->prepare("meta_key = %s", $user_meta_col . $mod_key);
                                    }
                                    $mtquery[$mtc] = "( " . $mtc_dot . "user_id NOT IN(SELECT DISTINCT " . $wpdb->usermeta . ".user_id FROM " . $wpdb->usermeta . " WHERE " . $wpdb->usermeta . "." . $mod_comp . ") )";
                                }
                            } else {
                                if (isset($wp_meta_col)) {
                                    $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = '" . $wp_meta_col . "' AND " . $mtc_dot . "meta_value " . $op . " " . $q_val . ")";
                                } else {
                                    if (isset($user_meta['group']) && false !== strpos($user_meta['group'], 'address')) {
                                        $mod_key = substr($fkey, 0, -1);
                                        // PREPARE $mod_comp = "meta_key LIKE '%".$user_meta_col. $mod_key . "%'";
                                        $mod_comp = $wpdb->prepare("meta_key LIKE %s", "%" . $user_meta_col . $mod_key . "%");
                                    } else {
                                        $mod_key = $fkey;
                                        // PREPARE $mod_comp = "meta_key = '".$user_meta_col. $mod_key . "'";
                                        $mod_comp = $wpdb->prepare("meta_key = %s", $user_meta_col . $mod_key);
                                    }
                                    $mtquery[$mtc] = "(" . $mtc_dot . $mod_comp . " AND " . $mtc_dot . "meta_value " . $op . " " . $q_val . ")";
                                }
                            }
                        }
                    }
                    // DETERMINE ANY QUERY POST-OPS
                    if (isset($value['post_ops'])) {
                        // SET THE SELECT FIELD FOR THE PRECEDING VALUE
                        $mtselect[] = $mtc_dot . "meta_key AS mv" . $mtc;
                        foreach ($value['post_ops'] as $post_op) {
                            // PUSH THE COMPARITORS
                            $kpost_op = array('meta' => $fkey, 'type' => $post_op, 'incl' => $value['operator']);
                            array_push($post_operator, $kpost_op);
                            // INCREMENT THE QUERY COUNTER
                            $mtc++;
                            // SET THE QUERY PREFIX
                            if (0 === $mtc) {
                                $mtc_as = '';
                                $mtc_dot = "{$wpdb->usermeta}.";
                            } else {
                                $mtc_as = 'AS mt' . $mtc . ' ';
                                $mtc_dot = 'mt' . $mtc . '.';
                            }
                            $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)";
                            // PREPARE $mtquery[$mtc] = "(" . $mtc_dot . "meta_key = 'bbconnect_" . $post_op . "')";
                            $mtquery[$mtc] = $wpdb->prepare("(" . $mtc_dot . "meta_key = %s)", "bbconnect_{$post_op}");
                            $mtselect[] = $mtc_dot . "meta_value AS mv" . $mtc;
                        }
                    }
                } else {
                    $skip_arr[] = 'bbconnect_' . $value['field'];
                }
                // NO MATTER WHAT, SAVE THE DATA FOR THE COLUMNS
                // IT'S A TAXONOMY!
                if ('taxonomy' == $user_meta['options']['field_type']) {
                    // PULL THE TAXONOMY DATA AND ASSIGN THE DISPLAY VALUES
                    $tab_head = get_taxonomy($fkey);
                    // ASSIGN THE DISPLAY VALUES
                    $table_head[] = array(false, $tab_head->labels->name);
                    if ('bbconnect' != $user_meta['source']) {
                        $switch_key = $fkey;
                    } elseif ('bbconnect' == $user_meta['source']) {
                        $switch_key = $option_key;
                    }
                    // TEST FOR DISPLAY PURPOSES
                    if (empty($value['query'])) {
                        $table_body[$switch_key][] = '';
                        // GET ALL THE TERMS!
                    } else {
                        foreach ($value['query'] as $term) {
                            // GET THE TERM ID
                            $table_body[$switch_key][] = $term;
                        }
                    }
                    // IT'S A META!
                } else {
                    // THE HEADER
                    $table_head[] = array($user_meta['meta_key'], $user_meta['name']);
                    // THE BODY
                    if ('wpr' == $user_meta['source']) {
                        if (isset($wp_col)) {
                            $table_body[$wp_col] = $fkey;
                        } else {
                            if (isset($wp_meta_col)) {
                                $table_body[$wp_meta_col] = $fkey;
                            }
                        }
                    } elseif ('bbconnect' != $user_meta['source']) {
                        $table_body[$fkey] = $fkey;
                    } elseif ('bbconnect' == $user_meta['source']) {
                        if ('address' == substr($user_meta['group'], 0, 7)) {
                            if (2 != count($key)) {
                                $atk = '_' . $key;
                            } else {
                                $atk = $key;
                            }
                            $table_body[$option_key . $atk] = $fkey;
                        } else {
                            $table_body[$option_key] = $fkey;
                        }
                    }
                }
                // CLEANUP
                $mtc++;
                if (isset($temp_arr)) {
                    unset($temp_arr);
                }
                if (isset($wp_col)) {
                    unset($wp_col);
                }
                if (isset($wp_meta_col)) {
                    unset($wp_meta_col);
                }
                if (isset($user_meta_col)) {
                    unset($user_meta_col);
                }
            }
            // SET UP THE ORDER CLAUSE
            if (isset($ometa)) {
                // SET THE QUERY PREFIX
                if (0 === $mtc) {
                    $mtc_as = '';
                    $mtc_dot = "{$wpdb->usermeta}.";
                } else {
                    $mtc_as = 'AS mt' . $mtc . ' ';
                    $mtc_dot = 'mt' . $mtc . '.';
                }
                $mtjoin[$mtc] = "INNER JOIN {$wpdb->usermeta} " . $mtc_as . "ON ({$wpdb->users}.ID = " . $mtc_dot . "user_id)";
                if (in_array($order_by, $skip_arr)) {
                    // GET THE META TO TEST
                    $t_order_by = bbconnect_get_option($order_by);
                    if (false != $t_order_by) {
                        if ('bbconnect' == $t_order_by['source']) {
                            $order_by = 'bbconnect_' . $order_by;
                        }
                    }
                    $nullquo = $wpdb->prepare("IFNULL(" . $mtc_dot . "meta_key = %s,0) = %s", $order_by, $order_by);
                    $nullval = " ORDER BY IFNULL(" . $mtc_dot . "meta_value," . $mtc_dot . "meta_key) {$order}";
                } else {
                    // GET THE META TO TEST
                    $t_order_by = bbconnect_get_option($order_by);
                    if (false != $t_order_by) {
                        if ('bbconnect' == $t_order_by['source']) {
                            $order_by = 'bbconnect_' . $order_by;
                        }
                    }
                    if (isset($t_order_by['group']) && false !== strpos($t_order_by['group'], 'address')) {
                        $addext = count(strrchr($t_order_by['meta_key'], '_'));
                        $addapp = substr($t_order_by['meta_key'], 0, -$addext);
                        $nullquo = $wpdb->prepare($mtc_dot . "meta_key LIKE %s", '%bbconnect_' . $addapp . '%');
                    } else {
                        $nullquo = $wpdb->prepare($mtc_dot . "meta_key = %s", $order_by);
                    }
                    $nullval = " ORDER BY " . $mtc_dot . "meta_value {$order}";
                }
                $mtquery[$mtc] = $nullquo;
                $mtorder = $nullval;
                // CASE FOR ACTIONS
                //$actusers  = "INNER JOIN $wpdb->usermeta ON ($wpdb->posts.post_author = $wpdb->usermeta.user_id)";
                //$actquery = "$wpdb->usermeta.meta_key = '$order_by' AND";
                //$mtc++;
            } else {
                $mtorder = " ORDER BY {$wpdb->users}.{$order_by} {$order}";
                // CASE FOR ACTIONS
                //$actusers  = "INNER JOIN $wpdb->users ON ($wpdb->posts.post_author = $wpdb->users.ID)";
                //$actquery = ""; // "$wpdb->usermeta.meta_key = '$order_by' AND";
            }
            // JOIN THE QUERY
            $q_join = implode(' ', $mtjoin);
            $q_query = implode(' ' . $post_data['mod_results'] . ' ', $mtquery);
            $q_select = implode(', ', $mtselect);
            $wpdb->flush();
            if (empty($q_query)) {
                $all_query = "SELECT {$wpdb->users}.ID FROM {$wpdb->users} {$mtorder}";
                $all_search = $wpdb->get_col($all_query);
            } else {
                $all_query = "SELECT {$q_select} FROM {$wpdb->users} {$q_join} WHERE 1=1 AND {$q_query} {$mtorder}";
                if (count($mtselect) > 1) {
                    $all_search = $wpdb->get_results($all_query, ARRAY_N);
                } else {
                    $all_search = $wpdb->get_col($all_query);
                }
            }
            $wpdb->flush();
        } else {
            // ASSUME THEY WANT TO SEARCH EVERYONE...
            if (isset($ometa)) {
                $all_order = "INNER JOIN {$wpdb->usermeta} ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id) WHERE {$wpdb->usermeta}.meta_key = '{$order_by}' ORDER BY {$wpdb->usermeta}.meta_value {$order}";
            } else {
                $all_order = "ORDER BY {$wpdb->users}.{$order_by} {$order}";
            }
            $all_query = "SELECT {$wpdb->users}.ID FROM {$wpdb->users} {$all_order}";
            //
            $all_search = $wpdb->get_col($all_query);
            $wpdb->flush();
        }
        //echo $all_query;
        //print_r($post_data);
        // IF THE POST OPERATOR IS SET, FILTER THE RESULTS
        if (!empty($post_operator)) {
            // SET THE REFRESHED OPERATOR
            $po_all_search = array();
            // LOOP THROUGH THE OPERATORS AND TEST WHETHER THEY SHOULD BE INCLUDED
            foreach ($all_search as $key => $value) {
                // COUNT THE ELEMENTS IN THE RESULTS ARRAY
                if (!isset($po_arr_count)) {
                    $po_arr_count = count($value) - 1;
                }
                // LOCATE THE TARGET INTEGER FOR ADDRESSES
                //if ( !isset( $po_index ) ) {
                $pre_po_index = strrchr($value[1], '_');
                $po_index = substr($pre_po_index, 1);
                $po_count = 0 - strlen($po_index);
                //}
                // LOOP THROUGH THE VALUES AND IF THEY DON'T AGREE, UNSET THE VALUE
                for ($i = 2; $i <= $po_arr_count; $i++) {
                    if (substr($value[$i], $po_count) != $po_index) {
                        $cur_[$key] = true;
                    }
                }
                // IF THERE'S A MATCH, RE-BUILD THE ALL SEARCH ARRAY
                if (!isset($cur_[$key])) {
                    $po_all_search[] = $value[0];
                }
            }
            $all_search = $po_all_search;
            unset($po_all_search);
        }
        do_action('bbconnect_search_extend', $post_data, $all_search);
    } else {
        $all_search = $post_data['all_search'];
    }
    // CONTINUE ON WITH THE PAGINATION AND SORTING ACTIVITY...
    if (!empty($all_search)) {
        $users_count = count($all_search);
        // GET THE REQUESTED PAGE NUMBER
        if (isset($_GET['page_num'])) {
            $page_num = $_GET['page_num'];
        } else {
            if (isset($post_data['page_num'])) {
                $page_num = $post_data['page_num'];
            }
        }
        // GET THE REQUESTED RESULT SET
        if (isset($post_data['users_per_page'])) {
            //check if user per page is all
            if (strtolower($post_data['users_per_page']) == 'all') {
                $users_per_page = $users_count;
            } else {
                $users_per_page = $post_data['users_per_page'];
            }
        } else {
            $users_per_page = 25;
            // THIS NEEDS TO BE AN OPTION!!!
        }
        // GET THE NUMBER OF PAGES
        $max_num_pages = ceil($users_count / $users_per_page);
        $pages = (int) $page_num;
        if ($pages > $max_num_pages) {
            $pages = $max_num_pages;
        }
        if ($pages < 1) {
            $pages = 1;
        }
        // GET THE PAGE RANGE
        $page_low = ($pages - 1) * $users_per_page;
        $page_high = $users_per_page;
        // FINALLY, IF WE'RE PAGINATING, SLICE THE ARRAY
        $member_search = array_slice($all_search, $page_low, $page_high);
    }
    if (!isset($action_search)) {
        $action_search = false;
    }
    $ret_arr = array('all_search' => $all_search, 'member_search' => $member_search, 'action_search' => $action_search, 'post_vars' => $post_data, 'max_num_pages' => $max_num_pages, 'users_count' => $users_count, 'users_per_page' => $users_per_page, 'page_num' => $page_num, 'errors' => false, 'table_head' => $table_head, 'table_body' => $table_body);
    unset($all_search);
    unset($member_search);
    unset($action_search);
    return $ret_arr;
}
Exemplo n.º 8
0
function bbconnect_field($meta, $args = array())
{
    // CORNERSHOP CREATIVE CUSTOMIZATION
    $meta = apply_filters('bbconnect_field_prepare', $meta, $args);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    // FOR CONVENIENCE
    $key = $meta['meta_key'];
    $disabled = bbconnect_field_disabled($key);
    // SETUP THE LOGIC
    switch ($meta['options']['field_type']) {
        case 'title':
            // BUMP
            echo '<h3 class="bbconnect-section">' . stripslashes($meta['name']) . '</h3>';
            if (isset($meta['description']) && !empty($meta['description'])) {
                echo '<p>' . $meta['description'] . '</p>';
            }
            break;
        case 'taxonomy':
            $tax = $key;
            $taxonomy = get_taxonomy($tax);
            // DETERMINE WHETHER OR NOT CHILDREN ARE DISPLAYED
            if (isset($meta['options']['children']) && false == $meta['options']['children']) {
                $children = '&parent=0';
            } else {
                $children = '';
            }
            // SET THE DISPLAY OPTIONS
            if (isset($meta['options']['sort_by']) && false == $meta['options']['sort_by']) {
                $sort = '&orderby=name';
            } else {
                $sort = '&orderby=id';
            }
            $terms = get_terms($tax, 'hide_empty=0' . $sort . $children);
            if ('-view' == $action) {
                foreach ($terms as $term) {
                    if (!empty($value) && in_array_r($term->term_id, $value)) {
                        $output_arr[] = $term->name;
                    }
                }
                if (!empty($output_arr)) {
                    echo '<div> ' . implode(', ', $output_arr) . '</div>';
                }
            } else {
                $display = get_option('_bbconnect_taxonomy_display');
                // LET THE API OVERRIDE THIS
                if (isset($meta['options']['display'])) {
                    $display = $meta['options']['display'];
                }
                if ('select' == $display || '-search' == $action) {
                    echo '<select class="chzn-select" multiple="multiple" name="' . $name . '[]" style="width: 200px">';
                    $child_terms = array();
                    if ('' == $children) {
                        foreach ($terms as $term) {
                            $selected = '';
                            if (false != $term->parent) {
                                if (!empty($value) && in_array_r($term->term_id, $value)) {
                                    $selected = ' selected';
                                }
                                $child_terms[$term->parent][] = '<option value="' . $term->term_id . '"' . $selected . '>&nbsp;&nbsp;&nbsp;' . $term->name . '</option>';
                            }
                        }
                    }
                    foreach ($terms as $term) {
                        $selected = '';
                        if (false != $term->parent) {
                            continue;
                        }
                        if (!empty($value) && in_array_r($term->term_id, $value)) {
                            $selected = ' selected';
                        }
                        echo '<option value="' . $term->term_id . '"' . $selected . '>' . $term->name . '</option>';
                        if (isset($child_terms[$term->term_id])) {
                            foreach ($child_terms[$term->term_id] as $pk => $pv) {
                                echo $pv;
                            }
                        }
                    }
                    echo '</select>';
                } else {
                    echo '<div class="taxonomy-panel">';
                    if ('' == $children) {
                        foreach ($terms as $term) {
                            $checked = '';
                            if (false != $term->parent) {
                                if (!empty($value) && in_array_r($term->term_id, $value)) {
                                    $checked = ' checked';
                                }
                                $child_terms[$term->parent][] = '<span class="float-checkbox">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="' . $name . '[]"  value="' . $term->term_id . '"' . $checked . ' />&nbsp;' . $term->name . '</span>';
                            }
                        }
                    }
                    foreach ($terms as $term) {
                        $checked = '';
                        if (false != $term->parent) {
                            continue;
                        }
                        if (!empty($value) && in_array_r($term->term_id, $value)) {
                            $checked = ' checked';
                        }
                        echo '<span class="float-checkbox"><input type="checkbox" name="' . $name . '[]"  value="' . $term->term_id . '"' . $checked . ' />&nbsp;' . $term->name;
                        if (isset($child_terms[$term->term_id])) {
                            foreach ($child_terms[$term->term_id] as $pk => $pv) {
                                echo $pv;
                            }
                        }
                        echo '</span>';
                    }
                    echo '</div>';
                }
                if ('-edit' == $action) {
                    echo '<input type="hidden" name="' . $name . '[]"  value="" />';
                }
                // SPECIAL CASES
                if ('-bulk-edit' == $action) {
                    echo '<div style="clear: both; padding: 7px;"><input type="radio" name="bbconnect_user_taxonomy_options[' . $key . ']" value="append" checked="checked" /> ' . __('Append', 'bbconnect') . '<input type="radio" name="bbconnect_user_taxonomy_options[' . $key . ']" value="overwrite" /> ' . __('Overwrite', 'bbconnect') . '<input type="radio" name="bbconnect_user_taxonomy_options[' . $key . ']" value="remove" /> ' . __('Remove', 'bbconnect') . '</div>';
                }
                if ('-edit' == $action && current_user_can('list_users')) {
                    echo '<div class="end-of-float"><a href="' . get_bloginfo('wpurl') . '/wp-admin/edit-tags.php?taxonomy=' . $tax . '&TB_iframe=true&height=450&width=920" class="thickbox button-primary">' . __('Add terms', 'bbconnect') . '</a></div>';
                }
            }
            break;
        case 'section':
            if ('-view' != $action || 'true' == get_option('bbconnectpanels_public_labels')) {
                echo '<h3>' . stripslashes($meta['name']) . '</h3>';
            }
            echo '<ul>';
            if (!empty($meta['options']['choices'])) {
                // THIS IS A PASS THROUGH FOR ANY SANITIZED POST VALS
                $child_vals = array();
                if (isset($value) && is_array($value) && !empty($value)) {
                    $child_vals = $value;
                }
                foreach ($meta['options']['choices'] as $skey => $sval) {
                    // GET THE OPTION
                    $smeta = bbconnect_get_option($sval);
                    // CHECK TO SEE IF ANY FIELDS HAVE BEEN REMOVED FROM DISPLAY
                    $grouped_hide = bbconnect_hide_meta(array('meta' => $smeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                    if ($grouped_hide) {
                        continue;
                    }
                    $post_val = false;
                    if (in_array($smeta['options']['field_type'], array('group'))) {
                        $post_val = $child_vals;
                    } else {
                        if (isset($child_vals[$smeta['meta_key']])) {
                            $post_val = $child_vals[$smeta['meta_key']];
                        }
                    }
                    // ECHO OUT THE FIELDS!
                    bbconnect_get_field(array('meta' => $smeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                }
            }
            echo '</ul>';
            break;
        case 'textarea':
            // ALLOW OPTIONS TO HAVE SOME PRESETS
            if (empty($value) && !empty($meta['options']['choices'])) {
                $value = $meta['options']['choices'];
            }
            if ('-view' == $action) {
                echo wpautop($value);
            } else {
                if ('-edit' == $action) {
                    // ONLY DISPLAY THE TEXT AREA IF WE KNOW FOR SURE WE HAVE THE RIGHT RESOURCES
                    if (isset($meta['options']['wp_editor']) && false != $meta['options']['wp_editor']) {
                        // CORNERSHOP CREATIVE CUSTOMIZATION
                        $html_value = utf8_encode(html_entity_decode($value));
                        wp_editor($html_value, $key, array('textarea_name' => $name));
                    } else {
                        echo '<textarea ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="' . $class . '">' . $value . '</textarea>';
                    }
                } else {
                    echo '<textarea ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="' . $class . '">' . $value . '</textarea>';
                }
            }
            break;
        case 'select':
        case 'multiselect':
            if ('-view' == $action) {
                if ('wpr' == $meta['source'] && 'display_name' == $key) {
                    echo $value->display_name;
                } else {
                    echo $value;
                }
            } else {
                // OPTIONALLY ADD LOOKUPS
                if ('-search' == $action) {
                    $autocomp = ' chzn-select';
                    $multiple = ' multiple="multiple" data-placeholder="' . __('All Options', 'bbconnect') . '" style="width: 150px"';
                    $name = $name . '[]';
                } else {
                    if ('multiselect' == $meta['options']['field_type']) {
                        $autocomp = ' chzn-select';
                        $multiple = ' multiple="multiple"';
                        $name = $name . '[]';
                    } else {
                        if ('address' == substr($key, 0, 7)) {
                            if (false !== strpos($key, 'country')) {
                                $multiple = '';
                                $autocomp = ' country-field';
                            } else {
                                if (false !== strpos($key, 'state')) {
                                    $multiple = '';
                                    $autocomp = ' state-province-field';
                                } else {
                                    $autocomp = '';
                                    $multiple = '';
                                }
                            }
                        } else {
                            $autocomp = '';
                            $multiple = '';
                        }
                    }
                }
                if ('wpr' == $meta['source']) {
                    if ('-search' == $action) {
                    } else {
                        if (isset($flag) && 'normalize' == $flag) {
                        } else {
                            $name = $key;
                        }
                    }
                }
                // LET'S HANDLE ROLES
                if ('wpr' == $meta['source'] && 'role' == $key) {
                    echo '<select ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="regular-text' . $class . $autocomp . '"' . $multiple . '>';
                    if (is_array($value)) {
                        $user_role = $value;
                    } else {
                        //$user_roles = array_keys( $value->wp_capabilities );
                        //$user_role = array_shift( $user_roles );
                        $user_roles = array_intersect(array_values($value->roles), array_keys(get_editable_roles()));
                        $user_role = array_shift($user_roles);
                    }
                    // print the full list of roles with the primary one selected.
                    bbconnect_dropdown_roles($user_role);
                    // print the 'no role' option. Make it selected if the user has no role yet.
                    if ('-search' == $action) {
                        echo '<option value="no_role">' . __('No role for this site') . '</option>';
                    } else {
                        if ($user_role) {
                            echo '<option value="">' . __('&mdash; No role for this site &mdash;') . '</option>';
                        } else {
                            echo '<option value="" selected="selected">' . __('&mdash; No role for this site &mdash;') . '</option>';
                        }
                    }
                    echo '</select>';
                    // AND DISPLAY NAMES (ADDING A FEW OPTIONS ALONG THE WAY)
                } else {
                    if ('wpr' == $meta['source'] && 'display_name' == $key) {
                        if (is_user_logged_in() && !empty($value)) {
                            $cuser = $value;
                            echo '<select ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="regular-text' . $class . $autocomp . '"' . $multiple . '>';
                            $public_display = array();
                            if (!empty($cuser->nickname)) {
                                $public_display['display_nickname'] = $cuser->nickname;
                            }
                            if (!empty($cuser->user_login)) {
                                $public_display['display_username'] = $cuser->user_login;
                            }
                            if (!empty($cuser->first_name)) {
                                $public_display['display_firstname'] = $cuser->first_name;
                            }
                            if (!empty($cuser->last_name)) {
                                $public_display['display_lastname'] = $cuser->last_name;
                            }
                            // FOR ORGS
                            if (!empty($cuser->bbconnect_organization)) {
                                $public_display['display_organization'] = $cuser->bbconnect_organization;
                            }
                            if (!empty($cuser->first_name) && !empty($cuser->last_name)) {
                                // SETUP FORMAL VARS
                                if (!empty($cuser->bbconnect_prefix)) {
                                    $m_pre = $cuser->bbconnect_prefix . ' ';
                                }
                                if (!empty($cuser->bbconnect_suffix)) {
                                    $m_suf = ' ' . $cuser->bbconnect_suffix;
                                }
                                if (!empty($cuser->bbconnect_middle_name)) {
                                    $m_mid = ' ' . $cuser->bbconnect_middle_name . ' ';
                                } else {
                                    $m_mid = ' ';
                                }
                                $public_display['display_formal'] = $m_pre . $cuser->first_name . $m_mid . $cuser->last_name . $m_suf;
                                $public_display['display_firstlast'] = $cuser->first_name . ' ' . $cuser->last_name;
                                $public_display['display_lastfirst'] = $cuser->last_name . ' ' . $cuser->first_name;
                            }
                            if (!empty($cuser->display_name)) {
                                if (!in_array($cuser->display_name, $public_display)) {
                                    // Only add this if it isn't duplicated elsewhere
                                    $public_display = array('display_displayname' => $cuser->display_name) + $public_display;
                                }
                            }
                            $public_display = array_map('trim', $public_display);
                            $public_display = array_unique($public_display);
                            foreach ($public_display as $id => $item) {
                                echo '<option id="' . $id . '"' . selected($cuser->display_name, $item) . '>' . $item . '</option>';
                            }
                            echo '</select>';
                        }
                        // EVERYTHING ELSE
                    } else {
                        if (!is_array($value)) {
                            $value = html_entity_decode($value);
                            // Hack to fix issue with "Mr & Mrs"
                        }
                        echo '<select ' . $disabled . ' name="' . $name . '" id="' . $id . '" class="regular-text' . $class . $autocomp . '"' . $multiple . '>';
                        if (empty($value) && isset($meta['options']['default'])) {
                            $value = $meta['options']['default'];
                        }
                        $setext = '';
                        echo '<option value="">' . $setext . '</option>';
                        // IF THIS IS A REFERENCE TO A HELPER, PICK IT UP
                        if (!is_array($meta['options']['choices'])) {
                            $option_arr = call_user_func($meta['options']['choices']);
                        } else {
                            $option_arr = $meta['options']['choices'];
                        }
                        // IF THIS IS AN ASSOCIATIVE ARRAY, CREATE OPTION GROUPS
                        foreach ($option_arr as $choices => $choice) {
                            if (is_array($choice)) {
                                $true_match = true;
                                if (false !== strpos($meta['meta_key'], 'address_state_')) {
                                    $true_match = false;
                                    $address_number = substr($meta['meta_key'], -1);
                                    $user_country = get_user_meta($_GET['user_id'], 'bbconnect_address_country_' . $address_number, true);
                                    $countries = bbconnect_helper_country();
                                    $country = array_key_exists($user_country, $countries) ? $countries[$user_country] : $user_country;
                                    if ($choices == $country) {
                                        $true_match = true;
                                    }
                                }
                                foreach ($choice as $topkey => $topvalue) {
                                    if (is_array($topvalue)) {
                                        echo '<optgroup label="' . $topkey . '">';
                                        foreach ($topvalue as $subkey => $subvalue) {
                                            echo '<option value="' . $subkey . '"';
                                            if (is_array($value)) {
                                                if (in_array($subkey, $value) && $true_match) {
                                                    echo ' selected="selected"';
                                                }
                                            } elseif ($true_match) {
                                                echo selected($value, $subkey);
                                            }
                                            echo '>' . $subvalue . '</option>';
                                        }
                                        echo '</optgroup>';
                                    } else {
                                        echo '<option value="' . $topkey . '"';
                                        if (is_array($value)) {
                                            if (in_array($topkey, $value) && $true_match) {
                                                echo ' selected="selected"';
                                            }
                                        } elseif ($true_match) {
                                            echo selected($value, $topkey);
                                        }
                                        echo '>' . $topvalue . '</option>';
                                    }
                                }
                            } else {
                                echo '<option value="' . $choices . '"';
                                if (is_array($value)) {
                                    if (in_array($choices, $value)) {
                                        echo ' selected="selected"';
                                    }
                                } else {
                                    echo selected($value, $choices);
                                }
                                echo '>' . $choice . '</option>';
                            }
                        }
                        echo '</select>';
                    }
                }
            }
            break;
        case 'checkbox':
            if ('-bulk-edit' == $action) {
                echo '<select ' . $disabled . ' name="' . $name . '">';
                echo '<option value="true">' . __('yes', 'bbconnect') . '</option>';
                echo '<option value="false">' . __('no', 'bbconnect') . '</option>';
                echo '</select>';
            } else {
                if ('-search' === $action) {
                    echo '<select ' . $disabled . ' name="' . $name . '">';
                    echo '<option value=""' . selected($value, '') . '>' . __('empty', 'bbconnect') . '</option>';
                    echo '<option value="true"' . selected($value, 'true') . '>' . __('yes', 'bbconnect') . '</option>';
                    echo '<option value="false"' . selected($value, 'false') . '>' . __('no', 'bbconnect') . '</option>';
                    echo '</select>';
                } else {
                    if ('wp' == $meta['source']) {
                        // SET THE DEFAULTS
                        if ('true' === $meta['options']['choices']) {
                            $chk = 'on';
                            $val = 'true';
                        } else {
                            $chk = 'off';
                            $val = 'false';
                        }
                        // LET THE USER SAVED VALUE OVERRIDE THE DEFAULTS
                        if (!empty($value)) {
                            if ('true' === $value) {
                                $chk = 'on';
                                $val = 'true';
                            } else {
                                $chk = 'off';
                                $val = 'false';
                            }
                        }
                        // SPECIAL CASE FOR THE ADMIN BARS AND SSL PREFERENCES
                        if ('rich_editing' == $key || 'comment_shortcuts' == $key) {
                            $wp_class = 'upt ';
                            $wp_key = $key;
                            $field_name = ' name="' . $key . '"';
                        } else {
                            if ('show_admin_bar_front' == $key || 'show_admin_bar_admin' == $key || 'admin_bar_front' == $key) {
                                $wp_key = 'admin_bar_front';
                                $wp_class = 'uwpt ';
                                if ('on' == $chk) {
                                    $field_name = ' name="admin_bar_front"';
                                } else {
                                    $field_name = '';
                                }
                                $val = 'true';
                            } else {
                                $wp_key = $key;
                                $wp_class = 'umt ';
                                $field_name = ' name="' . $key . '"';
                            }
                        }
                        echo '<a class="' . $wp_class . $chk . $class . '" title="' . $wp_key . '"><input type="hidden" id="' . $wp_key . '"' . $field_name . ' value="' . $val . '" /> ' . $meta['name'] . '</a> ';
                    } else {
                        // SET THE DEFAULTS
                        if ('true' === $meta['options']['choices']) {
                            $chk = 'on';
                            $val = 'true';
                        } else {
                            $chk = 'off';
                            $val = 'false';
                        }
                        // LET THE USER SAVED VALUE OVERRIDE THE DEFAULTS
                        if (!empty($value)) {
                            if ('true' === $value) {
                                $chk = 'on';
                                $val = 'true';
                            } else {
                                $chk = 'off';
                                $val = 'false';
                            }
                        }
                        echo '<a class="upt ' . $chk . '" title="' . $title . '"><input type="hidden" id="' . $title . '"  name="' . $name . '" value="' . $val . '" /> ' . $meta['name'] . '</a> ';
                    }
                }
            }
            break;
        case 'radio':
            if ('-view' == $action) {
                echo $value;
            } else {
                // IF THIS IS A REFERENCE TO A HELPER, PICK IT UP
                if (!is_array($meta['options']['choices'])) {
                    $option_arr = call_user_func($meta['options']['choices']);
                } else {
                    $option_arr = $meta['options']['choices'];
                }
                echo '<ul>';
                // IF THIS IS AN ASSOCIATIVE ARRAY, CREATE OPTION GROUPS
                foreach ($option_arr as $subkey => $subvalue) {
                    if ('' != $value) {
                        if ($subkey == $value) {
                            $checked = ' checked';
                        } else {
                            $checked = '';
                        }
                    } else {
                        $checked = '';
                    }
                    echo '<li><input ' . $disabled . ' type="radio" name="' . $name . '" value="' . $subkey . '"' . $checked . ' /> ' . $subvalue . '</li>';
                }
                echo '</ul>';
            }
            break;
        case 'group':
            // THIS IS A PASS THROUGH FOR ANY SANITIZED POST VALS
            $child_vals = array();
            if (isset($value) && is_array($value) && !empty($value)) {
                $child_vals = $value;
            }
            if ('-view' == $action) {
                foreach ($meta['options']['choices'] as $gkey => $gvalue) {
                    // GET THE OPTION
                    $gmeta = get_option($gvalue);
                    $grouped_hide = bbconnect_hide_meta(array('meta' => $gmeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                    if ($grouped_hide) {
                        continue;
                    }
                    $post_val = false;
                    if (isset($child_vals[$gmeta['meta_key']])) {
                        $post_val = $child_vals[$gmeta['meta_key']];
                    }
                    bbconnect_get_field(array('meta' => $gmeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                }
            } else {
                $group_hide = bbconnect_hide_meta(array('meta' => $meta, 'group_override' => true, 'bbconnect_cap' => $capabilities, 'action' => $action));
                if (false == $group_hide) {
                    ?>
                    <li>
                        <div class="t-wrapper group">
                            <p class="t-trigger-wrapper group">
                                <span class="bbconnect-label group">
                                    <span class="t-trigger group" title="<?php 
                    echo $id . $action;
                    ?>
">
                                        <?php 
                    echo $meta['name'];
                    ?>
                                    </span>
                                </span>
                                <span class="bbconnect-field">
                                <?php 
                    // LET PLUGINS EXTEND GROUPS
                    do_action('bbconnect_group_markers', $meta, $cid, $action);
                    ?>
                                </span>
                            </p>
                            <div id="<?php 
                    echo $id . $action;
                    ?>
" class="t-panel">
                                <ul class="group-panel">
                                <?php 
                    foreach ($meta['options']['choices'] as $gkey => $gvalue) {
                        // GET THE OPTION
                        $gmeta = bbconnect_get_option($gvalue);
                        $grouped_hide = bbconnect_hide_meta(array('meta' => $gmeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                        if ($grouped_hide) {
                            continue;
                        }
                        $post_val = false;
                        if (isset($child_vals[$gmeta['meta_key']])) {
                            $post_val = $child_vals[$gmeta['meta_key']];
                        }
                        bbconnect_get_field(array('meta' => $gmeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                    }
                    ?>
                                </ul>
                            </div>
                        </div>
                    </li>
                <?php 
                } else {
                    foreach ($meta['options']['choices'] as $gkey => $gvalue) {
                        // GET THE OPTION
                        $gmeta = bbconnect_get_option($gvalue);
                        $grouped_hide = bbconnect_hide_meta(array('meta' => $gmeta, 'bbconnect_cap' => $capabilities, 'action' => $action));
                        if ($grouped_hide) {
                            continue;
                        }
                        $post_val = false;
                        if (isset($child_vals[$gmeta['meta_key']])) {
                            $post_val = $child_vals[$gmeta['meta_key']];
                        }
                        bbconnect_get_field(array('meta' => $gmeta, 'id' => $cid, 'action' => $action, 'type' => $type, 'post_val' => $post_val));
                    }
                }
            }
            break;
        case 'multitext':
            if ('-view' == $action) {
                $fdisplay = array();
                if (is_array($value)) {
                    foreach ($value as $fkey => $fval) {
                        if (is_array($fval)) {
                            $fdisplay[] = '<strong>' . $fval['type'] . ':</strong> ' . $fval['value'];
                        }
                    }
                }
                echo implode(', ', $fdisplay);
            } else {
                echo '<ul id="' . $id . '">';
                //if ( is_array( $value ) && count( $value ) > 1 ) {
                // IF WE'RE JUST STARTING OUT WITH DATA, PREFILL THE VALUE ARRAY WITH NULLITY
                if (!is_array($value) || empty($value)) {
                    $value = array();
                    // GO WITH OVERRIDES FIRST
                    if (isset($meta['options']['add_fields']) && is_array($meta['options']['add_fields'])) {
                        foreach ($meta['options']['add_fields'] as $k => $v) {
                            $value[0][$k] = '';
                        }
                    }
                    $value[0]['value'] = '';
                    if (is_array($meta['options']['choices']) && !empty($meta['options']['choices'])) {
                        $value[0]['type'] = '';
                    }
                }
                /*
                $single_val = '';
                foreach( $value as $fkey => $fval ) {
                    $single_val .= $value[$fkey]['value'];
                }
                */
                $arrcount = count($value);
                $nfkey = 0;
                $key_type = '';
                // COUNT THE FIELDS AVAILABLE
                $add_fields = false;
                $field_ct = 1;
                if (isset($meta['options']['add_fields']) && is_array($meta['options']['add_fields'])) {
                    $add_fields = true;
                    $field_ct = 1 + count($meta['options']['add_fields']);
                }
                $fper = round(52 / $field_ct);
                foreach ($value as $fkey => $fval) {
                    // CREATE THE TYPE FROM THE OPTION
                    // OPTIONALLY BYPASS THIS
                    if (is_array($meta['options']['choices'])) {
                        $arr_choices = array_filter($meta['options']['choices']);
                        if (!empty($arr_choices)) {
                            $key_type = '<select name="' . $name . '[' . $nfkey . '][type]" id="' . $id . '-' . $fkey . '-select">';
                            $key_type .= '<option value="">...</option>';
                            foreach ($meta['options']['choices'] as $typekey => $typeval) {
                                $key_type .= '<option value="' . $typekey . '"';
                                if (isset($value[$fkey]['type'])) {
                                    $key_type .= selected($value[$fkey]['type'], $typekey, false);
                                }
                                $key_type .= '>' . $typeval . '</option>';
                            }
                            $key_type .= '</select>';
                        }
                    }
                    if (false != $add_fields) {
                        $add_fields = '';
                        foreach ($meta['options']['add_fields'] as $k => $v) {
                            if (isset($value[$fkey][$k])) {
                                $ctv = $value[$fkey][$k];
                            } else {
                                $ctv = '';
                            }
                            $add_name = $v['name'];
                            if ('text' == $v['type']) {
                                if (isset($v['class'])) {
                                    $tempclass = $class . ' ' . implode(' ', $v['class']);
                                }
                                $add_fields .= '<input type="text" name="' . $name . '[' . $nfkey . '][' . $k . ']" class="regular-text regular-multi' . $tempclass . '" style="width: ' . $fper . '%;" value="' . $ctv . '" placeholder="' . $add_name . '" /> ';
                            } else {
                                if ('checkbox' == $v['type']) {
                                    $chk = '';
                                    if ('true' == $ctv) {
                                        $chk = 'on';
                                    }
                                    $add_fields .= '<a class="upt ' . $chk . '" title="' . $k . '-' . $nfkey . '"><input type="hidden" id="' . $k . '-' . $nfkey . '"  name="' . $name . '[' . $nfkey . '][' . $k . ']" value="' . $ctv . '" /> ' . $add_name . '</a> ';
                                }
                            }
                        }
                    }
                    ?>
                        <li id="<?php 
                    echo $id . '' . $fkey;
                    ?>
" class="multilist">
                            <?php 
                    /*<span class="handle"></span>*/
                    ?>
                            <span>
                                <?php 
                    echo $add_fields;
                    ?>
                                <input type="text" name="<?php 
                    echo $name . '[' . $nfkey . '][value]';
                    ?>
" class="regular-text regular-multi<?php 
                    echo $class;
                    ?>
" style="width: <?php 
                    echo $fper;
                    ?>
%;" value="<?php 
                    echo $value[$fkey]['value'];
                    ?>
" placeholder="<?php 
                    _e('Value', 'bbconnect');
                    ?>
" />
                                <?php 
                    echo $key_type;
                    ?>
                            </span>
                            <?php 
                    if ($arrcount == 1) {
                        ?>
                                <a id="<?php 
                        echo $id . '' . $nfkey;
                        ?>
-sub" class="sub" title="<?php 
                        echo $nfkey;
                        ?>
" style="display:none;">&nbsp;</a>
                                <a id="<?php 
                        echo $id . '' . $nfkey;
                        ?>
-add" class="add" title="<?php 
                        echo $nfkey;
                        ?>
">&nbsp;</a>
                            <?php 
                    } else {
                        if ($nfkey == $arrcount - 1) {
                            ?>
                                <a id="<?php 
                            echo $id . '' . $nfkey;
                            ?>
-sub" class="sub" title="<?php 
                            echo $nfkey;
                            ?>
">&nbsp;</a>
                                <a id="<?php 
                            echo $id . '' . $nfkey;
                            ?>
-add" class="add" title="<?php 
                            echo $nfkey;
                            ?>
">&nbsp;</a>
                            <?php 
                        } elseif ($nfkey == 0) {
                            ?>
                                <a id="<?php 
                            echo $id . '' . $nfkey;
                            ?>
-sub" class="sub" title="<?php 
                            echo $nfkey;
                            ?>
" style="display:none;">&nbsp;</a>
                            <?php 
                        } else {
                            ?>
                                <a class="sub" title="<?php 
                            echo $nfkey;
                            ?>
">&nbsp;</a>
                            <?php 
                        }
                    }
                    ?>
                        </li>
                    <?php 
                    $nfkey++;
                }
                /*
                } else {
                    if ( !is_array( $value ) ) {
                        $value = array();
                    }
                    $single_val = '';
                    foreach( $value as $fkey => $fval ) {
                        $single_val .= $value[$fkey]['value'];
                    }
                    if ( !isset( $fkey ) ) {
                        $fkey = 0;
                    }
                
                
                    // CREATE THE TYPE FROM THE OPTION
                    // OPTIONALLY BYPASS THIS
                    if ( isset( $meta['options']['single_value'] ) ) {
                        $key_type = '';
                    } else {
                        $key_type = '<select name="'.$name.'[0][type]">';
                        $key_type .= '<option value="">...</option>';
                        foreach ( $meta['options']['choices'] as $typekey => $typeval ) {
                            if ( is_array( $value ) && array_key_exists( $fkey, $value ) && isset( $value[$fkey]['type'] ) ) {
                                $key_type .= '<option value="'.$typekey.'"'. selected( $value[$fkey]['type'], $typekey, false ) . '>'.$typeval.'</option>';
                            } else {
                                $key_type .= '<option value="'.$typekey.'">'.$typeval.'</option>';
                            }
                        }
                        $key_type .= '</select>';
                    }
                
                    if ( isset( $meta['options']['double_value'] ) ) {
                        $dbl = '<input type="text" name="' . $name . '[0][label]" class="regular-text regular-multi' . $class . '" value="' . $value[$fkey]['label'] . '" /> ';
                    } else {
                        $dbl = false;
                    }
                    ?>
                    <li id="<?php echo $id .''. $fkey; ?>" class="multilist"><span><?php echo $dbl; ?><input type="text" name="<?php echo $name . '[0][value]'; ?>" class="regular-text regular-multi<?php echo $class; ?>" value="<?php echo $single_val; ?>" /> <?php echo $key_type; ?></span> <a id="<?php echo $id .''. $fkey; ?>-sub" class="sub" title="<?php echo $fkey; ?>" style="display:none;">&nbsp;</a> <a id="<?php echo $id .''. $fkey; ?>-add" class="add" title="0">&nbsp;</a></li>
                    <?php
                }
                */
                echo '</ul>';
            }
            break;
        case 'password':
            if ('-view' != $action) {
                echo '<ul>';
                $choices = $meta['options']['choices'];
                if ('wpr' == $meta['source']) {
                    ?>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $key . $choices[0];
                    ?>
" id="<?php 
                    echo $key . $choices[0] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('type password', 'bbconnect');
                    ?>
</li>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $key . $choices[1];
                    ?>
" id="<?php 
                    echo $key . $choices[1] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('re-type password', 'bbconnect');
                    ?>
</li>
                    <?php 
                } else {
                    ?>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $name;
                    ?>
[<?php 
                    echo $choices[0];
                    ?>
]" id="<?php 
                    echo $key . $choices[0] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('type password', 'bbconnect');
                    ?>
</li>
                    <li><input type="password" autocomplete="off" name="<?php 
                    echo $name;
                    ?>
[<?php 
                    echo $choices[1];
                    ?>
]" id="<?php 
                    echo $key . $choices[1] . $action;
                    ?>
" class="regular-text<?php 
                    echo $class;
                    ?>
" value="" /> <?php 
                    _e('re-type password', 'bbconnect');
                    ?>
</li>
                    <?php 
                }
                echo '</ul>';
            }
            break;
        case 'date':
            if ('wpr' == $meta['source']) {
                if ('-search' == $action) {
                } else {
                    if (isset($flag) && 'normalize' == $flag) {
                    } else {
                        $name = $key;
                    }
                }
            }
            if (is_array($value)) {
                $vds = $value[0];
                $vde = $value[1];
            } else {
                $vds = false;
                $vde = false;
                if ($disabled && !empty($value)) {
                    $value = date('d F Y', strtotime($value));
                }
            }
            if (!empty($vds) && is_real_date($vds) && $disabled) {
                $vds = date('d F Y', strtotime($vds));
            }
            if (!empty($vde) && is_real_date($vde) && $disabled) {
                $vde = date('d F Y', strtotime($vde));
            }
            if ('-search' == $action) {
                echo '<input ' . $disabled . ' type="text" name="' . $name . '[]" id="' . $id . '_start" placeholder="' . __('start', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $vds . '" />';
                echo '<input ' . $disabled . ' type="text" name="' . $name . '[]" id="' . $id . '_end" placeholder="' . __('end', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $vde . '" />';
            } else {
                echo '<input ' . $disabled . ' type="text" name="' . $name . '" id="' . $id . '" class="regular-text bbconnect-date' . $class . '" value="' . $value . '" />';
            }
            break;
        case 'plugin':
            $args = array();
            if ('user' == $type) {
                $args['fdata'] = get_userdata($cid);
            } else {
                if ('option' == $type) {
                    $args['fdata'] = $meta;
                } else {
                    if ('post' == $type) {
                        $args['fdata'] = array('id' => $id, 'name' => $name, 'class' => $class);
                    }
                }
            }
            $args['fvalue'] = $value;
            $args['faction'] = $action;
            $args['ftype'] = $type;
            $func = $meta['options']['choices'];
            call_user_func($func, $args);
            break;
        case 'number':
        case 'text':
        case 'hidden':
            // IF THIS IS A WORDPRESS USER FIELD, MAKE SOME SMALL MODIFICATIONS
            if ('wpr' == $meta['source']) {
                if (!empty($value) && is_object($value)) {
                    if ('email' == $key || 'url' == $key) {
                        $user_key = 'user_' . $key;
                    } else {
                        $user_key = $key;
                    }
                    $value = $value->{$user_key};
                    if ('user_registered' == $key && !empty($value)) {
                        $value = date(get_option('date_format'), strtotime($value));
                    }
                }
                if ('-search' == $action) {
                } else {
                    if (isset($flag) && 'normalize' == $flag) {
                    } else {
                        $name = $key;
                    }
                }
                if ('-search' != $action) {
                    if ('user_login' == $key && !empty($value)) {
                        $disabled = ' disabled';
                    }
                    if ('ID' == $key && !empty($value)) {
                        $disabled = ' disabled';
                    }
                    if ('user_registered' == $key && !empty($value)) {
                        $disabled = ' disabled';
                    }
                }
            }
            // ALLOW OPTIONS TO HAVE SOME PRESETS
            if (empty($value) && !empty($meta['options']['choices'])) {
                $value = $meta['options']['choices'];
            }
            $field_type = $meta['options']['field_type'];
            $attr = '';
            if ($field_type == 'number') {
                $align = 'right';
                if ($meta['options']['is_currency'] && $value != '' && $disabled) {
                    $field_type = 'text';
                    $value = '$' . number_format($value, 2);
                }
                $step = $meta['options']['is_currency'] ? '0.01' : '1';
                $attr = ' step="' . $step . '"';
            } else {
                $align = 'left';
            }
            if ('-view' == $action) {
                if ('email' == $key) {
                    echo '<a href="mailto:' . $value . '">' . $value . '</a>';
                } else {
                    if ('url' == $key) {
                        echo '<a href="' . $value . '">' . $value . '</a>';
                    } else {
                        echo $value;
                    }
                }
            } else {
                if ($meta['options']['field_type'] != 'text') {
                    echo '<input type="' . $field_type . '" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value="' . $value . '" style="text-align: ' . $align . ';" ' . $disabled . ' ' . $attr . '>';
                } else {
                    if ('-search' == $action && 'user_registered' == $key) {
                        if (is_array($value)) {
                            $vs = $value[0];
                            $ve = $value[1];
                        } else {
                            $vs = false;
                            $ve = false;
                        }
                        echo '<input type="text" name="' . $name . '[]" id="' . $id . '_start" placeholder="' . __('start', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $vs . '" />';
                        echo '<input type="text" name="' . $name . '[]" id="' . $id . '_end" placeholder="' . __('end', 'bbconnect') . '" class="regular-text bbconnect-date' . $class . '" value="' . $ve . '" />';
                    } else {
                        if ('-search' == $action && 'ID' == $key) {
                            echo '<input type="text" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value="' . $value . '"' . $disabled . ' />';
                        } else {
                            if ('user_registered' == $key || 'ID' == $key) {
                                echo $value . '<br />';
                                if ('ID' == $key) {
                                    echo implode('<br />', apply_filters('bbconnect_user_id_assets', array(), $value, $action));
                                }
                            } else {
                                if ('-search' == $action && is_array($value)) {
                                    echo '<input type="text" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value=""' . $disabled . ' />';
                                } else {
                                    echo '<input type="text" name="' . $name . '" id="' . $id . '" class="regular-text' . $class . '" value="' . $value . '"' . $disabled . ' />';
                                }
                            }
                        }
                    }
                }
            }
            break;
            // EXTEND THE FIELD SYSTEM
        // EXTEND THE FIELD SYSTEM
        default:
            do_action('bbconnect_field_switch', $meta, $args);
            break;
    }
}
Exemplo n.º 9
0
function bbconnect_show_form($args = null)
{
    // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED
    $defaults = array('pid' => false, 'show_msg' => true, 'show_notify' => true, 'show_links' => true, 'column_1' => array(), 'column_2' => array());
    // PARSE THE INCOMING ARGS
    $args = wp_parse_args($args, $defaults);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    $option = '';
    $delete = __('Delete this field', 'bbconnect');
    $undo = __('Undo', 'bbconnect');
    if (false == $pid) {
        return false;
    }
    $option = '_bbconnect_form_' . $pid;
    $form = get_option($option);
    $forms = get_option('_bbconnect_user_forms');
    $form_name = $forms[$pid];
    ?>
	
	<div id="form-data">
	<?php 
    if (false != $show_msg) {
        ?>
		<div class="options-field">
			<h3><?php 
        _e('Messages', 'bbconnect');
        ?>
</h3>
			<p><?php 
        printf(__('Add a %1$sgreeting%2$s or instructions to the form.', 'bbconnect'), '<strong>', '</strong>');
        ?>
</p>
			<textarea style="height: 100px;" name="_bbc_option[<?php 
        echo $option;
        ?>
][msg]"><?php 
        if (isset($form['msg'])) {
            echo bbconnect_scrub('bbconnect_esc_html', $form['msg']);
        }
        ?>
</textarea>
			
			<p><?php 
        printf(__('Add a %1$sthank you%2$s or instructions to the form.', 'bbconnect'), '<strong>', '</strong>');
        ?>
</p>
			<textarea style="height: 100px;" name="_bbc_option[<?php 
        echo $option;
        ?>
][confirm]"><?php 
        if (isset($form['confirm'])) {
            echo bbconnect_scrub('bbconnect_esc_html', $form['confirm']);
        }
        ?>
</textarea>
		</div>
	<?php 
    }
    ?>
	
	<?php 
    if (false != $show_notify) {
        $fields = bbconnect_form_notify($form_name);
        echo '<div class="options-field">';
        echo '<h3>' . __('Notifications', 'bbconnect') . '</h3>';
        echo '<ul>';
        foreach ($fields as $field) {
            $args['meta'] = $field['meta'];
            $args['type'] = 'option';
            $args['action'] = 'edit';
            $args['swap_name'] = array($option);
            if (is_array($form) && isset($form[$field['meta']['meta_key']])) {
                $args['post_val'] = $form[$field['meta']['meta_key']];
            } else {
                $args['post_val'] = false;
            }
            bbconnect_get_field($args);
        }
        echo '</ul>';
        echo '</div>';
    }
    /*	
    	?>
    		<div class="options-field">
    			<h3><?php _e( 'Notifications', 'bbconnect' ); ?></h3>
    			<p><?php printf( __( 'Decide which email addresses should be %1$snotified%2$s after the form is submitted. Multiple emails should be separated by commas.', 'bbconnect' ), '<strong>', '</strong>' ); ?></p>
    			<p><input type="text" class="regular-text" name="_bbc_option[<?php echo $option; ?>][notify]" value="<?php if ( isset( $form['notify'] ) ) { echo bbconnect_scrub( 'bbconnect_esc_html', $form['notify'] ); } else { echo get_option( 'admin_email' ); } ?>" /></p>
    			
    			<p><?php printf( __( 'Set the default %1$ssubject%2$s', 'bbconnect' ), '<strong>', '</strong>.' ); ?></p>
    			<p><input type="text" class="regular-text" name="_bbc_option[<?php echo $option; ?>][subject]" value="<?php if ( isset( $form['subject'] ) ) { echo bbconnect_scrub( 'bbconnect_esc_html', $form['subject'] ); } else { printf( __( '%1$s Submission', 'bbconnect' ), $form_name ); } ?>" /></p>
    		</div>
    	<?php } */
    ?>
	
		<div class="options-field">
			<h3><?php 
    _e('Add fields', 'bbconnect');
    ?>
</h3>
			<?php 
    bbconnect_user_data_select(array('id' => 'form-field-select', 's_context' => 'form_api', 'address_unlock' => true));
    ?>
 
			<a class="button" id="add-form-field" rel="form-field-select"><?php 
    _e('+ Add Field', 'bbconnect');
    ?>
</a>
		</div>
		
		<div class="options-field">
			<div class="inside t-panel" style="display: block;">

			<?php 
    // IF IT'S A SYSTEM-GENERATED FORM
    if ('bbconnect' == $form['source'] || false !== strpos($pid, 'default')) {
        echo '<input type="hidden" name="_bbc_option[' . $option . '][source]" value="bbconnect" />';
    } else {
        echo '<input type="hidden" name="_bbc_option[' . $option . '][source]" value="user" /></div>';
    }
    // PULL THE SPECIAL FORM FIELDS
    $form_fields = bbconnect_form_api_fields();
    ?>
				<div id="column_1_holder">
					<ul id="column_1" title="<?php 
    echo $option;
    ?>
" class="forms-sortable connected-forms-sortable primary-list column">
					<?php 
    // LOOP THROUGH ALL OF THE FIELDS REGISTERED WITH THE SYSTEM
    // RETRIEVE THEIR VALUES FOR DISPLAY
    // IF IT'S A GROUP, MAKE A SUBLIST
    // WE'LL USE DRAG & DROP FOR SORTING
    if (isset($form['column_1']) && !empty($form['column_1'])) {
        $column_1 = $form['column_1'];
    }
    foreach ($column_1 as $key => $value) {
        if (isset($form_fields[$value])) {
            $val_title = esc_attr($form_fields[$value]['name']);
        } else {
            $val_arr = bbconnect_get_option($value);
            $val_title = esc_attr($val_arr['name']);
        }
        ?>
						<li>
							<div class="t-wrapper">
								<div class="t-title">
									<span><?php 
        echo $val_title;
        ?>
</span>
									<span class="right">
										<a class="delete" rel="<?php 
        echo $key;
        ?>
" title="<?php 
        echo $delete;
        ?>
">&nbsp;</a>
										<a class="undo" rel="<?php 
        echo $key;
        ?>
" title="<?php 
        echo $undo;
        ?>
">&nbsp;</a>
									</span>
									<input class="column-input" type="hidden" id="<?php 
        echo $key;
        ?>
" name="_bbc_option[<?php 
        echo $option;
        ?>
][column_1][]" value="<?php 
        echo $value;
        ?>
" />
								</div>
							</div>
						</li>
						<?php 
    }
    ?>
					</ul>
				</div>
				
				<div id="column_2_holder">
					<ul id="column_2" title="<?php 
    echo $option;
    ?>
" class="forms-sortable connected-forms-sortable primary-list column">
					<?php 
    if (isset($form['column_2']) && !empty($form['column_2'])) {
        $column_2 = $form['column_2'];
    }
    foreach ($column_2 as $key => $value) {
        if (isset($form_fields[$value])) {
            $val_title = esc_attr($form_fields[$value]['name']);
        } else {
            $val_arr = bbconnect_get_option($value);
            $val_title = esc_attr($val_arr['name']);
        }
        ?>
						<li>
							<div class="t-wrapper">
								<div class="t-title">
									<span><?php 
        echo $val_title;
        ?>
</span>
									<span class="right">
										<a class="delete" rel="<?php 
        echo $key;
        ?>
" title="<?php 
        echo $delete;
        ?>
">&nbsp;</a>
										<a class="undo" rel="<?php 
        echo $key;
        ?>
" title="<?php 
        echo undo;
        ?>
">&nbsp;</a>
									</span>
									<input class="column-input" type="hidden" id="<?php 
        echo $key;
        ?>
" name="_bbc_option[<?php 
        echo $option;
        ?>
][column_2][]" value="<?php 
        echo $value;
        ?>
" />
								</div>
							</div>
						</li>
						<?php 
    }
    ?>
					</ul>
				</div>
			</div>
		</div>
		
		<?php 
    if (false != $show_links) {
        ?>
			<div class="options-field">
				<h3><?php 
        _e('Display this form', 'bbconnect');
        ?>
</h3>
				<?php 
        echo '<p>' . sprintf(__('Use the link, shortcode or menu options below to link to this form. You can replace %1$s with your own text.', 'bbconnect'), '<strong>' . $form_name . '</strong>') . '</p>';
        echo '<p class="code-help"><strong>' . __('Embed Shortcode (embeds the form. make sure you have turned on form embedding on the panels tab)', 'bbconnect') . '</strong><br /><textarea readonly class="fin-btn">[bbconnectf id="' . $pid . '"]</textarea></p>';
        echo '<p class="code-help"><strong>' . __('Link Shortcode (generates a link)', 'bbconnect') . '</strong><br /><textarea readonly class="fin-btn">[ppf_link id="' . $pid . '" text="' . $form_name . '"]</textarea></p>';
        echo '<p class="code-help"><strong>' . __('Local Link', 'bbconnect') . '</strong><br /><textarea readonly class="fin-btn">' . htmlentities('<a class="bbconnectpanels-toggle" title="' . $pid . '" href="' . home_url() . '/bbconnect/?rel=contact&amp;bbc_form=' . $pid . '">') . $form_name . htmlentities('</a>') . '</textarea></p>';
        $bbconnectref = urlencode(serialize(array('rel' => 'contact', 'bbc_form' => $pid)));
        echo '<p class="code-help"><strong>' . __('Direct Link', 'bbconnect') . '</strong><br /><textarea readonly class="fin-btn">' . home_url() . '?bbconnectref=' . $bbconnectref . '</textarea></p>';
        bbconnect_add_to_nav_menu($form_name, $pid, '/bbconnect/?rel=contact&amp;bbc_form=' . $pid);
        ?>
		
			</div>
		<?php 
    }
    ?>
		
		<?php 
    // IF IT'S A SYSTEM-GENERATED FORM
    if (isset($form['source']) && 'bbconnect' != $form['source']) {
        if (false === strpos($pid, 'default')) {
            ?>
		<div class="options-field">
			<h3><?php 
            _e('Delete this form', 'bbconnect');
            ?>
</h3>
			<div class="tright inside"><a class="button" id="delete-form" rel="<?php 
            echo $pid;
            ?>
"><?php 
            _e('Delete This Form', 'bbconnect');
            ?>
</a></div>
		</div>
		<?php 
        }
    }
    ?>
			
		<?php 
    do_action('bbconnect_form_ext_msg', $pid);
    ?>
			
	</div>
		
	
	<script type="text/javascript">
		jQuery.noConflict();
		jQuery(document).ready(function(){
			jQuery('#wpfooter').hide();
			jQuery('#show-form').on('click', '.delete', function(){
				jQuery(this).closest('li').remove();
			});
			// SORTING FUNCTION FOR LISTS
			jQuery(function() {
				jQuery('.forms-sortable').sortable({
					connectWith: '.connected-forms-sortable', 
					appendTo: document.body, 
					placeholder: 'pp-ui-highlight', 
					forcePlaceholderSize: true, 
					forceHelperSize: true,  
					update: function(event, ui) { 
						var cid = jQuery(this).attr('id');
						var oid = jQuery(this).attr('title');
						var fid = ui.item.attr('id');
						ui.item.find('.column-input').attr('name','_bbc_option['+oid+']['+cid+'][]');
					}
				}).disableSelection();
			});
			jQuery('#add-form-field').click(function(){
				//var cref = jQuery(this).previous('select');
				var fid = jQuery('#show-form select').val();
				var fna = jQuery('#show-form select option:selected').text();
				jQuery('<li><div class="t-wrapper"><div class="t-title">'+fna+'<span></span><span class="right"><a class="delete" rel="'+fid+'" title="<?php 
    echo $delete;
    ?>
">&nbsp;</a><a class="undo" rel="'+fid+'" title="<?php 
    echo $undo;
    ?>
">&nbsp;</a></span><input class="column-input" type="hidden" id="'+fid+'" name="_bbc_option[<?php 
    echo $option;
    ?>
][column_1][]" value="'+fid+'" /></div></div></li>').appendTo('#column_1');
				return false;
			});
		});
	</script>
	<?php 
}