예제 #1
0
파일: Setup.php 프로젝트: crunnells/shopp
 public function screen()
 {
     if (!current_user_can('shopp_settings')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     // Welcome screen handling
     if (!empty($_POST['setup'])) {
         shopp_set_setting('display_welcome', 'off');
     }
     $countries = ShoppLookup::countries();
     $basecountry = ShoppBaseLocale()->country();
     $countrymenu = Shopp::menuoptions($countries, $basecountry, true);
     $basestates = ShoppLookup::country_zones(array($basecountry));
     $statesmenu = '';
     if (!empty($basestates)) {
         $statesmenu = Shopp::menuoptions($basestates[$basecountry], ShoppBaseLocale()->state(), true);
     }
     $targets = shopp_setting('target_markets');
     if (is_array($targets)) {
         $targets = array_map('stripslashes', $targets);
     }
     if (!$targets) {
         $targets = array();
     }
     $zones_ajaxurl = wp_nonce_url(admin_url('admin-ajax.php'), 'wp_ajax_shopp_country_zones');
     include $this->ui('setup.php');
 }
예제 #2
0
파일: Payments.php 프로젝트: msigley/shopp
 public function updates()
 {
     $form = $this->form();
     if (empty($form)) {
         return;
     }
     do_action('shopp_save_payment_settings');
     $Gateways = Shopp::object()->Gateways;
     $gateways = array_keys($Gateways->activated());
     $gateway = key($form);
     // Handle Multi-instance payment systems
     $indexed = false;
     if (preg_match('/\\[(\\d+)\\]/', $gateway, $matched)) {
         $indexed = '-' . $matched[1];
         $gateway = str_replace($matched[0], '', $gateway);
     }
     // Merge the existing gateway settings with the newly updated settings
     if (isset($Gateways->active[$gateway])) {
         $Gateway = $Gateways->active[$gateway];
         // Cannot use array_merge() because it adds numeric index values instead of overwriting them
         $this->form[$gateway] = (array) $this->form[$gateway] + (array) $Gateway->settings;
     }
     // Add newly activated gateways
     if (!in_array($gateway . $indexed, $gateways)) {
         $gateways[] = $gateway . $indexed;
         shopp_set_setting('active_gateways', join(',', $gateways));
     }
     // Save the gateway settings
     shopp_set_formsettings();
     $this->notice(Shopp::__('Shopp payments settings saved.'));
     Shopp::redirect(add_query_arg());
 }
예제 #3
0
 public function welcome()
 {
     $Shopp = Shopp::object();
     include $this->ui('welcome.php');
     // Displayed the welcome, turn display_welcome flag off
     shopp_set_setting('display_welcome', 'off');
     return true;
 }
예제 #4
0
파일: Purchase.php 프로젝트: borkweb/shopp
 public function __construct()
 {
     $this->purchase_cols = ShoppPurchase::exportcolumns();
     $this->purchased_cols = ShoppPurchased::exportcolumns();
     $this->defined = array_merge($this->purchase_cols, $this->purchased_cols);
     $this->sitename = get_bloginfo('name');
     $this->headings = shopp_setting('purchaselog_headers') == "on";
     $this->selected = shopp_setting('purchaselog_columns');
     $this->date_format = get_option('date_format');
     $this->time_format = get_option('time_format');
     shopp_set_setting('purchaselog_lastexport', current_time('timestamp'));
 }
예제 #5
0
 /**
  * Displays the General Settings screen and processes updates
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @return void
  **/
 public function setup()
 {
     if (!current_user_can('shopp_settings')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     // Welcome screen handling
     if (!empty($_POST['setup'])) {
         $_POST['settings']['display_welcome'] = 'off';
         shopp_set_formsettings();
     }
     $country = isset($_POST['settings']) && isset($_POST['settings']['base_operations']) ? $_POST['settings']['base_operations']['country'] : '';
     $countries = array();
     $countrydata = Lookup::countries();
     $country_zones = Lookup::country_zones();
     foreach ($countrydata as $iso => $c) {
         if ($country == $iso) {
             $base_region = $c['region'];
         }
         $countries[$iso] = $c['name'];
     }
     // Save settings
     if (!empty($_POST['save']) && isset($_POST['settings'])) {
         check_admin_referer('shopp-setup');
         if (isset($_POST['settings']['base_operations'])) {
             $baseop =& $_POST['settings']['base_operations'];
             $zone = isset($baseop['zone']) && isset($country_zones[$country]) && isset($country_zones[$country][$baseop['zone']]) ? $baseop['zone'] : false;
             if (isset($countrydata[$country])) {
                 $baseop = $countrydata[$country];
             }
             $baseop['country'] = $country;
             $baseop['zone'] = $zone;
             $baseop['currency']['format'] = scan_money_format($baseop['currency']['format']);
             if (is_array($baseop['currency']['format'])) {
                 $fields = array_keys($baseop['currency']['format']);
                 foreach ($fields as $field) {
                     if (isset($baseop['currency'][$field])) {
                         $baseop['currency']['format'][$field] = $baseop['currency'][$field];
                     }
                 }
             }
             shopp_set_setting('tax_inclusive', in_array($country, Lookup::country_inclusive_taxes()) ? 'on' : 'off');
         }
         if (!isset($_POST['settings']['target_markets'])) {
             asort($_POST['settings']['target_markets']);
         }
         shopp_set_formsettings();
         $updated = __('Shopp settings saved.', 'Shopp');
     }
     $operations = shopp_setting('base_operations');
     if (isset($country_zones[$operations['country']])) {
         $zones = $country_zones[$operations['country']];
     }
     $targets = shopp_setting('target_markets');
     if (is_array($targets)) {
         $targets = array_map('stripslashes', $targets);
     }
     if (!$targets) {
         $targets = array();
     }
     include $this->ui('setup.php');
 }
예제 #6
0
 /**
  * Setup the module for runtime
  *
  * Auto-loads settings for the module and setups defaults
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function __construct()
 {
     $this->module = get_class($this);
     $this->session = ShoppShopping()->session;
     $this->Order = ShoppOrder();
     if ('ShoppFreeOrder' != $this->module) {
         // There are no settings for ShoppFreeOrder
         $this->settings = shopp_setting($this->module);
         // @todo Remove legacy gateway settings migrations
         // Attempt to copy old settings if this is a new prefixed gateway class
         if (empty($this->settings) && false !== strpos($this->module, 'Shopp')) {
             $legacy = substr($this->module, 5);
             $this->settings = shopp_setting($legacy);
             if (!empty($this->settings)) {
                 shopp_set_setting($this->module, $this->settings);
             }
         }
     }
     if (!isset($this->settings['label']) && $this->cards) {
         $this->settings['label'] = __('Credit Card', 'Shopp');
     }
     $this->baseop = ShoppBaseLocale()->settings();
     $this->currency = ShoppBaseCurrency()->code();
     $this->precision = ShoppBaseCurrency()->precision();
     $this->_loadcards();
     $gateway = GatewayModules::hookname($this->module);
     add_action('shopp_init', array($this, 'myactions'), 30);
     add_action('shopp_' . $gateway . '_refunded', array($this, 'cancelorder'));
     if ($this->authonly) {
         add_filter('shopp_purchase_order_' . $gateway . '_processing', create_function('', 'return "auth";'));
     } elseif ($this->saleonly) {
         add_filter('shopp_purchase_order_' . $gateway . '_processing', create_function('', 'return "sale";'));
     }
 }
예제 #7
0
파일: Modules.php 프로젝트: borkweb/shopp
 protected function uninstalled($module)
 {
     if (($detected = shopp_setting(self::MODULES_SETTING)) === false) {
         return;
     }
     if (isset($detected[$module])) {
         unset($detected[$module]);
         shopp_set_setting(self::MODULES_SETTING, $detected);
     }
 }
예제 #8
0
 public function advanced()
 {
     if (!current_user_can('shopp_settings_system')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     if (!empty($_POST['save'])) {
         check_admin_referer('shopp-system-advanced');
         if (!isset($_POST['settings']['error_notifications'])) {
             $_POST['settings']['error_notifications'] = array();
         }
         shopp_set_formsettings();
         // Reinitialize Error System
         ShoppErrors()->reporting((int) shopp_setting('error_logging'));
         ShoppErrorLogging()->loglevel((int) shopp_setting('error_logging'));
         ShoppErrorNotification()->setup();
         if (isset($_POST['shopp_services_plugins']) && $this->helper_installed()) {
             add_option('shopp_services_plugins');
             // Add if it doesn't exist
             update_option('shopp_services_plugins', $_POST['shopp_services_plugins']);
         }
         $this->notice(Shopp::__('Advanced settings saved.'));
     } elseif (!empty($_POST['rebuild'])) {
         check_admin_referer('shopp-system-advanced');
         $assets = ShoppDatabaseObject::tablename(ProductImage::$table);
         $query = "DELETE FROM {$assets} WHERE context='image' AND type='image'";
         if (sDB::query($query)) {
             $this->notice(Shopp::__('All cached images have been cleared.'));
         }
     } elseif (!empty($_POST['resum'])) {
         check_admin_referer('shopp-system-advanced');
         $summaries = ShoppDatabaseObject::tablename(ProductSummary::$table);
         $query = "UPDATE {$summaries} SET modified='" . ProductSummary::RECALCULATE . "'";
         if (sDB::query($query)) {
             $this->notice(Shopp::__('Product summaries are set to recalculate.'));
         }
     } elseif (isset($_POST['shopp_services_helper'])) {
         check_admin_referer('shopp-system-advanced');
         $plugin = 'ShoppServices.php';
         $source = SHOPP_PATH . "/core/library/{$plugin}";
         $install = WPMU_PLUGIN_DIR . '/' . $plugin;
         if (false === ($creds = request_filesystem_credentials($this->url, '', false, false, null))) {
             return true;
         }
         // stop the normal page form from displaying
         if (!WP_Filesystem($creds)) {
             // credentials were no good, ask for them again
             request_filesystem_credentials($this->url, '', false, false, null);
             return true;
         }
         global $wp_filesystem;
         if ('install' == $_POST['shopp_services_helper']) {
             if (!$wp_filesystem->exists($install)) {
                 if ($wp_filesystem->exists(WPMU_PLUGIN_DIR) || $wp_filesystem->mkdir(WPMU_PLUGIN_DIR, FS_CHMOD_DIR)) {
                     // Install the mu-plugin helper
                     $wp_filesystem->copy($source, $install, true, FS_CHMOD_FILE);
                 } else {
                     $this->notice(Shopp::_mi('The services helper could not be installed because the `mu-plugins` directory could not be created. Check the file permissions of the `%s` directory on the web aserver.', WP_CONTENT_DIR), 'error');
                 }
             }
             if ($wp_filesystem->exists($install)) {
                 shopp_set_setting('shopp_services_helper', 'on');
                 $this->notice(Shopp::__('Services helper installed.'));
             } else {
                 $this->notice(Shopp::__('The services helper failed to install.'), 'error');
             }
         } elseif ('remove' == $_POST['shopp_services_helper']) {
             global $wp_filesystem;
             if ($wp_filesystem->exists($install)) {
                 $wp_filesystem->delete($install);
             }
             if (!$wp_filesystem->exists($install)) {
                 shopp_set_setting('shopp_services_helper', 'off');
                 $this->notice(Shopp::__('Services helper uninstalled.'));
             } else {
                 $this->notice(Shopp::__('Services helper could not be uninstalled.'), 'error');
             }
         }
     }
     $notifications = shopp_setting('error_notifications');
     if (empty($notifications)) {
         $notifications = array();
     }
     $notification_errors = array(SHOPP_TRXN_ERR => Shopp::__('Transaction Errors'), SHOPP_AUTH_ERR => Shopp::__('Login Errors'), SHOPP_ADDON_ERR => Shopp::__('Add-on Errors'), SHOPP_COMM_ERR => Shopp::__('Communication Errors'), SHOPP_STOCK_ERR => Shopp::__('Inventory Warnings'));
     $errorlog_levels = array(0 => Shopp::__('Disabled'), SHOPP_ERR => Shopp::__('General Shopp Errors'), SHOPP_TRXN_ERR => Shopp::__('Transaction Errors'), SHOPP_AUTH_ERR => Shopp::__('Login Errors'), SHOPP_ADDON_ERR => Shopp::__('Add-on Errors'), SHOPP_COMM_ERR => Shopp::__('Communication Errors'), SHOPP_STOCK_ERR => Shopp::__('Inventory Warnings'), SHOPP_ADMIN_ERR => Shopp::__('Admin Errors'), SHOPP_DB_ERR => Shopp::__('Database Errors'), SHOPP_PHP_ERR => Shopp::__('PHP Errors'), SHOPP_ALL_ERR => Shopp::__('All Errors'), SHOPP_DEBUG_ERR => Shopp::__('Debugging Messages'));
     $plugins = get_plugins();
     $service_plugins = get_option('shopp_services_plugins');
     include $this->ui('advanced.php');
 }
예제 #9
0
 public function __construct()
 {
     $this->customer_cols = ShoppCustomer::exportcolumns();
     $this->billing_cols = BillingAddress::exportcolumns();
     $this->shipping_cols = ShippingAddress::exportcolumns();
     $this->defined = array_merge($this->customer_cols, $this->billing_cols, $this->shipping_cols);
     $this->sitename = get_bloginfo('name');
     $this->headings = shopp_setting('customerexport_headers') == "on";
     $this->selected = shopp_setting('customerexport_columns');
     shopp_set_setting('customerexport_lastexport', current_time('timestamp'));
 }
예제 #10
0
 /**
  * Handles maintenance mode messages
  **/
 private function maintenance()
 {
     if (ShoppLoader::is_activating() || Shopp::upgradedb()) {
         return;
     }
     if (isset($_POST['settings']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'shopp-setup')) {
         if (isset($_POST['settings']['maintenance'])) {
             shopp_set_setting('maintenance', $_POST['settings']['maintenance']);
         }
     }
     if (Shopp::maintenance()) {
         if (isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'shopp_disable_maintenance')) {
             shopp_set_setting('maintenance', 'off');
         } else {
             $url = wp_nonce_url(add_query_arg('page', $this->Admin->pagename('setup'), admin_url('admin.php')), 'shopp_disable_maintenance');
             $this->notice(Shopp::__('Shopp is currently in maintenance mode. %sDisable Maintenance Mode%s', '<a href="' . $url . '" class="button">', '</a>'), 'error', 1);
         }
     }
 }
예제 #11
0
 public function save($country, $state = '')
 {
     $this->country = $country;
     $this->state = $state;
     shopp_set_setting('base_locale', array($country, $state));
     shopp_set_setting('tax_inclusive', in_array($country, ShoppLookup::country_inclusive_taxes()) ? 'on' : 'off');
     $this->lookup($country);
 }
예제 #12
0
 /**
  * Initializes a shipping module
  *
  * Grabs settings that most shipping modules will needs and establishes
  * the event listeners to trigger module functionality.
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function __construct()
 {
     $Order = ShoppOrder();
     $this->module = get_class($this);
     if ($this->singular) {
         // @todo Remove legacy gateway settings migrations
         // Attempt to copy old settings if this is a new prefixed gateway class
         $this->settings = shopp_setting($this->module);
         if (empty($this->settings) && false !== strpos($this->module, 'Shopp')) {
             $legacy = substr($this->module, 5);
             $this->settings = shopp_setting($legacy);
             if (!empty($this->settings)) {
                 shopp_set_setting($this->module, $this->settings);
                 shopp_rmv_setting($legacy);
                 // Clean up legacy setting
             }
         }
     } else {
         $active = shopp_setting('active_shipping');
         if (isset($active[$this->module]) && is_array($active[$this->module])) {
             $this->methods = array();
             $this->fallbacks = array();
             foreach ($active[$this->module] as $index => $set) {
                 $setting = shopp_setting("{$this->module}-{$index}");
                 if (isset($setting['fallback']) && 'on' == $setting['fallback']) {
                     $this->fallbacks["{$this->module}-{$index}"] = $setting;
                 } else {
                     $this->methods["{$this->module}-{$index}"] = $setting;
                 }
             }
         }
     }
     $this->base = shopp_setting('base_operations');
     $this->units = shopp_setting('weight_unit');
     // Setup default packaging for shipping module
     $this->settings['shipping_packaging'] = shopp_setting('shipping_packaging');
     // Shipping module can override the default behavior and the global setting by specifying the local packaging property
     if (isset($this->packaging) && $this->packaging != $this->settings['shipping_packaging']) {
         $this->settings['shipping_packaging'] = $this->packaging;
     }
     $this->packager = apply_filters('shopp_' . strtolower($this->module) . '_packager', new ShippingPackager(array('type' => $this->settings['shipping_packaging']), $this->module));
     $this->destinations = __('Service provider markets', 'Shopp');
     add_action('shopp_calculate_shipping_init', array(&$this, 'init'));
     add_action('shopp_calculate_item_shipping', array(&$this, 'calcitem'), 10, 2);
     add_action('shopp_calculate_shipping', array(&$this, 'calculate'), 10, 2);
     if (isset($this->fallbacks) && !empty($this->fallbacks)) {
         add_action('shopp_calculate_fallback_shipping_init', array(&$this, 'fallbacks'));
         add_action('shopp_calculate_fallback_shipping', array(&$this, 'calculate'));
         add_action('shopp_calculate_fallback_shipping', array(&$this, 'reset'), 20);
     }
 }
예제 #13
0
파일: Admin.php 프로젝트: forthrobot/inuvik
 /**
  * Adds a maintenance mode notice to every admin screen
  *
  * @since 1.3
  *
  * @return void
  **/
 public function maintenance()
 {
     if (ShoppLoader::is_activating() || Shopp::upgradedb()) {
         return;
     }
     $setting = isset($_POST['settings']['maintenance']) ? $_POST['settings']['maintenance'] : false;
     $nonce = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : false;
     if (false !== $setting && wp_verify_nonce($nonce, 'shopp-setup')) {
         shopp_set_setting('maintenance', $setting);
     }
     if (!Shopp::maintenance()) {
         return;
     }
     if (wp_verify_nonce($this->request('_wpnonce'), 'shopp_disable_maintenance')) {
         shopp_set_setting('maintenance', 'off');
     } else {
         $url = wp_nonce_url(add_query_arg('page', ShoppAdmin::pagename('settings'), admin_url('admin.php')), 'shopp_disable_maintenance');
         $this->Screen->notice(Shopp::__('Shopp is currently in maintenance mode. %sDisable Maintenance Mode%s', '<a href="' . $url . '" class="button">', '</a>'), 'error', 1);
     }
 }
예제 #14
0
파일: Admin.php 프로젝트: borkweb/shopp
 /**
  * Update the stored path to the activated theme
  *
  * Automatically updates the Shopp theme path setting when the
  * a new theme is activated.
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function themepath()
 {
     shopp_set_setting('theme_templates', addslashes(sanitize_path(STYLESHEETPATH . '/' . "shopp")));
 }
예제 #15
0
파일: Install.php 프로젝트: crunnells/shopp
 public function upgrade_130()
 {
     global $wpdb;
     $db_version = ShoppSettings::dbversion();
     if ($db_version < 1201) {
         // 1.3 schema changes
         $this->upschema();
         // All existing sessions must be cleared and restarted, 1.3 & 1.3.6 sessions are not compatible with any prior version of Shopp
         ShoppShopping()->reset();
         $sessions_table = ShoppDatabaseObject::tablename('shopping');
         sDB::query("DELETE FROM {$sessions_table}");
         // Remove all the temporary PHP native session data from the options table
         sDB::query("DELETE FROM from {$wpdb->options} WHERE option_name LIKE '__php_session_*'");
     }
     if ($db_version < 1200) {
         $meta_table = ShoppDatabaseObject::tablename('meta');
         sDB::query("UPDATE {$meta_table} SET value='on' WHERE name='theme_templates' AND (value != '' AND value != 'off')");
         sDB::query("DELETE FROM {$meta_table} WHERE type='image' AND value LIKE '%O:10:\"ShoppError\"%'");
         // clean up garbage from legacy bug
         sDB::query("DELETE FROM {$meta_table} WHERE CONCAT('', name *1) = name AND context = 'category' AND type = 'meta'");
         // clean up bad category meta
         // Update purchase gateway values to match new prefixed class names
         $gateways = array('PayPalStandard' => 'ShoppPayPalStandard', '_2Checkout' => 'Shopp2Checkout', 'OfflinePayment' => 'ShoppOfflinePayment', 'TestMode' => 'ShoppTestMode', 'FreeOrder' => 'ShoppFreeOrder');
         foreach ($gateways as $name => $classname) {
             sDB::query("UPDATE {$purchase_table} SET gateway='{$classname}' WHERE gateway='{$name}'");
         }
         $activegateways = explode(',', shopp_setting('active_gateways'));
         foreach ($activegateways as &$setting) {
             if (false === strpos($setting, 'Shopp')) {
                 $setting = str_replace(array_keys($gateways), $gateways, $setting);
             }
         }
         shopp_set_setting('active_gateways', join(',', $activegateways));
     }
     if ($db_version < 1200 && shopp_setting_enabled('tax_inclusive')) {
         $price_table = ShoppDatabaseObject::tablename('price');
         $taxrates = shopp_setting('taxrates');
         $baseop = shopp_setting('base_operations');
         $taxtaxes = array();
         // Capture taxonomy condition tax rates
         $basetaxes = array();
         // Capture base of operations rate(s)
         foreach ($taxrates as $rate) {
             if (!($baseop['country'] == $rate['country'] || ShoppTax::ALL == $rate['country'])) {
                 continue;
             }
             if (!empty($rate['zone']) && $baseop['zone'] != $rate['zone']) {
                 continue;
             }
             if (!empty($rate['rules']) && $rate['logic'] == 'any') {
                 // Capture taxonomy conditional rates
                 foreach ($rate['rules'] as $raterule) {
                     if ('product-category' == $raterule['p']) {
                         $taxname = ProductCategory::$taxon . '::' . $raterule['v'];
                     } elseif ('product-tags' == $raterule['p']) {
                         $taxname = ProductTag::$taxon . '::' . $raterule['v'];
                     }
                     $taxtaxes[$taxname] = Shopp::floatval($rate['rate']) / 100;
                 }
             } else {
                 $basetaxes[] = Shopp::floatval($rate['rate']) / 100;
             }
         }
         // Find products by in each taxonomy termno
         $done = array();
         // Capture each set into the "done" list
         foreach ($taxtaxes as $taxterm => $taxrate) {
             list($taxonomy, $name) = explode('::', $taxterm);
             $Collection = new ProductCollection();
             $Collection->load(array('ids' => true, 'taxquery' => array(array('taxonomy' => $taxonomy, 'field' => 'name', 'terms' => $name))));
             $query = "UPDATE {$price_table} SET price=price+(price*{$taxrate}) WHERE tax='on' AND product IN (" . join(',', $Collection->products) . ")";
             sDB::query($query);
             $done = array_merge($done, $Collection->products);
         }
         // Update the rest of the prices (skipping those we've already done) with the tax rate that matches the base of operations
         $taxrate = array_sum($basetaxes);
         // Merge all the base taxes into a single rate
         $done = empty($done) ? '' : " AND product NOT IN (" . join(',', $done) . ")";
         $query = "UPDATE {$price_table} SET price=price+(price*{$taxrate}) WHERE tax='on'{$done}";
         sDB::query($query);
     }
 }
예제 #16
0
 public function screen()
 {
     $shipcarriers = Lookup::shipcarriers();
     $serviceareas = array('*', ShoppBaseLocale()->code());
     foreach ($shipcarriers as $c => $record) {
         if (!in_array($record->areas, $serviceareas)) {
             continue;
         }
         $carriers[$c] = $record->name;
     }
     unset($shipcarriers);
     $shipping_carriers = shopp_setting('shipping_carriers');
     if (empty($shipping_carriers)) {
         $shipping_carriers = array_keys($carriers);
     }
     $imperial = 'imperial' == ShoppBaseLocale()->units();
     $weights = $imperial ? array('oz' => Shopp::__('ounces (oz)'), 'lb' => Shopp::__('pounds (lbs)')) : array('g' => Shopp::__('gram (g)'), 'kg' => Shopp::__('kilogram (kg)'));
     $weightsmenu = menuoptions($weights, shopp_setting('weight_unit'), true);
     $dimensions = $imperial ? array('in' => Shopp::__('inches (in)'), 'ft' => Shopp::__('feet (ft)')) : array('cm' => Shopp::__('centimeters (cm)'), 'm' => Shopp::__('meters (m)'));
     $dimsmenu = menuoptions($dimensions, shopp_setting('dimension_unit'), true);
     $rates = shopp_setting('shipping_rates');
     if (!empty($rates)) {
         ksort($rates);
     }
     $Shopp = Shopp::object();
     $Shipping = $Shopp->Shipping;
     $Shipping->settings();
     // Load all installed shipping modules for settings UIs
     $methods = $Shopp->Shipping->methods;
     $edit = false;
     if (isset($_REQUEST['id'])) {
         $edit = (int) $_REQUEST['id'];
     }
     $active = shopp_setting('active_shipping');
     if (!$active) {
         $active = array();
     }
     if (isset($_POST['module'])) {
         $setting = false;
         $module = isset($_POST['module']) ? $_POST['module'] : false;
         $id = isset($_POST['id']) ? $_POST['id'] : false;
         if ($id == $module) {
             if (isset($_POST['settings'])) {
                 shopp_set_formsettings();
             }
             /** Save shipping service settings **/
             $active[$module] = true;
             shopp_set_setting('active_shipping', $active);
             $updated = __('Shipping settings saved.', 'Shopp');
             // Cancel editing if saving
             if (isset($_POST['save'])) {
                 unset($_REQUEST['id']);
             }
             $Errors = ShoppErrors();
             do_action('shopp_verify_shipping_services');
             if ($Errors->exist()) {
                 // Get all addon related errors
                 $failures = $Errors->level(SHOPP_ADDON_ERR);
                 if (!empty($failures)) {
                     $updated = __('Shipping settings saved but there were errors: ', 'Shopp');
                     foreach ($failures as $error) {
                         $updated .= '<p>' . $error->message(true, true) . '</p>';
                     }
                 }
             }
         } else {
             /** Save shipping calculator settings **/
             $setting = $_POST['id'];
             if (empty($setting)) {
                 // Determine next available setting ID
                 $index = 0;
                 if (is_array($active[$module])) {
                     $index = count($active[$module]);
                 }
                 $setting = "{$module}-{$index}";
             }
             // Cancel editing if saving
             if (isset($_POST['save'])) {
                 unset($_REQUEST['id']);
             }
             $setting_module = $setting;
             $id = 0;
             if (false !== strpos($setting, '-')) {
                 list($setting_module, $id) = explode('-', $setting);
             }
             // Prevent fishy stuff from happening
             if ($module != $setting_module) {
                 $module = false;
             }
             // Save shipping calculator settings
             $Shipper = $Shipping->get($module);
             if ($Shipper && isset($_POST[$module])) {
                 $Shipper->setting($id);
                 $_POST[$module]['label'] = stripslashes($_POST[$module]['label']);
                 // Sterilize $values
                 foreach ($_POST[$module]['table'] as $i => &$row) {
                     if (isset($row['rate'])) {
                         $row['rate'] = Shopp::floatval($row['rate']);
                     }
                     if (!isset($row['tiers'])) {
                         continue;
                     }
                     foreach ($row['tiers'] as &$tier) {
                         if (isset($tier['rate'])) {
                             $tier['rate'] = Shopp::floatval($tier['rate']);
                         }
                     }
                 }
                 // Delivery estimates: ensure max equals or exceeds min
                 ShippingFramework::sensibleestimates($_POST[$module]['mindelivery'], $_POST[$module]['maxdelivery']);
                 shopp_set_setting($Shipper->setting, $_POST[$module]);
                 if (!array_key_exists($module, $active)) {
                     $active[$module] = array();
                 }
                 $active[$module][(int) $id] = true;
                 shopp_set_setting('active_shipping', $active);
                 $this->notice(Shopp::__('Shipping settings saved.'));
             }
         }
     }
     $postcodes = ShoppLookup::postcodes();
     foreach ($postcodes as &$postcode) {
         $postcode = !empty($postcode);
     }
     $lookup = array('regions' => array_merge(array('*' => Shopp::__('Anywhere')), ShoppLookup::regions()), 'regionmap' => ShoppLookup::regions('id'), 'countries' => ShoppLookup::countries(), 'areas' => ShoppLookup::country_areas(), 'zones' => ShoppLookup::country_zones(), 'postcodes' => $postcodes);
     $ShippingTemplates = new TemplateShippingUI();
     add_action('shopp_shipping_module_settings', array($Shipping, 'templates'));
     $Table = $this->table;
     $Table->prepare_items();
     include $this->ui('shipping.php');
 }
