Example #1
0
 public function cache_add_body($page, $body)
 {
     MainWP_Cache::addBody($page, $body);
 }
Example #2
0
    public static function PostsSearch_handler($data, $website, &$output)
    {
        if (preg_match('/<mainwp>(.*)<\\/mainwp>/', $data, $results) > 0) {
            $posts = unserialize(base64_decode($results[1]));
            unset($results);
            foreach ($posts as $post) {
                if (isset($post['dts'])) {
                    if (!stristr($post['dts'], '-')) {
                        $post['dts'] = MainWP_Utility::formatTimestamp(MainWP_Utility::getTimestamp($post['dts']));
                    }
                }
                if (!isset($post['title']) || $post['title'] == '') {
                    $post['title'] = '(No Title)';
                }
                ob_start();
                ?>
				<tr id="post-1"
					class="post-1 post type-post status-publish format-standard hentry category-uncategorized alternate iedit author-self"
					valign="top">
					<th scope="row" class="check-column"><input type="checkbox" name="post[]" value="1"></th>
					<td class="post-title page-title column-title">
						<input class="postId" type="hidden" name="id" value="<?php 
                echo $post['id'];
                ?>
"/>
						<input class="allowedBulkActions" type="hidden" name="allowedBulkActions" value="|trash|delete|<?php 
                if ($post['status'] == 'publish') {
                    echo 'unpublish|';
                }
                if ($post['status'] == 'pending') {
                    echo 'approve|';
                }
                if ($post['status'] == 'trash') {
                    echo 'restore|';
                }
                if ($post['status'] == 'future' || $post['status'] == 'draft') {
                    echo 'publish|';
                }
                ?>
"/>
						<input class="websiteId" type="hidden" name="id" value="<?php 
                echo $website->id;
                ?>
"/>

						<strong>
							<abbr title="<?php 
                echo $post['title'];
                ?>
">
								<?php 
                if ($post['status'] != 'trash') {
                    ?>
									<a class="row-title"
										href="admin.php?page=SiteOpen&websiteid=<?php 
                    echo $website->id;
                    ?>
&location=<?php 
                    echo base64_encode('post.php?post=' . $post['id'] . '&action=edit');
                    ?>
"
										title="Edit '<?php 
                    echo $post['title'];
                    ?>
'"><?php 
                    echo $post['title'];
                    ?>
</a>
								<?php 
                } else {
                    ?>
									<?php 
                    echo $post['title'];
                    ?>
								<?php 
                }
                ?>
							</abbr>
						</strong>

						<div class="row-actions">
							<?php 
                if ($post['status'] != 'trash') {
                    ?>
								<span class="edit"><a
										href="admin.php?page=SiteOpen&websiteid=<?php 
                    echo $website->id;
                    ?>
&location=<?php 
                    echo base64_encode('post.php?post=' . $post['id'] . '&action=edit');
                    ?>
"
										title="Edit this item"><?php 
                    _e('Edit', 'mainwp');
                    ?>
</a></span>
								<span class="trash">
                            | <a class="post_submitdelete" title="Move this item to the Trash" href="#"><?php 
                    _e('Trash', 'mainwp');
                    ?>
</a>
                        </span>
							<?php 
                }
                ?>

							<?php 
                if ($post['status'] == 'future' || $post['status'] == 'draft') {
                    ?>
								<span class="publish">
                            | <a class="post_submitpublish" title="Publish this item" href="#"><?php 
                    _e('Publish', 'mainwp');
                    ?>
</a>
                        </span>
							<?php 
                }
                ?>

							<?php 
                if ($post['status'] == 'pending') {
                    ?>
								<span class="post-approve">
                            | <a class="post_submitapprove" title="Approve this item" href="#"><?php 
                    _e('Approve', 'mainwp');
                    ?>
</a>
                        </span>
							<?php 
                }
                ?>

							<?php 
                if ($post['status'] == 'publish') {
                    ?>
								<span class="view">
                            | <a
										href="<?php 
                    echo $website->url . (substr($website->url, -1) != '/' ? '/' : '') . '?p=' . $post['id'];
                    ?>
"
										target="_blank" title="View “<?php 
                    echo $post['title'];
                    ?>
�?" rel="permalink"><?php 
                    _e('View', 'mainwp');
                    ?>
</a>
                        </span>
								<span class="unpublish">
                            | <a class="post_submitunpublish" title="Unpublish this item" href="#"><?php 
                    _e('Unpublish', 'mainwp');
                    ?>
</a>
                        </span>
							<?php 
                }
                ?>

							<?php 
                if ($post['status'] == 'trash') {
                    ?>
								<span class="restore">
                           <a class="post_submitrestore" title="Restore this item" href="#"><?php 
                    _e('Restore', 'mainwp');
                    ?>
</a>
                        </span>
								<span class="trash">
                            | <a class="post_submitdelete_perm" title="Delete this item permanently" href="#"><?php 
                    _e('Delete
                            Permanently', 'mainwp');
                    ?>
</a>
                        </span>
							<?php 
                }
                ?>
						</div>
						<div class="row-actions-working">
							<i class="fa fa-spinner fa-pulse"></i> <?php 
                _e('Please wait', 'mainwp');
                ?>
</div>
					</td>
					<td class="author column-author">
						<?php 
                echo $post['author'];
                ?>
					</td>
					<td class="categories column-categories">
						<?php 
                echo $post['categories'];
                ?>
					</td>
					<td class="tags column-tags"><?php 
                echo $post['tags'] == '' ? 'No Tags' : $post['tags'];
                ?>
</td>
					<td class="comments column-comments">
						<div class="post-com-count-wrapper">
							<a href="<?php 
                echo admin_url('admin.php?page=CommentBulkManage&siteid=' . $website->id . '&postid=' . $post['id']);
                ?>
" title="0 pending" class="post-com-count"><span
									class="comment-count"><abbr title="<?php 
                echo $post['comment_count'];
                ?>
"><?php 
                echo $post['comment_count'];
                ?>
</abbr></span></a>
						</div>
					</td>
					<td class="date column-date"><abbr
							title="<?php 
                echo $post['dts'];
                ?>
"><?php 
                echo $post['dts'];
                ?>
</abbr>
					</td>
					<td class="date column-status"><?php 
                echo self::getStatus($post['status']);
                ?>
</td>
					<td class="categories column-categories">
						<a href="<?php 
                echo $website->url;
                ?>
" target="_blank"><?php 
                echo $website->url;
                ?>
</a>

						<div class="row-actions">
							<span class="edit"><a href="admin.php?page=managesites&dashboard=<?php 
                echo $website->id;
                ?>
"><?php 
                _e('Dashboard', 'mainwp');
                ?>
</a> | <a href="admin.php?page=SiteOpen&websiteid=<?php 
                echo $website->id;
                ?>
"><?php 
                _e('WP Admin', 'mainwp');
                ?>
</a></span>
						</div>
					</td>
				</tr>
				<?php 
                $newOutput = ob_get_clean();
                echo $newOutput;
                MainWP_Cache::addBody('Post', $newOutput);
                $output->posts++;
            }
            unset($posts);
        } else {
            $output->errors[$website->id] = MainWP_Error_Helper::getErrorMessage(new MainWP_Exception('NOMAINWP', $website->url));
        }
    }
Example #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);
    }
