Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 335: Autocomplete not working correctly in Exclude IP Addressees field #345

Merged
merged 9 commits into from
Mar 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 56 additions & 10 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public static function load() {
// Ajax callback function to search users
add_action( 'wp_ajax_stream_get_users', array( __CLASS__, 'get_users' ) );

// Ajax callback function to search IPs
add_action( 'wp_ajax_stream_get_ips', array( __CLASS__, 'get_ips' ) );

}

/**
Expand All @@ -73,17 +76,14 @@ public static function load() {
* @return void
*/
public static function get_users(){
if ( ! defined( 'DOING_AJAX' ) ) {
return;
}
if ( ! current_user_can( WP_Stream_Admin::SETTINGS_CAP ) ) {
if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( WP_Stream_Admin::SETTINGS_CAP ) ) {
return;
}

check_ajax_referer( 'stream_get_users', 'nonce' );

$response = (object) array(
'status' => false,
'status' => false,
'message' => __( 'There was an error in the request', 'stream' ),
);

Expand All @@ -102,6 +102,7 @@ public static function get_users(){
'user_email',
'user_url',
),
'orderby' => 'display_name',
)
);

Expand All @@ -113,20 +114,62 @@ public static function get_users(){

$response->status = true;
$response->message = '';
$response->users = array();

$response->users = array();
foreach ( $users->results as $key => $user ) {
$gravatar_url = null;

if ( preg_match( '# src=[\'" ]([^\'" ]*)#', get_avatar( $user->ID, 16 ), $gravatar_src_match ) ) {
list( $gravatar_src, $gravatar_url ) = $gravatar_src_match;
}

$args = array(
'id' => $user->ID,
'id' => $user->ID,
'text' => $user->display_name,
);

if ( null !== $gravatar_url ) {
$args['icon'] = $gravatar_url;
}

$response->users[] = $args;
}

wp_send_json_success( $response );
}

/**
* Ajax callback function to search IP addresses that is used on exclude setting page
*
* @uses WP_User_Query WordPress User Query class.
* @return void
*/
public static function get_ips(){
if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( WP_Stream_Admin::SETTINGS_CAP ) ) {
return;
}

check_ajax_referer( 'stream_get_ips', 'nonce' );

global $wpdb;

$results = $wpdb->get_col(
$wpdb->prepare(
"
SELECT distinct(`ip`)
FROM `{$wpdb->stream}`
WHERE `ip` LIKE %s
ORDER BY inet_aton(`ip`) ASC
LIMIT %d;
",
like_escape( $_POST['find'] ) . '%',
$_POST['limit']
)
);

wp_send_json_success( $results );
}

/**
* Filter the columns to search in a WP_User_Query search.
*
Expand Down Expand Up @@ -211,7 +254,7 @@ public static function get_fields() {
'name' => 'authors_and_roles',
'title' => __( 'Authors & Roles', 'stream' ),
'type' => 'select2_user_role',
'desc' => __( 'No activity will be logged for these authors and roles.', 'stream' ),
'desc' => __( 'No activity will be logged for these authors and/or roles.', 'stream' ),
'choices' => self::get_roles(),
'default' => array(),
),
Expand Down Expand Up @@ -249,6 +292,7 @@ public static function get_fields() {
'desc' => __( 'No activity will be logged for these IP addresses.', 'stream' ),
'class' => 'ip-addresses',
'default' => array(),
'nonce' => 'stream_get_ips',
),
),
),
Expand Down Expand Up @@ -360,6 +404,7 @@ public static function render_field( $field ) {
$href = isset( $field['href'] ) ? $field['href'] : null;
$after_field = isset( $field['after_field'] ) ? $field['after_field'] : null;
$title = isset( $field['title'] ) ? $field['title'] : null;
$nonce = isset( $field['nonce'] ) ? $field['nonce'] : null;
$current_value = self::$options[ $section . '_' . $name ];

if ( is_callable( $current_value ) ) {
Expand Down Expand Up @@ -495,13 +540,14 @@ public static function render_field( $field ) {
esc_attr( $name )
);
$output .= sprintf(
'<input type="hidden" data-values=\'%1$s\' data-selected=\'%2$s\' value="%3$s" class="select2-select %4$s" data-select-placeholder="%5$s-%6$s-select-placeholder" />',
'<input type="hidden" data-values=\'%1$s\' data-selected=\'%2$s\' value="%3$s" class="select2-select %4$s" data-select-placeholder="%5$s-%6$s-select-placeholder" %7$s />',
esc_attr( json_encode( $data_values ) ),
esc_attr( json_encode( $selected_values ) ),
esc_attr( implode( ',', $current_value ) ),
$class,
esc_attr( $section ),
esc_attr( $name )
esc_attr( $name ),
isset( $nonce ) ? sprintf( ' data-nonce="%s"', esc_attr( wp_create_nonce( $nonce ) ) ) : ''
);
// to store data with default value if nothing is selected
$output .= sprintf(
Expand Down
116 changes: 66 additions & 50 deletions ui/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@
}
}

@media only screen and (max-width: 782px) {
.toplevel_page_wp_stream .tablenav.bottom .displaying-num {
top: -8px;
}
}

@media only screen and (max-width: 900px) {
.toplevel_page_wp_stream .fixed .column-context,
.toplevel_page_wp_stream .fixed .column-action,
Expand Down Expand Up @@ -179,32 +185,74 @@
display: inline;
}

.toplevel_page_wp_stream .date-interval .field-predefined {
.toplevel_page_wp_stream .select2-container {
margin-right: 6px;
margin-bottom: 6px;
}

.toplevel_page_wp_stream .select2-container.select2-allowclear .select2-choice abbr {
margin-top: -2px;
}


/* Live Update */

