/** * Выводит форму для редактирования профиля и обрабатывает её * */ protected function EventProfile() { $this->Viewer_AddHtmlTitle($this->Lang_Get('settings_menu_profile')); /** * Если нажали кнопку "Сохранить" */ if (isPost('submit_profile_edit')) { $this->Security_ValidateSendForm(); $bError = false; /** * Заполняем профиль из полей формы */ /** * Проверяем имя */ if (func_check(getRequest('profile_name'), 'text', 2, 20)) { $this->oUserCurrent->setProfileName(getRequest('profile_name')); } else { $this->oUserCurrent->setProfileName(null); } /** * Проверка мыла */ if (func_check(getRequest('mail'), 'mail')) { if ($oUserMail = $this->User_GetUserByMail(getRequest('mail')) and $oUserMail->getId() != $this->oUserCurrent->getId()) { $this->Message_AddError($this->Lang_Get('settings_profile_mail_error_used'), $this->Lang_Get('error')); $bError = true; } else { $this->oUserCurrent->setMail(getRequest('mail')); } } else { $this->Message_AddError($this->Lang_Get('settings_profile_mail_error'), $this->Lang_Get('error')); $bError = true; } /** * Проверяем пол */ if (in_array(getRequest('profile_sex'), array('man', 'woman', 'other'))) { $this->oUserCurrent->setProfileSex(getRequest('profile_sex')); } else { $this->oUserCurrent->setProfileSex('other'); } /** * Проверяем дату рождения */ if (func_check(getRequest('profile_birthday_day'), 'id', 1, 2) and func_check(getRequest('profile_birthday_month'), 'id', 1, 2) and func_check(getRequest('profile_birthday_year'), 'id', 4, 4)) { $this->oUserCurrent->setProfileBirthday(date("Y-m-d H:i:s", mktime(0, 0, 0, getRequest('profile_birthday_month'), getRequest('profile_birthday_day'), getRequest('profile_birthday_year')))); } else { $this->oUserCurrent->setProfileBirthday(null); } /** * Проверяем страну */ if (func_check(getRequest('profile_country'), 'text', 1, 30)) { $this->oUserCurrent->setProfileCountry(getRequest('profile_country')); } else { $this->oUserCurrent->setProfileCountry(null); } /** * Проверяем регион * пока отключим регион, т.к. не понятно нужен ли он вообще =) */ /* if (func_check(getRequest('profile_region'),'text',1,30)) { $this->oUserCurrent->setProfileRegion(getRequest('profile_region')); } else { $this->oUserCurrent->setProfileRegion(null); } */ /** * Проверяем город */ if (func_check(getRequest('profile_city'), 'text', 1, 30)) { $this->oUserCurrent->setProfileCity(getRequest('profile_city')); } else { $this->oUserCurrent->setProfileCity(null); } /** * Проверяем ICQ */ if (func_check(getRequest('profile_icq'), 'id', 4, 15)) { $this->oUserCurrent->setProfileIcq(getRequest('profile_icq')); } else { $this->oUserCurrent->setProfileIcq(null); } /** * Проверяем сайт */ if (func_check(getRequest('profile_site'), 'text', 3, 200)) { $this->oUserCurrent->setProfileSite(getRequest('profile_site')); } else { $this->oUserCurrent->setProfileSite(null); } /** * Проверяем название сайта */ if (func_check(getRequest('profile_site_name'), 'text', 3, 50)) { $this->oUserCurrent->setProfileSiteName(getRequest('profile_site_name')); } else { $this->oUserCurrent->setProfileSiteName(null); } /** * Проверяем информацию о себе */ if (func_check(getRequest('profile_about'), 'text', 1, 3000)) { $this->oUserCurrent->setProfileAbout(getRequest('profile_about')); } else { $this->oUserCurrent->setProfileAbout(null); } /** * Проверка на смену пароля */ if (getRequest('password', '') != '') { if (func_check(getRequest('password'), 'password', 5)) { if (getRequest('password') == getRequest('password_confirm')) { if (func_encrypt(getRequest('password_now')) == $this->oUserCurrent->getPassword()) { $this->oUserCurrent->setPassword(func_encrypt(getRequest('password'))); } else { $bError = true; $this->Message_AddError($this->Lang_Get('settings_profile_password_current_error'), $this->Lang_Get('error')); } } else { $bError = true; $this->Message_AddError($this->Lang_Get('settings_profile_password_confirm_error'), $this->Lang_Get('error')); } } else { $bError = true; $this->Message_AddError($this->Lang_Get('settings_profile_password_new_error'), $this->Lang_Get('error')); } } /** * Загрузка аватара, делаем ресайзы */ if (isset($_FILES['avatar']) and is_uploaded_file($_FILES['avatar']['tmp_name'])) { /** * Получаем список текущих аватаров */ $sPathOld = $this->oUserCurrent->getProfileAvatar(); $aUserAvatars = array(); if ($sPathOld) { foreach (array_merge(Config::Get('module.user.avatar_size'), array(100)) as $iSize) { $aUserAvatars[$iSize] = $this->oUserCurrent->getProfileAvatarPath($iSize); } } if ($sPath = $this->User_UploadAvatar($_FILES['avatar'], $this->oUserCurrent)) { $this->oUserCurrent->setProfileAvatar($sPath); /** * Удаляем старые, если путь не совпадает с текущими аватарками */ if ($sPathOld and $sPath != $sPathOld and count($aUserAvatars)) { foreach ($aUserAvatars as $iSize => $sAvatarPath) { @unlink($this->Image_GetServerPath($sAvatarPath)); } } } else { $bError = true; $this->Message_AddError($this->Lang_Get('settings_profile_avatar_error'), $this->Lang_Get('error')); } } /** * Удалить аватара */ if (getRequest('avatar_delete')) { $this->User_DeleteAvatar($this->oUserCurrent); $this->oUserCurrent->setProfileAvatar(null); } /** * Загрузка фото, делаем ресайзы */ if (isset($_FILES['foto']) and is_uploaded_file($_FILES['foto']['tmp_name'])) { if ($sFileFoto = $this->User_UploadFoto($_FILES['foto'], $this->oUserCurrent)) { $this->oUserCurrent->setProfileFoto($sFileFoto); } else { $bError = true; $this->Message_AddError($this->Lang_Get('settings_profile_foto_error'), $this->Lang_Get('error')); } } /** * Удалить фото */ if (isset($_REQUEST['foto_delete'])) { $this->User_DeleteFoto($this->oUserCurrent); $this->oUserCurrent->setProfileFoto(null); } /** * Ставим дату последнего изменения профиля */ $this->oUserCurrent->setProfileDate(date("Y-m-d H:i:s")); /** * Сохраняем изменения профиля */ if (!$bError) { if ($this->User_Update($this->oUserCurrent)) { /** * Добавляем страну */ if ($this->oUserCurrent->getProfileCountry()) { if (!($oCountry = $this->User_GetCountryByName($this->oUserCurrent->getProfileCountry()))) { $oCountry = Engine::GetEntity('User_Country'); $oCountry->setName($this->oUserCurrent->getProfileCountry()); $this->User_AddCountry($oCountry); } $this->User_SetCountryUser($oCountry->getId(), $this->oUserCurrent->getId()); } /** * Добавляем город */ if ($this->oUserCurrent->getProfileCity()) { if (!($oCity = $this->User_GetCityByName($this->oUserCurrent->getProfileCity()))) { $oCity = Engine::GetEntity('User_City'); $oCity->setName($this->oUserCurrent->getProfileCity()); $this->User_AddCity($oCity); } $this->User_SetCityUser($oCity->getId(), $this->oUserCurrent->getId()); } $this->Message_AddNoticeSingle($this->Lang_Get('settings_profile_submit_ok')); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error')); } } } }
/** * Обработка отправки формы при редактировании форума * * @param unknown_type $oForum */ protected function submitEditForum($oForum = null) { $sNewType = isPost('f_type') ? getRequestStr('f_type') : 'forum'; /** * Обновляем свойства форума */ $oForum->setTitle(forum_parse_title(getRequestStr('forum_title'))); $oForum->setUrl(preg_replace("/\\s+/", '_', trim(getRequestStr('forum_url', '')))); if ($sNewType == 'category') { $oForum->setCanPost(1); } else { $oForum->setDescription(getRequestStr('forum_description')); $oForum->setParentId(getRequestStr('forum_parent')); $oForum->setType(getRequestStr('forum_type')); $oForum->setCanPost((int) getRequest('forum_sub_can_post', 0, 'post') === 1); $oForum->setQuickReply((int) getRequest('forum_quick_reply', 0, 'post') === 1); $oForum->setPassword(getRequestStr('forum_password')); $oForum->setSort(getRequestStr('forum_sort')); $oForum->setRedirectUrl(getRequestStr('forum_redirect_url')); if (isPost('forum_redirect_url')) { $oForum->setRedirectOn((int) getRequest('forum_redirect_on', 0, 'post') === 1); } $oForum->setLimitRatingTopic((double) getRequest('forum_limit_rating_topic')); /** * Опции */ if (isPost('forum_display_subforum_list')) { $oForum->setOptionsValue('display_subforum_list', (int) getRequest('forum_display_subforum_list', 0, 'post') === 1); } if (isPost('forum_display_on_index')) { $oForum->setOptionsValue('display_on_index', (int) getRequest('forum_display_on_index', 0, 'post') === 1); } if (isPost('forum_topics_per_page')) { $oForum->setOptionsValue('topics_per_page', getRequestStr('forum_topics_per_page')); } if (isPost('forum_posts_per_page')) { $oForum->setOptionsValue('posts_per_page', getRequestStr('forum_posts_per_page')); } /** * Копируем права доступа */ if (getRequest('forum_perms')) { if ($oCopyForum = $this->PluginForum_Forum_GetForumById(getRequestStr('forum_perms'))) { $oForum->setPermissions($oCopyForum->getPermissions()); } } /** * Загружаем иконку */ if (isset($_FILES['forum_icon']) && is_uploaded_file($_FILES['forum_icon']['tmp_name'])) { if ($sPath = $this->PluginForum_Forum_UploadIcon($_FILES['forum_icon'], $oForum)) { $oForum->setIcon($sPath); } else { $this->Message_AddError($this->Lang_Get('plugin.forum.create_icon_error'), $this->Lang_Get('error')); return false; } } /** * Удаляем иконку */ if (isset($_REQUEST['forum_icon_delete'])) { $this->PluginForum_Forum_DeleteIcon($oForum); $oForum->setIcon(null); } } /** * Проверяем корректность полей */ if (!$this->checkForumFields($oForum)) { return; } /** * Вызов хуков */ $this->Hook_Run('forum_edit_before', array('oForum' => $oForum)); /** * Сохраняем форум */ if ($this->PluginForum_Forum_SaveForum($oForum)) { $this->Hook_Run('forum_edit_after', array('oForum' => $oForum)); $this->Message_AddNotice($this->Lang_Get('plugin.forum.edit_ok'), null, 1); } else { $this->Message_AddError($this->Lang_Get('system_error'), null, 1); } if (isPost('submit_forum_save_next_perms')) { Router::Location(Router::GetPath('forum') . "admin/forums/perms/{$oForum->getId()}"); } else { Router::Location(Router::GetPath('forum') . 'admin/forums/'); } }