當前位置: 首頁>>代碼示例>>PHP>>正文


PHP waRequest::cookie方法代碼示例

本文整理匯總了PHP中waRequest::cookie方法的典型用法代碼示例。如果您正苦於以下問題:PHP waRequest::cookie方法的具體用法?PHP waRequest::cookie怎麽用?PHP waRequest::cookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在waRequest的用法示例。


在下文中一共展示了waRequest::cookie方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: init

 public function init()
 {
     parent::init();
     $this->storage = waSystem::getInstance()->getStorage();
     if (!isset(self::$options['session_timeout'])) {
         self::$options['session_timeout'] = 1800;
     }
     if (ini_get('session.gc_maxlifetime') < self::$options['session_timeout']) {
         ini_set('session.gc_maxlifetime', self::$options['session_timeout']);
     }
     $auth = waSystem::getInstance()->getAuth();
     $info = $auth->isAuth();
     if ($info && isset($info['id']) && $info['id']) {
         $this->auth = true;
         $this->id = $info['id'];
         // update last_datetime for contact
         if (!waRequest::request('background_process')) {
             $this->updateLastTime();
         }
         // check CSRF cookie
         if (!waRequest::cookie('_csrf')) {
             waSystem::getInstance()->getResponse()->setCookie('_csrf', uniqid('', true));
         }
     }
 }
開發者ID:navi8602,項目名稱:wa-shop-ppg,代碼行數:25,代碼來源:waAuthUser.class.php

