Ejemplo n.º 1
0
 public function get_data($tab)
 {
     global $paged;
     try {
         switch ($tab) {
             case 'search':
                 $term = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
                 $api = Sputnik_API::search($term);
                 break;
             case 'account':
                 $api = Sputnik_API::get_purchased();
                 break;
             case 'featured':
             case 'popular':
             case 'new':
             case 'updated':
             case 'price':
             default:
                 $api = Sputnik_API::get_all($paged, array('browse' => $tab));
                 break;
         }
     } catch (Exception $e) {
         $this->connect_error = true;
         return false;
     }
     return array('items' => $api['body'], 'pages' => $api['headers']['x-pagecount']);
 }
Ejemplo n.º 2
0
 public function get_data($tab)
 {
     try {
         switch ($tab) {
             case 'yours':
                 add_filter('sputnik_install_row_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
                 add_filter('sputnik_install_grid_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
                 $api = Sputnik_API::get_own();
                 break;
             default:
             case 'purchased':
                 $api = Sputnik_API::get_purchased();
                 break;
         }
     } catch (Exception $e) {
         $this->connect_error = true;
         return false;
     }
     $this->count = count($api['body']);
     if ($tab === 'yours') {
         $api['body'][] = (object) array('slug' => '__add_new', 'name' => __('Add Your Plugin', 'wp-e-commerce'), 'description' => __('List your plugin on the WPEconomy store. Read our developer documentation and get started!', 'wp-e-commerce'), 'rating' => (object) array('average' => 0, 'count' => 0), 'price' => 0, 'version' => '', 'author' => '', 'author_slug' => '', 'thumb' => false);
     }
     $count = 1;
     if (!empty($api['headers']['x-pagecount'])) {
         $count = $api['headers']['x-pagecount'];
     }
     return array('items' => $api['body'], 'pages' => $count);
 }
Ejemplo n.º 3
0
    public static function auth_access()
    {
        if (isset($_REQUEST['denied'])) {
            $return_url = Sputnik_Admin::build_url(array('auth' => 'denied'));
        } else {
            $request = get_option('sputnik_oauth_request', false);
            self::$auth = new Sputnik_API_Auth(Sputnik::OAUTH_KEY, Sputnik::OAUTH_SECRET, $request['oauth_token'], $request['oauth_token_secret']);
            $access = self::$auth->get_access_token($_REQUEST['oauth_verifier']);
            update_option('sputnik_oauth_access', $access);
            $args = array();
            if (!empty($_REQUEST['oauth_buy'])) {
                $args['oauth_buy'] = $_REQUEST['oauth_buy'];
            }
            $return_url = Sputnik_Admin::build_url($args);
        }
        // Close the authentication popup
        ?>
<!DOCTYPE html><html>
	<head>
		<title><?php 
        _e('Redirecting ...', 'wpsc');
        ?>
</title>
		<script type="text/javascript">
			parent.location = '<?php 
        echo wp_validate_redirect($return_url);
        ?>
';
			window.close();
		</script>
	</head>
	<body>&nbsp;</body>
</html><?php 
        die;
    }
Ejemplo n.º 4
0
 public function prepare_items()
 {
     require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     global $tabs, $tab, $paged, $type, $term;
     wp_reset_vars(array('tab'));
     $paged = $this->get_pagenum();
     // These are the tabs which are shown on the page
     $tabs = array();
     $tabs['purchased'] = __('Purchased Plugins', 'wp-e-commerce');
     $tabs['yours'] = __('Your Plugins', 'wp-e-commerce');
     $nonmenu_tabs = array();
     //Valid actions to perform which do not have a Menu item.
     $tabs = apply_filters('install_plugins_tabs', $tabs);
     $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
     // If a non-valid menu tab has been selected, and its not a non-menu action.
     if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) {
         $tab = key($tabs);
     }
     $args = array();
     try {
         switch ($tab) {
             case 'yours':
                 add_filter('sputnik_install_row_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
                 add_filter('sputnik_install_grid_action_links', array(__CLASS__, 'mangle_action_for_own'), 10, 2);
                 $api = Sputnik_API::get_own();
                 break;
             default:
             case 'purchased':
                 $api = Sputnik_API::get_purchased();
                 break;
         }
     } catch (Exception $e) {
         $this->connect_error = true;
         return false;
     }
     if (!empty($_REQUEST['view'])) {
         switch ($_REQUEST['view']) {
             case 'grid':
             case 'list':
                 $this->view = $_REQUEST['view'];
                 break;
             default:
                 $this->view = 'grid';
                 break;
         }
     } else {
         $this->view = 'grid';
     }
     $this->items = $api['body'];
     if (isset($api['headers']['x-pagecount'])) {
         $this->set_pagination_args(array('total_items' => $api['headers']['x-pagecount'], 'per_page' => 30));
     }
 }
Ejemplo n.º 5
0
 protected static function download($url, $timeout = 300)
 {
     //WARNING: The file is not automatically deleted, The script must unlink() the file.
     if (!$url) {
         return new WP_Error('http_no_url', __('Invalid URL Provided.', 'wp-e-commerce'));
     }
     $tmpfname = wp_tempnam($url);
     if (!$tmpfname) {
         return new WP_Error('http_no_file', __('Could not create Temporary file.', 'wp-e-commerce'));
     }
     $args = array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname, 'headers' => array('X-WP-Domain' => Sputnik_API::domain()), 'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION);
     Sputnik_API::sign_download($url, $args);
     $response = wp_safe_remote_get($url, $args);
     if (is_wp_error($response)) {
         unlink($tmpfname);
         return $response;
     }
     if (200 != wp_remote_retrieve_response_code($response)) {
         unlink($tmpfname);
         return new WP_Error('http_404', trim(wp_remote_retrieve_response_message($response)));
     }
     return $tmpfname;
 }
Ejemplo n.º 6
0
 public function prepare_items()
 {
     require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     global $tabs, $tab, $paged, $type, $term;
     wp_reset_vars(array('tab'));
     $paged = $this->get_pagenum();
     // These are the tabs which are shown on the page
     $tabs = array();
     $tabs['dashboard'] = __('Search', 'wp-e-commerce');
     if (Sputnik::account_is_linked()) {
         $tabs['purchased'] = __('Purchased Plugins', 'wp-e-commerce');
     } elseif ($tab == 'purchased') {
         wp_redirect(Sputnik_Admin::build_url());
         exit;
     }
     if ('search' == $tab) {
         $tabs['search'] = __('Search Results', 'wp-e-commerce');
     }
     $tabs['featured'] = _x('Featured', 'Plugin Installer', 'wp-e-commerce');
     $tabs['popular'] = _x('Popular', 'Plugin Installer', 'wp-e-commerce');
     $tabs['new'] = _x('Newest', 'Plugin Installer', 'wp-e-commerce');
     $tabs['updated'] = _x('Recently Updated', 'Plugin Installer', 'wp-e-commerce');
     $tabs['price'] = _x('Lowest Priced', 'Plugin Installer', 'wp-e-commerce');
     $nonmenu_tabs = array('account');
     //Valid actions to perform which do not have a Menu item.
     $tabs = apply_filters('install_plugins_tabs', $tabs);
     $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
     // If a non-valid menu tab has been selected, and its not a non-menu action.
     if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) {
         $tab = key($tabs);
     }
     $args = array();
     try {
         switch ($tab) {
             case 'purchased':
                 $api = Sputnik_API::get_purchased();
                 break;
             case 'search':
                 $term = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
                 $api = Sputnik_API::search(urlencode($term), array('browse' => $tab), $paged);
                 break;
             case 'account':
                 $api = Sputnik_API::get_purchased();
                 break;
             case 'featured':
             case 'popular':
             case 'new':
             case 'updated':
             case 'price':
             default:
                 $api = Sputnik_API::get_all($paged, array('browse' => $tab));
                 break;
         }
     } catch (Exception $e) {
         $this->connect_error = true;
         return false;
     }
     if (!empty($_REQUEST['view'])) {
         switch ($_REQUEST['view']) {
             case 'grid':
             case 'list':
                 $this->view = $_REQUEST['view'];
                 break;
             default:
                 $this->view = 'grid';
                 break;
         }
     } else {
         $this->view = 'grid';
     }
     $this->items = $api['body'];
     $total_items = isset($api['headers']['x-pagecount']) ? $api['headers']['x-pagecount'] : -1;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => 30));
 }
