Пример #1
0
 /**
  * Detects if Shopp is unsupported in the current hosting environment
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return boolean True if requirements are missing, false if no errors were detected
  **/
 public static function unsupported()
 {
     if (defined('SHOPP_UNSUPPORTED')) {
         return SHOPP_UNSUPPORTED;
     }
     $activation = false;
     if (isset($_GET['action']) && isset($_GET['plugin'])) {
         $activation = 'activate' == $_GET['action'];
         if ($activation) {
             $plugin = $_GET['plugin'];
             if (function_exists('check_admin_referer')) {
                 check_admin_referer('activate-plugin_' . $plugin);
             }
         }
     }
     $errors = array();
     // Check PHP version
     if (version_compare(PHP_VERSION, '5.2.4', '<')) {
         array_push($errors, 'phpversion', 'php524');
     }
     // Check WordPress version
     if (version_compare(get_bloginfo('version'), '3.5', '<')) {
         array_push($errors, 'wpversion', 'wp35');
     }
     // Check for GD
     if (!function_exists('gd_info')) {
         $errors[] = 'gdsupport';
     } elseif (!array_keys(gd_info(), array('JPG Support', 'JPEG Support'))) {
         $errors[] = 'jpgsupport';
     }
     if (empty($errors)) {
         if (!defined('SHOPP_UNSUPPORTED')) {
             define('SHOPP_UNSUPPORTED', false);
         }
         return false;
     }
     $plugin_path = dirname(__FILE__);
     // Manually load text domain for translated activation errors
     $languages_path = str_replace('\\', '/', $plugin_path . '/lang');
     load_plugin_textdomain('Shopp', false, $languages_path);
     // Define translated messages
     $_ = array('header' => Shopp::_x('Shopp Activation Error', 'Shopp activation error'), 'intro' => Shopp::_x('Sorry! Shopp cannot be activated for this WordPress install.', 'Shopp activation error'), 'phpversion' => sprintf(Shopp::_x('Your server is running PHP %s!', 'Shopp activation error'), PHP_VERSION), 'php524' => Shopp::_x('Shopp requires PHP 5.2.4+.', 'Shopp activation error'), 'wpversion' => sprintf(Shopp::_x('This site is running WordPress %s!', 'Shopp activation error'), get_bloginfo('version')), 'wp35' => Shopp::_x('Shopp requires WordPress 3.5.', 'Shopp activation error'), 'gdsupport' => Shopp::_x('Your server does not have GD support! Shopp requires the GD image library with JPEG support for generating gallery and thumbnail images.', 'Shopp activation error'), 'jpgsupport' => Shopp::_x('Your server does not have JPEG support for the GD library! Shopp requires JPEG support in the GD image library to generate JPEG images.', 'Shopp activation error'), 'nextstep' => sprintf(Shopp::_x('Try contacting your web hosting provider or server administrator to upgrade your server. For more information about the requirements for running Shopp, see the %sShopp Documentation%s', 'Shopp activation error'), '<a href="' . ShoppSupport::DOCS . 'system-requirements">', '</a>'), 'continue' => Shopp::_x('Return to Plugins page', 'Shopp activation error'));
     if ($activation) {
         $string = '<h1>' . $_['header'] . '</h1><p>' . $_['intro'] . '</h1></p><ul>';
         foreach ((array) $errors as $error) {
             if (isset($_[$error])) {
                 $string .= "<li>{$_[$error]}</li>";
             }
         }
         $string .= '</ul><p>' . $_['nextstep'] . '</p><p><a class="button" href="' . admin_url('plugins.php') . '">&larr; ' . $_['continue'] . '</a></p>';
         wp_die($string);
     }
     if (!function_exists('deactivate_plugins')) {
         require ABSPATH . 'wp-admin/includes/plugin.php';
     }
     $plugin = basename($plugin_path) . __FILE__;
     deactivate_plugins($plugin, true);
     $phperror = '';
     if (is_array($errors) && !empty($errors)) {
         foreach ($errors as $error) {
             if (isset($_[$error])) {
                 $phperror .= $_[$error] . ' ';
             }
             trigger_error($phperror, E_USER_WARNING);
         }
     }
     if (!defined('SHOPP_UNSUPPORTED')) {
         define('SHOPP_UNSUPPORTED', true);
     }
     return true;
 }
