public function registrationAction() { if (Fw_Auth::isValid()) { Fw_Request::redirect(C::uri(array('donors', Fw_Auth::get('id')))); } $antispam = Fw_Request::post('antispam', NULL); $data = array(); $error = array(); if (!is_null($antispam)) { if ($this->checkSecureKey($antispam)) { $data['name'] = Fw_Request::post('name', NULL); $data['surname'] = Fw_Request::post('surname', NULL); $data['email'] = Fw_Request::post('email', NULL); $data['login'] = Fw_Request::post('login', NULL); $data['password'] = Fw_Request::post('password', NULL); $data['repassword'] = Fw_Request::post('repassword', NULL); if (!preg_match("/^[\\p{L}]{2,50}\$/ui", $data['name'])) { $error['name'] = C::getLanguageString('registration_only_chars_name'); } if (!preg_match("/^[\\p{L}]{2,50}\$/ui", $data['surname'])) { $error['surname'] = C::getLanguageString('registration_only_chars_surname'); } if (!preg_match("/^[-a-z0-9!#\$%&'*+\\/=?^_`{|}~]+(?:\\.[-a-z0-9!#\$%&'*+\\/=?^_`{|}~]+)*@(?:[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?\\.)*(?:aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z][a-z])\$/ui", $data['email'])) { $error['email'] = C::getLanguageString('contact_error_email'); } elseif ($this->model->chekEmailRepeat($data['email'])) { $error['email'] = C::getLanguageString('registration_repeat_email'); } if (!preg_match("/^[a-z\\d_\\-]{2,50}\$/ui", $data['login'])) { $error['login'] = C::getLanguageString('contact_error_login'); } elseif ($this->model->chekLoginRepeat($data['login'])) { $error['login'] = C::getLanguageString('registration_repeat_login'); } if (!preg_match("/^.{8,64}\$/ui", $data['password'])) { $error['password'] = C::getLanguageString('registration_password_error'); } if (sha1($data['password']) !== sha1($data['repassword'])) { $error['repassword'] = C::getLanguageString('registration_repassword_error'); } if (empty($error)) { if (!$this->model->registrationNewUser($data)) { throw new Fw_Exception('[f:"' . __FILE__ . '", l:"' . __LINE__ . '"] Ошибка сохранения пользователя', 500); } $this->sendConfirmationMail($data); Fw_Request::redirect(C::uri(array('user', 'success'))); } else { $this->view->error = $error; $this->view->data = $data; } } else { die('You\'r bot'); } } $this->view->setBlocks(array('breadcrumbs')); $this->view->antispam = $this->createSecureKey(); $this->view->render(); }
public function updateUserData($data) { $sql_parts = array(); $id = Fw_Auth::get('id'); foreach ($data as $key => $value) { $sql_parts[] = "`" . $key . "` = '" . $value . "'"; } $this->sql->setQuery("UPDATE users SET " . implode(",", $sql_parts) . " WHERE u_id = " . $id); return $this->sql->sendQuery(); }
public function getProjectsByDonor($id) { $cache = true; if (Fw_Auth::isValid()) { $cache = Fw_Auth::get('id') == $id ? false : true; } $lang = Fw_Request::get('language'); $this->sql->setQuery("\n SELECT\n p.p_id,\n p.p_date_create,\n p.p_need,\n p.p_current,\n p.p_count_vote,\n pl.pl_description,\n pl.pl_text,\n pl.pl_title,\n pl.pl_alias,\n pl.pl_lang,\n GROUP_CONCAT(DISTINCT pph.pp_src ORDER BY pph.pp_ord ASC SEPARATOR ',') AS images\n FROM projects_pays AS pp\n LEFT JOIN projects_lang AS pl ON pl.pl_p_id = pp.pp_p_id AND pl.pl_lang = '{$lang}'\n LEFT JOIN projects AS p ON p.p_id = pl.pl_p_id\n LEFT JOIN projects_photos AS pph ON pph.pp_p_id = pl.pl_p_id\n WHERE pp.pp_u_id = {$id} AND p.p_state = 1\n GROUP BY pp.pp_p_id\n ORDER BY pp.pp_data DESC\n "); $this->sql->sendQuery($cache, 3600, array('donors', 'donor', $lang)); return $this->sql->fetchObjects(); }
public function getProject($id, $only_ended = false) { $lang = Fw_Request::get('language'); $sql_select = $sql_left_join = ''; $cache = true; if (Fw_Auth::isValid()) { $sql_select = ", pv.pv_id"; $sql_left_join = " LEFT JOIN projects_votes AS pv ON pv.pv_p_id = p.p_id AND pv.pv_u = " . Fw_Auth::get('id'); $cache = false; } $this->sql->setQuery(" \n SELECT\n p.*,\n pl.*,\n (SELECT pl2.pl_alias FROM projects_lang AS pl2 WHERE pl2.pl_p_id = {$id} AND pl2.pl_lang = 'ua') AS ua_alias,\n (SELECT pl2.pl_alias FROM projects_lang AS pl2 WHERE pl2.pl_p_id = {$id} AND pl2.pl_lang = 'ru') AS ru_alias,\n GROUP_CONCAT(DISTINCT pp.pp_src ORDER BY pp.pp_ord SEPARATOR ',') AS images\n " . $sql_select . "\n FROM projects AS p\n LEFT JOIN projects_lang AS pl ON p.p_id = pl.pl_p_id AND pl.pl_lang = '{$lang}'\n LEFT JOIN projects_photos AS pp ON pp.pp_p_id = p.p_id\n " . $sql_left_join . "\n WHERE \n p.p_state = 1 \n AND p.p_id = {$id}\n LIMIT 1\n "); $this->sql->sendQuery($cache, 1200, array('project', $lang)); return $this->sql->fetchRow(); }
?> /user/registration/" title="<?php echo C::getLanguageString('register_new_user'); ?> "><?php echo C::getLanguageString('registration'); ?> </a> <?php } else { ?> <a href="<?php echo C::$lang == 'ua' ? '' : '/ru'; ?> /donors/<?php echo Fw_Auth::get('id'); ?> /" title="<?php echo C::getLanguageString('profile'); ?> "><?php echo C::getLanguageString('profile'); ?> </a> <?php } ?> <img alt="" src="/img/icon_entering.png" width="20" height="20"> <?php if (!Fw_Auth::isValid()) {
public function voteAction() { $id = Fw_Request::get('id', 10); if (Fw_Auth::isValid()) { $user_id = Fw_Auth::get('id'); if ($this->model->voteByProject($id, $user_id)) { $this->model->updateVoteByProject($id); echo 1; } else { echo 0; } } else { echo 0; } die; }
public function indexAction() { $id = Fw_Request::get('id', null); if (!is_null($id)) { $this->view->setLayout('donors', 'donor'); $this->view->data = $this->model->getDonor($id); if (!isset($this->view->data['u_id']) || !is_numeric($this->view->data['u_id'])) { throw new Fw_Exception('[f:"' . __FILE__ . '", l:"' . __LINE__ . '"] Страница не найдена', 404); } $name_bread = $this->view->data['u_surname'] . ' ' . $this->view->data['u_name']; if (Fw_Auth::isValid() && Fw_Auth::get('id') == $id) { $this->view->error = array(); $data = array(); $name = Fw_Request::post('u_name', null); $antispam = Fw_Request::post('antispam', null); $surname = Fw_Request::post('u_surname', null); $address = Fw_Request::post('u_address', null); $img = Fw_Request::getFile('u_img', null); $information = Fw_Request::postNoHtml('u_information', 0, 1500); if (!is_null($antispam)) { if (!preg_match("/^[\\p{L}]{2,100}\$/ui", $name)) { $this->view->error['u_name'] = C::getLanguageString('registration_only_chars_name'); } $data['u_name'] = $name; if (!preg_match("/^[\\p{L}]{2,100}\$/ui", $surname)) { $this->view->error['u_surname'] = C::getLanguageString('registration_only_chars_surname'); } $data['u_surname'] = $surname; if (!empty($address)) { if (!preg_match("/^[^\\s][\\.\\p{L}\\d\\,\\-\\s]{0,100}\$/ui", $address)) { $this->view->error['u_address'] = C::getLanguageString('registration_only_chars_name'); } $data['u_address'] = $address; } else { $data['u_address'] = ''; } $data['u_information'] = !is_null($information) ? $information : ''; if (!is_null($img) && isset($img['name']) && !empty($img['name'])) { $type = array_pop(explode(".", $img['name'])); if (in_array(strtolower($type), array('png', 'jpeg', 'jpg', 'gif'))) { if ($img['size'] > 1024 * 1024 * 2) { $this->view->error['u_img'] = C::getLanguageString('wrong_file_size'); } else { $new_file_name = $data['u_img'] = sha1($img['name'] . time()) . '.' . $type; $to_path = realpath(APPLICATION_PATH . '/../' . C::pub_dir . '/images') . C::ds . $new_file_name; if (move_uploaded_file($img['tmp_name'], $to_path) === false) { throw new Fw_Exception('[f:"' . __FILE__ . '", l:"' . __LINE__ . '"] Ошибка загрузки аватара', 500); } if (!empty($this->view->data['u_img']) && $this->view->data['u_img'] !== 'anonim_donor.jpg') { $config = C::getConfig('img'); $del_file = realpath(APPLICATION_PATH . '/../' . C::pub_dir . '/images') . C::ds . $this->view->data['u_img']; if (is_file($del_file)) { unlink($del_file); } foreach ($config['size'] as $sizes) { $del_file = realpath(APPLICATION_PATH . '/../' . C::pub_dir . '/images/cropr_' . $sizes) . C::ds . $this->view->data['u_img']; if (is_file($del_file)) { unlink($del_file); } } } } } else { $this->view->error['u_img'] = C::getLanguageString('wrong_file_format'); } } if (empty($this->view->error)) { if (!Fw_Model::getInstance()->getModel('user')->updateUserData($data)) { throw new Fw_Exception('[f:"' . __FILE__ . '", l:"' . __LINE__ . '"] Ошибка обновления данных пользователя', 500); } Fw_Request::redirect(C::uri(array('donors', $id))); } } $this->view->antispam = base64_encode(time()); } if (!empty($this->view->data['pl_description'])) { $description = strip_tags($this->view->data['pl_description']); $description = trim($description); if (!empty($description)) { if (mb_strlen($description, 'UTF-8') > 240) { $description = substr($description, 0, 240) . '...'; } $this->view->setHead('meta', array('name' => 'description', 'content' => $description), '', false); } } $this->view->ru_lang_url = '/ru/donors/' . $this->view->data['u_id'] . DS; $this->view->ua_lang_url = '/ua/donors/' . $this->view->data['u_id'] . DS; $this->view->projects_data = $this->model->getProjectsByDonor($id); $this->view->setHead('title', array(), $name_bread . ' ' . C::getLanguageString('donor_h1'), true); $this->view->setHead('meta', array('name' => 'keywords', 'content' => strtolower(C::getLanguageString('donor')) . ', ' . $name_bread), '', false); $breadcrumb = unserialize(Fw_Model::getInstance()->getModel('blocks')->getBreadCrumbs($this->name, $this->actionName)); if ($breadcrumb) { array_push($breadcrumb, array('name' => $name_bread)); $this->view->setBlocks(array('breadcrumbs' => array('data' => serialize($breadcrumb)))); } } else { $this->view->data = $this->model->getOrderDonors('new', 0, 10); $this->view->setBlocks(array('breadcrumbs')); } $this->view->render(); }