Ejemplo n.º 1
0
 public function cache_add_context($page, $context)
 {
     MainWP_Cache::addContext($page, $context);
 }
Ejemplo n.º 2
0
    public static function renderTable($keyword, $dtsstart, $dtsstop, $status, $groups, $sites, $postId, $userId)
    {
        MainWP_Cache::initCache('Post');
        //Fetch all!
        //Build websites array
        $dbwebsites = array();
        if ($sites != '') {
            foreach ($sites as $k => $v) {
                if (MainWP_Utility::ctype_digit($v)) {
                    $website = MainWP_DB::Instance()->getWebsiteById($v);
                    $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                }
            }
        }
        if ($groups != '') {
            foreach ($groups as $k => $v) {
                if (MainWP_Utility::ctype_digit($v)) {
                    $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($v));
                    while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
                        if ($website->sync_errors != '') {
                            continue;
                        }
                        $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                    }
                    @MainWP_DB::free_result($websites);
                }
            }
        }
        $output = new stdClass();
        $output->errors = array();
        $output->posts = 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'));
            if (isset($postId) && $postId != '') {
                $post_data['postId'] = $postId;
            } else {
                if (isset($userId) && $userId != '') {
                    $post_data['userId'] = $userId;
                }
            }
            MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'get_all_posts', $post_data, array(MainWP_Post::getClassName(), 'PostsSearch_handler'), $output);
        }
        MainWP_Cache::addContext('Post', array('count' => $output->posts, 'keyword' => $keyword, 'dtsstart' => $dtsstart, 'dtsstop' => $dtsstop, 'status' => $status));
        //Sort if required
        if ($output->posts == 0) {
            ob_start();
            ?>
			<tr>
				<td colspan="9">No posts found</td>
			</tr>
			<?php 
            $newOutput = ob_get_clean();
            echo $newOutput;
            MainWP_Cache::addBody('Post', $newOutput);
            return;
        }
    }
Ejemplo n.º 3
0
    public static function renderTable($keyword, $status, $groups, $sites)
    {
        MainWP_Cache::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 (MainWP_Utility::ctype_digit($v)) {
                        $website = MainWP_DB::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 (MainWP_Utility::ctype_digit($v)) {
                        $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($v));
                        while ($websites && ($website = @MainWP_DB::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;
                            }
                        }
                        @MainWP_DB::free_result($websites);
                    }
                }
            }
        } else {
            //Fetch all!
            //Build websites array
            $dbwebsites = array();
            if ($sites != '') {
                foreach ($sites as $k => $v) {
                    if (MainWP_Utility::ctype_digit($v)) {
                        $website = MainWP_DB::Instance()->getWebsiteById($v);
                        $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                    }
                }
            }
            if ($groups != '') {
                foreach ($groups as $k => $v) {
                    if (MainWP_Utility::ctype_digit($v)) {
                        $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($v));
                        while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
                            if ($website->sync_errors != '') {
                                continue;
                            }
                            $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                        }
                        @MainWP_DB::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;
            }
            MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'get_all_themes', $post_data, array(MainWP_Themes::getClassName(), 'ThemesSearch_handler'), $output);
            if (count($output->errors) > 0) {
                foreach ($output->errors as $siteid => $error) {
                    echo '<strong>Error on ' . MainWP_Utility::getNiceURL($dbwebsites[$siteid]->url) . ': ' . $error . ' <br /></strong>';
                }
                echo '<br />';
            }
            if (count($output->errors) == count($dbwebsites)) {
                return;
            }
        }
        MainWP_Cache::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;
            MainWP_Cache::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" id="themes_fixedtable" style="width: auto; word-wrap: normal">
				<thead>
				<tr>
					<th class="headcol" style="text-align: center; border-bottom: 1px Solid #e1e1e1; font-size: 18px; z-index:999; padding: auto; width: 15em !important;"><?php 
        _e('Child Site / Theme', 'mainwp');
        ?>
						<p style="font-size: 10px; line-height: 12px;"><?php 
        _e('Click on the Theme Name to select the theme on all sites or click the Site URL to select all themes on the site.', 'mainwp');
        ?>
</p>
					</th>
					<?php 
        foreach ($themesVersion as $theme_name => $theme_title) {
            ?>
						<th height="100" style="padding: 5px;">
							<div style="max-width: 120px; text-align: center;" title="<?php 
            echo $theme_title;
            ?>
" >
								<input type="checkbox" value="<?php 
            echo $themes[$theme_name];
            ?>
" id="<?php 
            echo $theme_name;
            ?>
" version="<?php 
            echo $themesRealVersion[$theme_name];
            ?>
" class="mainwp_theme_check_all" style="display: none ;" />
								<label for="<?php 
            echo $theme_name;
            ?>
"><?php 
            echo $theme_title;
            ?>
</label>
							</div>
						</th>
						<?php 
        }
        ?>
				</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;
            ?>
"><?php 
            echo $site_url;
            ?>
</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>
		<script type="text/javascript">
			jQuery(document).ready(function() {
				jQuery("#themes_fixedtable").tableHeadFixer({"left" : 1});
			});
		</script>
		<?php 
        $newOutput = ob_get_clean();
        echo $newOutput;
        MainWP_Cache::addBody('Themes', $newOutput);
    }
Ejemplo n.º 4
0
    public static function renderTable($role, $groups, $sites, $search = null)
    {
        MainWP_Cache::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 (MainWP_Utility::ctype_digit($v)) {
                        $website = MainWP_DB::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 (MainWP_Utility::ctype_digit($v)) {
                        $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($v));
                        while ($websites && ($website = @MainWP_DB::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);
                            }
                        }
                        @MainWP_DB::free_result($websites);
                    }
                }
            }
        } else {
            //Fetch all!
            //Build websites array
            $dbwebsites = array();
            if ($sites != '') {
                foreach ($sites as $k => $v) {
                    if (MainWP_Utility::ctype_digit($v)) {
                        $website = MainWP_DB::Instance()->getWebsiteById($v);
                        $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                    }
                }
            }
            if ($groups != '') {
                foreach ($groups as $k => $v) {
                    if (MainWP_Utility::ctype_digit($v)) {
                        $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($v));
                        while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
                            if ($website->sync_errors != '') {
                                continue;
                            }
                            $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                        }
                        @MainWP_DB::free_result($websites);
                    }
                }
            }
            if ($role) {
                $post_data = array('role' => $role);
                MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'get_all_users', $post_data, array(MainWP_User::getClassName(), 'UsersSearch_handler'), $output);
            } else {
                if ($search !== null) {
                    $post_data = array('search' => '*' . trim($search) . '*', 'search_columns' => 'user_login,display_name,user_email');
                    MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'search_users', $post_data, array(MainWP_User::getClassName(), 'UsersSearch_handler'), $output);
                }
            }
        }
        MainWP_Cache::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;
            MainWP_Cache::addBody('Users', $newOutput);
            return;
        }
    }