示例2: __construct

 public function __construct()
 {
     $this->view = waSystem::getInstance()->getView();
     if (wa()->getEnv() == 'frontend') {
         // save utm to cookie
         $utm = array();
         foreach (waRequest::get() as $k => $v) {
             if (substr($k, 0, 4) == 'utm_') {
                 $utm[substr($k, 4)] = $v;
             }
         }
         if ($utm) {
             // save utm to cookie
             wa()->getResponse()->setCookie('utm', json_encode($utm), time() + 30 * 86400, null, '', false, true);
         }
         // save referer
         if ($ref = waRequest::server('HTTP_REFERER')) {
             $ref_host = @parse_url($ref, PHP_URL_HOST);
             if ($ref_host != waRequest::server('HTTP_HOST')) {
                 wa()->getResponse()->setCookie('referer', waRequest::server('HTTP_REFERER'), time() + 30 * 86400, null, '', false, true);
             }
         }
         // save landing page
         if (!waRequest::cookie('landing')) {
             wa()->getResponse()->setCookie('landing', waRequest::server('REQUEST_URI'), 0, null, '', false, true);
         }
     }
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:28,代碼來源:waLayout.class.php

示例3: cartSync

 private function cartSync($contact = null)
 {
     if (!$this->getSettings('enabled')) {
         return null;
     }
     if (!$contact) {
         $id = wa()->getUser()->getId();
     } else {
         $id = $contact->getId;
     }
     $cart = waRequest::cookie('shop_cart');
     $model = new shopCartItemsModel();
     $carts = $model->query('SELECT code FROM shop_cart_items WHERE contact_id=' . $id)->fetchAssoc();
     if (count($carts) == 0) {
         return null;
     }
     $values = array('contact_id' => $id);
     if (count($carts) == 1) {
         if ($cart != $carts['code']) {
             $data = array('code' => $cart);
             $model->updateByField($data, $values);
             $data = array('code' => $carts['code']);
             $model->updateByField($values, $data);
             $model->updateByField($data, $values);
             wa()->getResponse()->setCookie('shop_cart', $carts['code'], time() + 30 * 86400, null, '', false, true);
             return true;
         }
     }
 }
開發者ID:xylsss,項目名稱:waplugins,代碼行數:29,代碼來源:shopPersistentcartPlugin.class.php

示例4: execute

 public function execute()
 {
     if (wa()->getAuth()->isAuth()) {
         $this->afterAuth();
     }
     // check XMLHttpRequest (ajax)
     $this->checkXMLHttpRequest();
     if (wa()->getEnv() == 'frontend') {
         $this->checkAuthConfig();
     }
     $auth = wa()->getAuth();
     // check remember enabled
     if (waRequest::method() == 'get') {
         $this->view->assign('remember', waRequest::cookie('remember', 1));
     }
     $this->saveReferer();
     $error = '';
     // try auth
     try {
         if ($auth->auth()) {
             $this->afterAuth();
         }
     } catch (waException $e) {
         $error = $e->getMessage();
     }
     $this->view->assign('error', $error);
     // assign auth options
     $this->view->assign('options', $auth->getOptions());
     wa()->getResponse()->setTitle(_ws('Log in'));
 }
開發者ID:navi8602,項目名稱:wa-shop-ppg,代碼行數:30,代碼來源:waLoginAction.class.php

示例5: frontend_head

    public function frontend_head()
    {
        if (!$this->getSettings('enabled')) {
            return false;
        }
        if (waRequest::cookie('agecheck') == 1) {
            return false;
        } else {
            $enter = !empty($this->getSettings('enter')) ? $this->getSettings('enter') : _wp('Enter');
            $leave = !empty($this->getSettings('leave')) ? $this->getSettings('leave') : _wp('Leave');
            $header = !empty($this->getSettings('header')) ? $this->getSettings('header') : _wp('Adults only');
            $style = !empty($this->getSettings('css')) ? $this->getSettings('css') : '';
            $logo = !empty($this->getSettings('logo_url')) ? $this->getSettings('logo_url') : $this->getPluginStaticUrl(true) . 'img/' . $this->getSettings('logo') . '.png';
            $html = '<div id="agecheck" class="agecheck-fade">';
            $html .= '<script type="text/javascript">
			$(document).on("click","#s-agecheck-enter",function(){var e=new Date;e.setTime(e.getTime()+31536e7),document.cookie="agecheck=1;path=/;expires="+e.toUTCString(),$("#agecheck").hide()}),$(document).on("click","#s-agecheck-leave",function(){""==document.referrer?window.close():window.location.href=document.referrer});
</script>';
            $html .= '<style>.agecheck-fade{height:100%;width:100%;background-color:rgba(0,0,0,.9);position:fixed;overflow:hidden;left:0;top:0;display:block;z-index:10000}.agecheck-cont{padding:20px;margin:10% auto 0;width:350px;background-color:#FFF!important;-moz-box-shadow:0 0 100px 1px #444;-webkit-box-shadow:0 0 100px 1px #444;font-size:20px}.agecheck-button{font-family:inherit;font-size:100%;padding:.5em 1em;color:#444;border:1px solid #999;background-color:#E6E6E6;text-decoration:none;border-radius:2px}</style>';
            if (!empty($style)) {
                $html .= '<style>' . $style . '</style>';
            }
            $html .= '
		<div class="agecheck-cont" align="center">
			<img align="middle" class="agecheck-logo" style="clear:both" src="' . $logo . '"></img><br><br>
			<h3>' . $header . '</h3>
			<button class="agecheck-button" id="s-agecheck-enter">' . $enter . '</button>&nbsp;&nbsp;<button class="agecheck-button" id="s-agecheck-leave">' . $leave . '</button>
		</div></div>';
            return $html;
        }
    }
開發者ID:xylsss,項目名稱:waplugins,代碼行數:30,代碼來源:shopAgecheckPlugin.class.php

示例6: execute

 public function execute()
 {
     $id = (int) waRequest::get('id');
     $html = '';
     $app_settings_model = new waAppSettingsModel();
     $settings = $app_settings_model->get(array('shop', 'fprview'));
     $product = new shopProduct($id);
     $route_params = array('product_url' => $product['url']);
     if (isset($product['category_url'])) {
         $route_params['category_url'] = $product['category_url'];
     }
     $product['frontend_url'] = wa()->getRouteUrl('shop/frontend/product', $route_params);
     $feature_codes = array_keys($product->features);
     $feature_model = new shopFeatureModel();
     $features = $feature_model->getByCode($feature_codes);
     $theme = waRequest::param('theme', 'default');
     $theme_path = wa()->getDataPath('themes', true) . '/' . $theme;
     if (!file_exists($theme_path) || !file_exists($theme_path . '/theme.xml')) {
         $theme_path = wa()->getAppPath() . '/themes/' . $theme;
     }
     switch ($settings['template_type']) {
         case 'plugin':
             $view = wa()->getView();
             $view->assign('features', $features);
             $view->assign('product', $product);
             $view->assign('fprview_settings', $settings);
             $html = $view->fetch(realpath(dirname(__FILE__) . "/../../") . '/templates/Frontend.html');
             break;
         case 'theme':
             if ($settings['template_theme_file'] && file_exists($theme_path . '/' . $settings['template_theme_file'])) {
                 $view = wa()->getView(array('template_dir' => $theme_path));
                 list($services, $skus_services) = $this->getServiceVars($product);
                 $compare = waRequest::cookie('shop_compare', array(), waRequest::TYPE_ARRAY_INT);
                 $stock_model = new shopStockModel();
                 $view->assign(array('sku_services' => $skus_services, 'services' => $services, 'compare' => in_array($product['id'], $compare) ? $compare : array(), 'currency_info' => $this->getCurrencyInfo(), 'stocks' => $stock_model->getAll('id'), 'reviews' => $this->getTopReviews($product['id']), 'rates' => $this->reviews_model->getProductRates($product['id']), 'reviews_total_count' => $this->getReviewsTotalCount($product['id']), 'features' => $features, 'product' => $product));
                 $view->assign('frontend_product', wa()->event('frontend_product', $product, array('menu', 'cart', 'block_aux', 'block')));
                 $template = $this->setThemeTemplate($settings['template_theme_file']);
                 $html = $view->fetch($this->getTemplate());
             }
             break;
         default:
             $html = '';
             break;
     }
     echo $html;
     exit;
 }
開發者ID:max-severin,項目名稱:fprview,代碼行數:47,代碼來源:shopFprviewPluginFrontendFprview.controller.php

示例7: setCollection

 protected function setCollection(shopProductsCollection $collection)
 {
     $collection->filters(waRequest::get());
     $limit = (int) waRequest::cookie('products_per_page');
     if (!$limit || $limit < 0 || $limit > 500) {
         $limit = $this->getConfig()->getOption('products_per_page');
     }
     $page = waRequest::get('page', 1, 'int');
     if ($page < 1) {
         $page = 1;
     }
     $offset = ($page - 1) * $limit;
     $products = $collection->getProducts('*', $offset, $limit);
     $count = $collection->count();
     $pages_count = ceil((double) $count / $limit);
     $this->view->assign('pages_count', $pages_count);
     $this->view->assign('products', $products);
     $this->view->assign('products_count', $count);
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:19,代碼來源:shopFrontend.action.php

示例8: orderActionCreate

 public function orderActionCreate($params)
 {
     if ($this->getSettings('status') && waRequest::cookie('uuid')) {
         $customer_model = new shopCustomerModel();
         $is_spamer = $customer_model->getByField(array('uuid' => waRequest::cookie('uuid'), 'is_spamer' => 1));
         $update = array();
         if ($is_spamer && $this->getSettings('action_id')) {
             $update['is_spamer'] = 1;
             $action_id = $this->getSettings('action_id');
             $workflow = new shopWorkflow();
             $action = $workflow->getActionById($action_id);
             $action->run($params['order_id']);
         }
         $customer = $customer_model->getById($params['contact_id']);
         if (!$customer['uuid']) {
             $update['uuid'] = waRequest::cookie('uuid');
             $customer_model->updateById($params['contact_id'], $update);
         }
     }
 }
開發者ID:klxqz,項目名稱:orderantispam,代碼行數:20,代碼來源:shopOrderantispam.plugin.php

示例9: defaultAction

 /** Default action when no other action is specified. */
 public function defaultAction()
 {
     $lm = new checklistsListModel();
     $lists = $lm->getAllowed();
     if (!$lists) {
         if ($this->getRights('add_list')) {
             $this->execute('editor');
             return;
         }
         // No available lists and cannot create new one: show default template
         return;
     }
     // is there a cookie with last list user opened?
     $id = waRequest::cookie('last_list_id', 0, 'int');
     if ($id && isset($lists[$id])) {
         $this->execute('list', $lists[$id]);
         return;
     }
     // simply show the first list
     $lists = array_values($lists);
     $this->execute('list', $lists[0]);
 }
開發者ID:cjmaximal,項目名稱:webasyst-framework,代碼行數:23,代碼來源:checklistsBackend.actions.php

示例10: updateAuth

 public function updateAuth($data)
 {
     wa()->getStorage()->set('auth_user', $this->getAuthData($data));
     if (waRequest::cookie('auth_token')) {
         $cookie_domain = ifset($this->options['cookie_domain'], '');
         wa()->getResponse()->setCookie('auth_token', $this->getToken($data), time() + 2592000, null, $cookie_domain, false, true);
     }
 }
開發者ID:cjmaximal,項目名稱:webasyst-framework,代碼行數:8,代碼來源:waAuth.class.php

示例11: execute

 public function execute()
 {
     $ids = waRequest::param('id', array(), waRequest::TYPE_ARRAY_INT);
     if (!$ids) {
         $ids = waRequest::cookie('shop_compare', array(), waRequest::TYPE_ARRAY_INT);
     }
     $collection = new shopProductsCollection('id/' . implode(',', $ids));
     $products = $collection->getProducts();
     $features = array();
     $i = 0;
     $compare_link = wa()->getRouteUrl('/frontend/compare', array('id' => '%ID%'));
     foreach ($products as &$p) {
         $p = new shopProduct($p);
         $temp_ids = $ids;
         unset($temp_ids[array_search($p['id'], $temp_ids)]);
         $p['delete_url'] = str_replace('%ID%', implode(',', $temp_ids), $compare_link);
         if (!$temp_ids) {
             $p['delete_url'] = substr($p['delete_url'], 0, -1);
         }
         foreach ($p->features as $code => $v) {
             if (is_object($v)) {
                 $v = trim(isset($v['compare']) ? $v['compare'] : $v['value']);
             } elseif (is_array($v)) {
                 foreach ($v as &$_v) {
                     if (is_object($_v)) {
                         $_v = trim(isset($_v['compare']) ? $_v['compare'] : $_v['value']);
                     } else {
                         $_v = trim($_v);
                     }
                     unset($_v);
                 }
                 sort($v, SORT_STRING);
                 $v = serialize($v);
             } else {
                 $v = trim($v);
             }
             if (isset($features[$code]) && $features[$code]['same']) {
                 if ($v !== $features[$code]['value']) {
                     $features[$code]['same'] = false;
                 }
             } else {
                 if (!isset($features[$code])) {
                     $features[$code] = array();
                 }
                 if (!$i) {
                     $features[$code]['same'] = true;
                     $features[$code]['value'] = $v;
                 } else {
                     $features[$code]['same'] = false;
                 }
             }
         }
         foreach ($features as $code => $v) {
             if (!isset($p->features[$code])) {
                 $features[$code]['same'] = false;
             }
         }
         $i++;
         unset($p);
     }
     if ($features) {
         $feature_model = new shopFeatureModel();
         foreach ($all_features = $feature_model->getByCode(array_keys($features)) as $code => $f) {
             $features[$code] += $f;
         }
     }
     $this->view->assign('features', $features);
     $this->view->assign('products', $products);
     $this->setLayout(new shopFrontendLayout());
     $this->setThemeTemplate('compare.html');
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:71,代碼來源:shopFrontendCompare.action.php

示例12: createOrder

 protected function createOrder()
 {
     $checkout_data = wa()->getStorage()->get('shop/checkout');
     if (wa()->getUser()->isAuth()) {
         $contact = wa()->getUser();
     } else {
         if (!empty($checkout_data['contact']) && $checkout_data['contact'] instanceof waContact) {
             $contact = $checkout_data['contact'];
         } else {
             $contact = new waContact();
         }
     }
     $cart = new shopCart();
     $items = $cart->items(false);
     // remove id from item
     foreach ($items as &$item) {
         unset($item['id']);
         unset($item['parent_id']);
     }
     unset($item);
     $order = array('contact' => $contact, 'items' => $items, 'total' => $cart->total(false), 'params' => isset($checkout_data['params']) ? $checkout_data['params'] : array());
     $order['discount_description'] = null;
     $order['discount'] = shopDiscounts::apply($order, $order['discount_description']);
     if (isset($checkout_data['shipping'])) {
         $order['params']['shipping_id'] = $checkout_data['shipping']['id'];
         $order['params']['shipping_rate_id'] = $checkout_data['shipping']['rate_id'];
         $shipping_step = new shopOnestepCheckoutShipping();
         $rate = $shipping_step->getRate($order['params']['shipping_id'], $order['params']['shipping_rate_id']);
         $order['params']['shipping_plugin'] = $rate['plugin'];
         $order['params']['shipping_name'] = $rate['name'];
         if (isset($rate['est_delivery'])) {
             $order['params']['shipping_est_delivery'] = $rate['est_delivery'];
         }
         if (!isset($order['shipping'])) {
             $order['shipping'] = $rate['rate'];
         }
         if (!empty($order['params']['shipping'])) {
             foreach ($order['params']['shipping'] as $k => $v) {
                 $order['params']['shipping_params_' . $k] = $v;
             }
             unset($order['params']['shipping']);
         }
     } else {
         $order['shipping'] = 0;
     }
     if (isset($checkout_data['payment'])) {
         $order['params']['payment_id'] = $checkout_data['payment'];
         $plugin_model = new shopPluginModel();
         $plugin_info = $plugin_model->getById($checkout_data['payment']);
         $order['params']['payment_name'] = $plugin_info['name'];
         $order['params']['payment_plugin'] = $plugin_info['plugin'];
         if (!empty($order['params']['payment'])) {
             foreach ($order['params']['payment'] as $k => $v) {
                 $order['params']['payment_params_' . $k] = $v;
             }
             unset($order['params']['payment']);
         }
     }
     if ($skock_id = waRequest::post('stock_id')) {
         $order['params']['stock_id'] = $skock_id;
     }
     $routing_url = wa()->getRouting()->getRootUrl();
     $order['params']['storefront'] = wa()->getConfig()->getDomain() . ($routing_url ? '/' . $routing_url : '');
     if ($ref = waRequest::cookie('referer')) {
         $order['params']['referer'] = $ref;
         $ref_parts = @parse_url($ref);
         $order['params']['referer_host'] = $ref_parts['host'];
         // try get search keywords
         if (!empty($ref_parts['query'])) {
             $search_engines = array('text' => 'yandex\\.|rambler\\.', 'q' => 'bing\\.com|mail\\.|google\\.', 's' => 'nigma\\.ru', 'p' => 'yahoo\\.com');
             $q_var = false;
             foreach ($search_engines as $q => $pattern) {
                 if (preg_match('/(' . $pattern . ')/si', $ref_parts['host'])) {
                     $q_var = $q;
                     break;
                 }
             }
             // default query var name
             if (!$q_var) {
                 $q_var = 'q';
             }
             parse_str($ref_parts['query'], $query);
             if (!empty($query[$q_var])) {
                 $order['params']['keyword'] = $query[$q_var];
             }
         }
     }
     if ($utm = waRequest::cookie('utm')) {
         $utm = json_decode($utm, true);
         if ($utm && is_array($utm)) {
             foreach ($utm as $k => $v) {
                 $order['params']['utm_' . $k] = $v;
             }
         }
     }
     if (($landing = waRequest::cookie('landing')) && ($landing = @parse_url($landing))) {
         if (!empty($landing['query'])) {
             @parse_str($landing['query'], $arr);
             if (!empty($arr['gclid']) && !empty($order['params']['referer_host']) && strpos($order['params']['referer_host'], 'google') !== false) {
                 $order['params']['referer_host'] .= ' (cpc)';
//.........這裏部分代碼省略.........
開發者ID:Lazary,項目名稱:webasyst,代碼行數:101,代碼來源:shopOnestepPluginFrontendOnestep.action.php

示例13: csrf

 public function csrf()
 {
     return '<input type="hidden" name="_csrf" value="' . waRequest::cookie('_csrf', '') . '" />';
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:4,代碼來源:waViewHelper.class.php

示例14: dispatch


//.........這裏部分代碼省略.........
             } else {
                 throw new waException("Page not found", 404);
             }
         } elseif (!strncmp($this->config->getRequestUrl(true), 'oauth.php', 9)) {
             $app_id = $this->getStorage()->get('auth_app');
             if ($app_id && !$this->appExists($app_id)) {
                 throw new waException("Page not found", 404);
             }
             $app_system = self::getInstance($app_id);
             if (class_exists($app_id . 'OAuthController')) {
                 $app_system->getFrontController()->execute(null, 'OAuth');
             } else {
                 wa('webasyst')->getFrontController()->execute(null, 'OAuth');
             }
         } elseif (!strncmp($this->config->getRequestUrl(true), 'payments.php/', 13)) {
             $url = substr($this->config->getRequestUrl(true), 13);
             waRequest::setParam('module_id', strtok($url, '/?'));
             $webasyst_system = self::getInstance('webasyst');
             $webasyst_system->getFrontController()->execute(null, 'payments', null, true);
         } elseif ($this->getEnv() == 'backend' && !$this->getUser()->isAuth()) {
             $webasyst_system = self::getInstance('webasyst', null, true);
             $webasyst_system->getFrontController()->execute(null, 'login', waRequest::get('action'), true);
         } elseif ($this->config instanceof waAppConfig) {
             if ($this->getEnv() == 'backend' && !$this->getUser()->getRights($this->getConfig()->getApplication(), 'backend')) {
                 header("Location: " . $this->getConfig()->getBackendUrl(true));
                 exit;
             }
             $this->getFrontController()->dispatch();
         } else {
             $app = null;
             $route = null;
             if ($this->getEnv() == 'frontend') {
                 // logout
                 if (null !== ($logout_url = waRequest::get('logout'))) {
                     // for getting app
                     $this->getRouting()->dispatch();
                     $app = waRequest::param('app');
                     // For logging logout action
                     $data = array('app_id' => $app, 'contact_id' => $this->getUser()->getId(), 'datetime' => date("Y-m-d H:i:s"), 'action' => 'logout', 'params' => $this->getEnv());
                     // logout itself
                     $this->getUser()->logout();
                     if (!$logout_url) {
                         $logout_url = $this->config->getRequestUrl(false, true);
                     }
                     // logging logout
                     if (!class_exists('waLogModel')) {
                         wa('webasyst');
                     }
                     $log_model = new waLogModel();
                     $log_model->insert($data);
                     // make redirect after logout
                     $this->getResponse()->redirect($logout_url);
                 }
                 if (!$this->getRouting()->dispatch()) {
                     $this->getResponse()->redirect($this->getConfig()->getBackendUrl(true), 302);
                 }
                 $app = waRequest::param('app');
             } else {
                 self::getInstance('webasyst');
                 $path = $this->getConfig()->getRequestUrl(true);
                 if (($i = strpos($path, '?')) !== false) {
                     $path = substr($path, 0, $i);
                 }
                 $url = explode("/", $path);
                 $app = isset($url[1]) && $url[1] != 'index.php' ? $url[1] : 'webasyst';
             }
             if (!$app) {
                 $app = 'webasyst';
             }
             $app_system = self::getInstance($app, null, true);
             if ($app != 'webasyst' && $this->getEnv() == 'backend' && !$this->getUser()->getRights($app_system->getConfig()->getApplication(), 'backend')) {
                 //$this->getResponse()->redirect($this->getConfig()->getBackendUrl(true), 302);
                 throw new waRightsException('Access to this app denied', 403);
             }
             if ((waRequest::param('secure') || waRequest::param('auth')) && !$this->getUser()->isAuth()) {
                 $auth = $this->getAuthConfig();
                 if (!empty($auth['app'])) {
                     $app_system = self::getInstance($auth['app'], null, true);
                 }
                 $app_system->login();
             } else {
                 if (waRequest::param('secure') && $app_system->getConfig()->getInfo('csrf') && waRequest::method() == 'post' && waRequest::post('_csrf') != waRequest::cookie('_csrf')) {
                     throw new waException('CSRF Protection', 403);
                 }
                 $app_system->getFrontController()->dispatch();
             }
         }
     } catch (waApiException $e) {
         print $e;
     } catch (waException $e) {
         print $e;
     } catch (Exception $e) {
         if (waSystemConfig::isDebug()) {
             print $e;
         } else {
             $e = new waException($e->getMessage(), $e->getCode());
             print $e;
         }
     }
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:101,代碼來源:waSystem.class.php

示例15: save


//.........這裏部分代碼省略.........
                     } else {
                         if (isset($val['value']) && is_string($val['value'])) {
                             $val['value'] = trim($val['value']);
                         } else {
                             if ($f instanceof waContactCompositeField && isset($val['data']) && is_array($val['data'])) {
                                 foreach ($val['data'] as &$v) {
                                     if (is_string($v)) {
                                         $v = trim($v);
                                     }
                                 }
                                 unset($v);
                             }
                         }
                     }
                 }
                 unset($val);
             } else {
                 if (is_string($value)) {
                     $value = trim($value);
                 } else {
                     if (isset($value['value']) && is_string($value['value'])) {
                         $value['value'] = trim($value['value']);
                     } else {
                         if ($f instanceof waContactCompositeField && isset($value['data']) && is_array($value['data'])) {
                             foreach ($value['data'] as &$v) {
                                 if (is_string($v)) {
                                     $v = trim($v);
                                 }
                             }
                             unset($v);
                         }
                     }
                 }
             }
             if ($validate !== 42) {
                 // this deep dark magic is used when merging contacts
                 if ($validate) {
                     if ($e = $f->validate($value, $this->id)) {
                         $errors[$f->getId()] = $e;
                     }
                 } elseif ($f->isUnique()) {
                     // validate unique
                     if ($e = $f->validateUnique($value, $this->id)) {
                         $errors[$f->getId()] = $e;
                     }
                 }
             }
             if (!$errors && $f->getStorage()) {
                 $save[$f->getStorage()->getType()][$field] = $f->prepareSave($value, $this);
             }
         } elseif ($contact_model->fieldExists($field)) {
             $save['waContactInfoStorage'][$field] = $value;
         } else {
             $save['waContactDataStorage'][$field] = $value;
         }
     }
     // Returns errors
     if ($errors) {
         return $errors;
     }
     $is_add = false;
     // Saving to all storages
     try {
         if (!$this->id) {
             $is_add = true;
             $storage = 'waContactInfoStorage';
             if (wa()->getEnv() == 'frontend') {
                 if ($ref = waRequest::cookie('referer')) {
                     $save['waContactDataStorage']['referer'] = $ref;
                     $save['waContactDataStorage']['referer_host'] = parse_url($ref, PHP_URL_HOST);
                 }
                 if ($utm = waRequest::cookie('utm')) {
                     $utm = json_decode($utm, true);
                     if ($utm && is_array($utm)) {
                         foreach ($utm as $k => $v) {
                             $save['waContactDataStorage']['utm_' . $k] = $v;
                         }
                     }
                 }
             }
             $this->id = waContactFields::getStorage($storage)->set($this, $save[$storage]);
             unset($save[$storage]);
         }
         foreach ($save as $storage => $storage_data) {
             waContactFields::getStorage($storage)->set($this, $storage_data);
         }
         $this->data = array();
         wa()->event(array('contacts', 'save'), $this);
         $this->removeCache();
         $this->clearDisabledFields();
     } catch (Exception $e) {
         // remove created contact
         if ($is_add && $this->id) {
             $this->delete();
             $this->id = null;
         }
         $errors['name'][] = $e->getMessage();
     }
     return $errors ? $errors : 0;
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:101,代碼來源:waContact.class.php


注:本文中的waRequest::cookie方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。