コード例 #1
0
function x_addons_product_validation()
{
    if (isset($_POST['validate']) && check_admin_referer('x-addons-product-validation')) {
        if (strip_tags($_POST['x_addons_product_validation_submitted']) == 'submitted') {
            //
            // If $input is set and an empty string, delete the option and provide a
            // message to confirm that the key has been removed.
            //
            // Else, check the value returned by $response['code'] and provide an
            // appropriate action and message.
            //
            // $response['code'] == 1 - Success
            // $response['code'] == 2 - General Error
            // $response['code'] == 3 - Invalid API Key
            // $response['code'] == 4 - Connection Error
            //
            $name = x_addons_get_api_key_option_name();
            $input = strip_tags($_POST[$name]);
            if (isset($input) && $input == '') {
                delete_option($name);
                echo '<div class="updated"><p>API key removed successfully!</p></div>';
            } else {
                $response = X_Update_API::validate_key($input);
                if ($response['code'] == 2 || $response['code'] == 3 || $response['code'] == 4) {
                    delete_option($name);
                    echo '<div class="error"><p>' . $response['message'] . '</p></div>';
                    if (isset($_GET['x-verbose']) && $_GET['x-verbose'] == 1) {
                        x_dump(X_Update_API::get_errors(), 350, 'var_dump');
                    }
                } else {
                    update_option($name, $input);
                    echo '<div class="updated"><p>' . $response['message'] . '</p></div>';
                }
            }
            delete_site_option('x_addon_list_cache');
        }
    }
}
コード例 #2
0
function x_addons_page_extensions()
{
    ?>

  <?php 
    //
    // Allow cache to be cleared manually.
    //
    if (isset($_GET['force-check']) && $_GET['force-check'] == 1) {
        delete_site_option('x_addon_list_cache');
    }
    //
    // Retrieve addons from cache, or check immediately if they were just cleared.
    //
    $addons_cache = X_Update_API::get_cached_addons();
    //
    // Show connection errors on screen.
    //
    if (isset($_GET['x-verbose']) && $_GET['x-verbose'] == 1) {
        delete_site_option('x_addon_list_cache');
        x_dump(X_Update_API::get_errors(), 350, 'var_dump');
    }
    ?>

  <div class="wrap x-addons-extensions">

    <header class="x-addons-header">
      <h2>Extensions</h2>
      <p>Custom and third party plugins you can use for free (over $1,000 in value) with updates!</p>

      <?php 
    if (isset($addons_cache['error']) && $addons_cache['error']) {
        ?>
        <div class="error"><p><?php 
        echo $addons_cache['message'];
        ?>
</p></div>
      <?php 
    }
    ?>

    </header>

    <ul class="x-addons-extensions-list cf" id="x-addons-extensions-list">

      <?php 
    $plugins = TGM_Plugin_Activation::$instance->plugins;
    foreach ($plugins as $key => $plugin) {
        if ($plugin['slug'] == 'cornerstone') {
            $cornerstone = $plugin;
            unset($plugins[$key]);
        }
    }
    array_unshift($plugins, $cornerstone);
    foreach ($plugins as $plugin) {
        ?>

        <?php 
        if (x_plugin_exists($plugin['x_plugin'])) {
            if (is_plugin_active($plugin['x_plugin'])) {
                $status = 'active';
                $status_message = 'Active';
            } else {
                $status = 'inactive';
                $status_message = 'Inactive';
            }
            $button = '<a class="x-addon-button button" href="' . admin_url('plugins.php') . '">Manage Plugin</a>';
        } else {
            if ($plugin['source'] == NULL) {
                $url = x_addons_get_link_product_validation();
                $text = 'Validate Purchase to Install';
                $class = 'x-addon-button button';
            } else {
                $url = wp_nonce_url(add_query_arg(array('page' => TGM_Plugin_Activation::$instance->menu, 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'tgmpa-install' => 'install-plugin'), admin_url(TGM_Plugin_Activation::$instance->parent_url_slug)), 'tgmpa-install');
                $text = 'Install Plugin';
                $class = 'x-addon-button button button-primary';
            }
            $status = 'not-installed';
            $status_message = 'Not Installed';
            $button = '<a class="' . $class . '" href="' . $url . '">' . $text . '</a>';
        }
        ?>

        <li class="x-addons-extension <?php 
        echo $status;
        ?>
" id="<?php 
        echo $plugin['slug'];
        ?>
">
          <div class="top cf">
            <img src="<?php 
        echo $plugin['x_logo'];
        ?>
" class="img">
            <div class="info">
              <h4 class="title"><?php 
        echo $plugin['name'];
        ?>
</h4>
              <span class="status <?php 
        echo $status;
        ?>
"><?php 
        echo $status_message;
        ?>
</span>
              <p class="desc"><?php 
        echo $plugin['x_description'];
        ?>
</p>
              <p class="author"><cite>By <?php 
        echo $plugin['x_author'];
        ?>
</cite></p>
            </div>
          </div>
          <div class="bottom cf"><?php 
        echo $button;
        ?>
</div>
        </li>

      <?php 
    }
    ?>

    </ul>

  </div>

<?php 
}
コード例 #3
0
function x_addons_demo_content_output()
{
    $request = wp_remote_get('https://theme.co/x/member/demo-api/');
    //
    // Check if request returns an error.
    //
    if (is_wp_error($request)) {
        if (isset($_GET['x-verbose']) && $_GET['x-verbose'] == 1) {
            x_dump($request->get_error_message(), 350, 'var_dump');
        }
        ?>

    <div class="x-addons-postbox demo-content">
      <div class="error"><p>Unable to retrieve demo content. A firewall may be blocking connections to theme.co.</p></div>
    </div>

    <?php 
    } else {
        $data = json_decode($request['body'], true);
        ?>

  <div class="x-addons-postbox demo-content">
    <div class="inside">
      <form id="x-demo-content-form" method="post">
        <?php 
        wp_nonce_field('x-addons-demo-content');
        ?>
        <div class="controls">
          <div class="control full">
            <h3>Demo Content</h3>
            <p>Select which demo content you would like to use on your website. This will setup the Customizer settings for that demo.</p>
            <select name="demo" id="demo">
              <?php 
        foreach ($data as $key => $info) {
            echo '<option value="' . $key . '">' . $info['title'] . '</option>';
        }
        ?>
            </select>
            <p><a href="//theme.co/x/demo/integrity/1/" id="demo-content-link" target="_blank">Online Demo</a></p>
          </div>
        </div>
        <div class="controls">
          <div class="control">
            <h3>Import Posts</h3>
            <p>Include posts with your demo setup to see how various features work.</p>
            <fieldset>
              <legend class="screen-reader-text"><span>input type="radio"</span></legend>
              <label class="radio-label"><input type="radio" class="radio" name="posts" value="yes"> <span><?php 
        _e('Yes', '__x__');
        ?>
</span></label>
              <label class="radio-label"><input type="radio" class="radio" name="posts" value="no" checked="checked"> <span><?php 
        _e('No', '__x__');
        ?>
</span></label>
            </fieldset>
          </div>
          <div class="control">
            <h3>Import Portfolio Items</h3>
            <p>Include portfolio items with your demo setup to see how various features work.</p>
            <fieldset>
              <legend class="screen-reader-text"><span>input type="radio"</span></legend>
              <label class="radio-label"><input type="radio" class="radio" name="portfolio-items" value="yes"> <span><?php 
        _e('Yes', '__x__');
        ?>
</span></label>
              <label class="radio-label"><input type="radio" class="radio" name="portfolio-items" value="no" checked="checked"> <span><?php 
        _e('No', '__x__');
        ?>
</span></label>
            </fieldset>
          </div>
        </div>
        <p class="submit">
          <input type="submit" name="setup" id="x-addons-demo-content-submit" class="button button-primary" value="Setup Demo Content">
        </p>
      </form>
    </div>
  </div>

  <script>

    jQuery(document).ready(function($) {

      $('.x-addons-postbox.demo-content').prepend('<div id="demo-message" class="message"><span>You demo content is being setup.</span></div>');

      $('#demo').change(function() {
        var optVal  = $(this).val();
        var stack   = optVal.split('-').shift();
        var number  = optVal.split('-').pop();
        var newHref = '//theme.co/x/demo/' + stack + '/' + number + '/';
        $('#demo-content-link').attr('href', newHref);
      });

      $('form').on('submit', function(e) {

        e.preventDefault();


        //
        // Only run setup if confirmed.
        //

        xAdminConfirm('error', 'Installing demo content will not alter any of your pages or posts, but it will overwrite your Customizer settings. This is not reversible unless you have previously made a backup of your settings. Are you sure you want to proceed?', function() {

          //
          // 1. Reveal the status message.
          // 2. Disable button.
          // 3. Run setup.
          //

          $('#demo-message').fadeIn(250);                            // 1
          $('#x-addons-demo-content-submit').attr('disabled', true); // 2
          run_setup();                                               // 3

        });


        //
        // Place for button state changes, et cetera.
        //

        url_params = {
          'action'          : 'x_demo_content_setup',
          'demo'            : $('#demo').val(),
          'homepage-markup' : $('#x-demo-content-form input[name="homepage-markup"]:checked').val(),
          'posts'           : $('#x-demo-content-form input[name="posts"]:checked').val(),
          'portfolio-items' : $('#x-demo-content-form input[name="portfolio-items"]:checked').val(),
        };

        var ajax_url = "<?php 
        echo admin_url('admin-ajax.php');
        ?>
?" + $.param(url_params);

        formFeedback = function( newMessage, dataSuccess ) {

          var alertMessage = $('#demo-message');

          alertMessage.html(newMessage);

          if ( dataSuccess === true ) {

            setTimeout(function() {
              alertMessage.fadeOut(250);
            }, 1500);

            setTimeout(function() {
              alertMessage.html('<span>You demo content is being setup.</span>');
              $('#x-addons-demo-content-submit').removeAttr('disabled');
            }, 2000);

          }

        };

        run_setup = function() {

          $.getJSON(ajax_url, function(data) {

            if ( data.result === 'success' ) {

              formFeedback('<span>All done. Have fun!</span>', true);

            } else if ( data.result === 'error' ) {

              //
              // Display error message and log connection errors to console
              // for troubleshooting.
              //

              console.log(data);

            }

          }).fail(function(data) {

            //
            // Auto failover. No valid JSON response could mean a timeout
            // during thumbnail generation. This will run the setup again,
            // skipping completed sections.
            //

            formFeedback('<span>Hang in there, we\'re almost done...</span>', false);

            console.log(data);

            run_setup();

          });

        };

      });

    });

  </script>

  <?php 
    }
}
コード例 #4
0
function x_addons_page_demo_content_setup()
{
    $data = array();
    if (isset($_GET['clean-cache'])) {
        delete_option('x_demo_importer_registry');
        delete_transient('x_demo_listing');
    }
    //
    // Try restoring from transient first
    //
    $transient = get_transient('x_demo_listing');
    if (false !== $transient) {
        return $transient;
    }
    //
    // Get Remote demo list
    //
    $request = wp_remote_get('http://themeco-demo-content.s3.amazonaws.com/x/' . apply_filters('x_demo_listing_index', 'index') . '.json');
    //
    // Check if request returns an error.
    //
    if (is_wp_error($request)) {
        if (isset($_GET['x-verbose']) && $_GET['x-verbose'] == 1) {
            x_dump($request->get_error_message(), 350, 'var_dump');
        }
        $data['error'] = __('Unable to retrieve demo content. Your WordPress install may be having issues making outbound HTTP requests. For more information, please review the <a href="https://theme.co/community/kb/connection-issues/">connection issues</a> article in our Knowledge Base.', '__x__');
        return $data;
    }
    $response = json_decode($request['body'], true);
    if (is_array($response) && isset($response['standard']) && isset($response['expanded']) && !empty($response['standard']) && !empty($response['expanded'])) {
        $data['standard_demos'] = $response['standard'];
        $data['expanded_demos'] = $response['expanded'];
        set_transient('x_demo_listing', $data, 12 * HOUR_IN_SECONDS);
    } else {
        $data['standard_demos'] = array('undefined' => array('title' => '', 'url' => ''));
        $data['expanded_demos'] = $data['standard_demos'];
        $data['error'] = __('No demos found. Refreshing this page may resolve the issue. If it persists, please review the <a href="https://theme.co/community/kb/connection-issues/">connection issues</a> article in our Knowledge Base.', '__x__');
    }
    return $data;
}
コード例 #5
0
function x_addons_product_validation()
{
    if (isset($_POST['validate']) && check_admin_referer('x-addons-product-validation')) {
        if (strip_tags($_POST['x_addons_product_validation_submitted']) == 'submitted') {
            $name = x_addons_get_api_key_option_name();
            $input = strip_tags($_POST[$name]);
            if (isset($input) && $input == '') {
                delete_option($name);
                Themeco_Update_Api::refresh();
                echo '<div class="updated"><p>' . __('API key removed successfully!', '__x__') . '</p></div>';
            } else {
                $validation = X_Update_API::validate_key($input);
                if ($validation['valid']) {
                    update_option($name, $input);
                    echo '<div class="updated"><p>' . $validation['message'] . '</p></div>';
                } else {
                    delete_option($name);
                    echo '<div class="error"><p>' . $validation['message'] . '</p></div>';
                    if (isset($_GET['x-verbose']) && $_GET['x-verbose'] == 1) {
                        x_dump($validation['verbose'], 350, 'var_dump');
                    }
                }
            }
        }
    }
}