Пример #1
0
function utf8EncodeRecursive(&$data)
{
    if (is_array($data) || is_object($data)) {
        settype($data, 'array');
        foreach ($data as &$_val) {
            utf8EncodeRecursive($_val);
        }
    } else {
        $data = strip_tags(html_entity_decode($data));
        if (extension_loaded('mbstring')) {
            global $encodings;
            if (!$encodings) {
                $encodings = array();
                foreach (explode(',', 'UTF-8,ISO-8859-1,ISO-8859-2,ISO-8859-3,ISO-8859-4,ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,ISO-8859-9,ISO-8859-10,ISO-8859-13,ISO-8859-14,ISO-8859-15,ISO-8859-16,Windows-1252,Windows-1250,Windows-1251,Windows-1254') as $encoding) {
                    if (in_array($encoding, mb_list_encodings())) {
                        $encodings[] = $encoding;
                    }
                }
                mb_detect_order(array_merge($encodings, mb_list_encodings()));
            }
            if (($encoding = mb_detect_encoding($data, null, true)) != 'UTF-8') {
                mb_convert_variables('UTF-8', $encoding, $data);
            }
        } elseif (!preg_match('%^(?:
			[\\x09\\x0A\\x0D\\x20-\\x7E] # ASCII
			| [\\xC2-\\xDF][\\x80-\\xBF] # non-overlong 2-byte
			| \\xE0[\\xA0-\\xBF][\\x80-\\xBF] # excluding overlongs
			| [\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2} # straight 3-byte
			| \\xED[\\x80-\\x9F][\\x80-\\xBF] # excluding surrogates
			| \\xF0[\\x90-\\xBF][\\x80-\\xBF]{2} # planes 1-3
			| [\\xF1-\\xF3][\\x80-\\xBF]{3} # planes 4-15
			| \\xF4[\\x80-\\x8F][\\x80-\\xBF]{2} # plane 16
			)*$%xs', $data)) {
            if (extension_loaded('iconv')) {
                $data = iconv(iconv_get_encoding('internal_encoding'), 'UTF-8//IGNORE', $data);
            } else {
                $data = utf8_encode($data);
            }
        }
    }
}
Пример #2
0
    /**
     * Execute hook
     * 
     * @param mixed $params
     */
    public function hookOrderConfirmation($params)
    {
        global $smarty, $cookie, $link;
        if (!$this->active) {
            return;
        }
        // seting error handler
        eval('function itembaseErrorHandler($errno, $errstr, $errfile, $errline) {
' . ((bool) Configuration::get('PS_ITEMBASE_DEBUG') ? 'echo "
<!--ITEMBASE
".print_r(array($errno, $errstr, $errfile, $errline), true)."ITEMBASE-->
";' : '') . '
	return true;
}');
        set_error_handler('itembaseErrorHandler', E_ALL);
        try {
            include_once rtrim(_PS_MODULE_DIR_, '/') . '/itembase/plugindata.php';
            include_once rtrim(_PS_MODULE_DIR_, '/') . '/itembase/oauth.php';
            // geting access token
            $responseArray = $this->jsonDecode(authenticateClient(Configuration::get('PS_ITEMBASE_APIKEY'), Configuration::get('PS_ITEMBASE_SECRET')));
            if (!isset($responseArray['access_token'])) {
                itembaseErrorHandler(0, 'no access_token for ' . Tools::safeOutput(Configuration::get('PS_ITEMBASE_APIKEY')) . ' ' . substr(Tools::safeOutput(Configuration::get('PS_ITEMBASE_SECRET')), 0, 4) . '... ' . PS_ITEMBASE_SERVER_OAUTH . ' ' . print_r($responseArray, true), __FILE__, __LINE__ - 1);
            }
            // order data gathering
            $order = new Order($params['objOrder']->id, NULL);
            $currency = Currency::getCurrency((int) $order->id_currency);
            $carrier = new Carrier((int) $order->id_carrier);
            $language = Language::getLanguage((int) $cookie->id_lang);
            $customer = new Customer((int) $order->id_customer);
            $address = $customer->getAddresses($cookie->id_lang);
            if (is_object($address)) {
                $address = (array) $address;
            }
            if (isset($address['0'])) {
                $address = $address['0'];
            }
            // products data gathering
            $allProducts = array();
            foreach ($order->getProductsDetail() as $order_detail) {
                $product_id = $order_detail['product_id'];
                $product = new Product($product_id, true, null);
                $cover = Product::getCover($product_id);
                $product_img = $link->getImageLink($product->link_rewrite, $product_id . '-' . $cover['id_image']);
                if (strpos($product_img, 'http') !== 0) {
                    $product_img = Tools::getHttpHost(true) . $product_img;
                }
                $category = new Category($product->id_category_default);
                $allProducts[] = array('id' => $order_detail['product_id'], 'category' => $category->name, 'name' => $product->name, 'quantity' => $order_detail['product_quantity'], 'price' => $product->getPrice(true, NULL, 2), 'ean' => $product->ean13, 'isbn' => '', 'asin' => '', 'description' => $product->description_short, 'pic_thumb' => $product_img, 'pic_medium' => $product_img, 'pic_large' => $product_img, 'url' => $product->getLink(), 'presta_lang_id' => $language['id_lang']);
            }
            $dataForItembase = array('access_token' => $responseArray['access_token'], 'email' => $customer->email, 'firstname' => $customer->firstname, 'lastname' => $customer->lastname, 'street' => $address['address1'] . ($address['address2'] ? ' ' . $address['address2'] : ''), 'zip' => $address['postcode'], 'city' => $address['city'], 'country' => $address['country'], 'phone' => $address['phone'], 'lang' => $language['iso_code'], 'purchase_date' => $order->date_add, 'currency' => $currency['iso_code'], 'total' => $order->total_products_wt, 'order_number' => $order->id, 'customer_id' => $order->id_customer, 'invoice_number' => $order->invoice_number, 'shipping_cost' => $order->total_shipping, 'carrier' => $carrier->name, 'payment_option' => $order->payment, 'is_opt_in' => $customer->newsletter, 'shop_name' => class_exists('Context', false) ? Context::getContext()->shop->name : Configuration::get('PS_SHOP_NAME'), 'products' => $allProducts);
            // encoding data
            utf8EncodeRecursive($dataForItembase);
            $smarty->assign('ibdata', $dataForItembase);
            $smarty->assign('ibdatajson', $this->jsonEncode($dataForItembase));
            $smarty->assign('ibembedserver', PS_ITEMBASE_SERVER_EMBED);
            $smarty->assign('ibhostserver', PS_ITEMBASE_SERVER_HOST);
            $smarty->assign('ibpluginversion', PS_ITEMBASE_PLUGIN_VERSION);
            $smarty->assign('ibtop', Configuration::get('PS_ITEMBASE_TOP'));
        } catch (Exception $e) {
            itembaseErrorHandler($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
        }
        // restoring error handler
        restore_error_handler();
        return $this->display(__FILE__, 'views/templates/front/checkout_plugin.tpl');
    }