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); } }
function amr_meta_overview_onelist_settings($i) { /* the main setting spage - num of lists and names of lists */ global $amain, $aopt; $status = ''; // if (function_exists('amr_offer_filtering')) { if (is_plugin_active('amr-users-plus/amr-users-plus.php')) { $greyedout = ''; $plusstatus = ''; } else { $greyedout = ' style="color: #AAAAAA;" '; $plusstatus = ' disabled="disabled"'; } echo '<tr>'; echo '<td>'; echo $i; echo '</td>'; echo '<td><input type="text" size="45" id="name' . $i . '" name="name[' . $i . ']" value="' . $amain['names'][$i] . '" />'; echo '<br />'; if ($_REQUEST['page'] == 'ameta-admin-general.php') { echo au_configure_link(__('Configure', 'amr-users'), $i, $amain['names'][$i]); echo ' |' . au_copy_link(' ' . __('Copy', 'amr-users'), $i, $amain['names'][$i]); } else { echo au_buildcache_link(' ' . __('Rebuild', 'amr-users'), $i, $amain['names'][$i]); } echo ' |' . au_delete_link(' ' . __('Delete', 'amr-users'), $i, $amain['names'][$i]) . ' |' . au_view_link(' ' . __('View', 'amr-users'), $i, $amain['names'][$i]); if (!is_network_admin()) { echo ' |' . au_add_userlist_page(' ' . __('Add page', 'amr-users'), $i, $amain['names'][$i]); echo '</td>'; } echo '<td align="center">'; echo '<input type="checkbox" id="public' . $i . '" name="public[' . $i . ']" value="1" '; if (!empty($amain['public'][$i])) { echo 'checked="checked" />'; $status = ''; } echo '</td>'; echo '<td align="left">'; if (empty($amain['html_type'][$i])) { $amain['html_type'][$i] = 'table'; } foreach (array('table', 'simple') as $type) { echo '<input type="radio" id="html_type' . $i . '" name="html_type[' . $i . ']" value="' . $type . '" '; if ($amain['html_type'][$i] == $type) { echo 'checked="Checked"'; } echo '/>'; _e($type); echo '<br />'; } echo '</td>'; //} if (empty($amain['list_rows_per_page'][$i])) { $amain['list_rows_per_page'][$i] = $amain['rows_per_page']; } echo '<td><input type="text" size="3" id="rows_per_page' . $i . '" name="list_rows_per_page[' . $i . ']" value="' . $amain['list_rows_per_page'][$i] . '" /></td>'; if (empty($amain['avatar_size'])) { $amain['avatar_size'] = 10; } if (empty($amain['list_avatar_size'][$i])) { $amain['list_avatar_size'][$i] = $amain['avatar_size']; } echo '<td><input type="text" size="3" id="avatar_size' . $i . '" name="list_avatar_size[' . $i . ']" value="' . $amain['list_avatar_size'][$i] . '" /></td>'; // echo '<td align="center"><input type="checkbox" id="show_search' . $i . '" name="show_search[' . $i . ']" value="1" ' . $status; if (!empty($amain['show_search'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"><input type="checkbox" id="show_perpage' . $i . '" name="show_perpage[' . $i . ']" value="1" ' . $status; if (!empty($amain['show_perpage'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"><input type="checkbox" id="show_pagination' . $i . '" name="show_pagination[' . $i . ']" value="1" ' . $status; if (!empty($amain['show_pagination'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"><input type="checkbox" id="show_headings' . $i . '" name="show_headings[' . $i . ']" value="1" ' . $status; if (!empty($amain['show_headings'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"><input type="checkbox" id="show_csv' . $i . '" name="show_csv[' . $i . ']" value="1" ' . $status; if (!empty($amain['show_csv'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"><input type="checkbox" id="show_refresh' . $i . '" name="show_refresh[' . $i . ']" value="1" ' . $status; if (!empty($amain['show_refresh'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"> <input type="checkbox" id="sortable' . $i . '" name="sortable[' . $i . ']" '; echo ' value="1" '; if (!empty($amain['sortable'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; // echo '<td align="center"> <input type="checkbox" id="customnav' . $i . '" name="customnav[' . $i . ']" ' . $plusstatus; echo ' value="1" '; if (!empty($amain['customnav'][$i])) { echo 'checked="Checked"'; } echo '/></td>'; echo '<td align="left">'; if (empty($amain['filter_html_type'][$i])) { $amain['filter_html_type'][$i] = 'none'; } foreach (array('intableheader' => __('in table', 'amr-users'), 'above' => __('above', 'amr-users'), 'none' => __('none', 'amr-users')) as $val => $type) { echo '<input type="radio" id="filter_html_type' . $i . '" name="filter_html_type[' . $i . ']" value="' . $val . '" ' . $plusstatus; if ($amain['filter_html_type'][$i] == $val) { echo 'checked="Checked"'; } echo '/>'; echo $type; echo '<br />'; } echo '</td>'; }
function amr_rebuild_in_realtime_with_info($list) { // nlr ? if (amr_build_user_data_maybe_cache($list)) { echo '<div class="update">' . sprintf(__('Cache rebuilt for %s ', 'amr-users'), $list) . '</div>'; /* check that allowed */ echo au_view_link(__('View Report', 'amr-users'), $list, __('View the recently cached report', 'amr-users')); } else { echo '<div class="update">' . sprintf(__('Check cache log for completion of list %s ', 'amr-users'), $list) . '</div>'; } /* check that allowed */ }