/** * Check an email address for correct format. * @param string $email email address * @return boolean */ public static function email($email) { if (Text::strlen($email) > 254) { return FALSE; } $expression = '/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\\.[a-z]{2,6}|\\d{1,3}(?:\\.\\d{1,3}){3})$/iD'; return (bool) preg_match($expression, (string) $email); }
public function create_cart() { // Generate hash of new cart for cookie $hash = sha1(microtime() . Text::random()); // Save cart into database $this->_cart_id = Arr::get(DB::insert('carts', array('hash', 'created_at'))->values(array($hash, time()))->execute(), 0); // Save cart to cookie Cookie::set('cart', $hash, 60 * 60 * 24 * 365); return true; }
public function indexAction() { $this->_template = 'Text'; Config::set('content_class', 'brands-list'); // Seo $this->_seo['h1'] = 'Бренды'; $this->_seo['title'] = 'Бренды'; $this->_seo['keywords'] = 'Бренды'; $this->_seo['description'] = 'Бренды'; // Get brands list $result = DB::select()->from('brands')->where('status', '=', 1)->order_by('name', 'ASC')->as_object()->execute(); // Get alphabet $alphabet = Text::get_alphabet($result); $this->_content = View::tpl(array('alphabet' => $alphabet), 'Brands/List'); }
/** * Generate a random password */ public static function generate_random_password() { return Text::random('alnum', 8); }
public function orderAction() { // Check incoming data $name = Text::xssClean(Arr::get($this->post, 'name')); if (!$name) { $this->error('Вы не указали имя!'); } $email = Text::xssClean(Arr::get($this->post, 'email')); if (!$email or !filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->error('Вы указали неверный e-mail!'); } $phone = Text::xssClean(Arr::get($this->post, 'phone')); if (!$phone or !preg_match('/\\(\\d{3}\\)\\s\\d{3}-\\d{2}-\\d{2}/', $phone, $matches)) { $this->error('Вы указали неверный телефон!'); } $places = Text::xssClean(Arr::get($this->post, 'seats')); $places = array_filter(explode(',', $places)); if (!$places or !is_array($places)) { $this->error('Вы не выбрали места!'); } $message = nl2br(Text::xssClean(Arr::get($this->post, 'message', null))); $afishaId = (int) Text::xssClean(Arr::get($this->post, 'id')); // Get prices by afisha ID $prices = DB::select('id')->from('prices')->where('afisha_id', '=', $afishaId)->find_all(); if (count($prices) == 0) { $this->error('Ошибка создания заказа (выборка цен)'); } $pricesIds = array(); foreach ($prices as $price) { $pricesIds[] = $price->id; } // Generate seats id from places list $seats = DB::select('id')->from('seats')->where('view_key', 'IN', $places)->where('price_id', 'IN', $pricesIds)->and_where_open()->where('status', '=', 1)->or_where_open()->where('status', '=', 2)->where('reserved_at', '<', time() - 60 * 60 * 24 * conf::get('reserved_days'))->or_where_close()->and_where_close()->find_all(); if (count($seats) == 0) { $this->error('Ошибка создания заказа (выборка мест)'); } $seatsId = array(); foreach ($seats as $seat) { $seatsId[] = $seat->id; } $data = array('afisha_id' => $afishaId, 'name' => $name, 'email' => $email, 'phone' => $phone, 'message' => $message, 'seats_keys' => implode(',', $places), 'created_at' => time(), 'first_created_at' => time(), 'updated_at' => time(), 'ip' => System::getRealIP()); $res = \Core\Common::insert('afisha_orders', $data)->execute(); if (!$res) { $this->error('ошибка создания заказа'); } // Update status $res2 = DB::update('seats')->set(array('status' => 2, 'reserved_at' => time()))->where('id', 'IN', $seatsId)->execute(); $afisha = DB::select()->from('afisha')->where('id', '=', $afishaId)->find(); $data['event_name'] = $afisha->name; // Send email messages for adimn and user Afisha\Models\Afisha::sendOrderMessageAdmin(array('id_order' => $res[0], 'order' => $data, 'order_text' => Arr::get($this->post, 'order'))); Afisha\Models\Afisha::sendOrderMessageUser(array('id_order' => $res[0], 'order' => $data, 'order_text' => Arr::get($this->post, 'order'))); // Save log $qName = 'Новый заказ'; $url = '/backend/afisha_orders/edit/' . $res[0]; Log::add($qName, $url, 8); $response = array(); // Redirect to payment system if (Arr::get($this->post, 'action') == 'payment') { $response['redirect'] = \Core\HTML::link('payment/' . $res[0]); } else { $response['reload'] = true; } $response['response'] = 'Ваш заказ отправлен'; return $this->success($response); }
public function setSeoForGroup($page) { $tpl = DB::select()->from('seo')->where('id', '=', 1)->as_object()->execute()->current(); $from = array('{{name}}', '{{content}}'); $text = trim(strip_tags($page->text)); $to = array($page->name, $text); $res = preg_match_all('/{{content:[0-9]*}}/', $tpl->description, $matches); if ($res) { $matches = array_unique($matches); foreach ($matches[0] as $pattern) { preg_match('/[0-9]+/', $pattern, $m); $from[] = $pattern; $to[] = Text::limit_words($text, $m[0]); } } $title = str_replace($from, $to, $tpl->title) . (Arr::get($_GET, 'sort') == 'cost' && Arr::get($_GET, 'type') == 'asc' ? ', От бютжетных к дорогим' : '') . (Arr::get($_GET, 'sort') == 'cost' && Arr::get($_GET, 'type') == 'desc' ? ', От дорогих к бютжетным' : '') . (Arr::get($_GET, 'sort') == 'created_at' && Arr::get($_GET, 'type') == 'desc' ? ', От новых моделей к старым' : '') . (Arr::get($_GET, 'sort') == 'created_at' && Arr::get($_GET, 'type') == 'asc' ? ', От старых моделей к новым' : '') . (Arr::get($_GET, 'sort') == 'name' && Arr::get($_GET, 'type') == 'asc' ? ', По названию от А до Я' : '') . (Arr::get($_GET, 'sort') == 'name' && Arr::get($_GET, 'type') == 'desc' ? ', По названию от Я до А' : '') . (Arr::get($_GET, 'page', 1) > 1 ? ', Страница ' . Arr::get($_GET, 'page', 1) : ''); $this->_seo['h1'] = str_replace($from, $to, $tpl->h1); $this->_seo['title'] = $title; $this->_seo['keywords'] = str_replace($from, $to, $tpl->keywords); $this->_seo['description'] = str_replace($from, $to, $tpl->description); $this->_seo['seo_text'] = $page->text; $this->generateParentBreadcrumbs($page->parent_id, 'catalog_tree', 'parent_id', '/catalog/'); $this->setBreadcrumbs($page->name); }