Beispiel #1
0
 public static function doImport()
 {
     if (isset($_POST['select_by'])) {
         $selected_sites = array();
         if (isset($_POST['selected_sites']) && is_array($_POST['selected_sites'])) {
             foreach ($_POST['selected_sites'] as $selected) {
                 $selected_sites[] = $selected;
             }
         }
         $selected_groups = array();
         if (isset($_POST['selected_groups']) && is_array($_POST['selected_groups'])) {
             foreach ($_POST['selected_groups'] as $selected) {
                 $selected_groups[] = $selected;
             }
         }
     }
     $user_to_add = array('user_pass' => $_POST['pass1'], 'user_login' => $_POST['user_login'], 'user_url' => $_POST['url'], 'user_email' => $_POST['email'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'role' => $_POST['role']);
     $ret = array();
     $dbwebsites = array();
     $not_valid = array();
     $error_sites = '';
     if ($_POST['select_by'] == 'site') {
         //Get all selected websites
         foreach ($selected_sites as $url) {
             if (!empty($url)) {
                 $website = MainWP_DB::Instance()->getWebsitesByUrl($url);
                 if ($website) {
                     $dbwebsites[$website[0]->id] = MainWP_Utility::mapSite($website[0], array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                 } else {
                     $not_valid[] = __("Error - The website doesn't exist in the Network.", 'mainwp') . " " . $url;
                     $error_sites .= $url . ';';
                 }
             }
         }
     } else {
         //Get all websites from the selected groups
         foreach ($selected_groups as $group) {
             if (MainWP_DB::Instance()->getGroupsByName($group)) {
                 $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupName($group));
                 if ($websites) {
                     while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
                         $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                     }
                     @MainWP_DB::free_result($websites);
                 } else {
                     $not_valid[] = __('Error - These are not websites in the group. ', 'mainwp') . $group;
                     $error_sites .= $group . ';';
                 }
             } else {
                 $not_valid[] = __("Error - The group doesn't exist in the Network. ", 'mainwp') . $group;
                 $error_sites .= $group . ';';
             }
         }
     }
     if (count($dbwebsites) > 0) {
         $post_data = array('new_user' => base64_encode(serialize($user_to_add)), 'send_password' => isset($_POST['send_password']) ? $_POST['send_password'] : '');
         $output = new stdClass();
         $output->ok = array();
         $output->errors = array();
         MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'newuser', $post_data, array(MainWP_Bulk_Add::getClassName(), 'PostingBulk_handler'), $output);
     }
     $ret['ok_list'] = $ret['error_list'] = array();
     foreach ($dbwebsites as $website) {
         if (isset($output->ok[$website->id]) && $output->ok[$website->id] == 1) {
             $ret['ok_list'][] = 'New user(s) created: ' . stripslashes($website->name);
         } else {
             $ret['error_list'][] = $output->errors[$website->id] . ' ' . stripslashes($website->name);
             $error_sites .= $website->url . ';';
         }
     }
     foreach ($not_valid as $val) {
         $ret['error_list'][] = $val;
     }
     $ret['failed_logging'] = '';
     if (!empty($error_sites)) {
         $error_sites = rtrim($error_sites, ';');
         $ret['failed_logging'] = $_POST['user_login'] . ',' . $_POST['email'] . ',' . $_POST['first_name'] . ',' . $_POST['last_name'] . ',' . $_POST['url'] . ',' . $_POST['pass1'] . ',' . intval($_POST['send_password']) . ',' . $_POST['role'] . ',' . $error_sites . ',';
     }
     $ret['line_number'] = $_POST['line_number'];
     die(json_encode($ret));
 }
