/** * 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; }
function bbconnect_minify_admin() { global $post, $pagenow; $minify = false; if ($pagenow == 'post.php' || $pagenow == 'post-new.php') { $bbconnect_user_actions = bbconnect_get_user_actions(); foreach ($bbconnect_user_actions as $key => $value) { $action_types[] = $value['type']; } if (in_array($post->post_type, $action_types)) { $minify = true; } } else { if ('users.php' == $pagenow && isset($_GET['page']) && 'bbconnect_modal_action' == $_GET['page']) { $minify = true; } } if ($minify) { //if ( isset( $_GET['uid'] ) || isset( $_GET['pid'] ) || isset( $_POST['bbconnect_iframe'] ) ) { ?> <script type="text/javascript"> var iframe = (window.location != window.parent.location) ? true : false; if ( iframe ) { jQuery.noConflict(); jQuery('head').append('<style type="text/css" media="screen">html.wp-toolbar { padding-top: 0; } #adminmenuback, #adminmenuwrap, #wphead, #wpfooter, #footer, #wpadminbar, .update-nag { display: none; } #wpcontent, #wpfooter { margin-left: 10px !important; }</style>'); } </script> <?php //} } }
/** * 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 { } }
/** * Swaps the originating author for the targeted user when inserting actions into the db and updates the log. * * @since 1.0.2 * * @param arr $data Required. An array containing the post data. * @param arr $postarr Required. An array containing the submitted data on $_POST. * * @return arr an array of default actions. */ function bbconnect_log_user_action_meta($data, $postarr) { // FIRST, MAKE SURE THAT A SUBMISSION HAS OCCURRED if (isset($postarr['_bbc_post']['_bbc_author'])) { $bbconnect_user_actions = bbconnect_get_user_actions(); // PROCESS THE REGISTERED ACTIONS TO RETRIEVE THE WP POST TYPE $bbconnect_user_action_types = array(); foreach ($bbconnect_user_actions as $key => $value) { $bbconnect_user_action_types[] = $value['type']; } // CHECK TO SEE IF THIS IS A REGISTERED ACTION if (in_array_r($data['post_type'], $bbconnect_user_action_types)) { // IF THE POSTED _bbc_author CONVERSION !MATCHES THE POST_AUTHOR UPDATE IT if ($data['post_author'] != $postarr['_bbc_post']['_bbc_author']) { $data['post_author'] = $postarr['_bbc_post']['_bbc_author']; } // UPDATE THE LOG if (isset($postarr['_bbc_post']['_bbc_agent'])) { $cur_user_arr = array('id' => $postarr['_bbc_post']['_bbc_agent'], 'date' => time()); $cur_log = get_post_meta($postarr['ID'], '_bbc_log', true); if (empty($cur_log)) { $cur_log = array(); } array_push($cur_log, $cur_user_arr); update_post_meta($postarr['ID'], '_bbc_log', $cur_log); } } } return $data; }