Example #4
0
    protected static function usersSearchHandlerRenderer($users, $website)
    {
        $return = 0;
        foreach ($users as $user) {
            ob_start();
            ?>
			<tr id="user-1" class="alternate">
				<th scope="row" class="check-column"><input type="checkbox" name="user[]" value="1"></th>
				<td class="username column-username">
					<input class="userId" type="hidden" name="id" value="<?php 
            echo $user['id'];
            ?>
"/>
					<input class="userName" type="hidden" name="name" value="<?php 
            echo $user['login'];
            ?>
"/>
					<input class="websiteId" type="hidden" name="id"
						value="<?php 
            echo $website->id;
            ?>
"/>

					<?php 
            if (isset($user['avatar'])) {
                echo $user['avatar'];
            }
            ?>
					<strong><abbr title="<?php 
            echo $user['login'];
            ?>
"><?php 
            echo $user['login'];
            ?>
</abbr></strong>

					<div class="row-actions">
                    <span class="edit"><a
		                    href="admin.php?page=SiteOpen&websiteid=<?php 
            echo $website->id;
            ?>
&location=<?php 
            echo base64_encode('user-edit.php?user_id=' . $user['id']);
            ?>
"
		                    title="Edit this user"><?php 
            _e('Edit', 'mainwp');
            ?>
</a>
                    </span>
						<?php 
            if ($user['id'] != 1 && $user['login'] != $website->adminname) {
                ?>
							<span class="trash">
                        | <a class="user_submitdelete" title="Delete this user" href="#"><?php 
                _e('Delete', 'mainwp');
                ?>
</a>
                    </span>
						<?php 
            } else {
                if ($user['id'] == 1 || $user['login'] == $website->adminname) {
                    ?>
							<span class="trash">
                        | <span title="This user is used for our secure link, it can not be deleted." style="color: gray"><?php 
                    _e('Delete', 'mainwp');
                    ?>
&nbsp;&nbsp;<?php 
                    MainWP_Utility::renderToolTip(__('This user is used for our secure link, it can not be deleted.', 'mainwp'), 'http://docs.mainwp.com/deleting-secure-link-admin', 'images/info.png', 'float: none !important;');
                    ?>
</span>
                    </span>
						<?php 
                }
            }
            ?>
					</div>
					<div class="row-actions-working">
						<i class="fa fa-spinner fa-pulse"></i> <?php 
            _e('Please wait', 'mainwp');
            ?>
					</div>
				</td>
				<td class="name column-name"><?php 
            echo $user['display_name'];
            ?>
</td>
				<td class="email column-email"><a
						href="mailto:<?php 
            echo $user['email'];
            ?>
"><?php 
            echo $user['email'];
            ?>
</a></td>
				<td class="role column-role"><?php 
            echo self::getRole($user['role']);
            ?>
</td>
				<td class="posts column-posts" style="text-align: left; padding-left: 1.7em ;">
					<a href="<?php 
            echo admin_url('admin.php?page=PostBulkManage&siteid=' . $website->id . '&userid=' . $user['id']);
            ?>
"><?php 
            echo $user['post_count'];
            ?>
</a>
				</td>
				<td class="website column-website"><a
						href="<?php 
            echo $website->url;
            ?>
"><?php 
            echo $website->url;
            ?>
</a>

					<div class="row-actions">
						<span class="edit"><a href="admin.php?page=managesites&dashboard=<?php 
            echo $website->id;
            ?>
"><?php 
            _e('Dashboard', 'mainwp');
            ?>
</a> | <a href="admin.php?page=SiteOpen&websiteid=<?php 
            echo $website->id;
            ?>
"><?php 
            _e('WP Admin', 'mainwp');
            ?>
</a></span>
					</div>
				</td>
			</tr>
			<?php 
            $newOutput = ob_get_clean();
            echo $newOutput;
            MainWP_Cache::addBody('Users', $newOutput);
            $return++;
        }
        return $return;
    }