.toplevel_page_wp_stream .stream-live-update-checkbox .spinner {
margin-top: 5px;
}

.toplevel_page_wp_stream .new-row {
background-color: #ffffe0;

-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-ms-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
}

.toplevel_page_wp_stream .new-row.fadeout {
background-color: transparent;
}


/* Settings */

.stream_page_wp_stream_settings .nav-tab-wrapper a:not(.nav-tab-active) {
border-bottom: 1px solid #ccc;
}


/* Date Interval Common */

.wp_stream_screen .date-interval .field-predefined {
width: 165px;
float: left;
margin-right: 6px;
margin-bottom: 6px;
}

.toplevel_page_wp_stream .date-interval .date-inputs {
.wp_stream_screen .date-interval .date-inputs {
float: left;
margin-right: 6px;
margin-bottom: 6px;
}

.toplevel_page_wp_stream .date-interval .date-inputs .field-to,
.toplevel_page_wp_stream .date-interval .date-inputs .field-from {
.wp_stream_screen .date-interval .date-inputs .field-to,
.wp_stream_screen .date-interval .date-inputs .field-from {
line-height: 28px;
height: 28px;
margin: 0;
width: 125px;
}

.toplevel_page_wp_stream .date-interval .date-inputs .box {
.wp_stream_screen .date-interval .date-inputs .box {
position: relative;
display: block;
float: left;
}

.toplevel_page_wp_stream .date-interval .date-inputs .box .date-remove {
.wp_stream_screen .date-interval .date-inputs .box .date-remove {
display: none;
position: absolute;
cursor: pointer;
Expand All @@ -218,11 +266,11 @@
padding-right: 2px;
}

.toplevel_page_wp_stream .date-interval .date-inputs .box .date-remove:before {
.wp_stream_screen .date-interval .date-inputs .box .date-remove:before {
content: '\f158';
}

.toplevel_page_wp_stream .date-interval .date-inputs .connector {
.wp_stream_screen .date-interval .date-inputs .connector {
display: block;
float: left;
border: 1px solid #ddd;
Expand All @@ -236,59 +284,27 @@
font-size: 14px;
}

.toplevel_page_wp_stream .date-interval .date-inputs .connector:before {
.wp_stream_screen .date-interval .date-inputs .connector:before {
content: '\f345';
}

.toplevel_page_wp_stream .select2-container {
margin-right: 6px;
margin-bottom: 6px;
}

.toplevel_page_wp_stream .select2-results .select2-disabled {
background: transparent;
color: #aaa;
}

.toplevel_page_wp_stream .select2-container.select2-allowclear .select2-choice abbr {
margin-top: -2px;
}

/* Select2 Common */

/* Live Update */

.toplevel_page_wp_stream .stream-live-update-checkbox .spinner {
margin-top: 5px;
}

.toplevel_page_wp_stream .new-row {
background-color: #ffffe0;

-webkit-transition: background 0.5s linear;
-moz-transition: background 0.5s linear;
-ms-transition: background 0.5s linear;
-o-transition: background 0.5s linear;
transition: background 0.5s linear;
}

.toplevel_page_wp_stream .new-row.fadeout {
background-color: transparent;
}


/* Settings */

.stream_page_wp_stream_settings .nav-tab-wrapper a:not(.nav-tab-active) {
border-bottom: 1px solid #ccc;
.wp_stream_screen li.select2-searching {
background: none;
padding: 3px 7px 0;
}


/* Select2 Common */

.wp_stream_screen li.select2-result {
margin-bottom: 1px;
}

.wp_stream_screen .select2-results .select2-disabled {
background: transparent;
color: #aaa;
}

.wp_stream_screen .select2-container.authors_and_roles .select2-search-choice .icon16 {
margin: -6px 1px 0 -3px;
padding: 0;
Expand Down
Loading