예제 #17
0
파일: Taxes.php 프로젝트: msigley/shopp
 public function upload()
 {
     if (!isset($_FILES['ratefile'])) {
         return false;
     }
     $upload = $_FILES['ratefile'];
     $filename = $upload['tmp_name'];
     if (empty($filename) && empty($upload['name']) && !isset($_POST['upload'])) {
         return false;
     }
     $error = false;
     if ($upload['error'] != 0) {
         return $this->notice(ShoppLookup::errors('uploads', $upload['error']));
     }
     if (!is_readable($filename)) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_readable'));
     }
     if (empty($upload['size'])) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_empty'));
     }
     if ($upload['size'] != filesize($filename)) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'filesize_mismatch'));
     }
     if (!is_uploaded_file($filename)) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_uploaded_file'));
     }
     $data = file_get_contents($upload['tmp_name']);
     $cr = array("\r\n", "\r");
     $formats = array(0 => false, 3 => 'xml', 4 => 'tab', 5 => 'csv');
     preg_match('/((<[^>]+>.+?<\\/[^>]+>)|(.+?\\t.+?[\\n|\\r])|(.+?,.+?[\\n|\\r]))/', $data, $_);
     $format = $formats[count($_)];
     if (!$format) {
         return $this->notice(Shopp::__('The uploaded file is not properly formatted as an XML, CSV or tab-delimmited file.'));
     }
     $_ = array();
     switch ($format) {
         case 'xml':
             /*
             Example XML import file:
             	<localtaxrates>
             		<taxrate name="Kent">1</taxrate>
             		<taxrate name="New Castle">0.25</taxrate>
             		<taxrate name="Sussex">1.4</taxrate>
             	</localtaxrates>
             
             Taxrate record format:
             	<taxrate name="(Name of locality)">(Percentage of the supplemental tax)</taxrate>
             
             Tax rate percentages should be represented as percentage numbers, not decimal percentages:
             	1.25	= 1.25%	(0.0125)
             	10		= 10%	(0.1)
             */
             $XML = new xmlQuery($data);
             $taxrates = $XML->tag('taxrate');
             while ($rate = $taxrates->each()) {
                 $name = $rate->attr(false, 'name');
                 $value = $rate->content();
                 $_[$name] = $value;
             }
             break;
         case 'csv':
             ini_set('auto_detect_line_endings', true);
             if (($csv = fopen($upload['tmp_name'], 'r')) === false) {
                 return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_readable'));
             }
             while (($data = fgetcsv($csv, 1000)) !== false) {
                 $_[$data[0]] = !empty($data[1]) ? $data[1] : 0;
             }
             fclose($csv);
             ini_set('auto_detect_line_endings', false);
             break;
         case 'tab':
         default:
             $data = str_replace($cr, "\n", $data);
             $lines = explode("\n", $data);
             foreach ($lines as $line) {
                 list($key, $value) = explode("\t", $line);
                 $_[$key] = $value;
             }
     }
     if (empty($_)) {
         return $this->notice(Shopp::__('No useable tax rates could be found. The uploaded file may not be properly formatted.'));
     }
     $id = $_POST['id'];
     $rates = shopp_setting('taxrates');
     $rates[$id]['locals'] = apply_filters('shopp_local_taxrates_upload', $_);
     shopp_set_setting('taxrates', $rates);
 }
