Ejemplo n.º 1
0
function onPageComplete($page = false)
{
    global $debug_total_time;
    global $debug_total_sql_query;
    global $debug_sql_query_stack;
    $debug_total_string = '';
    if (isset($debug_total_time) && $debug_total_time) {
        $time = microtime(true) - $debug_total_time;
        $debug_total_memory = function_exists('memory_get_peak_usage') ? memory_get_peak_usage() : 0;
        $debug_total_string .= sprintf('<div style="z-index:9999;position:fixed;right:50px;top:5px;height:23px;padding:0px;padding-bottom:2px;font-weight:bolder;color:green;background-color:#000033;opacity:0.8;border:1px dotted grey;"><span style="padding-left:10px;color:%s;">%0.3f s</span>' . "\t", $time > 0.5 ? $time > 1 ? 'red' : 'yellow' : 'green', $time);
        if ($debug_total_memory) {
            $debug_total_memory /= 1048576;
            $debug_total_string .= sprintf('<span style="padding-left:10px;color:%s;"> %0.3f MB</span>' . "\t", $debug_total_memory > 8 ? $debug_total_memory > 16 ? 'red' : 'yellow' : 'green', $debug_total_memory);
        }
        if (extension_loaded('eAccelerator')) {
            $eaccelerator_info = eaccelerator_info();
            if ($eaccelerator_info['cache']) {
                $debug_total_string .= sprintf('<span style="padding-left:10px;color:%s;"> eAccelerator %s [%0.2fMB(%d%%)/%d scripts]</span>' . "\t" . "\n", 'cyan', $eaccelerator_info['version'], $eaccelerator_info['memoryAllocated'] / 1048576, 100 * $eaccelerator_info['memoryAllocated'] / $eaccelerator_info['memorySize'], $eaccelerator_info['cachedScripts']);
            }
        } elseif (extension_loaded('xCache')) {
            if (isset($_GET['xcache'])) {
                $pcnt = xcache_count(XC_TYPE_PHP);
                $total = array('size' => 0, 'avail' => 0, 'cached' => 0, 'slots' => 0);
                $fields = array('size', 'avail', 'cached', 'slots');
                for ($i = 0; $i < $pcnt; $i++) {
                    $data = xcache_info(XC_TYPE_PHP, $i);
                    foreach ($fields as $field) {
                        $total[$field] += $data[$field];
                    }
                }
                $total['used'] = $total['size'] - $total['avail'];
                $version = phpversion('xcache');
                $debug_total_string .= sprintf('<span style="padding-left:10px;color:%s;"> xCache %s [%0.2fMB(%d%%)/%d scripts]</span>' . "\t" . "\n", 'cyan', $version, $total['used'] / 1048576, 100 * $total['used'] / $total['size'], $total['cached']);
            } else {
                $version = phpversion('xcache');
                $debug_total_string .= sprintf('<span style="padding-left:10px;color:%s;"> xCache %s</span>' . "\t" . "\n", 'cyan', $version);
            }
        }
        $debug_total_string .= sprintf('<span style="padding-left:10px;color:%s;"> %d SQL query</span>' . "\t" . "\n", $debug_total_sql_query > 50 ? $debug_total_sql_query > 100 ? 'red' : 'yellow' : 'green', $debug_total_sql_query);
        $debug_total_string .= sprintf('<span style="padding-left:10px;"> %d File(s)</span>' . "\t" . "\n", count(get_included_files()));
        $page_size = ob_get_length();
        $debug_total_string .= sprintf('<span style="padding-left:10px;"> %0.3f KB page size</span>' . "\t", ($page_size ? $page_size : strlen($page)) / 1024);
        //$debug_total_string .= sprintf('<span style="padding-left:10px;"> %s mode</span>',false?'DEV':'PRODUCTION');
        $debug_total_string .= '<img style="padding:0;padding-left:10px;margin:0;cursor:pointer;" src="' . URL_IMAGES_COMMON . '/close.gif" title="close" alt="close" onclick="this.parentNode.style.display=\'none\';"></div>';
        $firebug_enabled = false;
        if (class_exists('FirePHP')) {
            $firebug_enabled = strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'firephp') === false ? false : true;
            $firebug = FirePHP::getInstance(true);
            $firebug_enabled = $firebug->detectClientExtension();
            $firebug->setEnabled($firebug_enabled);
            $firebug->info(strip_tags($debug_total_string), basename(__FILE__));
            if ($debug_sql_query_stack && (isset($_COOKIE['debug']) && $_COOKIE['debug'] == 'sql')) {
                $total = 0.0;
                foreach ($debug_sql_query_stack as $stack_item) {
                    $total += $stack_item['time'];
                }
                $debug_sql_query_stack[] = array('#' => 'TOTAL', 'time' => sprintf('%0.2f', $total), 'query' => '');
                $firebug->table('SQL', $debug_sql_query_stack);
            }
        }
        if (!SystemSettings::is_hosted() && (isset($_COOKIE['debug']) && $_COOKIE['debug'] == 'log') && ($fp = @fopen(DIR_TEMP . '/access.' . date("Y.m.d") . '.log', "a"))) {
            @fwrite($fp, date("Y-m-d H:i:s") . "\t" . $_REQUEST['REQUEST_URI'] . $_REQUEST['QUERY_STRING'] . "\t" . preg_replace('/\\s+/', ' ', strip_tags($debug_total_string)) . "\n");
            if ($debug_sql_query_stack) {
                foreach ($debug_sql_query_stack as $query) {
                    @fwrite($fp, "\t" . implode("\t", $query) . "\n\n");
                }
                @fwrite($fp, "\n\n==========================================\n");
            }
            @fclose($fp);
        }
    }
    session_write_close();
    if ($page) {
        if (!$firebug_enabled) {
            print preg_replace('@</body>\\s*</html>\\s*$@', '', $page);
            print $debug_total_string . '
	</body>
</html>';
        } else {
            print $page;
            return $debug_total_string;
        }
    }
}
Ejemplo n.º 2
0
function cartUpdateAddCounter($productID)
{
    db_phquery("UPDATE ?#PRODUCTS_TABLE SET add2cart_counter=(add2cart_counter+1) WHERE productID=?", $productID);
    //TODO: add_metric_code
    /*
    include_once('class.metric.php');
    $metric = metric::getInstance();
    $metric->addAction($DB_KEY, $currentUser, 'SC', _ACTION_, _CLIENT_, _DATA_);
    _ACTION_ - DOWNLOAD/UPLOAD/ADDCONTACT/etc...
    _CLIENT_ - FLASH/JAVA/etc.. (default WA)
    _DATA_ - данные поясняющие действие.
    */
    if (SystemSettings::is_hosted() && file_exists(WBS_DIR . '/kernel/classes/class.metric.php')) {
        include_once WBS_DIR . '/kernel/classes/class.metric.php';
        $DB_KEY = strtoupper(SystemSettings::get('DB_KEY'));
        $U_ID = sc_getSessionData('U_ID');
        $metric = metric::getInstance();
        $metric->addAction($DB_KEY, $U_ID, 'SC', 'ADD2CART', isset($_GET['widgets']) ? 'WIDGET' : 'STOREFRONT', '');
    }
}
Ejemplo n.º 3
0
 function main()
 {
     $Register =& Register::getInstance();
     $smarty =& $Register->get(VAR_SMARTY);
     /*@var $smarty Smarty*/
     // shopping cart
     //iframe cookie security workaround
     if (isset($_GET['check_cookie'])) {
         if ($_GET['check_cookie'] != session_id()) {
             $productID = (int) $_GET['productID'];
             $product_data = GetProduct($productID);
             $product_slug = $product_data && isset($product_data['slug']) ? $product_data['slug'] : '';
             $url = "?ukey=product_widget&productID={$productID}&product_slug={$product_slug}&check_cookie&";
             $widgets = false;
             $Register->set('widgets', $widgets);
             $_SERVER['REQUEST_URI'] = preg_replace('/(^|&)widgets=1/', '', $_SERVER['REQUEST_URI']);
             RedirectSQ($url);
         } else {
             renderURL('check_cookie&productID', '', true);
         }
     }
     if (isset($_GET["make_more_exact_cart_content"])) {
         $smarty->assign("make_more_exact_cart_content", 1);
     }
     if (isset($_GET["remove"]) && $_GET["remove"] > 0) {
         //remove from cart product with productID == $remove
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $cartEntry->setItemQuantity($_GET['remove'], 0);
         $cartEntry->saveCurrentCart();
         if ($cartEntry->isEmpty()) {
             //remove coupon from empty cart
             ClassManager::includeClass('discount_coupon');
             discount_coupon::remove();
         }
         RedirectSQ('remove=');
     }
     $cart_view = $this->_detect_cart_view();
     if (isset($_POST["update"]) || isset($_POST["recalculate"])) {
         //update shopping cart content
         if ($_POST['discount_coupon_code'] != '') {
             $this->_check_and_apply_coupon($_POST['discount_coupon_code']);
         }
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $upd_data = scanArrayKeysForID($_POST, 'count');
         foreach ($upd_data as $_itemID => $_data) {
             $cartEntry->setItemQuantity($_itemID, intval($_data['count']));
         }
         $cartEntry->saveCurrentCart();
         if ($cartEntry->isEmpty()) {
             //remove coupon from empty cart
             ClassManager::includeClass('discount_coupon');
             discount_coupon::remove();
         }
         if (cartCheckMinOrderAmount() && cartCheckMinTotalOrderAmount()) {
             switch ($cart_view) {
                 case CARTVIEW_FRAME:
                     if (isset($_POST['checkout']) && $Register->get('store_mode') == 'facebook') {
                         $store_mode = false;
                         $Register->set('store_mode', $store_mode);
                         $jsgoto = '?ukey=checkout&view=noframe';
                         RedirectSQ($jsgoto ? 'jsgoto=' . base64_encode(set_query($jsgoto)) : '');
                     }
                     RedirectSQ(isset($_POST['checkout']) ? '?ukey=checkout' : (isset($_POST['ppe_checkout_x']) ? 'ppexpresscheckout2=1' : (isset($_POST['google_checkout_x']) ? 'googlecheckout2=1' : '')));
                     break;
                 case CARTVIEW_WIDGET:
                 case CARTVIEW_FADE:
                     $jsgoto = isset($_POST['checkout']) ? '?ukey=checkout&view=noframe' : (isset($_POST['ppe_checkout_x']) ? 'ppexpresscheckout2=1&view=frame' : (isset($_POST['google_checkout_x']) ? 'googlecheckout2=1&view=frame' : ''));
                     RedirectSQ($jsgoto ? 'jsgoto=' . base64_encode(set_query($jsgoto)) : '');
                     break;
             }
         } elseif (isset($_POST['checkout']) || isset($_POST['google_checkout_x']) || isset($_POST['ppe_checkout_x'])) {
             $smarty->assign('cart_error_show', '1');
         }
     }
     if (isset($_GET["clear_cart"])) {
         //completely clear shopping cart
         $cartEntry = new ShoppingCart();
         $cartEntry->loadCurrentCart();
         $cartEntry->cleanCurrentCart('erase');
         //remove coupon from empty cart
         ClassManager::includeClass('discount_coupon');
         discount_coupon::remove();
         RedirectSQ('clear_cart=');
     }
     if (isset($_POST['checkout'])) {
         if (SystemSettings::is_hosted() && file_exists(WBS_DIR . '/kernel/classes/class.metric.php')) {
             include_once WBS_DIR . '/kernel/classes/class.metric.php';
             $DB_KEY = SystemSettings::get('DB_KEY');
             $U_ID = sc_getSessionData('U_ID');
             $metric = metric::getInstance();
             $metric->addAction($DB_KEY, $U_ID, 'SC', 'CHECKOUT', isset($_GET['widgets']) ? 'WIDGET' : 'STOREFRONT', '');
         }
     }
     $resCart = cartGetCartContent();
     $resDiscount = dscGetCartDiscounts($resCart["total_price"], isset($_SESSION["log"]) ? $_SESSION["log"] : "");
     $currencyEntry = Currency::getSelectedCurrencyInstance();
     $cart_discount_show = $resDiscount['other_discounts']['cu'] > 0 ? $currencyEntry->getView($resDiscount['other_discounts']['cu']) : '';
     $coupon_discount_show = $resDiscount['coupon_discount']['cu'] > 0 ? $currencyEntry->getView($resDiscount['coupon_discount']['cu']) : '';
     $smarty->assign("cart_content", xHtmlSpecialChars($resCart["cart_content"], null, 'name'));
     $smarty->assign("cart_amount", $resCart["total_price"] - $resDiscount["discount_standart_unit"]);
     $smarty->assign('cart_min', show_price(CONF_MINIMAL_ORDER_AMOUNT));
     $smarty->assign("cart_total", $currencyEntry->getView($resDiscount['total']['cu']));
     $smarty->assign('cart_discount', $cart_discount_show);
     $smarty->assign('discount_percent', round($resDiscount['discount_percent'], 1));
     $smarty->assign('coupon_discount', $coupon_discount_show);
     $smarty->assign("current_coupon", discount_coupon::getCurrentCoupon());
     if (isset($_SESSION['log'])) {
         $smarty->assign('shippingAddressID', regGetDefaultAddressIDByLogin($_SESSION['log']));
     }
     if (isset($_GET['min_order'])) {
         $smarty->assign('minOrder', 'error');
     }
     if (isset($_GET['jsgoto'])) {
         $smarty->assign('jsgoto', base64_decode($_GET['jsgoto']));
     }
     $smarty->assign('main_content_template', 'shopping_cart.html');
     $smarty->assign('main_body_style', 'style="' . (CONF_SHOPPING_CART_VIEW == 2 || $cart_view == CARTVIEW_FRAME ? '' : 'background:#FFFFFF;') . 'min-width:auto;width:auto;_width:auto;"');
 }