/** * Get a ShoppCustomer with ShoppBilling and ShoppShipping * * @api * @since 1.2 * * @param int $customer (optional) customer id, WordPress user associated customer, email address associated with customer, or false to load the current global customer object * @param string $key (optional default:customer) customer for lookup by customer id, wpuser to lookup by WordPress user, or email to lookup by email address * @return mixed, stdClass representation of the customer, bool false on failure **/ function shopp_customer($customer = false, $key = 'customer') { $Customer = false; if (!$customer) { $Customer =& ShoppCustomer(); return $Customer; } if ('wpuser' == $key) { if ('wordpress' != shopp_setting('account_system')) { shopp_debug(__FUNCTION__ . " failed: Customer {$customer} could not be found."); return false; } $Customer = new ShoppCustomer($customer, 'wpuser'); } else { if ('email' == $key) { $Customer = new ShoppCustomer($customer, 'email'); } else { $Customer = new ShoppCustomer($customer); } } if (!$Customer->id) { shopp_debug(__FUNCTION__ . " failed: Customer {$customer} could not be found."); return false; } $Customer->Billing = new BillingAddress($Customer->id, 'customer'); $Customer->Shipping = new ShippingAddress($Customer->id, 'customer'); if (!$Customer->id) { $Customer->Shipping->copydata($Customer->Billing); } return $Customer; }
/** * Returns the global context object used in the shopp('checkout') call * * @internal * @since 1.2 * * @param ShoppOrder $Object The ShoppOrder object to set as the working context * @param string $object The context being worked on by the Theme API * @return ShoppOrder|ShoppCustomer The active object context **/ public static function _setobject($Object, $object, $tag) { if (is_object($Object) && is_a($Object, 'ShoppOrder') && 'checkout' == strtolower($object)) { return $Object; } else { if (strtolower($object) != 'checkout') { return $Object; } } // not mine, do nothing if (isset(self::$register[$tag])) { $handler = self::$register[$tag]; if (is_array($handler) && 'ShoppCustomerThemeAPI' == $handler[0]) { return ShoppCustomer(); } } return ShoppOrder(); }
function widget($args, $options) { if (!empty($args)) { extract($args); } $loggedin = ShoppCustomer()->loggedin(); // Hide login form on account page when not logged in to prevent duplicate forms if (is_account_page() && !$loggedin) { return ''; } $defaults = array('title' => $loggedin ? __('Your Account', 'Shopp') : __('Login', 'Shopp')); $options = array_merge($defaults, $options); extract($options); $title = $before_title . $title . $after_title; remove_filter('shopp_show_account_errors', array($this, 'showerrors')); $Page = new ShoppAccountPage(); $menu = $Page->content('', 'widget'); echo $before_widget . $title . $menu . $after_widget; }
/** * Checks if the customer is not logged in * * @api `shopp('customer.not-logged-in')` * @since 1.1 * * @param string $result The output * @param array $options The options * @param ShoppCustomer $O The working object * @return bool True if not logged in, false otherwise **/ public static function not_logged_in($result, $options, $O) { return !ShoppCustomer()->loggedin() && 'none' != shopp_setting('account_system'); }
/** * Setup and process account dashboard page requests * * @author Jonathan Davis * @since 1.2 * * @return void **/ public function dashboard() { $Order = ShoppOrder(); $this->add_dashboard('logout', __('Logout', 'Shopp')); $this->add_dashboard('orders', __('Your Orders', 'Shopp'), true, array(ShoppCustomer(), 'load_orders')); $this->add_dashboard('downloads', __('Downloads', 'Shopp'), true, array(ShoppCustomer(), 'load_downloads')); $this->add_dashboard('profile', __('My Account', 'Shopp'), true); // Pages not in menu navigation $this->add_dashboard('login', __('Login to your Account'), false); $this->add_dashboard('recover', __('Password Recovery'), false); $this->add_dashboard('rp', __('Password Recovery'), false); $this->add_dashboard('menu', __('Dashboard', 'Shopp'), false); do_action('shopp_account_menu'); // Always handle customer profile updates add_action('shopp_account_management', array(ShoppCustomer(), 'profile')); // Add dashboard page specific handlers add_action('shopp_account_management', array($this, 'dashboard_handler')); $query = $_SERVER['QUERY_STRING']; $query = html_entity_decode($query); $query = explode('&', $query); $request = 'menu'; $id = false; foreach ($query as $queryvar) { $value = false; if (false !== strpos($queryvar, '=')) { list($key, $value) = explode('=', $queryvar); } else { $key = $queryvar; } if (in_array($key, array_keys($this->dashboard))) { $request = $key; $id = $value; } } $this->account = compact('request', 'id'); $download_request = get_query_var('s_dl'); if (!ShoppCustomer()->loggedin()) { $screens = array('login', 'recover', 'rp'); if (!in_array($this->account['request'], $screens)) { $this->account = array('request' => 'login', 'id' => false); } } do_action('shopp_account_management'); if ('rp' == $request) { ShoppAccountPage::resetpassword($_GET['rp']); } if (isset($_POST['recover-login'])) { ShoppAccountPage::recovery(); } }
public function content($content, $request = false) { if (!$request) { global $wp_query; // Test that this is the main query and it is the account page if (!$wp_query->is_main_query() || !is_shopp_page('account')) { return $content; } } $widget = 'widget' === $request; if ($widget) { $request = 'menu'; } // Modify widget request to render the account menu $orderlookup = ''; if ('none' == shopp_setting('account_system')) { $orderlookup = shopp('customer', 'get-order-lookup'); } // $download_request = get_query_var('s_dl'); if (!$request) { $request = ShoppStorefront()->account['request']; } $templates = array('account-' . $request . '.php', 'account.php'); $context = ShoppStorefront::intemplate(); // Set account page context $Errors = ShoppErrorStorefrontNotices(); ob_start(); if (apply_filters('shopp_show_account_errors', true) && $Errors->exist()) { echo ShoppStorefront::errors(array("errors-{$context}", 'account-errors.php', 'errors.php')); } if (!empty($orderlookup)) { echo $orderlookup; } else { if ('login' == $request || !ShoppCustomer()->loggedin()) { $templates = array('login-' . $request . '.php', 'login.php'); } Shopp::locate_template($templates, true); } $content = ob_get_clean(); // Suppress the #shopp div for sidebar widgets if ($widget) { $content = '<!-- id="shopp" -->' . $content; } return apply_filters('shopp_account_template', $content, $request); }
/** * Handles product file download requests * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function download() { $Shopp = Shopp::object(); $download = $this->request['shopp_download']; $Purchase = false; $Purchased = false; if (defined('WP_ADMIN')) { $forbidden = false; $Download = new ProductDownload($download); } else { $Order = ShoppOrder(); $accounts = 'none' != shopp_setting('account_system'); $Download = new ProductDownload(); $Download->loadby_dkey($download); $Purchased = $Download->purchased(); $Purchase = new ShoppPurchase($Purchased->purchase); $Purchase->load_events(); $name = $Purchased->name . (!empty($Purchased->optionlabel) ? ' (' . $Purchased->optionlabel . ')' : ''); $forbidden = false; // Voided orders if ($Purchase->isvoid()) { shopp_add_error(Shopp::__('"%s" cannot be downloaded because the order has been cancelled.', $name)); $forbidden = true; } // Purchase Completion check if (!$Purchase->ispaid() && !SHOPP_PREPAYMENT_DOWNLOADS) { shopp_add_error(Shopp::__('"%s" cannot be downloaded because payment has not been received yet.', $name)); $forbidden = true; } // If accounts are used and this is not a guest account if ($accounts && Shopp::__('Guest') != ShoppCustomer()->type) { // User must be logged in when accounts are being used if (!ShoppCustomer()->loggedin()) { shopp_add_error(Shopp::__('You must login to download purchases.')); $forbidden = true; } // Logged in account must be the owner of the purchase if (ShoppCustomer()->id != $Purchase->customer) { shopp_add_error(Shopp::__('You are not authorized to download the requested file.')); $forbidden = true; } } // Download limit checking if (shopp_setting('download_limit') && $Purchased->downloads + 1 > shopp_setting('download_limit')) { shopp_add_error(Shopp::__('"%s" is no longer available for download because the download limit has been reached.', $name)); $forbidden = true; } // Download expiration checking if (shopp_setting('download_timelimit') && $Purchased->created + shopp_setting('download_timelimit') < current_time('timestamp')) { shopp_add_error(Shopp::__('"%s" is no longer available for download because it has expired.', 'Shopp', $name)); $forbidden = true; } // IP restriction checks if ('ip' == shopp_setting('download_restriction') && !empty($Purchase->ip) && $Purchase->ip != $_SERVER['REMOTE_ADDR']) { shopp_add_error(Shopp::__('"%s" cannot be downloaded because your computer could not be verified as the system the file was purchased from.', $name)); $forbidden = true; } do_action_ref_array('shopp_download_request', array($Purchased)); } if (apply_filters('shopp_download_forbidden', $forbidden, $Purchased)) { Shopp::redirect(add_query_arg('downloads', '', Shopp::url(false, 'account')), true, 303); } // Send the download $download = $Download->download(); if (is_a($download, 'ShoppError')) { // If the result is an error redirect to the account downloads page Shopp::redirect(add_query_arg('downloads', '', Shopp::url(false, 'account')), true, 303); } else { do_action_ref_array('shopp_download_success', array($Purchased, $Purchase, $Download)); // @deprecated use shopp_download_order_event instead shopp_add_order_event($Purchase->id, 'download', array('purchased' => $Purchased->id, 'download' => $Download->id, 'ip' => ShoppShopping()->ip, 'customer' => ShoppCustomer()->id)); } exit; }
/** * Resets a customer/user password with a valid activation key * * @since 1.0 * * @param string $activation The activation key * @return void **/ static function resetpassword($activation) { if ('none' == shopp_setting('account_system') || ShoppCustomer()->loggedin()) { return; } $user_data = false; $activation = preg_replace('/[^a-z0-9]/i', '', $activation); $errors = array(); if (empty($activation) || !is_string($activation)) { $errors[] = shopp_add_error(Shopp::__("Invalid password reset key. Try copy/pasting the url in password reset email into your web browser's address bar.")); } else { $RecoveryCustomer = new ShoppCustomer($activation, 'activation'); if (empty($RecoveryCustomer->id)) { $errors[] = shopp_add_error(Shopp::__("Invalid password reset key. Try copy/pasting the url in password reset email into your web browser's address bar.")); } } if (!empty($errors)) { return false; } // Generate a new random password $password = wp_generate_password(12, false); do_action_ref_array('password_reset', array($RecoveryCustomer, $password)); $RecoveryCustomer->password = wp_hash_password($password); if ('wordpress' == shopp_setting('account_system')) { $user_data = get_userdata($RecoveryCustomer->wpuser); wp_set_password($password, $user_data->ID); } $RecoveryCustomer->activation = ''; $RecoveryCustomer->save(); $subject = apply_filters('shopp_reset_password_subject', Shopp::__('[%s] New Password', get_option('blogname'))); $_ = array(); $_[] = 'From: ' . Shopp::email_from(shopp_setting('merchant_email'), shopp_setting('business_name')); $_[] = 'To: ' . $RecoveryCustomer->email; $_[] = 'Subject: ' . $subject; $_[] = 'Content-type: text/html'; $_[] = ''; $_[] = '<p>' . Shopp::__('Your new password for %s:', get_bloginfo('url')) . '</p>'; $_[] = ''; $_[] = '<ul>'; if (apply_filters('shopp_reset_password_wpuser', true) && !empty($user_data->user_login)) { $_[] = '<li>' . Shopp::__('Login: %s', $user_data->user_login) . '</li>'; } elseif (!empty($RecoveryCustomer->email)) { $_[] = '<li>' . Shopp::__('Login: %s', $RecoveryCustomer->email) . '</li>'; } $_[] = '<li>' . Shopp::__('Password: %s', $password) . '</li>'; $_[] = '</ul>'; $_[] = ''; $_[] = '<p>' . Shopp::__('Click here to login: %s', Shopp::url(false, 'account')) . '</p>'; $message = apply_filters('shopp_reset_password_message', $_); if (!Shopp::email(join("\n", $message))) { shopp_add_notice(Shopp::__('Your password was reset to: ' . $password)); } else { shopp_add_notice(Shopp::__('Your new password has been emailed to you for your records. Your password was reset to: ' . $password)); } unset($_GET['acct']); // Auto-login $RecoveryCustomer->login(); // Login the customer if (!empty($user_data)) { // Log the WordPress user in ShoppLogin::wpuser($user_data); } // Show notice after login in case of failures during login shopp_add_notice(Shopp::__('You are now logged into your account.')); if (apply_filters('shopp_reset_password_redirect', true)) { shopp_add_notice(Shopp::__('If you wish, please use the form below to change your password to one of your choosing.')); Shopp::redirect(add_query_arg('profile', '', Shopp::url(false, 'account'))); } }
public function keygen() { $message = ShoppCustomer()->email . serialize($this) . current_time('mysql'); $key = sha1($message); $limit = 25; $c = 0; while ((int) sDB::query("SELECT count(*) AS found FROM {$this->_table} WHERE dkey='{$key}'", 'auto', 'col', 'found') > 0) { $key = sha1($message . rand()); if ($c++ > $limit) { break; } } $this->dkey = $key; do_action_ref_array('shopp_download_keygen', array(&$this)); }