예제 #1
0
function alist_one_widget($type = 'user', $i = 1, $do_headings = false, $do_csv = false, $max = 10)
{
    /* a widget version of alist one*/
    /* Get the fields to use for the chosen list type */
    global $aopt;
    global $amain;
    $c = new adb_cache();
    $rptid = $c->reportid($i, $type);
    $line = $c->get_cache_report_lines($rptid, '0', '2');
    /* get the internal heading names  for internal plugin use only */
    /* get the user defined heading names */
    if (!defined('str_getcsv')) {
        $icols = amr_str_getcsv($line[0]['csvcontent'], ',', '"', '\\');
    } else {
        $icols = str_getcsv($line[0]['csvcontent'], ',', '"', '\\');
    }
    //		if (!defined('str_getcsv')) $cols = amr_str_getcsv( $line[1]['csvcontent'], '","','"','\\');
    //		else $cols = str_getcsv( $line[1]['csvcontent'], ',','"','\\');
    foreach ($icols as $ic => $cv) {
        /* use the icols as our controlling array, so that we have the internal field names */
        $v = $cols[$ic];
        $html .= '<th>' . $v . '</th>';
    }
    $hhtml = '<thead><tr>' . $html . '</tr></thead>';
    /* setup the html for the table headings */
    $fhtml = '<tfoot><tr>' . $html . '</tr>' . '</tfoot>';
    /* setup the html for the table headings */
    $html = '';
    $totalitems = $c->get_cache_totallines($rptid);
    $lines = $c->get_cache_report_lines($rptid, $start + 1, $max);
    if (!($lines > 0)) {
        amr_flag_error($c->get_error('numoflists'));
        return false;
    }
    foreach ($lines as $il => $l) {
        $id = $lineitems[0];
        /*  *** pop the first one - this should always be the id */
        $user = amr_get_userdata($id);
        unset($linehtml);
        foreach ($icols as $ic => $c) {
            /* use the icols as our controlling array, so that we have the internal field names */
            $v = $lineitems[$ic];
            $linehtml .= '<td>' . amr_format_user_cell($c, $v, $user) . '</td>';
        }
        $html .= PHP_EOL . '<tr>' . $linehtml . '</tr>';
    }
    $html = '<table>' . $hhtml . $fhtml . '<tbody>' . $html . '</tbody></table>';
    return $html;
}
예제 #2
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);
     }
 }
예제 #3
0
function amrmeta_validate_names()
{
    /*  the names of lists */
    global $amain;
    if (is_array($_POST['name'])) {
        foreach ($_POST['name'] as $i => $n) {
            /* for each list */
            $amain['names'][$i] = $n;
        }
        return true;
    } else {
        amr_flag_error(adb_cache::get_error('nonamesarray'));
        return false;
    }
}