예제 #18
0
파일: Setup.php 프로젝트: forthrobot/inuvik
 /**
  * Displays the General Settings screen and processes updates
  *
  * @author Jonathan Davis
  * @since 1.0
  *
  * @return void
  **/
 public function setup()
 {
     if (!current_user_can('shopp_settings')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     // Welcome screen handling
     if (!empty($_POST['setup'])) {
         shopp_set_setting('display_welcome', 'off');
     }
     $countries = ShoppLookup::countries();
     $states = array();
     // Save settings
     if (!empty($_POST['save']) && isset($_POST['settings'])) {
         check_admin_referer('shopp-setup');
         if (!isset($_POST['settings']['target_markets'])) {
             asort($_POST['settings']['target_markets']);
         }
         shopp_set_formsettings();
         if (isset($_POST['settings']['base_locale'])) {
             $baseop =& $_POST['settings']['base_locale'];
             if (isset($countries[strtoupper($baseop['country'])])) {
                 // Validate country
                 $country = strtoupper($baseop['country']);
                 $state = '';
                 if (!empty($baseop['state'])) {
                     // Valid state
                     $states = ShoppLookup::country_zones(array($country));
                     if (isset($states[$country][strtoupper($baseop['state'])])) {
                         $state = strtoupper($baseop['state']);
                     }
                 }
                 ShoppBaseLocale()->save($country, $state);
             }
             shopp_set_setting('tax_inclusive', in_array($country, Lookup::country_inclusive_taxes()) ? 'on' : 'off');
         }
         $updated = __('Shopp settings saved.', 'Shopp');
     }
     $basecountry = ShoppBaseLocale()->country();
     $countrymenu = Shopp::menuoptions($countries, $basecountry, true);
     $basestates = ShoppLookup::country_zones(array($basecountry));
     $statesmenu = Shopp::menuoptions($basestates[$basecountry], ShoppBaseLocale()->state(), true);
     $targets = shopp_setting('target_markets');
     if (is_array($targets)) {
         $targets = array_map('stripslashes', $targets);
     }
     if (!$targets) {
         $targets = array();
     }
     include $this->ui('setup.php');
 }