/**
 * Render the page
 *
 * @since 0.8.5
 */
function mgjp_mv_render_extra_activation_steps_page()
{
    wp_enqueue_style('mgjp-mv-eas-page', plugins_url('css/mv-eas-page.css', __FILE__), 'all', null);
    global $is_apache;
    $home_path = get_home_path();
    $rewrite_rules_enabled = mgjp_mv_check_rewrite_rules();
    $eas_supported = $is_apache;
    if (isset($_POST['enable_mediavault'])) {
        if ($rewrite_rules_enabled) {
            check_admin_referer('mgjp_mv_enable_media_vault');
            ?>
        <div class="updated">
          <p>
            <?php 
            printf(esc_html__('Media Vault was successfully enabled! Congrats! Now go protect some %s!', 'media-vault'), '<a href="upload.php">' . esc_html__('files', 'media-vault') . '</a>');
            ?>
          </p>
        </div>
      <?php 
            update_site_option('mgjp_mv_enabled', true);
        } else {
            ?>
        <div class="error">
          <p>
            <?php 
            esc_html_e('Media Vault could not be enabled because the rewrite rules have not been set up correctly. Please verify that you have gone through and correctly completed each of the steps below and try again.', 'media-vault');
            ?>
          </p>
        </div>
      <?php 
        }
    }
    ?>

    <div class="wrap">

      <h2>
        <img class="mgjp-mv-icon" alt="Media Vault Logo" src="<?php 
    echo plugins_url('imgs/media-vault-logo.png', __FILE__);
    ?>
">
        <?php 
    _e('Media Vault Activation Helper', 'media-vault');
    ?>
      </h2>

      <?php 
    if ($rewrite_rules_enabled && get_site_option('mgjp_mv_enabled')) {
        ?>

        <p>
          <?php 
        printf(esc_html__('This page and the Media Vault Activation Helper will now no longer appear in your WordPress admin as you don\'t need them anymore! Congratulations, your setup is currently fully configured for Media Vault to function. You can now go and protect any of your %s or try %s to the Media Vault protected folder. Also don\'t forget to check out the plugin\'s %s. Thank you for using Media Vault.', 'media-vault'), '<a href="upload.php">' . esc_html__('Media files', 'media-vault') . '</a>', '<a href="media-new.php">' . esc_html__('uploading new files', 'media-vault') . '</a>', '<a href="options-media.php#mgjp_mv_settings_section">' . esc_html__('settings', 'media-vault') . '</a>');
        ?>
        </p>

        <?php 
        if (!$eas_supported) {
            ?>
          <p>
            <em>
              <?php 
            printf(esc_html__('Note: You have clearly successfully ported the Apache rewrite rules to run on your server technology, which was not supported by the Media Vault Activation Helper. If you are certain about your configuration, please consider posting the full method you used on the Media Vault %s. If such a post does not already exist of course! Thank you!', 'media-vault'), '<a href="http://wordpress.org/support/plugin/media-vault" target="_blank">' . esc_html__('support forum', 'media-vault') . '</a>');
            ?>
            </em>
          </p>
        <?php 
        }
        ?>

      <?php 
    } else {
        ?>

        <p>
          <?php 
        esc_html_e('Normally, Media Vault would automatically set up the necessary rewrite rules for the plugin to protect your files.', 'media-vault');
        echo ' ';
        if (!$is_apache) {
            $errors['Notapache'] = sprintf(esc_html_x('you are not on an %s', 'as in: "you are not on an Apache webserver"', 'media-vault'), '<b>Apache Server</b>');
        }
        if (is_multisite()) {
            $errors['Multisite'] = sprintf(esc_html_x('you are running a %s installation', 'as in: "you are on a WordPress Multisite installation"', 'media-vault'), '<b>WordPress MultiSite</b>');
        }
        if (!isset($errors) && !get_option('permalink_structure')) {
            $errors['Nopretty'] = sprintf(esc_html_x('you do not have %s enabled', 'as in: "you do not have Pretty Permalinks enabled"', 'media-vault'), '<a href="http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks" target="_blank">' . esc_html__('Pretty Permalinks') . '</a>');
        }
        if (!isset($errors) && !is_writable($home_path . '.htaccess')) {
            $errors['Nonwritable'] = sprintf(esc_html__('the site\'s %s file is not writable', 'as in: "the site\'s .htaccess file is not writable "', 'media-vault'), '<code>.htaccess</code>');
        }
        if (isset($errors)) {
            $error_txt = '';
            $last_error = array_pop($errors);
            if (count($errors) > 0) {
                $error_txt .= implode(', ', $errors) . ' ' . esc_html__('and', 'media-vault') . ' ';
            }
            $error_txt .= $last_error . ',';
            printf(esc_html_x('However, because %s the plugin was unable to successfully update the rewrite rules for this site programmatically.', 'as in: "Because *you are running WordPress MultiSite* Media Vault cannot do it automatically"', 'media-vault'), $error_txt);
        } else {
            esc_html_e('However for some reason the plugin was unable to successfully update the rewrite rules for this site.', 'media-vault');
        }
        echo ' ';
        echo wp_kses(__('In order to manually fully activate Media Vault on your setup please <strong>carefully</strong> follow the instructions below:', 'media-vault'), array('strong' => array()), false);
        ?>
        </p>

        <ol>

          <?php 
        if ($is_apache && !got_mod_rewrite()) {
            ?>
            <li>
              <p>
                <strong><?php 
            esc_html_e('Important', 'media-vault');
            ?>
!:</strong> <?php 
            printf(esc_html__('Media Vault %s the %s module to be installed and enabled on your %s server.', 'media-vault'), '<strong>' . esc_html__('requires') . '</strong>', '<code>mod_rewrite</code>', '<strong>Apache</strong>');
            ?>
              </p>
            </li>
          <?php 
        }
        ?>

          <li>

            <?php 
        if ($eas_supported) {
            ?>
              <p>
                <?php 
            $rewrite_file_type = '<code>.htaccess</code>';
            $rewrite_file_loc = '<code>' . $home_path . '</code>';
            $rewrite_rule_loc = sprintf(wp_kses(__('<strong>in the WordPress rewrite block</strong> (the WordPress block usually starts with %s and ends with %s), <strong>just below</strong> the line reading %s', 'media-vault'), array('strong' => array()), false), '<code># BEGIN WordPress</code>', '<code># END WordPress</code>', '<code>RewriteRule ^index\\.php$ - [L]</code>');
            if (!is_multisite() && !get_option('permalink_structure')) {
                $rewrite_rule_loc = __('<strong>above</strong> any other rewrite rules in the file.', 'media-vault');
                printf(wp_kses(__('Media Vault works best with %s enabled, so it is strongly recommended that you %s! If, however, you really <i>really</i> want to use ugly permalinks, then...', 'media-vault'), array('i' => array()), false), '<a href="http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks" target="_blank">' . esc_html__('Pretty Permalinks', 'media-vault') . '</a>', '<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">' . esc_html__('enable them', 'media-vault') . '</a>');
                echo "\n";
            }
            printf(esc_html__('Add the following to your %s file in %s', 'media-vault'), $rewrite_file_type, $rewrite_file_loc);
            echo ' ', $rewrite_rule_loc;
            ?>
              </p>
            <?php 
        } else {
            ?>
              <p>
                <?php 
            esc_html_e('Sorry, the Media Vault Activation Helper does not currently support your server setup. This does not necessarily mean that Media Vault cannot work with your setup, just that, for now, there are no simple steps to follow. Currently Apache is the only server software that is supported by the Activation Helper. Support for more is being added in future updates of the plugin. You can try the plugin\'s support forum for more help.', 'media-vault');
            ?>
              </p>
              <p>
                <?php 
            esc_html_e('Below are what the rewrite rules would look like if you were running WordPress on an Apache server. Feel free to try and port these to your own server technology. If you believe you have correctly set up the necessary rewrites to emulate the behaviour of the below rules, then click on the "Enable Media Vault" button below. If Media Vault verifies that the rules you implemented are functioning correctly it will enable the rest of the plugin.', 'media-vault');
            ?>
              </p>
            <?php 
        }
        ?>

            <?php 
        $rewrite_rules = mgjp_mv_get_the_rewrite_rules();
        ?>
            <textarea class="code" readonly="readonly" cols="125" rows="<?php 
        echo count($rewrite_rules);
        ?>
"><?php 
        echo esc_textarea(implode("\n", $rewrite_rules));
        ?>
</textarea>

          </li>

          <li>
            <p>
              <?php 
        esc_html_e('Once you have completed the above steps, press the "Enable Media Vault" button below.', 'media-vault');
        ?>
            </p>
            <form method="post" action="plugins.php?page=mgjp-mv-eas">
              <?php 
        wp_nonce_field('mgjp_mv_enable_media_vault');
        ?>
              <?php 
        submit_button(__('Enable Media Vault', 'media-vault'), 'primary', 'enable_mediavault', false);
        ?>
            </form>
          </li>

        </ol>

      <?php 
    }
    ?>

    </div>

  <?php 
}
 /**
  * Verifies that the rewrite rules required for Media Vault
  * to function correctly are set and functioning. If they are
  * it enables all the plugin's functionality and sets the
  * force_reload flag for the update class
  *
  * @since 0.8.5
  *
  * @uses mgjp_mv_check_rewrite_rules()
  */
 function update_085()
 {
     if (!mgjp_mv_check_rewrite_rules()) {
         return;
     }
     update_site_option('mgjp_mv_enabled', true);
     $this->force_reload = true;
 }