Ejemplo n.º 7
0
 protected function http($url, $method, $postfields = NULL)
 {
     $args = array('method' => $method);
     switch ($method) {
         case 'POST':
             if (!empty($postfields)) {
                 $args['body'] = $postfields;
             }
             break;
     }
     $args['headers'] = array('X-WP-Domain' => Sputnik_API::domain());
     $response = wp_remote_request($url, $args);
     if (is_wp_error($response)) {
         throw new Exception($response->get_error_message());
     }
     if ($response['response']['code'] != 200) {
         throw new Exception($response['body']);
     }
     return $response['body'];
 }
Ejemplo n.º 8
0
 /**
  * When a user clicks a plugin's "Buy Now" button, setup a payment flow.
  *
  * @param string $plugin_id
  */
 protected static function purchase($plugin_id)
 {
     $plugin = Sputnik::get_plugin($plugin_id);
     if (Sputnik::is_purchased($plugin->slug)) {
         wp_redirect(self::build_url(array('install' => $plugin_id)));
         die;
     }
     // Request a checkout token from the Baikonur REST API for this product (associate user ID in custom field?)
     $response = Sputnik_API::get_checkout_token($plugin);
     // Redirect to PayPal with token in checkout URL
     wp_redirect($response['body']->checkout_uri);
     exit;
 }
Ejemplo n.º 9
0
 public static function mangle_bulk_http($r, $url)
 {
     if (strpos($url, Sputnik::API_BASE) === false) {
         return $r;
     }
     $auth_header = Sputnik_API::get_auth_for_download($url);
     list($key, $auth_header) = explode(':', $auth_header);
     $r['headers']['X-WP-Domain'] = Sputnik_API::domain();
     $r['headers']['Authorization'] = $auth_header;
     return $r;
 }
Ejemplo n.º 10
0
 /**
  * Get a single module
  *
  * @param string $id
  * @return stdObject
  */
 public static function get_plugin($id, $user = 0)
 {
     $plugin = Sputnik_API::get_single($id, $user);
     return $plugin['body'];
 }