<?php
/**
 * @package StaticHTMLOutput
 *
 * Copyright (c) 2011 Leon Stafford
 */

$ajax_nonce = wp_create_nonce( 'statichtmloutput' );

$tpl = new StaticHTMLOutput\TemplateHelper();

?>

<div class="wrap statichtmloutput">
  <?php if ( PHP_VERSION < 7.3 ) : ?>

   <div class="notice notice-error inline statichtmloutput-notice">
      <h2 class="title">Outdated PHP version detected</h2>
      <p>The current officially supported PHP versions can be found on <a href="http://php.net/supported-versions.php" target="_blank">PHP.net</a></p>

      <p>Whilst the plugin tries to work on the most common PHP environments, it currently requires PHP 5.6 or higher.</p>

      <p>StaticHTMLOutput requires at least PHP 7.3. If your hosting doesn't offer PHP 7.4 or at least PHP 7.3, find a better host!</p>

      <p>Your current PHP version is: <?php echo PHP_VERSION; ?></p>
    </div>

  <?php endif; ?>


  <?php if ( ! $this->wp_site->uploads_writable ) : ?>

   <div class="notice notice-error inline statichtmloutput-notice">
      <h2 class="title">Your uploads directory is not writable</h2>
      <p>Please ensure that <code><?php echo $this->wp_site->wp_uploads_path; ?></code>
            is writable by your webserver. 
    </p>
    </div>

  <?php endif; ?>

  <?php if ( ! $this->wp_site->curl_enabled ) : ?>

   <div class="notice notice-error inline statichtmloutput-notice">
      <h2 class="title">You need the cURL extension enabled on your web server</h2>
        <p> This is a library that allows the plugin to better export your static site out to services like GitHub, S3, Dropbox, BunnyCDN, etc. It's usually an easy fix to get this working. You can try Googling "How to enable cURL extension for PHP", along with the name of the environment you are using to run your WordPress site. This may be something like DigitalOcean, GoDaddy or LAMP, MAMP, WAMP for your webserver on your local computer. If you're still having trouble, the developer of this plugin is easger to help you get up and running. Please ask for help on our <a href="https://forum.statichtmloutput.com">forum</a>.</p>
    </div>

  <?php endif; ?>

  <?php if ( ! class_exists('DOMDocument') ) : ?>

   <div class="notice notice-error inline statichtmloutput-notice">
      <h2 class="title">You're missing a required PHP library (DOMDocument)</h2>
        <p> This is a library that is used to parse the HTML documents when StaticHTMLOutput crawls your site. It's usually an easy fix to get this working. You can try Googling "DOMDocument missing", along with the name of the environment you are using to run your WordPress site. This may be something like DigitalOcean, GoDaddy or LAMP, MAMP, WAMP for your webserver on your local computer. If you're still having trouble, the developer of this plugin is easger to help you get up and running. Please ask for help on our <a href="https://forum.statichtmloutput.com">forum</a>.</p>
    </div>

  <?php endif; ?>

  <?php if ( ! $this->wp_site->permalinks_set ) : ?>

   <div class="notice notice-error inline statichtmloutput-notice">
      <h2 class="title">You need to set your WordPress Pemalinks</h2>

        <p>Due to the nature of how static sites work, you'll need to have some kind of permalinks structure defined in your <a href="<?php echo admin_url( 'options-permalink.php' ); ?>">Permalink Settings</a> within WordPress. To learn more on how to do this, please see WordPress's official guide to the <a href="https://codex.wordpress.org/Settings_Permalinks_Screen">Settings Permalinks Screen</a>.</p>
    </div>

  <?php endif; ?>

  <h2 class="nav-tab-wrapper">
    <a href="#" class="nav-tab nav-tab-active">Deploy static website</a>
    <a href="#" class="nav-tab">Crawling</a>
    <a href="#" class="nav-tab">Processing</a>
    <a href="#" class="nav-tab">Advanced options</a>
    <a href="#" class="nav-tab">Logs</a>
  </h2>

  <!-- main form containing options that get sent -->
  <form id="general-options" class="options-form" method="post" action="">

    <!-- placeholder input fields to allow select menu deployment options to use existing behaviour -->
    <span class="hiddenExportOptions" style="display:none;">
      <?php $tpl->displayCheckbox($this, 'createZip', 'Create a ZIP file of your statically exported site, ready for you to manually deploy. Download link will appear in the Export Log below'); ?>
    </span>

    <?php

    function generateDeploymentMethodOptions() {
      $options = array(
        "folder" => array('Subdirectory on current server', 'free'),
        "blank1" => array("--- Manual Deployment ---", 'free'),
        "zip" => array('ZIP archive (.zip)'),
        "blank2" => array("--- Automated Deployment ---"),
        "s3" => array("Amazon S3"),
        "bitbucket" => array("Bitbucket"),
        "bunnycdn" => array("BunnyCDN"),
        "github" => array("GitHub Pages"),
        "gitlab" => array("GitLab"),
        "netlify" => array("Netlify"),
        "blank3" => array("--- Other Automated Deployments ---"),
        "ftp" => array("FTP"),
      );

      foreach ($options as $key => $value) {
            echo "<option value='$key'>$value[0]</option>";
      }
    }

    ?>

    <?php require_once(__DIR__ . '/tab_export.phtml'); ?>
    <?php require_once(__DIR__ . '/tab_crawling.phtml'); ?>
    <?php require_once(__DIR__ . '/tab_processing.phtml'); ?>
    <?php require_once(__DIR__ . '/tab_advanced.phtml'); ?>
    <?php require_once(__DIR__ . '/tab_logs.phtml'); ?>

    <br>

    <span class="submit" style="display:none;">
      <?php wp_nonce_field($this->onceAction) ?>
      <input id="formActionHiddenField" class="hiddenActionField" type="hidden" name="action" value="wp_static_html_output_ajax" />
      <input id="basedir" type="hidden" name="basedir" value="" />
      <input id="wp_site_url" type="hidden" name="wp_site_url" value="" />
      <input id="wp_uploads_path" type="hidden" name="wp_uploads_path" value="" />
      <input id="wp_uploads_url" type="hidden" name="wp_uploads_url" value="" />
      <input id="subdirectory" type="hidden" name="subdirectory" value="<?php echo $this->wp_site->subdirectory; ?>" />
      <input id="wp_site_path" type="hidden" name="wp_site_path" value="" />
      <input id="wp_inc" type="hidden" name="wp_inc" value="" />
      <input id="wp_active_theme" type="hidden" name="wp_active_theme" value="" />
      <input id="wp_uploads" type="hidden" name="wp_uploads" value="" />
      <input id="hiddenNonceField" type="hidden" name="nonce" value="<?php echo $ajax_nonce; ?>" />
      <input id="hiddenAJAXAction" type="hidden" name="ajax_action" value="" />
      <input name="staticExportSettings" class="hiddenSettingsField" type="hidden" name="action" value="" />
    </span>
  </form>

    </div>
  </div>

    <div id="statichtmloutput-footer">

          <div class="inside">

            <div class="submit">
              <?php wp_nonce_field($this->onceAction) ?>
              <button id="startExportButton" class="button-primary button-hero" disabled>Start static site export</button>
              <button class="saveSettingsButton button-secondary" disabled>Save current options</button>
              <button class="button resetDefaultSettingsButton" disabled>Reset to default settings</button>
              <button style="display:none;" class="button cancelExportButton">Cancel export</button>

              <a href="" id="downloadZIP"><button class="button button-secondary button-call-to-action" target="_blank">Download ZIP</button></a>

              <a href="#" class="button button-secondary button-call-to-action" target="_blank" id="goToMyStaticSite" style="display:none;">Go to my deployed site</a>

            </div>

        </div><!-- end inside -->

            <div id="pbar-container">
                <div id="pbar-fill">

                </div>

                <div id="progress-container">
                  <div id="progress">
                    <div class="pulsate-css"></div>
                    <div id="current_action">Starting export</div>
                  </div>

                  <p id="exportDuration" style="display:block;"></p>
                </div>
            </div>

    </div><!-- end statichtmloutput-footer -->

</div>
