예제 #1
0
/**
 * Smarty plugin
 * -------------------------------------------------------------
 * Type:     modifier<br>
 * Name:     to_json<br>
 * Purpose:  converts php array to javascript object notation 
 * Example:  {$a|to_json}
 * -------------------------------------------------------------
 */
function smarty_modifier_to_json($data)
{
    if (function_exists('json_encode')) {
        return json_encode($data);
    }
    if (is_null($data)) {
        $content = 'null';
    } elseif ($data === false) {
        $content = 'false';
    } elseif ($data === true) {
        $content = 'true';
    } elseif (is_array($data)) {
        $result = array();
        $akeys = array_keys($data);
        $diff = array_diff($akeys, range(0, sizeof($akeys) - 1));
        $is_list = empty($diff);
        if ($is_list) {
            foreach ($data as $v) {
                $result[] = smarty_modifier_to_json($v);
            }
            $content = '[' . join(',', $result) . ']';
        } else {
            foreach ($data as $k => $v) {
                $result[] = smarty_modifier_to_json($k) . ':' . smarty_modifier_to_json($v);
            }
            $content = '{' . join(',', $result) . '}';
        }
    } else {
        $content = empty($data) ? "''" : (is_string($data) ? "'" . fn_js_escape($data) . "'" : $data);
    }
    return $content;
}
예제 #2
0
파일: Ajax.php 프로젝트: arpad9/bygmarket
    public function destruct($content = '')
    {
        static $called = false;
        if ($called == false && $this->_internal_request) {
            $called = true;
            $text = $this->_request_type != self::REQUEST_COMET ? ob_get_clean() : '';
            if (empty($text) && !empty($content)) {
                $text = $content;
            }
            if (!empty($this->result_ids)) {
                $result_ids = array();
                // get the matching ids
                foreach ($this->result_ids as $r_id) {
                    if (strpos($r_id, '*')) {
                        $clear_id = str_replace('*', '\\w+?', $r_id);
                        preg_match_all('/<[^>]*?id=(?:\'|")(' . $clear_id . '\\w*?)(?:\'|")[^>]*?>/isS', $text, $ids);
                        if (!empty($ids[1])) {
                            foreach ($ids[1] as $r_id2) {
                                $result_ids[] = $r_id2;
                            }
                        }
                    } else {
                        $result_ids[] = $r_id;
                    }
                }
                foreach ($result_ids as $r_id) {
                    if (strpos($text, ' id="' . $r_id . '">') !== false) {
                        $start = strpos($text, ' id="' . $r_id . '">') + strlen(' id="' . $r_id . '">');
                        $end = strpos($text, '<!--' . $r_id . '--></');
                        $this->assignHtml($r_id, substr($text, $start, $end - $start));
                        // Assume that all data should be put to div with this ID
                    } elseif ($this->_skip_result_ids_check == true) {
                        $this->assignHtml($r_id, $text);
                    }
                }
                if ($this->full_render && preg_match('/<title>(.*?)<\\/title>/s', $text, $m)) {
                    $this->assign('title', html_entity_decode($m[1], ENT_QUOTES));
                }
                // Fix for payment processor form, should be removed after payments refactoring
                if (Embedded::isEnabled() && empty($this->_result['html']) && $this->_skip_result_ids_check == false && !empty($text)) {
                    foreach ($this->result_ids as $r_id) {
                        $text .= '<script type="text/javascript">if (document.process) { document.process.target="_parent"; document.process.submit(); }</script>';
                        $this->assignHtml($r_id, $text);
                        break;
                    }
                }
                $text = '';
            }
            if (empty($this->_result['non_ajax_notifications'])) {
                $this->assign('notifications', fn_get_notifications());
            }
            if (Embedded::isEnabled()) {
                $this->assign('session_data', array('name' => Session::getName(), 'id' => Session::getId()));
            }
            if (!empty($this->anchor)) {
                $this->assign('anchor', $this->anchor);
            }
            // we call session saving directly
            session_write_close();
            // Prepare response
            $response = $this->_result;
            if (fn_string_not_empty($text)) {
                $response['text'] = trim($text);
            }
            $response = json_encode($response, JSON_UNESCAPED_UNICODE);
            if (!headers_sent()) {
                header(' ', true, 200);
                // force 200 header, because we still need to return content
                if (Embedded::isEnabled() || $this->_request_type == self::REQUEST_JSONP_POST) {
                    header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
                    // for IE cors
                }
            }
            if ($this->_request_type == self::REQUEST_XML) {
                // Return json object
                header('Content-type: ' . $this->_content_type . '; charset=' . CHARSET);
            } elseif ($this->_request_type == self::REQUEST_JSONP) {
                // Return jsonp object
                header('Content-type: ' . $this->_content_type . '; charset=' . CHARSET);
                $response = $this->callback . '(' . $response . ');';
            } elseif ($this->_request_type == self::REQUEST_JSONP_POST) {
                // Return jsonp object
                header("X-Frame-Options: ", true);
                $response = '<script type="text/javascript" src="' . Registry::get('config.current_location') . '/js/lib/jquery/jquery.min.js' . '"></script>
                             <script type="text/javascript" src="' . Registry::get('config.current_location') . '/js/lib/postmessage/jquery.ba-postmessage.js' . '"></script>
                             <script type="text/javascript">

                                var Tygh = {};
                                Tygh.$ = jQuery.noConflict(true);
                             </script>
                             <script type="text/javascript">Tygh.$.postMessage(
                                "' . fn_js_escape($response) . '",\'' . Embedded::getUrl() . '\');</script>';
            } else {
                // Return html textarea object
                $response = '<textarea>' . fn_html_escape($response) . '</textarea>';
            }
            fn_echo($response);
        }
    }
예제 #3
0
function fn_get_vkontakte_description($params)
{
    $description = '';
    if ($params['object'] == 'products') {
        $product = Registry::get('view')->getTemplateVars('product');
        $description = htmlspecialchars(strip_tags($product['full_description']));
    } elseif ($params['object'] == 'pages') {
        $page = Registry::get('view')->getTemplateVars('page');
        $description = htmlspecialchars(strip_tags($page['description']));
    }
    return fn_js_escape($description);
}
예제 #4
0
function fn_vkontakte_prepare_settings($vkontakte_settings, $params)
{
    if (empty($vkontakte_settings['vkontakte_display_on'][$params['object']]) || $vkontakte_settings['vkontakte_display_on'][$params['object']] != 'Y') {
        return '';
    }
    $vkontakte_fields = array('type' => $vkontakte_settings['vkontakte_button_style'], 'width' => $vkontakte_settings['vkontakte_width'], 'height' => $vkontakte_settings['vkontakte_height'], 'pageImage' => fn_get_sb_image_url($params), 'pageTitle' => fn_get_vkontakte_title($params), 'pageDescription' => fn_js_escape(fn_truncate_chars(fn_get_sb_description($params), 200)), 'pageUrl' => fn_sb_get_url(), 'verb' => $vkontakte_settings['vkontakte_buttons_name'] == 'like' ? 0 : 1);
    $default_values = array('pageTitle' => fn_sb_format_page_title());
    //By default VK caches all data. We need to recalculate hash in order for VK to change the data in their cache
    $page_id = md5(implode(",", $vkontakte_fields));
    $vk_settings = '{';
    foreach ($vkontakte_fields as $field_name => $value) {
        if (empty($value) && !empty($default_values[$field_name])) {
            $value = $default_values[$field_name];
        }
        if (!empty($value)) {
            $vk_settings .= $field_name . ": '" . $value . "', ";
        }
    }
    $vk_settings .= "}, '" . $page_id . "'";
    return $vk_settings;
}
예제 #5
0
function fn_get_aff_banner_html($type, $banner_data, $mode = '', $partner_id = '', $lang_code = CART_LANGUAGE)
{
    $banner_correct = true;
    $auth =& $_SESSION['auth'];
    if ((empty($banner_data['banner_id']) || empty($banner_data['type'])) && $mode != 'demo') {
        return false;
    }
    $banner_data['banner_url'] = fn_get_aff_banner_url($banner_data, $partner_id, $lang_code);
    $banner_data['flash_vars'] = "sl={$lang_code}" . (empty($partner_id) ? '' : "&aff_id={$partner_id}");
    if ($banner_data['type'] == 'P') {
        $condition = '';
        $join = '';
        if (!empty($partner_id)) {
            $plan_data = fn_get_affiliate_plan_data_by_partner_id($partner_id);
            if (!empty($plan_data['product_ids'])) {
                $condition1 = db_quote("(?:products.product_id IN (?n))", array_keys($plan_data['product_ids']));
            }
            if (!empty($plan_data['category_ids'])) {
                $condition2 = db_quote("(category_id IN (?n))", array_keys($plan_data['category_ids']));
                $join .= " LEFT JOIN ?:products_categories ON ?:products.product_id = ?:products_categories.product_id ";
            }
            $condition .= !empty($condition1) && !empty($condition2) ? " AND ({$condition1} OR {$condition2}) " : (!empty($condition1) ? " AND {$condition1} " : (!empty($condition2) ? " AND {$condition2} " : ''));
        }
        if (!empty($banner_data['product_ids'])) {
            $condition .= db_quote(" AND ?:products.product_id IN (?n)", explode('-', $banner_data['product_ids']));
        }
        $prod_cnt = db_get_field("SELECT COUNT(*) FROM ?:products {$join} WHERE status = 'A' {$condition}");
        $product_id = db_get_field("SELECT ?:products.product_id FROM ?:products {$join} WHERE status = 'A' {$condition} LIMIT " . rand(0, $prod_cnt - 1) . ', 1');
        if (!empty($product_id)) {
            $banner_data['product_id'] = $product_id;
            if ($mode != 'demo') {
                $banner_data['banner_url'] .= "&product_id={$banner_data['product_id']}";
            } else {
                $banner_data['banner_url'] = '';
            }
            $prod_data = fn_get_product_data($product_id, $auth, CART_LANGUAGE, "?:products.product_id, product, full_description as product_full_description, short_description as product_short_description", false, true, false);
            $banner_data = fn_array_merge($banner_data, $prod_data);
            if (!empty($banner_data['main_pair']['icon']['image_path'])) {
                $banner_data['main_pair']['icon']['image_path'] = 'http://' . Registry::get('config.http_host') . $banner_data['main_pair']['icon']['image_path'];
            }
        } else {
            $banner_correct = false;
            $banner_data['type'] = 'T';
            $banner_data['link_to'] = 'U';
            $banner_data['show_title'] = 'N';
            $banner_data['content'] = '<div align="center" style="font-family: tahoma, arial; font-size: 12px;">' . fn_get_lang_var('warning') . '</div><hr size="0" style="border-top: #3b67d2 1px solid;" /><span style="font-family: tahoma, arial; font-size: 10px; color: #3b67d2;">' . fn_get_lang_var('text_no_products_found') . '</span>';
        }
    }
    if (in_array($type, array('js_content', 'iframe'))) {
        $banner_data['border'] = empty($banner_data['border']) || $banner_data['border'] != 'Y' ? '' : 'style="border: #999999 1px solid;"';
    }
    if (@$banner_data['type'] == 'G') {
        $image_data = fn_get_aff_banner_image_data($banner_data['banner_id'], 'icon', $lang_code);
        if (!empty($image_data)) {
            $banner_data = fn_array_merge($banner_data, $image_data);
        }
    }
    if (!empty($banner_data['width']) || !empty($banner_data['height'])) {
        $banner_data['wh_style'] = 'style="' . (!empty($banner_data['width']) ? "width:{$banner_data['width']}px;" : '') . (!empty($banner_data['height']) ? "height:{$banner_data['height']}px;" : '') . '"';
    } else {
        $banner_data['wh_style'] = '';
    }
    Registry::get('view')->assign('partner_id', $partner_id);
    Registry::get('view')->assign('banner_type', $type);
    Registry::get('view')->assign('mode', $mode);
    Registry::get('view')->assign('banner_data', $banner_data);
    Registry::get('view')->assign('no_image_path', 'http://' . Registry::get('config.http_host') . Registry::get('config.no_image_path'));
    Registry::get('view')->assign('affiliate_opts_settings', Registry::get('addons.affiliate'));
    $html_content = trim(Registry::get('view')->display('addons/affiliate/views/banners_manager/components/banner_content.tpl', false));
    if ($type == 'js_content') {
        $html_content = fn_js_escape($html_content);
    }
    Registry::get('view')->assign('html_content', $html_content);
    $return_content = '';
    if ($type == 'js' && $mode == 'demo' || $type == 'js_content') {
        $return_content .= fn_get_contents(DIR_ADDONS . 'affiliate/js/banner_script.js');
    }
    $return_content .= trim(Registry::get('view')->display('addons/affiliate/views/banners_manager/components/banner.tpl', false));
    if (in_array($type, array('iframe_content', 'js_content')) && !empty($partner_id) && $banner_correct) {
        fn_add_partner_action('show', $banner_data['banner_id'], $partner_id, '', array('R' => !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''));
    }
    return empty($return_content) ? false : $return_content;
}