コード例 #1
0
function amr_trash_the_cache()
{
    ausers_delete_option('amr-users-cache-status');
    $text = __('Cache status records deleted, try building cache again', 'amr-users');
    $text = $text . '<br/>' . '<a href="">' . __('Return', 'amr-users') . '</a>';
    amr_users_message($text);
}
コード例 #2
0
function amrmeta_validate_overview()
{
    global $amain;
    global $aopt;
    if (isset($_REQUEST['addnew'])) {
        if (count($amain['names']) < 1) {
            $amain['names'][1] = __('New list', 'amr-users');
        } else {
            $amain['names'][] = __('New list', 'amr-users');
        }
        $amain['no-lists'] = count($amain['names']);
    }
    if (isset($_POST['name'])) {
        $return = amrmeta_validate_names();
        if (is_wp_error($return)) {
            echo $return->get_error_message();
        }
    }
    if (isset($_POST['checkedpublic'])) {
        /* admin has seen the message and navigated to the settings screen and saved */
        $amain['checkedpublic'] = true;
    }
    //	unset($amain['public']);
    //	unset($amain['sortable']);
    //	unset($amain['customnav']);
    //
    if (isset($_POST['list_avatar_size'])) {
        if (is_array($_POST['list_avatar_size'])) {
            foreach ($_POST['list_avatar_size'] as $i => $value) {
                $amain['list_avatar_size'][$i] = (int) $value;
            }
        }
    }
    if (isset($_POST['list_rows_per_page'])) {
        if (is_array($_POST['list_rows_per_page'])) {
            foreach ($_POST['list_rows_per_page'] as $i => $value) {
                $amain['list_rows_per_page'][$i] = (int) $value;
            }
        }
    }
    if (isset($_POST['html_type'])) {
        if (is_array($_POST['html_type'])) {
            foreach ($_POST['html_type'] as $i => $value) {
                if (in_array($value, array('table', 'simple'))) {
                    $amain['html_type'][$i] = $value;
                }
            }
        }
    }
    //
    if (isset($_POST['filter_html_type'])) {
        if (is_array($_POST['filter_html_type'])) {
            foreach ($_POST['filter_html_type'] as $i => $value) {
                if (in_array($value, array('intableheader', 'above', 'none'))) {
                    $amain['filter_html_type'][$i] = $value;
                }
            }
        }
    }
    //
    foreach ($amain['names'] as $i => $n) {
        // clear booleans in case not set
        if (!isset($_REQUEST['ulist']) or $_REQUEST['ulist'] == $i) {
            // in case we are only doing 1 list - insingle view
            $amain['show_search'][$i] = false;
            $amain['show_perpage'][$i] = false;
            $amain['show_pagination'][$i] = false;
            $amain['show_headings'][$i] = false;
            $amain['show_csv'][$i] = false;
            $amain['show_refresh'][$i] = false;
            $amain['public'][$i] = false;
            $amain['customnav'][$i] = false;
            $amain['sortable'][$i] = false;
        }
    }
    if (isset($_POST['sortable'])) {
        if (is_array($_POST['sortable'])) {
            foreach ($_POST['sortable'] as $i => $y) {
                $amain['sortable'][$i] = true;
            }
        }
    }
    if (isset($_POST['public'])) {
        if (is_array($_POST['public'])) {
            foreach ($_POST['public'] as $i => $y) {
                $amain['public'][$i] = true;
            }
        }
    }
    amr_users_clear_all_public_csv($amain['public']);
    amr_users_message(__('Csv lists privacy check done.  Any no longer public lists deleted. ', 'amr-users'));
    if (isset($_POST['show_search'])) {
        if (is_array($_POST['show_search'])) {
            foreach ($_POST['show_search'] as $i => $y) {
                $amain['show_search'][$i] = true;
            }
        }
    }
    if (isset($_POST['customnav'])) {
        if (is_array($_POST['customnav'])) {
            foreach ($_POST['customnav'] as $i => $y) {
                $amain['customnav'][$i] = true;
            }
        }
    }
    if (isset($_POST['show_perpage'])) {
        if (is_array($_REQUEST['show_perpage'])) {
            foreach ($_REQUEST['show_perpage'] as $i => $y) {
                $amain['show_perpage'][$i] = true;
            }
        }
    }
    if (isset($_POST['show_pagination'])) {
        if (is_array($_REQUEST['show_pagination'])) {
            foreach ($_REQUEST['show_pagination'] as $i => $y) {
                $amain['show_pagination'][$i] = true;
            }
        }
    }
    if (isset($_POST['show_headings'])) {
        if (is_array($_REQUEST['show_headings'])) {
            foreach ($_REQUEST['show_headings'] as $i => $y) {
                $amain['show_headings'][$i] = true;
            }
        }
    }
    if (isset($_POST['show_csv'])) {
        if (is_array($_REQUEST['show_csv'])) {
            foreach ($_REQUEST['show_csv'] as $i => $y) {
                $amain['show_csv'][$i] = true;
            }
        }
    }
    if (isset($_POST['show_refresh'])) {
        if (is_array($_REQUEST['show_refresh'])) {
            foreach ($_REQUEST['show_refresh'] as $i => $y) {
                $amain['show_refresh'][$i] = true;
            }
        }
    }
    $amain['version'] = AUSERS_VERSION;
    if (isset($_POST)) {
        ausers_update_option('amr-users-main', $amain);
        //ausers_update_option ('amr-users', $aopt);
    }
    amr_users_message(__('Options Updated', 'amr-users'));
    return;
}
コード例 #3
0
 function cache_status()
 {
     /* show the cache status and offer to rebuild */
     global $wpdb;
     global $amain;
     $problem = false;
     $now = time();
     $dt = new DateTime('now', $this->tz);
     $nowtxt = date_format($dt, 'D, j M Y G:i e');
     if (is_admin()) {
         if (!($amain = ausers_get_option('amr-users-main'))) {
             $amain = ameta_default_main();
         }
         $wpdb->show_errors();
         $sql = 'SELECT DISTINCT reportid AS "rid", COUNT(reportid) AS "lines" FROM ' . $this->table_name . ' GROUP BY reportid';
         $results = $wpdb->get_results($sql, ARRAY_A);
         /* Now e have a summary of what isin the cache table - rid, lines */
         if (is_wp_error($results)) {
             echo '<h2>' . $results->get_error_message() . '</h2>';
             return false;
         } else {
             if (!empty($results)) {
                 //var_dump($results);  var_dump($amain);
                 foreach ($results as $i => $rpt) {
                     $r = intval(substr($rpt['rid'], 5));
                     /* *** skip the 'users' and take the rest */
                     $summary[$r]['rid'] = $rpt['rid'];
                     $summary[$r]['lines'] = $rpt['lines'] - 2;
                     /* as first two liens are headers anyway*/
                     $summary[$r]['name'] = $amain['names'][intval($r)];
                 }
             } else {
                 echo adb_cache::get_error('nocacheany');
                 // attempt a realtime run  NO!!! Don't do this - for large databases that are failing anyway will be no good.
                 //foreach ($amain['names'] as $i => $name) {
                 //	amr_build_user_data_maybe_cache($i);
                 //}
             }
             $status = ausers_get_option('amr-users-cache-status');
             /* Now pickup the record of starts etc reportid, start   and reportid end*/
             if (!empty($status)) {
                 foreach ($status as $rd => $se) {
                     $r = intval(substr($rd, 5));
                     /* *** skip the 'users' and take the rest */
                     if (empty($se['end'])) {
                         $now = time();
                         $diff = $now - $se['start'];
                         if ($diff > 60 * 5) {
                             $problem = true;
                             $summary[$r]['end'] = __('Taking too long, may have been aborted... delete cache status, try again, check server logs and/or memory limit', 'amr-users');
                             delete_transient('amr_users_cache_' . $r);
                             // so another can run
                         } else {
                             $summary[$r]['end'] = sprintf(__('Started %s', 'amr-users'), human_time_diff($now, $se['start']));
                         }
                         $summary[$r]['time_since'] = __('?', 'amr-users');
                         $summary[$r]['time_taken'] = __('?', 'amr-users');
                         $summary[$r]['peakmem'] = __('?', 'amr-users');
                         $summary[$r]['rid'] = $rd;
                         $r = intval(substr($rd, 5));
                         /* *** skip the 'users' and take the rest */
                         $summary[$r]['name'] = $amain['names'][intval($r)];
                     } else {
                         if (empty($se['end'])) {
                             $summary[$r]['end'] = 'In progress';
                         } else {
                             $datetime = new datetime(date('Y-m-d H:i:s', $se['end']));
                             if (empty($tzobj)) {
                                 $tzobj = amr_getset_timezone();
                             }
                             $datetime->setTimezone($tzobj);
                             $summary[$r]['end'] = $datetime->format('D, j M G:i');
                         }
                         //$summary[$r]['end'] = empty($se['end']) ? 'In progress' : date_i18n('D, j M H:i:s',$se['end']);  /* this is in unix timestamp not "our time" , so just say how long ago */
                         $summary[$r]['start'] = date_i18n('D, j M Y H:i:s', $se['start']);
                         /* this is in unix timestamp not "our time" , so just say how long ago */
                         $dt = new DateTime('now', $this->tz);
                         $nowtxt = date_format($dt, 'D, j M Y G:i e');
                         $summary[$r]['time_since'] = human_time_diff($se['end'], time());
                         /* the time that the last cache ended */
                         $summary[$r]['time_taken'] = $se['end'] - $se['start'];
                         /* the time that the last cache ended */
                         $summary[$r]['peakmem'] = $se['peakmem'];
                         $summary[$r]['headings'] = $se['headings'];
                     }
                 }
             } else {
                 if (!empty($summary)) {
                     foreach ($summary as $rd => $rpt) {
                         $summary[$rd]['time_since'] = $summary[$rd]['time_taken'] = $summary[$rd]['end'] = $summary[$rd]['peakmem'] = '';
                     }
                 }
             }
             if (!empty($summary)) {
                 echo PHP_EOL . '<div class="wrap" style="padding-top: 20px;">' . '<h3>' . $nowtxt . '</h3>' . PHP_EOL . '<table class="widefat" style="width:auto; ">' . '<thead><tr><th>' . __('Report Id', 'amr-users') . '</th><th>' . __('Name', 'amr-users') . '</th><th>' . __('Lines', 'amr-users') . '</th><th style="text-align: right;">' . __('Ended?', 'amr-users') . '</th><th style="text-align: right;">' . __('How long ago?', 'amr-users') . '</th><th style="text-align: right;">' . __('Seconds taken', 'amr-users') . '</th><th style="text-align: right;">' . __('Peak Memory', 'amr-users') . '</th><th style="text-align: right;">' . __('Details', 'amr-users') . '</th></tr></thead>';
                 foreach ($summary as $rd => $rpt) {
                     if (!isset($rpt['headings'])) {
                         $rpt['headings'] = ' ';
                     }
                     if (!isset($rpt['lines'])) {
                         $rpt['lines'] = ' ';
                     }
                     if (isset($rpt['rid'])) {
                         echo '<tr>' . '<td>' . $rpt['rid'] . '</td>' . '<td>' . au_view_link($rpt['name'], $rd, '') . '</td>' . '<td align="right">' . $rpt['lines'] . '</td>' . '<td align="right">' . $rpt['end'] . '</td>' . '<td align="right">' . $rpt['time_since'] . '</td>' . '<td align="right">' . $rpt['time_taken'] . '</td>' . '<td align="right">' . $rpt['peakmem'] . '</td>' . '<td align="right">' . $rpt['headings'] . '</td>' . '</tr>';
                     }
                 }
                 echo PHP_EOL . '</table>' . PHP_EOL . '</div><!-- end wrap -->' . PHP_EOL;
             }
         }
     } else {
         echo '<h3>not admin?</h3>';
     }
     if ($problem) {
         $fun = '<a target="_blank" title="' . __('Link to audio file of the astronauts of Apollo 13 reporting a problem.', 'amr-users') . '" href="http://upload.wikimedia.org/wikipedia/commons/1/12/Apollo13-wehaveaproblem_edit_1.ogg" >' . __('Houston, we have a problem', 'amr-users') . '</a>';
         $text = __('The background job\'s may be having problems.', 'amr-users');
         $text .= '<br />' . __('Delete all the cache records and try again', 'amr-users');
         $text .= '<br />' . __('Check the server logs and your php wordpress memory limit.', 'amr-users');
         $text .= '<br />' . __('The TPC memory usage plugin may be useful to assess whether the problem is memory.', 'amr-users');
         $text = $fun . '<br/>' . $text;
         amr_users_message($text);
     }
 }
