Plugin Directory

Changeset 732491


Ignore:
Timestamp:
06/26/2013 11:41:07 PM (13 years ago)
Author:
joshua.strebel
Message:

3.1.5

Location:
pagely-reseller-management/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • pagely-reseller-management/trunk/inc/helpers.php

    r702419 r732491  
    3434    if ( !is_ssl() && !$pagely->_is_sandbox() ) {
    3535   
    36         echo "<script type='text/javascript'>window.location = '$location'</script>";
    37         die();
     36    //  echo "<script type='text/javascript'>window.location = '$location'</script>";
     37    //  die();
    3838    }
    3939
     
    5656}
    5757
     58function get_products() {
     59   
     60    $pagely = PagelyApi::init();
     61    return $pagely->_get_products();
     62}
    5863// enable sessions
    5964function pp_session_enable(){
  • pagely-reseller-management/trunk/partner-api.php

    r728580 r732491  
    44Plugin URI: https://docs-api.pagely.com/reseller-plugin/
    55Description: For Pagely Resellers
    6 Version: 3.1.4
     6Version: 3.1.5
    77Author: joshua.strebel
    88Author URI: https://page.ly
     
    7070}
    7171
    72 // require some helper functions
     72// require some helper public functions
    7373require_once(PP_PLUGIN_ASSETS_PATH."/inc/helpers.php");
    7474
     
    8181   var $pagely_api_sec = '';
    8282   var $bypass_pagely_varnish = true;       // if running on page.ly, need to bypass varnish
    83    
    8483   var $live_endpoint           = 'https://api.pagely.com/v1';
    85    var $sandbox_endpoint        = 'https://sandbox-api.pagely.com/v1';
    86   // var $sandbox_endpoint      = 'http://api.hcs/v1';
    87 
    88 
     84  // var $sandbox_endpoint      = 'https://sandbox-api.pagely.com/v1';
     85   var $sandbox_endpoint        = 'http://api.hcs/v1';
    8986   var $api_endpoint            = '';
    90 
    91     var $pp_portal_url      = 'https://atomic.pagely.com/';
     87    static $pp_portal_url       = 'https://atomic.pagely.com/';
    9288    var $locale = '';
     89    var $page_slug;
     90    var $options_page = '';
    9391   
    94     var $page_slug;
    95    
    96     function &init() {
    97         static $instance = false;
    98         if ( !$instance ) {
    99             $instance = new PagelyApi;
    100         }
    101         return $instance;
    102 
    103     }
    104    
    105     // main init to run on admin screens
    106     function pagelyApi() {
    107         // GLOBALS         
     92    public function __construct() {
     93        // GLOBALS     
    10894        global $wp_rewrite,$wp_version;
    109        
    110        
    11195        // get the post slug and create session
    11296       
    113         add_action('init',array(&$this, '_test_session') ,20);
     97       
     98        add_action('init',array($this, '_test_session') ,20);
    11499
    115100       
     
    129114       }
    130115     
     116
    131117       
    132118        // IF ROLE ADMIN
    133119        if ( current_user_can('administrator') ) {
    134120            // only add the options page if role is admin
    135             add_action( 'admin_menu', array(&$this, '_create_menu') ,20);
     121           
     122            add_action( 'admin_menu', array('PagelyAPIOptions', '_create_menu') ,20);
    136123
    137124        }
    138125       
    139126        // after wp has fully loaded, enqueue scripts on only the correct page(s)
    140         add_action( 'wp',array(&$this, '_load_scripts_head'),1);
     127        add_action( 'wp',array($this, '_load_scripts_head'),1);
    141128       
    142129       
     
    149136       
    150137        // these are ajax handlers
    151         add_action( 'wp_ajax_pagely_jax_formvalidate_callback', array(&$this,'_pagely_jax_formvalidate_callback') );
    152         add_action( 'wp_ajax_nopriv_pagely_jax_formvalidate_callback', array(&$this,'_pagely_jax_formvalidate_callback') );
    153        
    154         add_action( 'wp_ajax_pagely_jax_accformsubmit_callback', array(&$this,'_pagely_jax_accformsubmit_callback') );
    155         add_action( 'wp_ajax_nopriv_pagely_jax_accformsubmit_callback', array(&$this,'_pagely_jax_accformsubmit_callback') );
    156        
    157         add_action( 'wp_ajax_pagely_jax_payformsubmit_callback', array(&$this,'_pagely_jax_payformsubmit_callback') );
    158         add_action( 'wp_ajax_nopriv_pagely_jax_payformsubmit_callback', array(&$this,'_pagely_jax_payformsubmit_callback') );
    159        
    160         add_action( 'wp_ajax_pagely_jax_addtocart_callback', array(&$this,'_pagely_jax_addtocart_callback') );
    161         add_action( 'wp_ajax_nopriv_pagely_jax_addtocart_callback', array(&$this,'_pagely_jax_addtocart_callback') );
    162        
    163         add_action( 'wp_ajax_pagely_jax_removefromcart_callback', array(&$this,'_pagely_jax_removefromcart_callback') );
    164         add_action( 'wp_ajax_nopriv_pagely_jax_removefromcart_callback', array(&$this,'_pagely_jax_removefromcart_callback') );
    165        
    166         add_action( 'wp_ajax_pagely_jax_purchase_cart_callback', array(&$this,'_pagely_jax_purchase_cart_callback') );
    167         add_action( 'wp_ajax_nopriv_pagely_jax_purchase_cart_callback', array(&$this,'_pagely_jax_purchase_cart_callback') );
    168        
    169         add_action( 'wp_ajax_pagely_jax_generic_callback', array(&$this,'_pagely_jax_generic_callback') );
    170         add_action( 'wp_ajax_nopriv_pagely_jax_generic_callback', array(&$this,'_pagely_jax_generic_callback') );
    171        
    172         add_action( 'wp_ajax_pagely_jax_gopaypal_callback', array(&$this,'_pagely_jax_gopaypal_callback') );
    173         add_action( 'wp_ajax_nopriv_pagely_jax_gopaypal_callback', array(&$this,'_pagely_jax_gopaypal_callback') );
     138        add_action( 'wp_ajax_pagely_jax_formvalidate_callback', array($this,'_pagely_jax_formvalidate_callback') );
     139        add_action( 'wp_ajax_nopriv_pagely_jax_formvalidate_callback', array($this,'_pagely_jax_formvalidate_callback') );
     140       
     141        add_action( 'wp_ajax_pagely_jax_accformsubmit_callback', array($this,'_pagely_jax_accformsubmit_callback') );
     142        add_action( 'wp_ajax_nopriv_pagely_jax_accformsubmit_callback', array($this,'_pagely_jax_accformsubmit_callback') );
     143       
     144        add_action( 'wp_ajax_pagely_jax_payformsubmit_callback', array($this,'_pagely_jax_payformsubmit_callback') );
     145        add_action( 'wp_ajax_nopriv_pagely_jax_payformsubmit_callback', array($this,'_pagely_jax_payformsubmit_callback') );
     146       
     147        add_action( 'wp_ajax_pagely_jax_addtocart_callback', array($this,'_pagely_jax_addtocart_callback') );
     148        add_action( 'wp_ajax_nopriv_pagely_jax_addtocart_callback', array($this,'_pagely_jax_addtocart_callback') );
     149       
     150        add_action( 'wp_ajax_pagely_jax_removefromcart_callback', array($this,'_pagely_jax_removefromcart_callback') );
     151        add_action( 'wp_ajax_nopriv_pagely_jax_removefromcart_callback', array($this,'_pagely_jax_removefromcart_callback') );
     152       
     153        add_action( 'wp_ajax_pagely_jax_purchase_cart_callback', array($this,'_pagely_jax_purchase_cart_callback') );
     154        add_action( 'wp_ajax_nopriv_pagely_jax_purchase_cart_callback', array($this,'_pagely_jax_purchase_cart_callback') );
     155       
     156        add_action( 'wp_ajax_pagely_jax_generic_callback', array($this,'_pagely_jax_generic_callback') );
     157        add_action( 'wp_ajax_nopriv_pagely_jax_generic_callback', array($this,'_pagely_jax_generic_callback') );
     158       
     159        add_action( 'wp_ajax_pagely_jax_gopaypal_callback', array($this,'_pagely_jax_gopaypal_callback') );
     160        add_action( 'wp_ajax_nopriv_pagely_jax_gopaypal_callback', array($this,'_pagely_jax_gopaypal_callback') );
    174161           
    175162           
    176163        return;
    177164
    178     }
    179    
    180     function _test_session() {
     165   }
     166   
     167 
     168   
     169    public function &init() {
     170        static $instance = false;
     171        if ( !$instance ) {
     172            $instance = new PagelyApi;
     173           
     174        }
     175        return $instance;
     176
     177    }
     178       
     179    public function _test_session() {
    181180        $slug = get_option('pp-signup-slug');
    182181        if ( preg_match('/'.$slug .'/i',$_SERVER['REQUEST_URI'],$matches) || preg_match('/admin-ajax.php/i',$_SERVER['REQUEST_URI'],$matches) ) {
     
    186185       
    187186    }
    188     function _load_scripts_head() {
     187    public function _load_scripts_head() {
    189188        global $post;
    190189   
     
    222221   
    223222    // Is sandbox mode active?
    224     function _is_sandbox() {
     223    public function _is_sandbox() {
    225224        $api_options = get_option('pp_api');
    226225        $sandbox = $api_options['pp_mode'];
     
    232231    // return the API key from database
    233232    // api key is saved in the options table. You need 2 keys.
    234     function _api_key() {
     233    public function _api_key() {
    235234        $api_options = get_option('pp_api');
    236235        return $api_key = $api_options['api_key']; 
     
    238237   
    239238    //are signups on?
    240     function _signups_on() {
     239    public function _signups_on() {
    241240        $api_options = get_option('pp_api');
    242241        $allow_signups = $api_options['signups_active'];   
     
    249248   
    250249    //are signups on?
    251     function _get_trial_length() {
     250    public function _get_trial_length() {
    252251        $api_options = get_option('pp_api');
    253252        $free_trial_days = $api_options['free_trial_days'];
     
    260259   
    261260    // This is the header so Page.ly varnish will not cache pages.
    262     function _set_response_header() {
     261    public function _set_response_header() {
    263262        if ($this->bypass_pagely_varnish) {
    264263        header("X-No-Cache: true");
     
    267266
    268267    // get custom css
    269     function _custom_css() {
     268    public function _custom_css() {
    270269        $api_options = get_option('pp_api');
    271270        return $api_options['custom_css']; 
     
    273272   
    274273    /***********************
    275     * PAGE.LY API SESSION MANAGEMENT FUNCTIONS
     274    * PAGE.LY API SESSION MANAGEMENT public functionS
    276275    ***********************/
    277276   
    278277    // get some value from the session
    279     function _get_pp_session($key = false) {
     278    public function _get_pp_session($key = false) {
    280279        if ( $key && isset($_SESSION['pp_order'][$key]) ) {
    281280            return $_SESSION['pp_order'][$key];
     
    290289       
    291290    // set some value in the session
    292     function _set_pp_session( $array ) {
     291    public function _set_pp_session( $array ) {
    293292
    294293        foreach ($array as $k => $v) {
     
    298297   
    299298    // clear the session   
    300     function _clear_pp_session () {
     299    public function _clear_pp_session () {
    301300        // Unset all of the session variables.
    302301        $_SESSION = array();
     
    310309    /* ASSETS */
    311310    // script js in footer of admin pages
    312     function _footer_scripts() { ?>
     311    public function _footer_scripts() { ?>
    313312        <!--<script type='text/javascript'>
    314             jQuery(document).ready(function($) {
     313            jQuery(document).ready(public function($) {
    315314            });
    316315        </script>
     
    322321
    323322    // render admin head styles
    324     function _head_styles() {
     323    public function _head_styles() {
    325324        global $wp_version;
    326325        // no styles to load at this time
    327326    }
    328327   
    329     /************
    330     * THE PAGE.LY API OPTIONS PAGE
    331     *************/
    332     function _create_menu() {
    333         //create new top-level menu
    334         $pagely_options = get_option('pp_api');
    335        
    336         if (isset($pagely_options['pp_menu_placement']) && 'sub' == $pagely_options['pp_menu_placement'] ) {
    337             add_options_page( 'Pagely Partner API', 'Pagely API', 'administrator',  __FILE__, array(&$this, '_settings_page'));
    338         } else {
    339             add_menu_page('Pagely Partner API', 'Pagely API', 'administrator', __FILE__, array(&$this, '_settings_page'),'',99);                   
    340         }
    341        
    342        
    343         add_action( 'admin_init', array(&$this, '_register_PagelyApi_settings') );
    344     }
    345    
    346     // api options page settings and sections
    347     function _register_PagelyApi_settings() {   
    348        
    349         // TODO check the validity of the API key(s)
    350         $api_check = $this->_test_api();
    351 
    352        
    353         // we store the options in an array called pp_api
    354         $pagely_options = get_option('pp_api');     
    355         if ( !isset($pagely_options['reseller_id']) ) {
    356             // get reseller id
    357             $reseller = $this->_pagely_api_request($method = 'GET','/resellers/single', $params = array());
    358             $reseller = json_decode($reseller);
    359             $pagely_options['reseller_id'] = $reseller->id;
    360             $pagely_options['support_url'] = $reseller->support_link;
    361             update_option('pp_api',$pagely_options);
    362             $pagely_options = get_option('pp_api');     
    363 
    364         }
    365    
    366         register_setting( 'pp_api', 'pp_api', array(&$this, '_sanitize_options'));
    367        
    368         // settings sections
    369         add_settings_section( 
    370             'pp_api',                                                   // ID used to identify this section and with which to register options 
    371             'Partner API Settings',                                 // Title to be displayed on the administration page 
    372             array(&$this, '_pagely_options_section_callback'), // Callback used to render the description of the section 
    373             'partner-api'                                       // Page on which to add this section of options 
    374         );
    375        
    376         // settings fields
    377         add_settings_field( 
    378             'pp_mode',                                                  // ID used to identify the field throughout the theme 
    379             'API Mode',                                         // The label to the left of the option interface element 
    380             array(&$this, '_pagely_options_field_mode'),    // The name of the function responsible for rendering the option interface 
    381             'partner-api',                                      // The page on which this option will be displayed 
    382             'pp_api',                                                   // The name of the section to which this field belongs 
    383             array( $pagely_options['pp_mode'], 'pp_mode' )     // The array of arguments to pass to the
    384         );
    385        
    386         // settings fields
    387         add_settings_field( 
    388             'pp_menu_placement',                                                // ID used to identify the field throughout the theme 
    389             'WP Menu Placement',                                        // The label to the left of the option interface element 
    390             array(&$this, '_pagely_options_field_menu'),    // The name of the function responsible for rendering the option interface 
    391             'partner-api',                                      // The page on which this option will be displayed 
    392             'pp_api',                                                   // The name of the section to which this field belongs 
    393             array( $pagely_options['pp_menu_placement'], 'pp_menu_placement' )     // The array of arguments to pass to the
    394         );
    395         // settings fields
    396         add_settings_field( 
    397             'api_key',                                                 
    398             'Your API key',                                         
    399             array(&$this, '_pagely_options_field_apikey'),       
    400             'partner-api',                                       
    401             'pp_api',                                                     
    402             array( $pagely_options['api_key'], 'api_key' )     
    403         );
    404                
    405         if ($api_check) { // show these settings if the apu check passed
    406        
    407             // the support url settings field
    408             if (!isset($pagely_options['signups_active'])) { $pagely_options['signups_active'] = 1; }
    409             add_settings_field( 
    410                 'signups_active',                                 
    411                 'Allow new Signups',                       
    412                 array(&$this, '_pagely_options_field_active'),                 
    413                 'partner-api',                         
    414                 'pp_api',                                   
    415                 array( $pagely_options['signups_active'], 'signups_active' ) 
    416             );
    417 
    418             // the support url settings field
    419             if (!isset($pagely_options['support_url'])) { $pagely_options['support_url'] = 'https://support.pagely.com'; }
    420             add_settings_field( 
    421                 'support_url',                                   
    422                 'Support Site',                       
    423                 array(&$this, '_pagely_options_field_support_url'),                 
    424                 'partner-api',                         
    425                 'pp_api',                                   
    426                 array( $pagely_options['support_url'], 'support_url' ) 
    427             );
    428            
    429        
    430             // free_trial length
    431             if ($pagely_options['reseller_id'] == 1) {
    432                 if (!isset($pagely_options['free_trial_days'])) { $pagely_options['free_trial_days'] = 0; }
    433                 add_settings_field( 
    434                     'free_trial_days',                                   
    435                     'Length of Free Trial (Days)',                       
    436                     array(&$this, '_pagely_options_field_free_trial'),                 
    437                     'partner-api',                         
    438                     'pp_api',                                   
    439                     array( $pagely_options['free_trial_days'], 'free_trial_days' ) 
    440                 );
    441             }
    442            
    443             // order_by
    444             if (!isset($pagely_options['order_by'])) { $pagely_options['order_by'] = array(); }
    445             add_settings_field( 
    446                 'order_by',                                   
    447                 'Order Plans by',                       
    448                 array(&$this, '_pagely_options_field_order_by'),                 
    449                 'partner-api',                         
    450                 'pp_api',                                   
    451                 array( $pagely_options['order_by'], 'order_by' ) 
    452             );
    453            
    454             // the plans to show settings field
    455             if (!isset($pagely_options['plans_to_show'])) { $pagely_options['plans_to_show'] = array(); }
    456             add_settings_field( 
    457                 'plans_to_show',                                 
    458                 'Choose up to 3 plans for customers to purchase',                         
    459                 array(&$this, '_pagely_options_field_plans_to_show'),                   
    460                 'partner-api',                       
    461                 'pp_api',                                   
    462                 array( $pagely_options['plans_to_show'], 'plans_to_show' ) 
    463             );
    464            
    465             // the products to show settings field
    466             if (!isset($pagely_options['products_to_show'])) { $pagely_options['products_to_show'] = array(); }
    467 
    468             add_settings_field( 
    469                 'products_to_show',                                   
    470                 'Choose which products to show',                       
    471                 array(&$this, '_pagely_options_field_products_to_show'),                 
    472                 'partner-api',                         
    473                 'pp_api',                                   
    474                 array( $pagely_options['products_to_show'], 'products_to_show' ) 
    475             );
    476            
    477             // custom css
    478             if (!isset($pagely_options['custom_css'])) { $pagely_options['custom_css'] = ""; }
    479 
    480             add_settings_field( 
    481                 'custom_css',                                 
    482                 'Your Custom CSS (optional)',                       
    483                 array(&$this, '_pagely_options_field_custom_css'),                   
    484                 'partner-api',                         
    485                 'pp_api',                                   
    486                 array( $pagely_options['custom_css'], 'custom_css' ) 
    487             );
    488            
    489            
    490         }
    491     }
    492    
    493    
    494     // WP Menu Placement
    495     function _pagely_options_field_menu($args) { 
    496 
    497         $args[0] == 'main' ? $checked1 = "selected='selected'" : $checked1 = '';
    498         $args[0] == 'sub' ? $checked2 = "selected='selected'" : $checked2 = '';
    499 
    500         echo "<select id='{$args[1]}' name='pp_api[{$args[1]}]'>
    501                     <option value='main' {$checked1}>Top Level</option>
    502                     <option value='sub' {$checked2}>Settings Sub-menu item</option>
    503                 </select><span class='inline-help'>Access this page via a Top level menu item, or move under the Settings Menu.</span>";
    504     }
    505    
    506     // Order by key field
    507     function _pagely_options_field_order_by($args) { 
    508 
    509         $args[0] == 0 ? $checked1 = "selected='selected'" : $checked1 = '';
    510         $args[0] == 1 ? $checked2 = "selected='selected'" : $checked2 = '';
    511 
    512         echo "<select id='{$args[1]}' name='pp_api[{$args[1]}]'>
    513                     <option value='0' {$checked1}>Price: Low-to-High</option>
    514                     <option value='1' {$checked2}>Price: High-to-Low</option>
    515                 </select>";
    516     }
    517    
    518     // free trial days_dropdown
    519     function _pagely_options_field_free_trial($args) { 
    520 
    521         $args[0] == 0 ? $checked1 = "selected='selected'" : $checked1 = '';
    522         $args[0] == 5 ? $checked2 = "selected='selected'" : $checked2 = '';
    523         $args[0] == 10 ? $checked3 = "selected='selected'" : $checked3 = '';
    524         $args[0] == 15 ? $checked4 = "selected='selected'" : $checked4 = '';
    525         $args[0] == 30 ? $checked5 = "selected='selected'" : $checked5 = '';
    526 
    527         echo "<select id='{$args[1]}' name='pp_api[{$args[1]}]'>
    528                     <option value='0' {$checked1}>0</option>
    529                     <option value='5' {$checked2}>5</option>
    530                     <option value='10' {$checked3}>10</option>
    531                     <option value='15' {$checked4}>15</option>
    532                     <option value='30' {$checked5}>30</option>
    533                 </select>";
    534     } 
    535    
    536     // api key field
    537     function _pagely_options_field_apikey($args) { 
    538         echo "<input id='{$args[1]}' name='pp_api[{$args[1]}]' size='40' type='text' value='{$args[0]}' required/> <span class='description'>Key given to you at registration</span>";
    539     }
    540    
    541     // api mode selection live/sandbox
    542     function _pagely_options_field_mode($args) { 
    543         $args[0] == 0 ? $checked1 = "selected='selected'" : $checked1 = '';
    544         $args[0] == 1 ? $checked2 = "selected='selected'" : $checked2 = '';
    545         echo "<select id='{$args[1]}' name='pp_api[{$args[1]}]'><option value='0' {$checked1}>Sandbox</option><option value='1' {$checked2}>Live</option></select> <span class='description'>Sandbox for is for testing, be sure to switch to live when ready. Recently added plans may not be available in Sandbox mode right away.</span>";
    546 
    547     } 
    548 
    549     // support url field
    550     function _pagely_options_field_support_url($args) { 
    551         echo "<input id='{$args[1]}' name='pp_api[{$args[1]}]' size='40' type='text' value='{$args[0]}' required/> <span class='description'>Url of your support desk, or use https://support.pagely.com</span>";
    552     }
    553    
    554     // active field
    555     function _pagely_options_field_active($args) { 
    556    
    557         $args[0] == 0 ? $checked1 = "selected='selected'" : $checked1 = '';
    558         $args[0] == 1 ? $checked2 = "selected='selected'" : $checked2 = '';
    559 
    560         echo "<select id='{$args[1]}' name='pp_api[{$args[1]}]'>
    561                     <option value='0' {$checked1}>No</option>
    562                     <option value='1' {$checked2}>Yes</option>
    563                 </select> <span class='description'>Will show a maintenance message on cart pages.</span>";
    564     }
    565    
    566    
    567    
    568     // checkboxes for which plans to show.
    569     function _pagely_options_field_plans_to_show($args) { 
    570         // this can be improved
    571         $portal = $this->pp_portal_url;
    572         // print_r($args[0]);
    573        
    574         $all_plans = $this->_get_reseller_plans($limit = 20,$offset = 0);
    575    
    576         if ( is_array($all_plans->objects) && count($all_plans->objects) > 0 ) {
    577             echo "<div id='plans_check'>
    578                         <table class='wp-list-table widefat' cellspacing='0'>
    579                             <thead>
    580                                 <tr>
    581                                     <th scope='col' id='cb' class='manage-column column-show column-cb check-column'></th>
    582                                     <th scope='col' id='plan' class='manage-column column-plan'>Plan</th>
    583                                     <th scope='col' id='price' class='manage-column column-price'>Price</th>
    584                                     <th scope='col' id='featured' class='manage-column column-featured'>Featured</th>
    585                                     <th scope='col' id='hidden' class='manage-column column-hidden'>*Hidden</th>
    586                                 </tr>
    587                             </thead>";
    588                            
    589             foreach ($all_plans->objects as $p) {
    590                 if ($p->active == "1") {
    591                     $checked = '';
    592                     $checkradio = '';
    593                     if (is_array($args[0])) {
    594                         if ( in_array($p->id,$args[0]) ) { $checked = "checked='checked'";}
    595                     }
    596                    
    597                     $visible = $p->visible == 0 ? '<span style="color:#ccc">Yes</span>' : '<span style="color:green;">No</span>';
    598                    
    599                     if ( isset($args[0]['plan_default']) && $args[0]['plan_default'] == $p->id) {$checkradio = "checked='checked'";}       
    600                     echo "<tr>
    601                                 <td>
    602                                     <input type='checkbox' class='required' id='{$args[1]}{$p->id}' name='pp_api[{$args[1]}][]' value='{$p->id}' {$checked} />
    603                                 </td>
    604                                 <td>{$p->name}</td>
    605                                 <td>".$this->_cash($p->price)."</td>
    606                                 <td><input type='radio' name='pp_api[{$args[1]}][plan_default]' value='{$p->id}' {$checkradio}/></td>
    607                                 <td>{$visible}</td>
    608                             </tr>";
    609                 }
    610             }
    611            
    612             echo "</table><span class='description'>These are all the hosting plans that are active in our system for your account. You may choose 3 at any one time to list for sale via this plugin. If you wish to modify or create plans, visit the <a href='https://photon.pagely.com'>API Portal</a>.</span> <strong>*Hidden</strong> plans may be purchased by the customer here, but are hidden from within the dashboard. Use case is for plans you only want new customers to see.";
    613         } else {
    614        
    615             // no plans
    616             echo "<span class='description'>You have not created any plans yet. <a href='https://photon.pagely.com'>Login to the Portal and create some.</a></span>";
    617        
    618         }
    619        
    620        
    621     }
    622    
    623     // checkboxes for which products to show.
    624     function _pagely_options_field_products_to_show($args) { 
    625         // this can be improved
    626 
    627         // checkboxes for which plans to show.
    628         $portal = $this->pp_portal_url;
    629    
    630         $all_products = $this->_get_reseller_products($limit = 10,$offset = 0);
    631         //  echo '<pre>';
    632         //print_r($all_products);
    633         if ( is_array($all_products->objects) && count($all_products->objects) > 0 ) {
    634             echo "<table class='wp-list-table widefat' cellspacing='0'>
    635                     <thead>
    636                         <tr>
    637                             <th scope='col' id='cb' class='manage-column column-show column-cb check-column'></th>
    638                             <th scope='col' id='plan' class='manage-column column-plan'>Product</th>
    639                             <th scope='col' id='plan' class='manage-column column-plan'>Price</th>
    640                             <th scope='col' id='plan' class='manage-column column-plan'>Recurring</th>
    641 
    642                         </tr>
    643                     </thead>";
    644            
    645             foreach ($all_products->objects as $p) {
    646                 if ($p->active == "1") {
    647                     $checked = '';
    648                    
    649                     if (is_array($args[0])) {
    650                    
    651                         if ( in_array($p->id,$args[0]) ) {
    652                             $checked = "checked='checked'";
    653                         }   
    654                    
    655                     }
    656                    
    657                     ($p->recurring == 1) ? $recurring = "Yes" : $recurring = "No";
    658 
    659        
    660                     echo "<tr>
    661                                 <td><input type='checkbox' class='required' id='{$args[1]}{$p->id}' name='pp_api[{$args[1]}][]' value='{$p->id}' {$checked} /></td>
    662                                 <td><label for='{$args[1]}{$p->id}'>{$p->name}</label></td>
    663                                 <td> ".$this->_cash($p->price)."</td>
    664                                 <td>{$recurring}</td>
    665                             </tr>";
    666                 }
    667             }
    668            
    669             echo "</table><span class='description'>These are all the hosting plans that are active in our system for your account. You may choose 3 at any one time to list for sale via this plugin. If you wish to modify or create plans, visit the <a href='https://photon.pagely.com'>API Portal</a>.</span></div>";
    670        
    671         } else {
    672             // no products
    673             echo "<span class='description'>You have not created any products yet. <a href='https://photon.pagely.com'>Login to the Portal and create some.</a></span>";
    674        
    675         }
    676        
    677     }
    678    
    679     // custom css textarea
    680     function _pagely_options_field_custom_css($args) { 
    681         echo "<textarea id='{$args[1]}' name='pp_api[{$args[1]}]' style='width:70%' rows='10'>{$args[0]}</textarea>";
    682     }
    683    
    684 
    685     // unused callback
    686     function _pagely_options_section_callback() { 
    687         $this->_clear_cached_keys();
    688         return;
    689     }   
    690    
    691 
    692     // sanitize some shiz
    693     function _sanitize_options($input) {
    694         // Create our array for storing the validated options 
    695         $output = array(); 
    696  
    697         // Loop through each of the incoming options 
    698         foreach( $input as $key => $value ) {   
    699         if( isset( $input[$key] ) ) { 
    700               // Strip all HTML and PHP tags and properly handle quoted strings 
    701              if (is_array($input[ $key ])) {
    702                 foreach ($input[ $key ] as $k => $v) {
    703                     $output[$key][$k] = strip_tags( stripslashes( $v ) );
    704                 }
    705              } else {
    706                 $output[$key] = strip_tags( stripslashes( $input[ $key ] ) ); 
    707                  }
    708         } 
    709         } 
    710  
    711         // Return the array processing any additional functions filtered by this action 
    712         return $output;
    713     }
    714        
    715     // the actual settings page
    716     function _settings_page() {
    717    
    718         wp_enqueue_script( 'pp-options' ); // is this needed still?
    719         if ($_POST) {
    720             if ($_POST['cache_clear']) {
    721                
    722                 $this->_clear_cached_keys();
    723                
    724                                
    725                 $this->_dialog( 'Cache Cleared' ,$type = 'notice');
    726             } else {
    727                 $this->_dialog( 'Posted' ,$type = 'notice');
    728             }
    729         }
    730         echo $this->_get_view( PP_PLUGIN_ASSETS_PATH . 'views/options-page.php');
    731        
    732        
    733     }
    734    
    735     function _clear_cached_keys() {
    736        
    737         //clear cached plans
    738         delete_transient( 'pp_plans' );
    739         update_option( 'pp_plans', '' );
    740         //clear caches products
    741         delete_transient( 'pp_products' );
    742         update_option( 'pp_products', '' );
    743 
    744     }
    745 
     328   
     329   
    746330    /************
    747331    * RENDERS THE ORDER FORM
    748332    *************/
    749     function _render_pagely_order_form($slug) {
     333    public function _render_pagely_order_form($slug) {
    750334       
    751335        // keep the track of which page the form is on
     
    791375            }
    792376        }
     377       
     378        if (isset($_POST['pagely_order']['product_id'])) {
     379            // plan preselected
     380            $this->_set_pp_session( array('preselected_plan' => $_POST['pagely_order']['product_id'] ) );
     381            // we'll check this session value on the order form and hide the plan selection.
     382            // if we already have a product selected we need to empty the cart and add the new one
     383        //TODO chekc cart   
     384            $product_id = $this->_get_pp_session('product_id');
     385            if (!empty($product_id)) {
     386                //get cart
     387                $cart = $this->_cart_contents();
     388               
     389                if (!empty($cart)) {
     390                    foreach ($cart as $k => $v) {
     391                        if ( $v['id'] == $product_id) {
     392                            // remove item
     393                            $this->_delitem_cart($k);
     394                            // add the new plan
     395                            $newplan = $this->_get_product($_POST['pagely_order']['product_id']);
     396                            // build item
     397                            $newitem = array(
     398                                'type'  => 'default',
     399                                'id'        => $newplan->id,
     400                                'name'  => $newplan->name,
     401                                'price'     => $newplan->price,
     402                                'desc'  => $newplan->desc,
     403                                'qty'   => 1,
     404                                'recurring' => 1,
     405                            );
     406                            // add to cart
     407                            $this->_additem_cart($newitem);
     408                        }
     409                    }
     410                }
     411               
     412            }
     413        }
    793414        $this->_set_pp_session( array('site' =>  home_url( '/' ).$slug ) );
    794415        $this->_set_pp_session( array('page' =>  $slug ) );
    795416               
    796         // our _get_view function loads an html snippet
     417        // our _get_view public function loads an html snippet
    797418        echo $this->_get_view(PP_PLUGIN_ASSETS_PATH . 'views/order-form.php' );         
    798419    }
    799420   
    800421    // this is the final page, after products
    801     function _render_pagely_complete($slug) {
     422    public function _render_pagely_complete($slug) {
    802423        if ( session_id() ) {
    803424            $this->_clear_pp_session();
     
    809430   
    810431    /************
    811     * API CART FUNCTIONS
     432    * API CART public functionS
    812433    *************/
    813434   
     
    815436    // this is the total on the payment page   
    816437    // dont think we use this anywhere
    817     function _cart_contents_js() {
     438    public function _cart_contents_js() {
    818439       
    819440        $cart = $this->_cart_contents();
     
    839460   
    840461    // get the count of cart items
    841     function _cart_total_items() { 
     462    public function _cart_total_items() {   
    842463        $cart = $this->_cart_contents();
    843464        return count($cart);       
     
    845466   
    846467    // get the dollar amount total of cart
    847     function _cart_total() {   
     468    public function _cart_total() {
    848469        $cart = $this->_get_pp_session('cart');
    849470        $cart = $this->_calc_cart_total($cart);
     
    852473
    853474    // get the contents (items) of cart
    854     function _cart_contents() {
     475    public function _cart_contents() {
    855476        // we want to return json of the cart items
    856477        $cart = $this->_get_pp_session('cart');
     
    866487    // add an item to the cart
    867488    // this adds the item to the session
    868     function _additem_cart($item = false) {
     489    public function _additem_cart($item = false) {
    869490        if (! $item ) {
    870491            //look for post
     
    905526    }
    906527   
    907     // function just returns a money format decimal based on locale settings
     528    // public function just returns a money format decimal based on locale settings
    908529    // locale is not fully implemented
    909     function _cash($amt) {
     530    public function _cash($amt) {
    910531        // we want to return json of the cart items
    911532        $sym = "$";
     
    915536   
    916537    // remove an item from the cart
    917     function _delitem_cart($item_id = false) {
     538    public function _delitem_cart($item_id = false) {
    918539        if (!$item_id && $_POST['item_id']) {
    919540            $item_id = $_POST['item_id'];
     
    936557   
    937558    // calc the cart total
    938     function _calc_cart_total($cart = false) {
     559    public function _calc_cart_total($cart = false) {
    939560        $total = 0;
    940561        foreach ($cart['items'] as $item) {
     
    947568   
    948569    // empty the cart
    949     function _clear_cart() {
     570    public function _clear_cart() {
    950571        $this->_set_pp_session( array('cart' => array()) );         
    951572    }
     
    955576    ***************/
    956577    // dont think we use this
    957     function _render_pagely_payment_form() {
     578    public function _render_pagely_payment_form() {
    958579
    959580        $this->_set_pp_session( array('last_activity' =>  time() ) );
     
    974595    * @return[body] returned will be a json response, see our API docs
    975596    */ 
    976     function _get_reseller_plans($limit = 25,$offset = 0) {
     597    public function _get_reseller_plans($limit = 25,$offset = 0) {
    977598       
    978599        $pagely_options = get_option('pp_api');
     
    1000621   
    1001622    // get a single plan, $plan_id, un cached
    1002     function _get_plan($plan_id) {
     623    public function _get_plan($plan_id) {
    1003624        $plan = $this->_pagely_api_request($method = 'GET','/bill_plans/single', $params = array(
    1004625                'id'=> $plan_id
     
    1006627        );     
    1007628        return json_decode($plan);
     629    }
     630   
     631    // get a single product, $plan_id, un cached
     632    public function _get_product($product_id) {
     633        $product = $this->_pagely_api_request($method = 'GET','/bill_products/single', $params = array(
     634                'id'=> $product_id
     635                )
     636        );     
     637        return json_decode($product);
    1008638    }
    1009639   
     
    1017647    * @return[body] returned will be a json response, see our API docs
    1018648    */ 
    1019     function _get_reseller_products($limit = 10,$offset = 0) {
     649    public function _get_reseller_products($limit = 10,$offset = 0) {
    1020650       
    1021651        $pagely_options = get_option('pp_api');
     
    1049679    * @return[body] returned will be a json response, see our API docs
    1050680    */ 
    1051     function _pagely_jax_formvalidate_callback() {
     681    public function _pagely_jax_formvalidate_callback() {
    1052682        header( "Content-Type: application/json" );
    1053683
     
    1093723    * @return[body] returned will be a json response, see our API docs
    1094724    */ 
    1095     function _pagely_jax_accformsubmit_callback() {
     725    public function _pagely_jax_accformsubmit_callback() { 
    1096726        // we did the form validation client side, so lets call this input good for now and save it to the session.
    1097727        header( "Content-Type: application/json" );
     
    1128758   
    1129759    // send the previously saved data from the session, to the api
    1130     function _send_account_data() {
     760    public function _send_account_data() {
    1131761           
    1132762        $form = $this->_get_pp_session('acc_form_post');
     
    1174804            $form['domain_type'] = isset($form['domain_type']) ? $form['domain_type'] : 0;
    1175805            $form['domain']     = isset($form['domain']) ?  $form['domain'] : '';
     806            $form['is_hosted']      = isset($form['is_hosted']) ?  $form['is_hosted'] : 1;
    1176807           
    1177808            $this->_set_pp_session( array('account_id' => $result->id) );
     
    1181812            $this->_set_pp_session( array('promo_code' => $form['promo_code'] ) );
    1182813            $this->_set_pp_session( array('domain_type' => $form['domain_type'] ) );
    1183            
     814            $this->_set_pp_session( array('is_hosted' => $form['is_hosted'] ) );
     815            $this->_set_pp_session( array('product_id' => $form['product_id'] ) );
    1184816            $result->message = "Welcome aboard <em>{$result->object->name}</em>!";
    1185817                   
     
    1187819            // we need to add an item to the cart
    1188820           
    1189             // get the plan_id
    1190             $plan_id = $form['plan'];
    1191             // get the plan details
    1192            
    1193             // this call is direct to the api to make sure we have the latest info
    1194             $plan = $this->_get_plan($plan_id);
    1195            
    1196             // build item
    1197             $item = array(
    1198                 'type'  => 'default',
    1199                 'id'        => $plan->id,
    1200                 'name'  => $plan->name,
    1201                 'price'     => $plan->price,
    1202                 'desc'  => $plan->desc,
    1203                 'qty'   => 1,
    1204                 'recurring' => 1,
    1205             );
     821            // if a hosted plan do...
     822            if ($form['is_hosted'] == 1 && isset($form['plan']) ) {
     823                // get the plan_id
     824                $plan_id = $form['plan'];
     825               
     826                // get the plan details
     827                // this call is direct to the api to make sure we have the latest info
     828                $plan = $this->_get_plan($plan_id);
     829               
     830                // build item
     831                $item = array(
     832                    'type'  => 'default',
     833                    'id'        => $plan->id,
     834                    'name'  => $plan->name,
     835                    'price'     => $plan->price,
     836                    'desc'  => $plan->desc,
     837                    'qty'   => 1,
     838                    'recurring' => 1,
     839                );
     840           
     841            } else if($form['is_hosted'] == 0 && isset($form['product_id']) ) {
     842                // else this is just a product, like CDN or domain reg
     843
     844                $product_id = $form['product_id'];
     845                // get the product details
     846                // this call is direct to the api to make sure we have the latest info
     847                $product = $this->_get_product($product_id);
     848                // build item
     849                $item = array(
     850                        'type'  => $product->type,
     851                        'id'        => $product->id,
     852                        'name'  => $product->name,
     853                        'price'     => $product->price,
     854                        'desc'  => $product->desc,
     855                        'qty'   => 1,
     856                        'recurring' => $product->recurring,
     857                    );
     858               
     859            }           
    1206860            // add to cart
    1207861            $this->_additem_cart($item);
    1208862           
    1209             // add registration to the cart if needed for domain
    1210             if ( $form['domain_type'] == 1) {
     863        /*  if ( $form['domain_type'] == 1) {
    1211864               
    1212865                $item = array(
     
    1222875                $this->_additem_cart($item);
    1223876            }
     877        */
    1224878       
    1225879        }
     
    1235889    * @return[body] returned will be a json response, see our API docs
    1236890    */ 
    1237     function _pagely_jax_gopaypal_callback() { 
     891    public function _pagely_jax_gopaypal_callback() {   
    1238892        header( "Content-Type: application/json" );
    1239893       
     
    1304958    * @return[body] returned will be a json response, see our API docs
    1305959    */ 
    1306     function _pagely_jax_payformsubmit_callback() {
     960    public function _pagely_jax_payformsubmit_callback() { 
    1307961   
    1308962        header( "Content-Type: application/json" );
     
    13881042            if ($this->_get_pp_session('paid') == 1 && !$this->_get_pp_session('domain_queued')) {
    13891043                $domain_push = $this->_put_domain($params);
    1390                 $domain_push = json_decode($domain_push);
     1044                //$domain_push = json_decode($domain_push);
    13911045                if($domain_push->result != 2) {
    13921046                    // there was an error pushing the domain to the install queue
     
    13951049                }
    13961050            }
    1397             $this->_clear_cart();
     1051           
     1052           
     1053            if ( $this->_get_pp_session('is_hosted') == 1 && !$this->_get_pp_session('product_id')) {
     1054                $this->_clear_cart();
     1055            } else {
     1056                //we shoudl have a product in the cart we need too add a purchase for
     1057                $this->_set_pp_session( array('domain_queued' => 'true') );
     1058                $this->_set_pp_session( array('order_complete' => 'true') );
     1059                $this->purchase_cart();
     1060               
     1061            }
    13981062           
    13991063        } else {
     
    14141078    */
    14151079   
    1416     function _put_domain($oldparams = false) {
     1080    public function _put_domain($oldparams = false) {
    14171081        $params = array();
    14181082        $this->_set_pp_session( array('last_activity' =>  time() ) );
     
    14201084       
    14211085        // never trust user input, rebuild the post array before sending.
     1086        $params['is_hosted']                = $this->_get_pp_session('is_hosted');
    14221087        $params['account_id']           = $this->_get_pp_session('account_id');
    14231088        $params['domain']                   = $this->_get_pp_session('domain');
     
    14631128    * @return[body] returned will be a json response, see our API docs
    14641129    */
    1465     function _process_post_paypal() {
     1130    public function _process_post_paypal() {
    14661131        global $post;
    14671132        pp_session_enable();
     
    14781143                }
    14791144            }
    1480             $this->_clear_cart();
     1145            if ( $this->_get_pp_session('is_hosted') == 1 && !$this->_get_pp_session('product_id') ) {
     1146                $this->_clear_cart();
     1147            } else {
     1148                //purchase the products in the cart
     1149                $this->purchase_cart();
     1150                $this->_set_pp_session( array('domain_queued' => 'true') );
     1151                $this->_set_pp_session( array('order_complete' => 'true') );
     1152                wp_redirect( $this->_get_pp_session('site').'?complete=true', 301 );
     1153
     1154            }
    14811155        } else {
    14821156            $this->_set_pp_session( array('paid' => 0) );
     
    14951169    */     
    14961170   
    1497     function _pagely_jax_purchase_cart_callback() {
     1171    public function _pagely_jax_purchase_cart_callback() {
    14981172        header( "Content-Type: application/json" );
    14991173
    1500         // get the cart contents
     1174        $result = _purchase_cart();     
     1175        echo json_encode($result);
     1176        die();
     1177    }
     1178
     1179    public function purchase_cart() {
     1180       
     1181        // get the cart contents
    15011182        $cart_contents = $this->_cart_contents();
    15021183       
     
    15441225            $result->failures = $failure;
    15451226        }
    1546        
    1547         echo json_encode($result);
    1548         die();
    1549     }
    1550 
     1227
     1228        return $result;
     1229    }
    15511230
    15521231   
     
    15541233    * AJAX add item to cart
    15551234    ******************************/     
    1556     function _pagely_jax_addtocart_callback() {
     1235    public function _pagely_jax_addtocart_callback() {
    15571236        header( "Content-Type: application/json" );
    15581237
     
    16191298    * AJAX remove item to cart
    16201299    ******************************/         
    1621     function _pagely_jax_removefromcart_callback() {
     1300    public function _pagely_jax_removefromcart_callback() {
    16221301
    16231302        $item_hash = $_POST['item_id'];
     
    16351314    * @return[body] returned will be a json response, see our API docs
    16361315    */ 
    1637     function _pagely_jax_generic_callback() {
     1316    public function _pagely_jax_generic_callback() {
    16381317        $posted = $_POST;
    16391318        switch ($posted['ppdo']) {
     
    16551334    */     
    16561335   
    1657     function _test_api() {
     1336    public function _test_api() {
    16581337
    16591338        $params = array();
     
    16821361
    16831362    /***************************
    1684     * WRAPPER FUNCTION FOR ALL PAGELY API REQUESTS 
    1685     * This function makes a remote request to the Pagely REST API
     1363    * WRAPPER public function FOR ALL PAGELY API REQUESTS   
     1364    * This public function makes a remote request to the Pagely REST API
    16861365    * @param string $method GET | POST | PUT | DELETE
    16871366    * @param string $uri the controller and method to call on teh api
     
    16901369    * @return[body] returned will be a json response, see our API docs
    16911370    */
    1692     function _pagely_api_request($method = 'GET', $uri = '/controller/method', $params = array() ) {
     1371    public function _pagely_api_request($method = 'GET', $uri = '/controller/method', $params = array() ) {
    16931372
    16941373        // setup the request
     
    17621441   
    17631442    /************
    1764     *   MISC FUNCTIONS
     1443    *   MISC public functionS
    17651444    *************/
    17661445    // send an email to support
    17671446    // dont think we use this
    1768     function _support_email($to,$from,$subject,$msg) {
     1447    public function _support_email($to,$from,$subject,$msg) {
    17691448        wp_mail( $to, $subject, $message);
    17701449    }
    17711450   
    17721451    // support site
    1773    function _supportsite() {
     1452   public function _supportsite() {
    17741453        // get option
    17751454        $key = 'support_url';
     
    17811460   
    17821461   // These are the 3 plan id's the user selected on the options page
    1783    function _get_plans_to_show() {
     1462   public function _get_plans_to_show() {
    17841463        $key = 'plans_to_show';
    17851464        $api_options = get_option('pp_api');
     
    17911470   
    17921471    // These are the product id's the user selected on the options page
    1793    function _get_products_to_show() {
     1472   public function _get_products_to_show() {
    17941473        $key = 'products_to_show';
    17951474        $api_options = get_option('pp_api');
     
    18011480   
    18021481   
    1803     // This function filters the 3 selected against all plans
     1482    // This public function filters the 3 selected against all plans
    18041483    // to return a full plan object for each of the 3
    18051484    // we do this way for now so we always get an uncached list before saving locally
    1806    function _get_plans() {
     1485   public function _get_plans() {
    18071486        $plans = $this->_get_reseller_plans(10,0);
    18081487        $plans_to_show = $this->_get_plans_to_show();
     
    18131492   
    18141493        $return_plans = array();
    1815                
     1494        if (!is_array($plans_to_show)) {
     1495            return $return_plans;
     1496        }       
    18161497        // check short list against master list
    18171498        if ($plans->result == 2 && count($plans->objects) > 0 ) {
     
    18251506        if ($order_by == 0) {
    18261507            // sort by $p->price, low to high
    1827             usort($return_plans['plans'], array(&$this,  "_sort_plans_asc"));
     1508            usort($return_plans['plans'], array($this,  "_sort_plans_asc"));
    18281509           
    18291510        } else if ($order_by == 1) {
    18301511            // sort by $p->price, high to low
    18311512
    1832             usort($return_plans['plans'], array(&$this,  "_sort_plans_desc"));
     1513            usort($return_plans['plans'], array($this,  "_sort_plans_desc"));
    18331514           
    18341515        }
     
    18471528   
    18481529    // sort array of objects
    1849     function _sort_plans_asc($a, $b) {
     1530    public function _sort_plans_asc($a, $b) {
    18501531        $al = $a->price;
    18511532        $bl = $b->price;
     
    18571538   
    18581539    // sort array of objects
    1859     function _sort_plans_desc($a, $b) {
     1540    public function _sort_plans_desc($a, $b) {
    18601541        $al = $a->price;
    18611542        $bl = $b->price;
     
    18661547    }
    18671548   
    1868     // This function filters the selected products against all products
     1549    // This public function filters the selected products against all products
    18691550    // to return a full product object for each
    1870    function _get_products() {
     1551   public function _get_products() {
    18711552        $products = $this->_get_reseller_products(10,0);
    18721553        //print_r($products);
    18731554        $products_to_show = $this->_get_products_to_show();
     1555
     1556        $api_options = get_option('pp_api');
     1557        $order_by = $api_options['order_by']; // 0 is price: low to high, 1 is price: high to low
     1558
    18741559        if (!$products_to_show) {
    18751560            return false;
     
    18841569            }
    18851570        }
     1571       
     1572        // sort
     1573        if ($order_by == 0) {
     1574            // sort by $p->price, low to high
     1575            usort($return_products, array($this,  "_sort_plans_asc"));
     1576           
     1577        } else if ($order_by == 1) {
     1578            // sort by $p->price, high to low
     1579
     1580            usort($return_products, array($this,  "_sort_plans_desc"));
     1581           
     1582        }
     1583
    18861584        // return selected plans
    18871585        if (count($return_products) > 0) {
     
    18951593    // some error messages and warning. jquery.dialog //
    18961594    // pretty sure we dropped jquery ui
    1897     function _dialog($msg,$type = 'error') {
     1595    public function _dialog($msg,$type = 'error') {
    18981596            switch ($type) {
    18991597                case 'error':
     
    19081606   
    19091607    /**********
    1910     * loads a view file, should be last function of class
     1608    * loads a view file, should be last public function of class
    19111609    **********/
    1912     function _get_view($filename) {
     1610    public function _get_view($filename) {
    19131611        if (is_file($filename)) {
    19141612        ob_start();
     
    19261624// load the plugin
    19271625add_action( 'init', array( 'PagelyApi', 'init' ),1);
    1928 
     1626//$PagelyApi = new PagelyApi;
    19291627// no closing php tag
     1628require_once(PP_PLUGIN_ASSETS_PATH."/inc/options_page.php");
     1629
  • pagely-reseller-management/trunk/readme.txt

    r728580 r732491  
    33Tags: admin, administration, plugin, website reseller, hosting, Wordpress, CMS, page.ly,pagely Wordpress Hosting
    44Requires at least: 3.4
    5 Tested up to: 3.5.1
     5Tested up to: 3.5.2
    66Stable tag: trunk
    77License: GPLv2 or later
     
    2020Read [the documentation here](https://docs-api.pagely.com/reseller-plugin/).
    2121== Changelog ==
     22= 3.1.5 =
     23new options page class, and options
    2224= 3.1.4 =
    2325Added additional client ip header to API calls. Allow for plugin options page to me moved under the Settings Menu.
  • pagely-reseller-management/trunk/views/complete.php

    r702419 r732491  
    11<!-- order complete -->
     2
    23<div id="pp">
    34    <div class="hero-unit">
    45        <h2>Order Complete. Thank You.</h2>
    5         <p>Please allow a few moments for your new site to provision and then <strong>check your email</strong> for your welcome information. <strong>Thanks again and Welcome Aboard!</strong></p>
     6        <p>Please allow a few moments for your new service to provision and then <strong>check your email</strong> for your welcome information. <strong>Thanks again and Welcome Aboard!</strong></p>
    67       
    78        <?php if( isset($_GET['product_fails']) ) { ?>
  • pagely-reseller-management/trunk/views/order_step1.php

    r702419 r732491  
    33</span></div>-->
    44<?php
    5 
    65$preselected_plan = $this->_get_pp_session('preselected_plan');                         
    76$plans = $this->_get_plans();
     7$products = $this->_get_products();
     8$api_options = get_option('pp_api');
    89
    910$form = $this->_get_pp_session('acc_form_post');
     
    1617$this_site = str_replace(array('http://','https://'),'',site_url());
    1718
     19if ( !isset($api_options['products_only']) || $api_options['products_only'] == 0 ) {
     20    $product_only = false;
     21} else {
     22    $product_only = true;
     23}
    1824if (!empty($_POST) && $referer_parse['host'] == $this_site && isset($_POST['auto_submit']) ) {
    1925    $posted_from_dff_page = true;
     
    4652
    4753            <div class="well">         
     54                <?php if ( !$product_only) { ?>
     55                <input type="hidden" name="pagely_order[is_hosted]" value="1"/>
     56
    4857                <div class="control-group">
    4958                  <label class="control-label" for="input01">Plan</label> 
     
    7786                    </div>
    7887                </div>
     88               
     89                <?php } else { // just products ?>
     90                    <input type="hidden" name="pagely_order[is_hosted]" value="0"/>
     91                    <div class="control-group">
     92                  <label class="control-label" for="input01">Item</label> 
     93                  <div class="controls">
     94        <?php if (!empty($preselected_plan)) {
     95                foreach ($products as $p) {
     96                if ($p->id == $preselected_plan) {?>
     97                    <p class="lead" style="margin:0"><?php echo $p->name;?> <button id="planchange"class="btn btn-mini pull-right">Change</button></p>         
     98                <?php }
     99            }
     100            } ?>
     101                      <select id="planselector" name="pagely_order[product_id]" class="required <?php if (!empty($preselected_plan)){?>hide<?php }?>">     
     102                        <?php foreach ($products as $p) {
     103                                    if ( $p->id == $products['default'] ) {
     104                                         $recommended = $p->id;
     105                                    }
     106                           
     107                                    if (!$preselected_plan) {
     108                                        $selected = $recommended;
     109                                    } else {
     110                                        $selected = $preselected_plan;
     111                                    }
     112                                   
     113                                    $featured = false;
     114                                    $price = explode('.',$p->price);
     115                                    if( !$preselected_plan && $recommended == $p->id ) { $featured = 'featured'; }                     
     116                        ?>
     117                            <option value="<?php echo $p->id?>" <?php if( $selected == $p->id) { echo 'selected="selected"'; } ?>><?php echo $p->name?> | $<?php echo $p->price;?></option>     
     118                            <?php } ?>
     119                        </select>
     120                                       
     121                    </div>
     122                </div>
     123
     124                <?php } ?>
     125               
    79126           </div><!--well-->
    80127           
     
    85132              <div class="controls">
    86133               
    87                     <input id="po_domain" name="pagely_order[domain]" type="text" class="span3 required" placeholder="domain.com" value="<?php if (isset($form['domain']) ) { echo $form['domain']; }?>"> <span class="help-inline">Change at anytime. Does not include registration.</span>
     134                    <input id="po_domain" name="pagely_order[domain]" type="text" class="span3 required" placeholder="domain.com" value="<?php if (isset($form['domain']) ) { echo $form['domain']; }?>"> <?php if ($product_only) { ?><span class="help-inline">What domain to use with this item?</span><?php } else { ?><span class="help-inline">Change at anytime. Does not include registration.</span><?php }?>
    88135                    <span class="validation_msg"></span>
    89136              </div>
     
    212259                    <div class="well cen">
    213260                        <p><button id="pay_by_paypal" class="btn btn-large btn-success">PayPal</button></p>
    214                         <p class="lead">Pay easily from your Paypal Account</p>
     261                        <p class="lead">Pay easily with your PayPal<sup>&reg;</sup> Account</p>
    215262                        <?php wp_nonce_field('pagely_pay_submit','pagely_order_pay_nounce'); ?>
    216263
Note: See TracChangeset for help on using the changeset viewer.