예제 #1
0
function ausers_get_option($option)
{
    // allows user reports to be run either at site level and/or at blog level
    global $ausersadminurl, $amr_nicenames;
    if (amr_is_network_admin()) {
        $result = get_site_option('network_' . $option);
    } else {
        $result = get_option($option);
    }
    if (empty($result)) {
        // it's new, get defaults
        //if ($option == 'amr-users-no-lists' ) 	return ameta_default_main(); // old - leave for upgrade check
        if ($option == 'amr-users-main') {
            // and it's empty
            //-------------------------
            //if (WP_DEBUG) echo '<br />Renaming stored option "amr-users-no-lists" to "amr-users-main" ';
            $amain = get_site_option('amr-users-no-lists');
            // might return default ok, if not will have done upgrade check
            if (empty($amain)) {
                $amain = ausers_get_option('amr-users-no-lists');
                if (empty($amain)) {
                    $amain = ameta_default_main();
                }
            }
            $amain['version'] = AUSERS_VERSION;
            ausers_update_option('amr-users-main', $amain);
            ausers_delete_option('amr-users-no-lists');
            return $amain;
            //-------------------------
        }
        if ($option == 'amr-users') {
            return ameta_default_list_options();
        }
        if ($option == 'amr-users-nicenames-excluded') {
            return array('attachment_count' => true, 'activation_key' => true, 'dismissed_wp_pointers' => true, 'default_password_nag' => true, 'nav_menu_item_count' => true, 'revision_count' => true, 'comment_count' => true, 'show_admin_bar_front' => true, 'show_welcome_panel' => true, 'user_activation_key' => true, 'user_status' => true, 'yim' => true, 'aim' => true, 'jabber' => true, 'reply_count' => true, 'topic_count' => true, 'forum_count' => true, 'use_ssl' => true);
        }
        if ($option == 'amr-users-original-keys') {
            return array();
        }
        if ($option == 'amr-users-custom-headings') {
            return array();
        }
        if ($option == 'amr-users-prefixes-in-use') {
            return array();
        }
        if ($option == 'amr-users-nicenames') {
            $amr_nicenames = ameta_defaultnicenames();
        }
    }
    return $result;
}
function amr_meta_handle_export()
{
    if (isset($_POST['export-list']) and isset($_POST['export-list-text'])) {
        check_admin_referer('amr-meta', 'amr-meta');
        $filename = sanitize_title(get_bloginfo('name')) . "-amr-users-list.txt";
        if (amr_is_network_admin()) {
            $filename = 'network-' . $filename;
        }
        $content = htmlspecialchars_decode($_POST['export-list-text']);
        header("Content-Description: File Transfer");
        header("Content-type: application/txt");
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        header("Pragma: no-cache");
        header("Expires: 0");
        echo $content;
        die;
    }
}
예제 #3
0
function amr_to_csv($csv, $suffix)
{
    /* create a csv file for download */
    if (!isset($suffix)) {
        $suffix = 'csv';
    }
    $file = 'userlist-' . date('Ymd_Hi') . '.' . $suffix;
    if (amr_is_network_admin()) {
        $file = 'network_' . $file;
    }
    header("Content-Description: File Transfer");
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename={$file}");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $csv;
    exit(0);
    /* Terminate the current script sucessfully */
}
function ameta_cachetable_name()
{
    global $wpdb;
    global $table_prefix;
    if (is_network_admin() or amr_is_network_admin()) {
        $table_name = $wpdb->base_prefix . "network_amr_reportcache";
    } else {
        $table_name = $wpdb->prefix . "amr_reportcache";
    }
    return $table_name;
}
function amr_about_users()
{
    global $wpdb, $charset_collate;
    global $ausersadminurl;
    if (!defined('WP_DEBUG')) {
        define('WP_DEBUG', true);
    }
    $_REQUEST['mem'] = true;
    // to make track progress work
    register_shutdown_function('amr_shutdown');
    set_time_limit(360);
    // should we make this an option....
    //$time_start = microtime(true);
    echo '<p>';
    _e('Compare the memory limits to the memory stats shown in your cache status', 'amr-users');
    echo '<a href="' . $ausersadminurl . '?page=ameta-admin-cache-settings.php&tab=status' . '"> ' . __('go', 'amr-users') . '</a>';
    echo '</p>';
    echo '<p>';
    _e('If the user and user meta numbers are large, you may experience problems with large lists.', 'amr-users');
    echo '<br /><br />';
    _e('If this happens, try: increasing php memory, clean up users (get rid of the spammy users), clean up usermeta.  You may have records from inactive plugins.', 'amr-users');
    echo '</p>';
    $wpdb->show_errors();
    if (is_multisite() and is_network_admin()) {
        $where = '';
        $wheremeta = '';
        _e('This is a multi-site network.  All users shown here.', 'amr-users');
        echo '<br />';
    } else {
        $where = ' INNER JOIN ' . $wpdb->usermeta . ' am_um ON      ' . $wpdb->users . '.ID = am_um.user_id 
        WHERE   am_um.meta_key =\'' . $wpdb->prefix . 'capabilities\'';
        printf(__('This website with blog_id=%s and prefix=%s has:', 'amr-users'), $GLOBALS['blog_id'], $wpdb->prefix);
        $wheremeta = '';
    }
    echo '<ul>';
    echo '<li>';
    printf(__('Plugin version: %s', 'amr-users'), AUSERS_VERSION);
    echo '</li>';
    echo '<li>';
    printf(__('Php version: %s ', 'amr-users'), phpversion());
    echo '</li>';
    echo '<li>';
    printf(__('Wp version: %s ', 'amr-users'), get_bloginfo('version', 'display'));
    echo '</li>';
    echo '<li>';
    printf(__('Wordpress Memory limit: %s ', 'amr-users'), WP_MEMORY_LIMIT);
    echo '</li>';
    echo '<li>';
    printf(__('Php Memory Limit: %s ', 'amr-users'), ini_get('memory_limit'));
    echo '</li>';
    echo '<li>';
    printf(__('Charset: %s ', 'amr-users'), get_bloginfo('charset', 'display'));
    echo '</li>';
    if (!empty($charset_collate)) {
        echo '<li>';
        printf(__('Collation: %s ', 'amr-users'), $charset_collate);
        echo '</li>';
    }
    //------------------------------------------
    echo '<li>';
    track_progress('Before count users:<br/>');
    $result = count_users();
    printf(__('There are %s total users: ', 'amr-users'), $result['total_users']);
    foreach ($result['avail_roles'] as $role => $count) {
        echo $count . ' ' . $role . ', ';
    }
    echo '<br />';
    track_progress('After count users:<br/>');
    echo '</li>';
    //------------------------------------------
    if (is_multisite()) {
        if (amr_is_network_admin()) {
            $sql = "SELECT count(*) FROM " . $wpdb->blogs;
            $text = __('%d sites', 'amr-users');
            amr_count_sql($sql, $text, '<li>', '</li>');
        } else {
            echo '<li>In multisite, but not in <a href="' . network_admin_url('admin.php?page=amr-users&tab=userdb') . '" >network admin</a></li>.';
        }
    }
    echo '</ul>';
    //------------------------------------------
    if (!empty($where)) {
        // then we already know we are in a sub blog
        $wheremeta = " WHERE " . $wpdb->usermeta . ".user_id IN " . "(SELECT distinct user_id FROM " . $wpdb->usermeta . " WHERE " . $wpdb->usermeta . ".meta_key ='" . $wpdb->prefix . "capabilities')";
    }
    echo '<p><b>' . __('These queries could be slow.  Be patient.  Wait:', 'amr-users') . '</b></p>';
    echo '<input id="submit"  class="button-secondary subsubsub" name="getstats" type="submit" value="';
    _e('Get meta stats', 'amr-users');
    echo '" /> ';
    echo '<input id="submit"  class="button-secondary subsubsub" name="testqueries" type="submit" value="';
    _e('Run user test query', 'amr-users');
    echo '" /> ';
    echo '<input id="submit"  class="button-secondary subsubsub" name="testquerymeta" type="submit" value="';
    _e('Run user meta test query', 'amr-users');
    echo '" />';
    /*echo '<input id="submit"  class="button-secondary subsubsub" name="testwpmetaquery" type="submit" value="';
    		_e('Run wp meta test query', 'amr-users'); 
    		echo '" />';*/
    echo '<br /><br />';
    //------------------------------------------
    if (isset($_REQUEST['getstats'])) {
        echo '<h4>' . __('Meta stats:', 'amr-users') . '</h4>';
        echo '<ul>';
        echo '<li>';
        track_progress('Before meta stats:<br/>');
        /* TOO SLOW		
        		echo '<li>';		
        		$sql = "SELECT COUNT(DISTINCT meta_key) FROM $wpdb->usermeta ".$wheremeta ;  // 97 seconds on 1.1 million records		
        		$total = $wpdb->get_var( $sql );		
        		printf(__('%s different user meta keys.', 'amr-users'),number_format($total,0,'.',',')); 
        		track_progress('After count distinct usermeta:');
        		unset($results);
        		echo '</li>';
        */
        echo '<li>';
        $sql = "SELECT DISTINCT meta_key FROM {$wpdb->usermeta}";
        // uses more mem but faster
        echo '<br /><em>Executing query:<br /> ' . $sql . '</em><br />';
        $results = $wpdb->get_results($sql, ARRAY_A);
        $total = count($results);
        printf(__('%s different user meta keys.', 'amr-users'), number_format($total, 0, '.', ','));
        track_progress('After alternate count distinct usermeta:');
        echo '</li>';
        $sql = "SELECT count(*) FROM {$wpdb->usermeta} " . $wheremeta;
        $text = __('%d user meta records.', 'amr-users');
        echo '<br /><em>Executing query:<br /> ' . $sql . '</em><br />';
        amr_count_sql($sql, $text, '<li>', '</li>');
        echo '</ul>';
        flush();
    }
    //------------------------------------------
    if (isset($_REQUEST['testqueries'])) {
        echo '<hr /><b>' . __('Running some test queries:', 'amr-users') . '</b>';
        $_REQUEST['mem'] = true;
        // to make track progress work
        track_progress('Test full user query memory impact:');
        $sql = "SELECT ID, user_login, user_email, display_name FROM {$wpdb->users}" . $where;
        echo '<br /><em>Executing query:<br /> ' . $sql . '</em><br />';
        $results = $wpdb->get_col($sql, 0);
        echo '<br />Queried all from user master:' . count($results);
        track_progress('After users - how was it?');
    }
    if (isset($_REQUEST['testquerymeta'])) {
        track_progress('Test user meta query:');
        $sql = 'SELECT user_id, meta_key, meta_value ' . " FROM {$wpdb->usermeta} " . $wheremeta . " AND {$wpdb->usermeta}.meta_key " . " in (" . "'first_name', 'last_name', 'nickname', 'description' " . ") ";
        echo '<br /><em>Executing query:<br /> ' . $sql . '</em><br />';
        $results = $wpdb->get_results($sql, ARRAY_A);
        echo '<br />Queried user meta master:' . count($results);
        track_progress('After usermeta - how was it?');
        echo '<hr /><b>' . __('If these queries completed, the "fetch users directly" method should work, even if the "wp_query" method fails.', 'amr-users') . __('See "How to fetch data" in the general settings.', 'amr-users') . '</b>';
    }
    if (isset($_REQUEST['testwpmetaquery'])) {
        // put in request line - just testing for now
        track_progress('Test wp query impact with test query:');
        $parameters = array('role' => 'subscriber', 'fields' => array('ID', 'user_login', 'user_email', 'display_name'));
        $all_users_query = new WP_User_Query($parameters);
        $results = $all_users_query->get_results();
        var_dump($results[1]);
        echo '<br />Queried all from user master:' . count($results);
        track_progress('After users - how was it?');
    }
    echo '<p>' . __('Page complete.  Please note memory and incremental runtimes.', 'amr-users') . '</p>';
}
function ausers_job_prefix()
{
    if (amr_is_network_admin()) {
        return 'network_';
    } else {
        return '';
    }
}