コード例 #4
0
function amr_meta_keys_page()
{
    global $ausersadminurl;
    //amr_meta_main_admin_header('Find fields, make nice names' );
    amr_meta_admin_headings($plugin_page = '');
    // does the nonce check etc
    if (isset($_POST['action']) and !($_POST['action'] === "save")) {
        return;
    }
    echo PHP_EOL . '<div class="clear" style="clear:both;">&nbsp;</div>' . PHP_EOL;
    if (isset($_POST['deleteconfirmed']) and $_POST['deleteconfirmed'] === "Confirm Delete") {
        if (isset($_POST['delete']) and is_array($_POST['delete'])) {
            amr_delete_user_meta($_POST['delete']);
        } else {
            echo amr_users_message(__('No meta_keys selected for deletion', 'amr-users'));
        }
    } elseif (isset($_POST['delete']) and $_POST['delete'] === "Delete") {
        if (isset($_POST['del']) and is_array($_POST['del'])) {
            amr_confirm_delete_user_meta($_POST['del']);
        } else {
            echo amr_users_message(__('No meta_keys selected for deletion', 'amr-users'));
        }
        return;
    } elseif (isset($_POST['update']) and $_POST['update'] === "Update") {
        /* Validate the input and save */
        if (amrmeta_validate_excluded_keys()) {
            // updates inside the function now
        } else {
            echo '<h2>' . __('Validation failed', 'amr-users') . '</h2>';
        }
    } elseif (isset($_POST['resetex']) and $_POST['resetex'] === "Reset") {
        if (ausers_delete_option('amr-users-excluded-meta-keys')) {
            //201410 - wrong optionname
            echo '<h2>' . __('Deleting all excluded keys settings in database', 'amr-users') . '</h2>';
        }
    } else {
        //amrmeta_check_find_keys();
    }
    ameta_list_excluded_keys();
}
コード例 #5
0
function amr_request_cache_with_feedback($list = null)
{
    global $ausersadminurl;
    $result = amr_request_cache($list);
    if (!empty($result)) {
        amr_users_message($result);
        ?>

			<ul><li><?php 
        _e('Report Cache has been scheduled.', 'amr-users');
        ?>
			</li><li><?php 
        _e('If you have a lot of records, it may take a while.', 'amr-users');
        ?>
			</li><li><?php 
        _e('Please check the cache log - refresh for updates and do not reschedule until all the reports have completed. ', 'amr-users');
        ?>
			</li><li><?php 
        _e('If you think it is taking too long, problems may be occuring in the background job, such as running out of memory.  Check server logs and/or Increase wordpress\\s php memory limit', 'amr-users');
        ?>
			</li><li><?php 
        _e('The cache status or the TPC Memory Usage plugin may be useful to assess this.', 'amr-users');
        ?>
			</li><li><?php 
        echo au_cachelog_link();
        ?>
			</li><li><?php 
        echo au_cachestatus_link();
        ?>
			</a></li>
			</ul>
	<?php 
    } else {
        echo '<h2>Error requesting cache:' . $result . '</h2>';
        /**** */
    }
    return $result;
    // time()+3600 = one hour from now.
}
コード例 #6
0
function amrmeta_configure_page()
{
    global $aopt;
    global $amr_nicenames;
    global $pluginpage;
    global $amain;
    ameta_options();
    // should handle emptiness etc
    if (isset($_POST['addnew']) and isset($_POST['copylist'])) {
        $copyfrom = intval($_REQUEST['copylist']);
        $amain['names'][] = __('New list copy of ') . $amain['names'][$copyfrom];
        $aopt['list'][] = $aopt['list'][$copyfrom];
        $ulist = array_pop(array_keys($amain['names']));
        $amain['names'][$ulist] .= ' #' . $ulist;
        ausers_update_option('amr-users', $aopt);
        ausers_update_option('amr-users-main', $amain);
        amr_users_message('Added list: ' . $ulist);
        $_REQUEST['ulist'] = $ulist;
    } else {
        if (!empty($_REQUEST['ulist'])) {
            $ulist = (int) $_REQUEST['ulist'];
        } else {
            $ulist = '1';
        }
    }
    amr_meta_main_admin_header('Configure a user list');
    amr_meta_admin_headings($plugin_page = '');
    // does the nonce check  and formstartetc
    //	else
    if (isset($_REQUEST['rebuild'])) {
        /* can only do one list at a time in realtime */
        amr_rebuild_in_realtime_with_info($ulist);
        echo ausers_form_end();
        return;
    } elseif (!empty($_REQUEST['rebuildback'])) {
        /*  */
        amr_request_cache_with_feedback();
        echo ausers_form_end();
        return;
    } elseif (!empty($_REQUEST['rebuildwarning'])) {
        /*  */
        amr_rebuildwarning($ulist);
        echo ausers_form_end();
        return;
    } elseif (isset($_REQUEST['custom_navigation'])) {
        if (function_exists('amrmeta_custom_navigation_page')) {
            amrmeta_custom_navigation_page($ulist);
            echo ausers_form_end();
            return;
        } else {
            echo 'Function not active';
        }
    } elseif (isset($_REQUEST['grouping'])) {
        if (function_exists('amr_grouping_admin_form')) {
            amr_grouping_admin_form($ulist);
            echo ausers_form_end();
            return;
        } else {
            _e('Grouping Function not active', 'amr-users');
        }
    } elseif (amr_users_can_edit('filtering')) {
        amrmeta_filtering_page($ulist);
    } elseif (isset($_POST['action']) and $_POST['action'] == "save") {
        if (isset($_POST['updateoverview'])) {
            amrmeta_validate_overview();
        } elseif (isset($_POST['update'])) {
            if (!amrmeta_validate_listfields($ulist)) {
                amr_users_message(__('List Fields Validation failed', 'amr-users'));
            }
        } elseif (isset($_POST['configure'])) {
            // ulist already set above, so will just configure
        }
    }
    list_configurable_lists();
    // to allow selection of which to configure
    amrmeta_listfields($ulist);
    echo ausers_form_end();
}
コード例 #7
0
function amrmeta_check_find_fields()
{
    global $amr_nicenames;
    $amr_nicenames = ausers_get_option('amr-users-nicenames');
    // refetch so have all includidng excluded
    if (is_wp_error($amr_nicenames) or empty($amr_nicenames)) {
        /* ***  Check if we have nicenames already built */
        echo '<h3 style="clear:both;">' . __('List of possible fields not yet built.', 'amr-users') . '</h3>';
        track_progress('Before counting users');
        $result = count_users();
        track_progress('After counting users');
        $total_users = $result['total_users'];
        if ($total_users > 1000) {
            amr_users_message(__('You have many users. Please be patient when you rebuild.', 'amr-users'));
            echo '<p>';
            foreach ($result['avail_roles'] as $i => $t) {
                echo '<br />' . __($i) . ' ' . $t;
            }
            echo '<p>';
            echo alist_rebuild_names();
            return;
        } else {
            echo '<h3 style="clear:both;">' . __('Automatically rebuilding list of possible fields now.', 'amr-users') . '</h3>';
            track_progress('Before rebuilding names');
            $amr_nicenames = ameta_rebuildnicenames();
            track_progress('After rebuilding names');
            echo '<h3 style="clear:both;">' . __('List Rebuilt', 'amr-users') . '</h3>';
        }
    }
}
コード例 #8
0
function amr_meta_handle_import()
{
    global $amain, $aopt;
    if (isset($_POST['import-list'])) {
        //	require_once(ABSPATH . 'wp-admin/includes/admin.php');
        if (empty($_FILES)) {
            amr_users_message('No file specified', 'amr-users');
            return;
        }
        if (empty($_FILES['importfile'])) {
            amr_users_message('Problem in upload', 'amr-users');
            return;
        }
        $file = $_FILES['importfile'];
        $uploaded = wp_handle_upload($file, array('test_form' => FALSE));
        if (is_wp_error($uploaded)) {
            $errors['upload_error'] = $uploaded;
        }
        if (!empty($errors)) {
            amr_users_message('There was an error uploading your file.', 'amr-users');
            return;
        }
        if (empty($uploaded['file'])) {
            amr_users_message('No import file chosen.', 'amr-users');
            return;
        }
        $content = file_get_contents($uploaded['file']);
        //var_dump ($content);
        $data = unserialize(stripslashes($content));
        //$data = unserialize($content);
        if (!is_array($data) or !isset($data['version'])) {
            echo '<div class="error"><p>';
            _e('Invalid data in settings file', 'amr-users');
            echo '</p></div';
            die;
        }
        if (version_compare($data['version'], $amain['version'], '==')) {
            amr_users_message(sprintf(__('Your plugin version is %s. Imported settings are from plugin version: %s', 'amr-users'), $amain['version'], $data['version']) . ' &nbsp; Yay!');
        } else {
            amr_users_message(sprintf(__('Your plugin version is %s, BUT imported settings are from plugin version: %s', 'amr-users'), $amain['version'], $data['version']) . ' ' . __('Please test thoroughly.', 'amr-users'));
        }
        $toimport = amr_main_to_export();
        // get the list of overview settings
        $amain['names'][] = 'justimported';
        foreach ($amain['names'] as $index => $name) {
            if ($name == 'justimported') {
                $thisindex = $index;
            }
        }
        foreach ($toimport as $setting) {
            if (isset($data[$setting])) {
                $amain[$setting][$thisindex] = $data[$setting];
            }
        }
        $aopt['list'][$thisindex] = $data['list'];
        ausers_update_option('amr-users', $aopt);
        ausers_update_option('amr-users-main', $amain);
        amr_users_message(sprintf(__('List %s will be saved with imported data', 'amr-users'), $thisindex));
    }
}
コード例 #9
0
function amr_users_store_column_headings($ulist, $customcols)
{
    if (!($amr_users_column_headings = ausers_get_option('amr-users-custom-headings'))) {
        $amr_users_column_headings = array();
    }
    $amr_users_column_headings[$ulist] = $customcols;
    $results = ausers_update_option('amr-users-custom-headings', $amr_users_column_headings);
    if ($results) {
        amr_users_message(__('Custom Column Headings Updated', 'amr-users'));
    } else {
        amr_users_message(__('Column headings not updated - no change or error.', 'amr-users'));
    }
    return $results;
}
コード例 #10
0
function amr_rebuildwarning($list)
{
    $logcache = new adb_cache();
    if ($logcache->cache_in_progress($logcache->reportid($list, 'user'))) {
        $text = sprintf(__('Cache of %s already in progress', 'amr-users'), $list);
        $logcache->log_cache_event($text);
        echo $text;
        return;
    } else {
        $text = $logcache->cache_already_scheduled($list);
        if (!empty($text)) {
            $new_text = __('Report ', 'amr-users') . $list . ': ' . $text;
            $logcache->log_cache_event($new_text);
            amr_users_message($new_text);
            //return;	 - let it run anyway
        }
    }
    echo alist_rebuildreal($list);
    return;
}