public static function renderTable($keyword, $dtsstart, $dtsstop, $status, $groups, $sites) { MainWPCache::initCache('Page'); //Fetch all! //Build websites array $dbwebsites = array(); if ($sites != '') { foreach ($sites as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $website = MainWPDB::Instance()->getWebsiteById($v); $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } } } if ($groups != '') { foreach ($groups as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($v)); while ($websites && ($website = @MainWPDB::fetch_object($websites))) { if ($website->sync_errors != '') { continue; } $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } @MainWPDB::free_result($websites); } } } $output = new stdClass(); $output->errors = array(); $output->pages = 0; if (count($dbwebsites) > 0) { $post_data = array('keyword' => $keyword, 'dtsstart' => $dtsstart, 'dtsstop' => $dtsstop, 'status' => $status, 'maxRecords' => get_option('mainwp_maximumPosts') === false ? 50 : get_option('mainwp_maximumPosts')); MainWPUtility::fetchUrlsAuthed($dbwebsites, 'get_all_pages', $post_data, array(MainWPPage::getClassName(), 'PagesSearch_handler'), $output); } MainWPCache::addContext('Page', array('count' => $output->pages, 'keyword' => $keyword, 'dtsstart' => $dtsstart, 'dtsstop' => $dtsstop, 'status' => $status)); //Sort if required if ($output->pages == 0) { ob_start(); ?> <tr> <td colspan="7">No pages found</td> </tr> <?php $newOutput = ob_get_clean(); echo $newOutput; MainWPCache::addBody('Page', $newOutput); return; } }
public function cache_init($page) { MainWPCache::initCache($page); }
public static function renderTable($role, $groups, $sites, $search = null) { MainWPCache::initCache('Users'); $output = new stdClass(); $output->errors = array(); $output->users = 0; if (get_option('mainwp_optimize') == 1) { //Search in local cache if ($sites != '') { foreach ($sites as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $website = MainWPDB::Instance()->getWebsiteById($v); $allUsers = json_decode($website->users, true); for ($i = 0; $i < count($allUsers); $i++) { $user = $allUsers[$i]; if ($role) { $roles = explode(',', $_POST['role']); if (is_array($roles)) { $found = false; foreach ($roles as $role) { if (stristr($user['role'], $role)) { $found = true; break; } } if (!$found) { continue; } } else { continue; } } else { if ($search !== null) { if ($search != '' && !stristr($user['login'], trim($search)) && !stristr($user['display_name'], trim($search)) && !stristr($user['email'], trim($search))) { continue; } } else { continue; } } $tmpUsers = array($user); $output->users += self::usersSearchHandlerRenderer($tmpUsers, $website); } } } } if ($groups != '') { foreach ($groups as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($v)); while ($websites && ($website = @MainWPDB::fetch_object($websites))) { if ($website->sync_errors != '') { continue; } $allUsers = json_decode($website->users, true); for ($i = 0; $i < count($allUsers); $i++) { $user = $allUsers[$i]; if ($role) { $roles = explode(',', $_POST['role']); if (is_array($roles)) { $found = false; foreach ($roles as $role) { if (stristr($user['role'], $role)) { $found = true; break; } } if (!$found) { continue; } } else { continue; } } else { if ($search !== null) { if ($search != '' && !stristr($user['login'], trim($search)) && !stristr($user['display_name'], trim($search)) && !stristr($user['email'], trim($search))) { continue; } } else { continue; } } $tmpUsers = array($user); $output->users += self::usersSearchHandlerRenderer($tmpUsers, $website); } } @MainWPDB::free_result($websites); } } } } else { //Fetch all! //Build websites array $dbwebsites = array(); if ($sites != '') { foreach ($sites as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $website = MainWPDB::Instance()->getWebsiteById($v); $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } } } if ($groups != '') { foreach ($groups as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($v)); while ($websites && ($website = @MainWPDB::fetch_object($websites))) { if ($website->sync_errors != '') { continue; } $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } @MainWPDB::free_result($websites); } } } if ($role) { $post_data = array('role' => $role); MainWPUtility::fetchUrlsAuthed($dbwebsites, 'get_all_users', $post_data, array(MainWPUser::getClassName(), 'UsersSearch_handler'), $output); } else { if ($search !== null) { $post_data = array('search' => '*' . trim($search) . '*', 'search_columns' => 'user_login,display_name,user_email'); MainWPUtility::fetchUrlsAuthed($dbwebsites, 'search_users', $post_data, array(MainWPUser::getClassName(), 'UsersSearch_handler'), $output); } } } MainWPCache::addContext('Users', array('count' => $output->users, 'keyword' => $search, 'status' => isset($_POST['role']) ? $_POST['role'] : 'administrator')); //Sort if required if ($output->users == 0) { ob_start(); ?> <tr> <td colspan="7">No users found</td> </tr> <?php $newOutput = ob_get_clean(); echo $newOutput; MainWPCache::addBody('Users', $newOutput); return; } }
public static function renderTable($keyword, $status, $groups, $sites) { MainWPCache::initCache('Themes'); $output = new stdClass(); $output->errors = array(); $output->themes = array(); if (get_option('mainwp_optimize') == 1) { //Search in local cache if ($sites != '') { foreach ($sites as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $website = MainWPDB::Instance()->getWebsiteById($v); $allThemes = json_decode($website->themes, true); for ($i = 0; $i < count($allThemes); $i++) { $theme = $allThemes[$i]; if ($status == "active" || $status == "inactive") { if ($theme['active'] == 1 && $status !== "active") { continue; } else { if ($theme['active'] != 1 && $status !== "inactive") { continue; } } } if ($keyword != '' && !stristr($theme['title'], $keyword)) { continue; } $theme['websiteid'] = $website->id; $theme['websiteurl'] = $website->url; $output->themes[] = $theme; } } } } if ($groups != '') { foreach ($groups as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($v)); while ($websites && ($website = @MainWPDB::fetch_object($websites))) { if ($website->sync_errors != '') { continue; } $allThemes = json_decode($website->themes, true); for ($i = 0; $i < count($allThemes); $i++) { $theme = $allThemes[$i]; if ($status == "active" || $status == "inactive") { if ($theme['active'] == 1 && $status !== "active") { continue; } else { if ($theme['active'] != 1 && $status !== "inactive") { continue; } } } if ($keyword != '' && !stristr($theme['title'], $keyword)) { continue; } $theme['websiteid'] = $website->id; $theme['websiteurl'] = $website->url; $output->themes[] = $theme; } } @MainWPDB::free_result($websites); } } } } else { //Fetch all! //Build websites array $dbwebsites = array(); if ($sites != '') { foreach ($sites as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $website = MainWPDB::Instance()->getWebsiteById($v); $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } } } if ($groups != '') { foreach ($groups as $k => $v) { if (MainWPUtility::ctype_digit($v)) { $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($v)); while ($websites && ($website = @MainWPDB::fetch_object($websites))) { if ($website->sync_errors != '') { continue; } $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey')); } @MainWPDB::free_result($websites); } } } $post_data = array('keyword' => $keyword); if ($status == "active" || $status == "inactive") { $post_data['status'] = $status; $post_data['filter'] = true; } else { $post_data['status'] = ""; $post_data['filter'] = false; } MainWPUtility::fetchUrlsAuthed($dbwebsites, 'get_all_themes', $post_data, array(MainWPThemes::getClassName(), 'ThemesSearch_handler'), $output); if (count($output->errors) > 0) { foreach ($output->errors as $siteid => $error) { echo '<strong>Error on ' . MainWPUtility::getNiceURL($dbwebsites[$siteid]->url) . ': ' . $error . ' <br /></strong>'; } echo '<br />'; } if (count($output->errors) == count($dbwebsites)) { return; } } MainWPCache::addContext('Themes', array('keyword' => $keyword, 'the_status' => $status)); ob_start(); ?> <div class="alignleft"> <select name="bulk_action" id="mainwp_bulk_action"> <option value="none"><?php _e('Choose Action', 'mainwp'); ?> </option> <?php if ($status == 'inactive') { ?> <?php if (mainwp_current_user_can("dashboard", "activate_themes")) { ?> <option value="activate"><?php _e('Activate', 'mainwp'); ?> </option> <?php } ?> <?php if (mainwp_current_user_can("dashboard", "delete_themes")) { ?> <option value="delete"><?php _e('Delete', 'mainwp'); ?> </option> <?php } ?> <?php } ?> <?php if (mainwp_current_user_can("dashboard", "ignore_unignore_updates")) { ?> <option value="ignore_updates"><?php _e('Ignore Updates', 'mainwp'); ?> </option> <?php } ?> </select> <input type="button" name="" id="mainwp_bulk_theme_action_apply" class="button" value="<?php _e('Confirm', 'mainwp'); ?> "/> <span id="mainwp_bulk_action_loading"><i class="fa fa-spinner fa-pulse"></i></span> </div> <div class="clear"></div> <?php if (count($output->themes) == 0) { ?> No themes found <?php $newOutput = ob_get_clean(); echo $newOutput; MainWPCache::addBody('Themes', $newOutput); return; } //Map per siteId $sites = array(); //id -> url $siteThemes = array(); //site_id -> theme_version_name -> theme obj $themes = array(); //name_version -> name $themesVersion = array(); //name_version -> title_version $themesRealVersion = $themesSlug = array(); //name_version -> title_version foreach ($output->themes as $theme) { $sites[$theme['websiteid']] = $theme['websiteurl']; $themes[$theme['name'] . '_' . $theme['version']] = $theme['name']; $themesSlug[$theme['name'] . '_' . $theme['version']] = $theme['slug']; $themesVersion[$theme['name'] . '_' . $theme['version']] = $theme['title'] . ' ' . $theme['version']; $themesRealVersion[$theme['name'] . '_' . $theme['version']] = $theme['version']; if (!isset($siteThemes[$theme['websiteid']]) || !is_array($siteThemes[$theme['websiteid']])) { $siteThemes[$theme['websiteid']] = array(); } $siteThemes[$theme['websiteid']][$theme['name'] . '_' . $theme['version']] = $theme; } ?> <div id="mainwp-table-overflow" style="overflow: auto !important ;"> <table class="wp-list-table widefat fixed pages" style="width: auto; word-wrap: normal"> <thead> <tr> <th class="headcol"></th> <?php foreach ($themesVersion as $theme_name => $theme_title) { echo '<th style="height: 100px; padding: 5px ;"> <p style="font-family: Arial, Sans-Serif; text-shadow: none ; width: 100px !important; height: 30px ; text-align: center; width: auto; height: auto; font-size: 13px; -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -o-transform: rotate(-90deg); -ms-transform: rotate(-90deg); writing-mode: lr-tb; "> <input type="checkbox" value="' . $themes[$theme_name] . '" id="' . $theme_name . '" version="' . $themesRealVersion[$theme_name] . '" class="mainwp_theme_check_all" style="margin: 3px 0px 0px 0px; display: none ; " /> <label for="' . $theme_name . '">' . $theme_title . '</label> </p> </th>'; } ?> </tr> </thead> <tbody> <?php foreach ($sites as $site_id => $site_url) { ?> <tr> <td class="headcol"> <input class="websiteId" type="hidden" name="id" value="<?php echo $site_id; ?> "/> <label for="<?php echo $site_url; ?> "><strong><?php echo $site_url; ?> </strong></label> <input type="checkbox" value="" id="<?php echo $site_url; ?> " class="mainwp_site_check_all" style="display: none ;"/> </td> <?php foreach ($themesVersion as $theme_name => $theme_title) { echo '<td style="text-align: center">'; if (isset($siteThemes[$site_id]) && isset($siteThemes[$site_id][$theme_name])) { echo '<input type="checkbox" value="' . $themes[$theme_name] . '" version="' . $themesRealVersion[$theme_name] . '" slug="' . $themesSlug[$theme_name] . '" class="selected_theme" />'; } echo '</td>'; } ?> </tr> <?php } ?> </tbody> </table> </div> <?php $newOutput = ob_get_clean(); echo $newOutput; MainWPCache::addBody('Themes', $newOutput); }