function mainwp_twitter_dashboard_action()
 {
     $success = false;
     if (isset($_POST['actionName']) && isset($_POST['countSites']) && !empty($_POST['countSites'])) {
         $success = MainWPTwitter::updateTwitterInfo($_POST['actionName'], $_POST['countSites'], (int) $_POST['countSeconds'], isset($_POST['countRealItems']) ? $_POST['countRealItems'] : 0, time(), isset($_POST['countItems']) ? $_POST['countItems'] : 0);
     }
     if (isset($_POST['showNotice']) && !empty($_POST['showNotice'])) {
         if (MainWPTwitter::enabledTwitterMessages()) {
             $twitters = MainWPTwitter::getTwitterNotice($_POST['actionName']);
             $html = "";
             if (is_array($twitters)) {
                 foreach ($twitters as $timeid => $twit_mess) {
                     if (!empty($twit_mess)) {
                         $sendText = MainWPTwitter::getTwitToSend($_POST['actionName'], $timeid);
                         $html .= '<div class="mainwp-tips mainwp_info-box-blue twitter"><span class="mainwp-tip" twit-what="' . $_POST['actionName'] . '" twit-id="' . $timeid . '">' . $twit_mess . '</span>&nbsp;' . MainWPTwitter::genTwitterButton($sendText, false) . '<span><a href="#" class="mainwp-dismiss-twit" ><i class="fa fa-times-circle"></i>' . __('Dismiss', 'mainwp') . '</a></span></div>';
                     }
                 }
             }
             die($html);
         }
     } else {
         if ($success) {
             die('ok');
         }
     }
     die('');
 }