/**
 * Checks whether Media Vault requires extra
 * deactivation steps before it can be correctly
 * deactivated
 *
 * @since 0.8.5
 *
 * @return bool true
 *              false
 */
function mgjp_mv_is_deactivation_allowed()
{
    if ('temp' === get_site_option('mgjp_mv_deactivation')) {
        return true;
    }
    global $is_apache;
    if ($is_apache && !is_multisite() && get_option('permalink_structure') && is_writable(get_home_path() . '.htaccess')) {
        return true;
    }
    if (!mgjp_mv_check_rewrite_rules(true)) {
        return true;
    }
    return false;
}
/**
 * Render the page
 *
 * @since 0.8.5
 */
function mgjp_mv_render_extra_deactivation_steps_page()
{
    wp_enqueue_style('mgjp-mv-eas-page', plugins_url('css/mv-eas-page.css', __FILE__), 'all', null);
    global $is_apache;
    $home_path = get_home_path();
    $rewrite_rules_enabled = mgjp_mv_check_rewrite_rules(true);
    $eds_supported = $is_apache;
    if (isset($_POST['true_deactivation'])) {
        if ($rewrite_rules_enabled) {
            ?>
        <div class="error">
          <p>
            <?php 
            echo wp_kses(__('<em>At least one Media Vault rewrite rule is still functional.</em> Media Vault will not be properly deactivated if the rewrite rules are not removed because they <strong>will</strong> cause problems when attempting to access files that are in the Media Vault protected folders.', 'media-vault'), array('em' => array(), 'strong' => array()));
            ?>
          </p>
          <p>
            <?php 
            esc_html_e('Please either verify that you have gone through and correctly completed each of the steps below and try again, or click the "Temporarily Deactivate Media Vault" button if you do not want to remove the rules and will re-activate the plugin again soon.', 'media-vault');
            ?>
          </p>
        </div>
      <?php 
        } else {
            check_admin_referer('mgjp_mv_deactivation');
            update_site_option('mgjp_mv_deactivation', 'allowed');
        }
    } else {
        if (isset($_POST['temp_deactivation'])) {
            check_admin_referer('mgjp_mv_deactivation');
            update_site_option('mgjp_mv_deactivation', 'temp');
        }
    }
    if (in_array(get_site_option('mgjp_mv_deactivation'), array('allowed', 'temp'))) {
        $plugin = mgjp_mv_get_dirfile();
        $nonce = wp_create_nonce("deactivate-plugin_{$plugin}");
        $location = 'plugins.php?action=deactivate&plugin=' . urlencode($plugin) . "&_wpnonce={$nonce}";
        wp_redirect(network_admin_url($location));
        exit;
    }
    if (isset($_REQUEST['cancel_deactivation'])) {
        check_admin_referer('mgjp_mv_deactivation');
        delete_site_option('mgjp_mv_deactivation');
        wp_redirect(network_admin_url('plugins.php'));
        exit;
    }
    ?>

    <div class="wrap">

      <h2>
        <img class="mgjp-mv-icon" alt="Media Vault Logo" src="<?php 
    echo plugins_url('imgs/media-vault-logo.png', __FILE__);
    ?>
">
        <?php 
    _e('Media Vault Deactivation Helper', 'media-vault');
    ?>
      </h2>

      <p>
        <?php 
    esc_html_e('Normally, the Media Vault rewrite rules would be automatically removed when the plugin is deactivated.', 'media-vault');
    echo ' ';
    if (!$is_apache) {
        $errors['Notapache'] = sprintf(esc_html_x('you are not on an %s', 'as in: "you are not on an Apache webserver"', 'media-vault'), '<b>Apache Server</b>');
    }
    if (is_multisite()) {
        $errors['Multisite'] = sprintf(esc_html_x('you are running a %s installation', 'as in: "you are on a WordPress Multisite installation"', 'media-vault'), '<b>WordPress MultiSite</b>');
    }
    if (!isset($errors) && !get_option('permalink_structure')) {
        $errors['Nopretty'] = sprintf(esc_html_x('you do not have %s enabled', 'as in: "you do not have Pretty Permalinks enabled"', 'media-vault'), '<a href="http://codex.wordpress.org/Introduction_to_Blogging#Pretty_Permalinks" target="_blank">' . esc_html__('Pretty Permalinks') . '</a>');
    }
    if (!isset($errors) && !is_writable($home_path . '.htaccess')) {
        $errors['Nonwritable'] = sprintf(esc_html__('the site\'s %s file is not writable', 'as in: "the site\'s .htaccess file is not writable "', 'media-vault'), '<code>.htaccess</code>');
    }
    if (isset($errors)) {
        $error_txt = '';
        $last_error = array_pop($errors);
        if (count($errors) > 0) {
            $error_txt .= implode(', ', $errors) . ' ' . esc_html__('and', 'media-vault') . ' ';
        }
        $error_txt .= $last_error . ',';
        printf(esc_html_x('However, because %s the plugin was unable to successfully update the rewrite rules for this site programmatically.', 'as in: "Because *you are running WordPress MultiSite* Media Vault cannot do it automatically"', 'media-vault'), $error_txt);
    } else {
        esc_html_e('However for some reason the plugin was unable to successfully update the rewrite rules for this site.', 'media-vault');
    }
    printf(wp_kses(__('In order to manually fully %s Media Vault on your setup please <strong>carefully</strong> follow the instructions below:', 'media-vault'), array('strong' => array()), false), 'deactivate');
    ?>
      </p>
      <p>
        <em>
          <?php 
    echo wp_kses(__('If you want to <strong>temporarily</strong> deactivate Media Vault and do not mind leaving the rewrite rules functioning, simply click the "Temporarily Deactivate Media Vault" button. <strong>However, if you are planning on permanently deactivating Media Vault make sure to follow the steps below, otherwise you may experience problems when trying to access attachment files still in the Media Vault protected folders.</strong>', 'media-vault'), array('strong' => array()));
    ?>
        </em>
      </p>

      <ol>

        <li>
          <?php 
    if ($eds_supported) {
        ?>
            <p>
              <?php 
        $rewrite_file_type = '<code>.htaccess</code>';
        $rewrite_file_loc = '<code>' . $home_path . '</code>';
        printf(wp_kses(__('From your %s file in %s, remove <strong>all</strong> the code between the lines starting with %s and ending with %s.', 'media-vault'), array('strong' => array())), $rewrite_file_type, $rewrite_file_loc, '<code># Media Vault Rewrite Rules</code>', '<code># Media Vault Rewrite Rules End</code>');
        ?>
            </p>
          <?php 
    } else {
        ?>
            <p>
              <?php 
        printf(esc_html__('In order to fully deactivate Media Vault you are going to need to remove (or comment out) all the rewrite rules you had set up to enable the plugin when you activated it. Sorry these instructions are not more specific but the Media Vault Deactivation Helper does not yet support your setup. If you have additional questions you can try asking them on the plugin\'s %s', 'media-vault'), '<a href="http://wordpress.org/plugins/media-vault/support/" target="_blank">' . esc_html__('support forum', 'media-vault') . '</a>');
        ?>
            </p>
          <?php 
    }
    ?>
        </li>

        <li>
          <p>
            <?php 
    _e('Once you have completed the above steps, press the "Deactivate Media Vault" button below to deactivate Media Vault.', 'media-vault');
    ?>
          </p>
          <form method="post" action="plugins.php?page=mgjp-mv-eds">
            <?php 
    wp_nonce_field('mgjp_mv_deactivation');
    ?>
            <?php 
    submit_button(__('Deactivate Media Vault', 'media-vault'), 'primary', 'true_deactivation', false);
    ?>
            <?php 
    submit_button(__('Temporarily Deactivate Media Vault', 'media-vault'), '', 'temp_deactivation', false);
    ?>
            <?php 
    submit_button(__('Cancel Deactivation', 'media-vault'), 'primary', 'cancel_deactivation', false);
    ?>
          </form>
        </li>

      </ol>

    </div>

  <?php 
}