예제 #1
0
    public static function load_page()
    {
        // temporary fix for old perks relying on markdown
        if (!function_exists('Markdown')) {
            require_once GWPerks::get_base_path() . '/includes/markdown.php';
        }
        self::load_perk_pointers();
        add_action('admin_print_footer_scripts', array(__CLASS__, 'output_tb_resize_script'), 11);
        $is_install = gwget('view') == 'install' && current_user_can('install_plugins');
        $installed_perks = GWPerks::get_installed_perks();
        wp_enqueue_style('gf_tooltip', GFCommon::get_base_url() . '/css/tooltip.css', null, GFCommon::$version);
        wp_print_styles('gf_tooltip');
        ?>

        <style type="text/css">

            #gwp-header-links { float: right; margin-top: -36px; }
                #gwp-header-links li { display: inline; padding-left: 10px; }

            .gp-active-perks { overflow: hidden; }

            .perks { padding: 20px 0 0; }

            .perks .manage-perks-intro,
            .perks .install-perks-intro { border-bottom: 1px solid #eee; padding: 0 20px 20px; margin: 0 0 20px; }
                .perks .install-perks-intro h3 { margin-top: 0; }
            .perks .no-perks-installed { padding: 60px 20px 20px; margin: 0 0 20px; text-align: center; font-size: 24px;
                line-height: 36px; }
                .perks .no-perks-installed a { cursor: pointer; }

            .perks .all-perks-installed { padding: 60px 20px 20px; margin: 0 0 20px; text-align: center; font-size: 24px;
                line-height: 36px; }

            #install.tab-container { overflow: hidden; position: relative; }
                #install #need-license-splash { background-color: #fff; position: absolute; z-index: 99;
                    top: 100px; left: 50%; margin-left: -25%; width: 44%; padding: 3%;
                    box-shadow: 0 0 100px 100px #fff; }
                #install #need-license-splash .perk-listing { width: auto; }
                #install #need-license-splash .perk-listing .wrap { min-height: 0; }
                #install #need-license-splash h3 { margin: 0 0 18px; }
                #install #need-license-splash p { margin: 0 0 18px; }
                #install #need-license-splash .dismiss-link { float: right; line-height: 22px; }

            .perk-listing { background-color: #f4f8fc; box-shadow: 0 0 20px #D8E9FA inset;
                border: 1px solid #eee; float: left; margin: 0 10px 20px; width: 260px; }

                .perk-listing .wrap { padding: 15px; border: 4px solid #fff; min-height: 140px; margin: 0;
                    position: relative; }
                .perk-listing h3 { margin: 0 0 4px; }
                .perk-listing p { margin: 0; padding: 0; }
                .perk-listing span.version { color: #6E9FB5; }
                .perk-listing .actions { margin: 0 0 12px; }

                    .perks .perk-listing a.button-primary { color: #fff; }

                .perk-listing .network-activated-perk { background-color: #fff; padding: 5px 7px; line-height: 1;
                    position: absolute; bottom: 0; right: 15px; border-top-left-radius: 4px; border-top-right-radius: 4px; }
                .perk-listing .network-activated-perk a { background: none repeat scroll 0 0 transparent; display: block;
                    font-size: 10px; height: auto; text-decoration: none; text-indent: 0; text-transform: uppercase; width: auto; }

                .perk-listing .update-available { margin-top: 12px; text-align: center; }

                .qtip-content ul { margin: 0; }

            .perk-listing.install,
            .perk-listing.inactive { background-color: #f7f7f7; box-shadow: 0 0 20px #e7e7e7 inset; padding: 0; }

                .perk-listing.install .actions { position: absolute; bottom: 10px; }
                .perk-listing.install h3 { margin: 0 0 12px; }
                .perk-listing.install span.version,
                .perk-listing.inactive span.version { color: #999; }

            .perk-listing.failed-requirements { background-color: #FFEBE8; box-shadow: 0 0 20px #FCCCC8 inset; }

                .perk-listing.failed-requirements span.version { color: #999; }
                .perk-listing.failed-requirements a { color: #7F564D; }
                .perk-listing.failed-requirements a.gp-requirements { background-image: url(<?php 
        echo GWPerks::get_base_url();
        ?>
/images/icon-exclamation.png);
                    text-indent: -999em; display: inline-block; height: 16px; }

            .forms_page_gwp_perks .gwp_buy_license-pointer .wp-pointer-arrow { left: auto; right: 50px; }
            .forms_page_gwp_perks .gwp_register_license-pointer .wp-pointer-arrow { left: auto; right: 44px; }
            .forms_page_gwp_perks .gwp_get_support-pointer .wp-pointer-arrow { left: auto; right: 27px; }

        </style>

        <?php 
        if (wp_script_is('gform_tooltip_init', 'registered')) {
            wp_print_scripts('gform_tooltip_init');
        } else {
            if (wp_script_is('gf_tooltip_init', 'registered')) {
                wp_print_scripts('gf_tooltip_init');
            }
        }
        ?>

        <script type="text/javascript">

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

                // handle tabs
                var tab = <?php 
        echo $is_install ? '"install"' : 'window.location.hash';
        ?>
;
                /*if(tab)
                    toggleTabs(false, tab);*/

                $('h2.nav-tab-wrapper a').click(function(event){
                    event.preventDefault();
                    toggleTabs($(this));
                });

                // handle ajax activate/deactivate

                $(document).on('click', 'a.activate, a.deactivate, a.uninstall', function(event){
                    event.preventDefault();

                    var link = $(this ),
                        confirmMessage = link.data( 'confirm-message' );

                    if( confirmMessage && ! confirm( confirmMessage ) ) {
                        return;
                    }

                    var spinner = gperk.ajaxSpinner( link, gperk.baseUrl + '/images/ajax-loader-trans.gif' );

                    $.post(ajaxurl, {
                        request_url: link.attr('href'),
                        action: 'gwp_manage_perk',
                        gwp_manage_perk: '<?php 
        echo wp_create_nonce('gwp_manage_perk');
        ?>
'
                    }, function(response){
                        spinner.destroy();
                        var response = $.parseJSON(response);
                        if(response['success']) {
                            link.parents('.perk-listing').after(response['listing_html']);
                            link.parents('.perk-listing').remove();
                            jQuery( ".gf_tooltip" ).tooltip( {
                                show: 500,
                                hide: 1000,
                                content: function () {
                                    return jQuery(this).prop('title');
                                }
                            } );
                        }
                    });

                });

                $(document).on('gperks_toggle_tabs', function() {
                    sortPerks();
                });

                <?php 
        if (self::show_splash()) {
            ?>
                    if( tab != 'install' ) {
                        $(document).one('gperks_toggle_tabs.splash', function() {
                            showLicenseSplash();
                        });
                    } else {
                        showLicenseSplash();
                    }
                <?php 
        }
        ?>

                // adjust perk listing height
                setDynamicPerkHeight( $( '.gp-active-perks .perk-listing .wrap' ) );
                setDynamicPerkHeight( $( '.gp-inactive-perks .perk-listing .wrap' ) );
                setDynamicPerkHeight( $( '#install .perk-listing .wrap' ) );

            });

            function toggleTabs(elem, tab) {

                // assume tab is passed
                if(arguments.length == 2) {
                    var link = jQuery('a.nav-tab[href="' + tab + '"]');
                } else {
                    var link = jQuery(elem);
                    var tab = link.attr('href')
                }

                jQuery('h2.nav-tab-wrapper a').removeClass('nav-tab-active');
                link.addClass('nav-tab-active');

                jQuery('div.wrap .tab-container').hide();
                jQuery(tab).show();

                jQuery(document).trigger('gperks_toggle_tabs', tab);
            }

            function sortPerks() {
                jQuery('div#manage.perks div.perk-listing').each(function(){
                    var perkListing = jQuery(this);
                    if(perkListing.hasClass('active')) {
                        perkListing.appendTo('div.gp-active-perks');
                    } else {
                        perkListing.appendTo('div.gp-inactive-perks');
                    }
                });
            }

            function setDynamicPerkHeight( group ) {

                var maxHeight = 0;

                jQuery.each( group, function() {
                    var height = jQuery( this ).height();
                    if( height > maxHeight )
                        maxHeight = height;
                } );

                jQuery.each( group, function() {
                    jQuery( this ).height( maxHeight );
                } );

            }

            function showLicenseSplash() {
                jQuery('#install .perk-listings').animate({'opacity': '0.3'}, 500, function(){
                    jQuery('#need-license-splash').fadeIn();
                });
            }

            function dismissLicenseSplash() {
                jQuery.post( ajaxurl, {
                    pointer: 'need_license_splash',
                    action: 'dismiss-wp-pointer'
                });
                jQuery('#need-license-splash').fadeOut(function(){
                    jQuery('#install .perk-listings').animate({'opacity': '1.0'}, 500);
                });
            }

        </script>

        <div class="wrap">

            <div class="icon32" id="icon-themes"><br></div>
            <h2 class="nav-tab-wrapper">
                <a class="nav-tab <?php 
        echo !$is_install ? 'nav-tab-active' : '';
        ?>
" href="#manage">Manage Perks</a>
                <?php 
        if (current_user_can('install_plugins')) {
            ?>
                    <a class="nav-tab <?php 
            echo $is_install ? 'nav-tab-active' : '';
            ?>
" href="#install">Install Perks</a>
                <?php 
        }
        ?>
            </h2>

            <?php 
        self::display_header_links();
        ?>

            <?php 
        self::handle_message_code();
        ?>

            <div id="manage" class="perks plugins tab-container" <?php 
        echo $is_install ? 'style="display:none;"' : '';
        ?>
 >

                <?php 
        if (!empty($installed_perks)) {
            $active_perks = $inactive_perks = array();
            foreach ($installed_perks as $perk_file => $perk_data) {
                if (is_plugin_active($perk_file)) {
                    $active_perks[$perk_file] = $perk_data;
                } else {
                    $inactive_perks[$perk_file] = $perk_data;
                }
            }
            if (!empty($active_perks)) {
                ?>

                        <h3 class="gp-inline-header"><?php 
                _e('Active Perks', 'gravityperks');
                ?>
</h3>
                        <div class="gp-active-perks">
                            <?php 
                foreach ($active_perks as $perk_file => $perk_data) {
                    self::get_perk_listing($perk_file, $perk_data);
                }
                ?>
                        </div>

                        <?php 
            }
            if (!empty($inactive_perks)) {
                ?>

                        <h3 class="gp-inline-header"><?php 
                _e('Inactive Perks', 'gravityperks');
                ?>
</h3>
                        <div class="gp-inactive-perks">
                            <?php 
                foreach ($inactive_perks as $perk_file => $perk_data) {
                    self::get_perk_listing($perk_file, $perk_data);
                }
                ?>
                        </div>

                        <?php 
            }
            unset($perk_file);
            unset($perk_data);
        } else {
            ?>

                    <div class="no-perks-installed">
                        <?php 
            printf(__('You don\'t have any perks installed.<br /> %sLet\'s go install some perks!%s', 'gravityperks'), '<a onclick="jQuery(\'a[href=\\\'#install\\\']\').click();">', '</a>');
            ?>
                    </div>

                    <?php 
        }
        ?>

            </div>

            <?php 
        if (current_user_can('install_plugins')) {
            self::install_page($is_install);
        }
        ?>

        </div>

        <?php 
    }
<?php

if (!class_exists('GP_EDD_SL_Plugin_Updater')) {
    require_once GWPerks::get_base_path() . '/includes/GP_EDD_SL_Plugin_Updater.php';
}
/**
* Interface for interacting with GW Store API and EDD Updater.
*
*/
class GWAPI
{
    private $license_key;
    private $product;
    private $updater;
    private $author;
    private $_perk_update_data = null;
    function __construct($args)
    {
        extract(wp_parse_args($args, array('version' => GWPerks::get_version(), 'license' => GWPerks::get_license_key(), 'item_name' => 'Gravity Perks', 'author' => 'David Smith', 'plugin_file' => null)));
        $this->license_key = $license;
        $this->slug = basename($plugin_file, '.php');
        $this->product = $item_name;
        $this->author = $author;
        $this->updater = new GP_EDD_SL_Plugin_Updater(GW_STORE_URL, $plugin_file, compact('version', 'license', 'item_name', 'author'));
        $this->hook();
    }
    private function hook()
    {
        add_filter('pre_set_site_transient_update_plugins', array($this, 'pre_set_site_transient_update_plugins_filter'), 99);
        add_filter('plugins_api', array($this, 'perks_plugins_api_filter'), 100, 3);
    }
예제 #3
0
 function include_field($class_name = false, $file = false)
 {
     $field_file_paths = array($file, $this->get_base_path() . '/fields.php', $this->get_base_path() . '/includes/fields.php');
     foreach ($field_file_paths as $file_path) {
         if ($file_path && file_exists($file_path)) {
             require_once GWPerks::get_base_path() . '/model/field.php';
             require_once $file_path;
             $field_class = $class_name ? $class_name : $this->slug . 'Field';
             if (!class_exists($field_class)) {
                 return false;
             }
             $args = array('perk' => $this);
             if (is_callable(array($field_class, 'get_instance'))) {
                 $field_obj = call_user_func(array($field_class, 'get_instance'), $args);
             } else {
                 $field_obj = new $field_class($args);
             }
             return $field_obj;
         }
     }
     return false;
 }
 public static function markdown($string)
 {
     if (!function_exists('Markdown')) {
         require_once GWPerks::get_base_path() . '/includes/markdown.php';
     }
     return Markdown($string);
 }