Beispiel #2
0
    public static function posting()
    {
        ?>
    <div class="wrap">
      <?php 
        //  Use this to add a new page. To bulk change pages click on the "Manage" tab.
        do_action("mainwp_bulkpage_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) {
            //Posts the saved sites
            if (isset($_GET['id'])) {
                $id = $_GET['id'];
                $post = get_post($id);
                if ($post) {
                    $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)));
                    $post_slug = base64_decode(get_post_meta($id, '_slug', true));
                    $post_custom = get_post_custom($id);
                    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_type' => 'page', '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 (MainWPUtility::ctype_digit($k)) {
                                $website = MainWPDB::Instance()->getWebsiteById($k);
                                $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                            }
                        }
                    } else {
                        //Get all websites from the selected groups
                        foreach ($selected_groups as $k) {
                            if (MainWPUtility::ctype_digit($k)) {
                                $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($k));
                                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->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_featured_image' => base64_encode($post_featured_image), 'mainwp_upload_dir' => base64_encode(serialize($mainwp_upload_dir)));
                        $post_data = apply_filters("mainwp_bulkpage_posting", $post_data, $id);
                        MainWPUtility::fetchUrlsAuthed($dbwebsites, 'newpost', $post_data, array(MainWPBulkAdd::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-page', $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;
                    foreach ($dbwebsites as $website) {
                        if (isset($output->ok[$website->id]) && $output->ok[$website->id] == 1) {
                            $countSites++;
                        }
                    }
                    if (!empty($countSites)) {
                        $seconds = time() - $startTime;
                        MainWPTwitter::updateTwitterInfo('new_page', $countSites, $seconds, 1, $startTime, 1);
                    }
                    if (MainWPTwitter::enabledTwitterMessages()) {
                        $twitters = MainWPTwitter::getTwitterNotice('new_page');
                        if (is_array($twitters)) {
                            foreach ($twitters as $timeid => $twit_mess) {
                                if (!empty($twit_mess)) {
                                    $sendText = MainWPTwitter::getTwitToSend('new_page', $timeid);
                                    ?>
                                    <div class="mainwp-tips mainwp_info-box-blue twitter"><span class="mainwp-tip" twit-what="new_page" twit-id="<?php 
                                    echo $timeid;
                                    ?>
"><?php 
                                    echo $twit_mess;
                                    ?>
</span>&nbsp;<?php 
                                    MainWPTwitter::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 page created. ' . "<a href=\"" . $output->link[$website->id] . "\"  target=\"_blank\">View Page</a>" : 'ERROR: ' . $output->errors[$website->id];
                    ?>
</p>
                    <?php 
                }
                ?>
                </div>
               
                <?php 
            } else {
                ?>
                <div class="error below-h2">
                    <p><strong>ERROR</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=PageBulkAdd" 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 
    }
Beispiel #3
0
    public static function doPost()
    {
        $errors = array();
        $errorFields = 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 you want to add the new user to.';
            }
        } else {
            $errors[] = 'Please select whether you want to add the user to specific sites or groups.';
        }
        if (!isset($_POST['user_login']) || $_POST['user_login'] == '') {
            $errorFields[] = 'user_login';
        }
        if (!isset($_POST['email']) || $_POST['email'] == '') {
            $errorFields[] = 'email';
        }
        if (!isset($_POST['pass1']) || $_POST['pass1'] == '' || !isset($_POST['pass2']) || $_POST['pass2'] == '') {
            $errorFields[] = 'pass1';
        } else {
            if ($_POST['pass1'] != $_POST['pass2']) {
                $errorFields[] = 'pass2';
            }
        }
        $allowed_roles = array('subscriber', 'administrator', 'editor', 'author', 'contributor');
        if (!isset($_POST['role']) || !in_array($_POST['role'], $allowed_roles)) {
            $errorFields[] = 'role';
        }
        if (count($errors) == 0 && count($errorFields) == 0) {
            $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']);
            $dbwebsites = array();
            if ($_POST['select_by'] == 'site') {
                //Get all selected websites
                foreach ($selected_sites as $k) {
                    if (MainWPUtility::ctype_digit($k)) {
                        $website = MainWPDB::Instance()->getWebsiteById($k);
                        $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                    }
                }
            } else {
                //Get all websites from the selected groups
                foreach ($selected_groups as $k) {
                    if (MainWPUtility::ctype_digit($k)) {
                        $websites = MainWPDB::Instance()->query(MainWPDB::Instance()->getSQLWebsitesByGroupId($k));
                        while ($websites && ($website = @MainWPDB::fetch_object($websites))) {
                            $dbwebsites[$website->id] = MainWPUtility::mapSite($website, array('id', 'url', 'name', 'adminname', 'nossl', 'privkey', 'nosslkey'));
                        }
                        @MainWPDB::free_result($websites);
                    }
                }
            }
            $startTime = time();
            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();
                MainWPUtility::fetchUrlsAuthed($dbwebsites, 'newuser', $post_data, array(MainWPBulkAdd::getClassName(), 'PostingBulk_handler'), $output);
            }
            $countSites = 0;
            foreach ($dbwebsites as $website) {
                if (isset($output->ok[$website->id]) && $output->ok[$website->id] == 1) {
                    $countSites++;
                }
            }
            if (!empty($countSites)) {
                $seconds = time() - $startTime;
                MainWPTwitter::updateTwitterInfo('create_new_user', $countSites, $seconds, 1, $startTime);
            }
            if (MainWPTwitter::enabledTwitterMessages()) {
                $twitters = MainWPTwitter::getTwitterNotice('create_new_user');
                if (is_array($twitters)) {
                    foreach ($twitters as $timeid => $twit_mess) {
                        if (!empty($twit_mess)) {
                            $sendText = MainWPTwitter::getTwitToSend('create_new_user', $timeid);
                            ?>
                            <div class="mainwp-tips mainwp_info-box-blue twitter"><span class="mainwp-tip" twit-what="create_new_user" twit-id="<?php 
                            echo $timeid;
                            ?>
"><?php 
                            echo $twit_mess;
                            ?>
</span>&nbsp;<?php 
                            MainWPTwitter::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 user created.' : 'ERROR: ' . $output->errors[$website->id];
                ?>
</p>
            <?php 
            }
            ?>
        </div>
        <br/>
        <a href="<?php 
            echo get_admin_url();
            ?>
admin.php?page=UserBulkAdd" 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>
        <?php 
        } else {
            echo 'ERROR ' . json_encode(array($errorFields, $errors));
        }
    }