Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MMB
File: Stats.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*************************************************************
[2] Fix | Delete
* stats.class.php
[3] Fix | Delete
* Get Site Stats
[4] Fix | Delete
* Copyright (c) 2011 Prelovac Media
[5] Fix | Delete
* www.prelovac.com
[6] Fix | Delete
**************************************************************/
[7] Fix | Delete
class MMB_Stats extends MMB_Core
[8] Fix | Delete
{
[9] Fix | Delete
public function get_site_statistics()
[10] Fix | Delete
{
[11] Fix | Delete
/** @var wpdb $wpdb */
[12] Fix | Delete
global $wpdb;
[13] Fix | Delete
$siteStatistics = array();
[14] Fix | Delete
$prefix = $wpdb->prefix;
[15] Fix | Delete
$basePrefix = $wpdb->base_prefix;
[16] Fix | Delete
[17] Fix | Delete
if (!$this->mmb_multisite) {
[18] Fix | Delete
$siteStatistics['users'] = (int)$wpdb->get_var("SELECT COUNT(*) FROM {$basePrefix}users");
[19] Fix | Delete
} else {
[20] Fix | Delete
$siteStatistics['users'] = count(get_users(
[21] Fix | Delete
array(
[22] Fix | Delete
'blog_id' => $wpdb->blogid,
[23] Fix | Delete
)
[24] Fix | Delete
));
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
$siteStatistics['approvedComments'] = (int)$wpdb->get_var("SELECT COUNT(*) FROM {$prefix}comments c INNER JOIN {$prefix}posts p ON c.comment_post_ID = p.ID WHERE comment_approved = '1' AND p.post_status = 'publish'");
[28] Fix | Delete
$siteStatistics['activePlugins'] = count((array)get_option('active_plugins', array()));
[29] Fix | Delete
$siteStatistics['publishedPosts'] = (int)$wpdb->get_var("SELECT COUNT(*) FROM {$prefix}posts WHERE post_type='post' AND post_status='publish'");
[30] Fix | Delete
$siteStatistics['draftPosts'] = (int)$wpdb->get_var("SELECT COUNT(*) FROM {$prefix}posts WHERE post_type='post' AND post_status='draft'");
[31] Fix | Delete
$siteStatistics['publishedPages'] = (int)$wpdb->get_var("SELECT COUNT(*) FROM {$prefix}posts WHERE post_type='page' AND post_status='publish'");
[32] Fix | Delete
$siteStatistics['draftPages'] = (int)$wpdb->get_var("SELECT COUNT(*) FROM {$prefix}posts WHERE post_type='page' AND post_status='draft'");
[33] Fix | Delete
[34] Fix | Delete
return $siteStatistics;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
public function get_core_update()
[38] Fix | Delete
{
[39] Fix | Delete
global $wp_version;
[40] Fix | Delete
$update = null;
[41] Fix | Delete
$locale = get_locale();
[42] Fix | Delete
$core = $this->mmb_get_transient('update_core');
[43] Fix | Delete
[44] Fix | Delete
if (empty($core->updates)) {
[45] Fix | Delete
return null;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
foreach ($core->updates as $availableUpdate) {
[49] Fix | Delete
if ($availableUpdate->locale == $locale && strtolower($availableUpdate->response) === "upgrade") {
[50] Fix | Delete
$update = $availableUpdate;
[51] Fix | Delete
break;
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
//fallback to first
[56] Fix | Delete
if (!$update) {
[57] Fix | Delete
$update = $core->updates[0];
[58] Fix | Delete
}
[59] Fix | Delete
// WordPress can actually have an update to the same version and locale if locale has not been updated
[60] Fix | Delete
if ($update->response === 'development' || $update->response === 'upgrade' || version_compare($wp_version, $update->current, '<') || $locale !== $update->locale) {
[61] Fix | Delete
$update->current_version = $wp_version;
[62] Fix | Delete
return $update;
[63] Fix | Delete
} else {
[64] Fix | Delete
return null;
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
public function get_comments($type, $limit, $trimlen = 200)
[69] Fix | Delete
{
[70] Fix | Delete
$comments = (array)get_comments('status='.$type.'&number='.$limit);
[71] Fix | Delete
foreach ($comments as &$comment) {
[72] Fix | Delete
$commented_post = get_post($comment->comment_post_ID);
[73] Fix | Delete
$comment->post_title = $commented_post->post_title;
[74] Fix | Delete
$comment->comment_content = $this->trim_content($comment->comment_content, $trimlen);
[75] Fix | Delete
$comment->comment_content = seems_utf8($comment->comment_content) ? $comment->comment_content : utf8_encode($comment->comment_content);
[76] Fix | Delete
unset($comment->comment_author_IP);
[77] Fix | Delete
unset($comment->comment_karma);
[78] Fix | Delete
unset($comment->comment_agent);
[79] Fix | Delete
unset($comment->comment_type);
[80] Fix | Delete
unset($comment->comment_parent);
[81] Fix | Delete
}
[82] Fix | Delete
return $comments;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
public function get_posts($limit)
[86] Fix | Delete
{
[87] Fix | Delete
$userIdMap = $this->getUsersIDs();
[88] Fix | Delete
$list = array();
[89] Fix | Delete
[90] Fix | Delete
[91] Fix | Delete
$posts = (array)get_posts('post_status=publish&numberposts='.$limit.'&orderby=post_date&order=desc');
[92] Fix | Delete
foreach ($posts as $id => $post) {
[93] Fix | Delete
$add = new stdClass();
[94] Fix | Delete
$add->post_permalink = get_permalink($post->ID);
[95] Fix | Delete
$add->ID = $post->ID;
[96] Fix | Delete
$add->post_date = $post->post_date;
[97] Fix | Delete
$add->post_title = $post->post_title;
[98] Fix | Delete
$add->post_type = $post->post_type;
[99] Fix | Delete
$add->comment_count = (int)$post->comment_count;
[100] Fix | Delete
[101] Fix | Delete
$author_name = isset($userIdMap[$post->post_author]) ? $userIdMap[$post->post_author] : '';
[102] Fix | Delete
$add->post_author_name = array('author_id' => $post->post_author, 'author_name' => $author_name);
[103] Fix | Delete
[104] Fix | Delete
$list[] = $add;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
$posts = (array)get_pages('post_status=publish&numberposts='.$limit.'&orderby=post_date&order=desc');
[108] Fix | Delete
foreach ($posts as $id => $post) {
[109] Fix | Delete
$add = new stdClass();
[110] Fix | Delete
$add->post_permalink = get_permalink($post->ID);
[111] Fix | Delete
$add->post_type = $post->post_type;
[112] Fix | Delete
$add->ID = $post->ID;
[113] Fix | Delete
$add->post_date = $post->post_date;
[114] Fix | Delete
$add->post_title = $post->post_title;
[115] Fix | Delete
[116] Fix | Delete
$author_name = isset($userIdMap[$post->post_author]) ? $userIdMap[$post->post_author] : '';
[117] Fix | Delete
$add->post_author = array('author_id' => $post->post_author, 'author_name' => $author_name);
[118] Fix | Delete
[119] Fix | Delete
$list[] = $add;
[120] Fix | Delete
}
[121] Fix | Delete
usort($list, array($this, 'cmp_posts_worker'));
[122] Fix | Delete
return array_slice($list, 0, $limit);
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
public function get_drafts($limit)
[126] Fix | Delete
{
[127] Fix | Delete
$list = array();
[128] Fix | Delete
[129] Fix | Delete
$posts = (array)get_posts('post_status=draft&numberposts='.$limit.'&orderby=post_date&order=desc');
[130] Fix | Delete
foreach ($posts as $id => $post) {
[131] Fix | Delete
$add = new stdClass();
[132] Fix | Delete
$add->post_permalink = get_permalink($post->ID);
[133] Fix | Delete
$add->post_type = $post->post_type;
[134] Fix | Delete
$add->ID = $post->ID;
[135] Fix | Delete
$add->post_date = $post->post_date;
[136] Fix | Delete
$add->post_title = $post->post_title;
[137] Fix | Delete
[138] Fix | Delete
$list[] = $add;
[139] Fix | Delete
}
[140] Fix | Delete
$posts = (array)get_pages('post_status=draft&numberposts='.$limit.'&orderby=post_date&order=desc');
[141] Fix | Delete
foreach ($posts as $id => $post) {
[142] Fix | Delete
$add = new stdClass();
[143] Fix | Delete
$add->post_permalink = get_permalink($post->ID);
[144] Fix | Delete
$add->ID = $post->ID;
[145] Fix | Delete
$add->post_type = $post->post_type;
[146] Fix | Delete
$add->post_date = $post->post_date;
[147] Fix | Delete
$add->post_title = $post->post_title;
[148] Fix | Delete
[149] Fix | Delete
$list[] = $add;
[150] Fix | Delete
}
[151] Fix | Delete
usort($list, array($this, 'cmp_posts_worker'));
[152] Fix | Delete
return array_slice($list, 0, $limit);
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
public function get_scheduled($numberOfItems)
[156] Fix | Delete
{
[157] Fix | Delete
$list = array();
[158] Fix | Delete
[159] Fix | Delete
$posts = (array)get_posts('post_status=future&numberposts='.$numberOfItems.'&orderby=post_date&order=desc');
[160] Fix | Delete
foreach ($posts as $id => $post) {
[161] Fix | Delete
$add = new stdClass();
[162] Fix | Delete
$add->post_permalink = get_permalink($post->ID);
[163] Fix | Delete
$add->ID = $post->ID;
[164] Fix | Delete
$add->post_date = $post->post_date;
[165] Fix | Delete
$add->post_type = $post->post_type;
[166] Fix | Delete
$add->post_title = $post->post_title;
[167] Fix | Delete
[168] Fix | Delete
$list[] = $add;
[169] Fix | Delete
}
[170] Fix | Delete
$posts = (array)get_pages('post_status=future&numberposts='.$numberOfItems.'&orderby=post_date&order=desc');
[171] Fix | Delete
foreach ((array)$posts as $id => $post) {
[172] Fix | Delete
$add = new stdClass();
[173] Fix | Delete
$add->post_permalink = get_permalink($post->ID);
[174] Fix | Delete
$add->ID = $post->ID;
[175] Fix | Delete
$add->post_type = $post->post_type;
[176] Fix | Delete
$add->post_date = $post->post_date;
[177] Fix | Delete
$add->post_title = $post->post_title;
[178] Fix | Delete
[179] Fix | Delete
$list[] = $add;
[180] Fix | Delete
}
[181] Fix | Delete
usort($list, array($this, 'cmp_posts_worker'));
[182] Fix | Delete
return array_slice($list, 0, $numberOfItems);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* @return array Map of wp_users.ID (string) => wp_users.display_name (string) where wp_users.user_status == 0.
[187] Fix | Delete
*/
[188] Fix | Delete
private function getUsersIDs()
[189] Fix | Delete
{
[190] Fix | Delete
global $wpdb;
[191] Fix | Delete
$users_authors = array();
[192] Fix | Delete
$users = $wpdb->get_results("SELECT ID as user_id, display_name FROM $wpdb->users WHERE user_status=0");
[193] Fix | Delete
[194] Fix | Delete
foreach ($users as $user_key => $user_val) {
[195] Fix | Delete
$users_authors[$user_val->user_id] = $user_val->display_name;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
return $users_authors;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
public function get_updates($stats, $options = array())
[202] Fix | Delete
{
[203] Fix | Delete
if (isset($options['themes']) && $options['themes']) {
[204] Fix | Delete
$upgrades = $this->get_installer_instance()->get_upgradable_themes();
[205] Fix | Delete
if (!empty($upgrades)) {
[206] Fix | Delete
$stats['upgradable_themes'] = $upgrades;
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
if (isset($options['plugins']) && $options['plugins']) {
[211] Fix | Delete
$upgrades = $this->get_installer_instance()->get_upgradable_plugins();
[212] Fix | Delete
if (!empty($upgrades)) {
[213] Fix | Delete
$stats['upgradable_plugins'] = $upgrades;
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
if (isset($options['translations']) && $options['translations']) {
[218] Fix | Delete
$upgrades = $this->get_installer_instance()->get_upgradable_translations();
[219] Fix | Delete
if (!empty($upgrades)) {
[220] Fix | Delete
$stats['upgradable_translations'] = $upgrades;
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
return $stats;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
public function getUserList()
[228] Fix | Delete
{
[229] Fix | Delete
$filter = array(
[230] Fix | Delete
'user_roles' => array(
[231] Fix | Delete
'administrator',
[232] Fix | Delete
),
[233] Fix | Delete
'username' => '',
[234] Fix | Delete
'username_filter' => '',
[235] Fix | Delete
);
[236] Fix | Delete
$users = $this->get_user_instance()->get_users($filter);
[237] Fix | Delete
[238] Fix | Delete
if (empty($users['users']) || !is_array($users['users'])) {
[239] Fix | Delete
return array();
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
$userList = array();
[243] Fix | Delete
foreach ($users['users'] as $user) {
[244] Fix | Delete
$userList[] = $user['user_login'];
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
return $userList;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
private function stats_arg(array $params, $widget, $arg)
[251] Fix | Delete
{
[252] Fix | Delete
// Cleanup plugin (the only one) has the following keys that hold options: overhead, revisions, spam.
[253] Fix | Delete
if (isset($params['item_filter']['get_stats']['plugins']['cleanup'][$widget][$arg])) {
[254] Fix | Delete
return $params['item_filter']['get_stats']['plugins']['cleanup'][$widget][$arg];
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
// Remaining "widgets" are number-indexed.
[258] Fix | Delete
foreach ((array)@$params['item_filter']['get_stats'] as $key => $data) {
[259] Fix | Delete
if ($key !== $widget) {
[260] Fix | Delete
continue;
[261] Fix | Delete
}
[262] Fix | Delete
if (isset($data[1][$arg])) {
[263] Fix | Delete
return $data[1][$arg];
[264] Fix | Delete
}
[265] Fix | Delete
break;
[266] Fix | Delete
}
[267] Fix | Delete
return null;
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
private function get_expired_transients(array $transientsData)
[271] Fix | Delete
{
[272] Fix | Delete
$expiredTransients = 0;
[273] Fix | Delete
foreach ($transientsData as $transient) {
[274] Fix | Delete
$expiredTransients += $this->get_expired_transients_size($transient['name'], $transient['suffix'], $transient['timeout'], $transient['mask'], $transient['limit']);
[275] Fix | Delete
}
[276] Fix | Delete
return $expiredTransients;
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
private function get_expired_transients_size($name, $suffix, $timeout, $mask, $limit)
[280] Fix | Delete
{
[281] Fix | Delete
/** @var wpdb $wpdb */
[282] Fix | Delete
global $wpdb;
[283] Fix | Delete
[284] Fix | Delete
$prefix = $wpdb->prefix;
[285] Fix | Delete
[286] Fix | Delete
$timeoutName = $name.$suffix;
[287] Fix | Delete
$subStrLength = strlen($timeoutName) + 1;
[288] Fix | Delete
[289] Fix | Delete
$escapedTimeoutName = str_replace('_', '\_', $timeoutName);
[290] Fix | Delete
[291] Fix | Delete
$selectTimeOutedTransients = <<<SQL
[292] Fix | Delete
SELECT SUBSTR(option_name, {$subStrLength}) AS transient_name FROM {$prefix}options WHERE option_name LIKE '{$escapedTimeoutName}{$mask}' AND option_value < {$timeout} LIMIT {$limit}
[293] Fix | Delete
SQL;
[294] Fix | Delete
[295] Fix | Delete
$transientsToDelete = $wpdb->get_col($selectTimeOutedTransients);
[296] Fix | Delete
$timeoutsToDelete = array();
[297] Fix | Delete
$transientsTotalSize = 0;
[298] Fix | Delete
[299] Fix | Delete
if (count($transientsToDelete) === 0) {
[300] Fix | Delete
return $transientsTotalSize;
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
foreach ($transientsToDelete as &$transient) {
[304] Fix | Delete
$timeoutsToDelete[] = "'".$timeoutName.$transient."'";
[305] Fix | Delete
$transient = "'".$name.$transient."'";
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
$transientSizeClause = implode(',', $transientsToDelete);
[309] Fix | Delete
[310] Fix | Delete
$transientsSizeQuery = <<<SQL
[311] Fix | Delete
SELECT SUM(LENGTH(option_value)) as valueSize, SUM(LENGTH(option_name)) as nameSize FROM {$prefix}options WHERE option_name IN ({$transientSizeClause})
[312] Fix | Delete
SQL;
[313] Fix | Delete
$transientsSize = $wpdb->get_results($transientsSizeQuery);
[314] Fix | Delete
$transientsTotalSize += ((int)$transientsSize[0]->nameSize);
[315] Fix | Delete
$transientsTotalSize += ((int)$transientsSize[0]->valueSize);
[316] Fix | Delete
[317] Fix | Delete
$transientSizeClause = implode(',', $timeoutsToDelete);
[318] Fix | Delete
$transientsSizeQuery = <<<SQL
[319] Fix | Delete
SELECT SUM(LENGTH(option_value)) as valueSize, SUM(LENGTH(option_name)) as nameSize FROM {$prefix}options WHERE option_name IN ({$transientSizeClause})
[320] Fix | Delete
SQL;
[321] Fix | Delete
$timeoutsSize = $wpdb->get_results($transientsSizeQuery);
[322] Fix | Delete
$transientsTotalSize += ((int)$timeoutsSize[0]->valueSize);
[323] Fix | Delete
$transientsTotalSize += ((int)$timeoutsSize[0]->nameSize);
[324] Fix | Delete
[325] Fix | Delete
return $transientsTotalSize;
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
public function get_stats(array $params)
[329] Fix | Delete
{
[330] Fix | Delete
$revisionLimit = (int)str_replace('r_', '', (string)$this->stats_arg($params, 'revisions', 'num_to_keep'));
[331] Fix | Delete
if (!$revisionLimit) {
[332] Fix | Delete
$revisionLimit = 5;
[333] Fix | Delete
}
[334] Fix | Delete
$commentLimit = (int)$this->stats_arg($params, 'comments', 'numberposts');
[335] Fix | Delete
if (!$commentLimit) {
[336] Fix | Delete
$commentLimit = 5;
[337] Fix | Delete
}
[338] Fix | Delete
// All post limits are the same on the API side.
[339] Fix | Delete
$postLimit = (int)$this->stats_arg($params, 'posts', 'numberposts');
[340] Fix | Delete
if (!$postLimit) {
[341] Fix | Delete
$postLimit = 5;
[342] Fix | Delete
}
[343] Fix | Delete
$transientsParams = (array)$this->stats_arg($params, 'transients', 'expire_data');
[344] Fix | Delete
[345] Fix | Delete
unset($params);
[346] Fix | Delete
$save = array('plugins' => array('cleanup' => array('revisions' => array('num_to_keep' => $revisionLimit))));
[347] Fix | Delete
// These options are only used for the revision cleanup action.
[348] Fix | Delete
update_option('mmb_stats_filter', $save);
[349] Fix | Delete
[350] Fix | Delete
include_once ABSPATH.'wp-includes/update.php';
[351] Fix | Delete
include_once ABSPATH.'wp-admin/includes/update.php';
[352] Fix | Delete
[353] Fix | Delete
mwp_logger()->debug('Started initializing stats');
[354] Fix | Delete
[355] Fix | Delete
$stats = array(
[356] Fix | Delete
'upgradable_themes' => $this->get_installer_instance()->get_upgradable_themes(),
[357] Fix | Delete
'upgradable_plugins' => $this->get_installer_instance()->get_upgradable_plugins(),
[358] Fix | Delete
'upgradable_translations' => $this->get_installer_instance()->get_upgradable_translations(),
[359] Fix | Delete
'core_updates' => $this->get_core_update(),
[360] Fix | Delete
'posts' => $this->get_posts($postLimit),
[361] Fix | Delete
'drafts' => $this->get_drafts($postLimit),
[362] Fix | Delete
'scheduled' => $this->get_scheduled($postLimit),
[363] Fix | Delete
'hit_counter' => get_option('user_hit_count'),
[364] Fix | Delete
'comments' => array(
[365] Fix | Delete
'pending' => $this->get_comments('hold', $commentLimit),
[366] Fix | Delete
'approved' => $this->get_comments('approve', $commentLimit),
[367] Fix | Delete
),
[368] Fix | Delete
'site_statistics' => $this->get_site_statistics(),
[369] Fix | Delete
'num_revisions' => mmb_num_revisions($revisionLimit),
[370] Fix | Delete
'overhead' => mmb_handle_overhead(false),
[371] Fix | Delete
'expired_transients' => $this->get_expired_transients($transientsParams),
[372] Fix | Delete
'num_spam_comments' => mmb_num_spam_comments(),
[373] Fix | Delete
);
[374] Fix | Delete
[375] Fix | Delete
mwp_logger()->debug('Finished initializing stats');
[376] Fix | Delete
[377] Fix | Delete
/** @var $wpdb wpdb */
[378] Fix | Delete
global $wpdb, $wp_version, $mmb_plugin_dir;
[379] Fix | Delete
[380] Fix | Delete
$stats['worker_version'] = $GLOBALS['MMB_WORKER_VERSION'];
[381] Fix | Delete
$stats['worker_revision'] = $GLOBALS['MMB_WORKER_REVISION'];
[382] Fix | Delete
$stats['wordpress_version'] = $wp_version;
[383] Fix | Delete
$stats['wordpress_locale_pckg'] = get_locale();
[384] Fix | Delete
$stats['php_version'] = phpversion();
[385] Fix | Delete
$stats['mysql_version'] = $wpdb->db_version();
[386] Fix | Delete
$stats['wp_multisite'] = $this->mmb_multisite;
[387] Fix | Delete
$stats['network_install'] = $this->network_admin_install;
[388] Fix | Delete
[389] Fix | Delete
mwp_logger()->debug('Started encrypting cookies...');
[390] Fix | Delete
[391] Fix | Delete
$stats['cookies'] = $this->get_stat_cookies();
[392] Fix | Delete
[393] Fix | Delete
mwp_logger()->debug('Finished encrypting cookies...');
[394] Fix | Delete
[395] Fix | Delete
$absPath = trailingslashit(ABSPATH); // This will prevent 2 backslash when WP in root
[396] Fix | Delete
[397] Fix | Delete
$stats['admin_usernames'] = $this->getUserList();
[398] Fix | Delete
$stats['site_title'] = get_bloginfo('name');
[399] Fix | Delete
$stats['site_tagline'] = get_bloginfo('description');
[400] Fix | Delete
$stats['blog_public'] = get_option('blog_public');
[401] Fix | Delete
$stats['timezone'] = get_option('timezone_string');
[402] Fix | Delete
$stats['timezone_offset'] = get_option('gmt_offset');
[403] Fix | Delete
$stats['server_ip'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null;
[404] Fix | Delete
$stats['hostname'] = php_uname('n');
[405] Fix | Delete
$stats['db_name'] = $this->get_active_db();
[406] Fix | Delete
$stats['db_prefix'] = $wpdb->prefix;
[407] Fix | Delete
$stats['content_path'] = WP_CONTENT_DIR;
[408] Fix | Delete
$stats['absolute_path'] = $absPath;
[409] Fix | Delete
$stats['worker_path'] = $mmb_plugin_dir;
[410] Fix | Delete
$stats['site_home'] = get_option('home');
[411] Fix | Delete
[412] Fix | Delete
$fs = new Symfony_Filesystem_Filesystem();
[413] Fix | Delete
if (defined('WP_CONTENT_DIR')) {
[414] Fix | Delete
$contentDir = WP_CONTENT_DIR;
[415] Fix | Delete
// This will prevent 2 backslash when WP in root
[416] Fix | Delete
if (substr($contentDir, 0, 2) === '//') {
[417] Fix | Delete
$contentDir = substr(WP_CONTENT_DIR, 1);
[418] Fix | Delete
$stats['content_path'] = $contentDir;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
if (substr($contentDir, 0, 1) != '/' && strpos($contentDir, ABSPATH) === false) {
[422] Fix | Delete
$contentDir = ABSPATH.$contentDir;
[423] Fix | Delete
}
[424] Fix | Delete
$stats['content_relative_path'] = $fs->makePathRelative($contentDir, $absPath);
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
if (defined('WP_PLUGIN_DIR')) {
[428] Fix | Delete
$pluginDir = WP_PLUGIN_DIR;
[429] Fix | Delete
// This will prevent 2 backslash when WP in root
[430] Fix | Delete
if (substr($pluginDir, 0, 2) === '//') {
[431] Fix | Delete
$pluginDir = substr(WP_PLUGIN_DIR, 1);
[432] Fix | Delete
}
[433] Fix | Delete
[434] Fix | Delete
if (substr($pluginDir, 0, 1) != '/' && strpos($pluginDir, ABSPATH) === false) {
[435] Fix | Delete
$pluginDir = ABSPATH.$pluginDir;
[436] Fix | Delete
}
[437] Fix | Delete
$stats['plugin_relative_path'] = $fs->makePathRelative($pluginDir, $absPath);
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
if (defined('WPMU_PLUGIN_DIR')) {
[441] Fix | Delete
$muPluginDir = WPMU_PLUGIN_DIR;
[442] Fix | Delete
// This will prevent 2 backslash when WP in root
[443] Fix | Delete
if (substr($muPluginDir, 0, 2) === '//') {
[444] Fix | Delete
$muPluginDir = substr(WPMU_PLUGIN_DIR, 1);
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
if (substr($muPluginDir, 0, 1) != '/' && strpos($muPluginDir, ABSPATH) === false) {
[448] Fix | Delete
$muPluginDir = ABSPATH.$muPluginDir;
[449] Fix | Delete
}
[450] Fix | Delete
$stats['mu_plugin_relative_path'] = $fs->makePathRelative($muPluginDir, $absPath);
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
$uploadDirArray = wp_upload_dir();
[454] Fix | Delete
if (false === $uploadDir = realpath($uploadDirArray['basedir'])) {
[455] Fix | Delete
$uploadDir = $uploadDirArray['basedir'];
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
$stats['uploads_relative_path'] = $fs->makePathRelative($uploadDir, $absPath);
[459] Fix | Delete
[460] Fix | Delete
$stats['writable'] = $this->is_server_writable();
[461] Fix | Delete
$stats['fs_method'] = !$this->check_if_pantheon() ? get_filesystem_method() : '';
[462] Fix | Delete
[463] Fix | Delete
$mmode = get_option('mwp_maintenace_mode');
[464] Fix | Delete
[465] Fix | Delete
if (!empty($mmode) && isset($mmode['active']) && $mmode['active'] == true) {
[466] Fix | Delete
$stats['maintenance'] = true;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
if ($this->mmb_multisite) {
[470] Fix | Delete
$stats = array_merge($stats, $this->get_multisite_stats($stats));
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
return $stats;
[474] Fix | Delete
}
[475] Fix | Delete
[476] Fix | Delete
public function get_multisite_stats()
[477] Fix | Delete
{
[478] Fix | Delete
/** @var $wpdb wpdb */
[479] Fix | Delete
global $current_user, $wpdb;
[480] Fix | Delete
$user_blogs = get_blogs_of_user($current_user->ID);
[481] Fix | Delete
$network_blogs = (array)$wpdb->get_results("select `blog_id`, `site_id` from `{$wpdb->blogs}`");
[482] Fix | Delete
$user_id = !empty($GLOBALS['mwp_user_id']) ? $GLOBALS['mwp_user_id'] : false;
[483] Fix | Delete
$mainBlogId = defined('BLOG_ID_CURRENT_SITE') ? BLOG_ID_CURRENT_SITE : false;
[484] Fix | Delete
[485] Fix | Delete
if ($this->network_admin_install != '1' || !is_super_admin($user_id) || empty($network_blogs)) {
[486] Fix | Delete
return array();
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
$stats = array('network_blogs' => array(), 'other_blogs' => array());
[490] Fix | Delete
foreach ($network_blogs as $details) {
[491] Fix | Delete
if (($mainBlogId !== false && $details->blog_id == $mainBlogId) || ($mainBlogId === false && $details->site_id == $details->blog_id)) {
[492] Fix | Delete
continue;
[493] Fix | Delete
} else {
[494] Fix | Delete
$data = get_blog_details($details->blog_id);
[495] Fix | Delete
if (in_array($details->blog_id, array_keys($user_blogs))) {
[496] Fix | Delete
$stats['network_blogs'][] = $data->siteurl;
[497] Fix | Delete
} else {
[498] Fix | Delete
$user = get_users(
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function