Модернизация профиля: Часть 1. Скрываем профиль от посторонних

в процессе модернизации своего профиля реализовал несколько фишечек.
По заявка фишка номер раз: Скрываем профиль от посторонних глаз.

идем в phpmyadmin
1) в таблице prefix_user создаем поле user_profile_closed с типом enum('all','friend','none') не Null и значением по умолчанию all

2) classes/modules/user/entity/User.entity.class.php
добавляем
public function setProfileClosed($data) {
    	$this->_aData['user_profile_closed']=$data;

    public function getProfileClosed() {
        return $this->_aData['user_profile_closed'];


3) classes/modules/user/mapper/User.mapper.class.php
после
user_activate = ? , 

вставить
user_profile_closed = ? ,

после
$oUser->getActivate(),

вставить
$oUser->getProfileClosed(),


4) classes/action/ActionSettings.class.php
в событие
protected function EventProfile() {

добавляем
/**
			 * Проверяем закрыт ли профиль
			 */
			if (in_array(getRequest('profile_closed'),array('all','friend','none'))) {
				$this->oUserCurrent->setProfileClosed(getRequest('profile_closed'));
			} else {
				$this->oUserCurrent->setProfileClosed('all');
			}

5) classes/actions/ActionProfile.class.php
вот тут начинается самая странная вщщь для меня :)
в Init() добавляем
$this->oUserCurrent=$this->User_GetUserCurrent();

(возможно это коряво и неправильно, не могу сказать)

далее, ищем по тексту
$aUsersFrend=$this->User_GetUsersFrend($this->oUserProfile->getId());

и заменяем на
$aFriendProfile=0;
		$aUsersFrend=$this->User_GetUsersFrend($this->oUserProfile->getId());
		foreach ($aUsersFrend as $oUser) {
		if(!$this->oUserCurrent){
		$aFriendProfile=0;}
		else{
		if ($this->oUserCurrent->getId() == $oUser->getId() or $this->oUserCurrent->getId() == $this->oUserProfile->getId()){
		$aFriendProfile=1;	}
		}
		}
			$this->Viewer_Assign('aFriendProfile',$aFriendProfile);

6) templates/skin/.../actions/ActionSettings/profile.tpl
вставить
<p><label for="">ПОказывать ваш профиль:</label>
	<label for=""><input type="radio" name="profile_closed" id="profile_closed_a" value="all" {if $oUserCurrent->getProfileClosed()=='all'}checked{/if} class="radio" />  —  Всем</label>
	<label for=""><input type="radio" name="profile_closed" id="profile_closed_f" value="friend" {if $oUserCurrent->getProfileClosed()=='friend'}checked{/if} class="radio" />  —  Друзьям</label>
	<label for=""><input type="radio" name="profile_closed" id="profile_closed_n" value="none" {if $oUserCurrent->getProfileClosed()=='none'}checked{/if} class="radio" />  —  Никому</label></p>

7) templates/skin/.../actions/ActionProfile/whois.tpl
после
{include file='header.tpl' menu="profile"}

вставить
{if $oUserProfile->getProfileClosed() == 'none' and $oUserCurrent && $oUserCurrent->getId() != $oUserProfile->getId() }
Пользователь предпочел скрыть свой профиль
{elseif $oUserProfile->getProfileClosed() == 'friend' and $aFriendProfile == 0}
Пользователь предпочел открыть свой профиль только для друзей
{else}


ну и перед
{include file='footer.tpl'}

вставить
{/if}

8)…
9) PROFIT

ну вот вроде бы и все должно работать. вопросы, предложения и ошибки прошу в комментарии.
Предлагаем качественный игровой хостинг samp.

7 комментариев

avatar
Спасибо, но мне вряд-ли пригодится..)
avatar
супер
а тексты похорошему надо в ланг файл вынести ;)
avatar
ну похорошему это еще и отверстать надо :)) я лишь для примера указал, кому нужно, то вынесет и сам :)
avatar
такая вот ошибка вылезла при открытии профиля, когда я сохранил чтобы он был виден только мне и вышел из логина своего

Fatal error: Uncaught exception 'Exception' with message 'The module has no required method: User->GetUsersFrend()' in /home/users1/n/neosashadesign/domains/metroboy.ru/engine/classes/Engine.class.php:329 Stack trace: #0 /home/users1/n/neosashadesign/domains/metroboy.ru/engine/classes/Action.class.php(298): Engine->_CallModule('User_GetUsersFr...', Array) #1 /home/users1/n/neosashadesign/domains/metroboy.ru/classes/actions/ActionProfile.class.php(154): Action->__call('User_GetUsersFr...', Array) #2 /home/users1/n/neosashadesign/domains/metroboy.ru/classes/actions/ActionProfile.class.php(154): ActionProfile->User_GetUsersFrend('1') #3 /home/users1/n/neosashadesign/domains/metroboy.ru/engine/classes/Action.class.php(104) : eval()'d code(1): ActionProfile->EventWhois() #4 /home/users1/n/neosashadesign/domains/metroboy.ru/engine/classes/Action.class.php(104): eval() #5 /home/users1/n/neosashadesign/domains/metroboy.ru/engine/classes/Router.class.php(206): Action->ExecEvent() #6 /home/users1/n/neosashadesign/domains/metroboy.r in /home/users1/n/neosashadesign/domains/metroboy.ru/engine/classes/Engine.class.php on line 329
avatar
Спасибо.
Но при установки в none, гости всё равно видят профиль, только friend скрывает.
Что нужно подправить в 7 шаге?
avatar
Сам себе отвечу (нашел таки время, хотя решение нашел почти сразу):
{if $oUserProfile->getProfileClosed() == 'friend' and $aFriendProfile == 0 and (!$oUserCurrent || (!$oUserCurrent->isAdministrator() && $oUserCurrent->getId() != $oUserProfile->getId()))}
<div class="profile-user"><p class="nickname">Пользователь {$oUserProfile->getLogin()} показывает свои персональные данные только друзьям!</div>
{else}

Этот код вставляется в templates/skin/.../actions/ActionProfile/whois.tpl — разрешается просмотр профиля только для друзей, себя и администраторов или всем.
Просто смысла прятать профиль и от друзей не вижу.
avatar
Fatal error: Call to a member function getId() on a non-object in /var/www/cuteshy/data/www/domen.ru/classes/actions/ActionProfile.class.php on line 368

Строка:
else { if ($this->oUserCurrent->getId() == $oUser->getId() or $this->oUserCurrent->getId() == $this->oUserProfile->getId()){ $aFriendProfile=1; }


Для 1.0.3 кажется оно больше не актуально, печаль.
Только зарегистрированные и авторизованные пользователи могут оставлять комментарии.