/** * Loads the correct fields for the selected actions under Profile > Actions. * * @since 1.0.0 * @param $data str. The type of action being requested. * @return html. The fields. */ function bbconnect_get_post_to_edit() { if (!wp_verify_nonce($_POST['bbconnect_admin_nonce'], 'bbconnect-admin-nonce')) { die(__('Terribly sorry.', 'bbconnect')); } if (isset($_POST['data'])) { $cid = $_POST['cid']; $type = $_POST['type']; $post_val = array(); global $post; // WE'RE EDITING AN EXISTING FILE if (false !== strpos($_POST['data'], 'edit-')) { $post_id = (int) substr($_POST['data'], 5); $post = get_post($post_id); $post_author = $post->post_author; $post_type = $post->post_type; $action = 'edit'; if ($post_type == 'bb_note') { $note_types = wp_get_post_terms($post_id, 'bb_note_type'); foreach ($note_types as $note_type) { if ($note_type->parent == 0) { $parent_term = $note_type; } else { $child_term = $note_type; } } } } else { if ('user' == $type) { $bbconnect_actions = bbconnect_get_user_actions(); $post_type = 'bb_note'; if (empty($_POST['data'])) { echo ''; die; } } else { $bbconnect_actions = bbconnect_get_post_actions(); $post_type = false; $post_type = $_POST['data']; if (false == $post_type) { echo ''; die; } } $post = get_default_post_to_edit($post_type, true); $post_author = $_POST['uid']; $action = $_POST['actung']; } // SET THE NONCE if ('user' == $type) { bbconnect_user_actions_nonce_field(); } else { bbconnect_post_actions_nonce_field(); } $post_fields = array(array('meta' => array('source' => 'wpr', 'meta_key' => 'post_title', 'name' => __('Title', 'bbconnect'), 'help' => '', 'options' => array('field_type' => 'text', 'req' => true, 'public' => false, 'choices' => false))), array('meta' => array('source' => 'wpr', 'meta_key' => 'post_date', 'name' => __('Date', 'bbconnect'), 'help' => '', 'options' => array('field_type' => 'date', 'req' => true, 'public' => false, 'choices' => false)))); if ('user' == $type) { if (!empty($parent_term)) { // Editing existing note $post_fields[] = array('post_val' => $parent_term->slug, 'meta' => array('source' => 'tax', 'meta_key' => 'bb_note_type_parent', 'name' => __('Type', 'bbconnect'), 'help' => '', 'options' => array('field_type' => 'select', 'req' => true, 'public' => true, 'choices' => array($parent_term->slug => $parent_term->name)))); $post_fields[] = array('post_val' => $child_term->slug, 'meta' => array('source' => 'tax', 'meta_key' => 'bb_note_type', 'name' => __('', 'bbconnect'), 'help' => '', 'options' => array('field_type' => 'select', 'req' => false, 'public' => true, 'choices' => array($child_term->slug => $child_term->name)))); } else { // New note $parent_term = get_term_by('slug', $_POST['data'], 'bb_note_type'); $terms = get_terms('bb_note_type', array('hide_empty' => false, 'parent' => $parent_term->term_id)); $choices = array(); foreach ($terms as $term) { $choices[$term->slug] = $term->name; } $post_fields[] = array('meta' => array('source' => 'tax', 'meta_key' => 'bb_note_type', 'name' => __('Type', 'bbconnect'), 'help' => '', 'options' => array('field_type' => 'select', 'req' => true, 'public' => false, 'choices' => $choices))); $post_fields[] = array('meta' => array('source' => 'tax', 'meta_key' => 'bb_note_type_parent', 'name' => __('', 'bbconnect'), 'help' => '', 'options' => array('field_type' => 'hidden', 'req' => false, 'public' => false, 'choices' => $parent_term->slug))); } } foreach ($post_fields as $field) { $meta_key = $field['meta']['meta_key']; $field['type'] = 'post'; $field['action'] = $action; $field['id'] = $post->ID; $field['swap_name'] = $meta_key; if (isset($post->{$meta_key})) { $field['post_val'] = $post->{$meta_key}; } echo '<p><ul style="display: block; float: none;">'; bbconnect_get_field($field); echo '</ul></p>'; } if ('bulk-edit' == $action) { echo '<ul><li class="meta-item"><span class="bbconnect-label">'; echo '<a class="rui off" title="' . $cid . 'bulk-edit">Enable Text</a>'; echo '</span><span class="bbconnect-field">'; } echo '<div style="width: 90%;padding: .3em;margin: .2em 0;"> </div>'; //echo '<p>'. __( 'Title', 'bbconnect' ) .'<br /><input type="text" name="post_title" class="regular-text" value="'.$post->post_title.'" /></p>'; //echo '<p>'. __( 'Date', 'bbconnect' ) .'<br /><input type="text" class="bbconnect-date" name="post_date" class="regular-text" value="'.$post->post_date.'" /></p>'; if (preg_match('/Firefox/i', $_SERVER['HTTP_USER_AGENT'])) { wp_editor(stripslashes($post->post_content), $cid, array('tinymce' => false, 'textarea_name' => 'post_content', 'teeny' => true, 'quicktags' => true)); } else { wp_editor(stripslashes($post->post_content), $cid, array('tinymce' => true, 'textarea_name' => 'post_content', 'teeny' => false, 'quicktags' => true)); } if ('bulk-edit' == $action) { echo '</span></li></ul>'; } // SET THE META if ('user' == $type) { bbconnect_user_actions_meta_fields(array('post_id' => $post->ID, 'fields' => bbconnect_get_user_actions_meta(), 'action' => $action, 'post_val' => $post_val)); } else { bbconnect_post_actions_meta_fields(array('post_id' => $post->ID, 'fields' => bbconnect_get_post_actions_meta(), 'action' => $action, 'post_val' => $post_val)); } ?> <input type="hidden" name="post_ID" value="<?php echo $post->ID; ?> " /> <input type="hidden" name="post_status" value="publish" /> <input type="hidden" name="post_author" value="<?php echo $post_author; ?> " /> <input type="hidden" name="post_type" value="<?php echo $post_type; ?> " /> <?php $inline_button = apply_filters('bbconnect_inline_do_action_button', array('<input type="submit" class="bbconnect-actions-save button-primary ' . $type . '" name="save" value="' . __('Save', 'bbconnect') . '" />'), $post_type, $type, $action); echo '<div class="tright">'; echo implode(' ', $inline_button); echo '</div>'; } else { echo 'error'; } if ('3.9' <= get_bloginfo('version')) { _WP_Editors::enqueue_scripts(); //print_footer_scripts(); _WP_Editors::editor_js(); echo '<script src="' . admin_url('js/editor.js') . '" />'; } die; }
/** * This is the main function for the BB Connect Options API. * * @since 1.0.2 * * @param str The title for your page. * @param arr The navigation elements. * * @return html outputs the options page with the activated option tab + contents. */ function bbconnect_options_form($form_title, $tabs = array()) { // STOP THEM IF THEY SHOULDN'T BE HERE if (!current_user_can('list_users')) { wp_die(__('You do not have sufficient permissions to access this page.')); } global $notice; if (!empty($notice)) { echo '<p class="bbconnect_notice">' . __('Settings Updated', 'bbconnect') . ': ' . implode(', ', $notice) . '</p>'; } ?> <div id="bbconnect" class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2><?php echo $form_title; ?> </h2> <form enctype="multipart/form-data" action="" method="POST"> <?php $nav_tab = ''; $nav_sel = ''; if (isset($_GET['tab'])) { $active = $_GET['tab']; } else { $active = current(array_keys($tabs)); } foreach ($tabs as $key => $val) { $pre = ''; if (isset($_GET['post_type'])) { $pre .= 'post_type=' . $_GET['post_type'] . '&'; } if ($active == $key) { $act_tab = ' nav-tab-active'; $selected = ' selected="selected"'; } else { $act_tab = ''; $selected = ''; } $nav_sel .= '<option value="?' . $pre . 'page=' . $_GET['page'] . '&tab=' . $key . '"' . $selected . '>' . $val['title'] . '</option>'; $nav_tab .= '<a href="?' . $pre . 'page=' . $_GET['page'] . '&tab=' . $key . '" class="nav-tab' . $act_tab . '">' . $val['title'] . '</a>'; } ?> <h2 class="nav-tab-wrapper non-responsive"><?php echo $nav_tab; ?> </h2> <div class="nav-tab-wrapper responsive"><select class="nav-tab-select"><?php echo $nav_sel; ?> </select></div> <?php // SET THE NONCE wp_nonce_field('bbconnect-nonce'); // DISPLAY ANY SUB NAVIGATION if (!empty($tabs[$active]['subs'])) { $sub_nav = bbconnect_options_sub_nav($active, $tabs[$active]['title'], $tabs[$active]['subs']); echo $sub_nav['nav']; $active = $sub_nav['active']; } // FLUSH THE PERMALINKS IF WE NEED TO DO ANY REWRITES global $bbconnect_flush; if (false != $bbconnect_flush) { flush_rewrite_rules(); } // DO ANY PRE OPTION KINDA THINGS do_action('bbconnect_options_pre', $active); ?> <div class="options-panel"> <div class="options-field"><div class="inside"> <fieldset> <ul> <?php $options = call_user_func($active); if (!empty($options)) { foreach ($options as $setting) { $setting['type'] = 'option'; $setting['action'] = 'edit'; if (isset($append)) { $setting['swap_name'] = $setting['meta']['meta_key'] . '_' . $append; } bbconnect_get_field($setting); } } ?> </ul> </fieldset> </div></div> </div> <?php // DO ANY POST OPTION KINDA THINGS do_action('bbconnect_options_post', $active); ?> <p class="submit"><input type="submit" name="save_options" value="<?php _e('Save Your Options', 'bbconnect '); ?> " class="button-primary" /></p> </form> </div> <?php }
function bbconnect_search_field_manipulation($args = null) { $defaults = array('meta' => false, 'type' => 'search', 'swap_name' => array(), 'action' => 'search', 'query' => false); // PARSE THE INCOMING ARGS $args = wp_parse_args($args, $defaults); // EXTRACT THE VARIABLES extract($args, EXTR_SKIP); if (false == $meta) { return false; } $args = array('meta' => $meta, 'action' => $action, 'type' => $type, 'swap_name' => $swap_name, 'swap_id' => $meta['meta_key'] . '_' . $swap_name[0], 'post_val' => false); if ('multitext' == $meta['options']['field_type'] || 'text' == $meta['options']['field_type']) { $args['meta']['options']['field_type'] = 'text'; if (!empty($query) && is_array($query) && 'user_registered' != $meta['meta_key']) { $args['post_val'] = $query[0]; } else { $args['post_val'] = $query; } } if ('number' == $meta['options']['field_type']) { $args['meta']['options']['field_type'] = 'number'; if (!empty($query) && is_array($query)) { $args['post_val'] = $query[0]; } else { $args['post_val'] = $query; } } if ('radio' == $meta['options']['field_type']) { $args['meta']['options']['field_type'] = 'select'; if (!empty($query)) { $args['post_val'] = $query; } } if ('display_name' == $meta['meta_key']) { $args['meta']['options']['field_type'] = 'text'; if (!empty($query)) { $args['post_val'] = $query; } } if ('textarea' == $meta['options']['field_type']) { $args['meta']['options']['field_type'] = 'text'; if (!empty($query)) { $args['post_val'] = $query; } } if ('taxonomy' == $meta['options']['field_type'] || 'select' == $meta['options']['field_type'] || 'multiselect' == $meta['options']['field_type'] || 'checkbox' == $meta['options']['field_type'] || 'date' == $meta['options']['field_type']) { $args['post_val'] = $query; } bbconnect_get_field($args); }
/** * 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 }
/** * 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; }
/** * Displays the fields captured by post type conscripted as an "action." Utilizes the fields API. * * @since 1.0.0 * * @param none. * * @return array. */ function bbconnect_post_actions_meta_fields($args = null) { // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED $defaults = array('post_id' => false, 'fields' => false, 'action' => 'edit', 'post_val' => array()); // PARSE THE INCOMING ARGS $args = wp_parse_args($args, $defaults); // EXTRACT THE VARIABLES extract($args, EXTR_SKIP); ?> <div class="action-panel"> <div class="action-field"><div class="inside"> <fieldset> <ul class="bbconnect-list"> <?php foreach ($fields as $field) { $meta_key = $field['meta']['meta_key']; $field['type'] = 'post'; $field['action'] = $action; $field['id'] = $post_id; if (isset($post_val[$meta_key])) { $field['post_val'] = $post_val; } bbconnect_get_field($field); } ?> </ul> </fieldset> </div></div> </div> <?php }
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 . '> ' . $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"> <input type="checkbox" name="' . $name . '[]" value="' . $term->term_id . '"' . $checked . ' /> ' . $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 . ' /> ' . $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="">' . __('— No role for this site —') . '</option>'; } else { echo '<option value="" selected="selected">' . __('— No role for this site —') . '</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;"> </a> <a id="<?php echo $id . '' . $nfkey; ?> -add" class="add" title="<?php echo $nfkey; ?> "> </a> <?php } else { if ($nfkey == $arrcount - 1) { ?> <a id="<?php echo $id . '' . $nfkey; ?> -sub" class="sub" title="<?php echo $nfkey; ?> "> </a> <a id="<?php echo $id . '' . $nfkey; ?> -add" class="add" title="<?php echo $nfkey; ?> "> </a> <?php } elseif ($nfkey == 0) { ?> <a id="<?php echo $id . '' . $nfkey; ?> -sub" class="sub" title="<?php echo $nfkey; ?> " style="display:none;"> </a> <?php } else { ?> <a class="sub" title="<?php echo $nfkey; ?> "> </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;"> </a> <a id="<?php echo $id .''. $fkey; ?>-add" class="add" title="0"> </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; } }
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; ?> "> </a> <a class="undo" rel="<?php echo $key; ?> " title="<?php echo $undo; ?> "> </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; ?> "> </a> <a class="undo" rel="<?php echo $key; ?> " title="<?php echo undo; ?> "> </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&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&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; ?> "> </a><a class="undo" rel="'+fid+'" title="<?php echo $undo; ?> "> </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 }