Beispiel #2
0
    public static function posting()
    {
        //Posts the saved sites
        ?>
		<div class="wrap">
			<h2>New Post</h2>
			<?php 
        do_action('mainwp_bulkpost_before_post', $_GET['id']);
        $skip_post = false;
        if (isset($_GET['id'])) {
            if ('yes' == get_post_meta($_GET['id'], '_mainwp_skip_posting', true)) {
                $skip_post = true;
                wp_delete_post($_GET['id'], true);
            }
        }
        if (!$skip_post) {
            if (isset($_GET['id'])) {
                $id = $_GET['id'];
                $post = get_post($id);
                if ($post) {
                    //                die('<pre>'.print_r($post, 1).'</pre>');
                    $selected_by = get_post_meta($id, '_selected_by', true);
                    $selected_sites = unserialize(base64_decode(get_post_meta($id, '_selected_sites', true)));
                    $selected_groups = unserialize(base64_decode(get_post_meta($id, '_selected_groups', true)));
                    /** @deprecated */
                    $post_category = base64_decode(get_post_meta($id, '_categories', true));
                    $post_tags = base64_decode(get_post_meta($id, '_tags', true));
                    $post_slug = base64_decode(get_post_meta($id, '_slug', true));
                    $post_custom = get_post_custom($id);
                    //                if (isset($post_custom['_tags'])) $post_custom['_tags'] = base64_decode(trim($post_custom['_tags']));
                    include_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'post-thumbnail-template.php';
                    $post_featured_image = get_post_thumbnail_id($id);
                    $mainwp_upload_dir = wp_upload_dir();
                    $new_post = array('post_title' => $post->post_title, 'post_content' => $post->post_content, 'post_status' => $post->post_status, 'post_date' => $post->post_date, 'post_date_gmt' => $post->post_date_gmt, 'post_tags' => $post_tags, 'post_name' => $post_slug, 'post_excerpt' => $post->post_excerpt, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'id_spin' => $post->ID);
                    if ($post_featured_image != null) {
                        //Featured image is set, retrieve URL
                        $img = wp_get_attachment_image_src($post_featured_image, 'full');
                        $post_featured_image = $img[0];
                    }
                    $dbwebsites = array();
                    if ($selected_by == 'site') {
                        //Get all selected websites
                        foreach ($selected_sites as $k) {
                            if (MainWP_Utility::ctype_digit($k)) {
                                $website = MainWP_DB::Instance()->getWebsiteById($k);
                                $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                            }
                        }
                    } else {
                        //Get all websites from the selected groups
                        foreach ($selected_groups as $k) {
                            if (MainWP_Utility::ctype_digit($k)) {
                                $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($k));
                                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->ok = array();
                    $output->errors = array();
                    $startTime = time();
                    if (count($dbwebsites) > 0) {
                        $post_data = array('new_post' => base64_encode(serialize($new_post)), 'post_custom' => base64_encode(serialize($post_custom)), 'post_category' => base64_encode($post_category), 'post_featured_image' => base64_encode($post_featured_image), 'mainwp_upload_dir' => base64_encode(serialize($mainwp_upload_dir)));
                        MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'newpost', $post_data, array(MainWP_Bulk_Add::getClassName(), 'PostingBulk_handler'), $output);
                    }
                    $failed_posts = array();
                    foreach ($dbwebsites as $website) {
                        if ($output->ok[$website->id] == 1 && isset($output->added_id[$website->id])) {
                            do_action('mainwp-post-posting-post', $website, $output->added_id[$website->id], isset($output->link[$website->id]) ? $output->link[$website->id] : null);
                            do_action('mainwp-bulkposting-done', $post, $website, $output);
                        } else {
                            $failed_posts[] = $website->id;
                        }
                    }
                    $del_post = true;
                    $saved_draft = get_post_meta($id, '_saved_as_draft', true);
                    if ($saved_draft == 'yes') {
                        if (count($failed_posts) > 0) {
                            $del_post = false;
                            update_post_meta($post->ID, '_selected_sites', base64_encode(serialize($failed_posts)));
                            update_post_meta($post->ID, '_selected_groups', '');
                            wp_update_post(array('ID' => $id, 'post_status' => 'draft'));
                        }
                    }
                    if ($del_post) {
                        wp_delete_post($id, true);
                    }
                    $countSites = 0;
                    $countRealItems = 0;
                    foreach ($dbwebsites as $website) {
                        if (isset($output->ok[$website->id]) && $output->ok[$website->id] == 1) {
                            $countSites++;
                            $countRealItems++;
                        }
                    }
                    if (!empty($countSites)) {
                        $seconds = time() - $startTime;
                        MainWP_Twitter::updateTwitterInfo('new_post', $countSites, $seconds, $countRealItems, $startTime, 1);
                    }
                    if (MainWP_Twitter::enabledTwitterMessages()) {
                        $twitters = MainWP_Twitter::getTwitterNotice('new_post');
                        if (is_array($twitters)) {
                            foreach ($twitters as $timeid => $twit_mess) {
                                if (!empty($twit_mess)) {
                                    $sendText = MainWP_Twitter::getTwitToSend('new_post', $timeid);
                                    ?>
										<div class="mainwp-tips mainwp_info-box-blue twitter">
											<span class="mainwp-tip" twit-what="new_post" twit-id="<?php 
                                    echo $timeid;
                                    ?>
"><?php 
                                    echo $twit_mess;
                                    ?>
</span>&nbsp;<?php 
                                    MainWP_Twitter::genTwitterButton($sendText);
                                    ?>
											<span><a href="#" class="mainwp-dismiss-twit"><i class="fa fa-times-circle"></i> <?php 
                                    _e('Dismiss', 'mainwp');
                                    ?>
												</a></span></div>
										<?php 
                                }
                            }
                        }
                    }
                    ?>

						<div id="message" class="updated">
							<?php 
                    foreach ($dbwebsites as $website) {
                        ?>
								<p>
									<a href="<?php 
                        echo admin_url('admin.php?page=managesites&dashboard=' . $website->id);
                        ?>
"><?php 
                        echo stripslashes($website->name);
                        ?>
</a>
									: <?php 
                        echo isset($output->ok[$website->id]) && $output->ok[$website->id] == 1 ? 'New post created. ' . '<a href="' . $output->link[$website->id] . '" target="_blank">View Post</a>' : 'ERROR: ' . $output->errors[$website->id];
                        ?>
								</p>
							<?php 
                    }
                    ?>
						</div>
						<?php 
                }
                // if ($post)
            } else {
                ?>
					<div class="error below-h2">
						<p>
							<strong><?php 
                _e('ERROR', 'mainwp');
                ?>
</strong>: <?php 
                _e('An undefined error occured.', 'mainwp');
                ?>
						</p>
					</div>
					<?php 
            }
        }
        // no skip posting
        ?>
			<br/>
			<a href="<?php 
        echo get_admin_url();
        ?>
admin.php?page=PostBulkAdd" class="add-new-h2" target="_top"><?php 
        _e('Add New', 'mainwp');
        ?>
</a>
			<a href="<?php 
        echo get_admin_url();
        ?>
admin.php?page=mainwp_tab" class="add-new-h2" target="_top"><?php 
        _e('Return
            to Dashboard', 'mainwp');
        ?>
</a>

		</div>
		<?php 
    }
    public static function render()
    {
        $show_form = true;
        if (isset($_POST['updateadminpassword'])) {
            check_admin_referer('mainwp_updateadminpassword', 'security');
            $errors = array();
            if (isset($_POST['select_by'])) {
                $selected_sites = array();
                if (isset($_POST['selected_sites']) && is_array($_POST['selected_sites'])) {
                    foreach ($_POST['selected_sites'] as $selected) {
                        $selected_sites[] = $selected;
                    }
                }
                $selected_groups = array();
                if (isset($_POST['selected_groups']) && is_array($_POST['selected_groups'])) {
                    foreach ($_POST['selected_groups'] as $selected) {
                        $selected_groups[] = $selected;
                    }
                }
                if ($_POST['select_by'] == 'group' && count($selected_groups) == 0 || $_POST['select_by'] == 'site' && count($selected_sites) == 0) {
                    $errors[] = __('Please select the sites or groups where you want to change the admin password.', 'mainwp');
                }
            } else {
                $errors[] = __('Please select whether you want to change the admin password for specific sites or groups.', 'mainwp');
            }
            if (!isset($_POST['pass1']) || $_POST['pass1'] == '' || !isset($_POST['pass2']) || $_POST['pass2'] == '') {
                $errors[] = __('Please enter the password twice.', 'mainwp');
            } else {
                if ($_POST['pass1'] != $_POST['pass2']) {
                    $errors[] = __('Please enter the same password in the two password fields.', 'mainwp');
                }
            }
            if (count($errors) == 0) {
                $show_form = false;
                $new_password = array('user_pass' => $_POST['pass1']);
                $dbwebsites = array();
                if ($_POST['select_by'] == 'site') {
                    //Get all selected websites
                    foreach ($selected_sites as $k) {
                        if (MainWP_Utility::ctype_digit($k)) {
                            $website = MainWP_DB::Instance()->getWebsiteById($k);
                            $dbwebsites[$website->id] = MainWP_Utility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                        }
                    }
                } else {
                    //Get all websites from the selected groups
                    foreach ($selected_groups as $k) {
                        if (MainWP_Utility::ctype_digit($k)) {
                            $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesByGroupId($k));
                            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 (count($dbwebsites) > 0) {
                    $post_data = array('new_password' => base64_encode(serialize($new_password)));
                    $output = new stdClass();
                    $output->ok = array();
                    $output->errors = array();
                    MainWP_Utility::fetchUrlsAuthed($dbwebsites, 'newadminpassword', $post_data, array(MainWP_Bulk_Add::getClassName(), 'PostingBulk_handler'), $output);
                }
            }
        }
        if (!$show_form) {
            //Added to..
            ?>
			<div class="wrap">
                <h2 id="add-new-user"><i class="fa fa-key"></i> Update Admin Passwords</h2>

				<div id="message" class="updated">
					<?php 
            foreach ($dbwebsites as $website) {
                ?>
						<p>
							<a href="<?php 
                echo admin_url('admin.php?page=managesites&dashboard=' . $website->id);
                ?>
"><?php 
                echo stripslashes($website->name);
                ?>
</a>: <?php 
                echo isset($output->ok[$website->id]) && $output->ok[$website->id] == 1 ? __('Admin password updated.', 'mainwp') : __('ERROR: ', 'mainwp') . $output->errors[$website->id];
                ?>
						</p>
					<?php 
            }
            ?>
				</div>
				<br/>
				<a href="<?php 
            echo get_admin_url();
            ?>
admin.php?page=UpdateAdminPasswords" class="add-new-h2" target="_top"><?php 
            _e('Update admin passwords', 'mainwp');
            ?>
</a>
				<a href="<?php 
            echo get_admin_url();
            ?>
admin.php?page=mainwp_tab" class="add-new-h2" target="_top"><?php 
            _e('Return to Dashboard', 'mainwp');
            ?>
</a>
			</div>
			<?php 
        } else {
            wp_enqueue_script('user-profile');
            // header in User page
            MainWP_User::renderHeader('UpdateAdminPasswords');
            ?>
			<form action="" method="post" name="createuser" id="createuser" class="add:users: validate">

				<input type="hidden" name="security" value="<?php 
            echo wp_create_nonce('mainwp_updateadminpassword');
            ?>
"/>

				<div class="mainwp_config_box_right">
					<?php 
            MainWP_UI::select_sites_box(__('Select Sites to Update', 'mainwp'));
            ?>
				</div>

				<div class="mainwp_config_box_left postbox mainwp-postbox">
					<h3 class="mainwp_box_title">
						<i class="fa fa-key"></i> <?php 
            _e('Bulk Update Administrator Passwords', 'mainwp');
            ?>
</h3>

					<div class="inside">
						<table class="form-table">
							<?php 
            global $wp_version;
            if (version_compare('4.3-alpha', $wp_version, '>=')) {
                ?>
								<tr class="form-field form-required">
									<th scope="row"><label for="pass1"><?php 
                _e('Enter New Password ', 'mainwp');
                ?>
											<br/><span class="description"><?php 
                _e('(twice, required)', 'mainwp');
                ?>
</span></label>
									</th>
									<td>
										<input name="user_login" type="hidden" id="user_login" value="admin">
										<input class="" name="pass1" type="password" id="pass1" autocomplete="off"/>
										<br/>
										<input class="" name="pass2" type="password" id="pass2" autocomplete="off"/>
										<br/>

										<div id="pass-strength-result" style="display: block;"><?php 
                _e('Strength indicator', 'mainwp');
                ?>
</div>
										<p class="description indicator-hint" style="clear:both;"><?php 
                _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).', 'mainwp');
                ?>
</p>
									</td>
								</tr>
							<?php 
            } else {
                ?>
								<tr class="form-field form-required user-pass1-wrap">
									<th scope="row">
										<label for="pass1">
											<?php 
                _e('New Password', 'mainwp');
                ?>
											<span class="description hide-if-js"><?php 
                _e('(required)');
                ?>
</span>
										</label>
									</th>
									<td>
										<input class="hidden" value=" "/><!-- #24364 workaround -->
										<!--                   			<button type="button" class="button button-secondary wp-generate-pw hide-if-no-js">--><?php 
                //_e( 'Show password' );
                ?>
<!--</button>-->
										<div class="wp-pwd123">
											<?php 
                $initial_password = wp_generate_password(24);
                ?>
											<span class="password-input-wrapper">
												<input type="password" name="pass1" id="pass1" class="regular-text" autocomplete="off" data-reveal="1" data-pw="<?php 
                echo esc_attr($initial_password);
                ?>
" aria-describedby="pass-strength-result"/>
											</span>
											<button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php 
                esc_attr_e('Hide password');
                ?>
">
												<span class="dashicons dashicons-hidden"></span>
												<span class="text"><?php 
                _e('Hide');
                ?>
</span>
											</button>
											<!--                   				<button type="button" class="button button-secondary wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="--><?php 
                //esc_attr_e( 'Cancel password change' );
                ?>
<!--">-->
											<!--                   					<span class="text">--><?php 
                //_e( 'Cancel' );
                ?>
<!--</span>-->
											<!--                                </button>-->
											<div style="display:none" id="pass-strength-result" aria-live="polite"></div>
										</div>
									</td>
								</tr>
								<tr class="form-field form-required user-pass2-wrap hide-if-js">
									<td scope="row"><label for="pass2"><?php 
                _e('Repeat Password');
                ?>
											<span class="description"><?php 
                _e('(required)');
                ?>
</span></label></td>
									<td>
										<input name="pass2" type="password" id="pass2" value="<?php 
                echo esc_attr($initial_password);
                ?>
" autocomplete="off"/>
									</td>
								</tr>
							<?php 
            }
            ?>
							<tr>
								<td colspan="2">
									<p class="description indicator-hint"><?php 
            _e('Hint: The password should be at least seven
                                characters long. To make it stronger, use upper and lower case letters, numbers and
                                symbols like ! " ? $ % ^ &amp; ).', 'mainwp');
            ?>
</p>
								</td>
							</tr>
							<tr>
								<td></td>
								<td colspan="2">
									<input type="submit" name="updateadminpassword" id="bulk_updateadminpassword" class="button-primary button button-hero" value="<?php 
            _e('Update Now', 'mainwp');
            ?>
"/>
								</td>
							</tr>
						</table>
					</div>
				</div>

			</form>
			<?php 
            MainWP_User::renderFooter('UpdateAdminPasswords');
        }
    }