/** * Сверяет введённое значение с сохранённым в сессии. */ protected function validate($value) { if (!($good = mcms::session('captcha:' . $this->value)) or $good != $value) { throw new ValidationException($this->label, t('Вы неверно ввели символы с картинки. Похоже, вы — робот, рассылающий спам!')); } mcms::session('captcha:' . $this->value, null); }
/** * Выход, завершение сеанса. * * @param Context $ctx * @return Response */ public static function rpc_get_logout(Context $ctx) { $uid = null; $stack = (array) mcms::session('uidstack'); $uid = array_pop($stack); mcms::session('uidstack', $stack); if (empty($uid)) { $ctx->user->logout(); } else { self::login($uid); } $next = $uid ? $ctx->get('from', '') : ''; return $ctx->getRedirect($next); }
private function checkUserHasVote(array $options) { $skey = 'already_voted_with_' . $this->getInstanceName() . "_{$options['node']}"; $rate = (array) mcms::session('rate'); // Мы кэшируем состояние в сессии для всех пользователей, поэтому проверяем в первую очередь. if (!empty($rate[$skey])) { return true; } // Анонимных пользователей считаем по IP, зарегистрированных -- по идентификатору. if ($this->user->id == 0) { $status = 0 != $this->ctx->db->getResult("SELECT COUNT(*) FROM `node__rating` WHERE `nid` = :nid AND `uid` = 0 AND `ip` = :ip", array(':nid' => $this->ctx->document->id, ':ip' => $_SERVER['REMOTE_ADDR'])); } else { $status = 0 != $this->ctx->db->getResult("SELECT COUNT(*) FROM `node__rating` WHERE `nid` = :nid AND `uid` = :uid", array(':nid' => $this->ctx->document->id, ':uid' => $this->user->id)); } // Сохраняем в сессии для последующего быстрого доступа. $rate[$skey] = $status; mcms::session('rate', $rate); return $status; }
/** * Return the contents of the session in array form. */ function contents() { mcms::session()->raw(); }
private static function getReturnTo($id = null) { $ctx = Context::last(); $url = $ctx->url()->getBase($ctx) . 'api/openid/return.rpc?id=' . urlencode($id) . '&sid=' . mcms::session()->id; if (!empty($_GET['destination'])) { $url .= '&destination=' . urlencode($_GET['destination']); } return $url; }
/** * Обработка запросов на вывод капчи. * @route GET//captcha.png */ public static function on_show(Context $ctx) { $id = $ctx->get('id', 'captcha'); $seed = substr(preg_replace('/[^0-9]/', '', md5(rand() . microtime())), 0, 6); mcms::session('captcha:' . $id, $seed); $captcha = new CaptchaModule($seed); $captcha->drawImage(); exit; }
/** * Возвращает содержимое корзины в виде XML. */ public function getXML($details = true) { $result = array(); $sumqty = 0; if (count($cart = $this->getItems())) { $sum = $sumqty = 0; $ids = array_keys($cart); foreach ($nodes = Node::find(array('id' => $ids)) as $node) { if (empty($items)) { $qty = $cart[$node->id]; } else { $del = $items[$node->id]['delete']; if ($del) { unset($cart[$node->id]); continue; } $qty = $items[$node->id]['qty']; $cart[$node->id] = $qty; } $sum += $node->price * $qty; $sumqty += $qty; $result[] = array('id' => $node->id, 'name' => $node->getName(), 'qty' => $qty, 'price' => $node->price, 'sum' => $node->price * $qty); } $total = $sum; $conf = $this->ctx->config->getArray('modules/cart'); if (!empty($conf['discount_threshold'])) { if ($sum >= $conf['discount_threshold']) { if (!empty($conf['discount_price'])) { if ('%' == substr($price = $conf['discount_price'], -1)) { $price = $sum / 100 * substr($price, 0, -1); } $result['discount'] = array('name' => t('Скидка %size при заказе от %sum', array('%size' => $conf['discount_price'], '%sum' => number_format($conf['discount_threshold'], 2, ',', '.'))), 'qty' => 1, 'price' => -$price, 'sum' => -$price); $total -= $price; } } } if (!empty($conf['delivery_threshold'])) { if (!empty($conf['delivery_price'])) { $result['delivery'] = array('name' => t('Доставка (бесплатно при заказе от %size)', array('%size' => number_format($conf['delivery_threshold'], 2, ',', '.'))), 'qty' => 1, 'price' => $sum < $conf['delivery_threshold'] ? $conf['delivery_price'] : 0); $result['delivery']['sum'] = $result['delivery']['price']; $total += $result['delivery']['sum']; } } } if ($discounter = $this->ctx->config->get('modules/cart/discounter')) { if (class_exists($discounter)) { $d = new $discounter(); $d->process($result); } } $result['total'] = array('name' => t('Итого'), 'qty' => $sumqty, 'price' => null, 'sum' => 0); mcms::session('cart', $cart); $output = ''; foreach ($result as $k => $v) { if (is_numeric($k)) { $result['total']['sum'] += $v['sum']; $output .= html::em('item', $v); } } $output = html::em('items', $result['total'], $output); if ($details) { $output .= html::wrap('details', Node::findXML(array('deleted' => 0, 'published' => 1, 'id' => array_keys($cart)))); } return $output; }
/** * Возвращает группы, в которых состоит пользователь. */ public function getGroups() { if (null === $this->groups) { $this->groups = (array) mcms::session('groups'); $this->groups[] = 0; } return $this->groups; }