Пример #2
0
 /**
  * Loads or constructs the Item object from product and product pricing parameters
  *
  * @author John Dillick, Jonathan Davis
  * @since 1.2
  *I
  * @param object $Product Product object
  * @param mixed $pricing A list of price IDs; The option key of a price object; or a Price object
  * @param int $category (optional)The breadcrumb category ID where the product was added from
  * @param array $data (optional) Custom data associated with the line item
  * @param array $addons (optional) A set of addon options
  * @return void
  **/
 public function load($Product, $pricing, $category = false, $data = array(), $addons = array())
 {
     $Product->load_data();
     // If option ids are passed, lookup by option key, otherwise by id
     $Price = false;
     if (is_array($pricing) && !empty($pricing)) {
         $optionkey = $Product->optionkey($pricing);
         if (!isset($Product->pricekey[$optionkey])) {
             $optionkey = $Product->optionkey($pricing, true);
         }
         // deprecated prime
         if (isset($Product->pricekey[$optionkey])) {
             $Price = $Product->pricekey[$optionkey];
         }
     } elseif (is_numeric($pricing)) {
         $Price = $Product->priceid[$pricing];
     } elseif (is_a($pricing, 'ShoppPrice')) {
         $Price = $pricing;
     }
     // Find single product priceline
     if (!$Price && !Shopp::str_true($Product->variants)) {
         foreach ($Product->prices as &$Price) {
             $stock = true;
             if (Shopp::str_true($Price->inventory) && 1 > $Price->stock) {
                 $stock = false;
             }
             if ('product' == $Price->context && 'N/A' != $Price->type && $stock) {
                 break;
             }
         }
     }
     // Find first available variant priceline
     if (!$Price && Shopp::str_true($Product->variants)) {
         foreach ($Product->prices as &$Price) {
             $stock = true;
             if (Shopp::str_true($Price->inventory) && 1 > $Price->stock) {
                 $stock = false;
             }
             if ('variation' == $Price->context && 'N/A' != $Price->type && $stock) {
                 break;
             }
         }
     }
     if (isset($Product->id)) {
         $this->product = $Product->id;
     }
     if (isset($Price->id)) {
         $this->priceline = $Price->id;
     }
     $this->name = $Product->name;
     $this->slug = $Product->slug;
     $this->category = $category;
     $this->categories = $this->namelist($Product->categories);
     $this->tags = $this->namelist($Product->tags);
     $this->image = current($Product->images);
     $this->description = $Product->summary;
     if (shopp_setting_enabled('taxes')) {
         // Must init taxable above addons roll-up #2825
         $this->taxable = array();
     }
     // Re-init during ShoppCart::change() loads #2922
     // Product has variants
     if (Shopp::str_true($Product->variants) && empty($this->variants)) {
         $this->variants($Product->prices);
     }
     // Product has Addons
     if (Shopp::str_true($Product->addons)) {
         if (!empty($this->addons)) {
             // Compute addon differences
             $addons = array_diff($addons, array_keys($this->addons));
         }
         $this->addons($this->addonsum, $addons, $Product->prices);
     }
     if (isset($Price->id)) {
         $this->option = $this->mapprice($Price);
     }
     $this->sku = $Price->sku;
     $this->type = $Price->type;
     $this->sale = Shopp::str_true($Product->sale);
     $this->freeshipping = isset($Price->freeshipping) ? $Price->freeshipping : false;
     $baseprice = roundprice($this->sale ? $Price->promoprice : $Price->price);
     $this->unitprice = $baseprice + $this->addonsum;
     if (shopp_setting_enabled('taxes')) {
         if (Shopp::str_true($Price->tax)) {
             $this->taxable[] = $baseprice;
         }
         $this->istaxed = array_sum($this->taxable) > 0;
         $this->includetax = shopp_setting_enabled('tax_inclusive');
         if (isset($Product->excludetax) && Shopp::str_true($Product->excludetax)) {
             $this->includetax = false;
         }
     }
     if ('Donation' == $this->type) {
         $this->donation = $Price->donation;
     }
     $this->inventory = Shopp::str_true($Price->inventory) && shopp_setting_enabled('inventory');
     $this->data = stripslashes_deep(esc_attrs($data));
     // Handle Recurrences
     if ($this->has_recurring()) {
         $this->subprice = $this->unitprice;
         $this->recurrences();
         if ($this->is_recurring() && $this->has_trial()) {
             $trial = $this->trial();
             $this->unitprice = $trial['price'];
         }
     } else {
         // Remove subscription labels in case they were set earlier
         unset($this->data[Shopp::_x('Subscription', 'Subscription terms label')]);
         unset($this->data[Shopp::_x('Trial Period', 'Item trial period label')]);
     }
     // Map out the selected menu name and option
     if (Shopp::str_true($Product->variants)) {
         $selected = explode(',', $this->option->options);
         $s = 0;
         $variants = isset($Product->options['v']) ? $Product->options['v'] : $Product->options;
         foreach ((array) $variants as $i => $menu) {
             foreach ((array) $menu['options'] as $option) {
                 if ($option['id'] == $selected[$s]) {
                     $this->variant[$menu['name']] = $option['name'];
                     break;
                 }
             }
             $s++;
         }
     }
     $this->packaging = Shopp::str_true(shopp_product_meta($Product->id, 'packaging'));
     if (!empty($Price->download)) {
         $this->download = $Price->download;
     }
     $this->shipped = 'Shipped' == $Price->type;
     if ($this->shipped) {
         $dimensions = array('weight' => 0, 'length' => 0, 'width' => 0, 'height' => 0);
         if (Shopp::str_true($Price->shipping)) {
             $this->shipfee = $Price->shipfee;
             if (isset($Price->dimensions)) {
                 $dimensions = array_merge($dimensions, $Price->dimensions);
             }
         } else {
             $this->freeshipping = true;
         }
         if (isset($Product->addons) && Shopp::str_true($Product->addons)) {
             $this->addons($dimensions, $addons, $Product->prices, 'dimensions');
             $this->addons($this->shipfee, $addons, $Product->prices, 'shipfee');
         }
         foreach ($dimensions as $dimension => $value) {
             $this->{$dimension} = $value;
         }
         if (isset($Product->processing) && Shopp::str_true($Product->processing)) {
             if (isset($Product->minprocess)) {
                 $this->processing['min'] = $Product->minprocess;
             }
             if (isset($Product->maxprocess)) {
                 $this->processing['max'] = $Product->maxprocess;
             }
         }
     }
 }